2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <sound/core.h>
53 #include <sound/asoundef.h>
54 #include "hda_codec.h"
55 #include "hda_local.h"
57 #define NID_MAPPING (-1)
60 #define AMP_VAL_IDX_SHIFT 19
61 #define AMP_VAL_IDX_MASK (0x0f<<19)
64 #define VT1708_HP_NID 0x13
65 #define VT1708_DIGOUT_NID 0x14
66 #define VT1708_DIGIN_NID 0x16
67 #define VT1708_DIGIN_PIN 0x26
68 #define VT1708_HP_PIN_NID 0x20
69 #define VT1708_CD_PIN_NID 0x24
71 #define VT1709_HP_DAC_NID 0x28
72 #define VT1709_DIGOUT_NID 0x13
73 #define VT1709_DIGIN_NID 0x17
74 #define VT1709_DIGIN_PIN 0x25
76 #define VT1708B_HP_NID 0x25
77 #define VT1708B_DIGOUT_NID 0x12
78 #define VT1708B_DIGIN_NID 0x15
79 #define VT1708B_DIGIN_PIN 0x21
81 #define VT1708S_HP_NID 0x25
82 #define VT1708S_DIGOUT_NID 0x12
84 #define VT1702_HP_NID 0x17
85 #define VT1702_DIGOUT_NID 0x11
105 /* codec parameterization */
106 struct snd_kcontrol_new *mixers[6];
107 unsigned int num_mixers;
109 struct hda_verb *init_verbs[5];
110 unsigned int num_iverbs;
112 char *stream_name_analog;
113 struct hda_pcm_stream *stream_analog_playback;
114 struct hda_pcm_stream *stream_analog_capture;
116 char *stream_name_digital;
117 struct hda_pcm_stream *stream_digital_playback;
118 struct hda_pcm_stream *stream_digital_capture;
121 struct hda_multi_out multiout;
122 hda_nid_t slave_dig_outs[2];
125 unsigned int num_adc_nids;
127 hda_nid_t mux_nids[3];
128 hda_nid_t dig_in_nid;
129 hda_nid_t dig_in_pin;
132 const struct hda_input_mux *input_mux;
133 unsigned int cur_mux[3];
135 /* PCM information */
136 struct hda_pcm pcm_rec[3];
138 /* dynamic controls, init_verbs and input_mux */
139 struct auto_pin_cfg autocfg;
140 struct snd_array kctls;
141 struct hda_input_mux private_imux[2];
142 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
145 const struct hda_input_mux *hp_mux;
146 unsigned int hp_independent_mode;
147 unsigned int hp_independent_mode_index;
148 unsigned int smart51_enabled;
149 unsigned int dmic_enabled;
150 enum VIA_HDA_CODEC codec_type;
152 /* work to check hp jack state */
153 struct hda_codec *codec;
154 struct delayed_work vt1708_hp_work;
155 int vt1708_jack_detectect;
156 int vt1708_hp_present;
157 #ifdef CONFIG_SND_HDA_POWER_SAVE
158 struct hda_loopback_check loopback;
162 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
163 static struct via_spec * via_new_spec(struct hda_codec *codec)
165 struct via_spec *spec;
167 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
173 spec->codec_type = get_codec_type(codec);
174 /* VT1708BCE & VT1708S are almost same */
175 if (spec->codec_type == VT1708BCE)
176 spec->codec_type = VT1708S;
180 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
182 u32 vendor_id = codec->vendor_id;
183 u16 ven_id = vendor_id >> 16;
184 u16 dev_id = vendor_id & 0xffff;
185 enum VIA_HDA_CODEC codec_type;
188 if (ven_id != 0x1106)
189 codec_type = UNKNOWN;
190 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
192 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
193 codec_type = VT1709_10CH;
194 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
195 codec_type = VT1709_6CH;
196 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
197 codec_type = VT1708B_8CH;
198 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
199 codec_type = VT1708BCE;
200 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
201 codec_type = VT1708B_4CH;
202 else if ((dev_id & 0xfff) == 0x397
203 && (dev_id >> 12) < 8)
204 codec_type = VT1708S;
205 else if ((dev_id & 0xfff) == 0x398
206 && (dev_id >> 12) < 8)
208 else if ((dev_id & 0xfff) == 0x428
209 && (dev_id >> 12) < 8)
210 codec_type = VT1718S;
211 else if (dev_id == 0x0433 || dev_id == 0xa721)
212 codec_type = VT1716S;
213 else if (dev_id == 0x0441 || dev_id == 0x4441)
214 codec_type = VT1718S;
215 else if (dev_id == 0x0438 || dev_id == 0x4438)
216 codec_type = VT2002P;
217 else if (dev_id == 0x0448)
219 else if (dev_id == 0x0440)
220 codec_type = VT1708S;
222 codec_type = UNKNOWN;
226 #define VIA_HP_EVENT 0x01
227 #define VIA_GPIO_EVENT 0x02
228 #define VIA_JACK_EVENT 0x04
229 #define VIA_MONO_EVENT 0x08
230 #define VIA_SPEAKER_EVENT 0x10
231 #define VIA_BIND_HP_EVENT 0x20
236 VIA_CTL_WIDGET_ANALOG_MUTE,
237 VIA_CTL_WIDGET_BIND_PIN_MUTE,
247 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
248 static void set_jack_power_state(struct hda_codec *codec);
249 static int is_aa_path_mute(struct hda_codec *codec);
251 static void vt1708_start_hp_work(struct via_spec *spec)
253 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
255 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
256 !spec->vt1708_jack_detectect);
257 if (!delayed_work_pending(&spec->vt1708_hp_work))
258 schedule_delayed_work(&spec->vt1708_hp_work,
259 msecs_to_jiffies(100));
262 static void vt1708_stop_hp_work(struct via_spec *spec)
264 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
266 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
267 && !is_aa_path_mute(spec->codec))
269 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
270 !spec->vt1708_jack_detectect);
271 cancel_delayed_work_sync(&spec->vt1708_hp_work);
275 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
276 struct snd_ctl_elem_value *ucontrol)
278 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
279 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
281 set_jack_power_state(codec);
282 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
283 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
284 if (is_aa_path_mute(codec))
285 vt1708_start_hp_work(codec->spec);
287 vt1708_stop_hp_work(codec->spec);
292 /* modify .put = snd_hda_mixer_amp_switch_put */
293 #define ANALOG_INPUT_MUTE \
294 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
297 .info = snd_hda_mixer_amp_switch_info, \
298 .get = snd_hda_mixer_amp_switch_get, \
299 .put = analog_input_switch_put, \
300 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
302 static void via_hp_bind_automute(struct hda_codec *codec);
304 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
305 struct snd_ctl_elem_value *ucontrol)
307 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
308 struct via_spec *spec = codec->spec;
312 long *valp = ucontrol->value.integer.value;
314 if (strstr(kcontrol->id.name, "Switch") == NULL) {
315 snd_printd("Invalid control!\n");
318 change = snd_hda_mixer_amp_switch_put(kcontrol,
321 lmute = *valp ? 0 : HDA_AMP_MUTE;
323 rmute = *valp ? 0 : HDA_AMP_MUTE;
326 if (!spec->hp_independent_mode) {
327 for (i = 0; i < spec->autocfg.hp_outs; i++) {
328 snd_hda_codec_amp_update(
329 codec, spec->autocfg.hp_pins[i],
330 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
332 snd_hda_codec_amp_update(
333 codec, spec->autocfg.hp_pins[i],
334 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
339 if (!lmute && !rmute) {
341 for (i = 0; i < spec->autocfg.line_outs; i++)
342 snd_hda_codec_amp_stereo(
343 codec, spec->autocfg.line_out_pins[i],
344 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
346 for (i = 0; i < spec->autocfg.speaker_outs; i++)
347 snd_hda_codec_amp_stereo(
348 codec, spec->autocfg.speaker_pins[i],
349 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
351 via_hp_bind_automute(codec);
355 /* Mute all left channels */
356 for (i = 1; i < spec->autocfg.line_outs; i++)
357 snd_hda_codec_amp_update(
359 spec->autocfg.line_out_pins[i],
360 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
362 for (i = 0; i < spec->autocfg.speaker_outs; i++)
363 snd_hda_codec_amp_update(
365 spec->autocfg.speaker_pins[i],
366 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
370 /* mute all right channels */
371 for (i = 1; i < spec->autocfg.line_outs; i++)
372 snd_hda_codec_amp_update(
374 spec->autocfg.line_out_pins[i],
375 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
377 for (i = 0; i < spec->autocfg.speaker_outs; i++)
378 snd_hda_codec_amp_update(
380 spec->autocfg.speaker_pins[i],
381 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
388 #define BIND_PIN_MUTE \
389 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
392 .info = snd_hda_mixer_amp_switch_info, \
393 .get = snd_hda_mixer_amp_switch_get, \
394 .put = bind_pin_switch_put, \
395 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
397 static struct snd_kcontrol_new via_control_templates[] = {
398 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
399 HDA_CODEC_MUTE(NULL, 0, 0, 0),
404 static hda_nid_t vt1708_adc_nids[2] = {
409 static hda_nid_t vt1709_adc_nids[3] = {
414 static hda_nid_t vt1708B_adc_nids[2] = {
419 static hda_nid_t vt1708S_adc_nids[2] = {
424 static hda_nid_t vt1702_adc_nids[3] = {
429 static hda_nid_t vt1718S_adc_nids[2] = {
434 static hda_nid_t vt1716S_adc_nids[2] = {
439 static hda_nid_t vt2002P_adc_nids[2] = {
444 static hda_nid_t vt1812_adc_nids[2] = {
450 /* add dynamic controls */
451 static int __via_add_control(struct via_spec *spec, int type, const char *name,
452 int idx, unsigned long val)
454 struct snd_kcontrol_new *knew;
456 snd_array_init(&spec->kctls, sizeof(*knew), 32);
457 knew = snd_array_new(&spec->kctls);
460 *knew = via_control_templates[type];
461 knew->name = kstrdup(name, GFP_KERNEL);
464 if (get_amp_nid_(val))
465 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
466 knew->private_value = val;
470 #define via_add_control(spec, type, name, val) \
471 __via_add_control(spec, type, name, 0, val)
473 static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
474 struct snd_kcontrol_new *tmpl)
476 struct snd_kcontrol_new *knew;
478 snd_array_init(&spec->kctls, sizeof(*knew), 32);
479 knew = snd_array_new(&spec->kctls);
483 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
489 static void via_free_kctls(struct hda_codec *codec)
491 struct via_spec *spec = codec->spec;
493 if (spec->kctls.list) {
494 struct snd_kcontrol_new *kctl = spec->kctls.list;
496 for (i = 0; i < spec->kctls.used; i++)
499 snd_array_free(&spec->kctls);
502 /* create input playback/capture controls for the given pin */
503 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
504 int type_idx, int idx, int mix_nid)
509 sprintf(name, "%s Playback Volume", ctlname);
510 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
511 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
514 sprintf(name, "%s Playback Switch", ctlname);
515 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
516 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
522 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
523 hda_nid_t nid, int pin_type,
527 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
529 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
531 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
532 snd_hda_codec_write(codec, nid, 0,
533 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
537 static void via_auto_init_multi_out(struct hda_codec *codec)
539 struct via_spec *spec = codec->spec;
542 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
543 hda_nid_t nid = spec->autocfg.line_out_pins[i];
545 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
549 static void via_auto_init_hp_out(struct hda_codec *codec)
551 struct via_spec *spec = codec->spec;
555 for (i = 0; i < spec->autocfg.hp_outs; i++) {
556 pin = spec->autocfg.hp_pins[i];
557 if (pin) /* connect to front */
558 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
562 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
564 static void via_auto_init_analog_input(struct hda_codec *codec)
566 struct via_spec *spec = codec->spec;
567 const struct auto_pin_cfg *cfg = &spec->autocfg;
571 for (i = 0; i < cfg->num_inputs; i++) {
572 hda_nid_t nid = cfg->inputs[i].pin;
573 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
575 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
579 snd_hda_codec_write(codec, nid, 0,
580 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
584 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
585 unsigned int *affected_parm)
588 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
589 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
590 >> AC_DEFCFG_MISC_SHIFT
591 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
592 unsigned present = snd_hda_jack_detect(codec, nid);
593 struct via_spec *spec = codec->spec;
594 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
595 || ((no_presence || present)
596 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
597 *affected_parm = AC_PWRST_D0; /* if it's connected */
602 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
605 static void set_jack_power_state(struct hda_codec *codec)
607 struct via_spec *spec = codec->spec;
611 if (spec->codec_type == VT1702) {
612 imux_is_smixer = snd_hda_codec_read(
613 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
615 /* PW 1/2/5 (14h/15h/18h) */
617 set_pin_power_state(codec, 0x14, &parm);
618 set_pin_power_state(codec, 0x15, &parm);
619 set_pin_power_state(codec, 0x18, &parm);
621 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
622 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
623 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
625 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
627 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
629 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
633 /* PW 3/4 (16h/17h) */
635 set_pin_power_state(codec, 0x16, &parm);
636 set_pin_power_state(codec, 0x17, &parm);
637 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
638 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
639 imux_is_smixer ? AC_PWRST_D0 : parm);
640 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
642 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
644 } else if (spec->codec_type == VT1708B_8CH
645 || spec->codec_type == VT1708B_4CH
646 || spec->codec_type == VT1708S) {
647 /* SW0 (17h) = stereo mixer */
648 int is_8ch = spec->codec_type != VT1708B_4CH;
649 imux_is_smixer = snd_hda_codec_read(
650 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
651 == ((spec->codec_type == VT1708S) ? 5 : 0);
653 /* PW 1/2/5 (1ah/1bh/1eh) */
655 set_pin_power_state(codec, 0x1a, &parm);
656 set_pin_power_state(codec, 0x1b, &parm);
657 set_pin_power_state(codec, 0x1e, &parm);
660 /* SW0 (17h), AIW 0/1 (13h/14h) */
661 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
663 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
665 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
669 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
671 set_pin_power_state(codec, 0x19, &parm);
672 if (spec->smart51_enabled)
674 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
676 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
679 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
682 set_pin_power_state(codec, 0x22, &parm);
683 if (spec->smart51_enabled)
685 snd_hda_codec_write(codec, 0x26, 0,
686 AC_VERB_SET_POWER_STATE, parm);
687 snd_hda_codec_write(codec, 0x24, 0,
688 AC_VERB_SET_POWER_STATE, parm);
691 /* PW 3/4/7 (1ch/1dh/23h) */
693 /* force to D0 for internal Speaker */
694 set_pin_power_state(codec, 0x1c, &parm);
695 set_pin_power_state(codec, 0x1d, &parm);
697 set_pin_power_state(codec, 0x23, &parm);
698 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
699 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
700 imux_is_smixer ? AC_PWRST_D0 : parm);
701 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
704 snd_hda_codec_write(codec, 0x25, 0,
705 AC_VERB_SET_POWER_STATE, parm);
706 snd_hda_codec_write(codec, 0x27, 0,
707 AC_VERB_SET_POWER_STATE, parm);
709 } else if (spec->codec_type == VT1718S) {
710 /* MUX6 (1eh) = stereo mixer */
711 imux_is_smixer = snd_hda_codec_read(
712 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
714 /* PW 5/6/7 (29h/2ah/2bh) */
716 set_pin_power_state(codec, 0x29, &parm);
717 set_pin_power_state(codec, 0x2a, &parm);
718 set_pin_power_state(codec, 0x2b, &parm);
721 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
722 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
724 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
726 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
728 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
732 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
734 set_pin_power_state(codec, 0x27, &parm);
735 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
737 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
740 /* PW2 (26h), AOW2 (ah) */
742 set_pin_power_state(codec, 0x26, &parm);
743 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
746 /* PW0/1 (24h/25h) */
748 set_pin_power_state(codec, 0x24, &parm);
749 set_pin_power_state(codec, 0x25, &parm);
750 if (!spec->hp_independent_mode) /* check for redirected HP */
751 set_pin_power_state(codec, 0x28, &parm);
752 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
754 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
756 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
757 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
758 imux_is_smixer ? AC_PWRST_D0 : parm);
759 if (spec->hp_independent_mode) {
760 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
762 set_pin_power_state(codec, 0x28, &parm);
763 snd_hda_codec_write(codec, 0x1b, 0,
764 AC_VERB_SET_POWER_STATE, parm);
765 snd_hda_codec_write(codec, 0x34, 0,
766 AC_VERB_SET_POWER_STATE, parm);
767 snd_hda_codec_write(codec, 0xc, 0,
768 AC_VERB_SET_POWER_STATE, parm);
770 } else if (spec->codec_type == VT1716S) {
771 unsigned int mono_out, present;
772 /* SW0 (17h) = stereo mixer */
773 imux_is_smixer = snd_hda_codec_read(
774 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
776 /* PW 1/2/5 (1ah/1bh/1eh) */
778 set_pin_power_state(codec, 0x1a, &parm);
779 set_pin_power_state(codec, 0x1b, &parm);
780 set_pin_power_state(codec, 0x1e, &parm);
783 /* SW0 (17h), AIW0(13h) */
784 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
786 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
790 set_pin_power_state(codec, 0x1e, &parm);
792 if (spec->dmic_enabled)
793 set_pin_power_state(codec, 0x22, &parm);
797 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
799 /* SW2(26h), AIW1(14h) */
800 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
802 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
806 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
808 set_pin_power_state(codec, 0x19, &parm);
809 /* Smart 5.1 PW2(1bh) */
810 if (spec->smart51_enabled)
811 set_pin_power_state(codec, 0x1b, &parm);
812 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
814 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
817 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
819 set_pin_power_state(codec, 0x23, &parm);
820 /* Smart 5.1 PW1(1ah) */
821 if (spec->smart51_enabled)
822 set_pin_power_state(codec, 0x1a, &parm);
823 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
826 /* Smart 5.1 PW5(1eh) */
827 if (spec->smart51_enabled)
828 set_pin_power_state(codec, 0x1e, &parm);
829 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
833 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
834 present = snd_hda_jack_detect(codec, 0x1c);
838 present = snd_hda_jack_detect(codec, 0x1d);
839 if (!spec->hp_independent_mode && present)
844 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
845 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
847 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
849 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
852 /* PW 3/4 (1ch/1dh) */
854 set_pin_power_state(codec, 0x1c, &parm);
855 set_pin_power_state(codec, 0x1d, &parm);
856 /* HP Independent Mode, power on AOW3 */
857 if (spec->hp_independent_mode)
858 snd_hda_codec_write(codec, 0x25, 0,
859 AC_VERB_SET_POWER_STATE, parm);
861 /* force to D0 for internal Speaker */
862 /* MW0 (16h), AOW0 (10h) */
863 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
864 imux_is_smixer ? AC_PWRST_D0 : parm);
865 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
866 mono_out ? AC_PWRST_D0 : parm);
867 } else if (spec->codec_type == VT2002P) {
868 unsigned int present;
869 /* MUX9 (1eh) = stereo mixer */
870 imux_is_smixer = snd_hda_codec_read(
871 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
873 /* PW 5/6/7 (29h/2ah/2bh) */
875 set_pin_power_state(codec, 0x29, &parm);
876 set_pin_power_state(codec, 0x2a, &parm);
877 set_pin_power_state(codec, 0x2b, &parm);
880 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
881 snd_hda_codec_write(codec, 0x1e, 0,
882 AC_VERB_SET_POWER_STATE, parm);
883 snd_hda_codec_write(codec, 0x1f, 0,
884 AC_VERB_SET_POWER_STATE, parm);
885 snd_hda_codec_write(codec, 0x10, 0,
886 AC_VERB_SET_POWER_STATE, parm);
887 snd_hda_codec_write(codec, 0x11, 0,
888 AC_VERB_SET_POWER_STATE, parm);
892 snd_hda_codec_write(codec, 0x8, 0,
893 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
895 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
897 set_pin_power_state(codec, 0x26, &parm);
898 snd_hda_codec_write(codec, 0x1c, 0,
899 AC_VERB_SET_POWER_STATE, parm);
900 snd_hda_codec_write(codec, 0x37,
901 0, AC_VERB_SET_POWER_STATE, parm);
903 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
905 set_pin_power_state(codec, 0x25, &parm);
906 snd_hda_codec_write(codec, 0x19, 0,
907 AC_VERB_SET_POWER_STATE, parm);
908 snd_hda_codec_write(codec, 0x35, 0,
909 AC_VERB_SET_POWER_STATE, parm);
910 if (spec->hp_independent_mode) {
911 snd_hda_codec_write(codec, 0x9, 0,
912 AC_VERB_SET_POWER_STATE, parm);
916 /* PW0 (24h), MW0(18h), MUX0(34h) */
917 present = snd_hda_jack_detect(codec, 0x25);
919 set_pin_power_state(codec, 0x24, &parm);
923 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
926 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
930 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
933 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
937 /* PW15 (31h), MW8(17h), MUX8(3bh) */
938 present = snd_hda_jack_detect(codec, 0x26);
940 set_pin_power_state(codec, 0x31, &parm);
944 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
947 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
951 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
954 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
958 if (imux_is_smixer || !is_aa_path_mute(codec))
961 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
965 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
966 } else if (spec->codec_type == VT1812) {
967 unsigned int present;
968 /* MUX10 (1eh) = stereo mixer */
969 imux_is_smixer = snd_hda_codec_read(
970 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
972 /* PW 5/6/7 (29h/2ah/2bh) */
974 set_pin_power_state(codec, 0x29, &parm);
975 set_pin_power_state(codec, 0x2a, &parm);
976 set_pin_power_state(codec, 0x2b, &parm);
979 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
980 snd_hda_codec_write(codec, 0x1e, 0,
981 AC_VERB_SET_POWER_STATE, parm);
982 snd_hda_codec_write(codec, 0x1f, 0,
983 AC_VERB_SET_POWER_STATE, parm);
984 snd_hda_codec_write(codec, 0x10, 0,
985 AC_VERB_SET_POWER_STATE, parm);
986 snd_hda_codec_write(codec, 0x11, 0,
987 AC_VERB_SET_POWER_STATE, parm);
991 snd_hda_codec_write(codec, 0x8, 0,
992 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
994 /* PW4 (28h), MW4 (18h), MUX4(38h) */
996 set_pin_power_state(codec, 0x28, &parm);
997 snd_hda_codec_write(codec, 0x18, 0,
998 AC_VERB_SET_POWER_STATE, parm);
999 snd_hda_codec_write(codec, 0x38, 0,
1000 AC_VERB_SET_POWER_STATE, parm);
1002 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1004 set_pin_power_state(codec, 0x25, &parm);
1005 snd_hda_codec_write(codec, 0x15, 0,
1006 AC_VERB_SET_POWER_STATE, parm);
1007 snd_hda_codec_write(codec, 0x35, 0,
1008 AC_VERB_SET_POWER_STATE, parm);
1009 if (spec->hp_independent_mode) {
1010 snd_hda_codec_write(codec, 0x9, 0,
1011 AC_VERB_SET_POWER_STATE, parm);
1014 /* Internal Speaker */
1015 /* PW0 (24h), MW0(14h), MUX0(34h) */
1016 present = snd_hda_jack_detect(codec, 0x25);
1018 set_pin_power_state(codec, 0x24, &parm);
1020 snd_hda_codec_write(codec, 0x14, 0,
1021 AC_VERB_SET_POWER_STATE,
1023 snd_hda_codec_write(codec, 0x34, 0,
1024 AC_VERB_SET_POWER_STATE,
1027 snd_hda_codec_write(codec, 0x14, 0,
1028 AC_VERB_SET_POWER_STATE,
1030 snd_hda_codec_write(codec, 0x34, 0,
1031 AC_VERB_SET_POWER_STATE,
1035 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1036 present = snd_hda_jack_detect(codec, 0x28);
1038 set_pin_power_state(codec, 0x31, &parm);
1040 snd_hda_codec_write(codec, 0x1c, 0,
1041 AC_VERB_SET_POWER_STATE,
1043 snd_hda_codec_write(codec, 0x3c, 0,
1044 AC_VERB_SET_POWER_STATE,
1046 snd_hda_codec_write(codec, 0x3e, 0,
1047 AC_VERB_SET_POWER_STATE,
1050 snd_hda_codec_write(codec, 0x1c, 0,
1051 AC_VERB_SET_POWER_STATE,
1053 snd_hda_codec_write(codec, 0x3c, 0,
1054 AC_VERB_SET_POWER_STATE,
1056 snd_hda_codec_write(codec, 0x3e, 0,
1057 AC_VERB_SET_POWER_STATE,
1061 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1063 set_pin_power_state(codec, 0x33, &parm);
1064 snd_hda_codec_write(codec, 0x1d, 0,
1065 AC_VERB_SET_POWER_STATE, parm);
1066 snd_hda_codec_write(codec, 0x3d, 0,
1067 AC_VERB_SET_POWER_STATE, parm);
1070 if (imux_is_smixer || !is_aa_path_mute(codec))
1071 snd_hda_codec_write(
1073 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1075 snd_hda_codec_write(
1077 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1082 * input MUX handling
1084 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1085 struct snd_ctl_elem_info *uinfo)
1087 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1088 struct via_spec *spec = codec->spec;
1089 return snd_hda_input_mux_info(spec->input_mux, uinfo);
1092 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1093 struct snd_ctl_elem_value *ucontrol)
1095 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1096 struct via_spec *spec = codec->spec;
1097 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1099 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
1103 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1104 struct snd_ctl_elem_value *ucontrol)
1106 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1107 struct via_spec *spec = codec->spec;
1108 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1111 if (!spec->mux_nids[adc_idx])
1113 /* switch to D0 beofre change index */
1114 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1115 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1116 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1117 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1119 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1120 spec->mux_nids[adc_idx],
1121 &spec->cur_mux[adc_idx]);
1122 /* update jack power state */
1123 set_jack_power_state(codec);
1128 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
1129 struct snd_ctl_elem_info *uinfo)
1131 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1132 struct via_spec *spec = codec->spec;
1133 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
1136 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
1137 struct snd_ctl_elem_value *ucontrol)
1139 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1140 hda_nid_t nid = kcontrol->private_value;
1141 unsigned int pinsel;
1143 /* use !! to translate conn sel 2 for VT1718S */
1144 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1145 AC_VERB_GET_CONNECT_SEL,
1147 ucontrol->value.enumerated.item[0] = pinsel;
1152 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1154 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1156 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1157 ctl->vd[0].access |= active
1158 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1159 snd_ctl_notify(codec->bus->card,
1160 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1164 static hda_nid_t side_mute_channel(struct via_spec *spec)
1166 switch (spec->codec_type) {
1167 case VT1708: return 0x1b;
1168 case VT1709_10CH: return 0x29;
1169 case VT1708B_8CH: /* fall thru */
1170 case VT1708S: return 0x27;
1175 static int update_side_mute_status(struct hda_codec *codec)
1177 /* mute side channel */
1178 struct via_spec *spec = codec->spec;
1179 unsigned int parm = spec->hp_independent_mode
1180 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1181 hda_nid_t sw3 = side_mute_channel(spec);
1184 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1189 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
1190 struct snd_ctl_elem_value *ucontrol)
1192 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1193 struct via_spec *spec = codec->spec;
1194 hda_nid_t nid = kcontrol->private_value;
1195 unsigned int pinsel = ucontrol->value.enumerated.item[0];
1196 /* Get Independent Mode index of headphone pin widget */
1197 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1199 if (spec->codec_type == VT1718S)
1200 snd_hda_codec_write(codec, nid, 0,
1201 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
1203 snd_hda_codec_write(codec, nid, 0,
1204 AC_VERB_SET_CONNECT_SEL, pinsel);
1206 if (spec->codec_type == VT1812)
1207 snd_hda_codec_write(codec, 0x35, 0,
1208 AC_VERB_SET_CONNECT_SEL, pinsel);
1209 if (spec->multiout.hp_nid && spec->multiout.hp_nid
1210 != spec->multiout.dac_nids[HDA_FRONT])
1211 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
1214 update_side_mute_status(codec);
1215 /* update HP volume/swtich active state */
1216 if (spec->codec_type == VT1708S
1217 || spec->codec_type == VT1702
1218 || spec->codec_type == VT1718S
1219 || spec->codec_type == VT1716S
1220 || spec->codec_type == VT2002P
1221 || spec->codec_type == VT1812) {
1222 activate_ctl(codec, "Headphone Playback Volume",
1223 spec->hp_independent_mode);
1224 activate_ctl(codec, "Headphone Playback Switch",
1225 spec->hp_independent_mode);
1227 /* update jack power state */
1228 set_jack_power_state(codec);
1232 static struct snd_kcontrol_new via_hp_mixer[2] = {
1234 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1235 .name = "Independent HP",
1236 .info = via_independent_hp_info,
1237 .get = via_independent_hp_get,
1238 .put = via_independent_hp_put,
1241 .iface = NID_MAPPING,
1242 .name = "Independent HP",
1246 static int via_hp_build(struct hda_codec *codec)
1248 struct via_spec *spec = codec->spec;
1249 struct snd_kcontrol_new *knew;
1252 hda_nid_t conn[HDA_MAX_CONNECTIONS];
1254 switch (spec->codec_type) {
1265 nid = spec->autocfg.hp_pins[0];
1269 if (spec->codec_type != VT1708) {
1270 nums = snd_hda_get_connections(codec, nid,
1271 conn, HDA_MAX_CONNECTIONS);
1276 knew = via_clone_control(spec, &via_hp_mixer[0]);
1280 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
1281 knew->private_value = nid;
1283 knew = via_clone_control(spec, &via_hp_mixer[1]);
1286 knew->subdevice = side_mute_channel(spec);
1291 static void notify_aa_path_ctls(struct hda_codec *codec)
1294 struct snd_ctl_elem_id id;
1295 const char *labels[] = {"Mic", "Front Mic", "Line"};
1297 memset(&id, 0, sizeof(id));
1298 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1299 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1300 sprintf(id.name, "%s Playback Volume", labels[i]);
1301 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1306 static void mute_aa_path(struct hda_codec *codec, int mute)
1308 struct via_spec *spec = codec->spec;
1309 hda_nid_t nid_mixer;
1313 /* get nid of MW0 and start & end index */
1314 switch (spec->codec_type) {
1342 /* check AA path's mute status */
1343 for (i = start_idx; i <= end_idx; i++) {
1344 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1345 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1349 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1351 const struct auto_pin_cfg *cfg = &spec->autocfg;
1354 for (i = 0; i < cfg->num_inputs; i++) {
1355 if (pin == cfg->inputs[i].pin)
1356 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
1361 static int via_smart51_info(struct snd_kcontrol *kcontrol,
1362 struct snd_ctl_elem_info *uinfo)
1364 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1366 uinfo->value.integer.min = 0;
1367 uinfo->value.integer.max = 1;
1371 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1372 struct snd_ctl_elem_value *ucontrol)
1374 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1375 struct via_spec *spec = codec->spec;
1376 const struct auto_pin_cfg *cfg = &spec->autocfg;
1380 for (i = 0; i < cfg->num_inputs; i++) {
1381 hda_nid_t nid = cfg->inputs[i].pin;
1382 int ctl = snd_hda_codec_read(codec, nid, 0,
1383 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1384 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1386 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1387 spec->hp_independent_mode && spec->codec_type != VT1718S)
1388 continue; /* ignore FMic for independent HP */
1389 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
1392 *ucontrol->value.integer.value = on;
1396 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1397 struct snd_ctl_elem_value *ucontrol)
1399 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1400 struct via_spec *spec = codec->spec;
1401 const struct auto_pin_cfg *cfg = &spec->autocfg;
1402 int out_in = *ucontrol->value.integer.value
1403 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1406 for (i = 0; i < cfg->num_inputs; i++) {
1407 hda_nid_t nid = cfg->inputs[i].pin;
1410 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1412 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1413 spec->hp_independent_mode && spec->codec_type != VT1718S)
1414 continue; /* don't retask FMic for independent HP */
1416 parm = snd_hda_codec_read(codec, nid, 0,
1417 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1418 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1420 snd_hda_codec_write(codec, nid, 0,
1421 AC_VERB_SET_PIN_WIDGET_CONTROL,
1423 if (out_in == AC_PINCTL_OUT_EN) {
1424 mute_aa_path(codec, 1);
1425 notify_aa_path_ctls(codec);
1427 if (spec->codec_type == VT1718S) {
1428 snd_hda_codec_amp_stereo(
1429 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1432 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
1433 if (spec->codec_type == VT1708S
1434 || spec->codec_type == VT1716S) {
1435 /* input = index 1 (AOW3) */
1436 snd_hda_codec_write(
1438 AC_VERB_SET_CONNECT_SEL, 1);
1439 snd_hda_codec_amp_stereo(
1440 codec, nid, HDA_OUTPUT,
1441 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1445 spec->smart51_enabled = *ucontrol->value.integer.value;
1446 set_jack_power_state(codec);
1450 static struct snd_kcontrol_new via_smart51_mixer[2] = {
1452 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1453 .name = "Smart 5.1",
1455 .info = via_smart51_info,
1456 .get = via_smart51_get,
1457 .put = via_smart51_put,
1460 .iface = NID_MAPPING,
1461 .name = "Smart 5.1",
1465 static int via_smart51_build(struct via_spec *spec)
1467 struct snd_kcontrol_new *knew;
1468 const struct auto_pin_cfg *cfg = &spec->autocfg;
1472 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1476 for (i = 0; i < cfg->num_inputs; i++) {
1477 nid = cfg->inputs[i].pin;
1478 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1479 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1482 knew->subdevice = nid;
1490 /* capture mixer elements */
1491 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1492 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1493 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1494 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1495 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1497 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1498 /* The multiple "Capture Source" controls confuse alsamixer
1499 * So call somewhat different..
1501 /* .name = "Capture Source", */
1502 .name = "Input Source",
1504 .info = via_mux_enum_info,
1505 .get = via_mux_enum_get,
1506 .put = via_mux_enum_put,
1511 /* check AA path's mute statue */
1512 static int is_aa_path_mute(struct hda_codec *codec)
1515 hda_nid_t nid_mixer;
1519 struct via_spec *spec = codec->spec;
1520 /* get nid of MW0 and start & end index */
1521 switch (spec->codec_type) {
1549 /* check AA path's mute status */
1550 for (i = start_idx; i <= end_idx; i++) {
1551 unsigned int con_list = snd_hda_codec_read(
1552 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1553 int shift = 8 * (i % 4);
1554 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1555 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1556 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1557 /* check mute status while the pin is connected */
1558 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1560 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1562 if (!mute_l || !mute_r) {
1571 /* enter/exit analog low-current mode */
1572 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1574 struct via_spec *spec = codec->spec;
1575 static int saved_stream_idle = 1; /* saved stream idle status */
1576 int enable = is_aa_path_mute(codec);
1577 unsigned int verb = 0;
1578 unsigned int parm = 0;
1580 if (stream_idle == -1) /* stream status did not change */
1581 enable = enable && saved_stream_idle;
1583 enable = enable && stream_idle;
1584 saved_stream_idle = stream_idle;
1587 /* decide low current mode's verb & parameter */
1588 switch (spec->codec_type) {
1592 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1598 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1602 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1607 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1610 return; /* other codecs are not supported */
1613 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1617 * generic initialization of ADC, input mixers and output mixers
1619 static struct hda_verb vt1708_volume_init_verbs[] = {
1621 * Unmute ADC0-1 and set the default input to mic-in
1623 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1624 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1627 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1630 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1631 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1632 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1633 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1634 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1635 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1638 * Set up output mixers (0x19 - 0x1b)
1640 /* set vol=0 to output mixers */
1641 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1642 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1643 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1645 /* Setup default input MW0 to PW4 */
1646 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1647 /* PW9 Output enable */
1648 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1652 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1653 struct hda_codec *codec,
1654 struct snd_pcm_substream *substream)
1656 struct via_spec *spec = codec->spec;
1657 int idle = substream->pstr->substream_opened == 1
1658 && substream->ref_count == 0;
1659 analog_low_current_mode(codec, idle);
1660 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1664 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1665 unsigned int stream_tag,
1666 unsigned int format,
1667 struct snd_pcm_substream *substream)
1669 struct via_spec *spec = codec->spec;
1670 struct hda_multi_out *mout = &spec->multiout;
1671 hda_nid_t *nids = mout->dac_nids;
1672 int chs = substream->runtime->channels;
1675 mutex_lock(&codec->spdif_mutex);
1676 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1678 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1680 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1681 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1682 /* turn off SPDIF once; otherwise the IEC958 bits won't
1684 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1685 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1686 AC_VERB_SET_DIGI_CONVERT_1,
1688 ~AC_DIG1_ENABLE & 0xff);
1689 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1690 stream_tag, 0, format);
1691 /* turn on again (if needed) */
1692 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1693 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1694 AC_VERB_SET_DIGI_CONVERT_1,
1695 codec->spdif_ctls & 0xff);
1697 mout->dig_out_used = 0;
1698 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1702 mutex_unlock(&codec->spdif_mutex);
1705 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1708 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1709 && !spec->hp_independent_mode)
1710 /* headphone out will just decode front left/right (stereo) */
1711 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1714 /* extra outputs copied from front */
1715 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1716 if (mout->extra_out_nid[i])
1717 snd_hda_codec_setup_stream(codec,
1718 mout->extra_out_nid[i],
1719 stream_tag, 0, format);
1722 for (i = 1; i < mout->num_dacs; i++) {
1723 if (chs >= (i + 1) * 2) /* independent out */
1724 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1726 else /* copy front */
1727 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1732 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1733 struct hda_codec *codec,
1734 unsigned int stream_tag,
1735 unsigned int format,
1736 struct snd_pcm_substream *substream)
1738 struct via_spec *spec = codec->spec;
1739 struct hda_multi_out *mout = &spec->multiout;
1740 hda_nid_t *nids = mout->dac_nids;
1742 if (substream->number == 0)
1743 playback_multi_pcm_prep_0(codec, stream_tag, format,
1746 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1747 spec->hp_independent_mode)
1748 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1749 stream_tag, 0, format);
1751 vt1708_start_hp_work(spec);
1755 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1756 struct hda_codec *codec,
1757 struct snd_pcm_substream *substream)
1759 struct via_spec *spec = codec->spec;
1760 struct hda_multi_out *mout = &spec->multiout;
1761 hda_nid_t *nids = mout->dac_nids;
1764 if (substream->number == 0) {
1765 for (i = 0; i < mout->num_dacs; i++)
1766 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1768 if (mout->hp_nid && !spec->hp_independent_mode)
1769 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1772 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1773 if (mout->extra_out_nid[i])
1774 snd_hda_codec_setup_stream(codec,
1775 mout->extra_out_nid[i],
1777 mutex_lock(&codec->spdif_mutex);
1778 if (mout->dig_out_nid &&
1779 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1780 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1782 mout->dig_out_used = 0;
1784 mutex_unlock(&codec->spdif_mutex);
1786 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1787 spec->hp_independent_mode)
1788 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1791 vt1708_stop_hp_work(spec);
1798 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1799 struct hda_codec *codec,
1800 struct snd_pcm_substream *substream)
1802 struct via_spec *spec = codec->spec;
1803 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1806 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1807 struct hda_codec *codec,
1808 struct snd_pcm_substream *substream)
1810 struct via_spec *spec = codec->spec;
1811 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1814 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1815 struct hda_codec *codec,
1816 unsigned int stream_tag,
1817 unsigned int format,
1818 struct snd_pcm_substream *substream)
1820 struct via_spec *spec = codec->spec;
1821 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1822 stream_tag, format, substream);
1825 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1826 struct hda_codec *codec,
1827 struct snd_pcm_substream *substream)
1829 struct via_spec *spec = codec->spec;
1830 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1837 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1838 struct hda_codec *codec,
1839 unsigned int stream_tag,
1840 unsigned int format,
1841 struct snd_pcm_substream *substream)
1843 struct via_spec *spec = codec->spec;
1845 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1846 stream_tag, 0, format);
1850 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1851 struct hda_codec *codec,
1852 struct snd_pcm_substream *substream)
1854 struct via_spec *spec = codec->spec;
1855 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1859 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1863 .nid = 0x10, /* NID to query formats and rates */
1865 .open = via_playback_pcm_open,
1866 .prepare = via_playback_multi_pcm_prepare,
1867 .cleanup = via_playback_multi_pcm_cleanup
1871 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1875 .nid = 0x10, /* NID to query formats and rates */
1876 /* We got noisy outputs on the right channel on VT1708 when
1877 * 24bit samples are used. Until any workaround is found,
1878 * disable the 24bit format, so far.
1880 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1882 .open = via_playback_pcm_open,
1883 .prepare = via_playback_multi_pcm_prepare,
1884 .cleanup = via_playback_multi_pcm_cleanup
1888 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1892 .nid = 0x15, /* NID to query formats and rates */
1894 .prepare = via_capture_pcm_prepare,
1895 .cleanup = via_capture_pcm_cleanup
1899 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1903 /* NID is set in via_build_pcms */
1905 .open = via_dig_playback_pcm_open,
1906 .close = via_dig_playback_pcm_close,
1907 .prepare = via_dig_playback_pcm_prepare,
1908 .cleanup = via_dig_playback_pcm_cleanup
1912 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1918 static int via_build_controls(struct hda_codec *codec)
1920 struct via_spec *spec = codec->spec;
1921 struct snd_kcontrol *kctl;
1922 struct snd_kcontrol_new *knew;
1925 for (i = 0; i < spec->num_mixers; i++) {
1926 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1931 if (spec->multiout.dig_out_nid) {
1932 err = snd_hda_create_spdif_out_ctls(codec,
1933 spec->multiout.dig_out_nid);
1936 err = snd_hda_create_spdif_share_sw(codec,
1940 spec->multiout.share_spdif = 1;
1942 if (spec->dig_in_nid) {
1943 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1948 /* assign Capture Source enums to NID */
1949 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1950 for (i = 0; kctl && i < kctl->count; i++) {
1951 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1956 /* other nid->control mapping */
1957 for (i = 0; i < spec->num_mixers; i++) {
1958 for (knew = spec->mixers[i]; knew->name; knew++) {
1959 if (knew->iface != NID_MAPPING)
1961 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1964 err = snd_hda_add_nid(codec, kctl, 0,
1969 /* init power states */
1970 set_jack_power_state(codec);
1971 analog_low_current_mode(codec, 1);
1973 via_free_kctls(codec); /* no longer needed */
1977 static int via_build_pcms(struct hda_codec *codec)
1979 struct via_spec *spec = codec->spec;
1980 struct hda_pcm *info = spec->pcm_rec;
1982 codec->num_pcms = 1;
1983 codec->pcm_info = info;
1985 info->name = spec->stream_name_analog;
1986 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1987 *(spec->stream_analog_playback);
1988 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1989 spec->multiout.dac_nids[0];
1990 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1991 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1993 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1994 spec->multiout.max_channels;
1996 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1999 info->name = spec->stream_name_digital;
2000 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2001 if (spec->multiout.dig_out_nid) {
2002 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2003 *(spec->stream_digital_playback);
2004 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2005 spec->multiout.dig_out_nid;
2007 if (spec->dig_in_nid) {
2008 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2009 *(spec->stream_digital_capture);
2010 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2018 static void via_free(struct hda_codec *codec)
2020 struct via_spec *spec = codec->spec;
2025 via_free_kctls(codec);
2026 vt1708_stop_hp_work(spec);
2030 /* mute internal speaker if HP is plugged */
2031 static void via_hp_automute(struct hda_codec *codec)
2033 unsigned int present = 0;
2034 struct via_spec *spec = codec->spec;
2036 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2038 if (!spec->hp_independent_mode) {
2039 struct snd_ctl_elem_id id;
2041 snd_hda_codec_amp_stereo(
2042 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
2043 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2045 memset(&id, 0, sizeof(id));
2046 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2047 strcpy(id.name, "Front Playback Switch");
2048 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2053 /* mute mono out if HP or Line out is plugged */
2054 static void via_mono_automute(struct hda_codec *codec)
2056 unsigned int hp_present, lineout_present;
2057 struct via_spec *spec = codec->spec;
2059 if (spec->codec_type != VT1716S)
2062 lineout_present = snd_hda_jack_detect(codec,
2063 spec->autocfg.line_out_pins[0]);
2065 /* Mute Mono Out if Line Out is plugged */
2066 if (lineout_present) {
2067 snd_hda_codec_amp_stereo(
2068 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
2072 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2074 if (!spec->hp_independent_mode)
2075 snd_hda_codec_amp_stereo(
2076 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
2077 hp_present ? HDA_AMP_MUTE : 0);
2080 static void via_gpio_control(struct hda_codec *codec)
2082 unsigned int gpio_data;
2083 unsigned int vol_counter;
2085 unsigned int master_vol;
2087 struct via_spec *spec = codec->spec;
2089 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
2090 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
2092 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
2093 0xF84, 0) & 0x3F0000) >> 16;
2095 vol = vol_counter & 0x1F;
2096 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
2097 AC_VERB_GET_AMP_GAIN_MUTE,
2100 if (gpio_data == 0x02) {
2101 /* unmute line out */
2102 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
2103 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
2105 if (vol_counter & 0x20) {
2106 /* decrease volume */
2107 if (vol > master_vol)
2109 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
2113 /* increase volume */
2114 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
2116 ((master_vol+vol) > 0x2A) ? 0x2A :
2119 } else if (!(gpio_data & 0x02)) {
2121 snd_hda_codec_amp_stereo(codec,
2122 spec->autocfg.line_out_pins[0],
2123 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2128 /* mute Internal-Speaker if HP is plugged */
2129 static void via_speaker_automute(struct hda_codec *codec)
2131 unsigned int hp_present;
2132 struct via_spec *spec = codec->spec;
2134 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2137 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2139 if (!spec->hp_independent_mode) {
2140 struct snd_ctl_elem_id id;
2141 snd_hda_codec_amp_stereo(
2142 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2143 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2145 memset(&id, 0, sizeof(id));
2146 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2147 strcpy(id.name, "Speaker Playback Switch");
2148 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2153 /* mute line-out and internal speaker if HP is plugged */
2154 static void via_hp_bind_automute(struct hda_codec *codec)
2156 /* use long instead of int below just to avoid an internal compiler
2157 * error with gcc 4.0.x
2159 unsigned long hp_present, present = 0;
2160 struct via_spec *spec = codec->spec;
2163 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2166 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2168 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2170 if (!spec->hp_independent_mode) {
2171 /* Mute Line-Outs */
2172 for (i = 0; i < spec->autocfg.line_outs; i++)
2173 snd_hda_codec_amp_stereo(
2174 codec, spec->autocfg.line_out_pins[i],
2176 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2178 present = hp_present;
2181 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2182 snd_hda_codec_amp_stereo(
2183 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2184 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2188 /* unsolicited event for jack sensing */
2189 static void via_unsol_event(struct hda_codec *codec,
2193 if (res & VIA_HP_EVENT)
2194 via_hp_automute(codec);
2195 if (res & VIA_GPIO_EVENT)
2196 via_gpio_control(codec);
2197 if (res & VIA_JACK_EVENT)
2198 set_jack_power_state(codec);
2199 if (res & VIA_MONO_EVENT)
2200 via_mono_automute(codec);
2201 if (res & VIA_SPEAKER_EVENT)
2202 via_speaker_automute(codec);
2203 if (res & VIA_BIND_HP_EVENT)
2204 via_hp_bind_automute(codec);
2207 static int via_init(struct hda_codec *codec)
2209 struct via_spec *spec = codec->spec;
2211 for (i = 0; i < spec->num_iverbs; i++)
2212 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2214 /* Lydia Add for EAPD enable */
2215 if (!spec->dig_in_nid) { /* No Digital In connection */
2216 if (spec->dig_in_pin) {
2217 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2218 AC_VERB_SET_PIN_WIDGET_CONTROL,
2220 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2221 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2223 } else /* enable SPDIF-input pin */
2224 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2225 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2227 /* assign slave outs */
2228 if (spec->slave_dig_outs[0])
2229 codec->slave_dig_outs = spec->slave_dig_outs;
2234 #ifdef SND_HDA_NEEDS_RESUME
2235 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2237 struct via_spec *spec = codec->spec;
2238 vt1708_stop_hp_work(spec);
2243 #ifdef CONFIG_SND_HDA_POWER_SAVE
2244 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2246 struct via_spec *spec = codec->spec;
2247 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2253 static struct hda_codec_ops via_patch_ops = {
2254 .build_controls = via_build_controls,
2255 .build_pcms = via_build_pcms,
2258 #ifdef SND_HDA_NEEDS_RESUME
2259 .suspend = via_suspend,
2261 #ifdef CONFIG_SND_HDA_POWER_SAVE
2262 .check_power_status = via_check_power_status,
2266 /* fill in the dac_nids table from the parsed pin configuration */
2267 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2268 const struct auto_pin_cfg *cfg)
2273 spec->multiout.num_dacs = cfg->line_outs;
2275 spec->multiout.dac_nids = spec->private_dac_nids;
2277 for (i = 0; i < 4; i++) {
2278 nid = cfg->line_out_pins[i];
2280 /* config dac list */
2282 case AUTO_SEQ_FRONT:
2283 spec->multiout.dac_nids[i] = 0x10;
2285 case AUTO_SEQ_CENLFE:
2286 spec->multiout.dac_nids[i] = 0x12;
2288 case AUTO_SEQ_SURROUND:
2289 spec->multiout.dac_nids[i] = 0x11;
2292 spec->multiout.dac_nids[i] = 0x13;
2301 /* add playback controls from the parsed DAC table */
2302 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2303 const struct auto_pin_cfg *cfg)
2306 static const char * const chname[4] = {
2307 "Front", "Surround", "C/LFE", "Side"
2309 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2312 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2313 nid = cfg->line_out_pins[i];
2318 nid_vol = nid_vols[i];
2320 if (i == AUTO_SEQ_CENLFE) {
2322 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2323 "Center Playback Volume",
2324 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2328 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2329 "LFE Playback Volume",
2330 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2334 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2335 "Center Playback Switch",
2336 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2340 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2341 "LFE Playback Switch",
2342 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2346 } else if (i == AUTO_SEQ_FRONT) {
2347 /* add control to mixer index 0 */
2348 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2349 "Master Front Playback Volume",
2350 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2354 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2355 "Master Front Playback Switch",
2356 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2361 /* add control to PW3 */
2362 sprintf(name, "%s Playback Volume", chname[i]);
2363 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2364 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2368 sprintf(name, "%s Playback Switch", chname[i]);
2369 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2370 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2375 sprintf(name, "%s Playback Volume", chname[i]);
2376 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2377 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2381 sprintf(name, "%s Playback Switch", chname[i]);
2382 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2383 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2393 static void create_hp_imux(struct via_spec *spec)
2396 struct hda_input_mux *imux = &spec->private_imux[1];
2397 static const char * const texts[] = { "OFF", "ON", NULL};
2399 /* for hp mode select */
2400 for (i = 0; texts[i]; i++)
2401 snd_hda_add_imux_item(imux, texts[i], i, NULL);
2403 spec->hp_mux = &spec->private_imux[1];
2406 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2413 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2414 spec->hp_independent_mode_index = 1;
2416 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2417 "Headphone Playback Volume",
2418 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2421 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2422 "Headphone Playback Switch",
2423 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2427 create_hp_imux(spec);
2432 /* create playback/capture controls for input pins */
2433 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
2434 const struct auto_pin_cfg *cfg,
2436 hda_nid_t pin_idxs[], int num_idxs)
2438 struct via_spec *spec = codec->spec;
2439 struct hda_input_mux *imux = &spec->private_imux[0];
2440 int i, err, idx, type, type_idx = 0;
2442 /* for internal loopback recording select */
2443 for (idx = 0; idx < num_idxs; idx++) {
2444 if (pin_idxs[idx] == 0xff) {
2445 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2450 for (i = 0; i < cfg->num_inputs; i++) {
2452 type = cfg->inputs[i].type;
2453 for (idx = 0; idx < num_idxs; idx++)
2454 if (pin_idxs[idx] == cfg->inputs[i].pin)
2456 if (idx >= num_idxs)
2458 if (i > 0 && type == cfg->inputs[i - 1].type)
2462 label = hda_get_autocfg_input_label(codec, cfg, i);
2463 if (spec->codec_type == VT1708S ||
2464 spec->codec_type == VT1702 ||
2465 spec->codec_type == VT1716S)
2466 err = via_new_analog_input(spec, label, type_idx,
2469 err = via_new_analog_input(spec, label, type_idx,
2473 snd_hda_add_imux_item(imux, label, idx, NULL);
2478 /* create playback/capture controls for input pins */
2479 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2480 const struct auto_pin_cfg *cfg)
2482 static hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2483 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
2484 ARRAY_SIZE(pin_idxs));
2487 #ifdef CONFIG_SND_HDA_POWER_SAVE
2488 static struct hda_amp_list vt1708_loopbacks[] = {
2489 { 0x17, HDA_INPUT, 1 },
2490 { 0x17, HDA_INPUT, 2 },
2491 { 0x17, HDA_INPUT, 3 },
2492 { 0x17, HDA_INPUT, 4 },
2497 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2499 unsigned int def_conf;
2500 unsigned char seqassoc;
2502 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2503 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2504 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2505 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2506 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2507 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2508 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2514 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2515 struct snd_ctl_elem_value *ucontrol)
2517 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2518 struct via_spec *spec = codec->spec;
2520 if (spec->codec_type != VT1708)
2522 spec->vt1708_jack_detectect =
2523 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2524 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2528 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2529 struct snd_ctl_elem_value *ucontrol)
2531 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2532 struct via_spec *spec = codec->spec;
2535 if (spec->codec_type != VT1708)
2537 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2538 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2539 == !spec->vt1708_jack_detectect;
2540 if (spec->vt1708_jack_detectect) {
2541 mute_aa_path(codec, 1);
2542 notify_aa_path_ctls(codec);
2547 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2549 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2550 .name = "Jack Detect",
2552 .info = snd_ctl_boolean_mono_info,
2553 .get = vt1708_jack_detectect_get,
2554 .put = vt1708_jack_detectect_put,
2559 static int vt1708_parse_auto_config(struct hda_codec *codec)
2561 struct via_spec *spec = codec->spec;
2564 /* Add HP and CD pin config connect bit re-config action */
2565 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2566 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2568 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2571 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2574 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2575 return 0; /* can't find valid BIOS pin config */
2577 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2580 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2583 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2586 /* add jack detect on/off control */
2587 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2591 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2593 if (spec->autocfg.dig_outs)
2594 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2595 spec->dig_in_pin = VT1708_DIGIN_PIN;
2596 if (spec->autocfg.dig_in_pin)
2597 spec->dig_in_nid = VT1708_DIGIN_NID;
2599 if (spec->kctls.list)
2600 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2602 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2604 spec->input_mux = &spec->private_imux[0];
2607 via_hp_build(codec);
2609 via_smart51_build(spec);
2613 /* init callback for auto-configuration model -- overriding the default init */
2614 static int via_auto_init(struct hda_codec *codec)
2616 struct via_spec *spec = codec->spec;
2619 via_auto_init_multi_out(codec);
2620 via_auto_init_hp_out(codec);
2621 via_auto_init_analog_input(codec);
2622 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2623 via_hp_bind_automute(codec);
2625 via_hp_automute(codec);
2626 via_speaker_automute(codec);
2632 static void vt1708_update_hp_jack_state(struct work_struct *work)
2634 struct via_spec *spec = container_of(work, struct via_spec,
2635 vt1708_hp_work.work);
2636 if (spec->codec_type != VT1708)
2638 /* if jack state toggled */
2639 if (spec->vt1708_hp_present
2640 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2641 spec->vt1708_hp_present ^= 1;
2642 via_hp_automute(spec->codec);
2644 vt1708_start_hp_work(spec);
2647 static int get_mux_nids(struct hda_codec *codec)
2649 struct via_spec *spec = codec->spec;
2650 hda_nid_t nid, conn[8];
2654 for (i = 0; i < spec->num_adc_nids; i++) {
2655 nid = spec->adc_nids[i];
2657 type = get_wcaps_type(get_wcaps(codec, nid));
2658 if (type == AC_WID_PIN)
2660 n = snd_hda_get_connections(codec, nid, conn,
2665 spec->mux_nids[i] = nid;
2674 static int patch_vt1708(struct hda_codec *codec)
2676 struct via_spec *spec;
2679 /* create a codec specific record */
2680 spec = via_new_spec(codec);
2684 /* automatic parse from the BIOS config */
2685 err = vt1708_parse_auto_config(codec);
2690 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2691 "from BIOS. Using genenic mode...\n");
2695 spec->stream_name_analog = "VT1708 Analog";
2696 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2697 /* disable 32bit format on VT1708 */
2698 if (codec->vendor_id == 0x11061708)
2699 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2700 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2702 spec->stream_name_digital = "VT1708 Digital";
2703 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2704 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2707 if (!spec->adc_nids && spec->input_mux) {
2708 spec->adc_nids = vt1708_adc_nids;
2709 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2710 get_mux_nids(codec);
2711 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2715 codec->patch_ops = via_patch_ops;
2717 codec->patch_ops.init = via_auto_init;
2718 #ifdef CONFIG_SND_HDA_POWER_SAVE
2719 spec->loopback.amplist = vt1708_loopbacks;
2721 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2725 /* capture mixer elements */
2726 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2727 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2728 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2729 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2730 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2731 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2732 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2734 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2735 /* The multiple "Capture Source" controls confuse alsamixer
2736 * So call somewhat different..
2738 /* .name = "Capture Source", */
2739 .name = "Input Source",
2741 .info = via_mux_enum_info,
2742 .get = via_mux_enum_get,
2743 .put = via_mux_enum_put,
2748 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2749 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2750 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2755 * generic initialization of ADC, input mixers and output mixers
2757 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2759 * Unmute ADC0-2 and set the default input to mic-in
2761 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2762 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2763 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2766 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2769 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2770 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2771 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2772 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2773 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2774 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2777 * Set up output selector (0x1a, 0x1b, 0x29)
2779 /* set vol=0 to output mixers */
2780 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2781 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2782 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2785 * Unmute PW3 and PW4
2787 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2788 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2790 /* Set input of PW4 as MW0 */
2791 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2792 /* PW9 Output enable */
2793 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2797 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2801 .nid = 0x10, /* NID to query formats and rates */
2803 .open = via_playback_pcm_open,
2804 .prepare = via_playback_multi_pcm_prepare,
2805 .cleanup = via_playback_multi_pcm_cleanup,
2809 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2813 .nid = 0x10, /* NID to query formats and rates */
2815 .open = via_playback_pcm_open,
2816 .prepare = via_playback_multi_pcm_prepare,
2817 .cleanup = via_playback_multi_pcm_cleanup,
2821 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2825 .nid = 0x14, /* NID to query formats and rates */
2827 .prepare = via_capture_pcm_prepare,
2828 .cleanup = via_capture_pcm_cleanup
2832 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2836 /* NID is set in via_build_pcms */
2838 .open = via_dig_playback_pcm_open,
2839 .close = via_dig_playback_pcm_close
2843 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2849 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2850 const struct auto_pin_cfg *cfg)
2855 if (cfg->line_outs == 4) /* 10 channels */
2856 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2857 else if (cfg->line_outs == 3) /* 6 channels */
2858 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2860 spec->multiout.dac_nids = spec->private_dac_nids;
2862 if (cfg->line_outs == 4) { /* 10 channels */
2863 for (i = 0; i < cfg->line_outs; i++) {
2864 nid = cfg->line_out_pins[i];
2866 /* config dac list */
2868 case AUTO_SEQ_FRONT:
2870 spec->multiout.dac_nids[i] = 0x10;
2872 case AUTO_SEQ_CENLFE:
2874 spec->multiout.dac_nids[i] = 0x12;
2876 case AUTO_SEQ_SURROUND:
2878 spec->multiout.dac_nids[i] = 0x11;
2882 spec->multiout.dac_nids[i] = 0x27;
2889 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2891 } else if (cfg->line_outs == 3) { /* 6 channels */
2892 for (i = 0; i < cfg->line_outs; i++) {
2893 nid = cfg->line_out_pins[i];
2895 /* config dac list */
2897 case AUTO_SEQ_FRONT:
2899 spec->multiout.dac_nids[i] = 0x10;
2901 case AUTO_SEQ_CENLFE:
2903 spec->multiout.dac_nids[i] = 0x12;
2905 case AUTO_SEQ_SURROUND:
2907 spec->multiout.dac_nids[i] = 0x11;
2919 /* add playback controls from the parsed DAC table */
2920 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2921 const struct auto_pin_cfg *cfg)
2924 static const char * const chname[4] = {
2925 "Front", "Surround", "C/LFE", "Side"
2927 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2930 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2931 nid = cfg->line_out_pins[i];
2936 nid_vol = nid_vols[i];
2938 if (i == AUTO_SEQ_CENLFE) {
2940 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2941 "Center Playback Volume",
2942 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2946 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2947 "LFE Playback Volume",
2948 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2952 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2953 "Center Playback Switch",
2954 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2958 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2959 "LFE Playback Switch",
2960 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2964 } else if (i == AUTO_SEQ_FRONT) {
2965 /* ADD control to mixer index 0 */
2966 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2967 "Master Front Playback Volume",
2968 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2972 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2973 "Master Front Playback Switch",
2974 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2979 /* add control to PW3 */
2980 sprintf(name, "%s Playback Volume", chname[i]);
2981 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2982 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2986 sprintf(name, "%s Playback Switch", chname[i]);
2987 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2988 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2992 } else if (i == AUTO_SEQ_SURROUND) {
2993 sprintf(name, "%s Playback Volume", chname[i]);
2994 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2995 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2999 sprintf(name, "%s Playback Switch", chname[i]);
3000 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3001 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3005 } else if (i == AUTO_SEQ_SIDE) {
3006 sprintf(name, "%s Playback Volume", chname[i]);
3007 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3008 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3012 sprintf(name, "%s Playback Switch", chname[i]);
3013 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3014 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3024 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3031 if (spec->multiout.num_dacs == 5) /* 10 channels */
3032 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
3033 else if (spec->multiout.num_dacs == 3) /* 6 channels */
3034 spec->multiout.hp_nid = 0;
3035 spec->hp_independent_mode_index = 1;
3037 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3038 "Headphone Playback Volume",
3039 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3042 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3043 "Headphone Playback Switch",
3044 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3051 /* create playback/capture controls for input pins */
3052 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
3053 const struct auto_pin_cfg *cfg)
3055 static hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
3056 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
3057 ARRAY_SIZE(pin_idxs));
3060 static int vt1709_parse_auto_config(struct hda_codec *codec)
3062 struct via_spec *spec = codec->spec;
3065 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3068 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
3071 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3072 return 0; /* can't find valid BIOS pin config */
3074 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
3077 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3080 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
3084 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3086 if (spec->autocfg.dig_outs)
3087 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3088 spec->dig_in_pin = VT1709_DIGIN_PIN;
3089 if (spec->autocfg.dig_in_pin)
3090 spec->dig_in_nid = VT1709_DIGIN_NID;
3092 if (spec->kctls.list)
3093 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3095 spec->input_mux = &spec->private_imux[0];
3098 via_hp_build(codec);
3100 via_smart51_build(spec);
3104 #ifdef CONFIG_SND_HDA_POWER_SAVE
3105 static struct hda_amp_list vt1709_loopbacks[] = {
3106 { 0x18, HDA_INPUT, 1 },
3107 { 0x18, HDA_INPUT, 2 },
3108 { 0x18, HDA_INPUT, 3 },
3109 { 0x18, HDA_INPUT, 4 },
3114 static int patch_vt1709_10ch(struct hda_codec *codec)
3116 struct via_spec *spec;
3119 /* create a codec specific record */
3120 spec = via_new_spec(codec);
3124 err = vt1709_parse_auto_config(codec);
3129 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3130 "Using genenic mode...\n");
3133 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3134 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3136 spec->stream_name_analog = "VT1709 Analog";
3137 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3138 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3140 spec->stream_name_digital = "VT1709 Digital";
3141 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3142 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3145 if (!spec->adc_nids && spec->input_mux) {
3146 spec->adc_nids = vt1709_adc_nids;
3147 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3148 get_mux_nids(codec);
3149 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3153 codec->patch_ops = via_patch_ops;
3155 codec->patch_ops.init = via_auto_init;
3156 codec->patch_ops.unsol_event = via_unsol_event;
3157 #ifdef CONFIG_SND_HDA_POWER_SAVE
3158 spec->loopback.amplist = vt1709_loopbacks;
3164 * generic initialization of ADC, input mixers and output mixers
3166 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3168 * Unmute ADC0-2 and set the default input to mic-in
3170 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3171 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3172 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3175 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3178 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3179 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3180 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3181 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3182 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3183 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3186 * Set up output selector (0x1a, 0x1b, 0x29)
3188 /* set vol=0 to output mixers */
3189 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3190 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3191 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3194 * Unmute PW3 and PW4
3196 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3197 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3199 /* Set input of PW4 as MW0 */
3200 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3201 /* PW9 Output enable */
3202 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3206 static int patch_vt1709_6ch(struct hda_codec *codec)
3208 struct via_spec *spec;
3211 /* create a codec specific record */
3212 spec = via_new_spec(codec);
3216 err = vt1709_parse_auto_config(codec);
3221 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3222 "Using genenic mode...\n");
3225 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3226 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3228 spec->stream_name_analog = "VT1709 Analog";
3229 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3230 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3232 spec->stream_name_digital = "VT1709 Digital";
3233 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3234 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3237 if (!spec->adc_nids && spec->input_mux) {
3238 spec->adc_nids = vt1709_adc_nids;
3239 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3240 get_mux_nids(codec);
3241 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3245 codec->patch_ops = via_patch_ops;
3247 codec->patch_ops.init = via_auto_init;
3248 codec->patch_ops.unsol_event = via_unsol_event;
3249 #ifdef CONFIG_SND_HDA_POWER_SAVE
3250 spec->loopback.amplist = vt1709_loopbacks;
3255 /* capture mixer elements */
3256 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3257 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3258 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3259 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3260 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3262 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3263 /* The multiple "Capture Source" controls confuse alsamixer
3264 * So call somewhat different..
3266 /* .name = "Capture Source", */
3267 .name = "Input Source",
3269 .info = via_mux_enum_info,
3270 .get = via_mux_enum_get,
3271 .put = via_mux_enum_put,
3276 * generic initialization of ADC, input mixers and output mixers
3278 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3280 * Unmute ADC0-1 and set the default input to mic-in
3282 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3283 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3286 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3289 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3290 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3291 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3292 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3293 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3294 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3297 * Set up output mixers
3299 /* set vol=0 to output mixers */
3300 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3301 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3302 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3304 /* Setup default input to PW4 */
3305 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3306 /* PW9 Output enable */
3307 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3308 /* PW10 Input enable */
3309 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3313 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3315 * Unmute ADC0-1 and set the default input to mic-in
3317 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3318 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3321 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3324 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3325 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3326 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3327 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3328 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3329 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3332 * Set up output mixers
3334 /* set vol=0 to output mixers */
3335 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3336 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3337 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3339 /* Setup default input of PW4 to MW0 */
3340 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3341 /* PW9 Output enable */
3342 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3343 /* PW10 Input enable */
3344 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3348 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3349 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3350 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3351 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3352 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3353 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3354 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3355 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3356 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3357 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3361 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3362 struct hda_codec *codec,
3363 struct snd_pcm_substream *substream)
3365 int idle = substream->pstr->substream_opened == 1
3366 && substream->ref_count == 0;
3368 analog_low_current_mode(codec, idle);
3372 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3376 .nid = 0x10, /* NID to query formats and rates */
3378 .open = via_playback_pcm_open,
3379 .prepare = via_playback_multi_pcm_prepare,
3380 .cleanup = via_playback_multi_pcm_cleanup,
3381 .close = via_pcm_open_close
3385 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3389 .nid = 0x10, /* NID to query formats and rates */
3391 .open = via_playback_pcm_open,
3392 .prepare = via_playback_multi_pcm_prepare,
3393 .cleanup = via_playback_multi_pcm_cleanup
3397 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3401 .nid = 0x13, /* NID to query formats and rates */
3403 .open = via_pcm_open_close,
3404 .prepare = via_capture_pcm_prepare,
3405 .cleanup = via_capture_pcm_cleanup,
3406 .close = via_pcm_open_close
3410 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3414 /* NID is set in via_build_pcms */
3416 .open = via_dig_playback_pcm_open,
3417 .close = via_dig_playback_pcm_close,
3418 .prepare = via_dig_playback_pcm_prepare,
3419 .cleanup = via_dig_playback_pcm_cleanup
3423 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3429 /* fill in the dac_nids table from the parsed pin configuration */
3430 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3431 const struct auto_pin_cfg *cfg)
3436 spec->multiout.num_dacs = cfg->line_outs;
3438 spec->multiout.dac_nids = spec->private_dac_nids;
3440 for (i = 0; i < 4; i++) {
3441 nid = cfg->line_out_pins[i];
3443 /* config dac list */
3445 case AUTO_SEQ_FRONT:
3446 spec->multiout.dac_nids[i] = 0x10;
3448 case AUTO_SEQ_CENLFE:
3449 spec->multiout.dac_nids[i] = 0x24;
3451 case AUTO_SEQ_SURROUND:
3452 spec->multiout.dac_nids[i] = 0x11;
3455 spec->multiout.dac_nids[i] = 0x25;
3464 /* add playback controls from the parsed DAC table */
3465 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3466 const struct auto_pin_cfg *cfg)
3469 static const char * const chname[4] = {
3470 "Front", "Surround", "C/LFE", "Side"
3472 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3473 hda_nid_t nid, nid_vol = 0;
3476 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3477 nid = cfg->line_out_pins[i];
3482 nid_vol = nid_vols[i];
3484 if (i == AUTO_SEQ_CENLFE) {
3486 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3487 "Center Playback Volume",
3488 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3492 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3493 "LFE Playback Volume",
3494 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3498 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3499 "Center Playback Switch",
3500 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3504 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3505 "LFE Playback Switch",
3506 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3510 } else if (i == AUTO_SEQ_FRONT) {
3511 /* add control to mixer index 0 */
3512 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3513 "Master Front Playback Volume",
3514 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3518 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3519 "Master Front Playback Switch",
3520 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3525 /* add control to PW3 */
3526 sprintf(name, "%s Playback Volume", chname[i]);
3527 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3528 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3532 sprintf(name, "%s Playback Switch", chname[i]);
3533 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3534 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3539 sprintf(name, "%s Playback Volume", chname[i]);
3540 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3541 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3545 sprintf(name, "%s Playback Switch", chname[i]);
3546 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3547 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3557 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3564 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3565 spec->hp_independent_mode_index = 1;
3567 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3568 "Headphone Playback Volume",
3569 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3572 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3573 "Headphone Playback Switch",
3574 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3578 create_hp_imux(spec);
3583 /* create playback/capture controls for input pins */
3584 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3585 const struct auto_pin_cfg *cfg)
3587 static hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3588 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3589 ARRAY_SIZE(pin_idxs));
3592 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3594 struct via_spec *spec = codec->spec;
3597 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3600 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3603 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3604 return 0; /* can't find valid BIOS pin config */
3606 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3609 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3612 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3616 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3618 if (spec->autocfg.dig_outs)
3619 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3620 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3621 if (spec->autocfg.dig_in_pin)
3622 spec->dig_in_nid = VT1708B_DIGIN_NID;
3624 if (spec->kctls.list)
3625 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3627 spec->input_mux = &spec->private_imux[0];
3630 via_hp_build(codec);
3632 via_smart51_build(spec);
3636 #ifdef CONFIG_SND_HDA_POWER_SAVE
3637 static struct hda_amp_list vt1708B_loopbacks[] = {
3638 { 0x16, HDA_INPUT, 1 },
3639 { 0x16, HDA_INPUT, 2 },
3640 { 0x16, HDA_INPUT, 3 },
3641 { 0x16, HDA_INPUT, 4 },
3645 static int patch_vt1708S(struct hda_codec *codec);
3646 static int patch_vt1708B_8ch(struct hda_codec *codec)
3648 struct via_spec *spec;
3651 if (get_codec_type(codec) == VT1708BCE)
3652 return patch_vt1708S(codec);
3653 /* create a codec specific record */
3654 spec = via_new_spec(codec);
3658 /* automatic parse from the BIOS config */
3659 err = vt1708B_parse_auto_config(codec);
3664 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3665 "from BIOS. Using genenic mode...\n");
3668 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3669 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3671 spec->stream_name_analog = "VT1708B Analog";
3672 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3673 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3675 spec->stream_name_digital = "VT1708B Digital";
3676 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3677 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3679 if (!spec->adc_nids && spec->input_mux) {
3680 spec->adc_nids = vt1708B_adc_nids;
3681 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3682 get_mux_nids(codec);
3683 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3687 codec->patch_ops = via_patch_ops;
3689 codec->patch_ops.init = via_auto_init;
3690 codec->patch_ops.unsol_event = via_unsol_event;
3691 #ifdef CONFIG_SND_HDA_POWER_SAVE
3692 spec->loopback.amplist = vt1708B_loopbacks;
3698 static int patch_vt1708B_4ch(struct hda_codec *codec)
3700 struct via_spec *spec;
3703 /* create a codec specific record */
3704 spec = via_new_spec(codec);
3708 /* automatic parse from the BIOS config */
3709 err = vt1708B_parse_auto_config(codec);
3714 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3715 "from BIOS. Using genenic mode...\n");
3718 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3719 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3721 spec->stream_name_analog = "VT1708B Analog";
3722 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3723 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3725 spec->stream_name_digital = "VT1708B Digital";
3726 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3727 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3729 if (!spec->adc_nids && spec->input_mux) {
3730 spec->adc_nids = vt1708B_adc_nids;
3731 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3732 get_mux_nids(codec);
3733 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3737 codec->patch_ops = via_patch_ops;
3739 codec->patch_ops.init = via_auto_init;
3740 codec->patch_ops.unsol_event = via_unsol_event;
3741 #ifdef CONFIG_SND_HDA_POWER_SAVE
3742 spec->loopback.amplist = vt1708B_loopbacks;
3748 /* Patch for VT1708S */
3750 /* capture mixer elements */
3751 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3752 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3753 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3754 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3755 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3756 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3757 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3761 /* The multiple "Capture Source" controls confuse alsamixer
3762 * So call somewhat different..
3764 /* .name = "Capture Source", */
3765 .name = "Input Source",
3767 .info = via_mux_enum_info,
3768 .get = via_mux_enum_get,
3769 .put = via_mux_enum_put,
3774 static struct hda_verb vt1708S_volume_init_verbs[] = {
3775 /* Unmute ADC0-1 and set the default input to mic-in */
3776 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3777 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3779 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3780 * analog-loopback mixer widget */
3781 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3782 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3783 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3784 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3785 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3786 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3788 /* Setup default input of PW4 to MW0 */
3789 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3790 /* PW9, PW10 Output enable */
3791 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3792 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3793 /* Enable Mic Boost Volume backdoor */
3795 /* don't bybass mixer */
3800 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3801 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3802 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3803 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3804 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3805 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3806 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3807 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3808 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3809 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3813 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3817 .nid = 0x10, /* NID to query formats and rates */
3819 .open = via_playback_pcm_open,
3820 .prepare = via_playback_multi_pcm_prepare,
3821 .cleanup = via_playback_multi_pcm_cleanup,
3822 .close = via_pcm_open_close
3826 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3830 .nid = 0x13, /* NID to query formats and rates */
3832 .open = via_pcm_open_close,
3833 .prepare = via_capture_pcm_prepare,
3834 .cleanup = via_capture_pcm_cleanup,
3835 .close = via_pcm_open_close
3839 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3843 /* NID is set in via_build_pcms */
3845 .open = via_dig_playback_pcm_open,
3846 .close = via_dig_playback_pcm_close,
3847 .prepare = via_dig_playback_pcm_prepare,
3848 .cleanup = via_dig_playback_pcm_cleanup
3852 /* fill in the dac_nids table from the parsed pin configuration */
3853 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3854 const struct auto_pin_cfg *cfg)
3859 spec->multiout.num_dacs = cfg->line_outs;
3861 spec->multiout.dac_nids = spec->private_dac_nids;
3863 for (i = 0; i < 4; i++) {
3864 nid = cfg->line_out_pins[i];
3866 /* config dac list */
3868 case AUTO_SEQ_FRONT:
3869 spec->multiout.dac_nids[i] = 0x10;
3871 case AUTO_SEQ_CENLFE:
3872 spec->multiout.dac_nids[i] = 0x24;
3874 case AUTO_SEQ_SURROUND:
3875 spec->multiout.dac_nids[i] = 0x11;
3878 spec->multiout.dac_nids[i] = 0x25;
3884 /* for Smart 5.1, line/mic inputs double as output pins */
3885 if (cfg->line_outs == 1) {
3886 spec->multiout.num_dacs = 3;
3887 spec->multiout.dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3888 spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3894 /* add playback controls from the parsed DAC table */
3895 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3896 const struct auto_pin_cfg *cfg)
3899 static const char * const chname[4] = {
3900 "Front", "Surround", "C/LFE", "Side"
3902 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3903 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3904 hda_nid_t nid, nid_vol, nid_mute;
3907 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3908 nid = cfg->line_out_pins[i];
3910 /* for Smart 5.1, there are always at least six channels */
3911 if (!nid && i > AUTO_SEQ_CENLFE)
3914 nid_vol = nid_vols[i];
3915 nid_mute = nid_mutes[i];
3917 if (i == AUTO_SEQ_CENLFE) {
3919 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3920 "Center Playback Volume",
3921 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3925 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3926 "LFE Playback Volume",
3927 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3931 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3932 "Center Playback Switch",
3933 HDA_COMPOSE_AMP_VAL(nid_mute,
3938 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3939 "LFE Playback Switch",
3940 HDA_COMPOSE_AMP_VAL(nid_mute,
3945 } else if (i == AUTO_SEQ_FRONT) {
3946 /* add control to mixer index 0 */
3947 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3948 "Master Front Playback Volume",
3949 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3953 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3954 "Master Front Playback Switch",
3955 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3961 sprintf(name, "%s Playback Volume", chname[i]);
3962 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3963 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3967 sprintf(name, "%s Playback Switch", chname[i]);
3968 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3969 HDA_COMPOSE_AMP_VAL(nid_mute,
3975 sprintf(name, "%s Playback Volume", chname[i]);
3976 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3977 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3981 sprintf(name, "%s Playback Switch", chname[i]);
3982 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3983 HDA_COMPOSE_AMP_VAL(nid_mute,
3994 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4001 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
4002 spec->hp_independent_mode_index = 1;
4004 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4005 "Headphone Playback Volume",
4006 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
4010 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4011 "Headphone Playback Switch",
4012 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4016 create_hp_imux(spec);
4021 /* create playback/capture controls for input pins */
4022 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
4023 const struct auto_pin_cfg *cfg)
4025 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
4026 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
4027 ARRAY_SIZE(pin_idxs));
4030 /* fill out digital output widgets; one for master and one for slave outputs */
4031 static void fill_dig_outs(struct hda_codec *codec)
4033 struct via_spec *spec = codec->spec;
4036 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4040 nid = spec->autocfg.dig_out_pins[i];
4043 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4046 if (!spec->multiout.dig_out_nid)
4047 spec->multiout.dig_out_nid = nid;
4049 spec->slave_dig_outs[0] = nid;
4050 break; /* at most two dig outs */
4055 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4057 struct via_spec *spec = codec->spec;
4060 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4063 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4066 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4067 return 0; /* can't find valid BIOS pin config */
4069 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4072 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4075 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4079 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4081 fill_dig_outs(codec);
4083 if (spec->kctls.list)
4084 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4086 spec->input_mux = &spec->private_imux[0];
4089 via_hp_build(codec);
4091 via_smart51_build(spec);
4095 #ifdef CONFIG_SND_HDA_POWER_SAVE
4096 static struct hda_amp_list vt1708S_loopbacks[] = {
4097 { 0x16, HDA_INPUT, 1 },
4098 { 0x16, HDA_INPUT, 2 },
4099 { 0x16, HDA_INPUT, 3 },
4100 { 0x16, HDA_INPUT, 4 },
4105 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4106 int offset, int num_steps, int step_size)
4108 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4109 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4110 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4111 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4112 (0 << AC_AMPCAP_MUTE_SHIFT));
4115 static int patch_vt1708S(struct hda_codec *codec)
4117 struct via_spec *spec;
4120 /* create a codec specific record */
4121 spec = via_new_spec(codec);
4125 /* automatic parse from the BIOS config */
4126 err = vt1708S_parse_auto_config(codec);
4131 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4132 "from BIOS. Using genenic mode...\n");
4135 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4136 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4138 if (codec->vendor_id == 0x11060440)
4139 spec->stream_name_analog = "VT1818S Analog";
4141 spec->stream_name_analog = "VT1708S Analog";
4142 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4143 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4145 if (codec->vendor_id == 0x11060440)
4146 spec->stream_name_digital = "VT1818S Digital";
4148 spec->stream_name_digital = "VT1708S Digital";
4149 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4151 if (!spec->adc_nids && spec->input_mux) {
4152 spec->adc_nids = vt1708S_adc_nids;
4153 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4154 get_mux_nids(codec);
4155 override_mic_boost(codec, 0x1a, 0, 3, 40);
4156 override_mic_boost(codec, 0x1e, 0, 3, 40);
4157 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4161 codec->patch_ops = via_patch_ops;
4163 codec->patch_ops.init = via_auto_init;
4164 codec->patch_ops.unsol_event = via_unsol_event;
4165 #ifdef CONFIG_SND_HDA_POWER_SAVE
4166 spec->loopback.amplist = vt1708S_loopbacks;
4169 /* correct names for VT1708BCE */
4170 if (get_codec_type(codec) == VT1708BCE) {
4171 kfree(codec->chip_name);
4172 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4173 snprintf(codec->bus->card->mixername,
4174 sizeof(codec->bus->card->mixername),
4175 "%s %s", codec->vendor_name, codec->chip_name);
4176 spec->stream_name_analog = "VT1708BCE Analog";
4177 spec->stream_name_digital = "VT1708BCE Digital";
4179 /* correct names for VT1818S */
4180 if (codec->vendor_id == 0x11060440) {
4181 spec->stream_name_analog = "VT1818S Analog";
4182 spec->stream_name_digital = "VT1818S Digital";
4187 /* Patch for VT1702 */
4189 /* capture mixer elements */
4190 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4191 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4192 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4193 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4194 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4195 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4196 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4197 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4200 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4201 /* The multiple "Capture Source" controls confuse alsamixer
4202 * So call somewhat different..
4204 /* .name = "Capture Source", */
4205 .name = "Input Source",
4207 .info = via_mux_enum_info,
4208 .get = via_mux_enum_get,
4209 .put = via_mux_enum_put,
4214 static struct hda_verb vt1702_volume_init_verbs[] = {
4216 * Unmute ADC0-1 and set the default input to mic-in
4218 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4219 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4220 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4223 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4226 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4227 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4228 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4229 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4230 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4231 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4233 /* Setup default input of PW4 to MW0 */
4234 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4235 /* PW6 PW7 Output enable */
4236 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4237 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4245 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4246 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4247 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4248 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4249 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4250 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4251 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4255 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4259 .nid = 0x10, /* NID to query formats and rates */
4261 .open = via_playback_pcm_open,
4262 .prepare = via_playback_multi_pcm_prepare,
4263 .cleanup = via_playback_multi_pcm_cleanup,
4264 .close = via_pcm_open_close
4268 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4272 .nid = 0x12, /* NID to query formats and rates */
4274 .open = via_pcm_open_close,
4275 .prepare = via_capture_pcm_prepare,
4276 .cleanup = via_capture_pcm_cleanup,
4277 .close = via_pcm_open_close
4281 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4285 /* NID is set in via_build_pcms */
4287 .open = via_dig_playback_pcm_open,
4288 .close = via_dig_playback_pcm_close,
4289 .prepare = via_dig_playback_pcm_prepare,
4290 .cleanup = via_dig_playback_pcm_cleanup
4294 /* fill in the dac_nids table from the parsed pin configuration */
4295 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4296 const struct auto_pin_cfg *cfg)
4298 spec->multiout.num_dacs = 1;
4299 spec->multiout.dac_nids = spec->private_dac_nids;
4301 if (cfg->line_out_pins[0]) {
4302 /* config dac list */
4303 spec->multiout.dac_nids[0] = 0x10;
4309 /* add playback controls from the parsed DAC table */
4310 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4311 const struct auto_pin_cfg *cfg)
4315 if (!cfg->line_out_pins[0])
4318 /* add control to mixer index 0 */
4319 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4320 "Master Front Playback Volume",
4321 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4324 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4325 "Master Front Playback Switch",
4326 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4331 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4332 "Front Playback Volume",
4333 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4336 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4337 "Front Playback Switch",
4338 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4345 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4348 struct hda_input_mux *imux;
4349 static const char * const texts[] = { "ON", "OFF", NULL};
4352 spec->multiout.hp_nid = 0x1D;
4353 spec->hp_independent_mode_index = 0;
4355 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4356 "Headphone Playback Volume",
4357 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4361 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4362 "Headphone Playback Switch",
4363 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4367 imux = &spec->private_imux[1];
4369 /* for hp mode select */
4370 for (i = 0; texts[i]; i++)
4371 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4373 spec->hp_mux = &spec->private_imux[1];
4377 /* create playback/capture controls for input pins */
4378 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4379 const struct auto_pin_cfg *cfg)
4381 static hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4382 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
4383 ARRAY_SIZE(pin_idxs));
4386 static int vt1702_parse_auto_config(struct hda_codec *codec)
4388 struct via_spec *spec = codec->spec;
4391 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4394 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4397 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4398 return 0; /* can't find valid BIOS pin config */
4400 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4403 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4406 /* limit AA path volume to 0 dB */
4407 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4408 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4409 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4410 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4411 (1 << AC_AMPCAP_MUTE_SHIFT));
4412 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4416 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4418 fill_dig_outs(codec);
4420 if (spec->kctls.list)
4421 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4423 spec->input_mux = &spec->private_imux[0];
4426 via_hp_build(codec);
4431 #ifdef CONFIG_SND_HDA_POWER_SAVE
4432 static struct hda_amp_list vt1702_loopbacks[] = {
4433 { 0x1A, HDA_INPUT, 1 },
4434 { 0x1A, HDA_INPUT, 2 },
4435 { 0x1A, HDA_INPUT, 3 },
4436 { 0x1A, HDA_INPUT, 4 },
4441 static int patch_vt1702(struct hda_codec *codec)
4443 struct via_spec *spec;
4446 /* create a codec specific record */
4447 spec = via_new_spec(codec);
4451 /* automatic parse from the BIOS config */
4452 err = vt1702_parse_auto_config(codec);
4457 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4458 "from BIOS. Using genenic mode...\n");
4461 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4462 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4464 spec->stream_name_analog = "VT1702 Analog";
4465 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4466 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4468 spec->stream_name_digital = "VT1702 Digital";
4469 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4471 if (!spec->adc_nids && spec->input_mux) {
4472 spec->adc_nids = vt1702_adc_nids;
4473 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4474 get_mux_nids(codec);
4475 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4479 codec->patch_ops = via_patch_ops;
4481 codec->patch_ops.init = via_auto_init;
4482 codec->patch_ops.unsol_event = via_unsol_event;
4483 #ifdef CONFIG_SND_HDA_POWER_SAVE
4484 spec->loopback.amplist = vt1702_loopbacks;
4490 /* Patch for VT1718S */
4492 /* capture mixer elements */
4493 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4494 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4495 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4496 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4497 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4498 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4499 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4502 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4503 /* The multiple "Capture Source" controls confuse alsamixer
4504 * So call somewhat different..
4506 .name = "Input Source",
4508 .info = via_mux_enum_info,
4509 .get = via_mux_enum_get,
4510 .put = via_mux_enum_put,
4515 static struct hda_verb vt1718S_volume_init_verbs[] = {
4517 * Unmute ADC0-1 and set the default input to mic-in
4519 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4520 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4523 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4526 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4527 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4528 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4529 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4530 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4531 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4533 /* Setup default input of Front HP to MW9 */
4534 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4535 /* PW9 PW10 Output enable */
4536 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4537 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4538 /* PW11 Input enable */
4539 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4540 /* Enable Boost Volume backdoor */
4542 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4543 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4544 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4545 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4546 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4547 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4548 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4549 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4550 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4551 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4552 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4553 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4554 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4555 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4556 /* Unmute MW4's index 0 */
4557 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4562 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4563 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4564 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4565 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4566 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4567 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4568 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4569 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4570 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4571 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4575 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4579 .nid = 0x8, /* NID to query formats and rates */
4581 .open = via_playback_pcm_open,
4582 .prepare = via_playback_multi_pcm_prepare,
4583 .cleanup = via_playback_multi_pcm_cleanup,
4584 .close = via_pcm_open_close,
4588 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4592 .nid = 0x10, /* NID to query formats and rates */
4594 .open = via_pcm_open_close,
4595 .prepare = via_capture_pcm_prepare,
4596 .cleanup = via_capture_pcm_cleanup,
4597 .close = via_pcm_open_close,
4601 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4605 /* NID is set in via_build_pcms */
4607 .open = via_dig_playback_pcm_open,
4608 .close = via_dig_playback_pcm_close,
4609 .prepare = via_dig_playback_pcm_prepare,
4610 .cleanup = via_dig_playback_pcm_cleanup
4614 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4620 /* fill in the dac_nids table from the parsed pin configuration */
4621 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4622 const struct auto_pin_cfg *cfg)
4627 spec->multiout.num_dacs = cfg->line_outs;
4629 spec->multiout.dac_nids = spec->private_dac_nids;
4631 for (i = 0; i < 4; i++) {
4632 nid = cfg->line_out_pins[i];
4634 /* config dac list */
4636 case AUTO_SEQ_FRONT:
4637 spec->multiout.dac_nids[i] = 0x8;
4639 case AUTO_SEQ_CENLFE:
4640 spec->multiout.dac_nids[i] = 0xa;
4642 case AUTO_SEQ_SURROUND:
4643 spec->multiout.dac_nids[i] = 0x9;
4646 spec->multiout.dac_nids[i] = 0xb;
4655 /* add playback controls from the parsed DAC table */
4656 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4657 const struct auto_pin_cfg *cfg)
4660 static const char * const chname[4] = {
4661 "Front", "Surround", "C/LFE", "Side"
4663 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4664 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4665 hda_nid_t nid, nid_vol, nid_mute = 0;
4668 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4669 nid = cfg->line_out_pins[i];
4673 nid_vol = nid_vols[i];
4674 nid_mute = nid_mutes[i];
4676 if (i == AUTO_SEQ_CENLFE) {
4678 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4679 "Center Playback Volume",
4680 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4684 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4685 "LFE Playback Volume",
4686 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4690 err = via_add_control(
4691 spec, VIA_CTL_WIDGET_MUTE,
4692 "Center Playback Switch",
4693 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4697 err = via_add_control(
4698 spec, VIA_CTL_WIDGET_MUTE,
4699 "LFE Playback Switch",
4700 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4704 } else if (i == AUTO_SEQ_FRONT) {
4706 sprintf(name, "%s Playback Volume", chname[i]);
4707 err = via_add_control(
4708 spec, VIA_CTL_WIDGET_VOL, name,
4709 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4712 sprintf(name, "%s Playback Switch", chname[i]);
4713 err = via_add_control(
4714 spec, VIA_CTL_WIDGET_MUTE, name,
4715 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4720 sprintf(name, "%s Playback Volume", chname[i]);
4721 err = via_add_control(
4722 spec, VIA_CTL_WIDGET_VOL, name,
4723 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4726 sprintf(name, "%s Playback Switch", chname[i]);
4727 err = via_add_control(
4728 spec, VIA_CTL_WIDGET_MUTE, name,
4729 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4738 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4745 spec->multiout.hp_nid = 0xc; /* AOW4 */
4746 spec->hp_independent_mode_index = 1;
4748 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4749 "Headphone Playback Volume",
4750 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4754 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4755 "Headphone Playback Switch",
4756 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4760 create_hp_imux(spec);
4764 /* create playback/capture controls for input pins */
4765 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4766 const struct auto_pin_cfg *cfg)
4768 static hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4769 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
4770 ARRAY_SIZE(pin_idxs));
4773 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4775 struct via_spec *spec = codec->spec;
4778 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4782 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4785 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4786 return 0; /* can't find valid BIOS pin config */
4788 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4791 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4794 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4798 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4800 fill_dig_outs(codec);
4802 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4803 spec->dig_in_nid = 0x13;
4805 if (spec->kctls.list)
4806 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4808 spec->input_mux = &spec->private_imux[0];
4811 via_hp_build(codec);
4813 via_smart51_build(spec);
4818 #ifdef CONFIG_SND_HDA_POWER_SAVE
4819 static struct hda_amp_list vt1718S_loopbacks[] = {
4820 { 0x21, HDA_INPUT, 1 },
4821 { 0x21, HDA_INPUT, 2 },
4822 { 0x21, HDA_INPUT, 3 },
4823 { 0x21, HDA_INPUT, 4 },
4828 static int patch_vt1718S(struct hda_codec *codec)
4830 struct via_spec *spec;
4833 /* create a codec specific record */
4834 spec = via_new_spec(codec);
4838 /* automatic parse from the BIOS config */
4839 err = vt1718S_parse_auto_config(codec);
4844 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4845 "from BIOS. Using genenic mode...\n");
4848 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4849 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4851 if (codec->vendor_id == 0x11060441)
4852 spec->stream_name_analog = "VT2020 Analog";
4853 else if (codec->vendor_id == 0x11064441)
4854 spec->stream_name_analog = "VT1828S Analog";
4856 spec->stream_name_analog = "VT1718S Analog";
4857 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4858 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4860 if (codec->vendor_id == 0x11060441)
4861 spec->stream_name_digital = "VT2020 Digital";
4862 else if (codec->vendor_id == 0x11064441)
4863 spec->stream_name_digital = "VT1828S Digital";
4865 spec->stream_name_digital = "VT1718S Digital";
4866 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4867 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4868 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4870 if (!spec->adc_nids && spec->input_mux) {
4871 spec->adc_nids = vt1718S_adc_nids;
4872 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4873 get_mux_nids(codec);
4874 override_mic_boost(codec, 0x2b, 0, 3, 40);
4875 override_mic_boost(codec, 0x29, 0, 3, 40);
4876 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4880 codec->patch_ops = via_patch_ops;
4882 codec->patch_ops.init = via_auto_init;
4883 codec->patch_ops.unsol_event = via_unsol_event;
4885 #ifdef CONFIG_SND_HDA_POWER_SAVE
4886 spec->loopback.amplist = vt1718S_loopbacks;
4892 /* Patch for VT1716S */
4894 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4895 struct snd_ctl_elem_info *uinfo)
4897 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4899 uinfo->value.integer.min = 0;
4900 uinfo->value.integer.max = 1;
4904 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4905 struct snd_ctl_elem_value *ucontrol)
4907 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4910 index = snd_hda_codec_read(codec, 0x26, 0,
4911 AC_VERB_GET_CONNECT_SEL, 0);
4913 *ucontrol->value.integer.value = index;
4918 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4919 struct snd_ctl_elem_value *ucontrol)
4921 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4922 struct via_spec *spec = codec->spec;
4923 int index = *ucontrol->value.integer.value;
4925 snd_hda_codec_write(codec, 0x26, 0,
4926 AC_VERB_SET_CONNECT_SEL, index);
4927 spec->dmic_enabled = index;
4928 set_jack_power_state(codec);
4933 /* capture mixer elements */
4934 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4935 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4936 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4937 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4938 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4939 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4940 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4943 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4944 .name = "Input Source",
4946 .info = via_mux_enum_info,
4947 .get = via_mux_enum_get,
4948 .put = via_mux_enum_put,
4953 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4954 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4956 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4957 .name = "Digital Mic Capture Switch",
4958 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4960 .info = vt1716s_dmic_info,
4961 .get = vt1716s_dmic_get,
4962 .put = vt1716s_dmic_put,
4968 /* mono-out mixer elements */
4969 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4970 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4974 static struct hda_verb vt1716S_volume_init_verbs[] = {
4976 * Unmute ADC0-1 and set the default input to mic-in
4978 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4979 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4982 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4985 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4986 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4987 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4988 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4989 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4990 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4992 /* MUX Indices: Stereo Mixer = 5 */
4993 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4995 /* Setup default input of PW4 to MW0 */
4996 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4998 /* Setup default input of SW1 as MW0 */
4999 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5001 /* Setup default input of SW4 as AOW0 */
5002 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5004 /* PW9 PW10 Output enable */
5005 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5006 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5008 /* Unmute SW1, PW12 */
5009 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5010 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5011 /* PW12 Output enable */
5012 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5013 /* Enable Boost Volume backdoor */
5015 /* don't bybass mixer */
5017 /* Enable mono output */
5023 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5024 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5025 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5026 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5027 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5028 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5029 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5030 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5031 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5032 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5036 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5040 .nid = 0x10, /* NID to query formats and rates */
5042 .open = via_playback_pcm_open,
5043 .prepare = via_playback_multi_pcm_prepare,
5044 .cleanup = via_playback_multi_pcm_cleanup,
5045 .close = via_pcm_open_close,
5049 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5053 .nid = 0x13, /* NID to query formats and rates */
5055 .open = via_pcm_open_close,
5056 .prepare = via_capture_pcm_prepare,
5057 .cleanup = via_capture_pcm_cleanup,
5058 .close = via_pcm_open_close,
5062 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5066 /* NID is set in via_build_pcms */
5068 .open = via_dig_playback_pcm_open,
5069 .close = via_dig_playback_pcm_close,
5070 .prepare = via_dig_playback_pcm_prepare,
5071 .cleanup = via_dig_playback_pcm_cleanup
5075 /* fill in the dac_nids table from the parsed pin configuration */
5076 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5077 const struct auto_pin_cfg *cfg)
5081 spec->multiout.num_dacs = cfg->line_outs;
5083 spec->multiout.dac_nids = spec->private_dac_nids;
5085 for (i = 0; i < 3; i++) {
5086 nid = cfg->line_out_pins[i];
5088 /* config dac list */
5090 case AUTO_SEQ_FRONT:
5091 spec->multiout.dac_nids[i] = 0x10;
5093 case AUTO_SEQ_CENLFE:
5094 spec->multiout.dac_nids[i] = 0x25;
5096 case AUTO_SEQ_SURROUND:
5097 spec->multiout.dac_nids[i] = 0x11;
5106 /* add playback controls from the parsed DAC table */
5107 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5108 const struct auto_pin_cfg *cfg)
5111 static const char * const chname[3] = {
5112 "Front", "Surround", "C/LFE"
5114 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5115 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5116 hda_nid_t nid, nid_vol, nid_mute;
5119 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5120 nid = cfg->line_out_pins[i];
5125 nid_vol = nid_vols[i];
5126 nid_mute = nid_mutes[i];
5128 if (i == AUTO_SEQ_CENLFE) {
5129 err = via_add_control(
5130 spec, VIA_CTL_WIDGET_VOL,
5131 "Center Playback Volume",
5132 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5135 err = via_add_control(
5136 spec, VIA_CTL_WIDGET_VOL,
5137 "LFE Playback Volume",
5138 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5141 err = via_add_control(
5142 spec, VIA_CTL_WIDGET_MUTE,
5143 "Center Playback Switch",
5144 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5148 err = via_add_control(
5149 spec, VIA_CTL_WIDGET_MUTE,
5150 "LFE Playback Switch",
5151 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5155 } else if (i == AUTO_SEQ_FRONT) {
5157 err = via_add_control(
5158 spec, VIA_CTL_WIDGET_VOL,
5159 "Master Front Playback Volume",
5160 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5163 err = via_add_control(
5164 spec, VIA_CTL_WIDGET_MUTE,
5165 "Master Front Playback Switch",
5166 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5170 sprintf(name, "%s Playback Volume", chname[i]);
5171 err = via_add_control(
5172 spec, VIA_CTL_WIDGET_VOL, name,
5173 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5176 sprintf(name, "%s Playback Switch", chname[i]);
5177 err = via_add_control(
5178 spec, VIA_CTL_WIDGET_MUTE, name,
5179 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5184 sprintf(name, "%s Playback Volume", chname[i]);
5185 err = via_add_control(
5186 spec, VIA_CTL_WIDGET_VOL, name,
5187 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5190 sprintf(name, "%s Playback Switch", chname[i]);
5191 err = via_add_control(
5192 spec, VIA_CTL_WIDGET_MUTE, name,
5193 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5202 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5209 spec->multiout.hp_nid = 0x25; /* AOW3 */
5210 spec->hp_independent_mode_index = 1;
5212 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5213 "Headphone Playback Volume",
5214 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5218 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5219 "Headphone Playback Switch",
5220 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5224 create_hp_imux(spec);
5228 /* create playback/capture controls for input pins */
5229 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5230 const struct auto_pin_cfg *cfg)
5232 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5233 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
5234 ARRAY_SIZE(pin_idxs));
5237 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5239 struct via_spec *spec = codec->spec;
5242 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5245 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5248 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5249 return 0; /* can't find valid BIOS pin config */
5251 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5254 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5257 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5261 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5263 fill_dig_outs(codec);
5265 if (spec->kctls.list)
5266 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5268 spec->input_mux = &spec->private_imux[0];
5271 via_hp_build(codec);
5273 via_smart51_build(spec);
5278 #ifdef CONFIG_SND_HDA_POWER_SAVE
5279 static struct hda_amp_list vt1716S_loopbacks[] = {
5280 { 0x16, HDA_INPUT, 1 },
5281 { 0x16, HDA_INPUT, 2 },
5282 { 0x16, HDA_INPUT, 3 },
5283 { 0x16, HDA_INPUT, 4 },
5288 static int patch_vt1716S(struct hda_codec *codec)
5290 struct via_spec *spec;
5293 /* create a codec specific record */
5294 spec = via_new_spec(codec);
5298 /* automatic parse from the BIOS config */
5299 err = vt1716S_parse_auto_config(codec);
5304 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5305 "from BIOS. Using genenic mode...\n");
5308 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5309 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5311 spec->stream_name_analog = "VT1716S Analog";
5312 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5313 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5315 spec->stream_name_digital = "VT1716S Digital";
5316 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5318 if (!spec->adc_nids && spec->input_mux) {
5319 spec->adc_nids = vt1716S_adc_nids;
5320 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5321 get_mux_nids(codec);
5322 override_mic_boost(codec, 0x1a, 0, 3, 40);
5323 override_mic_boost(codec, 0x1e, 0, 3, 40);
5324 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5328 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5331 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5333 codec->patch_ops = via_patch_ops;
5335 codec->patch_ops.init = via_auto_init;
5336 codec->patch_ops.unsol_event = via_unsol_event;
5338 #ifdef CONFIG_SND_HDA_POWER_SAVE
5339 spec->loopback.amplist = vt1716S_loopbacks;
5347 /* capture mixer elements */
5348 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5349 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5350 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5351 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5352 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5353 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5354 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5357 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5358 /* The multiple "Capture Source" controls confuse alsamixer
5359 * So call somewhat different..
5361 /* .name = "Capture Source", */
5362 .name = "Input Source",
5364 .info = via_mux_enum_info,
5365 .get = via_mux_enum_get,
5366 .put = via_mux_enum_put,
5371 static struct hda_verb vt2002P_volume_init_verbs[] = {
5373 * Unmute ADC0-1 and set the default input to mic-in
5375 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5376 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5379 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5382 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5383 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5384 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5385 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5386 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5387 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5389 /* MUX Indices: Mic = 0 */
5390 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5391 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5393 /* PW9 Output enable */
5394 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5396 /* Enable Boost Volume backdoor */
5399 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5400 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5401 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5402 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5403 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5404 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5405 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5406 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5407 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5409 /* set MUX0/1/4/8 = 0 (AOW0) */
5410 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5411 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5412 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5413 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5415 /* set PW0 index=0 (MW0) */
5416 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5418 /* Enable AOW0 to MW9 */
5424 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5425 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5426 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5427 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5428 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5429 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5430 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5431 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5435 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5439 .nid = 0x8, /* NID to query formats and rates */
5441 .open = via_playback_pcm_open,
5442 .prepare = via_playback_multi_pcm_prepare,
5443 .cleanup = via_playback_multi_pcm_cleanup,
5444 .close = via_pcm_open_close,
5448 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5452 .nid = 0x10, /* NID to query formats and rates */
5454 .open = via_pcm_open_close,
5455 .prepare = via_capture_pcm_prepare,
5456 .cleanup = via_capture_pcm_cleanup,
5457 .close = via_pcm_open_close,
5461 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5465 /* NID is set in via_build_pcms */
5467 .open = via_dig_playback_pcm_open,
5468 .close = via_dig_playback_pcm_close,
5469 .prepare = via_dig_playback_pcm_prepare,
5470 .cleanup = via_dig_playback_pcm_cleanup
5474 /* fill in the dac_nids table from the parsed pin configuration */
5475 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5476 const struct auto_pin_cfg *cfg)
5478 spec->multiout.num_dacs = 1;
5479 spec->multiout.dac_nids = spec->private_dac_nids;
5480 if (cfg->line_out_pins[0])
5481 spec->multiout.dac_nids[0] = 0x8;
5485 /* add playback controls from the parsed DAC table */
5486 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5487 const struct auto_pin_cfg *cfg)
5491 if (!cfg->line_out_pins[0])
5495 /* Line-Out: PortE */
5496 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5497 "Master Front Playback Volume",
5498 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5501 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5502 "Master Front Playback Switch",
5503 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5510 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5517 spec->multiout.hp_nid = 0x9;
5518 spec->hp_independent_mode_index = 1;
5520 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5521 "Headphone Playback Volume",
5522 HDA_COMPOSE_AMP_VAL(
5523 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5527 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5528 "Headphone Playback Switch",
5529 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5533 create_hp_imux(spec);
5537 /* create playback/capture controls for input pins */
5538 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5539 const struct auto_pin_cfg *cfg)
5541 struct via_spec *spec = codec->spec;
5542 struct hda_input_mux *imux = &spec->private_imux[0];
5543 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5546 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5547 ARRAY_SIZE(pin_idxs));
5550 /* build volume/mute control of loopback */
5551 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
5555 /* for digital mic select */
5556 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
5561 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5563 struct via_spec *spec = codec->spec;
5567 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5571 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5575 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5576 return 0; /* can't find valid BIOS pin config */
5578 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5581 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5584 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5588 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5590 fill_dig_outs(codec);
5592 if (spec->kctls.list)
5593 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5595 spec->input_mux = &spec->private_imux[0];
5598 via_hp_build(codec);
5603 #ifdef CONFIG_SND_HDA_POWER_SAVE
5604 static struct hda_amp_list vt2002P_loopbacks[] = {
5605 { 0x21, HDA_INPUT, 0 },
5606 { 0x21, HDA_INPUT, 1 },
5607 { 0x21, HDA_INPUT, 2 },
5613 /* patch for vt2002P */
5614 static int patch_vt2002P(struct hda_codec *codec)
5616 struct via_spec *spec;
5619 /* create a codec specific record */
5620 spec = via_new_spec(codec);
5624 /* automatic parse from the BIOS config */
5625 err = vt2002P_parse_auto_config(codec);
5630 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5631 "from BIOS. Using genenic mode...\n");
5634 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5635 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5637 spec->stream_name_analog = "VT2002P Analog";
5638 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5639 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5641 spec->stream_name_digital = "VT2002P Digital";
5642 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5644 if (!spec->adc_nids && spec->input_mux) {
5645 spec->adc_nids = vt2002P_adc_nids;
5646 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5647 get_mux_nids(codec);
5648 override_mic_boost(codec, 0x2b, 0, 3, 40);
5649 override_mic_boost(codec, 0x29, 0, 3, 40);
5650 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5654 codec->patch_ops = via_patch_ops;
5656 codec->patch_ops.init = via_auto_init;
5657 codec->patch_ops.unsol_event = via_unsol_event;
5659 #ifdef CONFIG_SND_HDA_POWER_SAVE
5660 spec->loopback.amplist = vt2002P_loopbacks;
5668 /* capture mixer elements */
5669 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5670 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5671 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5672 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5673 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5674 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5675 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5678 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5679 /* The multiple "Capture Source" controls confuse alsamixer
5680 * So call somewhat different..
5682 .name = "Input Source",
5684 .info = via_mux_enum_info,
5685 .get = via_mux_enum_get,
5686 .put = via_mux_enum_put,
5691 static struct hda_verb vt1812_volume_init_verbs[] = {
5693 * Unmute ADC0-1 and set the default input to mic-in
5695 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5696 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5699 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5702 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5703 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5704 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5705 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5706 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5707 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5709 /* MUX Indices: Mic = 0 */
5710 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5711 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5713 /* PW9 Output enable */
5714 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5716 /* Enable Boost Volume backdoor */
5719 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5720 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5721 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5722 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5723 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5724 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5725 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5726 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5727 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5728 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5729 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5731 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5732 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5733 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5734 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5735 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5736 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5738 /* Enable AOW0 to MW9 */
5744 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5745 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5746 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5747 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5748 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5749 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5750 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5751 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5752 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5756 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5760 .nid = 0x8, /* NID to query formats and rates */
5762 .open = via_playback_pcm_open,
5763 .prepare = via_playback_multi_pcm_prepare,
5764 .cleanup = via_playback_multi_pcm_cleanup,
5765 .close = via_pcm_open_close,
5769 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5773 .nid = 0x10, /* NID to query formats and rates */
5775 .open = via_pcm_open_close,
5776 .prepare = via_capture_pcm_prepare,
5777 .cleanup = via_capture_pcm_cleanup,
5778 .close = via_pcm_open_close,
5782 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5786 /* NID is set in via_build_pcms */
5788 .open = via_dig_playback_pcm_open,
5789 .close = via_dig_playback_pcm_close,
5790 .prepare = via_dig_playback_pcm_prepare,
5791 .cleanup = via_dig_playback_pcm_cleanup
5794 /* fill in the dac_nids table from the parsed pin configuration */
5795 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5796 const struct auto_pin_cfg *cfg)
5798 spec->multiout.num_dacs = 1;
5799 spec->multiout.dac_nids = spec->private_dac_nids;
5800 if (cfg->line_out_pins[0])
5801 spec->multiout.dac_nids[0] = 0x8;
5806 /* add playback controls from the parsed DAC table */
5807 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5808 const struct auto_pin_cfg *cfg)
5812 if (!cfg->line_out_pins[0])
5815 /* Line-Out: PortE */
5816 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5817 "Front Playback Volume",
5818 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5821 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5822 "Front Playback Switch",
5823 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5830 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5837 spec->multiout.hp_nid = 0x9;
5838 spec->hp_independent_mode_index = 1;
5841 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5842 "Headphone Playback Volume",
5843 HDA_COMPOSE_AMP_VAL(
5844 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5848 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5849 "Headphone Playback Switch",
5850 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5854 create_hp_imux(spec);
5858 /* create playback/capture controls for input pins */
5859 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5860 const struct auto_pin_cfg *cfg)
5862 struct via_spec *spec = codec->spec;
5863 struct hda_input_mux *imux = &spec->private_imux[0];
5864 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5867 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5868 ARRAY_SIZE(pin_idxs));
5872 /* build volume/mute control of loopback */
5873 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
5877 /* for digital mic select */
5878 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
5883 static int vt1812_parse_auto_config(struct hda_codec *codec)
5885 struct via_spec *spec = codec->spec;
5889 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5892 fill_dig_outs(codec);
5893 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5897 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5898 return 0; /* can't find valid BIOS pin config */
5900 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5903 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5906 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
5910 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5912 fill_dig_outs(codec);
5914 if (spec->kctls.list)
5915 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5917 spec->input_mux = &spec->private_imux[0];
5920 via_hp_build(codec);
5925 #ifdef CONFIG_SND_HDA_POWER_SAVE
5926 static struct hda_amp_list vt1812_loopbacks[] = {
5927 { 0x21, HDA_INPUT, 0 },
5928 { 0x21, HDA_INPUT, 1 },
5929 { 0x21, HDA_INPUT, 2 },
5935 /* patch for vt1812 */
5936 static int patch_vt1812(struct hda_codec *codec)
5938 struct via_spec *spec;
5941 /* create a codec specific record */
5942 spec = via_new_spec(codec);
5946 /* automatic parse from the BIOS config */
5947 err = vt1812_parse_auto_config(codec);
5952 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5953 "from BIOS. Using genenic mode...\n");
5957 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
5958 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
5960 spec->stream_name_analog = "VT1812 Analog";
5961 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
5962 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
5964 spec->stream_name_digital = "VT1812 Digital";
5965 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
5968 if (!spec->adc_nids && spec->input_mux) {
5969 spec->adc_nids = vt1812_adc_nids;
5970 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
5971 get_mux_nids(codec);
5972 override_mic_boost(codec, 0x2b, 0, 3, 40);
5973 override_mic_boost(codec, 0x29, 0, 3, 40);
5974 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
5978 codec->patch_ops = via_patch_ops;
5980 codec->patch_ops.init = via_auto_init;
5981 codec->patch_ops.unsol_event = via_unsol_event;
5983 #ifdef CONFIG_SND_HDA_POWER_SAVE
5984 spec->loopback.amplist = vt1812_loopbacks;
5993 static struct hda_codec_preset snd_hda_preset_via[] = {
5994 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
5995 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
5996 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
5997 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
5998 { .id = 0x1106e710, .name = "VT1709 10-Ch",
5999 .patch = patch_vt1709_10ch},
6000 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6001 .patch = patch_vt1709_10ch},
6002 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6003 .patch = patch_vt1709_10ch},
6004 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6005 .patch = patch_vt1709_10ch},
6006 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6007 .patch = patch_vt1709_6ch},
6008 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6009 .patch = patch_vt1709_6ch},
6010 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6011 .patch = patch_vt1709_6ch},
6012 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6013 .patch = patch_vt1709_6ch},
6014 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6015 .patch = patch_vt1708B_8ch},
6016 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6017 .patch = patch_vt1708B_8ch},
6018 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6019 .patch = patch_vt1708B_8ch},
6020 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6021 .patch = patch_vt1708B_8ch},
6022 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6023 .patch = patch_vt1708B_4ch},
6024 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6025 .patch = patch_vt1708B_4ch},
6026 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6027 .patch = patch_vt1708B_4ch},
6028 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6029 .patch = patch_vt1708B_4ch},
6030 { .id = 0x11060397, .name = "VT1708S",
6031 .patch = patch_vt1708S},
6032 { .id = 0x11061397, .name = "VT1708S",
6033 .patch = patch_vt1708S},
6034 { .id = 0x11062397, .name = "VT1708S",
6035 .patch = patch_vt1708S},
6036 { .id = 0x11063397, .name = "VT1708S",
6037 .patch = patch_vt1708S},
6038 { .id = 0x11064397, .name = "VT1708S",
6039 .patch = patch_vt1708S},
6040 { .id = 0x11065397, .name = "VT1708S",
6041 .patch = patch_vt1708S},
6042 { .id = 0x11066397, .name = "VT1708S",
6043 .patch = patch_vt1708S},
6044 { .id = 0x11067397, .name = "VT1708S",
6045 .patch = patch_vt1708S},
6046 { .id = 0x11060398, .name = "VT1702",
6047 .patch = patch_vt1702},
6048 { .id = 0x11061398, .name = "VT1702",
6049 .patch = patch_vt1702},
6050 { .id = 0x11062398, .name = "VT1702",
6051 .patch = patch_vt1702},
6052 { .id = 0x11063398, .name = "VT1702",
6053 .patch = patch_vt1702},
6054 { .id = 0x11064398, .name = "VT1702",
6055 .patch = patch_vt1702},
6056 { .id = 0x11065398, .name = "VT1702",
6057 .patch = patch_vt1702},
6058 { .id = 0x11066398, .name = "VT1702",
6059 .patch = patch_vt1702},
6060 { .id = 0x11067398, .name = "VT1702",
6061 .patch = patch_vt1702},
6062 { .id = 0x11060428, .name = "VT1718S",
6063 .patch = patch_vt1718S},
6064 { .id = 0x11064428, .name = "VT1718S",
6065 .patch = patch_vt1718S},
6066 { .id = 0x11060441, .name = "VT2020",
6067 .patch = patch_vt1718S},
6068 { .id = 0x11064441, .name = "VT1828S",
6069 .patch = patch_vt1718S},
6070 { .id = 0x11060433, .name = "VT1716S",
6071 .patch = patch_vt1716S},
6072 { .id = 0x1106a721, .name = "VT1716S",
6073 .patch = patch_vt1716S},
6074 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6075 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6076 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6077 { .id = 0x11060440, .name = "VT1818S",
6078 .patch = patch_vt1708S},
6082 MODULE_ALIAS("snd-hda-codec-id:1106*");
6084 static struct hda_codec_preset_list via_list = {
6085 .preset = snd_hda_preset_via,
6086 .owner = THIS_MODULE,
6089 MODULE_LICENSE("GPL");
6090 MODULE_DESCRIPTION("VIA HD-audio codec");
6092 static int __init patch_via_init(void)
6094 return snd_hda_add_codec_preset(&via_list);
6097 static void __exit patch_via_exit(void)
6099 snd_hda_delete_codec_preset(&via_list);
6102 module_init(patch_via_init)
6103 module_exit(patch_via_exit)