2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <sound/core.h>
53 #include <sound/asoundef.h>
54 #include "hda_codec.h"
55 #include "hda_local.h"
57 #define NID_MAPPING (-1)
60 #define AMP_VAL_IDX_SHIFT 19
61 #define AMP_VAL_IDX_MASK (0x0f<<19)
64 #define VT1708_HP_NID 0x13
65 #define VT1708_DIGOUT_NID 0x14
66 #define VT1708_DIGIN_NID 0x16
67 #define VT1708_DIGIN_PIN 0x26
68 #define VT1708_HP_PIN_NID 0x20
69 #define VT1708_CD_PIN_NID 0x24
71 #define VT1709_HP_DAC_NID 0x28
72 #define VT1709_DIGOUT_NID 0x13
73 #define VT1709_DIGIN_NID 0x17
74 #define VT1709_DIGIN_PIN 0x25
76 #define VT1708B_HP_NID 0x25
77 #define VT1708B_DIGOUT_NID 0x12
78 #define VT1708B_DIGIN_NID 0x15
79 #define VT1708B_DIGIN_PIN 0x21
81 #define VT1708S_HP_NID 0x25
82 #define VT1708S_DIGOUT_NID 0x12
84 #define VT1702_HP_NID 0x17
85 #define VT1702_DIGOUT_NID 0x11
105 #define VT2002P_COMPATIBLE(spec) \
106 ((spec)->codec_type == VT2002P ||\
107 (spec)->codec_type == VT1812 ||\
108 (spec)->codec_type == VT1802)
117 /* codec parameterization */
118 const struct snd_kcontrol_new *mixers[6];
119 unsigned int num_mixers;
121 const struct hda_verb *init_verbs[5];
122 unsigned int num_iverbs;
124 char stream_name_analog[32];
125 char stream_name_hp[32];
126 const struct hda_pcm_stream *stream_analog_playback;
127 const struct hda_pcm_stream *stream_analog_capture;
129 char stream_name_digital[32];
130 const struct hda_pcm_stream *stream_digital_playback;
131 const struct hda_pcm_stream *stream_digital_capture;
134 struct hda_multi_out multiout;
135 hda_nid_t slave_dig_outs[2];
136 hda_nid_t hp_dac_nid;
138 struct nid_path out_path[4];
139 struct nid_path hp_path;
140 struct nid_path hp_dep_path;
141 struct nid_path speaker_path;
144 unsigned int num_adc_nids;
145 hda_nid_t adc_nids[3];
146 hda_nid_t mux_nids[3];
147 hda_nid_t aa_mix_nid;
148 hda_nid_t dig_in_nid;
149 hda_nid_t dig_in_pin;
152 const struct hda_input_mux *input_mux;
153 unsigned int cur_mux[3];
155 /* PCM information */
156 struct hda_pcm pcm_rec[3];
158 /* dynamic controls, init_verbs and input_mux */
159 struct auto_pin_cfg autocfg;
160 struct snd_array kctls;
161 struct hda_input_mux private_imux[2];
162 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
165 const struct hda_input_mux *hp_mux;
166 unsigned int hp_independent_mode;
167 unsigned int hp_independent_mode_index;
168 unsigned int dmic_enabled;
169 unsigned int no_pin_power_ctl;
170 enum VIA_HDA_CODEC codec_type;
173 unsigned int smart51_nums;
174 hda_nid_t smart51_pins[2];
176 const char *smart51_labels[2];
177 unsigned int smart51_enabled;
179 /* work to check hp jack state */
180 struct hda_codec *codec;
181 struct delayed_work vt1708_hp_work;
182 int vt1708_jack_detect;
183 int vt1708_hp_present;
185 void (*set_widgets_power_state)(struct hda_codec *codec);
187 #ifdef CONFIG_SND_HDA_POWER_SAVE
188 struct hda_loopback_check loopback;
192 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
193 static struct via_spec * via_new_spec(struct hda_codec *codec)
195 struct via_spec *spec;
197 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
203 spec->codec_type = get_codec_type(codec);
204 /* VT1708BCE & VT1708S are almost same */
205 if (spec->codec_type == VT1708BCE)
206 spec->codec_type = VT1708S;
210 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
212 u32 vendor_id = codec->vendor_id;
213 u16 ven_id = vendor_id >> 16;
214 u16 dev_id = vendor_id & 0xffff;
215 enum VIA_HDA_CODEC codec_type;
218 if (ven_id != 0x1106)
219 codec_type = UNKNOWN;
220 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
222 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
223 codec_type = VT1709_10CH;
224 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
225 codec_type = VT1709_6CH;
226 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
227 codec_type = VT1708B_8CH;
228 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
229 codec_type = VT1708BCE;
230 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
231 codec_type = VT1708B_4CH;
232 else if ((dev_id & 0xfff) == 0x397
233 && (dev_id >> 12) < 8)
234 codec_type = VT1708S;
235 else if ((dev_id & 0xfff) == 0x398
236 && (dev_id >> 12) < 8)
238 else if ((dev_id & 0xfff) == 0x428
239 && (dev_id >> 12) < 8)
240 codec_type = VT1718S;
241 else if (dev_id == 0x0433 || dev_id == 0xa721)
242 codec_type = VT1716S;
243 else if (dev_id == 0x0441 || dev_id == 0x4441)
244 codec_type = VT1718S;
245 else if (dev_id == 0x0438 || dev_id == 0x4438)
246 codec_type = VT2002P;
247 else if (dev_id == 0x0448)
249 else if (dev_id == 0x0440)
250 codec_type = VT1708S;
251 else if ((dev_id & 0xfff) == 0x446)
254 codec_type = UNKNOWN;
258 #define VIA_JACK_EVENT 0x20
259 #define VIA_HP_EVENT 0x01
260 #define VIA_GPIO_EVENT 0x02
261 #define VIA_LINE_EVENT 0x03
266 VIA_CTL_WIDGET_ANALOG_MUTE,
269 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
270 static int is_aa_path_mute(struct hda_codec *codec);
272 static void vt1708_start_hp_work(struct via_spec *spec)
274 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
276 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
277 !spec->vt1708_jack_detect);
278 if (!delayed_work_pending(&spec->vt1708_hp_work))
279 schedule_delayed_work(&spec->vt1708_hp_work,
280 msecs_to_jiffies(100));
283 static void vt1708_stop_hp_work(struct via_spec *spec)
285 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
287 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
288 && !is_aa_path_mute(spec->codec))
290 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
291 !spec->vt1708_jack_detect);
292 cancel_delayed_work_sync(&spec->vt1708_hp_work);
295 static void set_widgets_power_state(struct hda_codec *codec)
297 struct via_spec *spec = codec->spec;
298 if (spec->set_widgets_power_state)
299 spec->set_widgets_power_state(codec);
302 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
303 struct snd_ctl_elem_value *ucontrol)
305 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
306 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
308 set_widgets_power_state(codec);
309 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
310 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
311 if (is_aa_path_mute(codec))
312 vt1708_start_hp_work(codec->spec);
314 vt1708_stop_hp_work(codec->spec);
319 /* modify .put = snd_hda_mixer_amp_switch_put */
320 #define ANALOG_INPUT_MUTE \
321 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
324 .info = snd_hda_mixer_amp_switch_info, \
325 .get = snd_hda_mixer_amp_switch_get, \
326 .put = analog_input_switch_put, \
327 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
329 static const struct snd_kcontrol_new via_control_templates[] = {
330 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
331 HDA_CODEC_MUTE(NULL, 0, 0, 0),
336 /* add dynamic controls */
337 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
338 const struct snd_kcontrol_new *tmpl,
341 struct snd_kcontrol_new *knew;
343 snd_array_init(&spec->kctls, sizeof(*knew), 32);
344 knew = snd_array_new(&spec->kctls);
351 knew->name = kstrdup(name, GFP_KERNEL);
358 static int __via_add_control(struct via_spec *spec, int type, const char *name,
359 int idx, unsigned long val)
361 struct snd_kcontrol_new *knew;
363 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
367 if (get_amp_nid_(val))
368 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
369 knew->private_value = val;
373 #define via_add_control(spec, type, name, val) \
374 __via_add_control(spec, type, name, 0, val)
376 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
378 static void via_free_kctls(struct hda_codec *codec)
380 struct via_spec *spec = codec->spec;
382 if (spec->kctls.list) {
383 struct snd_kcontrol_new *kctl = spec->kctls.list;
385 for (i = 0; i < spec->kctls.used; i++)
388 snd_array_free(&spec->kctls);
391 /* create input playback/capture controls for the given pin */
392 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
393 int type_idx, int idx, int mix_nid)
398 sprintf(name, "%s Playback Volume", ctlname);
399 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
400 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
403 sprintf(name, "%s Playback Switch", ctlname);
404 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
405 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
411 /* return the index of the given widget nid as the source of mux;
412 * return -1 if not found;
413 * if num_conns is non-NULL, set the total number of connections
415 static int __get_connection_index(struct hda_codec *codec, hda_nid_t mux,
416 hda_nid_t nid, int *num_conns)
418 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
421 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
424 for (i = 0; i < nums; i++)
430 #define get_connection_index(codec, mux, nid) \
431 __get_connection_index(codec, mux, nid, NULL)
433 /* unmute input amp and select the specificed source */
434 static void unmute_and_select(struct hda_codec *codec, hda_nid_t nid,
435 hda_nid_t src, hda_nid_t mix)
439 idx = __get_connection_index(codec, nid, src, &num_conns);
443 /* select the route explicitly when multiple connections exist */
445 snd_hda_codec_write(codec, nid, 0,
446 AC_VERB_SET_CONNECT_SEL, idx);
447 /* unmute if the input amp is present */
448 if (!(query_amp_caps(codec, nid, HDA_INPUT) &
449 (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE)))
451 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
454 /* unmute AA-path if present */
457 idx = __get_connection_index(codec, nid, mix, NULL);
459 snd_hda_codec_write(codec, nid, 0,
460 AC_VERB_SET_AMP_GAIN_MUTE,
464 /* set the given pin as output */
465 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
470 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
472 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
473 snd_hda_codec_write(codec, pin, 0,
474 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
477 static void via_auto_init_output(struct hda_codec *codec, hda_nid_t pin,
478 int pin_type, struct nid_path *path)
480 struct via_spec *spec = codec->spec;
488 init_output_pin(codec, pin, pin_type);
489 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
490 if (caps & AC_AMPCAP_MUTE) {
492 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
493 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
497 /* initialize the output path */
499 for (i = 0; i < path->depth; i++) {
500 unmute_and_select(codec, nid, path->idx[i], spec->aa_mix_nid);
502 if (query_amp_caps(codec, nid, HDA_OUTPUT) &
503 (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE))
504 snd_hda_codec_write(codec, nid, 0,
505 AC_VERB_SET_AMP_GAIN_MUTE,
511 static void via_auto_init_multi_out(struct hda_codec *codec)
513 struct via_spec *spec = codec->spec;
516 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++)
517 via_auto_init_output(codec, spec->autocfg.line_out_pins[i],
518 PIN_OUT, &spec->out_path[i]);
521 static void via_auto_init_hp_out(struct hda_codec *codec)
523 struct via_spec *spec = codec->spec;
525 if (spec->hp_dac_nid)
526 via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP,
529 via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP,
533 static void via_auto_init_speaker_out(struct hda_codec *codec)
535 struct via_spec *spec = codec->spec;
537 if (spec->autocfg.speaker_outs)
538 via_auto_init_output(codec, spec->autocfg.speaker_pins[0],
539 PIN_OUT, &spec->speaker_path);
542 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
544 static void via_auto_init_analog_input(struct hda_codec *codec)
546 struct via_spec *spec = codec->spec;
547 const struct auto_pin_cfg *cfg = &spec->autocfg;
548 hda_nid_t conn[HDA_MAX_CONNECTIONS];
553 for (i = 0; i < spec->num_adc_nids; i++) {
554 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
555 AC_VERB_SET_AMP_GAIN_MUTE,
560 for (i = 0; i < cfg->num_inputs; i++) {
561 hda_nid_t nid = cfg->inputs[i].pin;
562 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
564 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
568 snd_hda_codec_write(codec, nid, 0,
569 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
573 for (i = 0; i < spec->num_adc_nids; i++) {
574 const struct hda_input_mux *imux = spec->input_mux;
575 if (!imux || !spec->mux_nids[i])
577 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
578 AC_VERB_SET_CONNECT_SEL,
579 imux->items[spec->cur_mux[i]].index);
583 if (!spec->aa_mix_nid)
585 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
587 for (i = 0; i < num_conns; i++) {
588 unsigned int caps = get_wcaps(codec, conn[i]);
589 if (get_wcaps_type(caps) == AC_WID_PIN)
590 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
591 AC_VERB_SET_AMP_GAIN_MUTE,
596 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
597 unsigned int *affected_parm)
600 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
601 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
602 >> AC_DEFCFG_MISC_SHIFT
603 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
604 struct via_spec *spec = codec->spec;
605 unsigned present = 0;
607 no_presence |= spec->no_pin_power_ctl;
609 present = snd_hda_jack_detect(codec, nid);
610 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
611 || ((no_presence || present)
612 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
613 *affected_parm = AC_PWRST_D0; /* if it's connected */
618 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
621 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
622 struct snd_ctl_elem_info *uinfo)
624 static const char * const texts[] = {
625 "Disabled", "Enabled"
628 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
630 uinfo->value.enumerated.items = 2;
631 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
632 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
633 strcpy(uinfo->value.enumerated.name,
634 texts[uinfo->value.enumerated.item]);
638 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
639 struct snd_ctl_elem_value *ucontrol)
641 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
642 struct via_spec *spec = codec->spec;
643 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
647 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_value *ucontrol)
650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
651 struct via_spec *spec = codec->spec;
652 unsigned int val = !ucontrol->value.enumerated.item[0];
654 if (val == spec->no_pin_power_ctl)
656 spec->no_pin_power_ctl = val;
657 set_widgets_power_state(codec);
661 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
662 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
663 .name = "Dynamic Power-Control",
664 .info = via_pin_power_ctl_info,
665 .get = via_pin_power_ctl_get,
666 .put = via_pin_power_ctl_put,
673 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
674 struct snd_ctl_elem_info *uinfo)
676 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
677 struct via_spec *spec = codec->spec;
678 return snd_hda_input_mux_info(spec->input_mux, uinfo);
681 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
682 struct snd_ctl_elem_value *ucontrol)
684 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
685 struct via_spec *spec = codec->spec;
686 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
688 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
692 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
693 struct snd_ctl_elem_value *ucontrol)
695 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
696 struct via_spec *spec = codec->spec;
697 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
700 if (!spec->mux_nids[adc_idx])
702 /* switch to D0 beofre change index */
703 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
704 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
705 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
706 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
708 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
709 spec->mux_nids[adc_idx],
710 &spec->cur_mux[adc_idx]);
711 /* update jack power state */
712 set_widgets_power_state(codec);
717 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
718 struct snd_ctl_elem_info *uinfo)
720 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
721 struct via_spec *spec = codec->spec;
722 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
725 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
726 struct snd_ctl_elem_value *ucontrol)
728 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
729 struct via_spec *spec = codec->spec;
731 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
735 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
736 struct snd_ctl_elem_value *ucontrol)
738 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
739 struct via_spec *spec = codec->spec;
740 hda_nid_t nid = kcontrol->private_value;
741 unsigned int pinsel = ucontrol->value.enumerated.item[0];
742 /* Get Independent Mode index of headphone pin widget */
743 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
745 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
747 /* update jack power state */
748 set_widgets_power_state(codec);
752 static const struct snd_kcontrol_new via_hp_mixer = {
753 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
754 .name = "Independent HP",
755 .info = via_independent_hp_info,
756 .get = via_independent_hp_get,
757 .put = via_independent_hp_put,
760 static int via_hp_build(struct hda_codec *codec)
762 struct via_spec *spec = codec->spec;
763 struct snd_kcontrol_new *knew;
766 nid = spec->autocfg.hp_pins[0];
767 knew = via_clone_control(spec, &via_hp_mixer);
771 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
772 knew->private_value = nid;
777 static void notify_aa_path_ctls(struct hda_codec *codec)
779 struct via_spec *spec = codec->spec;
782 for (i = 0; i < spec->smart51_nums; i++) {
783 struct snd_kcontrol *ctl;
784 struct snd_ctl_elem_id id;
785 memset(&id, 0, sizeof(id));
786 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
787 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
788 ctl = snd_hda_find_mixer_ctl(codec, id.name);
790 snd_ctl_notify(codec->bus->card,
791 SNDRV_CTL_EVENT_MASK_VALUE,
796 static void mute_aa_path(struct hda_codec *codec, int mute)
798 struct via_spec *spec = codec->spec;
799 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
802 /* check AA path's mute status */
803 for (i = 0; i < spec->smart51_nums; i++) {
804 if (spec->smart51_idxs[i] < 0)
806 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
807 HDA_INPUT, spec->smart51_idxs[i],
812 static bool is_smart51_candidate(struct hda_codec *codec, hda_nid_t pin)
814 struct via_spec *spec = codec->spec;
815 const struct auto_pin_cfg *cfg = &spec->autocfg;
818 for (i = 0; i < cfg->num_inputs; i++) {
820 if (pin != cfg->inputs[i].pin)
822 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
824 defcfg = snd_hda_codec_get_pincfg(codec, pin);
825 if (snd_hda_get_input_pin_attr(defcfg) < INPUT_PIN_ATTR_NORMAL)
832 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
834 struct via_spec *spec = codec->spec;
837 for (i = 0; i < spec->smart51_nums; i++)
838 if (spec->smart51_pins[i] == pin)
843 static int via_smart51_info(struct snd_kcontrol *kcontrol,
844 struct snd_ctl_elem_info *uinfo)
846 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
848 uinfo->value.integer.min = 0;
849 uinfo->value.integer.max = 1;
853 static int via_smart51_get(struct snd_kcontrol *kcontrol,
854 struct snd_ctl_elem_value *ucontrol)
856 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
857 struct via_spec *spec = codec->spec;
861 for (i = 0; i < spec->smart51_nums; i++) {
862 hda_nid_t nid = spec->smart51_pins[i];
864 ctl = snd_hda_codec_read(codec, nid, 0,
865 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
866 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
869 *ucontrol->value.integer.value = on;
873 static int via_smart51_put(struct snd_kcontrol *kcontrol,
874 struct snd_ctl_elem_value *ucontrol)
876 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
877 struct via_spec *spec = codec->spec;
878 int out_in = *ucontrol->value.integer.value
879 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
882 for (i = 0; i < spec->smart51_nums; i++) {
883 hda_nid_t nid = spec->smart51_pins[i];
886 parm = snd_hda_codec_read(codec, nid, 0,
887 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
888 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
890 snd_hda_codec_write(codec, nid, 0,
891 AC_VERB_SET_PIN_WIDGET_CONTROL,
893 if (out_in == AC_PINCTL_OUT_EN) {
894 mute_aa_path(codec, 1);
895 notify_aa_path_ctls(codec);
898 spec->smart51_enabled = *ucontrol->value.integer.value;
899 set_widgets_power_state(codec);
903 static const struct snd_kcontrol_new via_smart51_mixer = {
904 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
907 .info = via_smart51_info,
908 .get = via_smart51_get,
909 .put = via_smart51_put,
912 static int via_smart51_build(struct hda_codec *codec)
914 struct via_spec *spec = codec->spec;
916 if (!spec->smart51_nums)
918 if (!via_clone_control(spec, &via_smart51_mixer))
923 /* check AA path's mute statue */
924 static int is_aa_path_mute(struct hda_codec *codec)
930 struct via_spec *spec = codec->spec;
931 /* get nid of MW0 and start & end index */
932 switch (spec->codec_type) {
957 /* check AA path's mute status */
958 for (i = start_idx; i <= end_idx; i++) {
959 unsigned int con_list = snd_hda_codec_read(
960 codec, spec->aa_mix_nid, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
961 int shift = 8 * (i % 4);
962 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
963 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
964 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
965 /* check mute status while the pin is connected */
966 int mute_l = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 0,
968 int mute_r = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 1,
970 if (!mute_l || !mute_r) {
979 /* enter/exit analog low-current mode */
980 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
982 struct via_spec *spec = codec->spec;
983 static int saved_stream_idle = 1; /* saved stream idle status */
984 int enable = is_aa_path_mute(codec);
985 unsigned int verb = 0;
986 unsigned int parm = 0;
988 if (stream_idle == -1) /* stream status did not change */
989 enable = enable && saved_stream_idle;
991 enable = enable && stream_idle;
992 saved_stream_idle = stream_idle;
995 /* decide low current mode's verb & parameter */
996 switch (spec->codec_type) {
1000 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1006 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1010 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1016 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1019 return; /* other codecs are not supported */
1022 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1026 * generic initialization of ADC, input mixers and output mixers
1028 static const struct hda_verb vt1708_init_verbs[] = {
1029 /* power down jack detect function */
1034 static void substream_set_idle(struct hda_codec *codec,
1035 struct snd_pcm_substream *substream)
1037 int idle = substream->pstr->substream_opened == 1
1038 && substream->ref_count == 0;
1039 analog_low_current_mode(codec, idle);
1042 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
1043 struct hda_codec *codec,
1044 struct snd_pcm_substream *substream)
1046 struct via_spec *spec = codec->spec;
1048 if (!spec->hp_independent_mode)
1049 spec->multiout.hp_nid = spec->hp_dac_nid;
1050 substream_set_idle(codec, substream);
1051 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1055 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1056 struct hda_codec *codec,
1057 struct snd_pcm_substream *substream)
1059 struct via_spec *spec = codec->spec;
1061 spec->multiout.hp_nid = 0;
1062 substream_set_idle(codec, substream);
1066 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1067 struct hda_codec *codec,
1068 struct snd_pcm_substream *substream)
1070 struct via_spec *spec = codec->spec;
1072 if (snd_BUG_ON(!spec->hp_dac_nid))
1074 if (!spec->hp_independent_mode || spec->multiout.hp_nid)
1076 substream_set_idle(codec, substream);
1080 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1081 struct hda_codec *codec,
1082 struct snd_pcm_substream *substream)
1084 substream_set_idle(codec, substream);
1088 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1089 struct hda_codec *codec,
1090 unsigned int stream_tag,
1091 unsigned int format,
1092 struct snd_pcm_substream *substream)
1094 struct via_spec *spec = codec->spec;
1096 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1098 vt1708_start_hp_work(spec);
1102 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1103 struct hda_codec *codec,
1104 unsigned int stream_tag,
1105 unsigned int format,
1106 struct snd_pcm_substream *substream)
1108 struct via_spec *spec = codec->spec;
1110 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1111 stream_tag, 0, format);
1112 vt1708_start_hp_work(spec);
1116 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1117 struct hda_codec *codec,
1118 struct snd_pcm_substream *substream)
1120 struct via_spec *spec = codec->spec;
1122 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1123 vt1708_stop_hp_work(spec);
1127 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1128 struct hda_codec *codec,
1129 struct snd_pcm_substream *substream)
1131 struct via_spec *spec = codec->spec;
1133 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1134 vt1708_stop_hp_work(spec);
1141 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1142 struct hda_codec *codec,
1143 struct snd_pcm_substream *substream)
1145 struct via_spec *spec = codec->spec;
1146 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1149 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1150 struct hda_codec *codec,
1151 struct snd_pcm_substream *substream)
1153 struct via_spec *spec = codec->spec;
1154 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1157 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1158 struct hda_codec *codec,
1159 unsigned int stream_tag,
1160 unsigned int format,
1161 struct snd_pcm_substream *substream)
1163 struct via_spec *spec = codec->spec;
1164 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1165 stream_tag, format, substream);
1168 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1169 struct hda_codec *codec,
1170 struct snd_pcm_substream *substream)
1172 struct via_spec *spec = codec->spec;
1173 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1180 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1181 struct hda_codec *codec,
1182 unsigned int stream_tag,
1183 unsigned int format,
1184 struct snd_pcm_substream *substream)
1186 struct via_spec *spec = codec->spec;
1188 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1189 stream_tag, 0, format);
1193 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1194 struct hda_codec *codec,
1195 struct snd_pcm_substream *substream)
1197 struct via_spec *spec = codec->spec;
1198 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1202 static const struct hda_pcm_stream via_pcm_analog_playback = {
1206 /* NID is set in via_build_pcms */
1208 .open = via_playback_multi_pcm_open,
1209 .close = via_playback_multi_pcm_close,
1210 .prepare = via_playback_multi_pcm_prepare,
1211 .cleanup = via_playback_multi_pcm_cleanup
1215 static const struct hda_pcm_stream via_pcm_hp_playback = {
1219 /* NID is set in via_build_pcms */
1221 .open = via_playback_hp_pcm_open,
1222 .close = via_playback_hp_pcm_close,
1223 .prepare = via_playback_hp_pcm_prepare,
1224 .cleanup = via_playback_hp_pcm_cleanup
1228 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1232 /* NID is set in via_build_pcms */
1233 /* We got noisy outputs on the right channel on VT1708 when
1234 * 24bit samples are used. Until any workaround is found,
1235 * disable the 24bit format, so far.
1237 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1239 .open = via_playback_multi_pcm_open,
1240 .close = via_playback_multi_pcm_close,
1241 .prepare = via_playback_multi_pcm_prepare,
1242 .cleanup = via_playback_multi_pcm_cleanup
1246 static const struct hda_pcm_stream via_pcm_analog_capture = {
1247 .substreams = 1, /* will be changed in via_build_pcms() */
1250 /* NID is set in via_build_pcms */
1252 .prepare = via_capture_pcm_prepare,
1253 .cleanup = via_capture_pcm_cleanup
1257 static const struct hda_pcm_stream via_pcm_digital_playback = {
1261 /* NID is set in via_build_pcms */
1263 .open = via_dig_playback_pcm_open,
1264 .close = via_dig_playback_pcm_close,
1265 .prepare = via_dig_playback_pcm_prepare,
1266 .cleanup = via_dig_playback_pcm_cleanup
1270 static const struct hda_pcm_stream via_pcm_digital_capture = {
1277 * slave controls for virtual master
1279 static const char * const via_slave_vols[] = {
1280 "Front Playback Volume",
1281 "Surround Playback Volume",
1282 "Center Playback Volume",
1283 "LFE Playback Volume",
1284 "Side Playback Volume",
1285 "Headphone Playback Volume",
1286 "Speaker Playback Volume",
1290 static const char * const via_slave_sws[] = {
1291 "Front Playback Switch",
1292 "Surround Playback Switch",
1293 "Center Playback Switch",
1294 "LFE Playback Switch",
1295 "Side Playback Switch",
1296 "Headphone Playback Switch",
1297 "Speaker Playback Switch",
1301 static int via_build_controls(struct hda_codec *codec)
1303 struct via_spec *spec = codec->spec;
1304 struct snd_kcontrol *kctl;
1305 const struct snd_kcontrol_new *knew;
1308 if (spec->set_widgets_power_state)
1309 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1312 for (i = 0; i < spec->num_mixers; i++) {
1313 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1318 if (spec->multiout.dig_out_nid) {
1319 err = snd_hda_create_spdif_out_ctls(codec,
1320 spec->multiout.dig_out_nid,
1321 spec->multiout.dig_out_nid);
1324 err = snd_hda_create_spdif_share_sw(codec,
1328 spec->multiout.share_spdif = 1;
1330 if (spec->dig_in_nid) {
1331 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1336 /* if we have no master control, let's create it */
1337 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1338 unsigned int vmaster_tlv[4];
1339 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1340 HDA_OUTPUT, vmaster_tlv);
1341 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1342 vmaster_tlv, via_slave_vols);
1346 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1347 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1348 NULL, via_slave_sws);
1353 /* assign Capture Source enums to NID */
1354 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1355 for (i = 0; kctl && i < kctl->count; i++) {
1356 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1361 /* other nid->control mapping */
1362 for (i = 0; i < spec->num_mixers; i++) {
1363 for (knew = spec->mixers[i]; knew->name; knew++) {
1364 if (knew->iface != NID_MAPPING)
1366 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1369 err = snd_hda_add_nid(codec, kctl, 0,
1374 /* init power states */
1375 set_widgets_power_state(codec);
1376 analog_low_current_mode(codec, 1);
1378 via_free_kctls(codec); /* no longer needed */
1382 static int via_build_pcms(struct hda_codec *codec)
1384 struct via_spec *spec = codec->spec;
1385 struct hda_pcm *info = spec->pcm_rec;
1387 codec->num_pcms = 1;
1388 codec->pcm_info = info;
1390 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1391 "%s Analog", codec->chip_name);
1392 info->name = spec->stream_name_analog;
1394 if (!spec->stream_analog_playback)
1395 spec->stream_analog_playback = &via_pcm_analog_playback;
1396 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1397 *spec->stream_analog_playback;
1398 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1399 spec->multiout.dac_nids[0];
1400 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1401 spec->multiout.max_channels;
1403 if (!spec->stream_analog_capture)
1404 spec->stream_analog_capture = &via_pcm_analog_capture;
1405 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1406 *spec->stream_analog_capture;
1407 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1408 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1411 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1414 snprintf(spec->stream_name_digital,
1415 sizeof(spec->stream_name_digital),
1416 "%s Digital", codec->chip_name);
1417 info->name = spec->stream_name_digital;
1418 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1419 if (spec->multiout.dig_out_nid) {
1420 if (!spec->stream_digital_playback)
1421 spec->stream_digital_playback =
1422 &via_pcm_digital_playback;
1423 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1424 *spec->stream_digital_playback;
1425 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1426 spec->multiout.dig_out_nid;
1428 if (spec->dig_in_nid) {
1429 if (!spec->stream_digital_capture)
1430 spec->stream_digital_capture =
1431 &via_pcm_digital_capture;
1432 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1433 *spec->stream_digital_capture;
1434 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1439 if (spec->hp_dac_nid) {
1442 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1443 "%s HP", codec->chip_name);
1444 info->name = spec->stream_name_hp;
1445 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1446 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1452 static void via_free(struct hda_codec *codec)
1454 struct via_spec *spec = codec->spec;
1459 via_free_kctls(codec);
1460 vt1708_stop_hp_work(spec);
1464 /* mute/unmute outputs */
1465 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1466 hda_nid_t *pins, bool mute)
1469 for (i = 0; i < num_pins; i++)
1470 snd_hda_codec_write(codec, pins[i], 0,
1471 AC_VERB_SET_PIN_WIDGET_CONTROL,
1472 mute ? 0 : PIN_OUT);
1475 /* mute internal speaker if line-out is plugged */
1476 static void via_line_automute(struct hda_codec *codec, int present)
1478 struct via_spec *spec = codec->spec;
1480 if (!spec->autocfg.speaker_outs)
1483 present = snd_hda_jack_detect(codec,
1484 spec->autocfg.line_out_pins[0]);
1485 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1486 spec->autocfg.speaker_pins,
1490 /* mute internal speaker if HP is plugged */
1491 static void via_hp_automute(struct hda_codec *codec)
1494 struct via_spec *spec = codec->spec;
1496 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0]) {
1497 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1498 toggle_output_mutes(codec, spec->autocfg.line_outs,
1499 spec->autocfg.line_out_pins,
1502 via_line_automute(codec, present);
1505 static void via_gpio_control(struct hda_codec *codec)
1507 unsigned int gpio_data;
1508 unsigned int vol_counter;
1510 unsigned int master_vol;
1512 struct via_spec *spec = codec->spec;
1514 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1515 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1517 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1518 0xF84, 0) & 0x3F0000) >> 16;
1520 vol = vol_counter & 0x1F;
1521 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1522 AC_VERB_GET_AMP_GAIN_MUTE,
1525 if (gpio_data == 0x02) {
1526 /* unmute line out */
1527 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1528 AC_VERB_SET_PIN_WIDGET_CONTROL,
1530 if (vol_counter & 0x20) {
1531 /* decrease volume */
1532 if (vol > master_vol)
1534 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1538 /* increase volume */
1539 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1541 ((master_vol+vol) > 0x2A) ? 0x2A :
1544 } else if (!(gpio_data & 0x02)) {
1546 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1547 AC_VERB_SET_PIN_WIDGET_CONTROL,
1552 /* unsolicited event for jack sensing */
1553 static void via_unsol_event(struct hda_codec *codec,
1558 if (res & VIA_JACK_EVENT)
1559 set_widgets_power_state(codec);
1561 res &= ~VIA_JACK_EVENT;
1563 if (res == VIA_HP_EVENT)
1564 via_hp_automute(codec);
1565 else if (res == VIA_GPIO_EVENT)
1566 via_gpio_control(codec);
1567 else if (res == VIA_LINE_EVENT)
1568 via_line_automute(codec, false);
1571 #ifdef SND_HDA_NEEDS_RESUME
1572 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1574 struct via_spec *spec = codec->spec;
1575 vt1708_stop_hp_work(spec);
1580 #ifdef CONFIG_SND_HDA_POWER_SAVE
1581 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1583 struct via_spec *spec = codec->spec;
1584 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1591 static int via_init(struct hda_codec *codec);
1593 static const struct hda_codec_ops via_patch_ops = {
1594 .build_controls = via_build_controls,
1595 .build_pcms = via_build_pcms,
1598 .unsol_event = via_unsol_event,
1599 #ifdef SND_HDA_NEEDS_RESUME
1600 .suspend = via_suspend,
1602 #ifdef CONFIG_SND_HDA_POWER_SAVE
1603 .check_power_status = via_check_power_status,
1607 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1609 struct via_spec *spec = codec->spec;
1612 for (i = 0; i < spec->multiout.num_dacs; i++) {
1613 if (spec->multiout.dac_nids[i] == dac)
1616 if (spec->hp_dac_nid == dac)
1621 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1622 hda_nid_t target_dac, struct nid_path *path,
1623 int depth, int wid_type)
1628 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1629 for (i = 0; i < nums; i++) {
1630 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1632 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1633 path->path[depth] = conn[i];
1634 path->idx[depth] = i;
1635 path->depth = ++depth;
1641 for (i = 0; i < nums; i++) {
1643 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1644 if (type == AC_WID_AUD_OUT ||
1645 (wid_type != -1 && type != wid_type))
1647 if (parse_output_path(codec, conn[i], target_dac,
1648 path, depth + 1, AC_WID_AUD_SEL)) {
1649 path->path[depth] = conn[i];
1650 path->idx[depth] = i;
1657 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1659 struct via_spec *spec = codec->spec;
1660 const struct auto_pin_cfg *cfg = &spec->autocfg;
1664 spec->multiout.dac_nids = spec->private_dac_nids;
1665 spec->multiout.num_dacs = cfg->line_outs;
1666 for (i = 0; i < cfg->line_outs; i++) {
1667 nid = cfg->line_out_pins[i];
1670 if (parse_output_path(codec, nid, 0, &spec->out_path[i], 0, -1))
1671 spec->private_dac_nids[i] =
1672 spec->out_path[i].path[spec->out_path[i].depth - 1];
1677 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1678 hda_nid_t pin, hda_nid_t dac, int chs)
1680 struct via_spec *spec = codec->spec;
1685 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1687 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1692 sprintf(name, "%s Playback Volume", pfx);
1693 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1694 HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT));
1699 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1701 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1706 sprintf(name, "%s Playback Switch", pfx);
1707 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1708 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1715 static void mangle_smart51(struct hda_codec *codec)
1717 struct via_spec *spec = codec->spec;
1718 struct auto_pin_cfg *cfg = &spec->autocfg;
1721 for (i = 0; i < cfg->num_inputs; i++) {
1722 if (is_smart51_candidate(codec, cfg->inputs[i].pin))
1725 if (cfg->line_outs + nums < 3)
1727 for (i = 0; i < cfg->num_inputs; i++) {
1728 if (!is_smart51_candidate(codec, cfg->inputs[i].pin))
1730 spec->smart51_pins[spec->smart51_nums++] = cfg->inputs[i].pin;
1731 cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin;
1732 if (cfg->line_outs == 3)
1737 /* add playback controls from the parsed DAC table */
1738 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1740 struct via_spec *spec = codec->spec;
1741 struct auto_pin_cfg *cfg = &spec->autocfg;
1742 static const char * const chname[4] = {
1743 "Front", "Surround", "C/LFE", "Side"
1749 old_line_outs = cfg->line_outs;
1750 if (cfg->line_outs == 1)
1751 mangle_smart51(codec);
1753 err = via_auto_fill_dac_nids(codec);
1757 for (i = 0; i < cfg->line_outs; i++) {
1759 pin = cfg->line_out_pins[i];
1760 dac = spec->multiout.dac_nids[i];
1763 if (i == HDA_CLFE) {
1764 err = create_ch_ctls(codec, "Center", pin, dac, 1);
1767 err = create_ch_ctls(codec, "LFE", pin, dac, 2);
1771 err = create_ch_ctls(codec, chname[i], pin, dac, 3);
1777 idx = get_connection_index(codec, spec->aa_mix_nid,
1778 spec->multiout.dac_nids[0]);
1780 /* add control to mixer */
1781 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1782 "PCM Playback Volume",
1783 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1787 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1788 "PCM Playback Switch",
1789 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1795 cfg->line_outs = old_line_outs;
1800 static void create_hp_imux(struct via_spec *spec)
1803 struct hda_input_mux *imux = &spec->private_imux[1];
1804 static const char * const texts[] = { "OFF", "ON", NULL};
1806 /* for hp mode select */
1807 for (i = 0; texts[i]; i++)
1808 snd_hda_add_imux_item(imux, texts[i], i, NULL);
1810 spec->hp_mux = &spec->private_imux[1];
1813 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
1815 struct via_spec *spec = codec->spec;
1821 if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) {
1822 spec->hp_dac_nid = spec->hp_path.path[spec->hp_path.depth - 1];
1823 spec->hp_independent_mode_index =
1824 spec->hp_path.idx[spec->hp_path.depth - 1];
1825 create_hp_imux(spec);
1828 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1829 &spec->hp_dep_path, 0, -1) &&
1834 err = create_ch_ctls(codec, "Headphone", pin, spec->hp_dac_nid, 3);
1841 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
1843 struct via_spec *spec = codec->spec;
1846 pin = spec->autocfg.speaker_pins[0];
1847 if (!spec->autocfg.speaker_outs || !pin)
1850 if (parse_output_path(codec, pin, 0, &spec->speaker_path, 0, -1)) {
1851 dac = spec->speaker_path.path[spec->speaker_path.depth - 1];
1852 spec->multiout.extra_out_nid[0] = dac;
1853 return create_ch_ctls(codec, "Speaker", pin, dac, 3);
1855 if (parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1856 &spec->speaker_path, 0, -1))
1857 return create_ch_ctls(codec, "Headphone", pin, 0, 3);
1863 static int via_fill_adcs(struct hda_codec *codec)
1865 struct via_spec *spec = codec->spec;
1866 hda_nid_t nid = codec->start_nid;
1869 for (i = 0; i < codec->num_nodes; i++, nid++) {
1870 unsigned int wcaps = get_wcaps(codec, nid);
1871 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1873 if (wcaps & AC_WCAP_DIGITAL)
1875 if (!(wcaps & AC_WCAP_CONN_LIST))
1877 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
1879 spec->adc_nids[spec->num_adc_nids++] = nid;
1884 static int get_mux_nids(struct hda_codec *codec);
1886 static const struct snd_kcontrol_new via_input_src_ctl = {
1887 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1888 /* The multiple "Capture Source" controls confuse alsamixer
1889 * So call somewhat different..
1891 /* .name = "Capture Source", */
1892 .name = "Input Source",
1893 .info = via_mux_enum_info,
1894 .get = via_mux_enum_get,
1895 .put = via_mux_enum_put,
1898 /* create playback/capture controls for input pins */
1899 static int via_auto_create_analog_input_ctls(struct hda_codec *codec,
1900 const struct auto_pin_cfg *cfg)
1902 struct via_spec *spec = codec->spec;
1903 struct hda_input_mux *imux = &spec->private_imux[0];
1904 int i, j, err, idx, idx2, type, type_idx = 0;
1906 hda_nid_t pin_idxs[8];
1909 err = via_fill_adcs(codec);
1912 err = get_mux_nids(codec);
1915 cap_nid = spec->mux_nids[0];
1917 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
1918 ARRAY_SIZE(pin_idxs));
1922 /* for internal loopback recording select */
1923 for (idx = 0; idx < num_idxs; idx++) {
1924 if (pin_idxs[idx] == spec->aa_mix_nid) {
1925 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
1930 for (i = 0; i < cfg->num_inputs; i++) {
1932 type = cfg->inputs[i].type;
1933 for (idx = 0; idx < num_idxs; idx++)
1934 if (pin_idxs[idx] == cfg->inputs[i].pin)
1936 if (idx >= num_idxs)
1938 if (i > 0 && type == cfg->inputs[i - 1].type)
1942 label = hda_get_autocfg_input_label(codec, cfg, i);
1943 idx2 = get_connection_index(codec, spec->aa_mix_nid,
1946 err = via_new_analog_input(spec, label, type_idx,
1947 idx2, spec->aa_mix_nid);
1950 snd_hda_add_imux_item(imux, label, idx, NULL);
1952 /* remember the label for smart51 control */
1953 for (j = 0; j < spec->smart51_nums; j++) {
1954 if (spec->smart51_pins[j] == cfg->inputs[i].pin) {
1955 spec->smart51_idxs[j] = idx;
1956 spec->smart51_labels[j] = label;
1962 /* create capture mixer elements */
1963 for (i = 0; i < spec->num_adc_nids; i++) {
1964 hda_nid_t adc = spec->adc_nids[i];
1965 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
1966 "Capture Volume", i,
1967 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
1971 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1972 "Capture Switch", i,
1973 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
1979 /* input-source control */
1980 for (i = 0; i < spec->num_adc_nids; i++)
1981 if (!spec->mux_nids[i])
1984 struct snd_kcontrol_new *knew;
1985 knew = via_clone_control(spec, &via_input_src_ctl);
1992 for (i = 0; i < cfg->num_inputs; i++) {
1993 hda_nid_t pin = cfg->inputs[i].pin;
1998 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2000 caps = query_amp_caps(codec, pin, HDA_INPUT);
2001 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2003 label = hda_get_autocfg_input_label(codec, cfg, i);
2004 snprintf(name, sizeof(name), "%s Boost Capture Volume", label);
2005 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2006 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2014 #ifdef CONFIG_SND_HDA_POWER_SAVE
2015 static const struct hda_amp_list vt1708_loopbacks[] = {
2016 { 0x17, HDA_INPUT, 1 },
2017 { 0x17, HDA_INPUT, 2 },
2018 { 0x17, HDA_INPUT, 3 },
2019 { 0x17, HDA_INPUT, 4 },
2024 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2026 unsigned int def_conf;
2027 unsigned char seqassoc;
2029 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2030 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2031 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2032 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2033 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2034 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2035 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2041 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2042 struct snd_ctl_elem_value *ucontrol)
2044 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2045 struct via_spec *spec = codec->spec;
2047 if (spec->codec_type != VT1708)
2049 spec->vt1708_jack_detect =
2050 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2051 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2055 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2056 struct snd_ctl_elem_value *ucontrol)
2058 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2059 struct via_spec *spec = codec->spec;
2062 if (spec->codec_type != VT1708)
2064 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2065 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2066 == !spec->vt1708_jack_detect;
2067 if (spec->vt1708_jack_detect) {
2068 mute_aa_path(codec, 1);
2069 notify_aa_path_ctls(codec);
2074 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2075 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2076 .name = "Jack Detect",
2078 .info = snd_ctl_boolean_mono_info,
2079 .get = vt1708_jack_detect_get,
2080 .put = vt1708_jack_detect_put,
2083 static void fill_dig_outs(struct hda_codec *codec);
2084 static void fill_dig_in(struct hda_codec *codec);
2086 static int via_parse_auto_config(struct hda_codec *codec)
2088 struct via_spec *spec = codec->spec;
2091 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2094 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2097 err = via_auto_create_multi_out_ctls(codec);
2100 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2103 err = via_auto_create_speaker_ctls(codec);
2106 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
2110 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2112 fill_dig_outs(codec);
2115 if (spec->kctls.list)
2116 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2118 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2120 spec->input_mux = &spec->private_imux[0];
2123 err = via_hp_build(codec);
2128 err = via_smart51_build(codec);
2132 /* assign slave outs */
2133 if (spec->slave_dig_outs[0])
2134 codec->slave_dig_outs = spec->slave_dig_outs;
2139 static void via_auto_init_dig_outs(struct hda_codec *codec)
2141 struct via_spec *spec = codec->spec;
2142 if (spec->multiout.dig_out_nid)
2143 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2144 if (spec->slave_dig_outs[0])
2145 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2148 static void via_auto_init_dig_in(struct hda_codec *codec)
2150 struct via_spec *spec = codec->spec;
2151 if (!spec->dig_in_nid)
2153 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2154 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2157 /* initialize the unsolicited events */
2158 static void via_auto_init_unsol_event(struct hda_codec *codec)
2160 struct via_spec *spec = codec->spec;
2161 struct auto_pin_cfg *cfg = &spec->autocfg;
2165 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2166 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2167 AC_VERB_SET_UNSOLICITED_ENABLE,
2168 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2170 if (cfg->speaker_pins[0])
2171 ev = VIA_LINE_EVENT;
2174 for (i = 0; i < cfg->line_outs; i++) {
2175 if (cfg->line_out_pins[i] &&
2176 is_jack_detectable(codec, cfg->line_out_pins[i]))
2177 snd_hda_codec_write(codec, cfg->line_out_pins[0], 0,
2178 AC_VERB_SET_UNSOLICITED_ENABLE,
2179 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2182 for (i = 0; i < cfg->num_inputs; i++) {
2183 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2184 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2185 AC_VERB_SET_UNSOLICITED_ENABLE,
2186 AC_USRSP_EN | VIA_JACK_EVENT);
2190 static int via_init(struct hda_codec *codec)
2192 struct via_spec *spec = codec->spec;
2195 for (i = 0; i < spec->num_iverbs; i++)
2196 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2198 via_auto_init_multi_out(codec);
2199 via_auto_init_hp_out(codec);
2200 via_auto_init_speaker_out(codec);
2201 via_auto_init_analog_input(codec);
2202 via_auto_init_dig_outs(codec);
2203 via_auto_init_dig_in(codec);
2205 via_auto_init_unsol_event(codec);
2207 via_hp_automute(codec);
2208 via_line_automute(codec, false);
2213 static void vt1708_update_hp_jack_state(struct work_struct *work)
2215 struct via_spec *spec = container_of(work, struct via_spec,
2216 vt1708_hp_work.work);
2217 if (spec->codec_type != VT1708)
2219 /* if jack state toggled */
2220 if (spec->vt1708_hp_present
2221 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2222 spec->vt1708_hp_present ^= 1;
2223 via_hp_automute(spec->codec);
2225 vt1708_start_hp_work(spec);
2228 static int get_mux_nids(struct hda_codec *codec)
2230 struct via_spec *spec = codec->spec;
2231 hda_nid_t nid, conn[8];
2235 for (i = 0; i < spec->num_adc_nids; i++) {
2236 nid = spec->adc_nids[i];
2238 type = get_wcaps_type(get_wcaps(codec, nid));
2239 if (type == AC_WID_PIN)
2241 n = snd_hda_get_connections(codec, nid, conn,
2246 spec->mux_nids[i] = nid;
2255 static int patch_vt1708(struct hda_codec *codec)
2257 struct via_spec *spec;
2260 /* create a codec specific record */
2261 spec = via_new_spec(codec);
2265 spec->aa_mix_nid = 0x17;
2267 /* Add HP and CD pin config connect bit re-config action */
2268 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2269 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2271 /* automatic parse from the BIOS config */
2272 err = via_parse_auto_config(codec);
2278 /* add jack detect on/off control */
2279 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2282 /* disable 32bit format on VT1708 */
2283 if (codec->vendor_id == 0x11061708)
2284 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2286 codec->patch_ops = via_patch_ops;
2288 #ifdef CONFIG_SND_HDA_POWER_SAVE
2289 spec->loopback.amplist = vt1708_loopbacks;
2291 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2296 * generic initialization of ADC, input mixers and output mixers
2298 #ifdef CONFIG_SND_HDA_POWER_SAVE
2299 static const struct hda_amp_list vt1709_loopbacks[] = {
2300 { 0x18, HDA_INPUT, 1 },
2301 { 0x18, HDA_INPUT, 2 },
2302 { 0x18, HDA_INPUT, 3 },
2303 { 0x18, HDA_INPUT, 4 },
2308 static int patch_vt1709_10ch(struct hda_codec *codec)
2310 struct via_spec *spec;
2313 /* create a codec specific record */
2314 spec = via_new_spec(codec);
2318 spec->aa_mix_nid = 0x18;
2320 err = via_parse_auto_config(codec);
2326 codec->patch_ops = via_patch_ops;
2328 #ifdef CONFIG_SND_HDA_POWER_SAVE
2329 spec->loopback.amplist = vt1709_loopbacks;
2335 * generic initialization of ADC, input mixers and output mixers
2337 static int patch_vt1709_6ch(struct hda_codec *codec)
2339 struct via_spec *spec;
2342 /* create a codec specific record */
2343 spec = via_new_spec(codec);
2347 spec->aa_mix_nid = 0x18;
2349 err = via_parse_auto_config(codec);
2355 codec->patch_ops = via_patch_ops;
2357 #ifdef CONFIG_SND_HDA_POWER_SAVE
2358 spec->loopback.amplist = vt1709_loopbacks;
2364 * generic initialization of ADC, input mixers and output mixers
2366 #ifdef CONFIG_SND_HDA_POWER_SAVE
2367 static const struct hda_amp_list vt1708B_loopbacks[] = {
2368 { 0x16, HDA_INPUT, 1 },
2369 { 0x16, HDA_INPUT, 2 },
2370 { 0x16, HDA_INPUT, 3 },
2371 { 0x16, HDA_INPUT, 4 },
2376 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2378 struct via_spec *spec = codec->spec;
2382 if ((spec->codec_type != VT1708B_4CH) &&
2383 (codec->vendor_id != 0x11064397))
2386 /* SW0 (17h) = stereo mixer */
2388 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2389 == ((spec->codec_type == VT1708S) ? 5 : 0));
2391 /* PW 1/2/5 (1ah/1bh/1eh) */
2393 set_pin_power_state(codec, 0x1a, &parm);
2394 set_pin_power_state(codec, 0x1b, &parm);
2395 set_pin_power_state(codec, 0x1e, &parm);
2398 /* SW0 (17h), AIW 0/1 (13h/14h) */
2399 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2400 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2401 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2404 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2406 set_pin_power_state(codec, 0x19, &parm);
2407 if (spec->smart51_enabled)
2408 set_pin_power_state(codec, 0x1b, &parm);
2409 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2410 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2412 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2415 set_pin_power_state(codec, 0x22, &parm);
2416 if (spec->smart51_enabled)
2417 set_pin_power_state(codec, 0x1a, &parm);
2418 snd_hda_codec_write(codec, 0x26, 0,
2419 AC_VERB_SET_POWER_STATE, parm);
2420 snd_hda_codec_write(codec, 0x24, 0,
2421 AC_VERB_SET_POWER_STATE, parm);
2422 } else if (codec->vendor_id == 0x11064397) {
2423 /* PW7(23h), SW2(27h), AOW2(25h) */
2425 set_pin_power_state(codec, 0x23, &parm);
2426 if (spec->smart51_enabled)
2427 set_pin_power_state(codec, 0x1a, &parm);
2428 snd_hda_codec_write(codec, 0x27, 0,
2429 AC_VERB_SET_POWER_STATE, parm);
2430 snd_hda_codec_write(codec, 0x25, 0,
2431 AC_VERB_SET_POWER_STATE, parm);
2434 /* PW 3/4/7 (1ch/1dh/23h) */
2436 /* force to D0 for internal Speaker */
2437 set_pin_power_state(codec, 0x1c, &parm);
2438 set_pin_power_state(codec, 0x1d, &parm);
2440 set_pin_power_state(codec, 0x23, &parm);
2442 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2443 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2444 imux_is_smixer ? AC_PWRST_D0 : parm);
2445 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2447 snd_hda_codec_write(codec, 0x25, 0,
2448 AC_VERB_SET_POWER_STATE, parm);
2449 snd_hda_codec_write(codec, 0x27, 0,
2450 AC_VERB_SET_POWER_STATE, parm);
2451 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2452 snd_hda_codec_write(codec, 0x25, 0,
2453 AC_VERB_SET_POWER_STATE, parm);
2456 static int patch_vt1708S(struct hda_codec *codec);
2457 static int patch_vt1708B_8ch(struct hda_codec *codec)
2459 struct via_spec *spec;
2462 if (get_codec_type(codec) == VT1708BCE)
2463 return patch_vt1708S(codec);
2464 /* create a codec specific record */
2465 spec = via_new_spec(codec);
2469 spec->aa_mix_nid = 0x16;
2471 /* automatic parse from the BIOS config */
2472 err = via_parse_auto_config(codec);
2478 codec->patch_ops = via_patch_ops;
2480 #ifdef CONFIG_SND_HDA_POWER_SAVE
2481 spec->loopback.amplist = vt1708B_loopbacks;
2484 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2489 static int patch_vt1708B_4ch(struct hda_codec *codec)
2491 struct via_spec *spec;
2494 /* create a codec specific record */
2495 spec = via_new_spec(codec);
2499 /* automatic parse from the BIOS config */
2500 err = via_parse_auto_config(codec);
2506 codec->patch_ops = via_patch_ops;
2508 #ifdef CONFIG_SND_HDA_POWER_SAVE
2509 spec->loopback.amplist = vt1708B_loopbacks;
2512 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2517 /* Patch for VT1708S */
2518 static const struct hda_verb vt1708S_init_verbs[] = {
2519 /* Enable Mic Boost Volume backdoor */
2521 /* don't bybass mixer */
2526 /* fill out digital output widgets; one for master and one for slave outputs */
2527 static void fill_dig_outs(struct hda_codec *codec)
2529 struct via_spec *spec = codec->spec;
2532 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2536 nid = spec->autocfg.dig_out_pins[i];
2539 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2542 if (!spec->multiout.dig_out_nid)
2543 spec->multiout.dig_out_nid = nid;
2545 spec->slave_dig_outs[0] = nid;
2546 break; /* at most two dig outs */
2551 static void fill_dig_in(struct hda_codec *codec)
2553 struct via_spec *spec = codec->spec;
2557 if (!spec->autocfg.dig_in_pin)
2560 dig_nid = codec->start_nid;
2561 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2562 unsigned int wcaps = get_wcaps(codec, dig_nid);
2563 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2565 if (!(wcaps & AC_WCAP_DIGITAL))
2567 if (!(wcaps & AC_WCAP_CONN_LIST))
2569 err = get_connection_index(codec, dig_nid,
2570 spec->autocfg.dig_in_pin);
2572 spec->dig_in_nid = dig_nid;
2578 #ifdef CONFIG_SND_HDA_POWER_SAVE
2579 static const struct hda_amp_list vt1708S_loopbacks[] = {
2580 { 0x16, HDA_INPUT, 1 },
2581 { 0x16, HDA_INPUT, 2 },
2582 { 0x16, HDA_INPUT, 3 },
2583 { 0x16, HDA_INPUT, 4 },
2588 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
2589 int offset, int num_steps, int step_size)
2591 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
2592 (offset << AC_AMPCAP_OFFSET_SHIFT) |
2593 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
2594 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
2595 (0 << AC_AMPCAP_MUTE_SHIFT));
2598 static int patch_vt1708S(struct hda_codec *codec)
2600 struct via_spec *spec;
2603 /* create a codec specific record */
2604 spec = via_new_spec(codec);
2608 spec->aa_mix_nid = 0x16;
2609 override_mic_boost(codec, 0x1a, 0, 3, 40);
2610 override_mic_boost(codec, 0x1e, 0, 3, 40);
2612 /* automatic parse from the BIOS config */
2613 err = via_parse_auto_config(codec);
2619 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
2621 codec->patch_ops = via_patch_ops;
2623 #ifdef CONFIG_SND_HDA_POWER_SAVE
2624 spec->loopback.amplist = vt1708S_loopbacks;
2627 /* correct names for VT1708BCE */
2628 if (get_codec_type(codec) == VT1708BCE) {
2629 kfree(codec->chip_name);
2630 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
2631 snprintf(codec->bus->card->mixername,
2632 sizeof(codec->bus->card->mixername),
2633 "%s %s", codec->vendor_name, codec->chip_name);
2635 /* correct names for VT1705 */
2636 if (codec->vendor_id == 0x11064397) {
2637 kfree(codec->chip_name);
2638 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
2639 snprintf(codec->bus->card->mixername,
2640 sizeof(codec->bus->card->mixername),
2641 "%s %s", codec->vendor_name, codec->chip_name);
2643 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2647 /* Patch for VT1702 */
2649 static const struct hda_verb vt1702_init_verbs[] = {
2657 #ifdef CONFIG_SND_HDA_POWER_SAVE
2658 static const struct hda_amp_list vt1702_loopbacks[] = {
2659 { 0x1A, HDA_INPUT, 1 },
2660 { 0x1A, HDA_INPUT, 2 },
2661 { 0x1A, HDA_INPUT, 3 },
2662 { 0x1A, HDA_INPUT, 4 },
2667 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
2669 int imux_is_smixer =
2670 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2673 /* PW 1/2/5 (14h/15h/18h) */
2675 set_pin_power_state(codec, 0x14, &parm);
2676 set_pin_power_state(codec, 0x15, &parm);
2677 set_pin_power_state(codec, 0x18, &parm);
2679 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
2680 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
2681 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2682 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
2683 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2684 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
2687 /* PW 3/4 (16h/17h) */
2689 set_pin_power_state(codec, 0x17, &parm);
2690 set_pin_power_state(codec, 0x16, &parm);
2691 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
2692 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
2693 imux_is_smixer ? AC_PWRST_D0 : parm);
2694 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2695 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
2698 static int patch_vt1702(struct hda_codec *codec)
2700 struct via_spec *spec;
2703 /* create a codec specific record */
2704 spec = via_new_spec(codec);
2708 spec->aa_mix_nid = 0x1a;
2710 /* limit AA path volume to 0 dB */
2711 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
2712 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
2713 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2714 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2715 (1 << AC_AMPCAP_MUTE_SHIFT));
2717 /* automatic parse from the BIOS config */
2718 err = via_parse_auto_config(codec);
2724 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
2726 codec->patch_ops = via_patch_ops;
2728 #ifdef CONFIG_SND_HDA_POWER_SAVE
2729 spec->loopback.amplist = vt1702_loopbacks;
2732 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
2736 /* Patch for VT1718S */
2738 static const struct hda_verb vt1718S_init_verbs[] = {
2739 /* Enable MW0 adjust Gain 5 */
2741 /* Enable Boost Volume backdoor */
2747 #ifdef CONFIG_SND_HDA_POWER_SAVE
2748 static const struct hda_amp_list vt1718S_loopbacks[] = {
2749 { 0x21, HDA_INPUT, 1 },
2750 { 0x21, HDA_INPUT, 2 },
2751 { 0x21, HDA_INPUT, 3 },
2752 { 0x21, HDA_INPUT, 4 },
2757 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
2759 struct via_spec *spec = codec->spec;
2762 /* MUX6 (1eh) = stereo mixer */
2764 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
2766 /* PW 5/6/7 (29h/2ah/2bh) */
2768 set_pin_power_state(codec, 0x29, &parm);
2769 set_pin_power_state(codec, 0x2a, &parm);
2770 set_pin_power_state(codec, 0x2b, &parm);
2773 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
2774 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2775 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2776 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2777 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2780 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
2782 set_pin_power_state(codec, 0x27, &parm);
2783 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
2784 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
2786 /* PW2 (26h), AOW2 (ah) */
2788 set_pin_power_state(codec, 0x26, &parm);
2789 if (spec->smart51_enabled)
2790 set_pin_power_state(codec, 0x2b, &parm);
2791 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
2793 /* PW0 (24h), AOW0 (8h) */
2795 set_pin_power_state(codec, 0x24, &parm);
2796 if (!spec->hp_independent_mode) /* check for redirected HP */
2797 set_pin_power_state(codec, 0x28, &parm);
2798 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
2799 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
2800 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
2801 imux_is_smixer ? AC_PWRST_D0 : parm);
2803 /* PW1 (25h), AOW1 (9h) */
2805 set_pin_power_state(codec, 0x25, &parm);
2806 if (spec->smart51_enabled)
2807 set_pin_power_state(codec, 0x2a, &parm);
2808 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
2810 if (spec->hp_independent_mode) {
2811 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
2813 set_pin_power_state(codec, 0x28, &parm);
2814 snd_hda_codec_write(codec, 0x1b, 0,
2815 AC_VERB_SET_POWER_STATE, parm);
2816 snd_hda_codec_write(codec, 0x34, 0,
2817 AC_VERB_SET_POWER_STATE, parm);
2818 snd_hda_codec_write(codec, 0xc, 0,
2819 AC_VERB_SET_POWER_STATE, parm);
2823 static int patch_vt1718S(struct hda_codec *codec)
2825 struct via_spec *spec;
2828 /* create a codec specific record */
2829 spec = via_new_spec(codec);
2833 spec->aa_mix_nid = 0x21;
2834 override_mic_boost(codec, 0x2b, 0, 3, 40);
2835 override_mic_boost(codec, 0x29, 0, 3, 40);
2837 /* automatic parse from the BIOS config */
2838 err = via_parse_auto_config(codec);
2844 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
2846 codec->patch_ops = via_patch_ops;
2848 #ifdef CONFIG_SND_HDA_POWER_SAVE
2849 spec->loopback.amplist = vt1718S_loopbacks;
2852 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
2857 /* Patch for VT1716S */
2859 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
2860 struct snd_ctl_elem_info *uinfo)
2862 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2864 uinfo->value.integer.min = 0;
2865 uinfo->value.integer.max = 1;
2869 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
2870 struct snd_ctl_elem_value *ucontrol)
2872 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2875 index = snd_hda_codec_read(codec, 0x26, 0,
2876 AC_VERB_GET_CONNECT_SEL, 0);
2878 *ucontrol->value.integer.value = index;
2883 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
2884 struct snd_ctl_elem_value *ucontrol)
2886 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2887 struct via_spec *spec = codec->spec;
2888 int index = *ucontrol->value.integer.value;
2890 snd_hda_codec_write(codec, 0x26, 0,
2891 AC_VERB_SET_CONNECT_SEL, index);
2892 spec->dmic_enabled = index;
2893 set_widgets_power_state(codec);
2897 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
2898 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
2900 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2901 .name = "Digital Mic Capture Switch",
2902 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
2904 .info = vt1716s_dmic_info,
2905 .get = vt1716s_dmic_get,
2906 .put = vt1716s_dmic_put,
2912 /* mono-out mixer elements */
2913 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
2914 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
2918 static const struct hda_verb vt1716S_init_verbs[] = {
2919 /* Enable Boost Volume backdoor */
2921 /* don't bybass mixer */
2923 /* Enable mono output */
2928 #ifdef CONFIG_SND_HDA_POWER_SAVE
2929 static const struct hda_amp_list vt1716S_loopbacks[] = {
2930 { 0x16, HDA_INPUT, 1 },
2931 { 0x16, HDA_INPUT, 2 },
2932 { 0x16, HDA_INPUT, 3 },
2933 { 0x16, HDA_INPUT, 4 },
2938 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
2940 struct via_spec *spec = codec->spec;
2943 unsigned int mono_out, present;
2944 /* SW0 (17h) = stereo mixer */
2946 (snd_hda_codec_read(codec, 0x17, 0,
2947 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
2949 /* PW 1/2/5 (1ah/1bh/1eh) */
2951 set_pin_power_state(codec, 0x1a, &parm);
2952 set_pin_power_state(codec, 0x1b, &parm);
2953 set_pin_power_state(codec, 0x1e, &parm);
2956 /* SW0 (17h), AIW0(13h) */
2957 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2958 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2961 set_pin_power_state(codec, 0x1e, &parm);
2963 if (spec->dmic_enabled)
2964 set_pin_power_state(codec, 0x22, &parm);
2966 snd_hda_codec_write(codec, 0x22, 0,
2967 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2969 /* SW2(26h), AIW1(14h) */
2970 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
2971 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2974 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2976 set_pin_power_state(codec, 0x19, &parm);
2977 /* Smart 5.1 PW2(1bh) */
2978 if (spec->smart51_enabled)
2979 set_pin_power_state(codec, 0x1b, &parm);
2980 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2981 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2983 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
2985 set_pin_power_state(codec, 0x23, &parm);
2986 /* Smart 5.1 PW1(1ah) */
2987 if (spec->smart51_enabled)
2988 set_pin_power_state(codec, 0x1a, &parm);
2989 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
2991 /* Smart 5.1 PW5(1eh) */
2992 if (spec->smart51_enabled)
2993 set_pin_power_state(codec, 0x1e, &parm);
2994 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
2997 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
2998 present = snd_hda_jack_detect(codec, 0x1c);
3003 present = snd_hda_jack_detect(codec, 0x1d);
3004 if (!spec->hp_independent_mode && present)
3009 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3010 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3011 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3012 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3014 /* PW 3/4 (1ch/1dh) */
3016 set_pin_power_state(codec, 0x1c, &parm);
3017 set_pin_power_state(codec, 0x1d, &parm);
3018 /* HP Independent Mode, power on AOW3 */
3019 if (spec->hp_independent_mode)
3020 snd_hda_codec_write(codec, 0x25, 0,
3021 AC_VERB_SET_POWER_STATE, parm);
3023 /* force to D0 for internal Speaker */
3024 /* MW0 (16h), AOW0 (10h) */
3025 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3026 imux_is_smixer ? AC_PWRST_D0 : parm);
3027 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3028 mono_out ? AC_PWRST_D0 : parm);
3031 static int patch_vt1716S(struct hda_codec *codec)
3033 struct via_spec *spec;
3036 /* create a codec specific record */
3037 spec = via_new_spec(codec);
3041 spec->aa_mix_nid = 0x16;
3042 override_mic_boost(codec, 0x1a, 0, 3, 40);
3043 override_mic_boost(codec, 0x1e, 0, 3, 40);
3045 /* automatic parse from the BIOS config */
3046 err = via_parse_auto_config(codec);
3052 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3054 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3057 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3059 codec->patch_ops = via_patch_ops;
3061 #ifdef CONFIG_SND_HDA_POWER_SAVE
3062 spec->loopback.amplist = vt1716S_loopbacks;
3065 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3071 static const struct hda_verb vt2002P_init_verbs[] = {
3072 /* Class-D speaker related verbs */
3076 /* Enable Boost Volume backdoor */
3078 /* Enable AOW0 to MW9 */
3083 static const struct hda_verb vt1802_init_verbs[] = {
3084 /* Enable Boost Volume backdoor */
3086 /* Enable AOW0 to MW9 */
3091 #ifdef CONFIG_SND_HDA_POWER_SAVE
3092 static const struct hda_amp_list vt2002P_loopbacks[] = {
3093 { 0x21, HDA_INPUT, 0 },
3094 { 0x21, HDA_INPUT, 1 },
3095 { 0x21, HDA_INPUT, 2 },
3100 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3102 struct via_spec *spec = codec->spec;
3105 unsigned int present;
3106 /* MUX9 (1eh) = stereo mixer */
3108 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3110 /* PW 5/6/7 (29h/2ah/2bh) */
3112 set_pin_power_state(codec, 0x29, &parm);
3113 set_pin_power_state(codec, 0x2a, &parm);
3114 set_pin_power_state(codec, 0x2b, &parm);
3116 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3117 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3118 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3119 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3120 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3124 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3126 if (spec->codec_type == VT1802) {
3127 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3129 set_pin_power_state(codec, 0x28, &parm);
3130 snd_hda_codec_write(codec, 0x18, 0,
3131 AC_VERB_SET_POWER_STATE, parm);
3132 snd_hda_codec_write(codec, 0x38, 0,
3133 AC_VERB_SET_POWER_STATE, parm);
3135 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3137 set_pin_power_state(codec, 0x26, &parm);
3138 snd_hda_codec_write(codec, 0x1c, 0,
3139 AC_VERB_SET_POWER_STATE, parm);
3140 snd_hda_codec_write(codec, 0x37, 0,
3141 AC_VERB_SET_POWER_STATE, parm);
3144 if (spec->codec_type == VT1802) {
3145 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3147 set_pin_power_state(codec, 0x25, &parm);
3148 snd_hda_codec_write(codec, 0x15, 0,
3149 AC_VERB_SET_POWER_STATE, parm);
3150 snd_hda_codec_write(codec, 0x35, 0,
3151 AC_VERB_SET_POWER_STATE, parm);
3153 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3155 set_pin_power_state(codec, 0x25, &parm);
3156 snd_hda_codec_write(codec, 0x19, 0,
3157 AC_VERB_SET_POWER_STATE, parm);
3158 snd_hda_codec_write(codec, 0x35, 0,
3159 AC_VERB_SET_POWER_STATE, parm);
3162 if (spec->hp_independent_mode)
3163 snd_hda_codec_write(codec, 0x9, 0,
3164 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3167 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3168 present = snd_hda_jack_detect(codec, 0x25);
3171 set_pin_power_state(codec, 0x24, &parm);
3172 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3173 if (spec->codec_type == VT1802)
3174 snd_hda_codec_write(codec, 0x14, 0,
3175 AC_VERB_SET_POWER_STATE, parm);
3177 snd_hda_codec_write(codec, 0x18, 0,
3178 AC_VERB_SET_POWER_STATE, parm);
3179 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3182 present = snd_hda_jack_detect(codec, 0x26);
3184 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3185 if (spec->codec_type == VT1802) {
3186 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3187 snd_hda_codec_write(codec, 0x33, 0,
3188 AC_VERB_SET_POWER_STATE, parm);
3189 snd_hda_codec_write(codec, 0x1c, 0,
3190 AC_VERB_SET_POWER_STATE, parm);
3191 snd_hda_codec_write(codec, 0x3c, 0,
3192 AC_VERB_SET_POWER_STATE, parm);
3194 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3195 snd_hda_codec_write(codec, 0x31, 0,
3196 AC_VERB_SET_POWER_STATE, parm);
3197 snd_hda_codec_write(codec, 0x17, 0,
3198 AC_VERB_SET_POWER_STATE, parm);
3199 snd_hda_codec_write(codec, 0x3b, 0,
3200 AC_VERB_SET_POWER_STATE, parm);
3203 if (imux_is_smixer || !is_aa_path_mute(codec))
3204 snd_hda_codec_write(codec, 0x21, 0,
3205 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3207 snd_hda_codec_write(codec, 0x21, 0,
3208 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3211 /* patch for vt2002P */
3212 static int patch_vt2002P(struct hda_codec *codec)
3214 struct via_spec *spec;
3217 /* create a codec specific record */
3218 spec = via_new_spec(codec);
3222 spec->aa_mix_nid = 0x21;
3223 override_mic_boost(codec, 0x2b, 0, 3, 40);
3224 override_mic_boost(codec, 0x29, 0, 3, 40);
3226 /* automatic parse from the BIOS config */
3227 err = via_parse_auto_config(codec);
3233 if (spec->codec_type == VT1802)
3234 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3236 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3238 codec->patch_ops = via_patch_ops;
3240 #ifdef CONFIG_SND_HDA_POWER_SAVE
3241 spec->loopback.amplist = vt2002P_loopbacks;
3244 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3250 static const struct hda_verb vt1812_init_verbs[] = {
3251 /* Enable Boost Volume backdoor */
3253 /* Enable AOW0 to MW9 */
3258 #ifdef CONFIG_SND_HDA_POWER_SAVE
3259 static const struct hda_amp_list vt1812_loopbacks[] = {
3260 { 0x21, HDA_INPUT, 0 },
3261 { 0x21, HDA_INPUT, 1 },
3262 { 0x21, HDA_INPUT, 2 },
3267 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3269 struct via_spec *spec = codec->spec;
3270 int imux_is_smixer =
3271 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3273 unsigned int present;
3274 /* MUX10 (1eh) = stereo mixer */
3276 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3278 /* PW 5/6/7 (29h/2ah/2bh) */
3280 set_pin_power_state(codec, 0x29, &parm);
3281 set_pin_power_state(codec, 0x2a, &parm);
3282 set_pin_power_state(codec, 0x2b, &parm);
3284 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3285 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3286 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3287 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3288 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3292 snd_hda_codec_write(codec, 0x8, 0,
3293 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3295 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3297 set_pin_power_state(codec, 0x28, &parm);
3298 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3299 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3301 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3303 set_pin_power_state(codec, 0x25, &parm);
3304 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3305 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3306 if (spec->hp_independent_mode)
3307 snd_hda_codec_write(codec, 0x9, 0,
3308 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3310 /* Internal Speaker */
3311 /* PW0 (24h), MW0(14h), MUX0(34h) */
3312 present = snd_hda_jack_detect(codec, 0x25);
3315 set_pin_power_state(codec, 0x24, &parm);
3317 snd_hda_codec_write(codec, 0x14, 0,
3318 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3319 snd_hda_codec_write(codec, 0x34, 0,
3320 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3322 snd_hda_codec_write(codec, 0x14, 0,
3323 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3324 snd_hda_codec_write(codec, 0x34, 0,
3325 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3330 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3331 present = snd_hda_jack_detect(codec, 0x28);
3334 set_pin_power_state(codec, 0x31, &parm);
3336 snd_hda_codec_write(codec, 0x1c, 0,
3337 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3338 snd_hda_codec_write(codec, 0x3c, 0,
3339 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3340 snd_hda_codec_write(codec, 0x3e, 0,
3341 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3343 snd_hda_codec_write(codec, 0x1c, 0,
3344 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3345 snd_hda_codec_write(codec, 0x3c, 0,
3346 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3347 snd_hda_codec_write(codec, 0x3e, 0,
3348 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3351 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3353 set_pin_power_state(codec, 0x33, &parm);
3354 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3355 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3359 /* patch for vt1812 */
3360 static int patch_vt1812(struct hda_codec *codec)
3362 struct via_spec *spec;
3365 /* create a codec specific record */
3366 spec = via_new_spec(codec);
3370 spec->aa_mix_nid = 0x21;
3371 override_mic_boost(codec, 0x2b, 0, 3, 40);
3372 override_mic_boost(codec, 0x29, 0, 3, 40);
3374 /* automatic parse from the BIOS config */
3375 err = via_parse_auto_config(codec);
3381 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3383 codec->patch_ops = via_patch_ops;
3385 #ifdef CONFIG_SND_HDA_POWER_SAVE
3386 spec->loopback.amplist = vt1812_loopbacks;
3389 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3396 static const struct hda_codec_preset snd_hda_preset_via[] = {
3397 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3398 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3399 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3400 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3401 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3402 .patch = patch_vt1709_10ch},
3403 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3404 .patch = patch_vt1709_10ch},
3405 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3406 .patch = patch_vt1709_10ch},
3407 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3408 .patch = patch_vt1709_10ch},
3409 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3410 .patch = patch_vt1709_6ch},
3411 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3412 .patch = patch_vt1709_6ch},
3413 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3414 .patch = patch_vt1709_6ch},
3415 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3416 .patch = patch_vt1709_6ch},
3417 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3418 .patch = patch_vt1708B_8ch},
3419 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3420 .patch = patch_vt1708B_8ch},
3421 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3422 .patch = patch_vt1708B_8ch},
3423 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3424 .patch = patch_vt1708B_8ch},
3425 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3426 .patch = patch_vt1708B_4ch},
3427 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3428 .patch = patch_vt1708B_4ch},
3429 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3430 .patch = patch_vt1708B_4ch},
3431 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3432 .patch = patch_vt1708B_4ch},
3433 { .id = 0x11060397, .name = "VT1708S",
3434 .patch = patch_vt1708S},
3435 { .id = 0x11061397, .name = "VT1708S",
3436 .patch = patch_vt1708S},
3437 { .id = 0x11062397, .name = "VT1708S",
3438 .patch = patch_vt1708S},
3439 { .id = 0x11063397, .name = "VT1708S",
3440 .patch = patch_vt1708S},
3441 { .id = 0x11064397, .name = "VT1705",
3442 .patch = patch_vt1708S},
3443 { .id = 0x11065397, .name = "VT1708S",
3444 .patch = patch_vt1708S},
3445 { .id = 0x11066397, .name = "VT1708S",
3446 .patch = patch_vt1708S},
3447 { .id = 0x11067397, .name = "VT1708S",
3448 .patch = patch_vt1708S},
3449 { .id = 0x11060398, .name = "VT1702",
3450 .patch = patch_vt1702},
3451 { .id = 0x11061398, .name = "VT1702",
3452 .patch = patch_vt1702},
3453 { .id = 0x11062398, .name = "VT1702",
3454 .patch = patch_vt1702},
3455 { .id = 0x11063398, .name = "VT1702",
3456 .patch = patch_vt1702},
3457 { .id = 0x11064398, .name = "VT1702",
3458 .patch = patch_vt1702},
3459 { .id = 0x11065398, .name = "VT1702",
3460 .patch = patch_vt1702},
3461 { .id = 0x11066398, .name = "VT1702",
3462 .patch = patch_vt1702},
3463 { .id = 0x11067398, .name = "VT1702",
3464 .patch = patch_vt1702},
3465 { .id = 0x11060428, .name = "VT1718S",
3466 .patch = patch_vt1718S},
3467 { .id = 0x11064428, .name = "VT1718S",
3468 .patch = patch_vt1718S},
3469 { .id = 0x11060441, .name = "VT2020",
3470 .patch = patch_vt1718S},
3471 { .id = 0x11064441, .name = "VT1828S",
3472 .patch = patch_vt1718S},
3473 { .id = 0x11060433, .name = "VT1716S",
3474 .patch = patch_vt1716S},
3475 { .id = 0x1106a721, .name = "VT1716S",
3476 .patch = patch_vt1716S},
3477 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3478 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3479 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3480 { .id = 0x11060440, .name = "VT1818S",
3481 .patch = patch_vt1708S},
3482 { .id = 0x11060446, .name = "VT1802",
3483 .patch = patch_vt2002P},
3484 { .id = 0x11068446, .name = "VT1802",
3485 .patch = patch_vt2002P},
3489 MODULE_ALIAS("snd-hda-codec-id:1106*");
3491 static struct hda_codec_preset_list via_list = {
3492 .preset = snd_hda_preset_via,
3493 .owner = THIS_MODULE,
3496 MODULE_LICENSE("GPL");
3497 MODULE_DESCRIPTION("VIA HD-audio codec");
3499 static int __init patch_via_init(void)
3501 return snd_hda_add_codec_preset(&via_list);
3504 static void __exit patch_via_exit(void)
3506 snd_hda_delete_codec_preset(&via_list);
3509 module_init(patch_via_init)
3510 module_exit(patch_via_exit)