2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec
6 * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com>
7 * 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 */
40 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 #include <linux/init.h>
44 #include <linux/delay.h>
45 #include <linux/slab.h>
46 #include <sound/core.h>
47 #include <sound/asoundef.h>
48 #include "hda_codec.h"
49 #include "hda_local.h"
52 #define AMP_VAL_IDX_SHIFT 19
53 #define AMP_VAL_IDX_MASK (0x0f<<19)
56 #define VT1708_HP_NID 0x13
57 #define VT1708_DIGOUT_NID 0x14
58 #define VT1708_DIGIN_NID 0x16
59 #define VT1708_DIGIN_PIN 0x26
60 #define VT1708_HP_PIN_NID 0x20
61 #define VT1708_CD_PIN_NID 0x24
63 #define VT1709_HP_DAC_NID 0x28
64 #define VT1709_DIGOUT_NID 0x13
65 #define VT1709_DIGIN_NID 0x17
66 #define VT1709_DIGIN_PIN 0x25
68 #define VT1708B_HP_NID 0x25
69 #define VT1708B_DIGOUT_NID 0x12
70 #define VT1708B_DIGIN_NID 0x15
71 #define VT1708B_DIGIN_PIN 0x21
73 #define VT1708S_HP_NID 0x25
74 #define VT1708S_DIGOUT_NID 0x12
76 #define VT1702_HP_NID 0x17
77 #define VT1702_DIGOUT_NID 0x11
97 /* codec parameterization */
98 struct snd_kcontrol_new *mixers[6];
99 unsigned int num_mixers;
101 struct hda_verb *init_verbs[5];
102 unsigned int num_iverbs;
104 char *stream_name_analog;
105 struct hda_pcm_stream *stream_analog_playback;
106 struct hda_pcm_stream *stream_analog_capture;
108 char *stream_name_digital;
109 struct hda_pcm_stream *stream_digital_playback;
110 struct hda_pcm_stream *stream_digital_capture;
113 struct hda_multi_out multiout;
114 hda_nid_t slave_dig_outs[2];
117 unsigned int num_adc_nids;
119 hda_nid_t mux_nids[3];
120 hda_nid_t dig_in_nid;
121 hda_nid_t dig_in_pin;
124 const struct hda_input_mux *input_mux;
125 unsigned int cur_mux[3];
127 /* PCM information */
128 struct hda_pcm pcm_rec[3];
130 /* dynamic controls, init_verbs and input_mux */
131 struct auto_pin_cfg autocfg;
132 struct snd_array kctls;
133 struct hda_input_mux private_imux[2];
134 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
137 const struct hda_input_mux *hp_mux;
138 unsigned int hp_independent_mode;
139 unsigned int hp_independent_mode_index;
140 unsigned int smart51_enabled;
141 unsigned int dmic_enabled;
142 enum VIA_HDA_CODEC codec_type;
144 /* work to check hp jack state */
145 struct hda_codec *codec;
146 struct delayed_work vt1708_hp_work;
147 int vt1708_jack_detectect;
148 int vt1708_hp_present;
149 #ifdef CONFIG_SND_HDA_POWER_SAVE
150 struct hda_loopback_check loopback;
154 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
156 u32 vendor_id = codec->vendor_id;
157 u16 ven_id = vendor_id >> 16;
158 u16 dev_id = vendor_id & 0xffff;
159 enum VIA_HDA_CODEC codec_type;
162 if (ven_id != 0x1106)
163 codec_type = UNKNOWN;
164 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
166 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
167 codec_type = VT1709_10CH;
168 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
169 codec_type = VT1709_6CH;
170 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
171 codec_type = VT1708B_8CH;
172 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
173 codec_type = VT1708BCE;
174 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
175 codec_type = VT1708B_4CH;
176 else if ((dev_id & 0xfff) == 0x397
177 && (dev_id >> 12) < 8)
178 codec_type = VT1708S;
179 else if ((dev_id & 0xfff) == 0x398
180 && (dev_id >> 12) < 8)
182 else if ((dev_id & 0xfff) == 0x428
183 && (dev_id >> 12) < 8)
184 codec_type = VT1718S;
185 else if (dev_id == 0x0433 || dev_id == 0xa721)
186 codec_type = VT1716S;
187 else if (dev_id == 0x0441 || dev_id == 0x4441)
188 codec_type = VT1718S;
189 else if (dev_id == 0x0438 || dev_id == 0x4438)
190 codec_type = VT2002P;
191 else if (dev_id == 0x0448)
194 codec_type = UNKNOWN;
198 #define VIA_HP_EVENT 0x01
199 #define VIA_GPIO_EVENT 0x02
200 #define VIA_JACK_EVENT 0x04
201 #define VIA_MONO_EVENT 0x08
202 #define VIA_SPEAKER_EVENT 0x10
203 #define VIA_BIND_HP_EVENT 0x20
208 VIA_CTL_WIDGET_ANALOG_MUTE,
209 VIA_CTL_WIDGET_BIND_PIN_MUTE,
219 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
220 static void set_jack_power_state(struct hda_codec *codec);
221 static int is_aa_path_mute(struct hda_codec *codec);
223 static void vt1708_start_hp_work(struct via_spec *spec)
225 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
227 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
228 !spec->vt1708_jack_detectect);
229 if (!delayed_work_pending(&spec->vt1708_hp_work))
230 schedule_delayed_work(&spec->vt1708_hp_work,
231 msecs_to_jiffies(100));
234 static void vt1708_stop_hp_work(struct via_spec *spec)
236 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
238 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
239 && !is_aa_path_mute(spec->codec))
241 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
242 !spec->vt1708_jack_detectect);
243 cancel_delayed_work(&spec->vt1708_hp_work);
244 flush_scheduled_work();
248 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
249 struct snd_ctl_elem_value *ucontrol)
251 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
252 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
254 set_jack_power_state(codec);
255 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
256 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
257 if (is_aa_path_mute(codec))
258 vt1708_start_hp_work(codec->spec);
260 vt1708_stop_hp_work(codec->spec);
265 /* modify .put = snd_hda_mixer_amp_switch_put */
266 #define ANALOG_INPUT_MUTE \
267 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
270 .info = snd_hda_mixer_amp_switch_info, \
271 .get = snd_hda_mixer_amp_switch_get, \
272 .put = analog_input_switch_put, \
273 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
275 static void via_hp_bind_automute(struct hda_codec *codec);
277 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
278 struct snd_ctl_elem_value *ucontrol)
280 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
281 struct via_spec *spec = codec->spec;
285 long *valp = ucontrol->value.integer.value;
287 if (strstr(kcontrol->id.name, "Switch") == NULL) {
288 snd_printd("Invalid control!\n");
291 change = snd_hda_mixer_amp_switch_put(kcontrol,
294 lmute = *valp ? 0 : HDA_AMP_MUTE;
296 rmute = *valp ? 0 : HDA_AMP_MUTE;
299 if (!spec->hp_independent_mode) {
300 for (i = 0; i < spec->autocfg.hp_outs; i++) {
301 snd_hda_codec_amp_update(
302 codec, spec->autocfg.hp_pins[i],
303 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
305 snd_hda_codec_amp_update(
306 codec, spec->autocfg.hp_pins[i],
307 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
312 if (!lmute && !rmute) {
314 for (i = 0; i < spec->autocfg.line_outs; i++)
315 snd_hda_codec_amp_stereo(
316 codec, spec->autocfg.line_out_pins[i],
317 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
319 for (i = 0; i < spec->autocfg.speaker_outs; i++)
320 snd_hda_codec_amp_stereo(
321 codec, spec->autocfg.speaker_pins[i],
322 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
324 via_hp_bind_automute(codec);
328 /* Mute all left channels */
329 for (i = 1; i < spec->autocfg.line_outs; i++)
330 snd_hda_codec_amp_update(
332 spec->autocfg.line_out_pins[i],
333 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
335 for (i = 0; i < spec->autocfg.speaker_outs; i++)
336 snd_hda_codec_amp_update(
338 spec->autocfg.speaker_pins[i],
339 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
343 /* mute all right channels */
344 for (i = 1; i < spec->autocfg.line_outs; i++)
345 snd_hda_codec_amp_update(
347 spec->autocfg.line_out_pins[i],
348 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
350 for (i = 0; i < spec->autocfg.speaker_outs; i++)
351 snd_hda_codec_amp_update(
353 spec->autocfg.speaker_pins[i],
354 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
361 #define BIND_PIN_MUTE \
362 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
365 .info = snd_hda_mixer_amp_switch_info, \
366 .get = snd_hda_mixer_amp_switch_get, \
367 .put = bind_pin_switch_put, \
368 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
370 static struct snd_kcontrol_new via_control_templates[] = {
371 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
372 HDA_CODEC_MUTE(NULL, 0, 0, 0),
377 static hda_nid_t vt1708_adc_nids[2] = {
382 static hda_nid_t vt1709_adc_nids[3] = {
387 static hda_nid_t vt1708B_adc_nids[2] = {
392 static hda_nid_t vt1708S_adc_nids[2] = {
397 static hda_nid_t vt1702_adc_nids[3] = {
402 static hda_nid_t vt1718S_adc_nids[2] = {
407 static hda_nid_t vt1716S_adc_nids[2] = {
412 static hda_nid_t vt2002P_adc_nids[2] = {
417 static hda_nid_t vt1812_adc_nids[2] = {
423 /* add dynamic controls */
424 static int via_add_control(struct via_spec *spec, int type, const char *name,
427 struct snd_kcontrol_new *knew;
429 snd_array_init(&spec->kctls, sizeof(*knew), 32);
430 knew = snd_array_new(&spec->kctls);
433 *knew = via_control_templates[type];
434 knew->name = kstrdup(name, GFP_KERNEL);
437 knew->private_value = val;
441 static void via_free_kctls(struct hda_codec *codec)
443 struct via_spec *spec = codec->spec;
445 if (spec->kctls.list) {
446 struct snd_kcontrol_new *kctl = spec->kctls.list;
448 for (i = 0; i < spec->kctls.used; i++)
451 snd_array_free(&spec->kctls);
454 /* create input playback/capture controls for the given pin */
455 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
456 int idx, int mix_nid)
461 sprintf(name, "%s Playback Volume", ctlname);
462 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
463 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
466 sprintf(name, "%s Playback Switch", ctlname);
467 err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name,
468 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
474 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
475 hda_nid_t nid, int pin_type,
479 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
481 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
483 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
484 snd_hda_codec_write(codec, nid, 0,
485 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
489 static void via_auto_init_multi_out(struct hda_codec *codec)
491 struct via_spec *spec = codec->spec;
494 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
495 hda_nid_t nid = spec->autocfg.line_out_pins[i];
497 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
501 static void via_auto_init_hp_out(struct hda_codec *codec)
503 struct via_spec *spec = codec->spec;
507 for (i = 0; i < spec->autocfg.hp_outs; i++) {
508 pin = spec->autocfg.hp_pins[i];
509 if (pin) /* connect to front */
510 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
514 static void via_auto_init_analog_input(struct hda_codec *codec)
516 struct via_spec *spec = codec->spec;
519 for (i = 0; i < AUTO_PIN_LAST; i++) {
520 hda_nid_t nid = spec->autocfg.input_pins[i];
522 snd_hda_codec_write(codec, nid, 0,
523 AC_VERB_SET_PIN_WIDGET_CONTROL,
524 (i <= AUTO_PIN_FRONT_MIC ?
525 PIN_VREF50 : PIN_IN));
530 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
532 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
533 unsigned int *affected_parm)
536 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
537 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
538 >> AC_DEFCFG_MISC_SHIFT
539 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
540 unsigned present = snd_hda_codec_read(codec, nid, 0,
541 AC_VERB_GET_PIN_SENSE, 0) >> 31;
542 struct via_spec *spec = codec->spec;
543 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
544 || ((no_presence || present)
545 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
546 *affected_parm = AC_PWRST_D0; /* if it's connected */
551 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
554 static void set_jack_power_state(struct hda_codec *codec)
556 struct via_spec *spec = codec->spec;
560 if (spec->codec_type == VT1702) {
561 imux_is_smixer = snd_hda_codec_read(
562 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
564 /* PW 1/2/5 (14h/15h/18h) */
566 set_pin_power_state(codec, 0x14, &parm);
567 set_pin_power_state(codec, 0x15, &parm);
568 set_pin_power_state(codec, 0x18, &parm);
570 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
571 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
572 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
574 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
576 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
578 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
582 /* PW 3/4 (16h/17h) */
584 set_pin_power_state(codec, 0x16, &parm);
585 set_pin_power_state(codec, 0x17, &parm);
586 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
587 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
588 imux_is_smixer ? AC_PWRST_D0 : parm);
589 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
591 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
593 } else if (spec->codec_type == VT1708B_8CH
594 || spec->codec_type == VT1708B_4CH
595 || spec->codec_type == VT1708S) {
596 /* SW0 (17h) = stereo mixer */
597 int is_8ch = spec->codec_type != VT1708B_4CH;
598 imux_is_smixer = snd_hda_codec_read(
599 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
600 == ((spec->codec_type == VT1708S) ? 5 : 0);
602 /* PW 1/2/5 (1ah/1bh/1eh) */
604 set_pin_power_state(codec, 0x1a, &parm);
605 set_pin_power_state(codec, 0x1b, &parm);
606 set_pin_power_state(codec, 0x1e, &parm);
609 /* SW0 (17h), AIW 0/1 (13h/14h) */
610 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
612 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
614 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
618 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
620 set_pin_power_state(codec, 0x19, &parm);
621 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
623 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
626 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
629 set_pin_power_state(codec, 0x22, &parm);
630 snd_hda_codec_write(codec, 0x26, 0,
631 AC_VERB_SET_POWER_STATE, parm);
632 snd_hda_codec_write(codec, 0x24, 0,
633 AC_VERB_SET_POWER_STATE, parm);
636 /* PW 3/4/7 (1ch/1dh/23h) */
638 /* force to D0 for internal Speaker */
639 set_pin_power_state(codec, 0x1c, &parm);
640 set_pin_power_state(codec, 0x1d, &parm);
642 set_pin_power_state(codec, 0x23, &parm);
643 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
644 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
645 imux_is_smixer ? AC_PWRST_D0 : parm);
646 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
649 snd_hda_codec_write(codec, 0x25, 0,
650 AC_VERB_SET_POWER_STATE, parm);
651 snd_hda_codec_write(codec, 0x27, 0,
652 AC_VERB_SET_POWER_STATE, parm);
654 } else if (spec->codec_type == VT1718S) {
655 /* MUX6 (1eh) = stereo mixer */
656 imux_is_smixer = snd_hda_codec_read(
657 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
659 /* PW 5/6/7 (29h/2ah/2bh) */
661 set_pin_power_state(codec, 0x29, &parm);
662 set_pin_power_state(codec, 0x2a, &parm);
663 set_pin_power_state(codec, 0x2b, &parm);
666 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
667 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
669 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
671 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
673 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
677 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
679 set_pin_power_state(codec, 0x27, &parm);
680 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
682 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
685 /* PW2 (26h), AOW2 (ah) */
687 set_pin_power_state(codec, 0x26, &parm);
688 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
691 /* PW0/1 (24h/25h) */
693 set_pin_power_state(codec, 0x24, &parm);
694 set_pin_power_state(codec, 0x25, &parm);
695 if (!spec->hp_independent_mode) /* check for redirected HP */
696 set_pin_power_state(codec, 0x28, &parm);
697 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
699 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
701 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
702 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
703 imux_is_smixer ? AC_PWRST_D0 : parm);
704 if (spec->hp_independent_mode) {
705 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
707 set_pin_power_state(codec, 0x28, &parm);
708 snd_hda_codec_write(codec, 0x1b, 0,
709 AC_VERB_SET_POWER_STATE, parm);
710 snd_hda_codec_write(codec, 0x34, 0,
711 AC_VERB_SET_POWER_STATE, parm);
712 snd_hda_codec_write(codec, 0xc, 0,
713 AC_VERB_SET_POWER_STATE, parm);
715 } else if (spec->codec_type == VT1716S) {
716 unsigned int mono_out, present;
717 /* SW0 (17h) = stereo mixer */
718 imux_is_smixer = snd_hda_codec_read(
719 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
721 /* PW 1/2/5 (1ah/1bh/1eh) */
723 set_pin_power_state(codec, 0x1a, &parm);
724 set_pin_power_state(codec, 0x1b, &parm);
725 set_pin_power_state(codec, 0x1e, &parm);
728 /* SW0 (17h), AIW0(13h) */
729 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
731 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
735 set_pin_power_state(codec, 0x1e, &parm);
737 if (spec->dmic_enabled)
738 set_pin_power_state(codec, 0x22, &parm);
742 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
744 /* SW2(26h), AIW1(14h) */
745 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
747 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
751 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
753 set_pin_power_state(codec, 0x19, &parm);
754 /* Smart 5.1 PW2(1bh) */
755 if (spec->smart51_enabled)
756 set_pin_power_state(codec, 0x1b, &parm);
757 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
759 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
762 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
764 set_pin_power_state(codec, 0x23, &parm);
765 /* Smart 5.1 PW1(1ah) */
766 if (spec->smart51_enabled)
767 set_pin_power_state(codec, 0x1a, &parm);
768 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
771 /* Smart 5.1 PW5(1eh) */
772 if (spec->smart51_enabled)
773 set_pin_power_state(codec, 0x1e, &parm);
774 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
778 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
779 present = snd_hda_codec_read(
780 codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
784 present = snd_hda_codec_read(
785 codec, 0x1d, 0, AC_VERB_GET_PIN_SENSE, 0)
787 if (!spec->hp_independent_mode && present)
792 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
793 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
795 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
797 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
800 /* PW 3/4 (1ch/1dh) */
802 set_pin_power_state(codec, 0x1c, &parm);
803 set_pin_power_state(codec, 0x1d, &parm);
804 /* HP Independent Mode, power on AOW3 */
805 if (spec->hp_independent_mode)
806 snd_hda_codec_write(codec, 0x25, 0,
807 AC_VERB_SET_POWER_STATE, parm);
809 /* force to D0 for internal Speaker */
810 /* MW0 (16h), AOW0 (10h) */
811 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
812 imux_is_smixer ? AC_PWRST_D0 : parm);
813 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
814 mono_out ? AC_PWRST_D0 : parm);
815 } else if (spec->codec_type == VT2002P) {
816 unsigned int present;
817 /* MUX9 (1eh) = stereo mixer */
818 imux_is_smixer = snd_hda_codec_read(
819 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
821 /* PW 5/6/7 (29h/2ah/2bh) */
823 set_pin_power_state(codec, 0x29, &parm);
824 set_pin_power_state(codec, 0x2a, &parm);
825 set_pin_power_state(codec, 0x2b, &parm);
828 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
829 snd_hda_codec_write(codec, 0x1e, 0,
830 AC_VERB_SET_POWER_STATE, parm);
831 snd_hda_codec_write(codec, 0x1f, 0,
832 AC_VERB_SET_POWER_STATE, parm);
833 snd_hda_codec_write(codec, 0x10, 0,
834 AC_VERB_SET_POWER_STATE, parm);
835 snd_hda_codec_write(codec, 0x11, 0,
836 AC_VERB_SET_POWER_STATE, parm);
840 snd_hda_codec_write(codec, 0x8, 0,
841 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
843 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
845 set_pin_power_state(codec, 0x26, &parm);
846 snd_hda_codec_write(codec, 0x1c, 0,
847 AC_VERB_SET_POWER_STATE, parm);
848 snd_hda_codec_write(codec, 0x37,
849 0, AC_VERB_SET_POWER_STATE, parm);
851 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
853 set_pin_power_state(codec, 0x25, &parm);
854 snd_hda_codec_write(codec, 0x19, 0,
855 AC_VERB_SET_POWER_STATE, parm);
856 snd_hda_codec_write(codec, 0x35, 0,
857 AC_VERB_SET_POWER_STATE, parm);
858 if (spec->hp_independent_mode) {
859 snd_hda_codec_write(codec, 0x9, 0,
860 AC_VERB_SET_POWER_STATE, parm);
864 /* PW0 (24h), MW0(18h), MUX0(34h) */
865 present = snd_hda_codec_read(
866 codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
868 set_pin_power_state(codec, 0x24, &parm);
872 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
875 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
879 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
882 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
886 /* PW15 (31h), MW8(17h), MUX8(3bh) */
887 present = snd_hda_codec_read(
888 codec, 0x26, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
890 set_pin_power_state(codec, 0x31, &parm);
894 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
897 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
901 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
904 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
908 if (imux_is_smixer || !is_aa_path_mute(codec))
911 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
915 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
916 } else if (spec->codec_type == VT1812) {
917 unsigned int present;
918 /* MUX10 (1eh) = stereo mixer */
919 imux_is_smixer = snd_hda_codec_read(
920 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
922 /* PW 5/6/7 (29h/2ah/2bh) */
924 set_pin_power_state(codec, 0x29, &parm);
925 set_pin_power_state(codec, 0x2a, &parm);
926 set_pin_power_state(codec, 0x2b, &parm);
929 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
930 snd_hda_codec_write(codec, 0x1e, 0,
931 AC_VERB_SET_POWER_STATE, parm);
932 snd_hda_codec_write(codec, 0x1f, 0,
933 AC_VERB_SET_POWER_STATE, parm);
934 snd_hda_codec_write(codec, 0x10, 0,
935 AC_VERB_SET_POWER_STATE, parm);
936 snd_hda_codec_write(codec, 0x11, 0,
937 AC_VERB_SET_POWER_STATE, parm);
941 snd_hda_codec_write(codec, 0x8, 0,
942 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
944 /* PW4 (28h), MW4 (18h), MUX4(38h) */
946 set_pin_power_state(codec, 0x28, &parm);
947 snd_hda_codec_write(codec, 0x18, 0,
948 AC_VERB_SET_POWER_STATE, parm);
949 snd_hda_codec_write(codec, 0x38, 0,
950 AC_VERB_SET_POWER_STATE, parm);
952 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
954 set_pin_power_state(codec, 0x25, &parm);
955 snd_hda_codec_write(codec, 0x15, 0,
956 AC_VERB_SET_POWER_STATE, parm);
957 snd_hda_codec_write(codec, 0x35, 0,
958 AC_VERB_SET_POWER_STATE, parm);
959 if (spec->hp_independent_mode) {
960 snd_hda_codec_write(codec, 0x9, 0,
961 AC_VERB_SET_POWER_STATE, parm);
964 /* Internal Speaker */
965 /* PW0 (24h), MW0(14h), MUX0(34h) */
966 present = snd_hda_codec_read(
967 codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
969 set_pin_power_state(codec, 0x24, &parm);
971 snd_hda_codec_write(codec, 0x14, 0,
972 AC_VERB_SET_POWER_STATE,
974 snd_hda_codec_write(codec, 0x34, 0,
975 AC_VERB_SET_POWER_STATE,
978 snd_hda_codec_write(codec, 0x14, 0,
979 AC_VERB_SET_POWER_STATE,
981 snd_hda_codec_write(codec, 0x34, 0,
982 AC_VERB_SET_POWER_STATE,
986 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
987 present = snd_hda_codec_read(
988 codec, 0x28, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
990 set_pin_power_state(codec, 0x31, &parm);
992 snd_hda_codec_write(codec, 0x1c, 0,
993 AC_VERB_SET_POWER_STATE,
995 snd_hda_codec_write(codec, 0x3c, 0,
996 AC_VERB_SET_POWER_STATE,
998 snd_hda_codec_write(codec, 0x3e, 0,
999 AC_VERB_SET_POWER_STATE,
1002 snd_hda_codec_write(codec, 0x1c, 0,
1003 AC_VERB_SET_POWER_STATE,
1005 snd_hda_codec_write(codec, 0x3c, 0,
1006 AC_VERB_SET_POWER_STATE,
1008 snd_hda_codec_write(codec, 0x3e, 0,
1009 AC_VERB_SET_POWER_STATE,
1013 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1015 set_pin_power_state(codec, 0x33, &parm);
1016 snd_hda_codec_write(codec, 0x1d, 0,
1017 AC_VERB_SET_POWER_STATE, parm);
1018 snd_hda_codec_write(codec, 0x3d, 0,
1019 AC_VERB_SET_POWER_STATE, parm);
1022 if (imux_is_smixer || !is_aa_path_mute(codec))
1023 snd_hda_codec_write(
1025 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1027 snd_hda_codec_write(
1029 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1034 * input MUX handling
1036 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1037 struct snd_ctl_elem_info *uinfo)
1039 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1040 struct via_spec *spec = codec->spec;
1041 return snd_hda_input_mux_info(spec->input_mux, uinfo);
1044 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1045 struct snd_ctl_elem_value *ucontrol)
1047 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1048 struct via_spec *spec = codec->spec;
1049 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1051 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
1055 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1056 struct snd_ctl_elem_value *ucontrol)
1058 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1059 struct via_spec *spec = codec->spec;
1060 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1062 if (!spec->mux_nids[adc_idx])
1064 /* switch to D0 beofre change index */
1065 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1066 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1067 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1068 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1069 /* update jack power state */
1070 set_jack_power_state(codec);
1072 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1073 spec->mux_nids[adc_idx],
1074 &spec->cur_mux[adc_idx]);
1077 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
1078 struct snd_ctl_elem_info *uinfo)
1080 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1081 struct via_spec *spec = codec->spec;
1082 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
1085 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
1086 struct snd_ctl_elem_value *ucontrol)
1088 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1089 struct via_spec *spec = codec->spec;
1091 unsigned int pinsel;
1093 switch (spec->codec_type) {
1104 nid = spec->autocfg.hp_pins[0];
1107 /* use !! to translate conn sel 2 for VT1718S */
1108 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1109 AC_VERB_GET_CONNECT_SEL,
1111 ucontrol->value.enumerated.item[0] = pinsel;
1116 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1118 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1120 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1121 ctl->vd[0].access |= active
1122 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1123 snd_ctl_notify(codec->bus->card,
1124 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1128 static int update_side_mute_status(struct hda_codec *codec)
1130 /* mute side channel */
1131 struct via_spec *spec = codec->spec;
1132 unsigned int parm = spec->hp_independent_mode
1133 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1136 switch (spec->codec_type) {
1153 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1158 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
1159 struct snd_ctl_elem_value *ucontrol)
1161 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1162 struct via_spec *spec = codec->spec;
1163 hda_nid_t nid = spec->autocfg.hp_pins[0];
1164 unsigned int pinsel = ucontrol->value.enumerated.item[0];
1165 /* Get Independent Mode index of headphone pin widget */
1166 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1169 switch (spec->codec_type) {
1172 pinsel = pinsel ? 2 : 0; /* indep HP use AOW4 (index 2) */
1173 spec->multiout.num_dacs = 4;
1182 nid = spec->autocfg.hp_pins[0];
1185 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
1187 if (spec->multiout.hp_nid && spec->multiout.hp_nid
1188 != spec->multiout.dac_nids[HDA_FRONT])
1189 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
1192 update_side_mute_status(codec);
1193 /* update HP volume/swtich active state */
1194 if (spec->codec_type == VT1708S
1195 || spec->codec_type == VT1702
1196 || spec->codec_type == VT1718S
1197 || spec->codec_type == VT1716S
1198 || spec->codec_type == VT2002P
1199 || spec->codec_type == VT1812) {
1200 activate_ctl(codec, "Headphone Playback Volume",
1201 spec->hp_independent_mode);
1202 activate_ctl(codec, "Headphone Playback Switch",
1203 spec->hp_independent_mode);
1208 static struct snd_kcontrol_new via_hp_mixer[] = {
1210 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1211 .name = "Independent HP",
1213 .info = via_independent_hp_info,
1214 .get = via_independent_hp_get,
1215 .put = via_independent_hp_put,
1220 static void notify_aa_path_ctls(struct hda_codec *codec)
1223 struct snd_ctl_elem_id id;
1224 const char *labels[] = {"Mic", "Front Mic", "Line"};
1226 memset(&id, 0, sizeof(id));
1227 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1228 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1229 sprintf(id.name, "%s Playback Volume", labels[i]);
1230 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1235 static void mute_aa_path(struct hda_codec *codec, int mute)
1237 struct via_spec *spec = codec->spec;
1238 hda_nid_t nid_mixer;
1242 /* get nid of MW0 and start & end index */
1243 switch (spec->codec_type) {
1266 /* check AA path's mute status */
1267 for (i = start_idx; i <= end_idx; i++) {
1268 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1269 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1273 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1277 for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
1278 if (pin == spec->autocfg.input_pins[index]) {
1286 static int via_smart51_info(struct snd_kcontrol *kcontrol,
1287 struct snd_ctl_elem_info *uinfo)
1289 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1291 uinfo->value.integer.min = 0;
1292 uinfo->value.integer.max = 1;
1296 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1297 struct snd_ctl_elem_value *ucontrol)
1299 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1300 struct via_spec *spec = codec->spec;
1301 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1305 for (i = 0; i < ARRAY_SIZE(index); i++) {
1306 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1309 snd_hda_codec_read(codec, nid, 0,
1310 AC_VERB_GET_PIN_WIDGET_CONTROL,
1312 if (i == AUTO_PIN_FRONT_MIC
1313 && spec->hp_independent_mode
1314 && spec->codec_type != VT1718S)
1315 continue; /* ignore FMic for independent HP */
1316 if (ctl & AC_PINCTL_IN_EN
1317 && !(ctl & AC_PINCTL_OUT_EN))
1321 *ucontrol->value.integer.value = on;
1325 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1326 struct snd_ctl_elem_value *ucontrol)
1328 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1329 struct via_spec *spec = codec->spec;
1330 int out_in = *ucontrol->value.integer.value
1331 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1332 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1335 for (i = 0; i < ARRAY_SIZE(index); i++) {
1336 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1337 if (i == AUTO_PIN_FRONT_MIC
1338 && spec->hp_independent_mode
1339 && spec->codec_type != VT1718S)
1340 continue; /* don't retask FMic for independent HP */
1342 unsigned int parm = snd_hda_codec_read(
1344 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1345 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1347 snd_hda_codec_write(codec, nid, 0,
1348 AC_VERB_SET_PIN_WIDGET_CONTROL,
1350 if (out_in == AC_PINCTL_OUT_EN) {
1351 mute_aa_path(codec, 1);
1352 notify_aa_path_ctls(codec);
1354 if (spec->codec_type == VT1718S)
1355 snd_hda_codec_amp_stereo(
1356 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1359 if (i == AUTO_PIN_FRONT_MIC) {
1360 if (spec->codec_type == VT1708S
1361 || spec->codec_type == VT1716S) {
1362 /* input = index 1 (AOW3) */
1363 snd_hda_codec_write(
1365 AC_VERB_SET_CONNECT_SEL, 1);
1366 snd_hda_codec_amp_stereo(
1367 codec, nid, HDA_OUTPUT,
1368 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1372 spec->smart51_enabled = *ucontrol->value.integer.value;
1373 set_jack_power_state(codec);
1377 static struct snd_kcontrol_new via_smart51_mixer[] = {
1379 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1380 .name = "Smart 5.1",
1382 .info = via_smart51_info,
1383 .get = via_smart51_get,
1384 .put = via_smart51_put,
1389 /* capture mixer elements */
1390 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1391 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1392 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1393 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1394 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1396 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1397 /* The multiple "Capture Source" controls confuse alsamixer
1398 * So call somewhat different..
1400 /* .name = "Capture Source", */
1401 .name = "Input Source",
1403 .info = via_mux_enum_info,
1404 .get = via_mux_enum_get,
1405 .put = via_mux_enum_put,
1410 /* check AA path's mute statue */
1411 static int is_aa_path_mute(struct hda_codec *codec)
1414 hda_nid_t nid_mixer;
1418 struct via_spec *spec = codec->spec;
1419 /* get nid of MW0 and start & end index */
1420 switch (spec->codec_type) {
1448 /* check AA path's mute status */
1449 for (i = start_idx; i <= end_idx; i++) {
1450 unsigned int con_list = snd_hda_codec_read(
1451 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1452 int shift = 8 * (i % 4);
1453 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1454 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1455 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1456 /* check mute status while the pin is connected */
1457 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1459 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1461 if (!mute_l || !mute_r) {
1470 /* enter/exit analog low-current mode */
1471 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1473 struct via_spec *spec = codec->spec;
1474 static int saved_stream_idle = 1; /* saved stream idle status */
1475 int enable = is_aa_path_mute(codec);
1476 unsigned int verb = 0;
1477 unsigned int parm = 0;
1479 if (stream_idle == -1) /* stream status did not change */
1480 enable = enable && saved_stream_idle;
1482 enable = enable && stream_idle;
1483 saved_stream_idle = stream_idle;
1486 /* decide low current mode's verb & parameter */
1487 switch (spec->codec_type) {
1491 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1497 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1501 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1506 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1509 return; /* other codecs are not supported */
1512 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1516 * generic initialization of ADC, input mixers and output mixers
1518 static struct hda_verb vt1708_volume_init_verbs[] = {
1520 * Unmute ADC0-1 and set the default input to mic-in
1522 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1523 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1526 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1529 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1530 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1531 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1532 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1533 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1534 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1537 * Set up output mixers (0x19 - 0x1b)
1539 /* set vol=0 to output mixers */
1540 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1541 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1542 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1544 /* Setup default input MW0 to PW4 */
1545 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1546 /* PW9 Output enable */
1547 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1551 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1552 struct hda_codec *codec,
1553 struct snd_pcm_substream *substream)
1555 struct via_spec *spec = codec->spec;
1556 int idle = substream->pstr->substream_opened == 1
1557 && substream->ref_count == 0;
1558 analog_low_current_mode(codec, idle);
1559 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1563 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1564 unsigned int stream_tag,
1565 unsigned int format,
1566 struct snd_pcm_substream *substream)
1568 struct via_spec *spec = codec->spec;
1569 struct hda_multi_out *mout = &spec->multiout;
1570 hda_nid_t *nids = mout->dac_nids;
1571 int chs = substream->runtime->channels;
1574 mutex_lock(&codec->spdif_mutex);
1575 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1577 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1579 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1580 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1581 /* turn off SPDIF once; otherwise the IEC958 bits won't
1583 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1584 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1585 AC_VERB_SET_DIGI_CONVERT_1,
1587 ~AC_DIG1_ENABLE & 0xff);
1588 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1589 stream_tag, 0, format);
1590 /* turn on again (if needed) */
1591 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1592 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1593 AC_VERB_SET_DIGI_CONVERT_1,
1594 codec->spdif_ctls & 0xff);
1596 mout->dig_out_used = 0;
1597 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1601 mutex_unlock(&codec->spdif_mutex);
1604 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1607 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1608 && !spec->hp_independent_mode)
1609 /* headphone out will just decode front left/right (stereo) */
1610 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1613 /* extra outputs copied from front */
1614 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1615 if (mout->extra_out_nid[i])
1616 snd_hda_codec_setup_stream(codec,
1617 mout->extra_out_nid[i],
1618 stream_tag, 0, format);
1621 for (i = 1; i < mout->num_dacs; i++) {
1622 if (chs >= (i + 1) * 2) /* independent out */
1623 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1625 else /* copy front */
1626 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1631 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1632 struct hda_codec *codec,
1633 unsigned int stream_tag,
1634 unsigned int format,
1635 struct snd_pcm_substream *substream)
1637 struct via_spec *spec = codec->spec;
1638 struct hda_multi_out *mout = &spec->multiout;
1639 hda_nid_t *nids = mout->dac_nids;
1641 if (substream->number == 0)
1642 playback_multi_pcm_prep_0(codec, stream_tag, format,
1645 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1646 spec->hp_independent_mode)
1647 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1648 stream_tag, 0, format);
1650 vt1708_start_hp_work(spec);
1654 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1655 struct hda_codec *codec,
1656 struct snd_pcm_substream *substream)
1658 struct via_spec *spec = codec->spec;
1659 struct hda_multi_out *mout = &spec->multiout;
1660 hda_nid_t *nids = mout->dac_nids;
1663 if (substream->number == 0) {
1664 for (i = 0; i < mout->num_dacs; i++)
1665 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1667 if (mout->hp_nid && !spec->hp_independent_mode)
1668 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1671 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1672 if (mout->extra_out_nid[i])
1673 snd_hda_codec_setup_stream(codec,
1674 mout->extra_out_nid[i],
1676 mutex_lock(&codec->spdif_mutex);
1677 if (mout->dig_out_nid &&
1678 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1679 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1681 mout->dig_out_used = 0;
1683 mutex_unlock(&codec->spdif_mutex);
1685 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1686 spec->hp_independent_mode)
1687 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1690 vt1708_stop_hp_work(spec);
1697 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1698 struct hda_codec *codec,
1699 struct snd_pcm_substream *substream)
1701 struct via_spec *spec = codec->spec;
1702 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1705 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1706 struct hda_codec *codec,
1707 struct snd_pcm_substream *substream)
1709 struct via_spec *spec = codec->spec;
1710 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1713 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1714 struct hda_codec *codec,
1715 unsigned int stream_tag,
1716 unsigned int format,
1717 struct snd_pcm_substream *substream)
1719 struct via_spec *spec = codec->spec;
1720 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1721 stream_tag, format, substream);
1724 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1725 struct hda_codec *codec,
1726 struct snd_pcm_substream *substream)
1728 struct via_spec *spec = codec->spec;
1729 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1736 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1737 struct hda_codec *codec,
1738 unsigned int stream_tag,
1739 unsigned int format,
1740 struct snd_pcm_substream *substream)
1742 struct via_spec *spec = codec->spec;
1744 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1745 stream_tag, 0, format);
1749 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1750 struct hda_codec *codec,
1751 struct snd_pcm_substream *substream)
1753 struct via_spec *spec = codec->spec;
1754 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1758 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1762 .nid = 0x10, /* NID to query formats and rates */
1764 .open = via_playback_pcm_open,
1765 .prepare = via_playback_multi_pcm_prepare,
1766 .cleanup = via_playback_multi_pcm_cleanup
1770 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1774 .nid = 0x10, /* NID to query formats and rates */
1775 /* We got noisy outputs on the right channel on VT1708 when
1776 * 24bit samples are used. Until any workaround is found,
1777 * disable the 24bit format, so far.
1779 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1781 .open = via_playback_pcm_open,
1782 .prepare = via_playback_multi_pcm_prepare,
1783 .cleanup = via_playback_multi_pcm_cleanup
1787 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1791 .nid = 0x15, /* NID to query formats and rates */
1793 .prepare = via_capture_pcm_prepare,
1794 .cleanup = via_capture_pcm_cleanup
1798 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1802 /* NID is set in via_build_pcms */
1804 .open = via_dig_playback_pcm_open,
1805 .close = via_dig_playback_pcm_close,
1806 .prepare = via_dig_playback_pcm_prepare,
1807 .cleanup = via_dig_playback_pcm_cleanup
1811 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1817 static int via_build_controls(struct hda_codec *codec)
1819 struct via_spec *spec = codec->spec;
1823 for (i = 0; i < spec->num_mixers; i++) {
1824 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1829 if (spec->multiout.dig_out_nid) {
1830 err = snd_hda_create_spdif_out_ctls(codec,
1831 spec->multiout.dig_out_nid);
1834 err = snd_hda_create_spdif_share_sw(codec,
1838 spec->multiout.share_spdif = 1;
1840 if (spec->dig_in_nid) {
1841 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1846 /* init power states */
1847 set_jack_power_state(codec);
1848 analog_low_current_mode(codec, 1);
1850 via_free_kctls(codec); /* no longer needed */
1854 static int via_build_pcms(struct hda_codec *codec)
1856 struct via_spec *spec = codec->spec;
1857 struct hda_pcm *info = spec->pcm_rec;
1859 codec->num_pcms = 1;
1860 codec->pcm_info = info;
1862 info->name = spec->stream_name_analog;
1863 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
1864 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
1865 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1866 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1868 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1869 spec->multiout.max_channels;
1871 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1874 info->name = spec->stream_name_digital;
1875 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1876 if (spec->multiout.dig_out_nid) {
1877 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1878 *(spec->stream_digital_playback);
1879 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1880 spec->multiout.dig_out_nid;
1882 if (spec->dig_in_nid) {
1883 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1884 *(spec->stream_digital_capture);
1885 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1893 static void via_free(struct hda_codec *codec)
1895 struct via_spec *spec = codec->spec;
1900 via_free_kctls(codec);
1901 vt1708_stop_hp_work(spec);
1905 /* mute internal speaker if HP is plugged */
1906 static void via_hp_automute(struct hda_codec *codec)
1908 unsigned int present = 0;
1909 struct via_spec *spec = codec->spec;
1911 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
1912 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1914 if (!spec->hp_independent_mode) {
1915 struct snd_ctl_elem_id id;
1917 snd_hda_codec_amp_stereo(
1918 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1919 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1921 memset(&id, 0, sizeof(id));
1922 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1923 strcpy(id.name, "Front Playback Switch");
1924 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1929 /* mute mono out if HP or Line out is plugged */
1930 static void via_mono_automute(struct hda_codec *codec)
1932 unsigned int hp_present, lineout_present;
1933 struct via_spec *spec = codec->spec;
1935 if (spec->codec_type != VT1716S)
1938 lineout_present = snd_hda_codec_read(
1939 codec, spec->autocfg.line_out_pins[0], 0,
1940 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1942 /* Mute Mono Out if Line Out is plugged */
1943 if (lineout_present) {
1944 snd_hda_codec_amp_stereo(
1945 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1949 hp_present = snd_hda_codec_read(
1950 codec, spec->autocfg.hp_pins[0], 0,
1951 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1953 if (!spec->hp_independent_mode)
1954 snd_hda_codec_amp_stereo(
1955 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1956 hp_present ? HDA_AMP_MUTE : 0);
1959 static void via_gpio_control(struct hda_codec *codec)
1961 unsigned int gpio_data;
1962 unsigned int vol_counter;
1964 unsigned int master_vol;
1966 struct via_spec *spec = codec->spec;
1968 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1969 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1971 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1972 0xF84, 0) & 0x3F0000) >> 16;
1974 vol = vol_counter & 0x1F;
1975 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1976 AC_VERB_GET_AMP_GAIN_MUTE,
1979 if (gpio_data == 0x02) {
1980 /* unmute line out */
1981 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1982 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1984 if (vol_counter & 0x20) {
1985 /* decrease volume */
1986 if (vol > master_vol)
1988 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1992 /* increase volume */
1993 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1995 ((master_vol+vol) > 0x2A) ? 0x2A :
1998 } else if (!(gpio_data & 0x02)) {
2000 snd_hda_codec_amp_stereo(codec,
2001 spec->autocfg.line_out_pins[0],
2002 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2007 /* mute Internal-Speaker if HP is plugged */
2008 static void via_speaker_automute(struct hda_codec *codec)
2010 unsigned int hp_present;
2011 struct via_spec *spec = codec->spec;
2013 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2016 hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
2017 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2019 if (!spec->hp_independent_mode) {
2020 struct snd_ctl_elem_id id;
2021 snd_hda_codec_amp_stereo(
2022 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2023 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2025 memset(&id, 0, sizeof(id));
2026 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2027 strcpy(id.name, "Speaker Playback Switch");
2028 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2033 /* mute line-out and internal speaker if HP is plugged */
2034 static void via_hp_bind_automute(struct hda_codec *codec)
2036 unsigned int hp_present, present = 0;
2037 struct via_spec *spec = codec->spec;
2040 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2043 hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
2044 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2046 present = snd_hda_codec_read(codec, spec->autocfg.line_out_pins[0], 0,
2047 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2049 if (!spec->hp_independent_mode) {
2050 /* Mute Line-Outs */
2051 for (i = 0; i < spec->autocfg.line_outs; i++)
2052 snd_hda_codec_amp_stereo(
2053 codec, spec->autocfg.line_out_pins[i],
2055 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2057 present = hp_present;
2060 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2061 snd_hda_codec_amp_stereo(
2062 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2063 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2067 /* unsolicited event for jack sensing */
2068 static void via_unsol_event(struct hda_codec *codec,
2072 if (res & VIA_HP_EVENT)
2073 via_hp_automute(codec);
2074 if (res & VIA_GPIO_EVENT)
2075 via_gpio_control(codec);
2076 if (res & VIA_JACK_EVENT)
2077 set_jack_power_state(codec);
2078 if (res & VIA_MONO_EVENT)
2079 via_mono_automute(codec);
2080 if (res & VIA_SPEAKER_EVENT)
2081 via_speaker_automute(codec);
2082 if (res & VIA_BIND_HP_EVENT)
2083 via_hp_bind_automute(codec);
2086 static int via_init(struct hda_codec *codec)
2088 struct via_spec *spec = codec->spec;
2090 for (i = 0; i < spec->num_iverbs; i++)
2091 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2093 spec->codec_type = get_codec_type(codec);
2094 if (spec->codec_type == VT1708BCE)
2095 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2097 /* Lydia Add for EAPD enable */
2098 if (!spec->dig_in_nid) { /* No Digital In connection */
2099 if (spec->dig_in_pin) {
2100 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2101 AC_VERB_SET_PIN_WIDGET_CONTROL,
2103 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2104 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2106 } else /* enable SPDIF-input pin */
2107 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2108 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2110 /* assign slave outs */
2111 if (spec->slave_dig_outs[0])
2112 codec->slave_dig_outs = spec->slave_dig_outs;
2117 #ifdef SND_HDA_NEEDS_RESUME
2118 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2120 struct via_spec *spec = codec->spec;
2121 vt1708_stop_hp_work(spec);
2126 #ifdef CONFIG_SND_HDA_POWER_SAVE
2127 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2129 struct via_spec *spec = codec->spec;
2130 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2136 static struct hda_codec_ops via_patch_ops = {
2137 .build_controls = via_build_controls,
2138 .build_pcms = via_build_pcms,
2141 #ifdef SND_HDA_NEEDS_RESUME
2142 .suspend = via_suspend,
2144 #ifdef CONFIG_SND_HDA_POWER_SAVE
2145 .check_power_status = via_check_power_status,
2149 /* fill in the dac_nids table from the parsed pin configuration */
2150 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2151 const struct auto_pin_cfg *cfg)
2156 spec->multiout.num_dacs = cfg->line_outs;
2158 spec->multiout.dac_nids = spec->private_dac_nids;
2160 for(i = 0; i < 4; i++) {
2161 nid = cfg->line_out_pins[i];
2163 /* config dac list */
2165 case AUTO_SEQ_FRONT:
2166 spec->multiout.dac_nids[i] = 0x10;
2168 case AUTO_SEQ_CENLFE:
2169 spec->multiout.dac_nids[i] = 0x12;
2171 case AUTO_SEQ_SURROUND:
2172 spec->multiout.dac_nids[i] = 0x11;
2175 spec->multiout.dac_nids[i] = 0x13;
2184 /* add playback controls from the parsed DAC table */
2185 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2186 const struct auto_pin_cfg *cfg)
2189 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2190 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2193 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2194 nid = cfg->line_out_pins[i];
2199 nid_vol = nid_vols[i];
2201 if (i == AUTO_SEQ_CENLFE) {
2203 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2204 "Center Playback Volume",
2205 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2209 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2210 "LFE Playback Volume",
2211 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2215 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2216 "Center Playback Switch",
2217 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2221 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2222 "LFE Playback Switch",
2223 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2227 } else if (i == AUTO_SEQ_FRONT){
2228 /* add control to mixer index 0 */
2229 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2230 "Master Front Playback Volume",
2231 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2235 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2236 "Master Front Playback Switch",
2237 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2242 /* add control to PW3 */
2243 sprintf(name, "%s Playback Volume", chname[i]);
2244 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2245 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2249 sprintf(name, "%s Playback Switch", chname[i]);
2250 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2251 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2256 sprintf(name, "%s Playback Volume", chname[i]);
2257 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2258 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2262 sprintf(name, "%s Playback Switch", chname[i]);
2263 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2264 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2274 static void create_hp_imux(struct via_spec *spec)
2277 struct hda_input_mux *imux = &spec->private_imux[1];
2278 static const char *texts[] = { "OFF", "ON", NULL};
2280 /* for hp mode select */
2282 while (texts[i] != NULL) {
2283 imux->items[imux->num_items].label = texts[i];
2284 imux->items[imux->num_items].index = i;
2289 spec->hp_mux = &spec->private_imux[1];
2292 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2299 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2300 spec->hp_independent_mode_index = 1;
2302 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2303 "Headphone Playback Volume",
2304 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2307 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2308 "Headphone Playback Switch",
2309 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2313 create_hp_imux(spec);
2318 /* create playback/capture controls for input pins */
2319 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
2320 const struct auto_pin_cfg *cfg)
2322 static char *labels[] = {
2323 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2325 struct hda_input_mux *imux = &spec->private_imux[0];
2326 int i, err, idx = 0;
2328 /* for internal loopback recording select */
2329 imux->items[imux->num_items].label = "Stereo Mixer";
2330 imux->items[imux->num_items].index = idx;
2333 for (i = 0; i < AUTO_PIN_LAST; i++) {
2334 if (!cfg->input_pins[i])
2337 switch (cfg->input_pins[i]) {
2338 case 0x1d: /* Mic */
2342 case 0x1e: /* Line In */
2346 case 0x21: /* Front Mic */
2354 err = via_new_analog_input(spec, labels[i], idx, 0x17);
2357 imux->items[imux->num_items].label = labels[i];
2358 imux->items[imux->num_items].index = idx;
2364 #ifdef CONFIG_SND_HDA_POWER_SAVE
2365 static struct hda_amp_list vt1708_loopbacks[] = {
2366 { 0x17, HDA_INPUT, 1 },
2367 { 0x17, HDA_INPUT, 2 },
2368 { 0x17, HDA_INPUT, 3 },
2369 { 0x17, HDA_INPUT, 4 },
2374 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2376 unsigned int def_conf;
2377 unsigned char seqassoc;
2379 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2380 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2381 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2382 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2383 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2384 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2385 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2391 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2392 struct snd_ctl_elem_value *ucontrol)
2394 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2395 struct via_spec *spec = codec->spec;
2397 if (spec->codec_type != VT1708)
2399 spec->vt1708_jack_detectect =
2400 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2401 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2405 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2406 struct snd_ctl_elem_value *ucontrol)
2408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2409 struct via_spec *spec = codec->spec;
2412 if (spec->codec_type != VT1708)
2414 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2415 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2416 == !spec->vt1708_jack_detectect;
2417 if (spec->vt1708_jack_detectect) {
2418 mute_aa_path(codec, 1);
2419 notify_aa_path_ctls(codec);
2424 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2426 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2427 .name = "Jack Detect",
2429 .info = snd_ctl_boolean_mono_info,
2430 .get = vt1708_jack_detectect_get,
2431 .put = vt1708_jack_detectect_put,
2436 static int vt1708_parse_auto_config(struct hda_codec *codec)
2438 struct via_spec *spec = codec->spec;
2441 /* Add HP and CD pin config connect bit re-config action */
2442 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2443 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2445 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2448 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2451 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2452 return 0; /* can't find valid BIOS pin config */
2454 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2457 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2460 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
2463 /* add jack detect on/off control */
2464 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2468 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2470 if (spec->autocfg.dig_outs)
2471 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2472 spec->dig_in_pin = VT1708_DIGIN_PIN;
2473 if (spec->autocfg.dig_in_pin)
2474 spec->dig_in_nid = VT1708_DIGIN_NID;
2476 if (spec->kctls.list)
2477 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2479 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2481 spec->input_mux = &spec->private_imux[0];
2484 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2486 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2490 /* init callback for auto-configuration model -- overriding the default init */
2491 static int via_auto_init(struct hda_codec *codec)
2493 struct via_spec *spec = codec->spec;
2496 via_auto_init_multi_out(codec);
2497 via_auto_init_hp_out(codec);
2498 via_auto_init_analog_input(codec);
2499 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2500 via_hp_bind_automute(codec);
2502 via_hp_automute(codec);
2503 via_speaker_automute(codec);
2509 static void vt1708_update_hp_jack_state(struct work_struct *work)
2511 struct via_spec *spec = container_of(work, struct via_spec,
2512 vt1708_hp_work.work);
2513 if (spec->codec_type != VT1708)
2515 /* if jack state toggled */
2516 if (spec->vt1708_hp_present
2517 != (snd_hda_codec_read(spec->codec, spec->autocfg.hp_pins[0], 0,
2518 AC_VERB_GET_PIN_SENSE, 0) >> 31)) {
2519 spec->vt1708_hp_present ^= 1;
2520 via_hp_automute(spec->codec);
2522 vt1708_start_hp_work(spec);
2525 static int get_mux_nids(struct hda_codec *codec)
2527 struct via_spec *spec = codec->spec;
2528 hda_nid_t nid, conn[8];
2532 for (i = 0; i < spec->num_adc_nids; i++) {
2533 nid = spec->adc_nids[i];
2535 type = get_wcaps_type(get_wcaps(codec, nid));
2536 if (type == AC_WID_PIN)
2538 n = snd_hda_get_connections(codec, nid, conn,
2543 spec->mux_nids[i] = nid;
2552 static int patch_vt1708(struct hda_codec *codec)
2554 struct via_spec *spec;
2557 /* create a codec specific record */
2558 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2564 /* automatic parse from the BIOS config */
2565 err = vt1708_parse_auto_config(codec);
2570 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2571 "from BIOS. Using genenic mode...\n");
2575 spec->stream_name_analog = "VT1708 Analog";
2576 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2577 /* disable 32bit format on VT1708 */
2578 if (codec->vendor_id == 0x11061708)
2579 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2580 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2582 spec->stream_name_digital = "VT1708 Digital";
2583 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2584 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2587 if (!spec->adc_nids && spec->input_mux) {
2588 spec->adc_nids = vt1708_adc_nids;
2589 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2590 get_mux_nids(codec);
2591 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2595 codec->patch_ops = via_patch_ops;
2597 codec->patch_ops.init = via_auto_init;
2598 #ifdef CONFIG_SND_HDA_POWER_SAVE
2599 spec->loopback.amplist = vt1708_loopbacks;
2601 spec->codec = codec;
2602 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2606 /* capture mixer elements */
2607 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2608 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2609 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2610 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2611 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2612 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2613 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2615 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2616 /* The multiple "Capture Source" controls confuse alsamixer
2617 * So call somewhat different..
2619 /* .name = "Capture Source", */
2620 .name = "Input Source",
2622 .info = via_mux_enum_info,
2623 .get = via_mux_enum_get,
2624 .put = via_mux_enum_put,
2629 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2630 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2631 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2636 * generic initialization of ADC, input mixers and output mixers
2638 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2640 * Unmute ADC0-2 and set the default input to mic-in
2642 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2643 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2644 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2647 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2650 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2651 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2652 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2653 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2654 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2655 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2658 * Set up output selector (0x1a, 0x1b, 0x29)
2660 /* set vol=0 to output mixers */
2661 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2662 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2663 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2666 * Unmute PW3 and PW4
2668 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2669 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2671 /* Set input of PW4 as MW0 */
2672 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2673 /* PW9 Output enable */
2674 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2678 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2682 .nid = 0x10, /* NID to query formats and rates */
2684 .open = via_playback_pcm_open,
2685 .prepare = via_playback_multi_pcm_prepare,
2686 .cleanup = via_playback_multi_pcm_cleanup,
2690 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2694 .nid = 0x10, /* NID to query formats and rates */
2696 .open = via_playback_pcm_open,
2697 .prepare = via_playback_multi_pcm_prepare,
2698 .cleanup = via_playback_multi_pcm_cleanup,
2702 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2706 .nid = 0x14, /* NID to query formats and rates */
2708 .prepare = via_capture_pcm_prepare,
2709 .cleanup = via_capture_pcm_cleanup
2713 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2717 /* NID is set in via_build_pcms */
2719 .open = via_dig_playback_pcm_open,
2720 .close = via_dig_playback_pcm_close
2724 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2730 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2731 const struct auto_pin_cfg *cfg)
2736 if (cfg->line_outs == 4) /* 10 channels */
2737 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2738 else if (cfg->line_outs == 3) /* 6 channels */
2739 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2741 spec->multiout.dac_nids = spec->private_dac_nids;
2743 if (cfg->line_outs == 4) { /* 10 channels */
2744 for (i = 0; i < cfg->line_outs; i++) {
2745 nid = cfg->line_out_pins[i];
2747 /* config dac list */
2749 case AUTO_SEQ_FRONT:
2751 spec->multiout.dac_nids[i] = 0x10;
2753 case AUTO_SEQ_CENLFE:
2755 spec->multiout.dac_nids[i] = 0x12;
2757 case AUTO_SEQ_SURROUND:
2759 spec->multiout.dac_nids[i] = 0x11;
2763 spec->multiout.dac_nids[i] = 0x27;
2770 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2772 } else if (cfg->line_outs == 3) { /* 6 channels */
2773 for(i = 0; i < cfg->line_outs; i++) {
2774 nid = cfg->line_out_pins[i];
2776 /* config dac list */
2778 case AUTO_SEQ_FRONT:
2780 spec->multiout.dac_nids[i] = 0x10;
2782 case AUTO_SEQ_CENLFE:
2784 spec->multiout.dac_nids[i] = 0x12;
2786 case AUTO_SEQ_SURROUND:
2788 spec->multiout.dac_nids[i] = 0x11;
2800 /* add playback controls from the parsed DAC table */
2801 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2802 const struct auto_pin_cfg *cfg)
2805 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2806 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2809 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2810 nid = cfg->line_out_pins[i];
2815 nid_vol = nid_vols[i];
2817 if (i == AUTO_SEQ_CENLFE) {
2819 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2820 "Center Playback Volume",
2821 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2825 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2826 "LFE Playback Volume",
2827 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2831 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2832 "Center Playback Switch",
2833 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2837 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2838 "LFE Playback Switch",
2839 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2843 } else if (i == AUTO_SEQ_FRONT){
2844 /* ADD control to mixer index 0 */
2845 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2846 "Master Front Playback Volume",
2847 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2851 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2852 "Master Front Playback Switch",
2853 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2858 /* add control to PW3 */
2859 sprintf(name, "%s Playback Volume", chname[i]);
2860 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2861 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2865 sprintf(name, "%s Playback Switch", chname[i]);
2866 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2867 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2871 } else if (i == AUTO_SEQ_SURROUND) {
2872 sprintf(name, "%s Playback Volume", chname[i]);
2873 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2874 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2878 sprintf(name, "%s Playback Switch", chname[i]);
2879 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2880 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2884 } else if (i == AUTO_SEQ_SIDE) {
2885 sprintf(name, "%s Playback Volume", chname[i]);
2886 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2887 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2891 sprintf(name, "%s Playback Switch", chname[i]);
2892 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2893 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2903 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2910 if (spec->multiout.num_dacs == 5) /* 10 channels */
2911 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2912 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2913 spec->multiout.hp_nid = 0;
2914 spec->hp_independent_mode_index = 1;
2916 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2917 "Headphone Playback Volume",
2918 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2921 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2922 "Headphone Playback Switch",
2923 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2930 /* create playback/capture controls for input pins */
2931 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
2932 const struct auto_pin_cfg *cfg)
2934 static char *labels[] = {
2935 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2937 struct hda_input_mux *imux = &spec->private_imux[0];
2938 int i, err, idx = 0;
2940 /* for internal loopback recording select */
2941 imux->items[imux->num_items].label = "Stereo Mixer";
2942 imux->items[imux->num_items].index = idx;
2945 for (i = 0; i < AUTO_PIN_LAST; i++) {
2946 if (!cfg->input_pins[i])
2949 switch (cfg->input_pins[i]) {
2950 case 0x1d: /* Mic */
2954 case 0x1e: /* Line In */
2958 case 0x21: /* Front Mic */
2966 err = via_new_analog_input(spec, labels[i], idx, 0x18);
2969 imux->items[imux->num_items].label = labels[i];
2970 imux->items[imux->num_items].index = idx;
2976 static int vt1709_parse_auto_config(struct hda_codec *codec)
2978 struct via_spec *spec = codec->spec;
2981 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2984 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2987 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2988 return 0; /* can't find valid BIOS pin config */
2990 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2993 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2996 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
3000 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3002 if (spec->autocfg.dig_outs)
3003 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3004 spec->dig_in_pin = VT1709_DIGIN_PIN;
3005 if (spec->autocfg.dig_in_pin)
3006 spec->dig_in_nid = VT1709_DIGIN_NID;
3008 if (spec->kctls.list)
3009 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3011 spec->input_mux = &spec->private_imux[0];
3014 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3016 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
3020 #ifdef CONFIG_SND_HDA_POWER_SAVE
3021 static struct hda_amp_list vt1709_loopbacks[] = {
3022 { 0x18, HDA_INPUT, 1 },
3023 { 0x18, HDA_INPUT, 2 },
3024 { 0x18, HDA_INPUT, 3 },
3025 { 0x18, HDA_INPUT, 4 },
3030 static int patch_vt1709_10ch(struct hda_codec *codec)
3032 struct via_spec *spec;
3035 /* create a codec specific record */
3036 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3042 err = vt1709_parse_auto_config(codec);
3047 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3048 "Using genenic mode...\n");
3051 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3052 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3054 spec->stream_name_analog = "VT1709 Analog";
3055 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3056 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3058 spec->stream_name_digital = "VT1709 Digital";
3059 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3060 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3063 if (!spec->adc_nids && spec->input_mux) {
3064 spec->adc_nids = vt1709_adc_nids;
3065 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3066 get_mux_nids(codec);
3067 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3071 codec->patch_ops = via_patch_ops;
3073 codec->patch_ops.init = via_auto_init;
3074 codec->patch_ops.unsol_event = via_unsol_event;
3075 #ifdef CONFIG_SND_HDA_POWER_SAVE
3076 spec->loopback.amplist = vt1709_loopbacks;
3082 * generic initialization of ADC, input mixers and output mixers
3084 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3086 * Unmute ADC0-2 and set the default input to mic-in
3088 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3089 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3090 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3093 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3096 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3097 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3098 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3099 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3100 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3101 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3104 * Set up output selector (0x1a, 0x1b, 0x29)
3106 /* set vol=0 to output mixers */
3107 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3108 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3109 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3112 * Unmute PW3 and PW4
3114 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3115 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3117 /* Set input of PW4 as MW0 */
3118 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3119 /* PW9 Output enable */
3120 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3124 static int patch_vt1709_6ch(struct hda_codec *codec)
3126 struct via_spec *spec;
3129 /* create a codec specific record */
3130 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3136 err = vt1709_parse_auto_config(codec);
3141 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3142 "Using genenic mode...\n");
3145 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3146 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3148 spec->stream_name_analog = "VT1709 Analog";
3149 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3150 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3152 spec->stream_name_digital = "VT1709 Digital";
3153 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3154 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3157 if (!spec->adc_nids && spec->input_mux) {
3158 spec->adc_nids = vt1709_adc_nids;
3159 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3160 get_mux_nids(codec);
3161 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3165 codec->patch_ops = via_patch_ops;
3167 codec->patch_ops.init = via_auto_init;
3168 codec->patch_ops.unsol_event = via_unsol_event;
3169 #ifdef CONFIG_SND_HDA_POWER_SAVE
3170 spec->loopback.amplist = vt1709_loopbacks;
3175 /* capture mixer elements */
3176 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3177 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3178 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3179 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3180 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3182 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3183 /* The multiple "Capture Source" controls confuse alsamixer
3184 * So call somewhat different..
3186 /* .name = "Capture Source", */
3187 .name = "Input Source",
3189 .info = via_mux_enum_info,
3190 .get = via_mux_enum_get,
3191 .put = via_mux_enum_put,
3196 * generic initialization of ADC, input mixers and output mixers
3198 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3200 * Unmute ADC0-1 and set the default input to mic-in
3202 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3203 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3206 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3209 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3210 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3211 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3212 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3213 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3214 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3217 * Set up output mixers
3219 /* set vol=0 to output mixers */
3220 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3221 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3222 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3224 /* Setup default input to PW4 */
3225 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3226 /* PW9 Output enable */
3227 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3228 /* PW10 Input enable */
3229 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3233 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3235 * Unmute ADC0-1 and set the default input to mic-in
3237 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3238 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3241 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3244 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3245 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3246 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3247 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3248 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3249 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3252 * Set up output mixers
3254 /* set vol=0 to output mixers */
3255 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3256 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3257 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3259 /* Setup default input of PW4 to MW0 */
3260 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3261 /* PW9 Output enable */
3262 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3263 /* PW10 Input enable */
3264 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3268 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3269 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3270 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3271 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3272 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3273 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3274 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3275 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3276 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3277 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3281 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3282 struct hda_codec *codec,
3283 struct snd_pcm_substream *substream)
3285 int idle = substream->pstr->substream_opened == 1
3286 && substream->ref_count == 0;
3288 analog_low_current_mode(codec, idle);
3292 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3296 .nid = 0x10, /* NID to query formats and rates */
3298 .open = via_playback_pcm_open,
3299 .prepare = via_playback_multi_pcm_prepare,
3300 .cleanup = via_playback_multi_pcm_cleanup,
3301 .close = via_pcm_open_close
3305 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3309 .nid = 0x10, /* NID to query formats and rates */
3311 .open = via_playback_pcm_open,
3312 .prepare = via_playback_multi_pcm_prepare,
3313 .cleanup = via_playback_multi_pcm_cleanup
3317 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3321 .nid = 0x13, /* NID to query formats and rates */
3323 .open = via_pcm_open_close,
3324 .prepare = via_capture_pcm_prepare,
3325 .cleanup = via_capture_pcm_cleanup,
3326 .close = via_pcm_open_close
3330 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3334 /* NID is set in via_build_pcms */
3336 .open = via_dig_playback_pcm_open,
3337 .close = via_dig_playback_pcm_close,
3338 .prepare = via_dig_playback_pcm_prepare,
3339 .cleanup = via_dig_playback_pcm_cleanup
3343 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3349 /* fill in the dac_nids table from the parsed pin configuration */
3350 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3351 const struct auto_pin_cfg *cfg)
3356 spec->multiout.num_dacs = cfg->line_outs;
3358 spec->multiout.dac_nids = spec->private_dac_nids;
3360 for (i = 0; i < 4; i++) {
3361 nid = cfg->line_out_pins[i];
3363 /* config dac list */
3365 case AUTO_SEQ_FRONT:
3366 spec->multiout.dac_nids[i] = 0x10;
3368 case AUTO_SEQ_CENLFE:
3369 spec->multiout.dac_nids[i] = 0x24;
3371 case AUTO_SEQ_SURROUND:
3372 spec->multiout.dac_nids[i] = 0x11;
3375 spec->multiout.dac_nids[i] = 0x25;
3384 /* add playback controls from the parsed DAC table */
3385 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3386 const struct auto_pin_cfg *cfg)
3389 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3390 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3391 hda_nid_t nid, nid_vol = 0;
3394 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3395 nid = cfg->line_out_pins[i];
3400 nid_vol = nid_vols[i];
3402 if (i == AUTO_SEQ_CENLFE) {
3404 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3405 "Center Playback Volume",
3406 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3410 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3411 "LFE Playback Volume",
3412 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3416 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3417 "Center Playback Switch",
3418 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3422 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3423 "LFE Playback Switch",
3424 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3428 } else if (i == AUTO_SEQ_FRONT) {
3429 /* add control to mixer index 0 */
3430 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3431 "Master Front Playback Volume",
3432 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3436 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3437 "Master Front Playback Switch",
3438 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3443 /* add control to PW3 */
3444 sprintf(name, "%s Playback Volume", chname[i]);
3445 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3446 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3450 sprintf(name, "%s Playback Switch", chname[i]);
3451 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3452 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3457 sprintf(name, "%s Playback Volume", chname[i]);
3458 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3459 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3463 sprintf(name, "%s Playback Switch", chname[i]);
3464 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3465 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3475 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3482 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3483 spec->hp_independent_mode_index = 1;
3485 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3486 "Headphone Playback Volume",
3487 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3490 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3491 "Headphone Playback Switch",
3492 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3496 create_hp_imux(spec);
3501 /* create playback/capture controls for input pins */
3502 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
3503 const struct auto_pin_cfg *cfg)
3505 static char *labels[] = {
3506 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3508 struct hda_input_mux *imux = &spec->private_imux[0];
3509 int i, err, idx = 0;
3511 /* for internal loopback recording select */
3512 imux->items[imux->num_items].label = "Stereo Mixer";
3513 imux->items[imux->num_items].index = idx;
3516 for (i = 0; i < AUTO_PIN_LAST; i++) {
3517 if (!cfg->input_pins[i])
3520 switch (cfg->input_pins[i]) {
3521 case 0x1a: /* Mic */
3525 case 0x1b: /* Line In */
3529 case 0x1e: /* Front Mic */
3537 err = via_new_analog_input(spec, labels[i], idx, 0x16);
3540 imux->items[imux->num_items].label = labels[i];
3541 imux->items[imux->num_items].index = idx;
3547 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3549 struct via_spec *spec = codec->spec;
3552 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3555 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3558 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3559 return 0; /* can't find valid BIOS pin config */
3561 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3564 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3567 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
3571 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3573 if (spec->autocfg.dig_outs)
3574 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3575 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3576 if (spec->autocfg.dig_in_pin)
3577 spec->dig_in_nid = VT1708B_DIGIN_NID;
3579 if (spec->kctls.list)
3580 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3582 spec->input_mux = &spec->private_imux[0];
3585 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3587 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
3591 #ifdef CONFIG_SND_HDA_POWER_SAVE
3592 static struct hda_amp_list vt1708B_loopbacks[] = {
3593 { 0x16, HDA_INPUT, 1 },
3594 { 0x16, HDA_INPUT, 2 },
3595 { 0x16, HDA_INPUT, 3 },
3596 { 0x16, HDA_INPUT, 4 },
3600 static int patch_vt1708S(struct hda_codec *codec);
3601 static int patch_vt1708B_8ch(struct hda_codec *codec)
3603 struct via_spec *spec;
3606 if (get_codec_type(codec) == VT1708BCE)
3607 return patch_vt1708S(codec);
3608 /* create a codec specific record */
3609 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3615 /* automatic parse from the BIOS config */
3616 err = vt1708B_parse_auto_config(codec);
3621 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3622 "from BIOS. Using genenic mode...\n");
3625 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3626 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3628 spec->stream_name_analog = "VT1708B Analog";
3629 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3630 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3632 spec->stream_name_digital = "VT1708B Digital";
3633 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3634 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3636 if (!spec->adc_nids && spec->input_mux) {
3637 spec->adc_nids = vt1708B_adc_nids;
3638 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3639 get_mux_nids(codec);
3640 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3644 codec->patch_ops = via_patch_ops;
3646 codec->patch_ops.init = via_auto_init;
3647 codec->patch_ops.unsol_event = via_unsol_event;
3648 #ifdef CONFIG_SND_HDA_POWER_SAVE
3649 spec->loopback.amplist = vt1708B_loopbacks;
3655 static int patch_vt1708B_4ch(struct hda_codec *codec)
3657 struct via_spec *spec;
3660 /* create a codec specific record */
3661 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3667 /* automatic parse from the BIOS config */
3668 err = vt1708B_parse_auto_config(codec);
3673 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3674 "from BIOS. Using genenic mode...\n");
3677 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3678 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3680 spec->stream_name_analog = "VT1708B Analog";
3681 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3682 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3684 spec->stream_name_digital = "VT1708B Digital";
3685 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3686 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3688 if (!spec->adc_nids && spec->input_mux) {
3689 spec->adc_nids = vt1708B_adc_nids;
3690 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3691 get_mux_nids(codec);
3692 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3696 codec->patch_ops = via_patch_ops;
3698 codec->patch_ops.init = via_auto_init;
3699 codec->patch_ops.unsol_event = via_unsol_event;
3700 #ifdef CONFIG_SND_HDA_POWER_SAVE
3701 spec->loopback.amplist = vt1708B_loopbacks;
3707 /* Patch for VT1708S */
3709 /* capture mixer elements */
3710 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3711 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3712 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3713 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3714 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3715 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3716 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3720 /* The multiple "Capture Source" controls confuse alsamixer
3721 * So call somewhat different..
3723 /* .name = "Capture Source", */
3724 .name = "Input Source",
3726 .info = via_mux_enum_info,
3727 .get = via_mux_enum_get,
3728 .put = via_mux_enum_put,
3733 static struct hda_verb vt1708S_volume_init_verbs[] = {
3734 /* Unmute ADC0-1 and set the default input to mic-in */
3735 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3736 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3738 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3739 * analog-loopback mixer widget */
3740 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3741 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3742 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3743 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3744 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3745 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3747 /* Setup default input of PW4 to MW0 */
3748 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3749 /* PW9, PW10 Output enable */
3750 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3751 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3752 /* Enable Mic Boost Volume backdoor */
3754 /* don't bybass mixer */
3759 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3760 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3761 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3762 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3763 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3764 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3765 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3766 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3767 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3768 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3772 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3776 .nid = 0x10, /* NID to query formats and rates */
3778 .open = via_playback_pcm_open,
3779 .prepare = via_playback_multi_pcm_prepare,
3780 .cleanup = via_playback_multi_pcm_cleanup,
3781 .close = via_pcm_open_close
3785 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3789 .nid = 0x13, /* NID to query formats and rates */
3791 .open = via_pcm_open_close,
3792 .prepare = via_capture_pcm_prepare,
3793 .cleanup = via_capture_pcm_cleanup,
3794 .close = via_pcm_open_close
3798 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3802 /* NID is set in via_build_pcms */
3804 .open = via_dig_playback_pcm_open,
3805 .close = via_dig_playback_pcm_close,
3806 .prepare = via_dig_playback_pcm_prepare,
3807 .cleanup = via_dig_playback_pcm_cleanup
3811 /* fill in the dac_nids table from the parsed pin configuration */
3812 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3813 const struct auto_pin_cfg *cfg)
3818 spec->multiout.num_dacs = cfg->line_outs;
3820 spec->multiout.dac_nids = spec->private_dac_nids;
3822 for (i = 0; i < 4; i++) {
3823 nid = cfg->line_out_pins[i];
3825 /* config dac list */
3827 case AUTO_SEQ_FRONT:
3828 spec->multiout.dac_nids[i] = 0x10;
3830 case AUTO_SEQ_CENLFE:
3831 spec->multiout.dac_nids[i] = 0x24;
3833 case AUTO_SEQ_SURROUND:
3834 spec->multiout.dac_nids[i] = 0x11;
3837 spec->multiout.dac_nids[i] = 0x25;
3846 /* add playback controls from the parsed DAC table */
3847 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3848 const struct auto_pin_cfg *cfg)
3851 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3852 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3853 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3854 hda_nid_t nid, nid_vol, nid_mute;
3857 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3858 nid = cfg->line_out_pins[i];
3863 nid_vol = nid_vols[i];
3864 nid_mute = nid_mutes[i];
3866 if (i == AUTO_SEQ_CENLFE) {
3868 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3869 "Center Playback Volume",
3870 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3874 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3875 "LFE Playback Volume",
3876 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3880 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3881 "Center Playback Switch",
3882 HDA_COMPOSE_AMP_VAL(nid_mute,
3887 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3888 "LFE Playback Switch",
3889 HDA_COMPOSE_AMP_VAL(nid_mute,
3894 } else if (i == AUTO_SEQ_FRONT) {
3895 /* add control to mixer index 0 */
3896 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3897 "Master Front Playback Volume",
3898 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3902 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3903 "Master Front Playback Switch",
3904 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3910 sprintf(name, "%s Playback Volume", chname[i]);
3911 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3912 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3916 sprintf(name, "%s Playback Switch", chname[i]);
3917 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3918 HDA_COMPOSE_AMP_VAL(nid_mute,
3924 sprintf(name, "%s Playback Volume", chname[i]);
3925 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3926 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3930 sprintf(name, "%s Playback Switch", chname[i]);
3931 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3932 HDA_COMPOSE_AMP_VAL(nid_mute,
3943 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3950 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3951 spec->hp_independent_mode_index = 1;
3953 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3954 "Headphone Playback Volume",
3955 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3959 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3960 "Headphone Playback Switch",
3961 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3965 create_hp_imux(spec);
3970 /* create playback/capture controls for input pins */
3971 static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
3972 const struct auto_pin_cfg *cfg)
3974 static char *labels[] = {
3975 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3977 struct hda_input_mux *imux = &spec->private_imux[0];
3978 int i, err, idx = 0;
3980 /* for internal loopback recording select */
3981 imux->items[imux->num_items].label = "Stereo Mixer";
3982 imux->items[imux->num_items].index = 5;
3985 for (i = 0; i < AUTO_PIN_LAST; i++) {
3986 if (!cfg->input_pins[i])
3989 switch (cfg->input_pins[i]) {
3990 case 0x1a: /* Mic */
3994 case 0x1b: /* Line In */
3998 case 0x1e: /* Front Mic */
4006 err = via_new_analog_input(spec, labels[i], idx, 0x16);
4009 imux->items[imux->num_items].label = labels[i];
4010 imux->items[imux->num_items].index = idx-1;
4016 /* fill out digital output widgets; one for master and one for slave outputs */
4017 static void fill_dig_outs(struct hda_codec *codec)
4019 struct via_spec *spec = codec->spec;
4022 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4026 nid = spec->autocfg.dig_out_pins[i];
4029 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4032 if (!spec->multiout.dig_out_nid)
4033 spec->multiout.dig_out_nid = nid;
4035 spec->slave_dig_outs[0] = nid;
4036 break; /* at most two dig outs */
4041 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4043 struct via_spec *spec = codec->spec;
4046 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4049 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4052 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4053 return 0; /* can't find valid BIOS pin config */
4055 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4058 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4061 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4065 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4067 fill_dig_outs(codec);
4069 if (spec->kctls.list)
4070 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4072 spec->input_mux = &spec->private_imux[0];
4075 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4077 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4081 #ifdef CONFIG_SND_HDA_POWER_SAVE
4082 static struct hda_amp_list vt1708S_loopbacks[] = {
4083 { 0x16, HDA_INPUT, 1 },
4084 { 0x16, HDA_INPUT, 2 },
4085 { 0x16, HDA_INPUT, 3 },
4086 { 0x16, HDA_INPUT, 4 },
4091 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4092 int offset, int num_steps, int step_size)
4094 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4095 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4096 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4097 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4098 (0 << AC_AMPCAP_MUTE_SHIFT));
4101 static int patch_vt1708S(struct hda_codec *codec)
4103 struct via_spec *spec;
4106 /* create a codec specific record */
4107 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4113 /* automatic parse from the BIOS config */
4114 err = vt1708S_parse_auto_config(codec);
4119 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4120 "from BIOS. Using genenic mode...\n");
4123 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4124 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4126 spec->stream_name_analog = "VT1708S Analog";
4127 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4128 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4130 spec->stream_name_digital = "VT1708S Digital";
4131 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4133 if (!spec->adc_nids && spec->input_mux) {
4134 spec->adc_nids = vt1708S_adc_nids;
4135 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4136 get_mux_nids(codec);
4137 override_mic_boost(codec, 0x1a, 0, 3, 40);
4138 override_mic_boost(codec, 0x1e, 0, 3, 40);
4139 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4143 codec->patch_ops = via_patch_ops;
4145 codec->patch_ops.init = via_auto_init;
4146 codec->patch_ops.unsol_event = via_unsol_event;
4147 #ifdef CONFIG_SND_HDA_POWER_SAVE
4148 spec->loopback.amplist = vt1708S_loopbacks;
4151 /* correct names for VT1708BCE */
4152 if (get_codec_type(codec) == VT1708BCE) {
4153 kfree(codec->chip_name);
4154 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4155 snprintf(codec->bus->card->mixername,
4156 sizeof(codec->bus->card->mixername),
4157 "%s %s", codec->vendor_name, codec->chip_name);
4158 spec->stream_name_analog = "VT1708BCE Analog";
4159 spec->stream_name_digital = "VT1708BCE Digital";
4164 /* Patch for VT1702 */
4166 /* capture mixer elements */
4167 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4168 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4169 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4170 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4171 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4172 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4173 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4174 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4177 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4178 /* The multiple "Capture Source" controls confuse alsamixer
4179 * So call somewhat different..
4181 /* .name = "Capture Source", */
4182 .name = "Input Source",
4184 .info = via_mux_enum_info,
4185 .get = via_mux_enum_get,
4186 .put = via_mux_enum_put,
4191 static struct hda_verb vt1702_volume_init_verbs[] = {
4193 * Unmute ADC0-1 and set the default input to mic-in
4195 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4196 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4197 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4200 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4203 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4204 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4205 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4206 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4207 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4208 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4210 /* Setup default input of PW4 to MW0 */
4211 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4212 /* PW6 PW7 Output enable */
4213 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4214 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4222 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4223 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4224 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4225 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4226 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4227 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4228 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4232 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4236 .nid = 0x10, /* NID to query formats and rates */
4238 .open = via_playback_pcm_open,
4239 .prepare = via_playback_multi_pcm_prepare,
4240 .cleanup = via_playback_multi_pcm_cleanup,
4241 .close = via_pcm_open_close
4245 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4249 .nid = 0x12, /* NID to query formats and rates */
4251 .open = via_pcm_open_close,
4252 .prepare = via_capture_pcm_prepare,
4253 .cleanup = via_capture_pcm_cleanup,
4254 .close = via_pcm_open_close
4258 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4262 /* NID is set in via_build_pcms */
4264 .open = via_dig_playback_pcm_open,
4265 .close = via_dig_playback_pcm_close,
4266 .prepare = via_dig_playback_pcm_prepare,
4267 .cleanup = via_dig_playback_pcm_cleanup
4271 /* fill in the dac_nids table from the parsed pin configuration */
4272 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4273 const struct auto_pin_cfg *cfg)
4275 spec->multiout.num_dacs = 1;
4276 spec->multiout.dac_nids = spec->private_dac_nids;
4278 if (cfg->line_out_pins[0]) {
4279 /* config dac list */
4280 spec->multiout.dac_nids[0] = 0x10;
4286 /* add playback controls from the parsed DAC table */
4287 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4288 const struct auto_pin_cfg *cfg)
4292 if (!cfg->line_out_pins[0])
4295 /* add control to mixer index 0 */
4296 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4297 "Master Front Playback Volume",
4298 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4301 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4302 "Master Front Playback Switch",
4303 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4308 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4309 "Front Playback Volume",
4310 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4313 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4314 "Front Playback Switch",
4315 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4322 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4325 struct hda_input_mux *imux;
4326 static const char *texts[] = { "ON", "OFF", NULL};
4329 spec->multiout.hp_nid = 0x1D;
4330 spec->hp_independent_mode_index = 0;
4332 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4333 "Headphone Playback Volume",
4334 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4338 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4339 "Headphone Playback Switch",
4340 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4344 imux = &spec->private_imux[1];
4346 /* for hp mode select */
4348 while (texts[i] != NULL) {
4349 imux->items[imux->num_items].label = texts[i];
4350 imux->items[imux->num_items].index = i;
4355 spec->hp_mux = &spec->private_imux[1];
4359 /* create playback/capture controls for input pins */
4360 static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
4361 const struct auto_pin_cfg *cfg)
4363 static char *labels[] = {
4364 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4366 struct hda_input_mux *imux = &spec->private_imux[0];
4367 int i, err, idx = 0;
4369 /* for internal loopback recording select */
4370 imux->items[imux->num_items].label = "Stereo Mixer";
4371 imux->items[imux->num_items].index = 3;
4374 for (i = 0; i < AUTO_PIN_LAST; i++) {
4375 if (!cfg->input_pins[i])
4378 switch (cfg->input_pins[i]) {
4379 case 0x14: /* Mic */
4383 case 0x15: /* Line In */
4387 case 0x18: /* Front Mic */
4391 err = via_new_analog_input(spec, labels[i], idx, 0x1A);
4394 imux->items[imux->num_items].label = labels[i];
4395 imux->items[imux->num_items].index = idx-1;
4401 static int vt1702_parse_auto_config(struct hda_codec *codec)
4403 struct via_spec *spec = codec->spec;
4406 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4409 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4412 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4413 return 0; /* can't find valid BIOS pin config */
4415 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4418 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4421 /* limit AA path volume to 0 dB */
4422 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4423 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4424 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4425 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4426 (1 << AC_AMPCAP_MUTE_SHIFT));
4427 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
4431 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4433 fill_dig_outs(codec);
4435 if (spec->kctls.list)
4436 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4438 spec->input_mux = &spec->private_imux[0];
4441 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4446 #ifdef CONFIG_SND_HDA_POWER_SAVE
4447 static struct hda_amp_list vt1702_loopbacks[] = {
4448 { 0x1A, HDA_INPUT, 1 },
4449 { 0x1A, HDA_INPUT, 2 },
4450 { 0x1A, HDA_INPUT, 3 },
4451 { 0x1A, HDA_INPUT, 4 },
4456 static int patch_vt1702(struct hda_codec *codec)
4458 struct via_spec *spec;
4461 /* create a codec specific record */
4462 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4468 /* automatic parse from the BIOS config */
4469 err = vt1702_parse_auto_config(codec);
4474 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4475 "from BIOS. Using genenic mode...\n");
4478 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4479 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4481 spec->stream_name_analog = "VT1702 Analog";
4482 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4483 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4485 spec->stream_name_digital = "VT1702 Digital";
4486 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4488 if (!spec->adc_nids && spec->input_mux) {
4489 spec->adc_nids = vt1702_adc_nids;
4490 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4491 get_mux_nids(codec);
4492 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4496 codec->patch_ops = via_patch_ops;
4498 codec->patch_ops.init = via_auto_init;
4499 codec->patch_ops.unsol_event = via_unsol_event;
4500 #ifdef CONFIG_SND_HDA_POWER_SAVE
4501 spec->loopback.amplist = vt1702_loopbacks;
4507 /* Patch for VT1718S */
4509 /* capture mixer elements */
4510 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4511 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4512 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4513 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4514 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4515 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4516 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4519 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4520 /* The multiple "Capture Source" controls confuse alsamixer
4521 * So call somewhat different..
4523 .name = "Input Source",
4525 .info = via_mux_enum_info,
4526 .get = via_mux_enum_get,
4527 .put = via_mux_enum_put,
4532 static struct hda_verb vt1718S_volume_init_verbs[] = {
4534 * Unmute ADC0-1 and set the default input to mic-in
4536 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4537 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4540 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4543 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4544 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4545 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4546 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4547 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4548 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4550 /* Setup default input of Front HP to MW9 */
4551 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4552 /* PW9 PW10 Output enable */
4553 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4554 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4555 /* PW11 Input enable */
4556 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4557 /* Enable Boost Volume backdoor */
4559 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4560 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4561 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4562 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4563 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4564 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4565 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4566 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4567 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4568 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4569 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4570 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4571 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4572 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4573 /* Unmute MW4's index 0 */
4574 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4579 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4580 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4581 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4582 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4583 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4584 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4585 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4586 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4587 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4588 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4592 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4596 .nid = 0x8, /* NID to query formats and rates */
4598 .open = via_playback_pcm_open,
4599 .prepare = via_playback_multi_pcm_prepare,
4600 .cleanup = via_playback_multi_pcm_cleanup,
4601 .close = via_pcm_open_close,
4605 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4609 .nid = 0x10, /* NID to query formats and rates */
4611 .open = via_pcm_open_close,
4612 .prepare = via_capture_pcm_prepare,
4613 .cleanup = via_capture_pcm_cleanup,
4614 .close = via_pcm_open_close,
4618 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4622 .rates = SNDRV_PCM_RATE_48000,
4623 /* NID is set in via_build_pcms */
4625 .open = via_dig_playback_pcm_open,
4626 .close = via_dig_playback_pcm_close,
4627 .prepare = via_dig_playback_pcm_prepare,
4628 .cleanup = via_dig_playback_pcm_cleanup
4632 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4638 /* fill in the dac_nids table from the parsed pin configuration */
4639 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4640 const struct auto_pin_cfg *cfg)
4645 spec->multiout.num_dacs = cfg->line_outs;
4647 spec->multiout.dac_nids = spec->private_dac_nids;
4649 for (i = 0; i < 4; i++) {
4650 nid = cfg->line_out_pins[i];
4652 /* config dac list */
4654 case AUTO_SEQ_FRONT:
4655 spec->multiout.dac_nids[i] = 0x8;
4657 case AUTO_SEQ_CENLFE:
4658 spec->multiout.dac_nids[i] = 0xa;
4660 case AUTO_SEQ_SURROUND:
4661 spec->multiout.dac_nids[i] = 0x9;
4664 spec->multiout.dac_nids[i] = 0xb;
4673 /* add playback controls from the parsed DAC table */
4674 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4675 const struct auto_pin_cfg *cfg)
4678 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4679 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4680 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4681 hda_nid_t nid, nid_vol, nid_mute = 0;
4684 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4685 nid = cfg->line_out_pins[i];
4689 nid_vol = nid_vols[i];
4690 nid_mute = nid_mutes[i];
4692 if (i == AUTO_SEQ_CENLFE) {
4694 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4695 "Center Playback Volume",
4696 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4700 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4701 "LFE Playback Volume",
4702 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4706 err = via_add_control(
4707 spec, VIA_CTL_WIDGET_MUTE,
4708 "Center Playback Switch",
4709 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4713 err = via_add_control(
4714 spec, VIA_CTL_WIDGET_MUTE,
4715 "LFE Playback Switch",
4716 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4720 } else if (i == AUTO_SEQ_FRONT) {
4722 sprintf(name, "%s Playback Volume", chname[i]);
4723 err = via_add_control(
4724 spec, VIA_CTL_WIDGET_VOL, name,
4725 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4728 sprintf(name, "%s Playback Switch", chname[i]);
4729 err = via_add_control(
4730 spec, VIA_CTL_WIDGET_MUTE, name,
4731 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4736 sprintf(name, "%s Playback Volume", chname[i]);
4737 err = via_add_control(
4738 spec, VIA_CTL_WIDGET_VOL, name,
4739 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4742 sprintf(name, "%s Playback Switch", chname[i]);
4743 err = via_add_control(
4744 spec, VIA_CTL_WIDGET_MUTE, name,
4745 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4754 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4761 spec->multiout.hp_nid = 0xc; /* AOW4 */
4762 spec->hp_independent_mode_index = 1;
4764 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4765 "Headphone Playback Volume",
4766 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4770 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4771 "Headphone Playback Switch",
4772 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4776 create_hp_imux(spec);
4780 /* create playback/capture controls for input pins */
4781 static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4782 const struct auto_pin_cfg *cfg)
4784 static char *labels[] = {
4785 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4787 struct hda_input_mux *imux = &spec->private_imux[0];
4788 int i, err, idx = 0;
4790 /* for internal loopback recording select */
4791 imux->items[imux->num_items].label = "Stereo Mixer";
4792 imux->items[imux->num_items].index = 5;
4795 for (i = 0; i < AUTO_PIN_LAST; i++) {
4796 if (!cfg->input_pins[i])
4799 switch (cfg->input_pins[i]) {
4800 case 0x2b: /* Mic */
4804 case 0x2a: /* Line In */
4808 case 0x29: /* Front Mic */
4816 err = via_new_analog_input(spec, labels[i], idx, 0x21);
4819 imux->items[imux->num_items].label = labels[i];
4820 imux->items[imux->num_items].index = idx;
4826 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4828 struct via_spec *spec = codec->spec;
4831 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4835 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4838 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4839 return 0; /* can't find valid BIOS pin config */
4841 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4844 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4847 err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4851 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4853 fill_dig_outs(codec);
4855 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4856 spec->dig_in_nid = 0x13;
4858 if (spec->kctls.list)
4859 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4861 spec->input_mux = &spec->private_imux[0];
4864 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4866 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4871 #ifdef CONFIG_SND_HDA_POWER_SAVE
4872 static struct hda_amp_list vt1718S_loopbacks[] = {
4873 { 0x21, HDA_INPUT, 1 },
4874 { 0x21, HDA_INPUT, 2 },
4875 { 0x21, HDA_INPUT, 3 },
4876 { 0x21, HDA_INPUT, 4 },
4881 static int patch_vt1718S(struct hda_codec *codec)
4883 struct via_spec *spec;
4886 /* create a codec specific record */
4887 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4893 /* automatic parse from the BIOS config */
4894 err = vt1718S_parse_auto_config(codec);
4899 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4900 "from BIOS. Using genenic mode...\n");
4903 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4904 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4906 if (codec->vendor_id == 0x11060441)
4907 spec->stream_name_analog = "VT2020 Analog";
4908 else if (codec->vendor_id == 0x11064441)
4909 spec->stream_name_analog = "VT1828S Analog";
4911 spec->stream_name_analog = "VT1718S Analog";
4912 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4913 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4915 if (codec->vendor_id == 0x11060441)
4916 spec->stream_name_digital = "VT2020 Digital";
4917 else if (codec->vendor_id == 0x11064441)
4918 spec->stream_name_digital = "VT1828S Digital";
4920 spec->stream_name_digital = "VT1718S Digital";
4921 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4922 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4923 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4925 if (!spec->adc_nids && spec->input_mux) {
4926 spec->adc_nids = vt1718S_adc_nids;
4927 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4928 get_mux_nids(codec);
4929 override_mic_boost(codec, 0x2b, 0, 3, 40);
4930 override_mic_boost(codec, 0x29, 0, 3, 40);
4931 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4935 codec->patch_ops = via_patch_ops;
4937 codec->patch_ops.init = via_auto_init;
4938 codec->patch_ops.unsol_event = via_unsol_event,
4940 #ifdef CONFIG_SND_HDA_POWER_SAVE
4941 spec->loopback.amplist = vt1718S_loopbacks;
4947 /* Patch for VT1716S */
4949 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4950 struct snd_ctl_elem_info *uinfo)
4952 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4954 uinfo->value.integer.min = 0;
4955 uinfo->value.integer.max = 1;
4959 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4960 struct snd_ctl_elem_value *ucontrol)
4962 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4965 index = snd_hda_codec_read(codec, 0x26, 0,
4966 AC_VERB_GET_CONNECT_SEL, 0);
4968 *ucontrol->value.integer.value = index;
4973 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4974 struct snd_ctl_elem_value *ucontrol)
4976 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4977 struct via_spec *spec = codec->spec;
4978 int index = *ucontrol->value.integer.value;
4980 snd_hda_codec_write(codec, 0x26, 0,
4981 AC_VERB_SET_CONNECT_SEL, index);
4982 spec->dmic_enabled = index;
4983 set_jack_power_state(codec);
4988 /* capture mixer elements */
4989 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4990 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4991 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4992 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4993 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4994 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4995 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4998 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4999 .name = "Input Source",
5001 .info = via_mux_enum_info,
5002 .get = via_mux_enum_get,
5003 .put = via_mux_enum_put,
5008 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
5009 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
5011 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5012 .name = "Digital Mic Capture Switch",
5014 .info = vt1716s_dmic_info,
5015 .get = vt1716s_dmic_get,
5016 .put = vt1716s_dmic_put,
5022 /* mono-out mixer elements */
5023 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
5024 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
5028 static struct hda_verb vt1716S_volume_init_verbs[] = {
5030 * Unmute ADC0-1 and set the default input to mic-in
5032 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5033 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5036 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5039 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5040 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5041 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5042 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5043 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5044 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5046 /* MUX Indices: Stereo Mixer = 5 */
5047 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
5049 /* Setup default input of PW4 to MW0 */
5050 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
5052 /* Setup default input of SW1 as MW0 */
5053 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5055 /* Setup default input of SW4 as AOW0 */
5056 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5058 /* PW9 PW10 Output enable */
5059 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5060 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5062 /* Unmute SW1, PW12 */
5063 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5064 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5065 /* PW12 Output enable */
5066 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5067 /* Enable Boost Volume backdoor */
5069 /* don't bybass mixer */
5071 /* Enable mono output */
5077 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5078 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5079 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5080 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5081 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5082 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5083 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5084 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5085 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5086 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5090 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5094 .nid = 0x10, /* NID to query formats and rates */
5096 .open = via_playback_pcm_open,
5097 .prepare = via_playback_multi_pcm_prepare,
5098 .cleanup = via_playback_multi_pcm_cleanup,
5099 .close = via_pcm_open_close,
5103 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5107 .nid = 0x13, /* NID to query formats and rates */
5109 .open = via_pcm_open_close,
5110 .prepare = via_capture_pcm_prepare,
5111 .cleanup = via_capture_pcm_cleanup,
5112 .close = via_pcm_open_close,
5116 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5120 .rates = SNDRV_PCM_RATE_48000,
5121 /* NID is set in via_build_pcms */
5123 .open = via_dig_playback_pcm_open,
5124 .close = via_dig_playback_pcm_close,
5125 .prepare = via_dig_playback_pcm_prepare,
5126 .cleanup = via_dig_playback_pcm_cleanup
5130 /* fill in the dac_nids table from the parsed pin configuration */
5131 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5132 const struct auto_pin_cfg *cfg)
5136 spec->multiout.num_dacs = cfg->line_outs;
5138 spec->multiout.dac_nids = spec->private_dac_nids;
5140 for (i = 0; i < 3; i++) {
5141 nid = cfg->line_out_pins[i];
5143 /* config dac list */
5145 case AUTO_SEQ_FRONT:
5146 spec->multiout.dac_nids[i] = 0x10;
5148 case AUTO_SEQ_CENLFE:
5149 spec->multiout.dac_nids[i] = 0x25;
5151 case AUTO_SEQ_SURROUND:
5152 spec->multiout.dac_nids[i] = 0x11;
5161 /* add playback controls from the parsed DAC table */
5162 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5163 const struct auto_pin_cfg *cfg)
5166 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5167 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5168 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5169 hda_nid_t nid, nid_vol, nid_mute;
5172 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5173 nid = cfg->line_out_pins[i];
5178 nid_vol = nid_vols[i];
5179 nid_mute = nid_mutes[i];
5181 if (i == AUTO_SEQ_CENLFE) {
5182 err = via_add_control(
5183 spec, VIA_CTL_WIDGET_VOL,
5184 "Center Playback Volume",
5185 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5188 err = via_add_control(
5189 spec, VIA_CTL_WIDGET_VOL,
5190 "LFE Playback Volume",
5191 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5194 err = via_add_control(
5195 spec, VIA_CTL_WIDGET_MUTE,
5196 "Center Playback Switch",
5197 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5201 err = via_add_control(
5202 spec, VIA_CTL_WIDGET_MUTE,
5203 "LFE Playback Switch",
5204 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5208 } else if (i == AUTO_SEQ_FRONT) {
5210 err = via_add_control(
5211 spec, VIA_CTL_WIDGET_VOL,
5212 "Master Front Playback Volume",
5213 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5216 err = via_add_control(
5217 spec, VIA_CTL_WIDGET_MUTE,
5218 "Master Front Playback Switch",
5219 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5223 sprintf(name, "%s Playback Volume", chname[i]);
5224 err = via_add_control(
5225 spec, VIA_CTL_WIDGET_VOL, name,
5226 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5229 sprintf(name, "%s Playback Switch", chname[i]);
5230 err = via_add_control(
5231 spec, VIA_CTL_WIDGET_MUTE, name,
5232 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5237 sprintf(name, "%s Playback Volume", chname[i]);
5238 err = via_add_control(
5239 spec, VIA_CTL_WIDGET_VOL, name,
5240 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5243 sprintf(name, "%s Playback Switch", chname[i]);
5244 err = via_add_control(
5245 spec, VIA_CTL_WIDGET_MUTE, name,
5246 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5255 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5262 spec->multiout.hp_nid = 0x25; /* AOW3 */
5263 spec->hp_independent_mode_index = 1;
5265 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5266 "Headphone Playback Volume",
5267 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5271 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5272 "Headphone Playback Switch",
5273 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5277 create_hp_imux(spec);
5281 /* create playback/capture controls for input pins */
5282 static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5283 const struct auto_pin_cfg *cfg)
5285 static char *labels[] = {
5286 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5288 struct hda_input_mux *imux = &spec->private_imux[0];
5289 int i, err, idx = 0;
5291 /* for internal loopback recording select */
5292 imux->items[imux->num_items].label = "Stereo Mixer";
5293 imux->items[imux->num_items].index = 5;
5296 for (i = 0; i < AUTO_PIN_LAST; i++) {
5297 if (!cfg->input_pins[i])
5300 switch (cfg->input_pins[i]) {
5301 case 0x1a: /* Mic */
5305 case 0x1b: /* Line In */
5309 case 0x1e: /* Front Mic */
5317 err = via_new_analog_input(spec, labels[i], idx, 0x16);
5320 imux->items[imux->num_items].label = labels[i];
5321 imux->items[imux->num_items].index = idx-1;
5327 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5329 struct via_spec *spec = codec->spec;
5332 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5335 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5338 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5339 return 0; /* can't find valid BIOS pin config */
5341 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5344 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5347 err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
5351 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5353 fill_dig_outs(codec);
5355 if (spec->kctls.list)
5356 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5358 spec->input_mux = &spec->private_imux[0];
5361 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5363 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
5368 #ifdef CONFIG_SND_HDA_POWER_SAVE
5369 static struct hda_amp_list vt1716S_loopbacks[] = {
5370 { 0x16, HDA_INPUT, 1 },
5371 { 0x16, HDA_INPUT, 2 },
5372 { 0x16, HDA_INPUT, 3 },
5373 { 0x16, HDA_INPUT, 4 },
5378 static int patch_vt1716S(struct hda_codec *codec)
5380 struct via_spec *spec;
5383 /* create a codec specific record */
5384 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5390 /* automatic parse from the BIOS config */
5391 err = vt1716S_parse_auto_config(codec);
5396 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5397 "from BIOS. Using genenic mode...\n");
5400 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5401 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5403 spec->stream_name_analog = "VT1716S Analog";
5404 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5405 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5407 spec->stream_name_digital = "VT1716S Digital";
5408 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5410 if (!spec->adc_nids && spec->input_mux) {
5411 spec->adc_nids = vt1716S_adc_nids;
5412 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5413 get_mux_nids(codec);
5414 override_mic_boost(codec, 0x1a, 0, 3, 40);
5415 override_mic_boost(codec, 0x1e, 0, 3, 40);
5416 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5420 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5423 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5425 codec->patch_ops = via_patch_ops;
5427 codec->patch_ops.init = via_auto_init;
5428 codec->patch_ops.unsol_event = via_unsol_event,
5430 #ifdef CONFIG_SND_HDA_POWER_SAVE
5431 spec->loopback.amplist = vt1716S_loopbacks;
5439 /* capture mixer elements */
5440 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5441 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5442 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5443 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5444 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5445 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5446 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5449 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5450 /* The multiple "Capture Source" controls confuse alsamixer
5451 * So call somewhat different..
5453 /* .name = "Capture Source", */
5454 .name = "Input Source",
5456 .info = via_mux_enum_info,
5457 .get = via_mux_enum_get,
5458 .put = via_mux_enum_put,
5463 static struct hda_verb vt2002P_volume_init_verbs[] = {
5465 * Unmute ADC0-1 and set the default input to mic-in
5467 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5468 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5471 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5474 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5475 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5476 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5477 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5478 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5479 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5481 /* MUX Indices: Mic = 0 */
5482 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5483 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5485 /* PW9 Output enable */
5486 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5488 /* Enable Boost Volume backdoor */
5491 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5492 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5493 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5494 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5495 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5496 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5497 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5498 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5499 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5501 /* set MUX0/1/4/8 = 0 (AOW0) */
5502 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5503 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5504 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5505 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5507 /* set PW0 index=0 (MW0) */
5508 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5510 /* Enable AOW0 to MW9 */
5516 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5517 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5518 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5519 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5520 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5521 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5522 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5523 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5527 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5531 .nid = 0x8, /* NID to query formats and rates */
5533 .open = via_playback_pcm_open,
5534 .prepare = via_playback_multi_pcm_prepare,
5535 .cleanup = via_playback_multi_pcm_cleanup,
5536 .close = via_pcm_open_close,
5540 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5544 .nid = 0x10, /* NID to query formats and rates */
5546 .open = via_pcm_open_close,
5547 .prepare = via_capture_pcm_prepare,
5548 .cleanup = via_capture_pcm_cleanup,
5549 .close = via_pcm_open_close,
5553 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5557 .rates = SNDRV_PCM_RATE_48000,
5558 /* NID is set in via_build_pcms */
5560 .open = via_dig_playback_pcm_open,
5561 .close = via_dig_playback_pcm_close,
5562 .prepare = via_dig_playback_pcm_prepare,
5563 .cleanup = via_dig_playback_pcm_cleanup
5567 /* fill in the dac_nids table from the parsed pin configuration */
5568 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5569 const struct auto_pin_cfg *cfg)
5571 spec->multiout.num_dacs = 1;
5572 spec->multiout.dac_nids = spec->private_dac_nids;
5573 if (cfg->line_out_pins[0])
5574 spec->multiout.dac_nids[0] = 0x8;
5578 /* add playback controls from the parsed DAC table */
5579 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5580 const struct auto_pin_cfg *cfg)
5584 if (!cfg->line_out_pins[0])
5588 /* Line-Out: PortE */
5589 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5590 "Master Front Playback Volume",
5591 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5594 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5595 "Master Front Playback Switch",
5596 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5603 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5610 spec->multiout.hp_nid = 0x9;
5611 spec->hp_independent_mode_index = 1;
5613 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5614 "Headphone Playback Volume",
5615 HDA_COMPOSE_AMP_VAL(
5616 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5620 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5621 "Headphone Playback Switch",
5622 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5626 create_hp_imux(spec);
5630 /* create playback/capture controls for input pins */
5631 static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
5632 const struct auto_pin_cfg *cfg)
5634 static char *labels[] = {
5635 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5637 struct hda_input_mux *imux = &spec->private_imux[0];
5638 int i, err, idx = 0;
5640 for (i = 0; i < AUTO_PIN_LAST; i++) {
5641 if (!cfg->input_pins[i])
5644 switch (cfg->input_pins[i]) {
5645 case 0x2b: /* Mic */
5649 case 0x2a: /* Line In */
5653 case 0x29: /* Front Mic */
5657 err = via_new_analog_input(spec, labels[i], idx, 0x21);
5660 imux->items[imux->num_items].label = labels[i];
5661 imux->items[imux->num_items].index = idx;
5665 /* build volume/mute control of loopback */
5666 err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
5670 /* for internal loopback recording select */
5671 imux->items[imux->num_items].label = "Stereo Mixer";
5672 imux->items[imux->num_items].index = 3;
5675 /* for digital mic select */
5676 imux->items[imux->num_items].label = "Digital Mic";
5677 imux->items[imux->num_items].index = 4;
5683 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5685 struct via_spec *spec = codec->spec;
5689 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5693 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5697 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5698 return 0; /* can't find valid BIOS pin config */
5700 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5703 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5706 err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
5710 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5712 fill_dig_outs(codec);
5714 if (spec->kctls.list)
5715 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5717 spec->input_mux = &spec->private_imux[0];
5720 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5725 #ifdef CONFIG_SND_HDA_POWER_SAVE
5726 static struct hda_amp_list vt2002P_loopbacks[] = {
5727 { 0x21, HDA_INPUT, 0 },
5728 { 0x21, HDA_INPUT, 1 },
5729 { 0x21, HDA_INPUT, 2 },
5735 /* patch for vt2002P */
5736 static int patch_vt2002P(struct hda_codec *codec)
5738 struct via_spec *spec;
5741 /* create a codec specific record */
5742 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5748 /* automatic parse from the BIOS config */
5749 err = vt2002P_parse_auto_config(codec);
5754 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5755 "from BIOS. Using genenic mode...\n");
5758 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5759 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5761 spec->stream_name_analog = "VT2002P Analog";
5762 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5763 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5765 spec->stream_name_digital = "VT2002P Digital";
5766 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5768 if (!spec->adc_nids && spec->input_mux) {
5769 spec->adc_nids = vt2002P_adc_nids;
5770 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5771 get_mux_nids(codec);
5772 override_mic_boost(codec, 0x2b, 0, 3, 40);
5773 override_mic_boost(codec, 0x29, 0, 3, 40);
5774 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5778 codec->patch_ops = via_patch_ops;
5780 codec->patch_ops.init = via_auto_init;
5781 codec->patch_ops.unsol_event = via_unsol_event,
5783 #ifdef CONFIG_SND_HDA_POWER_SAVE
5784 spec->loopback.amplist = vt2002P_loopbacks;
5792 /* capture mixer elements */
5793 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5794 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5795 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5796 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5797 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5798 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5799 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5802 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5803 /* The multiple "Capture Source" controls confuse alsamixer
5804 * So call somewhat different..
5806 .name = "Input Source",
5808 .info = via_mux_enum_info,
5809 .get = via_mux_enum_get,
5810 .put = via_mux_enum_put,
5815 static struct hda_verb vt1812_volume_init_verbs[] = {
5817 * Unmute ADC0-1 and set the default input to mic-in
5819 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5820 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5823 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5826 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5827 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5828 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5829 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5830 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5831 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5833 /* MUX Indices: Mic = 0 */
5834 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5835 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5837 /* PW9 Output enable */
5838 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5840 /* Enable Boost Volume backdoor */
5843 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5844 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5845 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5846 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5847 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5848 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5849 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5850 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5851 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5852 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5853 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5855 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5856 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5857 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5858 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5859 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5860 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5862 /* Enable AOW0 to MW9 */
5868 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5869 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5870 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5871 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5872 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5873 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5874 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5875 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5876 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5880 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5884 .nid = 0x8, /* NID to query formats and rates */
5886 .open = via_playback_pcm_open,
5887 .prepare = via_playback_multi_pcm_prepare,
5888 .cleanup = via_playback_multi_pcm_cleanup,
5889 .close = via_pcm_open_close,
5893 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5897 .nid = 0x10, /* NID to query formats and rates */
5899 .open = via_pcm_open_close,
5900 .prepare = via_capture_pcm_prepare,
5901 .cleanup = via_capture_pcm_cleanup,
5902 .close = via_pcm_open_close,
5906 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5910 .rates = SNDRV_PCM_RATE_48000,
5911 /* NID is set in via_build_pcms */
5913 .open = via_dig_playback_pcm_open,
5914 .close = via_dig_playback_pcm_close,
5915 .prepare = via_dig_playback_pcm_prepare,
5916 .cleanup = via_dig_playback_pcm_cleanup
5919 /* fill in the dac_nids table from the parsed pin configuration */
5920 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5921 const struct auto_pin_cfg *cfg)
5923 spec->multiout.num_dacs = 1;
5924 spec->multiout.dac_nids = spec->private_dac_nids;
5925 if (cfg->line_out_pins[0])
5926 spec->multiout.dac_nids[0] = 0x8;
5931 /* add playback controls from the parsed DAC table */
5932 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5933 const struct auto_pin_cfg *cfg)
5937 if (!cfg->line_out_pins[0])
5940 /* Line-Out: PortE */
5941 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5942 "Master Front Playback Volume",
5943 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5946 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5947 "Master Front Playback Switch",
5948 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5955 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5962 spec->multiout.hp_nid = 0x9;
5963 spec->hp_independent_mode_index = 1;
5966 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5967 "Headphone Playback Volume",
5968 HDA_COMPOSE_AMP_VAL(
5969 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5973 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5974 "Headphone Playback Switch",
5975 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5979 create_hp_imux(spec);
5983 /* create playback/capture controls for input pins */
5984 static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
5985 const struct auto_pin_cfg *cfg)
5987 static char *labels[] = {
5988 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5990 struct hda_input_mux *imux = &spec->private_imux[0];
5991 int i, err, idx = 0;
5993 for (i = 0; i < AUTO_PIN_LAST; i++) {
5994 if (!cfg->input_pins[i])
5997 switch (cfg->input_pins[i]) {
5998 case 0x2b: /* Mic */
6002 case 0x2a: /* Line In */
6006 case 0x29: /* Front Mic */
6010 err = via_new_analog_input(spec, labels[i], idx, 0x21);
6013 imux->items[imux->num_items].label = labels[i];
6014 imux->items[imux->num_items].index = idx;
6017 /* build volume/mute control of loopback */
6018 err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
6022 /* for internal loopback recording select */
6023 imux->items[imux->num_items].label = "Stereo Mixer";
6024 imux->items[imux->num_items].index = 5;
6027 /* for digital mic select */
6028 imux->items[imux->num_items].label = "Digital Mic";
6029 imux->items[imux->num_items].index = 6;
6035 static int vt1812_parse_auto_config(struct hda_codec *codec)
6037 struct via_spec *spec = codec->spec;
6041 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6044 fill_dig_outs(codec);
6045 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6049 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6050 return 0; /* can't find valid BIOS pin config */
6052 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6055 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6058 err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
6062 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6064 fill_dig_outs(codec);
6066 if (spec->kctls.list)
6067 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6069 spec->input_mux = &spec->private_imux[0];
6072 spec->mixers[spec->num_mixers++] = via_hp_mixer;
6077 #ifdef CONFIG_SND_HDA_POWER_SAVE
6078 static struct hda_amp_list vt1812_loopbacks[] = {
6079 { 0x21, HDA_INPUT, 0 },
6080 { 0x21, HDA_INPUT, 1 },
6081 { 0x21, HDA_INPUT, 2 },
6087 /* patch for vt1812 */
6088 static int patch_vt1812(struct hda_codec *codec)
6090 struct via_spec *spec;
6093 /* create a codec specific record */
6094 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6100 /* automatic parse from the BIOS config */
6101 err = vt1812_parse_auto_config(codec);
6106 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6107 "from BIOS. Using genenic mode...\n");
6111 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6112 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6114 spec->stream_name_analog = "VT1812 Analog";
6115 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6116 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6118 spec->stream_name_digital = "VT1812 Digital";
6119 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6122 if (!spec->adc_nids && spec->input_mux) {
6123 spec->adc_nids = vt1812_adc_nids;
6124 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6125 get_mux_nids(codec);
6126 override_mic_boost(codec, 0x2b, 0, 3, 40);
6127 override_mic_boost(codec, 0x29, 0, 3, 40);
6128 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6132 codec->patch_ops = via_patch_ops;
6134 codec->patch_ops.init = via_auto_init;
6135 codec->patch_ops.unsol_event = via_unsol_event,
6137 #ifdef CONFIG_SND_HDA_POWER_SAVE
6138 spec->loopback.amplist = vt1812_loopbacks;
6147 static struct hda_codec_preset snd_hda_preset_via[] = {
6148 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6149 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6150 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6151 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6152 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6153 .patch = patch_vt1709_10ch},
6154 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6155 .patch = patch_vt1709_10ch},
6156 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6157 .patch = patch_vt1709_10ch},
6158 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6159 .patch = patch_vt1709_10ch},
6160 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6161 .patch = patch_vt1709_6ch},
6162 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6163 .patch = patch_vt1709_6ch},
6164 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6165 .patch = patch_vt1709_6ch},
6166 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6167 .patch = patch_vt1709_6ch},
6168 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6169 .patch = patch_vt1708B_8ch},
6170 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6171 .patch = patch_vt1708B_8ch},
6172 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6173 .patch = patch_vt1708B_8ch},
6174 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6175 .patch = patch_vt1708B_8ch},
6176 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6177 .patch = patch_vt1708B_4ch},
6178 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6179 .patch = patch_vt1708B_4ch},
6180 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6181 .patch = patch_vt1708B_4ch},
6182 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6183 .patch = patch_vt1708B_4ch},
6184 { .id = 0x11060397, .name = "VT1708S",
6185 .patch = patch_vt1708S},
6186 { .id = 0x11061397, .name = "VT1708S",
6187 .patch = patch_vt1708S},
6188 { .id = 0x11062397, .name = "VT1708S",
6189 .patch = patch_vt1708S},
6190 { .id = 0x11063397, .name = "VT1708S",
6191 .patch = patch_vt1708S},
6192 { .id = 0x11064397, .name = "VT1708S",
6193 .patch = patch_vt1708S},
6194 { .id = 0x11065397, .name = "VT1708S",
6195 .patch = patch_vt1708S},
6196 { .id = 0x11066397, .name = "VT1708S",
6197 .patch = patch_vt1708S},
6198 { .id = 0x11067397, .name = "VT1708S",
6199 .patch = patch_vt1708S},
6200 { .id = 0x11060398, .name = "VT1702",
6201 .patch = patch_vt1702},
6202 { .id = 0x11061398, .name = "VT1702",
6203 .patch = patch_vt1702},
6204 { .id = 0x11062398, .name = "VT1702",
6205 .patch = patch_vt1702},
6206 { .id = 0x11063398, .name = "VT1702",
6207 .patch = patch_vt1702},
6208 { .id = 0x11064398, .name = "VT1702",
6209 .patch = patch_vt1702},
6210 { .id = 0x11065398, .name = "VT1702",
6211 .patch = patch_vt1702},
6212 { .id = 0x11066398, .name = "VT1702",
6213 .patch = patch_vt1702},
6214 { .id = 0x11067398, .name = "VT1702",
6215 .patch = patch_vt1702},
6216 { .id = 0x11060428, .name = "VT1718S",
6217 .patch = patch_vt1718S},
6218 { .id = 0x11064428, .name = "VT1718S",
6219 .patch = patch_vt1718S},
6220 { .id = 0x11060441, .name = "VT2020",
6221 .patch = patch_vt1718S},
6222 { .id = 0x11064441, .name = "VT1828S",
6223 .patch = patch_vt1718S},
6224 { .id = 0x11060433, .name = "VT1716S",
6225 .patch = patch_vt1716S},
6226 { .id = 0x1106a721, .name = "VT1716S",
6227 .patch = patch_vt1716S},
6228 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6229 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6230 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6234 MODULE_ALIAS("snd-hda-codec-id:1106*");
6236 static struct hda_codec_preset_list via_list = {
6237 .preset = snd_hda_preset_via,
6238 .owner = THIS_MODULE,
6241 MODULE_LICENSE("GPL");
6242 MODULE_DESCRIPTION("VIA HD-audio codec");
6244 static int __init patch_via_init(void)
6246 return snd_hda_add_codec_preset(&via_list);
6249 static void __exit patch_via_exit(void)
6251 snd_hda_delete_codec_preset(&via_list);
6254 module_init(patch_via_init)
6255 module_exit(patch_via_exit)