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_jack_detect(codec, nid);
551 struct via_spec *spec = codec->spec;
552 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
553 || ((no_presence || present)
554 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
555 *affected_parm = AC_PWRST_D0; /* if it's connected */
560 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
563 static void set_jack_power_state(struct hda_codec *codec)
565 struct via_spec *spec = codec->spec;
569 if (spec->codec_type == VT1702) {
570 imux_is_smixer = snd_hda_codec_read(
571 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
573 /* PW 1/2/5 (14h/15h/18h) */
575 set_pin_power_state(codec, 0x14, &parm);
576 set_pin_power_state(codec, 0x15, &parm);
577 set_pin_power_state(codec, 0x18, &parm);
579 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
580 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
581 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
583 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
585 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
587 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
591 /* PW 3/4 (16h/17h) */
593 set_pin_power_state(codec, 0x16, &parm);
594 set_pin_power_state(codec, 0x17, &parm);
595 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
596 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
597 imux_is_smixer ? AC_PWRST_D0 : parm);
598 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
600 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
602 } else if (spec->codec_type == VT1708B_8CH
603 || spec->codec_type == VT1708B_4CH
604 || spec->codec_type == VT1708S) {
605 /* SW0 (17h) = stereo mixer */
606 int is_8ch = spec->codec_type != VT1708B_4CH;
607 imux_is_smixer = snd_hda_codec_read(
608 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
609 == ((spec->codec_type == VT1708S) ? 5 : 0);
611 /* PW 1/2/5 (1ah/1bh/1eh) */
613 set_pin_power_state(codec, 0x1a, &parm);
614 set_pin_power_state(codec, 0x1b, &parm);
615 set_pin_power_state(codec, 0x1e, &parm);
618 /* SW0 (17h), AIW 0/1 (13h/14h) */
619 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
621 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
623 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
627 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
629 set_pin_power_state(codec, 0x19, &parm);
630 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
632 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
635 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
638 set_pin_power_state(codec, 0x22, &parm);
639 snd_hda_codec_write(codec, 0x26, 0,
640 AC_VERB_SET_POWER_STATE, parm);
641 snd_hda_codec_write(codec, 0x24, 0,
642 AC_VERB_SET_POWER_STATE, parm);
645 /* PW 3/4/7 (1ch/1dh/23h) */
647 /* force to D0 for internal Speaker */
648 set_pin_power_state(codec, 0x1c, &parm);
649 set_pin_power_state(codec, 0x1d, &parm);
651 set_pin_power_state(codec, 0x23, &parm);
652 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
653 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
654 imux_is_smixer ? AC_PWRST_D0 : parm);
655 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
658 snd_hda_codec_write(codec, 0x25, 0,
659 AC_VERB_SET_POWER_STATE, parm);
660 snd_hda_codec_write(codec, 0x27, 0,
661 AC_VERB_SET_POWER_STATE, parm);
663 } else if (spec->codec_type == VT1718S) {
664 /* MUX6 (1eh) = stereo mixer */
665 imux_is_smixer = snd_hda_codec_read(
666 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
668 /* PW 5/6/7 (29h/2ah/2bh) */
670 set_pin_power_state(codec, 0x29, &parm);
671 set_pin_power_state(codec, 0x2a, &parm);
672 set_pin_power_state(codec, 0x2b, &parm);
675 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
676 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
678 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
680 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
682 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
686 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
688 set_pin_power_state(codec, 0x27, &parm);
689 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
691 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
694 /* PW2 (26h), AOW2 (ah) */
696 set_pin_power_state(codec, 0x26, &parm);
697 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
700 /* PW0/1 (24h/25h) */
702 set_pin_power_state(codec, 0x24, &parm);
703 set_pin_power_state(codec, 0x25, &parm);
704 if (!spec->hp_independent_mode) /* check for redirected HP */
705 set_pin_power_state(codec, 0x28, &parm);
706 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
708 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
710 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
711 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
712 imux_is_smixer ? AC_PWRST_D0 : parm);
713 if (spec->hp_independent_mode) {
714 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
716 set_pin_power_state(codec, 0x28, &parm);
717 snd_hda_codec_write(codec, 0x1b, 0,
718 AC_VERB_SET_POWER_STATE, parm);
719 snd_hda_codec_write(codec, 0x34, 0,
720 AC_VERB_SET_POWER_STATE, parm);
721 snd_hda_codec_write(codec, 0xc, 0,
722 AC_VERB_SET_POWER_STATE, parm);
724 } else if (spec->codec_type == VT1716S) {
725 unsigned int mono_out, present;
726 /* SW0 (17h) = stereo mixer */
727 imux_is_smixer = snd_hda_codec_read(
728 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
730 /* PW 1/2/5 (1ah/1bh/1eh) */
732 set_pin_power_state(codec, 0x1a, &parm);
733 set_pin_power_state(codec, 0x1b, &parm);
734 set_pin_power_state(codec, 0x1e, &parm);
737 /* SW0 (17h), AIW0(13h) */
738 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
740 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
744 set_pin_power_state(codec, 0x1e, &parm);
746 if (spec->dmic_enabled)
747 set_pin_power_state(codec, 0x22, &parm);
751 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
753 /* SW2(26h), AIW1(14h) */
754 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
756 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
760 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
762 set_pin_power_state(codec, 0x19, &parm);
763 /* Smart 5.1 PW2(1bh) */
764 if (spec->smart51_enabled)
765 set_pin_power_state(codec, 0x1b, &parm);
766 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
768 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
771 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
773 set_pin_power_state(codec, 0x23, &parm);
774 /* Smart 5.1 PW1(1ah) */
775 if (spec->smart51_enabled)
776 set_pin_power_state(codec, 0x1a, &parm);
777 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
780 /* Smart 5.1 PW5(1eh) */
781 if (spec->smart51_enabled)
782 set_pin_power_state(codec, 0x1e, &parm);
783 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
787 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
788 present = snd_hda_jack_detect(codec, 0x1c);
792 present = snd_hda_jack_detect(codec, 0x1d);
793 if (!spec->hp_independent_mode && present)
798 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
799 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
801 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
803 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
806 /* PW 3/4 (1ch/1dh) */
808 set_pin_power_state(codec, 0x1c, &parm);
809 set_pin_power_state(codec, 0x1d, &parm);
810 /* HP Independent Mode, power on AOW3 */
811 if (spec->hp_independent_mode)
812 snd_hda_codec_write(codec, 0x25, 0,
813 AC_VERB_SET_POWER_STATE, parm);
815 /* force to D0 for internal Speaker */
816 /* MW0 (16h), AOW0 (10h) */
817 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
818 imux_is_smixer ? AC_PWRST_D0 : parm);
819 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
820 mono_out ? AC_PWRST_D0 : parm);
821 } else if (spec->codec_type == VT2002P) {
822 unsigned int present;
823 /* MUX9 (1eh) = stereo mixer */
824 imux_is_smixer = snd_hda_codec_read(
825 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
827 /* PW 5/6/7 (29h/2ah/2bh) */
829 set_pin_power_state(codec, 0x29, &parm);
830 set_pin_power_state(codec, 0x2a, &parm);
831 set_pin_power_state(codec, 0x2b, &parm);
834 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
835 snd_hda_codec_write(codec, 0x1e, 0,
836 AC_VERB_SET_POWER_STATE, parm);
837 snd_hda_codec_write(codec, 0x1f, 0,
838 AC_VERB_SET_POWER_STATE, parm);
839 snd_hda_codec_write(codec, 0x10, 0,
840 AC_VERB_SET_POWER_STATE, parm);
841 snd_hda_codec_write(codec, 0x11, 0,
842 AC_VERB_SET_POWER_STATE, parm);
846 snd_hda_codec_write(codec, 0x8, 0,
847 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
849 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
851 set_pin_power_state(codec, 0x26, &parm);
852 snd_hda_codec_write(codec, 0x1c, 0,
853 AC_VERB_SET_POWER_STATE, parm);
854 snd_hda_codec_write(codec, 0x37,
855 0, AC_VERB_SET_POWER_STATE, parm);
857 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
859 set_pin_power_state(codec, 0x25, &parm);
860 snd_hda_codec_write(codec, 0x19, 0,
861 AC_VERB_SET_POWER_STATE, parm);
862 snd_hda_codec_write(codec, 0x35, 0,
863 AC_VERB_SET_POWER_STATE, parm);
864 if (spec->hp_independent_mode) {
865 snd_hda_codec_write(codec, 0x9, 0,
866 AC_VERB_SET_POWER_STATE, parm);
870 /* PW0 (24h), MW0(18h), MUX0(34h) */
871 present = snd_hda_jack_detect(codec, 0x25);
873 set_pin_power_state(codec, 0x24, &parm);
877 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
880 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
884 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
887 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
891 /* PW15 (31h), MW8(17h), MUX8(3bh) */
892 present = snd_hda_jack_detect(codec, 0x26);
894 set_pin_power_state(codec, 0x31, &parm);
898 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
901 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
905 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
908 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
912 if (imux_is_smixer || !is_aa_path_mute(codec))
915 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
919 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
920 } else if (spec->codec_type == VT1812) {
921 unsigned int present;
922 /* MUX10 (1eh) = stereo mixer */
923 imux_is_smixer = snd_hda_codec_read(
924 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
926 /* PW 5/6/7 (29h/2ah/2bh) */
928 set_pin_power_state(codec, 0x29, &parm);
929 set_pin_power_state(codec, 0x2a, &parm);
930 set_pin_power_state(codec, 0x2b, &parm);
933 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
934 snd_hda_codec_write(codec, 0x1e, 0,
935 AC_VERB_SET_POWER_STATE, parm);
936 snd_hda_codec_write(codec, 0x1f, 0,
937 AC_VERB_SET_POWER_STATE, parm);
938 snd_hda_codec_write(codec, 0x10, 0,
939 AC_VERB_SET_POWER_STATE, parm);
940 snd_hda_codec_write(codec, 0x11, 0,
941 AC_VERB_SET_POWER_STATE, parm);
945 snd_hda_codec_write(codec, 0x8, 0,
946 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
948 /* PW4 (28h), MW4 (18h), MUX4(38h) */
950 set_pin_power_state(codec, 0x28, &parm);
951 snd_hda_codec_write(codec, 0x18, 0,
952 AC_VERB_SET_POWER_STATE, parm);
953 snd_hda_codec_write(codec, 0x38, 0,
954 AC_VERB_SET_POWER_STATE, parm);
956 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
958 set_pin_power_state(codec, 0x25, &parm);
959 snd_hda_codec_write(codec, 0x15, 0,
960 AC_VERB_SET_POWER_STATE, parm);
961 snd_hda_codec_write(codec, 0x35, 0,
962 AC_VERB_SET_POWER_STATE, parm);
963 if (spec->hp_independent_mode) {
964 snd_hda_codec_write(codec, 0x9, 0,
965 AC_VERB_SET_POWER_STATE, parm);
968 /* Internal Speaker */
969 /* PW0 (24h), MW0(14h), MUX0(34h) */
970 present = snd_hda_jack_detect(codec, 0x25);
972 set_pin_power_state(codec, 0x24, &parm);
974 snd_hda_codec_write(codec, 0x14, 0,
975 AC_VERB_SET_POWER_STATE,
977 snd_hda_codec_write(codec, 0x34, 0,
978 AC_VERB_SET_POWER_STATE,
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,
989 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
990 present = snd_hda_jack_detect(codec, 0x28);
992 set_pin_power_state(codec, 0x31, &parm);
994 snd_hda_codec_write(codec, 0x1c, 0,
995 AC_VERB_SET_POWER_STATE,
997 snd_hda_codec_write(codec, 0x3c, 0,
998 AC_VERB_SET_POWER_STATE,
1000 snd_hda_codec_write(codec, 0x3e, 0,
1001 AC_VERB_SET_POWER_STATE,
1004 snd_hda_codec_write(codec, 0x1c, 0,
1005 AC_VERB_SET_POWER_STATE,
1007 snd_hda_codec_write(codec, 0x3c, 0,
1008 AC_VERB_SET_POWER_STATE,
1010 snd_hda_codec_write(codec, 0x3e, 0,
1011 AC_VERB_SET_POWER_STATE,
1015 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1017 set_pin_power_state(codec, 0x33, &parm);
1018 snd_hda_codec_write(codec, 0x1d, 0,
1019 AC_VERB_SET_POWER_STATE, parm);
1020 snd_hda_codec_write(codec, 0x3d, 0,
1021 AC_VERB_SET_POWER_STATE, parm);
1024 if (imux_is_smixer || !is_aa_path_mute(codec))
1025 snd_hda_codec_write(
1027 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1029 snd_hda_codec_write(
1031 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1036 * input MUX handling
1038 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1039 struct snd_ctl_elem_info *uinfo)
1041 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1042 struct via_spec *spec = codec->spec;
1043 return snd_hda_input_mux_info(spec->input_mux, uinfo);
1046 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1047 struct snd_ctl_elem_value *ucontrol)
1049 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1050 struct via_spec *spec = codec->spec;
1051 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1053 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
1057 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1058 struct snd_ctl_elem_value *ucontrol)
1060 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1061 struct via_spec *spec = codec->spec;
1062 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1064 if (!spec->mux_nids[adc_idx])
1066 /* switch to D0 beofre change index */
1067 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1068 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1069 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1070 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1071 /* update jack power state */
1072 set_jack_power_state(codec);
1074 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1075 spec->mux_nids[adc_idx],
1076 &spec->cur_mux[adc_idx]);
1079 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
1080 struct snd_ctl_elem_info *uinfo)
1082 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1083 struct via_spec *spec = codec->spec;
1084 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
1087 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
1088 struct snd_ctl_elem_value *ucontrol)
1090 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1091 struct via_spec *spec = codec->spec;
1093 unsigned int pinsel;
1095 switch (spec->codec_type) {
1106 nid = spec->autocfg.hp_pins[0];
1109 /* use !! to translate conn sel 2 for VT1718S */
1110 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1111 AC_VERB_GET_CONNECT_SEL,
1113 ucontrol->value.enumerated.item[0] = pinsel;
1118 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1120 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1122 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1123 ctl->vd[0].access |= active
1124 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1125 snd_ctl_notify(codec->bus->card,
1126 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1130 static int update_side_mute_status(struct hda_codec *codec)
1132 /* mute side channel */
1133 struct via_spec *spec = codec->spec;
1134 unsigned int parm = spec->hp_independent_mode
1135 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1138 switch (spec->codec_type) {
1155 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1160 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
1161 struct snd_ctl_elem_value *ucontrol)
1163 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1164 struct via_spec *spec = codec->spec;
1165 hda_nid_t nid = spec->autocfg.hp_pins[0];
1166 unsigned int pinsel = ucontrol->value.enumerated.item[0];
1167 /* Get Independent Mode index of headphone pin widget */
1168 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1171 switch (spec->codec_type) {
1174 pinsel = pinsel ? 2 : 0; /* indep HP use AOW4 (index 2) */
1175 spec->multiout.num_dacs = 4;
1184 nid = spec->autocfg.hp_pins[0];
1187 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
1189 if (spec->multiout.hp_nid && spec->multiout.hp_nid
1190 != spec->multiout.dac_nids[HDA_FRONT])
1191 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
1194 update_side_mute_status(codec);
1195 /* update HP volume/swtich active state */
1196 if (spec->codec_type == VT1708S
1197 || spec->codec_type == VT1702
1198 || spec->codec_type == VT1718S
1199 || spec->codec_type == VT1716S
1200 || spec->codec_type == VT2002P
1201 || spec->codec_type == VT1812) {
1202 activate_ctl(codec, "Headphone Playback Volume",
1203 spec->hp_independent_mode);
1204 activate_ctl(codec, "Headphone Playback Switch",
1205 spec->hp_independent_mode);
1210 static struct snd_kcontrol_new via_hp_mixer[] = {
1212 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1213 .name = "Independent HP",
1215 .info = via_independent_hp_info,
1216 .get = via_independent_hp_get,
1217 .put = via_independent_hp_put,
1222 static void notify_aa_path_ctls(struct hda_codec *codec)
1225 struct snd_ctl_elem_id id;
1226 const char *labels[] = {"Mic", "Front Mic", "Line"};
1228 memset(&id, 0, sizeof(id));
1229 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1230 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1231 sprintf(id.name, "%s Playback Volume", labels[i]);
1232 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1237 static void mute_aa_path(struct hda_codec *codec, int mute)
1239 struct via_spec *spec = codec->spec;
1240 hda_nid_t nid_mixer;
1244 /* get nid of MW0 and start & end index */
1245 switch (spec->codec_type) {
1268 /* check AA path's mute status */
1269 for (i = start_idx; i <= end_idx; i++) {
1270 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1271 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1275 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1279 for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
1280 if (pin == spec->autocfg.input_pins[index]) {
1288 static int via_smart51_info(struct snd_kcontrol *kcontrol,
1289 struct snd_ctl_elem_info *uinfo)
1291 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1293 uinfo->value.integer.min = 0;
1294 uinfo->value.integer.max = 1;
1298 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1299 struct snd_ctl_elem_value *ucontrol)
1301 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1302 struct via_spec *spec = codec->spec;
1303 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1307 for (i = 0; i < ARRAY_SIZE(index); i++) {
1308 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1311 snd_hda_codec_read(codec, nid, 0,
1312 AC_VERB_GET_PIN_WIDGET_CONTROL,
1314 if (i == AUTO_PIN_FRONT_MIC
1315 && spec->hp_independent_mode
1316 && spec->codec_type != VT1718S)
1317 continue; /* ignore FMic for independent HP */
1318 if (ctl & AC_PINCTL_IN_EN
1319 && !(ctl & AC_PINCTL_OUT_EN))
1323 *ucontrol->value.integer.value = on;
1327 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1328 struct snd_ctl_elem_value *ucontrol)
1330 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1331 struct via_spec *spec = codec->spec;
1332 int out_in = *ucontrol->value.integer.value
1333 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1334 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1337 for (i = 0; i < ARRAY_SIZE(index); i++) {
1338 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1339 if (i == AUTO_PIN_FRONT_MIC
1340 && spec->hp_independent_mode
1341 && spec->codec_type != VT1718S)
1342 continue; /* don't retask FMic for independent HP */
1344 unsigned int parm = snd_hda_codec_read(
1346 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1347 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1349 snd_hda_codec_write(codec, nid, 0,
1350 AC_VERB_SET_PIN_WIDGET_CONTROL,
1352 if (out_in == AC_PINCTL_OUT_EN) {
1353 mute_aa_path(codec, 1);
1354 notify_aa_path_ctls(codec);
1356 if (spec->codec_type == VT1718S)
1357 snd_hda_codec_amp_stereo(
1358 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1361 if (i == AUTO_PIN_FRONT_MIC) {
1362 if (spec->codec_type == VT1708S
1363 || spec->codec_type == VT1716S) {
1364 /* input = index 1 (AOW3) */
1365 snd_hda_codec_write(
1367 AC_VERB_SET_CONNECT_SEL, 1);
1368 snd_hda_codec_amp_stereo(
1369 codec, nid, HDA_OUTPUT,
1370 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1374 spec->smart51_enabled = *ucontrol->value.integer.value;
1375 set_jack_power_state(codec);
1379 static struct snd_kcontrol_new via_smart51_mixer[] = {
1381 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1382 .name = "Smart 5.1",
1384 .info = via_smart51_info,
1385 .get = via_smart51_get,
1386 .put = via_smart51_put,
1391 /* capture mixer elements */
1392 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1393 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1394 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1395 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1396 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1398 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1399 /* The multiple "Capture Source" controls confuse alsamixer
1400 * So call somewhat different..
1402 /* .name = "Capture Source", */
1403 .name = "Input Source",
1405 .info = via_mux_enum_info,
1406 .get = via_mux_enum_get,
1407 .put = via_mux_enum_put,
1412 /* check AA path's mute statue */
1413 static int is_aa_path_mute(struct hda_codec *codec)
1416 hda_nid_t nid_mixer;
1420 struct via_spec *spec = codec->spec;
1421 /* get nid of MW0 and start & end index */
1422 switch (spec->codec_type) {
1450 /* check AA path's mute status */
1451 for (i = start_idx; i <= end_idx; i++) {
1452 unsigned int con_list = snd_hda_codec_read(
1453 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1454 int shift = 8 * (i % 4);
1455 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1456 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1457 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1458 /* check mute status while the pin is connected */
1459 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1461 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1463 if (!mute_l || !mute_r) {
1472 /* enter/exit analog low-current mode */
1473 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1475 struct via_spec *spec = codec->spec;
1476 static int saved_stream_idle = 1; /* saved stream idle status */
1477 int enable = is_aa_path_mute(codec);
1478 unsigned int verb = 0;
1479 unsigned int parm = 0;
1481 if (stream_idle == -1) /* stream status did not change */
1482 enable = enable && saved_stream_idle;
1484 enable = enable && stream_idle;
1485 saved_stream_idle = stream_idle;
1488 /* decide low current mode's verb & parameter */
1489 switch (spec->codec_type) {
1493 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1499 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1503 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1508 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1511 return; /* other codecs are not supported */
1514 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1518 * generic initialization of ADC, input mixers and output mixers
1520 static struct hda_verb vt1708_volume_init_verbs[] = {
1522 * Unmute ADC0-1 and set the default input to mic-in
1524 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1525 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1528 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1531 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1532 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1533 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1534 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1535 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1536 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1539 * Set up output mixers (0x19 - 0x1b)
1541 /* set vol=0 to output mixers */
1542 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1543 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1544 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1546 /* Setup default input MW0 to PW4 */
1547 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1548 /* PW9 Output enable */
1549 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1553 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1554 struct hda_codec *codec,
1555 struct snd_pcm_substream *substream)
1557 struct via_spec *spec = codec->spec;
1558 int idle = substream->pstr->substream_opened == 1
1559 && substream->ref_count == 0;
1560 analog_low_current_mode(codec, idle);
1561 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1565 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1566 unsigned int stream_tag,
1567 unsigned int format,
1568 struct snd_pcm_substream *substream)
1570 struct via_spec *spec = codec->spec;
1571 struct hda_multi_out *mout = &spec->multiout;
1572 hda_nid_t *nids = mout->dac_nids;
1573 int chs = substream->runtime->channels;
1576 mutex_lock(&codec->spdif_mutex);
1577 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1579 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1581 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1582 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1583 /* turn off SPDIF once; otherwise the IEC958 bits won't
1585 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1586 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1587 AC_VERB_SET_DIGI_CONVERT_1,
1589 ~AC_DIG1_ENABLE & 0xff);
1590 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1591 stream_tag, 0, format);
1592 /* turn on again (if needed) */
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,
1596 codec->spdif_ctls & 0xff);
1598 mout->dig_out_used = 0;
1599 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1603 mutex_unlock(&codec->spdif_mutex);
1606 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1609 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1610 && !spec->hp_independent_mode)
1611 /* headphone out will just decode front left/right (stereo) */
1612 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1615 /* extra outputs copied from front */
1616 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1617 if (mout->extra_out_nid[i])
1618 snd_hda_codec_setup_stream(codec,
1619 mout->extra_out_nid[i],
1620 stream_tag, 0, format);
1623 for (i = 1; i < mout->num_dacs; i++) {
1624 if (chs >= (i + 1) * 2) /* independent out */
1625 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1627 else /* copy front */
1628 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1633 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1634 struct hda_codec *codec,
1635 unsigned int stream_tag,
1636 unsigned int format,
1637 struct snd_pcm_substream *substream)
1639 struct via_spec *spec = codec->spec;
1640 struct hda_multi_out *mout = &spec->multiout;
1641 hda_nid_t *nids = mout->dac_nids;
1643 if (substream->number == 0)
1644 playback_multi_pcm_prep_0(codec, stream_tag, format,
1647 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1648 spec->hp_independent_mode)
1649 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1650 stream_tag, 0, format);
1652 vt1708_start_hp_work(spec);
1656 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1657 struct hda_codec *codec,
1658 struct snd_pcm_substream *substream)
1660 struct via_spec *spec = codec->spec;
1661 struct hda_multi_out *mout = &spec->multiout;
1662 hda_nid_t *nids = mout->dac_nids;
1665 if (substream->number == 0) {
1666 for (i = 0; i < mout->num_dacs; i++)
1667 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1669 if (mout->hp_nid && !spec->hp_independent_mode)
1670 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1673 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1674 if (mout->extra_out_nid[i])
1675 snd_hda_codec_setup_stream(codec,
1676 mout->extra_out_nid[i],
1678 mutex_lock(&codec->spdif_mutex);
1679 if (mout->dig_out_nid &&
1680 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1681 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1683 mout->dig_out_used = 0;
1685 mutex_unlock(&codec->spdif_mutex);
1687 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1688 spec->hp_independent_mode)
1689 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1692 vt1708_stop_hp_work(spec);
1699 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1700 struct hda_codec *codec,
1701 struct snd_pcm_substream *substream)
1703 struct via_spec *spec = codec->spec;
1704 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1707 static int via_dig_playback_pcm_close(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_close(codec, &spec->multiout);
1715 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1716 struct hda_codec *codec,
1717 unsigned int stream_tag,
1718 unsigned int format,
1719 struct snd_pcm_substream *substream)
1721 struct via_spec *spec = codec->spec;
1722 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1723 stream_tag, format, substream);
1726 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1727 struct hda_codec *codec,
1728 struct snd_pcm_substream *substream)
1730 struct via_spec *spec = codec->spec;
1731 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1738 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1739 struct hda_codec *codec,
1740 unsigned int stream_tag,
1741 unsigned int format,
1742 struct snd_pcm_substream *substream)
1744 struct via_spec *spec = codec->spec;
1746 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1747 stream_tag, 0, format);
1751 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1752 struct hda_codec *codec,
1753 struct snd_pcm_substream *substream)
1755 struct via_spec *spec = codec->spec;
1756 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1760 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1764 .nid = 0x10, /* NID to query formats and rates */
1766 .open = via_playback_pcm_open,
1767 .prepare = via_playback_multi_pcm_prepare,
1768 .cleanup = via_playback_multi_pcm_cleanup
1772 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1776 .nid = 0x10, /* NID to query formats and rates */
1777 /* We got noisy outputs on the right channel on VT1708 when
1778 * 24bit samples are used. Until any workaround is found,
1779 * disable the 24bit format, so far.
1781 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1783 .open = via_playback_pcm_open,
1784 .prepare = via_playback_multi_pcm_prepare,
1785 .cleanup = via_playback_multi_pcm_cleanup
1789 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1793 .nid = 0x15, /* NID to query formats and rates */
1795 .prepare = via_capture_pcm_prepare,
1796 .cleanup = via_capture_pcm_cleanup
1800 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1804 /* NID is set in via_build_pcms */
1806 .open = via_dig_playback_pcm_open,
1807 .close = via_dig_playback_pcm_close,
1808 .prepare = via_dig_playback_pcm_prepare,
1809 .cleanup = via_dig_playback_pcm_cleanup
1813 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1819 static int via_build_controls(struct hda_codec *codec)
1821 struct via_spec *spec = codec->spec;
1825 for (i = 0; i < spec->num_mixers; i++) {
1826 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1831 if (spec->multiout.dig_out_nid) {
1832 err = snd_hda_create_spdif_out_ctls(codec,
1833 spec->multiout.dig_out_nid);
1836 err = snd_hda_create_spdif_share_sw(codec,
1840 spec->multiout.share_spdif = 1;
1842 if (spec->dig_in_nid) {
1843 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1848 /* init power states */
1849 set_jack_power_state(codec);
1850 analog_low_current_mode(codec, 1);
1852 via_free_kctls(codec); /* no longer needed */
1856 static int via_build_pcms(struct hda_codec *codec)
1858 struct via_spec *spec = codec->spec;
1859 struct hda_pcm *info = spec->pcm_rec;
1861 codec->num_pcms = 1;
1862 codec->pcm_info = info;
1864 info->name = spec->stream_name_analog;
1865 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1866 *(spec->stream_analog_playback);
1867 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1868 spec->multiout.dac_nids[0];
1869 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1870 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1872 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1873 spec->multiout.max_channels;
1875 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1878 info->name = spec->stream_name_digital;
1879 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1880 if (spec->multiout.dig_out_nid) {
1881 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1882 *(spec->stream_digital_playback);
1883 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1884 spec->multiout.dig_out_nid;
1886 if (spec->dig_in_nid) {
1887 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1888 *(spec->stream_digital_capture);
1889 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1897 static void via_free(struct hda_codec *codec)
1899 struct via_spec *spec = codec->spec;
1904 via_free_kctls(codec);
1905 vt1708_stop_hp_work(spec);
1909 /* mute internal speaker if HP is plugged */
1910 static void via_hp_automute(struct hda_codec *codec)
1912 unsigned int present = 0;
1913 struct via_spec *spec = codec->spec;
1915 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1917 if (!spec->hp_independent_mode) {
1918 struct snd_ctl_elem_id id;
1920 snd_hda_codec_amp_stereo(
1921 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1922 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1924 memset(&id, 0, sizeof(id));
1925 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1926 strcpy(id.name, "Front Playback Switch");
1927 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1932 /* mute mono out if HP or Line out is plugged */
1933 static void via_mono_automute(struct hda_codec *codec)
1935 unsigned int hp_present, lineout_present;
1936 struct via_spec *spec = codec->spec;
1938 if (spec->codec_type != VT1716S)
1941 lineout_present = snd_hda_jack_detect(codec,
1942 spec->autocfg.line_out_pins[0]);
1944 /* Mute Mono Out if Line Out is plugged */
1945 if (lineout_present) {
1946 snd_hda_codec_amp_stereo(
1947 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1951 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1953 if (!spec->hp_independent_mode)
1954 snd_hda_codec_amp_stereo(
1955 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1956 hp_present ? HDA_AMP_MUTE : 0);
1959 static void via_gpio_control(struct hda_codec *codec)
1961 unsigned int gpio_data;
1962 unsigned int vol_counter;
1964 unsigned int master_vol;
1966 struct via_spec *spec = codec->spec;
1968 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1969 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1971 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1972 0xF84, 0) & 0x3F0000) >> 16;
1974 vol = vol_counter & 0x1F;
1975 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1976 AC_VERB_GET_AMP_GAIN_MUTE,
1979 if (gpio_data == 0x02) {
1980 /* unmute line out */
1981 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1982 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1984 if (vol_counter & 0x20) {
1985 /* decrease volume */
1986 if (vol > master_vol)
1988 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1992 /* increase volume */
1993 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1995 ((master_vol+vol) > 0x2A) ? 0x2A :
1998 } else if (!(gpio_data & 0x02)) {
2000 snd_hda_codec_amp_stereo(codec,
2001 spec->autocfg.line_out_pins[0],
2002 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2007 /* mute Internal-Speaker if HP is plugged */
2008 static void via_speaker_automute(struct hda_codec *codec)
2010 unsigned int hp_present;
2011 struct via_spec *spec = codec->spec;
2013 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2016 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2018 if (!spec->hp_independent_mode) {
2019 struct snd_ctl_elem_id id;
2020 snd_hda_codec_amp_stereo(
2021 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2022 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2024 memset(&id, 0, sizeof(id));
2025 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2026 strcpy(id.name, "Speaker Playback Switch");
2027 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2032 /* mute line-out and internal speaker if HP is plugged */
2033 static void via_hp_bind_automute(struct hda_codec *codec)
2035 /* use long instead of int below just to avoid an internal compiler
2036 * error with gcc 4.0.x
2038 unsigned long hp_present, present = 0;
2039 struct via_spec *spec = codec->spec;
2042 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2045 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2047 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2049 if (!spec->hp_independent_mode) {
2050 /* Mute Line-Outs */
2051 for (i = 0; i < spec->autocfg.line_outs; i++)
2052 snd_hda_codec_amp_stereo(
2053 codec, spec->autocfg.line_out_pins[i],
2055 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2057 present = hp_present;
2060 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2061 snd_hda_codec_amp_stereo(
2062 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2063 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2067 /* unsolicited event for jack sensing */
2068 static void via_unsol_event(struct hda_codec *codec,
2072 if (res & VIA_HP_EVENT)
2073 via_hp_automute(codec);
2074 if (res & VIA_GPIO_EVENT)
2075 via_gpio_control(codec);
2076 if (res & VIA_JACK_EVENT)
2077 set_jack_power_state(codec);
2078 if (res & VIA_MONO_EVENT)
2079 via_mono_automute(codec);
2080 if (res & VIA_SPEAKER_EVENT)
2081 via_speaker_automute(codec);
2082 if (res & VIA_BIND_HP_EVENT)
2083 via_hp_bind_automute(codec);
2086 static int via_init(struct hda_codec *codec)
2088 struct via_spec *spec = codec->spec;
2090 for (i = 0; i < spec->num_iverbs; i++)
2091 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2093 spec->codec_type = get_codec_type(codec);
2094 if (spec->codec_type == VT1708BCE)
2095 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2097 /* Lydia Add for EAPD enable */
2098 if (!spec->dig_in_nid) { /* No Digital In connection */
2099 if (spec->dig_in_pin) {
2100 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2101 AC_VERB_SET_PIN_WIDGET_CONTROL,
2103 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2104 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2106 } else /* enable SPDIF-input pin */
2107 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2108 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2110 /* assign slave outs */
2111 if (spec->slave_dig_outs[0])
2112 codec->slave_dig_outs = spec->slave_dig_outs;
2117 #ifdef SND_HDA_NEEDS_RESUME
2118 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2120 struct via_spec *spec = codec->spec;
2121 vt1708_stop_hp_work(spec);
2126 #ifdef CONFIG_SND_HDA_POWER_SAVE
2127 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2129 struct via_spec *spec = codec->spec;
2130 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2136 static struct hda_codec_ops via_patch_ops = {
2137 .build_controls = via_build_controls,
2138 .build_pcms = via_build_pcms,
2141 #ifdef SND_HDA_NEEDS_RESUME
2142 .suspend = via_suspend,
2144 #ifdef CONFIG_SND_HDA_POWER_SAVE
2145 .check_power_status = via_check_power_status,
2149 /* fill in the dac_nids table from the parsed pin configuration */
2150 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2151 const struct auto_pin_cfg *cfg)
2156 spec->multiout.num_dacs = cfg->line_outs;
2158 spec->multiout.dac_nids = spec->private_dac_nids;
2160 for (i = 0; i < 4; i++) {
2161 nid = cfg->line_out_pins[i];
2163 /* config dac list */
2165 case AUTO_SEQ_FRONT:
2166 spec->multiout.dac_nids[i] = 0x10;
2168 case AUTO_SEQ_CENLFE:
2169 spec->multiout.dac_nids[i] = 0x12;
2171 case AUTO_SEQ_SURROUND:
2172 spec->multiout.dac_nids[i] = 0x11;
2175 spec->multiout.dac_nids[i] = 0x13;
2184 /* add playback controls from the parsed DAC table */
2185 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2186 const struct auto_pin_cfg *cfg)
2189 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2190 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2193 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2194 nid = cfg->line_out_pins[i];
2199 nid_vol = nid_vols[i];
2201 if (i == AUTO_SEQ_CENLFE) {
2203 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2204 "Center Playback Volume",
2205 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2209 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2210 "LFE Playback Volume",
2211 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2215 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2216 "Center Playback Switch",
2217 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2221 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2222 "LFE Playback Switch",
2223 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2227 } else if (i == AUTO_SEQ_FRONT) {
2228 /* add control to mixer index 0 */
2229 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2230 "Master Front Playback Volume",
2231 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2235 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2236 "Master Front Playback Switch",
2237 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2242 /* add control to PW3 */
2243 sprintf(name, "%s Playback Volume", chname[i]);
2244 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2245 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2249 sprintf(name, "%s Playback Switch", chname[i]);
2250 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2251 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2256 sprintf(name, "%s Playback Volume", chname[i]);
2257 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2258 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2262 sprintf(name, "%s Playback Switch", chname[i]);
2263 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2264 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2274 static void create_hp_imux(struct via_spec *spec)
2277 struct hda_input_mux *imux = &spec->private_imux[1];
2278 static const char *texts[] = { "OFF", "ON", NULL};
2280 /* for hp mode select */
2282 while (texts[i] != NULL) {
2283 imux->items[imux->num_items].label = texts[i];
2284 imux->items[imux->num_items].index = i;
2289 spec->hp_mux = &spec->private_imux[1];
2292 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2299 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2300 spec->hp_independent_mode_index = 1;
2302 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2303 "Headphone Playback Volume",
2304 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2307 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2308 "Headphone Playback Switch",
2309 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2313 create_hp_imux(spec);
2318 /* create playback/capture controls for input pins */
2319 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
2320 const struct auto_pin_cfg *cfg)
2322 static char *labels[] = {
2323 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2325 struct hda_input_mux *imux = &spec->private_imux[0];
2326 int i, err, idx = 0;
2328 /* for internal loopback recording select */
2329 imux->items[imux->num_items].label = "Stereo Mixer";
2330 imux->items[imux->num_items].index = idx;
2333 for (i = 0; i < AUTO_PIN_LAST; i++) {
2334 if (!cfg->input_pins[i])
2337 switch (cfg->input_pins[i]) {
2338 case 0x1d: /* Mic */
2342 case 0x1e: /* Line In */
2346 case 0x21: /* Front Mic */
2354 err = via_new_analog_input(spec, labels[i], idx, 0x17);
2357 imux->items[imux->num_items].label = labels[i];
2358 imux->items[imux->num_items].index = idx;
2364 #ifdef CONFIG_SND_HDA_POWER_SAVE
2365 static struct hda_amp_list vt1708_loopbacks[] = {
2366 { 0x17, HDA_INPUT, 1 },
2367 { 0x17, HDA_INPUT, 2 },
2368 { 0x17, HDA_INPUT, 3 },
2369 { 0x17, HDA_INPUT, 4 },
2374 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2376 unsigned int def_conf;
2377 unsigned char seqassoc;
2379 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2380 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2381 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2382 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2383 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2384 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2385 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2391 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2392 struct snd_ctl_elem_value *ucontrol)
2394 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2395 struct via_spec *spec = codec->spec;
2397 if (spec->codec_type != VT1708)
2399 spec->vt1708_jack_detectect =
2400 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2401 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2405 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2406 struct snd_ctl_elem_value *ucontrol)
2408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2409 struct via_spec *spec = codec->spec;
2412 if (spec->codec_type != VT1708)
2414 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2415 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2416 == !spec->vt1708_jack_detectect;
2417 if (spec->vt1708_jack_detectect) {
2418 mute_aa_path(codec, 1);
2419 notify_aa_path_ctls(codec);
2424 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2426 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2427 .name = "Jack Detect",
2429 .info = snd_ctl_boolean_mono_info,
2430 .get = vt1708_jack_detectect_get,
2431 .put = vt1708_jack_detectect_put,
2436 static int vt1708_parse_auto_config(struct hda_codec *codec)
2438 struct via_spec *spec = codec->spec;
2441 /* Add HP and CD pin config connect bit re-config action */
2442 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2443 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2445 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2448 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2451 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2452 return 0; /* can't find valid BIOS pin config */
2454 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2457 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2460 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
2463 /* add jack detect on/off control */
2464 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2468 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2470 if (spec->autocfg.dig_outs)
2471 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2472 spec->dig_in_pin = VT1708_DIGIN_PIN;
2473 if (spec->autocfg.dig_in_pin)
2474 spec->dig_in_nid = VT1708_DIGIN_NID;
2476 if (spec->kctls.list)
2477 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2479 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2481 spec->input_mux = &spec->private_imux[0];
2484 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2486 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2490 /* init callback for auto-configuration model -- overriding the default init */
2491 static int via_auto_init(struct hda_codec *codec)
2493 struct via_spec *spec = codec->spec;
2496 via_auto_init_multi_out(codec);
2497 via_auto_init_hp_out(codec);
2498 via_auto_init_analog_input(codec);
2499 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2500 via_hp_bind_automute(codec);
2502 via_hp_automute(codec);
2503 via_speaker_automute(codec);
2509 static void vt1708_update_hp_jack_state(struct work_struct *work)
2511 struct via_spec *spec = container_of(work, struct via_spec,
2512 vt1708_hp_work.work);
2513 if (spec->codec_type != VT1708)
2515 /* if jack state toggled */
2516 if (spec->vt1708_hp_present
2517 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2518 spec->vt1708_hp_present ^= 1;
2519 via_hp_automute(spec->codec);
2521 vt1708_start_hp_work(spec);
2524 static int get_mux_nids(struct hda_codec *codec)
2526 struct via_spec *spec = codec->spec;
2527 hda_nid_t nid, conn[8];
2531 for (i = 0; i < spec->num_adc_nids; i++) {
2532 nid = spec->adc_nids[i];
2534 type = get_wcaps_type(get_wcaps(codec, nid));
2535 if (type == AC_WID_PIN)
2537 n = snd_hda_get_connections(codec, nid, conn,
2542 spec->mux_nids[i] = nid;
2551 static int patch_vt1708(struct hda_codec *codec)
2553 struct via_spec *spec;
2556 /* create a codec specific record */
2557 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2563 /* automatic parse from the BIOS config */
2564 err = vt1708_parse_auto_config(codec);
2569 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2570 "from BIOS. Using genenic mode...\n");
2574 spec->stream_name_analog = "VT1708 Analog";
2575 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2576 /* disable 32bit format on VT1708 */
2577 if (codec->vendor_id == 0x11061708)
2578 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2579 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2581 spec->stream_name_digital = "VT1708 Digital";
2582 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2583 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2586 if (!spec->adc_nids && spec->input_mux) {
2587 spec->adc_nids = vt1708_adc_nids;
2588 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2589 get_mux_nids(codec);
2590 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2594 codec->patch_ops = via_patch_ops;
2596 codec->patch_ops.init = via_auto_init;
2597 #ifdef CONFIG_SND_HDA_POWER_SAVE
2598 spec->loopback.amplist = vt1708_loopbacks;
2600 spec->codec = codec;
2601 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2605 /* capture mixer elements */
2606 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2607 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2608 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2609 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2610 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2611 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2612 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2614 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2615 /* The multiple "Capture Source" controls confuse alsamixer
2616 * So call somewhat different..
2618 /* .name = "Capture Source", */
2619 .name = "Input Source",
2621 .info = via_mux_enum_info,
2622 .get = via_mux_enum_get,
2623 .put = via_mux_enum_put,
2628 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2629 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2630 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2635 * generic initialization of ADC, input mixers and output mixers
2637 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2639 * Unmute ADC0-2 and set the default input to mic-in
2641 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2642 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2643 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2646 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2649 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2650 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2651 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2652 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2653 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2654 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2657 * Set up output selector (0x1a, 0x1b, 0x29)
2659 /* set vol=0 to output mixers */
2660 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2661 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2662 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2665 * Unmute PW3 and PW4
2667 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2668 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2670 /* Set input of PW4 as MW0 */
2671 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2672 /* PW9 Output enable */
2673 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2677 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2681 .nid = 0x10, /* NID to query formats and rates */
2683 .open = via_playback_pcm_open,
2684 .prepare = via_playback_multi_pcm_prepare,
2685 .cleanup = via_playback_multi_pcm_cleanup,
2689 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2693 .nid = 0x10, /* NID to query formats and rates */
2695 .open = via_playback_pcm_open,
2696 .prepare = via_playback_multi_pcm_prepare,
2697 .cleanup = via_playback_multi_pcm_cleanup,
2701 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2705 .nid = 0x14, /* NID to query formats and rates */
2707 .prepare = via_capture_pcm_prepare,
2708 .cleanup = via_capture_pcm_cleanup
2712 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2716 /* NID is set in via_build_pcms */
2718 .open = via_dig_playback_pcm_open,
2719 .close = via_dig_playback_pcm_close
2723 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2729 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2730 const struct auto_pin_cfg *cfg)
2735 if (cfg->line_outs == 4) /* 10 channels */
2736 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2737 else if (cfg->line_outs == 3) /* 6 channels */
2738 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2740 spec->multiout.dac_nids = spec->private_dac_nids;
2742 if (cfg->line_outs == 4) { /* 10 channels */
2743 for (i = 0; i < cfg->line_outs; i++) {
2744 nid = cfg->line_out_pins[i];
2746 /* config dac list */
2748 case AUTO_SEQ_FRONT:
2750 spec->multiout.dac_nids[i] = 0x10;
2752 case AUTO_SEQ_CENLFE:
2754 spec->multiout.dac_nids[i] = 0x12;
2756 case AUTO_SEQ_SURROUND:
2758 spec->multiout.dac_nids[i] = 0x11;
2762 spec->multiout.dac_nids[i] = 0x27;
2769 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2771 } else if (cfg->line_outs == 3) { /* 6 channels */
2772 for (i = 0; i < cfg->line_outs; i++) {
2773 nid = cfg->line_out_pins[i];
2775 /* config dac list */
2777 case AUTO_SEQ_FRONT:
2779 spec->multiout.dac_nids[i] = 0x10;
2781 case AUTO_SEQ_CENLFE:
2783 spec->multiout.dac_nids[i] = 0x12;
2785 case AUTO_SEQ_SURROUND:
2787 spec->multiout.dac_nids[i] = 0x11;
2799 /* add playback controls from the parsed DAC table */
2800 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2801 const struct auto_pin_cfg *cfg)
2804 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2805 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2808 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2809 nid = cfg->line_out_pins[i];
2814 nid_vol = nid_vols[i];
2816 if (i == AUTO_SEQ_CENLFE) {
2818 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2819 "Center Playback Volume",
2820 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2824 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2825 "LFE Playback Volume",
2826 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2830 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2831 "Center Playback Switch",
2832 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2836 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2837 "LFE Playback Switch",
2838 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2842 } else if (i == AUTO_SEQ_FRONT) {
2843 /* ADD control to mixer index 0 */
2844 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2845 "Master Front Playback Volume",
2846 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2850 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2851 "Master Front Playback Switch",
2852 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2857 /* add control to PW3 */
2858 sprintf(name, "%s Playback Volume", chname[i]);
2859 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2860 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2864 sprintf(name, "%s Playback Switch", chname[i]);
2865 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2866 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2870 } else if (i == AUTO_SEQ_SURROUND) {
2871 sprintf(name, "%s Playback Volume", chname[i]);
2872 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2873 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2877 sprintf(name, "%s Playback Switch", chname[i]);
2878 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2879 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2883 } else if (i == AUTO_SEQ_SIDE) {
2884 sprintf(name, "%s Playback Volume", chname[i]);
2885 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2886 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2890 sprintf(name, "%s Playback Switch", chname[i]);
2891 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2892 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2902 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2909 if (spec->multiout.num_dacs == 5) /* 10 channels */
2910 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2911 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2912 spec->multiout.hp_nid = 0;
2913 spec->hp_independent_mode_index = 1;
2915 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2916 "Headphone Playback Volume",
2917 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2920 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2921 "Headphone Playback Switch",
2922 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2929 /* create playback/capture controls for input pins */
2930 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
2931 const struct auto_pin_cfg *cfg)
2933 static char *labels[] = {
2934 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2936 struct hda_input_mux *imux = &spec->private_imux[0];
2937 int i, err, idx = 0;
2939 /* for internal loopback recording select */
2940 imux->items[imux->num_items].label = "Stereo Mixer";
2941 imux->items[imux->num_items].index = idx;
2944 for (i = 0; i < AUTO_PIN_LAST; i++) {
2945 if (!cfg->input_pins[i])
2948 switch (cfg->input_pins[i]) {
2949 case 0x1d: /* Mic */
2953 case 0x1e: /* Line In */
2957 case 0x21: /* Front Mic */
2965 err = via_new_analog_input(spec, labels[i], idx, 0x18);
2968 imux->items[imux->num_items].label = labels[i];
2969 imux->items[imux->num_items].index = idx;
2975 static int vt1709_parse_auto_config(struct hda_codec *codec)
2977 struct via_spec *spec = codec->spec;
2980 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2983 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2986 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2987 return 0; /* can't find valid BIOS pin config */
2989 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2992 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2995 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
2999 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3001 if (spec->autocfg.dig_outs)
3002 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3003 spec->dig_in_pin = VT1709_DIGIN_PIN;
3004 if (spec->autocfg.dig_in_pin)
3005 spec->dig_in_nid = VT1709_DIGIN_NID;
3007 if (spec->kctls.list)
3008 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3010 spec->input_mux = &spec->private_imux[0];
3013 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3015 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
3019 #ifdef CONFIG_SND_HDA_POWER_SAVE
3020 static struct hda_amp_list vt1709_loopbacks[] = {
3021 { 0x18, HDA_INPUT, 1 },
3022 { 0x18, HDA_INPUT, 2 },
3023 { 0x18, HDA_INPUT, 3 },
3024 { 0x18, HDA_INPUT, 4 },
3029 static int patch_vt1709_10ch(struct hda_codec *codec)
3031 struct via_spec *spec;
3034 /* create a codec specific record */
3035 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3041 err = vt1709_parse_auto_config(codec);
3046 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3047 "Using genenic mode...\n");
3050 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3051 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3053 spec->stream_name_analog = "VT1709 Analog";
3054 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3055 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3057 spec->stream_name_digital = "VT1709 Digital";
3058 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3059 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3062 if (!spec->adc_nids && spec->input_mux) {
3063 spec->adc_nids = vt1709_adc_nids;
3064 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3065 get_mux_nids(codec);
3066 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3070 codec->patch_ops = via_patch_ops;
3072 codec->patch_ops.init = via_auto_init;
3073 codec->patch_ops.unsol_event = via_unsol_event;
3074 #ifdef CONFIG_SND_HDA_POWER_SAVE
3075 spec->loopback.amplist = vt1709_loopbacks;
3081 * generic initialization of ADC, input mixers and output mixers
3083 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3085 * Unmute ADC0-2 and set the default input to mic-in
3087 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3088 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3089 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3092 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3095 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3096 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3097 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3098 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3099 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3100 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3103 * Set up output selector (0x1a, 0x1b, 0x29)
3105 /* set vol=0 to output mixers */
3106 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3107 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3108 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3111 * Unmute PW3 and PW4
3113 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3114 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3116 /* Set input of PW4 as MW0 */
3117 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3118 /* PW9 Output enable */
3119 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3123 static int patch_vt1709_6ch(struct hda_codec *codec)
3125 struct via_spec *spec;
3128 /* create a codec specific record */
3129 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3135 err = vt1709_parse_auto_config(codec);
3140 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3141 "Using genenic mode...\n");
3144 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3145 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3147 spec->stream_name_analog = "VT1709 Analog";
3148 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3149 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3151 spec->stream_name_digital = "VT1709 Digital";
3152 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3153 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3156 if (!spec->adc_nids && spec->input_mux) {
3157 spec->adc_nids = vt1709_adc_nids;
3158 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3159 get_mux_nids(codec);
3160 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3164 codec->patch_ops = via_patch_ops;
3166 codec->patch_ops.init = via_auto_init;
3167 codec->patch_ops.unsol_event = via_unsol_event;
3168 #ifdef CONFIG_SND_HDA_POWER_SAVE
3169 spec->loopback.amplist = vt1709_loopbacks;
3174 /* capture mixer elements */
3175 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3176 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3177 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3178 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3179 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3181 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3182 /* The multiple "Capture Source" controls confuse alsamixer
3183 * So call somewhat different..
3185 /* .name = "Capture Source", */
3186 .name = "Input Source",
3188 .info = via_mux_enum_info,
3189 .get = via_mux_enum_get,
3190 .put = via_mux_enum_put,
3195 * generic initialization of ADC, input mixers and output mixers
3197 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3199 * Unmute ADC0-1 and set the default input to mic-in
3201 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3202 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3205 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3208 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3209 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3210 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3211 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3212 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3213 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3216 * Set up output mixers
3218 /* set vol=0 to output mixers */
3219 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3220 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3221 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3223 /* Setup default input to PW4 */
3224 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3225 /* PW9 Output enable */
3226 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3227 /* PW10 Input enable */
3228 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3232 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3234 * Unmute ADC0-1 and set the default input to mic-in
3236 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3237 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3240 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3243 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3244 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3245 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3246 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3247 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3248 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3251 * Set up output mixers
3253 /* set vol=0 to output mixers */
3254 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3255 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3256 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3258 /* Setup default input of PW4 to MW0 */
3259 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3260 /* PW9 Output enable */
3261 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3262 /* PW10 Input enable */
3263 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3267 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3268 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3269 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3270 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3271 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3272 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3273 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3274 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3275 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3276 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3280 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3281 struct hda_codec *codec,
3282 struct snd_pcm_substream *substream)
3284 int idle = substream->pstr->substream_opened == 1
3285 && substream->ref_count == 0;
3287 analog_low_current_mode(codec, idle);
3291 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3295 .nid = 0x10, /* NID to query formats and rates */
3297 .open = via_playback_pcm_open,
3298 .prepare = via_playback_multi_pcm_prepare,
3299 .cleanup = via_playback_multi_pcm_cleanup,
3300 .close = via_pcm_open_close
3304 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3308 .nid = 0x10, /* NID to query formats and rates */
3310 .open = via_playback_pcm_open,
3311 .prepare = via_playback_multi_pcm_prepare,
3312 .cleanup = via_playback_multi_pcm_cleanup
3316 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3320 .nid = 0x13, /* NID to query formats and rates */
3322 .open = via_pcm_open_close,
3323 .prepare = via_capture_pcm_prepare,
3324 .cleanup = via_capture_pcm_cleanup,
3325 .close = via_pcm_open_close
3329 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3333 /* NID is set in via_build_pcms */
3335 .open = via_dig_playback_pcm_open,
3336 .close = via_dig_playback_pcm_close,
3337 .prepare = via_dig_playback_pcm_prepare,
3338 .cleanup = via_dig_playback_pcm_cleanup
3342 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3348 /* fill in the dac_nids table from the parsed pin configuration */
3349 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3350 const struct auto_pin_cfg *cfg)
3355 spec->multiout.num_dacs = cfg->line_outs;
3357 spec->multiout.dac_nids = spec->private_dac_nids;
3359 for (i = 0; i < 4; i++) {
3360 nid = cfg->line_out_pins[i];
3362 /* config dac list */
3364 case AUTO_SEQ_FRONT:
3365 spec->multiout.dac_nids[i] = 0x10;
3367 case AUTO_SEQ_CENLFE:
3368 spec->multiout.dac_nids[i] = 0x24;
3370 case AUTO_SEQ_SURROUND:
3371 spec->multiout.dac_nids[i] = 0x11;
3374 spec->multiout.dac_nids[i] = 0x25;
3383 /* add playback controls from the parsed DAC table */
3384 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3385 const struct auto_pin_cfg *cfg)
3388 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3389 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3390 hda_nid_t nid, nid_vol = 0;
3393 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3394 nid = cfg->line_out_pins[i];
3399 nid_vol = nid_vols[i];
3401 if (i == AUTO_SEQ_CENLFE) {
3403 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3404 "Center Playback Volume",
3405 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3409 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3410 "LFE Playback Volume",
3411 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3415 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3416 "Center Playback Switch",
3417 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3421 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3422 "LFE Playback Switch",
3423 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3427 } else if (i == AUTO_SEQ_FRONT) {
3428 /* add control to mixer index 0 */
3429 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3430 "Master Front Playback Volume",
3431 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3435 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3436 "Master Front Playback Switch",
3437 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3442 /* add control to PW3 */
3443 sprintf(name, "%s Playback Volume", chname[i]);
3444 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3445 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3449 sprintf(name, "%s Playback Switch", chname[i]);
3450 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3451 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3456 sprintf(name, "%s Playback Volume", chname[i]);
3457 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3458 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3462 sprintf(name, "%s Playback Switch", chname[i]);
3463 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3464 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3474 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3481 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3482 spec->hp_independent_mode_index = 1;
3484 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3485 "Headphone Playback Volume",
3486 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3489 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3490 "Headphone Playback Switch",
3491 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3495 create_hp_imux(spec);
3500 /* create playback/capture controls for input pins */
3501 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
3502 const struct auto_pin_cfg *cfg)
3504 static char *labels[] = {
3505 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3507 struct hda_input_mux *imux = &spec->private_imux[0];
3508 int i, err, idx = 0;
3510 /* for internal loopback recording select */
3511 imux->items[imux->num_items].label = "Stereo Mixer";
3512 imux->items[imux->num_items].index = idx;
3515 for (i = 0; i < AUTO_PIN_LAST; i++) {
3516 if (!cfg->input_pins[i])
3519 switch (cfg->input_pins[i]) {
3520 case 0x1a: /* Mic */
3524 case 0x1b: /* Line In */
3528 case 0x1e: /* Front Mic */
3536 err = via_new_analog_input(spec, labels[i], idx, 0x16);
3539 imux->items[imux->num_items].label = labels[i];
3540 imux->items[imux->num_items].index = idx;
3546 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3548 struct via_spec *spec = codec->spec;
3551 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3554 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3557 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3558 return 0; /* can't find valid BIOS pin config */
3560 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3563 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3566 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
3570 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3572 if (spec->autocfg.dig_outs)
3573 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3574 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3575 if (spec->autocfg.dig_in_pin)
3576 spec->dig_in_nid = VT1708B_DIGIN_NID;
3578 if (spec->kctls.list)
3579 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3581 spec->input_mux = &spec->private_imux[0];
3584 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3586 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
3590 #ifdef CONFIG_SND_HDA_POWER_SAVE
3591 static struct hda_amp_list vt1708B_loopbacks[] = {
3592 { 0x16, HDA_INPUT, 1 },
3593 { 0x16, HDA_INPUT, 2 },
3594 { 0x16, HDA_INPUT, 3 },
3595 { 0x16, HDA_INPUT, 4 },
3599 static int patch_vt1708S(struct hda_codec *codec);
3600 static int patch_vt1708B_8ch(struct hda_codec *codec)
3602 struct via_spec *spec;
3605 if (get_codec_type(codec) == VT1708BCE)
3606 return patch_vt1708S(codec);
3607 /* create a codec specific record */
3608 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3614 /* automatic parse from the BIOS config */
3615 err = vt1708B_parse_auto_config(codec);
3620 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3621 "from BIOS. Using genenic mode...\n");
3624 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3625 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3627 spec->stream_name_analog = "VT1708B Analog";
3628 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3629 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3631 spec->stream_name_digital = "VT1708B Digital";
3632 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3633 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3635 if (!spec->adc_nids && spec->input_mux) {
3636 spec->adc_nids = vt1708B_adc_nids;
3637 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3638 get_mux_nids(codec);
3639 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3643 codec->patch_ops = via_patch_ops;
3645 codec->patch_ops.init = via_auto_init;
3646 codec->patch_ops.unsol_event = via_unsol_event;
3647 #ifdef CONFIG_SND_HDA_POWER_SAVE
3648 spec->loopback.amplist = vt1708B_loopbacks;
3654 static int patch_vt1708B_4ch(struct hda_codec *codec)
3656 struct via_spec *spec;
3659 /* create a codec specific record */
3660 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3666 /* automatic parse from the BIOS config */
3667 err = vt1708B_parse_auto_config(codec);
3672 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3673 "from BIOS. Using genenic mode...\n");
3676 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3677 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3679 spec->stream_name_analog = "VT1708B Analog";
3680 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3681 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3683 spec->stream_name_digital = "VT1708B Digital";
3684 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3685 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3687 if (!spec->adc_nids && spec->input_mux) {
3688 spec->adc_nids = vt1708B_adc_nids;
3689 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3690 get_mux_nids(codec);
3691 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3695 codec->patch_ops = via_patch_ops;
3697 codec->patch_ops.init = via_auto_init;
3698 codec->patch_ops.unsol_event = via_unsol_event;
3699 #ifdef CONFIG_SND_HDA_POWER_SAVE
3700 spec->loopback.amplist = vt1708B_loopbacks;
3706 /* Patch for VT1708S */
3708 /* capture mixer elements */
3709 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3710 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3711 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3712 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3713 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3714 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3715 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3718 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3719 /* The multiple "Capture Source" controls confuse alsamixer
3720 * So call somewhat different..
3722 /* .name = "Capture Source", */
3723 .name = "Input Source",
3725 .info = via_mux_enum_info,
3726 .get = via_mux_enum_get,
3727 .put = via_mux_enum_put,
3732 static struct hda_verb vt1708S_volume_init_verbs[] = {
3733 /* Unmute ADC0-1 and set the default input to mic-in */
3734 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3735 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3737 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3738 * analog-loopback mixer widget */
3739 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3740 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3741 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3742 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3743 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3744 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3746 /* Setup default input of PW4 to MW0 */
3747 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3748 /* PW9, PW10 Output enable */
3749 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3750 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3751 /* Enable Mic Boost Volume backdoor */
3753 /* don't bybass mixer */
3758 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3759 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3760 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3761 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3762 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3763 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3764 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3765 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3766 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3767 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3771 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3775 .nid = 0x10, /* NID to query formats and rates */
3777 .open = via_playback_pcm_open,
3778 .prepare = via_playback_multi_pcm_prepare,
3779 .cleanup = via_playback_multi_pcm_cleanup,
3780 .close = via_pcm_open_close
3784 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3788 .nid = 0x13, /* NID to query formats and rates */
3790 .open = via_pcm_open_close,
3791 .prepare = via_capture_pcm_prepare,
3792 .cleanup = via_capture_pcm_cleanup,
3793 .close = via_pcm_open_close
3797 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3801 /* NID is set in via_build_pcms */
3803 .open = via_dig_playback_pcm_open,
3804 .close = via_dig_playback_pcm_close,
3805 .prepare = via_dig_playback_pcm_prepare,
3806 .cleanup = via_dig_playback_pcm_cleanup
3810 /* fill in the dac_nids table from the parsed pin configuration */
3811 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3812 const struct auto_pin_cfg *cfg)
3817 spec->multiout.num_dacs = cfg->line_outs;
3819 spec->multiout.dac_nids = spec->private_dac_nids;
3821 for (i = 0; i < 4; i++) {
3822 nid = cfg->line_out_pins[i];
3824 /* config dac list */
3826 case AUTO_SEQ_FRONT:
3827 spec->multiout.dac_nids[i] = 0x10;
3829 case AUTO_SEQ_CENLFE:
3830 spec->multiout.dac_nids[i] = 0x24;
3832 case AUTO_SEQ_SURROUND:
3833 spec->multiout.dac_nids[i] = 0x11;
3836 spec->multiout.dac_nids[i] = 0x25;
3845 /* add playback controls from the parsed DAC table */
3846 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3847 const struct auto_pin_cfg *cfg)
3850 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3851 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3852 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3853 hda_nid_t nid, nid_vol, nid_mute;
3856 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3857 nid = cfg->line_out_pins[i];
3862 nid_vol = nid_vols[i];
3863 nid_mute = nid_mutes[i];
3865 if (i == AUTO_SEQ_CENLFE) {
3867 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3868 "Center Playback Volume",
3869 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3873 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3874 "LFE Playback Volume",
3875 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3879 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3880 "Center Playback Switch",
3881 HDA_COMPOSE_AMP_VAL(nid_mute,
3886 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3887 "LFE Playback Switch",
3888 HDA_COMPOSE_AMP_VAL(nid_mute,
3893 } else if (i == AUTO_SEQ_FRONT) {
3894 /* add control to mixer index 0 */
3895 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3896 "Master Front Playback Volume",
3897 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3901 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3902 "Master Front Playback Switch",
3903 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3909 sprintf(name, "%s Playback Volume", chname[i]);
3910 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3911 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3915 sprintf(name, "%s Playback Switch", chname[i]);
3916 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3917 HDA_COMPOSE_AMP_VAL(nid_mute,
3923 sprintf(name, "%s Playback Volume", chname[i]);
3924 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3925 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3929 sprintf(name, "%s Playback Switch", chname[i]);
3930 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3931 HDA_COMPOSE_AMP_VAL(nid_mute,
3942 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3949 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3950 spec->hp_independent_mode_index = 1;
3952 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3953 "Headphone Playback Volume",
3954 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3958 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3959 "Headphone Playback Switch",
3960 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3964 create_hp_imux(spec);
3969 /* create playback/capture controls for input pins */
3970 static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
3971 const struct auto_pin_cfg *cfg)
3973 static char *labels[] = {
3974 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3976 struct hda_input_mux *imux = &spec->private_imux[0];
3977 int i, err, idx = 0;
3979 /* for internal loopback recording select */
3980 imux->items[imux->num_items].label = "Stereo Mixer";
3981 imux->items[imux->num_items].index = 5;
3984 for (i = 0; i < AUTO_PIN_LAST; i++) {
3985 if (!cfg->input_pins[i])
3988 switch (cfg->input_pins[i]) {
3989 case 0x1a: /* Mic */
3993 case 0x1b: /* Line In */
3997 case 0x1e: /* Front Mic */
4005 err = via_new_analog_input(spec, labels[i], idx, 0x16);
4008 imux->items[imux->num_items].label = labels[i];
4009 imux->items[imux->num_items].index = idx-1;
4015 /* fill out digital output widgets; one for master and one for slave outputs */
4016 static void fill_dig_outs(struct hda_codec *codec)
4018 struct via_spec *spec = codec->spec;
4021 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4025 nid = spec->autocfg.dig_out_pins[i];
4028 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4031 if (!spec->multiout.dig_out_nid)
4032 spec->multiout.dig_out_nid = nid;
4034 spec->slave_dig_outs[0] = nid;
4035 break; /* at most two dig outs */
4040 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4042 struct via_spec *spec = codec->spec;
4045 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4048 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4051 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4052 return 0; /* can't find valid BIOS pin config */
4054 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4057 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4060 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4064 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4066 fill_dig_outs(codec);
4068 if (spec->kctls.list)
4069 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4071 spec->input_mux = &spec->private_imux[0];
4074 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4076 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4080 #ifdef CONFIG_SND_HDA_POWER_SAVE
4081 static struct hda_amp_list vt1708S_loopbacks[] = {
4082 { 0x16, HDA_INPUT, 1 },
4083 { 0x16, HDA_INPUT, 2 },
4084 { 0x16, HDA_INPUT, 3 },
4085 { 0x16, HDA_INPUT, 4 },
4090 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4091 int offset, int num_steps, int step_size)
4093 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4094 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4095 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4096 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4097 (0 << AC_AMPCAP_MUTE_SHIFT));
4100 static int patch_vt1708S(struct hda_codec *codec)
4102 struct via_spec *spec;
4105 /* create a codec specific record */
4106 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4112 /* automatic parse from the BIOS config */
4113 err = vt1708S_parse_auto_config(codec);
4118 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4119 "from BIOS. Using genenic mode...\n");
4122 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4123 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4125 if (codec->vendor_id == 0x11060440)
4126 spec->stream_name_analog = "VT1818S Analog";
4128 spec->stream_name_analog = "VT1708S Analog";
4129 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4130 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4132 if (codec->vendor_id == 0x11060440)
4133 spec->stream_name_digital = "VT1818S Digital";
4135 spec->stream_name_digital = "VT1708S Digital";
4136 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4138 if (!spec->adc_nids && spec->input_mux) {
4139 spec->adc_nids = vt1708S_adc_nids;
4140 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4141 get_mux_nids(codec);
4142 override_mic_boost(codec, 0x1a, 0, 3, 40);
4143 override_mic_boost(codec, 0x1e, 0, 3, 40);
4144 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4148 codec->patch_ops = via_patch_ops;
4150 codec->patch_ops.init = via_auto_init;
4151 codec->patch_ops.unsol_event = via_unsol_event;
4152 #ifdef CONFIG_SND_HDA_POWER_SAVE
4153 spec->loopback.amplist = vt1708S_loopbacks;
4156 /* correct names for VT1708BCE */
4157 if (get_codec_type(codec) == VT1708BCE) {
4158 kfree(codec->chip_name);
4159 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4160 snprintf(codec->bus->card->mixername,
4161 sizeof(codec->bus->card->mixername),
4162 "%s %s", codec->vendor_name, codec->chip_name);
4163 spec->stream_name_analog = "VT1708BCE Analog";
4164 spec->stream_name_digital = "VT1708BCE Digital";
4169 /* Patch for VT1702 */
4171 /* capture mixer elements */
4172 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4173 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4174 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4175 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4176 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4177 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4178 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4179 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4182 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4183 /* The multiple "Capture Source" controls confuse alsamixer
4184 * So call somewhat different..
4186 /* .name = "Capture Source", */
4187 .name = "Input Source",
4189 .info = via_mux_enum_info,
4190 .get = via_mux_enum_get,
4191 .put = via_mux_enum_put,
4196 static struct hda_verb vt1702_volume_init_verbs[] = {
4198 * Unmute ADC0-1 and set the default input to mic-in
4200 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4201 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4202 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4205 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4208 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4209 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4210 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4211 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4212 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4213 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4215 /* Setup default input of PW4 to MW0 */
4216 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4217 /* PW6 PW7 Output enable */
4218 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4219 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4227 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4228 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4229 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4230 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4231 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4232 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4233 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4237 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4241 .nid = 0x10, /* NID to query formats and rates */
4243 .open = via_playback_pcm_open,
4244 .prepare = via_playback_multi_pcm_prepare,
4245 .cleanup = via_playback_multi_pcm_cleanup,
4246 .close = via_pcm_open_close
4250 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4254 .nid = 0x12, /* NID to query formats and rates */
4256 .open = via_pcm_open_close,
4257 .prepare = via_capture_pcm_prepare,
4258 .cleanup = via_capture_pcm_cleanup,
4259 .close = via_pcm_open_close
4263 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4267 /* NID is set in via_build_pcms */
4269 .open = via_dig_playback_pcm_open,
4270 .close = via_dig_playback_pcm_close,
4271 .prepare = via_dig_playback_pcm_prepare,
4272 .cleanup = via_dig_playback_pcm_cleanup
4276 /* fill in the dac_nids table from the parsed pin configuration */
4277 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4278 const struct auto_pin_cfg *cfg)
4280 spec->multiout.num_dacs = 1;
4281 spec->multiout.dac_nids = spec->private_dac_nids;
4283 if (cfg->line_out_pins[0]) {
4284 /* config dac list */
4285 spec->multiout.dac_nids[0] = 0x10;
4291 /* add playback controls from the parsed DAC table */
4292 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4293 const struct auto_pin_cfg *cfg)
4297 if (!cfg->line_out_pins[0])
4300 /* add control to mixer index 0 */
4301 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4302 "Master Front Playback Volume",
4303 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4306 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4307 "Master Front Playback Switch",
4308 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4313 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4314 "Front Playback Volume",
4315 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4318 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4319 "Front Playback Switch",
4320 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4327 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4330 struct hda_input_mux *imux;
4331 static const char *texts[] = { "ON", "OFF", NULL};
4334 spec->multiout.hp_nid = 0x1D;
4335 spec->hp_independent_mode_index = 0;
4337 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4338 "Headphone Playback Volume",
4339 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4343 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4344 "Headphone Playback Switch",
4345 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4349 imux = &spec->private_imux[1];
4351 /* for hp mode select */
4353 while (texts[i] != NULL) {
4354 imux->items[imux->num_items].label = texts[i];
4355 imux->items[imux->num_items].index = i;
4360 spec->hp_mux = &spec->private_imux[1];
4364 /* create playback/capture controls for input pins */
4365 static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
4366 const struct auto_pin_cfg *cfg)
4368 static char *labels[] = {
4369 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4371 struct hda_input_mux *imux = &spec->private_imux[0];
4372 int i, err, idx = 0;
4374 /* for internal loopback recording select */
4375 imux->items[imux->num_items].label = "Stereo Mixer";
4376 imux->items[imux->num_items].index = 3;
4379 for (i = 0; i < AUTO_PIN_LAST; i++) {
4380 if (!cfg->input_pins[i])
4383 switch (cfg->input_pins[i]) {
4384 case 0x14: /* Mic */
4388 case 0x15: /* Line In */
4392 case 0x18: /* Front Mic */
4396 err = via_new_analog_input(spec, labels[i], idx, 0x1A);
4399 imux->items[imux->num_items].label = labels[i];
4400 imux->items[imux->num_items].index = idx-1;
4406 static int vt1702_parse_auto_config(struct hda_codec *codec)
4408 struct via_spec *spec = codec->spec;
4411 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4414 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4417 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4418 return 0; /* can't find valid BIOS pin config */
4420 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4423 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4426 /* limit AA path volume to 0 dB */
4427 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4428 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4429 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4430 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4431 (1 << AC_AMPCAP_MUTE_SHIFT));
4432 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
4436 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4438 fill_dig_outs(codec);
4440 if (spec->kctls.list)
4441 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4443 spec->input_mux = &spec->private_imux[0];
4446 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4451 #ifdef CONFIG_SND_HDA_POWER_SAVE
4452 static struct hda_amp_list vt1702_loopbacks[] = {
4453 { 0x1A, HDA_INPUT, 1 },
4454 { 0x1A, HDA_INPUT, 2 },
4455 { 0x1A, HDA_INPUT, 3 },
4456 { 0x1A, HDA_INPUT, 4 },
4461 static int patch_vt1702(struct hda_codec *codec)
4463 struct via_spec *spec;
4466 /* create a codec specific record */
4467 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4473 /* automatic parse from the BIOS config */
4474 err = vt1702_parse_auto_config(codec);
4479 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4480 "from BIOS. Using genenic mode...\n");
4483 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4484 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4486 spec->stream_name_analog = "VT1702 Analog";
4487 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4488 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4490 spec->stream_name_digital = "VT1702 Digital";
4491 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4493 if (!spec->adc_nids && spec->input_mux) {
4494 spec->adc_nids = vt1702_adc_nids;
4495 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4496 get_mux_nids(codec);
4497 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4501 codec->patch_ops = via_patch_ops;
4503 codec->patch_ops.init = via_auto_init;
4504 codec->patch_ops.unsol_event = via_unsol_event;
4505 #ifdef CONFIG_SND_HDA_POWER_SAVE
4506 spec->loopback.amplist = vt1702_loopbacks;
4512 /* Patch for VT1718S */
4514 /* capture mixer elements */
4515 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4516 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4517 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4518 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4519 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4520 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4521 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4524 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4525 /* The multiple "Capture Source" controls confuse alsamixer
4526 * So call somewhat different..
4528 .name = "Input Source",
4530 .info = via_mux_enum_info,
4531 .get = via_mux_enum_get,
4532 .put = via_mux_enum_put,
4537 static struct hda_verb vt1718S_volume_init_verbs[] = {
4539 * Unmute ADC0-1 and set the default input to mic-in
4541 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4542 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4545 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4548 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4549 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4550 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4551 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4552 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4553 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4555 /* Setup default input of Front HP to MW9 */
4556 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4557 /* PW9 PW10 Output enable */
4558 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4559 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4560 /* PW11 Input enable */
4561 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4562 /* Enable Boost Volume backdoor */
4564 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4565 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4566 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4567 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4568 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4569 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4570 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4571 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4572 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4573 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4574 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4575 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4576 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4577 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4578 /* Unmute MW4's index 0 */
4579 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4584 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4585 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4586 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4587 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4588 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4589 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4590 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4591 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4592 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4593 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4597 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4601 .nid = 0x8, /* NID to query formats and rates */
4603 .open = via_playback_pcm_open,
4604 .prepare = via_playback_multi_pcm_prepare,
4605 .cleanup = via_playback_multi_pcm_cleanup,
4606 .close = via_pcm_open_close,
4610 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4614 .nid = 0x10, /* NID to query formats and rates */
4616 .open = via_pcm_open_close,
4617 .prepare = via_capture_pcm_prepare,
4618 .cleanup = via_capture_pcm_cleanup,
4619 .close = via_pcm_open_close,
4623 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4627 /* NID is set in via_build_pcms */
4629 .open = via_dig_playback_pcm_open,
4630 .close = via_dig_playback_pcm_close,
4631 .prepare = via_dig_playback_pcm_prepare,
4632 .cleanup = via_dig_playback_pcm_cleanup
4636 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4642 /* fill in the dac_nids table from the parsed pin configuration */
4643 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4644 const struct auto_pin_cfg *cfg)
4649 spec->multiout.num_dacs = cfg->line_outs;
4651 spec->multiout.dac_nids = spec->private_dac_nids;
4653 for (i = 0; i < 4; i++) {
4654 nid = cfg->line_out_pins[i];
4656 /* config dac list */
4658 case AUTO_SEQ_FRONT:
4659 spec->multiout.dac_nids[i] = 0x8;
4661 case AUTO_SEQ_CENLFE:
4662 spec->multiout.dac_nids[i] = 0xa;
4664 case AUTO_SEQ_SURROUND:
4665 spec->multiout.dac_nids[i] = 0x9;
4668 spec->multiout.dac_nids[i] = 0xb;
4677 /* add playback controls from the parsed DAC table */
4678 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4679 const struct auto_pin_cfg *cfg)
4682 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4683 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4684 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4685 hda_nid_t nid, nid_vol, nid_mute = 0;
4688 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4689 nid = cfg->line_out_pins[i];
4693 nid_vol = nid_vols[i];
4694 nid_mute = nid_mutes[i];
4696 if (i == AUTO_SEQ_CENLFE) {
4698 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4699 "Center Playback Volume",
4700 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4704 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4705 "LFE Playback Volume",
4706 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4710 err = via_add_control(
4711 spec, VIA_CTL_WIDGET_MUTE,
4712 "Center Playback Switch",
4713 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4717 err = via_add_control(
4718 spec, VIA_CTL_WIDGET_MUTE,
4719 "LFE Playback Switch",
4720 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4724 } else if (i == AUTO_SEQ_FRONT) {
4726 sprintf(name, "%s Playback Volume", chname[i]);
4727 err = via_add_control(
4728 spec, VIA_CTL_WIDGET_VOL, name,
4729 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4732 sprintf(name, "%s Playback Switch", chname[i]);
4733 err = via_add_control(
4734 spec, VIA_CTL_WIDGET_MUTE, name,
4735 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4740 sprintf(name, "%s Playback Volume", chname[i]);
4741 err = via_add_control(
4742 spec, VIA_CTL_WIDGET_VOL, name,
4743 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4746 sprintf(name, "%s Playback Switch", chname[i]);
4747 err = via_add_control(
4748 spec, VIA_CTL_WIDGET_MUTE, name,
4749 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4758 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4765 spec->multiout.hp_nid = 0xc; /* AOW4 */
4766 spec->hp_independent_mode_index = 1;
4768 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4769 "Headphone Playback Volume",
4770 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4774 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4775 "Headphone Playback Switch",
4776 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4780 create_hp_imux(spec);
4784 /* create playback/capture controls for input pins */
4785 static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4786 const struct auto_pin_cfg *cfg)
4788 static char *labels[] = {
4789 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4791 struct hda_input_mux *imux = &spec->private_imux[0];
4792 int i, err, idx = 0;
4794 /* for internal loopback recording select */
4795 imux->items[imux->num_items].label = "Stereo Mixer";
4796 imux->items[imux->num_items].index = 5;
4799 for (i = 0; i < AUTO_PIN_LAST; i++) {
4800 if (!cfg->input_pins[i])
4803 switch (cfg->input_pins[i]) {
4804 case 0x2b: /* Mic */
4808 case 0x2a: /* Line In */
4812 case 0x29: /* Front Mic */
4820 err = via_new_analog_input(spec, labels[i], idx, 0x21);
4823 imux->items[imux->num_items].label = labels[i];
4824 imux->items[imux->num_items].index = idx;
4830 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4832 struct via_spec *spec = codec->spec;
4835 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4839 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4842 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4843 return 0; /* can't find valid BIOS pin config */
4845 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4848 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4851 err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4855 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4857 fill_dig_outs(codec);
4859 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4860 spec->dig_in_nid = 0x13;
4862 if (spec->kctls.list)
4863 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4865 spec->input_mux = &spec->private_imux[0];
4868 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4870 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4875 #ifdef CONFIG_SND_HDA_POWER_SAVE
4876 static struct hda_amp_list vt1718S_loopbacks[] = {
4877 { 0x21, HDA_INPUT, 1 },
4878 { 0x21, HDA_INPUT, 2 },
4879 { 0x21, HDA_INPUT, 3 },
4880 { 0x21, HDA_INPUT, 4 },
4885 static int patch_vt1718S(struct hda_codec *codec)
4887 struct via_spec *spec;
4890 /* create a codec specific record */
4891 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4897 /* automatic parse from the BIOS config */
4898 err = vt1718S_parse_auto_config(codec);
4903 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4904 "from BIOS. Using genenic mode...\n");
4907 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4908 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4910 if (codec->vendor_id == 0x11060441)
4911 spec->stream_name_analog = "VT2020 Analog";
4912 else if (codec->vendor_id == 0x11064441)
4913 spec->stream_name_analog = "VT1828S Analog";
4915 spec->stream_name_analog = "VT1718S Analog";
4916 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4917 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4919 if (codec->vendor_id == 0x11060441)
4920 spec->stream_name_digital = "VT2020 Digital";
4921 else if (codec->vendor_id == 0x11064441)
4922 spec->stream_name_digital = "VT1828S Digital";
4924 spec->stream_name_digital = "VT1718S Digital";
4925 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4926 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4927 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4929 if (!spec->adc_nids && spec->input_mux) {
4930 spec->adc_nids = vt1718S_adc_nids;
4931 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4932 get_mux_nids(codec);
4933 override_mic_boost(codec, 0x2b, 0, 3, 40);
4934 override_mic_boost(codec, 0x29, 0, 3, 40);
4935 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4939 codec->patch_ops = via_patch_ops;
4941 codec->patch_ops.init = via_auto_init;
4942 codec->patch_ops.unsol_event = via_unsol_event;
4944 #ifdef CONFIG_SND_HDA_POWER_SAVE
4945 spec->loopback.amplist = vt1718S_loopbacks;
4951 /* Patch for VT1716S */
4953 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4954 struct snd_ctl_elem_info *uinfo)
4956 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4958 uinfo->value.integer.min = 0;
4959 uinfo->value.integer.max = 1;
4963 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4964 struct snd_ctl_elem_value *ucontrol)
4966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4969 index = snd_hda_codec_read(codec, 0x26, 0,
4970 AC_VERB_GET_CONNECT_SEL, 0);
4972 *ucontrol->value.integer.value = index;
4977 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4978 struct snd_ctl_elem_value *ucontrol)
4980 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4981 struct via_spec *spec = codec->spec;
4982 int index = *ucontrol->value.integer.value;
4984 snd_hda_codec_write(codec, 0x26, 0,
4985 AC_VERB_SET_CONNECT_SEL, index);
4986 spec->dmic_enabled = index;
4987 set_jack_power_state(codec);
4992 /* capture mixer elements */
4993 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4994 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4995 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4996 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4997 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4998 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4999 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5002 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5003 .name = "Input Source",
5005 .info = via_mux_enum_info,
5006 .get = via_mux_enum_get,
5007 .put = via_mux_enum_put,
5012 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
5013 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
5015 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5016 .name = "Digital Mic Capture Switch",
5018 .info = vt1716s_dmic_info,
5019 .get = vt1716s_dmic_get,
5020 .put = vt1716s_dmic_put,
5026 /* mono-out mixer elements */
5027 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
5028 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
5032 static struct hda_verb vt1716S_volume_init_verbs[] = {
5034 * Unmute ADC0-1 and set the default input to mic-in
5036 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5037 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5040 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5043 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5044 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5045 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5046 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5047 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5048 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5050 /* MUX Indices: Stereo Mixer = 5 */
5051 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
5053 /* Setup default input of PW4 to MW0 */
5054 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
5056 /* Setup default input of SW1 as MW0 */
5057 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5059 /* Setup default input of SW4 as AOW0 */
5060 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5062 /* PW9 PW10 Output enable */
5063 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5064 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5066 /* Unmute SW1, PW12 */
5067 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5068 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5069 /* PW12 Output enable */
5070 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5071 /* Enable Boost Volume backdoor */
5073 /* don't bybass mixer */
5075 /* Enable mono output */
5081 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5082 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5083 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5084 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5085 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5086 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5087 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5088 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5089 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5090 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5094 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5098 .nid = 0x10, /* NID to query formats and rates */
5100 .open = via_playback_pcm_open,
5101 .prepare = via_playback_multi_pcm_prepare,
5102 .cleanup = via_playback_multi_pcm_cleanup,
5103 .close = via_pcm_open_close,
5107 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5111 .nid = 0x13, /* NID to query formats and rates */
5113 .open = via_pcm_open_close,
5114 .prepare = via_capture_pcm_prepare,
5115 .cleanup = via_capture_pcm_cleanup,
5116 .close = via_pcm_open_close,
5120 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5124 /* NID is set in via_build_pcms */
5126 .open = via_dig_playback_pcm_open,
5127 .close = via_dig_playback_pcm_close,
5128 .prepare = via_dig_playback_pcm_prepare,
5129 .cleanup = via_dig_playback_pcm_cleanup
5133 /* fill in the dac_nids table from the parsed pin configuration */
5134 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5135 const struct auto_pin_cfg *cfg)
5139 spec->multiout.num_dacs = cfg->line_outs;
5141 spec->multiout.dac_nids = spec->private_dac_nids;
5143 for (i = 0; i < 3; i++) {
5144 nid = cfg->line_out_pins[i];
5146 /* config dac list */
5148 case AUTO_SEQ_FRONT:
5149 spec->multiout.dac_nids[i] = 0x10;
5151 case AUTO_SEQ_CENLFE:
5152 spec->multiout.dac_nids[i] = 0x25;
5154 case AUTO_SEQ_SURROUND:
5155 spec->multiout.dac_nids[i] = 0x11;
5164 /* add playback controls from the parsed DAC table */
5165 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5166 const struct auto_pin_cfg *cfg)
5169 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5170 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5171 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5172 hda_nid_t nid, nid_vol, nid_mute;
5175 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5176 nid = cfg->line_out_pins[i];
5181 nid_vol = nid_vols[i];
5182 nid_mute = nid_mutes[i];
5184 if (i == AUTO_SEQ_CENLFE) {
5185 err = via_add_control(
5186 spec, VIA_CTL_WIDGET_VOL,
5187 "Center Playback Volume",
5188 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5191 err = via_add_control(
5192 spec, VIA_CTL_WIDGET_VOL,
5193 "LFE Playback Volume",
5194 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5197 err = via_add_control(
5198 spec, VIA_CTL_WIDGET_MUTE,
5199 "Center Playback Switch",
5200 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5204 err = via_add_control(
5205 spec, VIA_CTL_WIDGET_MUTE,
5206 "LFE Playback Switch",
5207 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5211 } else if (i == AUTO_SEQ_FRONT) {
5213 err = via_add_control(
5214 spec, VIA_CTL_WIDGET_VOL,
5215 "Master Front Playback Volume",
5216 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5219 err = via_add_control(
5220 spec, VIA_CTL_WIDGET_MUTE,
5221 "Master Front Playback Switch",
5222 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5226 sprintf(name, "%s Playback Volume", chname[i]);
5227 err = via_add_control(
5228 spec, VIA_CTL_WIDGET_VOL, name,
5229 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5232 sprintf(name, "%s Playback Switch", chname[i]);
5233 err = via_add_control(
5234 spec, VIA_CTL_WIDGET_MUTE, name,
5235 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5240 sprintf(name, "%s Playback Volume", chname[i]);
5241 err = via_add_control(
5242 spec, VIA_CTL_WIDGET_VOL, name,
5243 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5246 sprintf(name, "%s Playback Switch", chname[i]);
5247 err = via_add_control(
5248 spec, VIA_CTL_WIDGET_MUTE, name,
5249 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5258 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5265 spec->multiout.hp_nid = 0x25; /* AOW3 */
5266 spec->hp_independent_mode_index = 1;
5268 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5269 "Headphone Playback Volume",
5270 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5274 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5275 "Headphone Playback Switch",
5276 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5280 create_hp_imux(spec);
5284 /* create playback/capture controls for input pins */
5285 static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5286 const struct auto_pin_cfg *cfg)
5288 static char *labels[] = {
5289 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5291 struct hda_input_mux *imux = &spec->private_imux[0];
5292 int i, err, idx = 0;
5294 /* for internal loopback recording select */
5295 imux->items[imux->num_items].label = "Stereo Mixer";
5296 imux->items[imux->num_items].index = 5;
5299 for (i = 0; i < AUTO_PIN_LAST; i++) {
5300 if (!cfg->input_pins[i])
5303 switch (cfg->input_pins[i]) {
5304 case 0x1a: /* Mic */
5308 case 0x1b: /* Line In */
5312 case 0x1e: /* Front Mic */
5320 err = via_new_analog_input(spec, labels[i], idx, 0x16);
5323 imux->items[imux->num_items].label = labels[i];
5324 imux->items[imux->num_items].index = idx-1;
5330 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5332 struct via_spec *spec = codec->spec;
5335 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5338 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5341 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5342 return 0; /* can't find valid BIOS pin config */
5344 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5347 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5350 err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
5354 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5356 fill_dig_outs(codec);
5358 if (spec->kctls.list)
5359 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5361 spec->input_mux = &spec->private_imux[0];
5364 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5366 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
5371 #ifdef CONFIG_SND_HDA_POWER_SAVE
5372 static struct hda_amp_list vt1716S_loopbacks[] = {
5373 { 0x16, HDA_INPUT, 1 },
5374 { 0x16, HDA_INPUT, 2 },
5375 { 0x16, HDA_INPUT, 3 },
5376 { 0x16, HDA_INPUT, 4 },
5381 static int patch_vt1716S(struct hda_codec *codec)
5383 struct via_spec *spec;
5386 /* create a codec specific record */
5387 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5393 /* automatic parse from the BIOS config */
5394 err = vt1716S_parse_auto_config(codec);
5399 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5400 "from BIOS. Using genenic mode...\n");
5403 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5404 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5406 spec->stream_name_analog = "VT1716S Analog";
5407 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5408 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5410 spec->stream_name_digital = "VT1716S Digital";
5411 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5413 if (!spec->adc_nids && spec->input_mux) {
5414 spec->adc_nids = vt1716S_adc_nids;
5415 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5416 get_mux_nids(codec);
5417 override_mic_boost(codec, 0x1a, 0, 3, 40);
5418 override_mic_boost(codec, 0x1e, 0, 3, 40);
5419 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5423 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5426 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5428 codec->patch_ops = via_patch_ops;
5430 codec->patch_ops.init = via_auto_init;
5431 codec->patch_ops.unsol_event = via_unsol_event;
5433 #ifdef CONFIG_SND_HDA_POWER_SAVE
5434 spec->loopback.amplist = vt1716S_loopbacks;
5442 /* capture mixer elements */
5443 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5444 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5445 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5446 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5447 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5448 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5449 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5452 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5453 /* The multiple "Capture Source" controls confuse alsamixer
5454 * So call somewhat different..
5456 /* .name = "Capture Source", */
5457 .name = "Input Source",
5459 .info = via_mux_enum_info,
5460 .get = via_mux_enum_get,
5461 .put = via_mux_enum_put,
5466 static struct hda_verb vt2002P_volume_init_verbs[] = {
5468 * Unmute ADC0-1 and set the default input to mic-in
5470 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5471 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5474 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5477 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5478 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5479 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5480 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5481 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5482 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5484 /* MUX Indices: Mic = 0 */
5485 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5486 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5488 /* PW9 Output enable */
5489 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5491 /* Enable Boost Volume backdoor */
5494 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5495 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5496 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5497 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5498 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5499 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5500 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5501 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5502 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5504 /* set MUX0/1/4/8 = 0 (AOW0) */
5505 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5506 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5507 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5508 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5510 /* set PW0 index=0 (MW0) */
5511 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5513 /* Enable AOW0 to MW9 */
5519 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5520 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5521 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5522 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5523 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5524 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5525 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5526 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5530 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5534 .nid = 0x8, /* NID to query formats and rates */
5536 .open = via_playback_pcm_open,
5537 .prepare = via_playback_multi_pcm_prepare,
5538 .cleanup = via_playback_multi_pcm_cleanup,
5539 .close = via_pcm_open_close,
5543 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5547 .nid = 0x10, /* NID to query formats and rates */
5549 .open = via_pcm_open_close,
5550 .prepare = via_capture_pcm_prepare,
5551 .cleanup = via_capture_pcm_cleanup,
5552 .close = via_pcm_open_close,
5556 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5560 /* NID is set in via_build_pcms */
5562 .open = via_dig_playback_pcm_open,
5563 .close = via_dig_playback_pcm_close,
5564 .prepare = via_dig_playback_pcm_prepare,
5565 .cleanup = via_dig_playback_pcm_cleanup
5569 /* fill in the dac_nids table from the parsed pin configuration */
5570 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5571 const struct auto_pin_cfg *cfg)
5573 spec->multiout.num_dacs = 1;
5574 spec->multiout.dac_nids = spec->private_dac_nids;
5575 if (cfg->line_out_pins[0])
5576 spec->multiout.dac_nids[0] = 0x8;
5580 /* add playback controls from the parsed DAC table */
5581 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5582 const struct auto_pin_cfg *cfg)
5586 if (!cfg->line_out_pins[0])
5590 /* Line-Out: PortE */
5591 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5592 "Master Front Playback Volume",
5593 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5596 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5597 "Master Front Playback Switch",
5598 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5605 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5612 spec->multiout.hp_nid = 0x9;
5613 spec->hp_independent_mode_index = 1;
5615 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5616 "Headphone Playback Volume",
5617 HDA_COMPOSE_AMP_VAL(
5618 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5622 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5623 "Headphone Playback Switch",
5624 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5628 create_hp_imux(spec);
5632 /* create playback/capture controls for input pins */
5633 static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
5634 const struct auto_pin_cfg *cfg)
5636 static char *labels[] = {
5637 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5639 struct hda_input_mux *imux = &spec->private_imux[0];
5640 int i, err, idx = 0;
5642 for (i = 0; i < AUTO_PIN_LAST; i++) {
5643 if (!cfg->input_pins[i])
5646 switch (cfg->input_pins[i]) {
5647 case 0x2b: /* Mic */
5651 case 0x2a: /* Line In */
5655 case 0x29: /* Front Mic */
5659 err = via_new_analog_input(spec, labels[i], idx, 0x21);
5662 imux->items[imux->num_items].label = labels[i];
5663 imux->items[imux->num_items].index = idx;
5667 /* build volume/mute control of loopback */
5668 err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
5672 /* for internal loopback recording select */
5673 imux->items[imux->num_items].label = "Stereo Mixer";
5674 imux->items[imux->num_items].index = 3;
5677 /* for digital mic select */
5678 imux->items[imux->num_items].label = "Digital Mic";
5679 imux->items[imux->num_items].index = 4;
5685 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5687 struct via_spec *spec = codec->spec;
5691 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5695 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5699 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5700 return 0; /* can't find valid BIOS pin config */
5702 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5705 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5708 err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
5712 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5714 fill_dig_outs(codec);
5716 if (spec->kctls.list)
5717 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5719 spec->input_mux = &spec->private_imux[0];
5722 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5727 #ifdef CONFIG_SND_HDA_POWER_SAVE
5728 static struct hda_amp_list vt2002P_loopbacks[] = {
5729 { 0x21, HDA_INPUT, 0 },
5730 { 0x21, HDA_INPUT, 1 },
5731 { 0x21, HDA_INPUT, 2 },
5737 /* patch for vt2002P */
5738 static int patch_vt2002P(struct hda_codec *codec)
5740 struct via_spec *spec;
5743 /* create a codec specific record */
5744 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5750 /* automatic parse from the BIOS config */
5751 err = vt2002P_parse_auto_config(codec);
5756 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5757 "from BIOS. Using genenic mode...\n");
5760 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5761 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5763 spec->stream_name_analog = "VT2002P Analog";
5764 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5765 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5767 spec->stream_name_digital = "VT2002P Digital";
5768 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5770 if (!spec->adc_nids && spec->input_mux) {
5771 spec->adc_nids = vt2002P_adc_nids;
5772 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5773 get_mux_nids(codec);
5774 override_mic_boost(codec, 0x2b, 0, 3, 40);
5775 override_mic_boost(codec, 0x29, 0, 3, 40);
5776 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5780 codec->patch_ops = via_patch_ops;
5782 codec->patch_ops.init = via_auto_init;
5783 codec->patch_ops.unsol_event = via_unsol_event;
5785 #ifdef CONFIG_SND_HDA_POWER_SAVE
5786 spec->loopback.amplist = vt2002P_loopbacks;
5794 /* capture mixer elements */
5795 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5796 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5797 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5798 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5799 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5800 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5801 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5805 /* The multiple "Capture Source" controls confuse alsamixer
5806 * So call somewhat different..
5808 .name = "Input Source",
5810 .info = via_mux_enum_info,
5811 .get = via_mux_enum_get,
5812 .put = via_mux_enum_put,
5817 static struct hda_verb vt1812_volume_init_verbs[] = {
5819 * Unmute ADC0-1 and set the default input to mic-in
5821 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5822 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5825 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5828 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5829 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5830 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5831 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5832 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5833 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5835 /* MUX Indices: Mic = 0 */
5836 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5837 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5839 /* PW9 Output enable */
5840 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5842 /* Enable Boost Volume backdoor */
5845 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5846 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5847 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5848 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5849 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5850 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5851 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5852 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5853 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5854 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5855 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5857 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5858 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5859 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5860 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5861 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5862 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5864 /* Enable AOW0 to MW9 */
5870 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5871 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5872 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5873 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5874 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5875 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5876 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5877 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5878 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5882 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5886 .nid = 0x8, /* NID to query formats and rates */
5888 .open = via_playback_pcm_open,
5889 .prepare = via_playback_multi_pcm_prepare,
5890 .cleanup = via_playback_multi_pcm_cleanup,
5891 .close = via_pcm_open_close,
5895 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5899 .nid = 0x10, /* NID to query formats and rates */
5901 .open = via_pcm_open_close,
5902 .prepare = via_capture_pcm_prepare,
5903 .cleanup = via_capture_pcm_cleanup,
5904 .close = via_pcm_open_close,
5908 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5912 /* NID is set in via_build_pcms */
5914 .open = via_dig_playback_pcm_open,
5915 .close = via_dig_playback_pcm_close,
5916 .prepare = via_dig_playback_pcm_prepare,
5917 .cleanup = via_dig_playback_pcm_cleanup
5920 /* fill in the dac_nids table from the parsed pin configuration */
5921 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5922 const struct auto_pin_cfg *cfg)
5924 spec->multiout.num_dacs = 1;
5925 spec->multiout.dac_nids = spec->private_dac_nids;
5926 if (cfg->line_out_pins[0])
5927 spec->multiout.dac_nids[0] = 0x8;
5932 /* add playback controls from the parsed DAC table */
5933 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5934 const struct auto_pin_cfg *cfg)
5938 if (!cfg->line_out_pins[0])
5941 /* Line-Out: PortE */
5942 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5943 "Master Front Playback Volume",
5944 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5947 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5948 "Master Front Playback Switch",
5949 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5956 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5963 spec->multiout.hp_nid = 0x9;
5964 spec->hp_independent_mode_index = 1;
5967 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5968 "Headphone Playback Volume",
5969 HDA_COMPOSE_AMP_VAL(
5970 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5974 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5975 "Headphone Playback Switch",
5976 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5980 create_hp_imux(spec);
5984 /* create playback/capture controls for input pins */
5985 static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
5986 const struct auto_pin_cfg *cfg)
5988 static char *labels[] = {
5989 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5991 struct hda_input_mux *imux = &spec->private_imux[0];
5992 int i, err, idx = 0;
5994 for (i = 0; i < AUTO_PIN_LAST; i++) {
5995 if (!cfg->input_pins[i])
5998 switch (cfg->input_pins[i]) {
5999 case 0x2b: /* Mic */
6003 case 0x2a: /* Line In */
6007 case 0x29: /* Front Mic */
6011 err = via_new_analog_input(spec, labels[i], idx, 0x21);
6014 imux->items[imux->num_items].label = labels[i];
6015 imux->items[imux->num_items].index = idx;
6018 /* build volume/mute control of loopback */
6019 err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
6023 /* for internal loopback recording select */
6024 imux->items[imux->num_items].label = "Stereo Mixer";
6025 imux->items[imux->num_items].index = 5;
6028 /* for digital mic select */
6029 imux->items[imux->num_items].label = "Digital Mic";
6030 imux->items[imux->num_items].index = 6;
6036 static int vt1812_parse_auto_config(struct hda_codec *codec)
6038 struct via_spec *spec = codec->spec;
6042 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6045 fill_dig_outs(codec);
6046 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6050 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6051 return 0; /* can't find valid BIOS pin config */
6053 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6056 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6059 err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
6063 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6065 fill_dig_outs(codec);
6067 if (spec->kctls.list)
6068 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6070 spec->input_mux = &spec->private_imux[0];
6073 spec->mixers[spec->num_mixers++] = via_hp_mixer;
6078 #ifdef CONFIG_SND_HDA_POWER_SAVE
6079 static struct hda_amp_list vt1812_loopbacks[] = {
6080 { 0x21, HDA_INPUT, 0 },
6081 { 0x21, HDA_INPUT, 1 },
6082 { 0x21, HDA_INPUT, 2 },
6088 /* patch for vt1812 */
6089 static int patch_vt1812(struct hda_codec *codec)
6091 struct via_spec *spec;
6094 /* create a codec specific record */
6095 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6101 /* automatic parse from the BIOS config */
6102 err = vt1812_parse_auto_config(codec);
6107 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6108 "from BIOS. Using genenic mode...\n");
6112 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6113 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6115 spec->stream_name_analog = "VT1812 Analog";
6116 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6117 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6119 spec->stream_name_digital = "VT1812 Digital";
6120 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6123 if (!spec->adc_nids && spec->input_mux) {
6124 spec->adc_nids = vt1812_adc_nids;
6125 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6126 get_mux_nids(codec);
6127 override_mic_boost(codec, 0x2b, 0, 3, 40);
6128 override_mic_boost(codec, 0x29, 0, 3, 40);
6129 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6133 codec->patch_ops = via_patch_ops;
6135 codec->patch_ops.init = via_auto_init;
6136 codec->patch_ops.unsol_event = via_unsol_event;
6138 #ifdef CONFIG_SND_HDA_POWER_SAVE
6139 spec->loopback.amplist = vt1812_loopbacks;
6148 static struct hda_codec_preset snd_hda_preset_via[] = {
6149 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6150 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6151 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6152 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6153 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6154 .patch = patch_vt1709_10ch},
6155 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6156 .patch = patch_vt1709_10ch},
6157 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6158 .patch = patch_vt1709_10ch},
6159 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6160 .patch = patch_vt1709_10ch},
6161 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6162 .patch = patch_vt1709_6ch},
6163 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6164 .patch = patch_vt1709_6ch},
6165 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6166 .patch = patch_vt1709_6ch},
6167 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6168 .patch = patch_vt1709_6ch},
6169 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6170 .patch = patch_vt1708B_8ch},
6171 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6172 .patch = patch_vt1708B_8ch},
6173 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6174 .patch = patch_vt1708B_8ch},
6175 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6176 .patch = patch_vt1708B_8ch},
6177 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6178 .patch = patch_vt1708B_4ch},
6179 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6180 .patch = patch_vt1708B_4ch},
6181 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6182 .patch = patch_vt1708B_4ch},
6183 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6184 .patch = patch_vt1708B_4ch},
6185 { .id = 0x11060397, .name = "VT1708S",
6186 .patch = patch_vt1708S},
6187 { .id = 0x11061397, .name = "VT1708S",
6188 .patch = patch_vt1708S},
6189 { .id = 0x11062397, .name = "VT1708S",
6190 .patch = patch_vt1708S},
6191 { .id = 0x11063397, .name = "VT1708S",
6192 .patch = patch_vt1708S},
6193 { .id = 0x11064397, .name = "VT1708S",
6194 .patch = patch_vt1708S},
6195 { .id = 0x11065397, .name = "VT1708S",
6196 .patch = patch_vt1708S},
6197 { .id = 0x11066397, .name = "VT1708S",
6198 .patch = patch_vt1708S},
6199 { .id = 0x11067397, .name = "VT1708S",
6200 .patch = patch_vt1708S},
6201 { .id = 0x11060398, .name = "VT1702",
6202 .patch = patch_vt1702},
6203 { .id = 0x11061398, .name = "VT1702",
6204 .patch = patch_vt1702},
6205 { .id = 0x11062398, .name = "VT1702",
6206 .patch = patch_vt1702},
6207 { .id = 0x11063398, .name = "VT1702",
6208 .patch = patch_vt1702},
6209 { .id = 0x11064398, .name = "VT1702",
6210 .patch = patch_vt1702},
6211 { .id = 0x11065398, .name = "VT1702",
6212 .patch = patch_vt1702},
6213 { .id = 0x11066398, .name = "VT1702",
6214 .patch = patch_vt1702},
6215 { .id = 0x11067398, .name = "VT1702",
6216 .patch = patch_vt1702},
6217 { .id = 0x11060428, .name = "VT1718S",
6218 .patch = patch_vt1718S},
6219 { .id = 0x11064428, .name = "VT1718S",
6220 .patch = patch_vt1718S},
6221 { .id = 0x11060441, .name = "VT2020",
6222 .patch = patch_vt1718S},
6223 { .id = 0x11064441, .name = "VT1828S",
6224 .patch = patch_vt1718S},
6225 { .id = 0x11060433, .name = "VT1716S",
6226 .patch = patch_vt1716S},
6227 { .id = 0x1106a721, .name = "VT1716S",
6228 .patch = patch_vt1716S},
6229 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6230 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6231 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6232 { .id = 0x11060440, .name = "VT1818S",
6233 .patch = patch_vt1708S},
6237 MODULE_ALIAS("snd-hda-codec-id:1106*");
6239 static struct hda_codec_preset_list via_list = {
6240 .preset = snd_hda_preset_via,
6241 .owner = THIS_MODULE,
6244 MODULE_LICENSE("GPL");
6245 MODULE_DESCRIPTION("VIA HD-audio codec");
6247 static int __init patch_via_init(void)
6249 return snd_hda_add_codec_preset(&via_list);
6252 static void __exit patch_via_exit(void)
6254 snd_hda_delete_codec_preset(&via_list);
6257 module_init(patch_via_init)
6258 module_exit(patch_via_exit)