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 <linux/module.h>
53 #include <sound/core.h>
54 #include <sound/asoundef.h>
55 #include "hda_codec.h"
56 #include "hda_local.h"
57 #include "hda_auto_parser.h"
59 #include "hda_generic.h"
62 #define VT1708_HP_PIN_NID 0x20
63 #define VT1708_CD_PIN_NID 0x24
85 #define VT2002P_COMPATIBLE(spec) \
86 ((spec)->codec_type == VT2002P ||\
87 (spec)->codec_type == VT1812 ||\
88 (spec)->codec_type == VT1802)
91 struct hda_gen_spec gen
;
93 /* codec parameterization */
94 const struct snd_kcontrol_new
*mixers
[6];
95 unsigned int num_mixers
;
97 const struct hda_verb
*init_verbs
[5];
98 unsigned int num_iverbs
;
101 unsigned int dmic_enabled
;
102 unsigned int no_pin_power_ctl
;
103 enum VIA_HDA_CODEC codec_type
;
105 /* analog low-power control */
108 /* work to check hp jack state */
110 int vt1708_jack_detect
;
112 void (*set_widgets_power_state
)(struct hda_codec
*codec
);
113 unsigned int dac_stream_tag
[4];
116 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
);
117 static void via_playback_pcm_hook(struct hda_pcm_stream
*hinfo
,
118 struct hda_codec
*codec
,
119 struct snd_pcm_substream
*substream
,
121 static void via_hp_automute(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
);
123 static struct via_spec
*via_new_spec(struct hda_codec
*codec
)
125 struct via_spec
*spec
;
127 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
132 snd_hda_gen_spec_init(&spec
->gen
);
133 spec
->codec_type
= get_codec_type(codec
);
134 /* VT1708BCE & VT1708S are almost same */
135 if (spec
->codec_type
== VT1708BCE
)
136 spec
->codec_type
= VT1708S
;
137 spec
->no_pin_power_ctl
= 1;
138 spec
->gen
.indep_hp
= 1;
139 spec
->gen
.keep_eapd_on
= 1;
140 spec
->gen
.pcm_playback_hook
= via_playback_pcm_hook
;
141 spec
->gen
.add_stereo_mix_input
= 1;
145 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
)
147 u32 vendor_id
= codec
->vendor_id
;
148 u16 ven_id
= vendor_id
>> 16;
149 u16 dev_id
= vendor_id
& 0xffff;
150 enum VIA_HDA_CODEC codec_type
;
153 if (ven_id
!= 0x1106)
154 codec_type
= UNKNOWN
;
155 else if (dev_id
>= 0x1708 && dev_id
<= 0x170b)
157 else if (dev_id
>= 0xe710 && dev_id
<= 0xe713)
158 codec_type
= VT1709_10CH
;
159 else if (dev_id
>= 0xe714 && dev_id
<= 0xe717)
160 codec_type
= VT1709_6CH
;
161 else if (dev_id
>= 0xe720 && dev_id
<= 0xe723) {
162 codec_type
= VT1708B_8CH
;
163 if (snd_hda_param_read(codec
, 0x16, AC_PAR_CONNLIST_LEN
) == 0x7)
164 codec_type
= VT1708BCE
;
165 } else if (dev_id
>= 0xe724 && dev_id
<= 0xe727)
166 codec_type
= VT1708B_4CH
;
167 else if ((dev_id
& 0xfff) == 0x397
168 && (dev_id
>> 12) < 8)
169 codec_type
= VT1708S
;
170 else if ((dev_id
& 0xfff) == 0x398
171 && (dev_id
>> 12) < 8)
173 else if ((dev_id
& 0xfff) == 0x428
174 && (dev_id
>> 12) < 8)
175 codec_type
= VT1718S
;
176 else if (dev_id
== 0x0433 || dev_id
== 0xa721)
177 codec_type
= VT1716S
;
178 else if (dev_id
== 0x0441 || dev_id
== 0x4441)
179 codec_type
= VT1718S
;
180 else if (dev_id
== 0x0438 || dev_id
== 0x4438)
181 codec_type
= VT2002P
;
182 else if (dev_id
== 0x0448)
184 else if (dev_id
== 0x0440)
185 codec_type
= VT1708S
;
186 else if ((dev_id
& 0xfff) == 0x446)
188 else if (dev_id
== 0x4760)
189 codec_type
= VT1705CF
;
190 else if (dev_id
== 0x4761 || dev_id
== 0x4762)
193 codec_type
= UNKNOWN
;
197 static void analog_low_current_mode(struct hda_codec
*codec
);
198 static bool is_aa_path_mute(struct hda_codec
*codec
);
200 #define hp_detect_with_aa(codec) \
201 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
202 !is_aa_path_mute(codec))
204 static void vt1708_stop_hp_work(struct hda_codec
*codec
)
206 struct via_spec
*spec
= codec
->spec
;
207 if (spec
->codec_type
!= VT1708
|| !spec
->gen
.autocfg
.hp_outs
)
209 if (spec
->hp_work_active
) {
210 snd_hda_codec_write(codec
, 0x1, 0, 0xf81, 1);
211 codec
->jackpoll_interval
= 0;
212 cancel_delayed_work_sync(&codec
->jackpoll_work
);
213 spec
->hp_work_active
= false;
217 static void vt1708_update_hp_work(struct hda_codec
*codec
)
219 struct via_spec
*spec
= codec
->spec
;
220 if (spec
->codec_type
!= VT1708
|| !spec
->gen
.autocfg
.hp_outs
)
222 if (spec
->vt1708_jack_detect
) {
223 if (!spec
->hp_work_active
) {
224 codec
->jackpoll_interval
= msecs_to_jiffies(100);
225 snd_hda_codec_write(codec
, 0x1, 0, 0xf81, 0);
226 queue_delayed_work(codec
->bus
->workq
,
227 &codec
->jackpoll_work
, 0);
228 spec
->hp_work_active
= true;
230 } else if (!hp_detect_with_aa(codec
))
231 vt1708_stop_hp_work(codec
);
234 static void set_widgets_power_state(struct hda_codec
*codec
)
236 #if 0 /* FIXME: the assumed connections don't match always with the
237 * actual routes by the generic parser, so better to disable
238 * the control for safety.
240 struct via_spec
*spec
= codec
->spec
;
241 if (spec
->set_widgets_power_state
)
242 spec
->set_widgets_power_state(codec
);
246 static void update_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
249 if (snd_hda_check_power_state(codec
, nid
, parm
))
251 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
254 static void update_conv_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
255 unsigned int parm
, unsigned int index
)
257 struct via_spec
*spec
= codec
->spec
;
260 if (snd_hda_check_power_state(codec
, nid
, parm
))
262 format
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_CONV
, 0);
263 if (format
&& (spec
->dac_stream_tag
[index
] != format
))
264 spec
->dac_stream_tag
[index
] = format
;
266 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
267 if (parm
== AC_PWRST_D0
) {
268 format
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_CONV
, 0);
269 if (!format
&& (spec
->dac_stream_tag
[index
] != format
))
270 snd_hda_codec_write(codec
, nid
, 0,
271 AC_VERB_SET_CHANNEL_STREAMID
,
272 spec
->dac_stream_tag
[index
]);
276 static bool smart51_enabled(struct hda_codec
*codec
)
278 struct via_spec
*spec
= codec
->spec
;
279 return spec
->gen
.ext_channel_count
> 2;
282 static bool is_smart51_pins(struct hda_codec
*codec
, hda_nid_t pin
)
284 struct via_spec
*spec
= codec
->spec
;
287 for (i
= 0; i
< spec
->gen
.multi_ios
; i
++)
288 if (spec
->gen
.multi_io
[i
].pin
== pin
)
293 static void set_pin_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
294 unsigned int *affected_parm
)
297 unsigned def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
298 unsigned no_presence
= (def_conf
& AC_DEFCFG_MISC
)
299 >> AC_DEFCFG_MISC_SHIFT
300 & AC_DEFCFG_MISC_NO_PRESENCE
; /* do not support pin sense */
301 struct via_spec
*spec
= codec
->spec
;
302 unsigned present
= 0;
304 no_presence
|= spec
->no_pin_power_ctl
;
306 present
= snd_hda_jack_detect(codec
, nid
);
307 if ((smart51_enabled(codec
) && is_smart51_pins(codec
, nid
))
308 || ((no_presence
|| present
)
309 && get_defcfg_connect(def_conf
) != AC_JACK_PORT_NONE
)) {
310 *affected_parm
= AC_PWRST_D0
; /* if it's connected */
315 update_power_state(codec
, nid
, parm
);
318 static int via_pin_power_ctl_info(struct snd_kcontrol
*kcontrol
,
319 struct snd_ctl_elem_info
*uinfo
)
321 return snd_hda_enum_bool_helper_info(kcontrol
, uinfo
);
324 static int via_pin_power_ctl_get(struct snd_kcontrol
*kcontrol
,
325 struct snd_ctl_elem_value
*ucontrol
)
327 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
328 struct via_spec
*spec
= codec
->spec
;
329 ucontrol
->value
.enumerated
.item
[0] = !spec
->no_pin_power_ctl
;
333 static int via_pin_power_ctl_put(struct snd_kcontrol
*kcontrol
,
334 struct snd_ctl_elem_value
*ucontrol
)
336 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
337 struct via_spec
*spec
= codec
->spec
;
338 unsigned int val
= !ucontrol
->value
.enumerated
.item
[0];
340 if (val
== spec
->no_pin_power_ctl
)
342 spec
->no_pin_power_ctl
= val
;
343 set_widgets_power_state(codec
);
344 analog_low_current_mode(codec
);
348 static const struct snd_kcontrol_new via_pin_power_ctl_enum
[] = {
350 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
351 .name
= "Dynamic Power-Control",
352 .info
= via_pin_power_ctl_info
,
353 .get
= via_pin_power_ctl_get
,
354 .put
= via_pin_power_ctl_put
,
360 /* check AA path's mute status */
361 static bool is_aa_path_mute(struct hda_codec
*codec
)
363 struct via_spec
*spec
= codec
->spec
;
364 const struct hda_amp_list
*p
;
367 p
= spec
->gen
.loopback
.amplist
;
370 for (; p
->nid
; p
++) {
371 for (ch
= 0; ch
< 2; ch
++) {
372 v
= snd_hda_codec_amp_read(codec
, p
->nid
, ch
, p
->dir
,
374 if (!(v
& HDA_AMP_MUTE
) && v
> 0)
381 /* enter/exit analog low-current mode */
382 static void __analog_low_current_mode(struct hda_codec
*codec
, bool force
)
384 struct via_spec
*spec
= codec
->spec
;
386 unsigned int verb
, parm
;
388 if (spec
->no_pin_power_ctl
)
391 enable
= is_aa_path_mute(codec
) && !spec
->gen
.active_streams
;
392 if (enable
== spec
->alc_mode
&& !force
)
394 spec
->alc_mode
= enable
;
396 /* decide low current mode's verb & parameter */
397 switch (spec
->codec_type
) {
401 parm
= enable
? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
407 parm
= enable
? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
411 parm
= enable
? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
417 parm
= enable
? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
422 parm
= enable
? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
425 return; /* other codecs are not supported */
428 snd_hda_codec_write(codec
, codec
->afg
, 0, verb
, parm
);
431 static void analog_low_current_mode(struct hda_codec
*codec
)
433 return __analog_low_current_mode(codec
, false);
436 static int via_build_controls(struct hda_codec
*codec
)
438 struct via_spec
*spec
= codec
->spec
;
441 err
= snd_hda_gen_build_controls(codec
);
445 if (spec
->set_widgets_power_state
)
446 spec
->mixers
[spec
->num_mixers
++] = via_pin_power_ctl_enum
;
448 for (i
= 0; i
< spec
->num_mixers
; i
++) {
449 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
457 static void via_playback_pcm_hook(struct hda_pcm_stream
*hinfo
,
458 struct hda_codec
*codec
,
459 struct snd_pcm_substream
*substream
,
462 analog_low_current_mode(codec
);
463 vt1708_update_hp_work(codec
);
466 static void via_free(struct hda_codec
*codec
)
468 struct via_spec
*spec
= codec
->spec
;
473 vt1708_stop_hp_work(codec
);
474 snd_hda_gen_spec_free(&spec
->gen
);
479 static int via_suspend(struct hda_codec
*codec
)
481 struct via_spec
*spec
= codec
->spec
;
482 vt1708_stop_hp_work(codec
);
484 /* Fix pop noise on headphones */
485 if (spec
->codec_type
== VT1802
)
486 snd_hda_shutup_pins(codec
);
493 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
495 struct via_spec
*spec
= codec
->spec
;
496 set_widgets_power_state(codec
);
497 analog_low_current_mode(codec
);
498 vt1708_update_hp_work(codec
);
499 return snd_hda_check_amp_list_power(codec
, &spec
->gen
.loopback
, nid
);
506 static int via_init(struct hda_codec
*codec
);
508 static const struct hda_codec_ops via_patch_ops
= {
509 .build_controls
= via_build_controls
,
510 .build_pcms
= snd_hda_gen_build_pcms
,
513 .unsol_event
= snd_hda_jack_unsol_event
,
515 .suspend
= via_suspend
,
516 .check_power_status
= via_check_power_status
,
521 static const struct hda_verb vt1708_init_verbs
[] = {
522 /* power down jack detect function */
526 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
528 unsigned int def_conf
;
529 unsigned char seqassoc
;
531 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
532 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
533 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
534 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
535 && (seqassoc
== 0xf0 || seqassoc
== 0xff)) {
536 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
537 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
543 static int vt1708_jack_detect_get(struct snd_kcontrol
*kcontrol
,
544 struct snd_ctl_elem_value
*ucontrol
)
546 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
547 struct via_spec
*spec
= codec
->spec
;
549 if (spec
->codec_type
!= VT1708
)
551 ucontrol
->value
.integer
.value
[0] = spec
->vt1708_jack_detect
;
555 static int vt1708_jack_detect_put(struct snd_kcontrol
*kcontrol
,
556 struct snd_ctl_elem_value
*ucontrol
)
558 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
559 struct via_spec
*spec
= codec
->spec
;
562 if (spec
->codec_type
!= VT1708
)
564 val
= !!ucontrol
->value
.integer
.value
[0];
565 if (spec
->vt1708_jack_detect
== val
)
567 spec
->vt1708_jack_detect
= val
;
568 vt1708_update_hp_work(codec
);
572 static const struct snd_kcontrol_new vt1708_jack_detect_ctl
[] = {
574 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
575 .name
= "Jack Detect",
577 .info
= snd_ctl_boolean_mono_info
,
578 .get
= vt1708_jack_detect_get
,
579 .put
= vt1708_jack_detect_put
,
584 static void via_hp_automute(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
)
586 set_widgets_power_state(codec
);
587 snd_hda_gen_hp_automute(codec
, tbl
);
590 static void via_line_automute(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
)
592 set_widgets_power_state(codec
);
593 snd_hda_gen_line_automute(codec
, tbl
);
596 static void via_jack_powerstate_event(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
)
598 set_widgets_power_state(codec
);
601 #define VIA_JACK_EVENT (HDA_GEN_LAST_EVENT + 1)
603 static void via_set_jack_unsol_events(struct hda_codec
*codec
)
605 struct via_spec
*spec
= codec
->spec
;
606 struct auto_pin_cfg
*cfg
= &spec
->gen
.autocfg
;
610 spec
->gen
.hp_automute_hook
= via_hp_automute
;
611 if (cfg
->speaker_pins
[0])
612 spec
->gen
.line_automute_hook
= via_line_automute
;
614 for (i
= 0; i
< cfg
->line_outs
; i
++) {
615 pin
= cfg
->line_out_pins
[i
];
616 if (pin
&& !snd_hda_jack_tbl_get(codec
, pin
) &&
617 is_jack_detectable(codec
, pin
))
618 snd_hda_jack_detect_enable_callback(codec
, pin
,
620 via_jack_powerstate_event
);
623 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
624 pin
= cfg
->line_out_pins
[i
];
625 if (pin
&& !snd_hda_jack_tbl_get(codec
, pin
) &&
626 is_jack_detectable(codec
, pin
))
627 snd_hda_jack_detect_enable_callback(codec
, pin
,
629 via_jack_powerstate_event
);
633 static const struct badness_table via_main_out_badness
= {
634 .no_primary_dac
= 0x10000,
636 .shared_primary
= 0x10000,
639 .shared_surr_main
= 0x20,
641 static const struct badness_table via_extra_out_badness
= {
642 .no_primary_dac
= 0x4000,
644 .shared_primary
= 0x12,
647 .shared_surr_main
= 0x10,
650 static int via_parse_auto_config(struct hda_codec
*codec
)
652 struct via_spec
*spec
= codec
->spec
;
655 spec
->gen
.main_out_badness
= &via_main_out_badness
;
656 spec
->gen
.extra_out_badness
= &via_extra_out_badness
;
658 err
= snd_hda_parse_pin_defcfg(codec
, &spec
->gen
.autocfg
, NULL
, 0);
662 err
= snd_hda_gen_parse_auto_config(codec
, &spec
->gen
.autocfg
);
666 via_set_jack_unsol_events(codec
);
670 static int via_init(struct hda_codec
*codec
)
672 struct via_spec
*spec
= codec
->spec
;
675 for (i
= 0; i
< spec
->num_iverbs
; i
++)
676 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
678 /* init power states */
679 set_widgets_power_state(codec
);
680 __analog_low_current_mode(codec
, true);
682 snd_hda_gen_init(codec
);
684 vt1708_update_hp_work(codec
);
689 static int vt1708_build_controls(struct hda_codec
*codec
)
691 /* In order not to create "Phantom Jack" controls,
692 temporary enable jackpoll */
694 int old_interval
= codec
->jackpoll_interval
;
695 codec
->jackpoll_interval
= msecs_to_jiffies(100);
696 err
= via_build_controls(codec
);
697 codec
->jackpoll_interval
= old_interval
;
701 static int vt1708_build_pcms(struct hda_codec
*codec
)
703 struct via_spec
*spec
= codec
->spec
;
706 err
= snd_hda_gen_build_pcms(codec
);
707 if (err
< 0 || codec
->vendor_id
!= 0x11061708)
710 /* We got noisy outputs on the right channel on VT1708 when
711 * 24bit samples are used. Until any workaround is found,
712 * disable the 24bit format, so far.
714 for (i
= 0; i
< codec
->num_pcms
; i
++) {
715 struct hda_pcm
*info
= &spec
->gen
.pcm_rec
[i
];
716 if (!info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].substreams
||
717 info
->pcm_type
!= HDA_PCM_TYPE_AUDIO
)
719 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].formats
=
720 SNDRV_PCM_FMTBIT_S16_LE
;
726 static int patch_vt1708(struct hda_codec
*codec
)
728 struct via_spec
*spec
;
731 /* create a codec specific record */
732 spec
= via_new_spec(codec
);
736 spec
->gen
.mixer_nid
= 0x17;
738 /* set jackpoll_interval while parsing the codec */
739 codec
->jackpoll_interval
= msecs_to_jiffies(100);
740 spec
->vt1708_jack_detect
= 1;
742 /* don't support the input jack switching due to lack of unsol event */
743 /* (it may work with polling, though, but it needs testing) */
744 spec
->gen
.suppress_auto_mic
= 1;
745 /* Some machines show the broken speaker mute */
746 spec
->gen
.auto_mute_via_amp
= 1;
748 /* Add HP and CD pin config connect bit re-config action */
749 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
750 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
752 /* automatic parse from the BIOS config */
753 err
= via_parse_auto_config(codec
);
759 /* add jack detect on/off control */
760 spec
->mixers
[spec
->num_mixers
++] = vt1708_jack_detect_ctl
;
762 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_init_verbs
;
764 codec
->patch_ops
= via_patch_ops
;
765 codec
->patch_ops
.build_controls
= vt1708_build_controls
;
766 codec
->patch_ops
.build_pcms
= vt1708_build_pcms
;
768 /* clear jackpoll_interval again; it's set dynamically */
769 codec
->jackpoll_interval
= 0;
774 static int patch_vt1709(struct hda_codec
*codec
)
776 struct via_spec
*spec
;
779 /* create a codec specific record */
780 spec
= via_new_spec(codec
);
784 spec
->gen
.mixer_nid
= 0x18;
786 err
= via_parse_auto_config(codec
);
792 codec
->patch_ops
= via_patch_ops
;
797 static void set_widgets_power_state_vt1708B(struct hda_codec
*codec
)
799 struct via_spec
*spec
= codec
->spec
;
803 if ((spec
->codec_type
!= VT1708B_4CH
) &&
804 (codec
->vendor_id
!= 0x11064397))
807 /* SW0 (17h) = stereo mixer */
809 (snd_hda_codec_read(codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00)
810 == ((spec
->codec_type
== VT1708S
) ? 5 : 0));
812 /* PW 1/2/5 (1ah/1bh/1eh) */
814 set_pin_power_state(codec
, 0x1a, &parm
);
815 set_pin_power_state(codec
, 0x1b, &parm
);
816 set_pin_power_state(codec
, 0x1e, &parm
);
819 /* SW0 (17h), AIW 0/1 (13h/14h) */
820 update_power_state(codec
, 0x17, parm
);
821 update_power_state(codec
, 0x13, parm
);
822 update_power_state(codec
, 0x14, parm
);
825 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
827 set_pin_power_state(codec
, 0x19, &parm
);
828 if (smart51_enabled(codec
))
829 set_pin_power_state(codec
, 0x1b, &parm
);
830 update_power_state(codec
, 0x18, parm
);
831 update_power_state(codec
, 0x11, parm
);
833 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
836 set_pin_power_state(codec
, 0x22, &parm
);
837 if (smart51_enabled(codec
))
838 set_pin_power_state(codec
, 0x1a, &parm
);
839 update_power_state(codec
, 0x26, parm
);
840 update_power_state(codec
, 0x24, parm
);
841 } else if (codec
->vendor_id
== 0x11064397) {
842 /* PW7(23h), SW2(27h), AOW2(25h) */
844 set_pin_power_state(codec
, 0x23, &parm
);
845 if (smart51_enabled(codec
))
846 set_pin_power_state(codec
, 0x1a, &parm
);
847 update_power_state(codec
, 0x27, parm
);
848 update_power_state(codec
, 0x25, parm
);
851 /* PW 3/4/7 (1ch/1dh/23h) */
853 /* force to D0 for internal Speaker */
854 set_pin_power_state(codec
, 0x1c, &parm
);
855 set_pin_power_state(codec
, 0x1d, &parm
);
857 set_pin_power_state(codec
, 0x23, &parm
);
859 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
860 update_power_state(codec
, 0x16, imux_is_smixer
? AC_PWRST_D0
: parm
);
861 update_power_state(codec
, 0x10, parm
);
863 update_power_state(codec
, 0x25, parm
);
864 update_power_state(codec
, 0x27, parm
);
865 } else if (codec
->vendor_id
== 0x11064397 && spec
->gen
.indep_hp_enabled
)
866 update_power_state(codec
, 0x25, parm
);
869 static int patch_vt1708S(struct hda_codec
*codec
);
870 static int patch_vt1708B(struct hda_codec
*codec
)
872 struct via_spec
*spec
;
875 if (get_codec_type(codec
) == VT1708BCE
)
876 return patch_vt1708S(codec
);
878 /* create a codec specific record */
879 spec
= via_new_spec(codec
);
883 spec
->gen
.mixer_nid
= 0x16;
885 /* automatic parse from the BIOS config */
886 err
= via_parse_auto_config(codec
);
892 codec
->patch_ops
= via_patch_ops
;
894 spec
->set_widgets_power_state
= set_widgets_power_state_vt1708B
;
899 /* Patch for VT1708S */
900 static const struct hda_verb vt1708S_init_verbs
[] = {
901 /* Enable Mic Boost Volume backdoor */
903 /* don't bybass mixer */
908 static void override_mic_boost(struct hda_codec
*codec
, hda_nid_t pin
,
909 int offset
, int num_steps
, int step_size
)
911 snd_hda_override_wcaps(codec
, pin
,
912 get_wcaps(codec
, pin
) | AC_WCAP_IN_AMP
);
913 snd_hda_override_amp_caps(codec
, pin
, HDA_INPUT
,
914 (offset
<< AC_AMPCAP_OFFSET_SHIFT
) |
915 (num_steps
<< AC_AMPCAP_NUM_STEPS_SHIFT
) |
916 (step_size
<< AC_AMPCAP_STEP_SIZE_SHIFT
) |
917 (0 << AC_AMPCAP_MUTE_SHIFT
));
920 static int patch_vt1708S(struct hda_codec
*codec
)
922 struct via_spec
*spec
;
925 /* create a codec specific record */
926 spec
= via_new_spec(codec
);
930 spec
->gen
.mixer_nid
= 0x16;
931 override_mic_boost(codec
, 0x1a, 0, 3, 40);
932 override_mic_boost(codec
, 0x1e, 0, 3, 40);
934 /* correct names for VT1708BCE */
935 if (get_codec_type(codec
) == VT1708BCE
) {
936 kfree(codec
->chip_name
);
937 codec
->chip_name
= kstrdup("VT1708BCE", GFP_KERNEL
);
938 snprintf(codec
->bus
->card
->mixername
,
939 sizeof(codec
->bus
->card
->mixername
),
940 "%s %s", codec
->vendor_name
, codec
->chip_name
);
942 /* correct names for VT1705 */
943 if (codec
->vendor_id
== 0x11064397) {
944 kfree(codec
->chip_name
);
945 codec
->chip_name
= kstrdup("VT1705", GFP_KERNEL
);
946 snprintf(codec
->bus
->card
->mixername
,
947 sizeof(codec
->bus
->card
->mixername
),
948 "%s %s", codec
->vendor_name
, codec
->chip_name
);
951 /* automatic parse from the BIOS config */
952 err
= via_parse_auto_config(codec
);
958 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_init_verbs
;
960 codec
->patch_ops
= via_patch_ops
;
962 spec
->set_widgets_power_state
= set_widgets_power_state_vt1708B
;
966 /* Patch for VT1702 */
968 static const struct hda_verb vt1702_init_verbs
[] = {
976 static void set_widgets_power_state_vt1702(struct hda_codec
*codec
)
979 snd_hda_codec_read(codec
, 0x13, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
982 /* PW 1/2/5 (14h/15h/18h) */
984 set_pin_power_state(codec
, 0x14, &parm
);
985 set_pin_power_state(codec
, 0x15, &parm
);
986 set_pin_power_state(codec
, 0x18, &parm
);
988 parm
= AC_PWRST_D0
; /* SW0 (13h) = stereo mixer (idx 3) */
989 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
990 update_power_state(codec
, 0x13, parm
);
991 update_power_state(codec
, 0x12, parm
);
992 update_power_state(codec
, 0x1f, parm
);
993 update_power_state(codec
, 0x20, parm
);
996 /* PW 3/4 (16h/17h) */
998 set_pin_power_state(codec
, 0x17, &parm
);
999 set_pin_power_state(codec
, 0x16, &parm
);
1000 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
1001 update_power_state(codec
, 0x1a, imux_is_smixer
? AC_PWRST_D0
: parm
);
1002 update_power_state(codec
, 0x10, parm
);
1003 update_power_state(codec
, 0x1d, parm
);
1006 static int patch_vt1702(struct hda_codec
*codec
)
1008 struct via_spec
*spec
;
1011 /* create a codec specific record */
1012 spec
= via_new_spec(codec
);
1016 spec
->gen
.mixer_nid
= 0x1a;
1018 /* limit AA path volume to 0 dB */
1019 snd_hda_override_amp_caps(codec
, 0x1A, HDA_INPUT
,
1020 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
1021 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
1022 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
1023 (1 << AC_AMPCAP_MUTE_SHIFT
));
1025 /* automatic parse from the BIOS config */
1026 err
= via_parse_auto_config(codec
);
1032 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_init_verbs
;
1034 codec
->patch_ops
= via_patch_ops
;
1036 spec
->set_widgets_power_state
= set_widgets_power_state_vt1702
;
1040 /* Patch for VT1718S */
1042 static const struct hda_verb vt1718S_init_verbs
[] = {
1043 /* Enable MW0 adjust Gain 5 */
1045 /* Enable Boost Volume backdoor */
1051 static void set_widgets_power_state_vt1718S(struct hda_codec
*codec
)
1053 struct via_spec
*spec
= codec
->spec
;
1055 unsigned int parm
, parm2
;
1056 /* MUX6 (1eh) = stereo mixer */
1058 snd_hda_codec_read(codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
1060 /* PW 5/6/7 (29h/2ah/2bh) */
1062 set_pin_power_state(codec
, 0x29, &parm
);
1063 set_pin_power_state(codec
, 0x2a, &parm
);
1064 set_pin_power_state(codec
, 0x2b, &parm
);
1067 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
1068 update_power_state(codec
, 0x1e, parm
);
1069 update_power_state(codec
, 0x1f, parm
);
1070 update_power_state(codec
, 0x10, parm
);
1071 update_power_state(codec
, 0x11, parm
);
1074 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
1076 set_pin_power_state(codec
, 0x27, &parm
);
1077 update_power_state(codec
, 0x1a, parm
);
1078 parm2
= parm
; /* for pin 0x0b */
1080 /* PW2 (26h), AOW2 (ah) */
1082 set_pin_power_state(codec
, 0x26, &parm
);
1083 if (smart51_enabled(codec
))
1084 set_pin_power_state(codec
, 0x2b, &parm
);
1085 update_power_state(codec
, 0xa, parm
);
1087 /* PW0 (24h), AOW0 (8h) */
1089 set_pin_power_state(codec
, 0x24, &parm
);
1090 if (!spec
->gen
.indep_hp_enabled
) /* check for redirected HP */
1091 set_pin_power_state(codec
, 0x28, &parm
);
1092 update_power_state(codec
, 0x8, parm
);
1093 if (!spec
->gen
.indep_hp_enabled
&& parm2
!= AC_PWRST_D3
)
1095 update_power_state(codec
, 0xb, parm
);
1096 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1097 update_power_state(codec
, 0x21, imux_is_smixer
? AC_PWRST_D0
: parm
);
1099 /* PW1 (25h), AOW1 (9h) */
1101 set_pin_power_state(codec
, 0x25, &parm
);
1102 if (smart51_enabled(codec
))
1103 set_pin_power_state(codec
, 0x2a, &parm
);
1104 update_power_state(codec
, 0x9, parm
);
1106 if (spec
->gen
.indep_hp_enabled
) {
1107 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
1109 set_pin_power_state(codec
, 0x28, &parm
);
1110 update_power_state(codec
, 0x1b, parm
);
1111 update_power_state(codec
, 0x34, parm
);
1112 update_power_state(codec
, 0xc, parm
);
1116 /* Add a connection to the primary DAC from AA-mixer for some codecs
1117 * This isn't listed from the raw info, but the chip has a secret connection.
1119 static int add_secret_dac_path(struct hda_codec
*codec
)
1121 struct via_spec
*spec
= codec
->spec
;
1126 if (!spec
->gen
.mixer_nid
)
1128 nums
= snd_hda_get_connections(codec
, spec
->gen
.mixer_nid
, conn
,
1129 ARRAY_SIZE(conn
) - 1);
1130 for (i
= 0; i
< nums
; i
++) {
1131 if (get_wcaps_type(get_wcaps(codec
, conn
[i
])) == AC_WID_AUD_OUT
)
1135 /* find the primary DAC and add to the connection list */
1136 nid
= codec
->start_nid
;
1137 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
1138 unsigned int caps
= get_wcaps(codec
, nid
);
1139 if (get_wcaps_type(caps
) == AC_WID_AUD_OUT
&&
1140 !(caps
& AC_WCAP_DIGITAL
)) {
1142 return snd_hda_override_conn_list(codec
,
1143 spec
->gen
.mixer_nid
,
1151 static int patch_vt1718S(struct hda_codec
*codec
)
1153 struct via_spec
*spec
;
1156 /* create a codec specific record */
1157 spec
= via_new_spec(codec
);
1161 spec
->gen
.mixer_nid
= 0x21;
1162 override_mic_boost(codec
, 0x2b, 0, 3, 40);
1163 override_mic_boost(codec
, 0x29, 0, 3, 40);
1164 add_secret_dac_path(codec
);
1166 /* automatic parse from the BIOS config */
1167 err
= via_parse_auto_config(codec
);
1173 spec
->init_verbs
[spec
->num_iverbs
++] = vt1718S_init_verbs
;
1175 codec
->patch_ops
= via_patch_ops
;
1177 spec
->set_widgets_power_state
= set_widgets_power_state_vt1718S
;
1182 /* Patch for VT1716S */
1184 static int vt1716s_dmic_info(struct snd_kcontrol
*kcontrol
,
1185 struct snd_ctl_elem_info
*uinfo
)
1187 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1189 uinfo
->value
.integer
.min
= 0;
1190 uinfo
->value
.integer
.max
= 1;
1194 static int vt1716s_dmic_get(struct snd_kcontrol
*kcontrol
,
1195 struct snd_ctl_elem_value
*ucontrol
)
1197 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1200 index
= snd_hda_codec_read(codec
, 0x26, 0,
1201 AC_VERB_GET_CONNECT_SEL
, 0);
1203 *ucontrol
->value
.integer
.value
= index
;
1208 static int vt1716s_dmic_put(struct snd_kcontrol
*kcontrol
,
1209 struct snd_ctl_elem_value
*ucontrol
)
1211 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1212 struct via_spec
*spec
= codec
->spec
;
1213 int index
= *ucontrol
->value
.integer
.value
;
1215 snd_hda_codec_write(codec
, 0x26, 0,
1216 AC_VERB_SET_CONNECT_SEL
, index
);
1217 spec
->dmic_enabled
= index
;
1218 set_widgets_power_state(codec
);
1222 static const struct snd_kcontrol_new vt1716s_dmic_mixer
[] = {
1223 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT
),
1225 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1226 .name
= "Digital Mic Capture Switch",
1227 .subdevice
= HDA_SUBDEV_NID_FLAG
| 0x26,
1229 .info
= vt1716s_dmic_info
,
1230 .get
= vt1716s_dmic_get
,
1231 .put
= vt1716s_dmic_put
,
1237 /* mono-out mixer elements */
1238 static const struct snd_kcontrol_new vt1716S_mono_out_mixer
[] = {
1239 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT
),
1243 static const struct hda_verb vt1716S_init_verbs
[] = {
1244 /* Enable Boost Volume backdoor */
1246 /* don't bybass mixer */
1248 /* Enable mono output */
1253 static void set_widgets_power_state_vt1716S(struct hda_codec
*codec
)
1255 struct via_spec
*spec
= codec
->spec
;
1258 unsigned int mono_out
, present
;
1259 /* SW0 (17h) = stereo mixer */
1261 (snd_hda_codec_read(codec
, 0x17, 0,
1262 AC_VERB_GET_CONNECT_SEL
, 0x00) == 5);
1264 /* PW 1/2/5 (1ah/1bh/1eh) */
1266 set_pin_power_state(codec
, 0x1a, &parm
);
1267 set_pin_power_state(codec
, 0x1b, &parm
);
1268 set_pin_power_state(codec
, 0x1e, &parm
);
1271 /* SW0 (17h), AIW0(13h) */
1272 update_power_state(codec
, 0x17, parm
);
1273 update_power_state(codec
, 0x13, parm
);
1276 set_pin_power_state(codec
, 0x1e, &parm
);
1278 if (spec
->dmic_enabled
)
1279 set_pin_power_state(codec
, 0x22, &parm
);
1281 update_power_state(codec
, 0x22, AC_PWRST_D3
);
1283 /* SW2(26h), AIW1(14h) */
1284 update_power_state(codec
, 0x26, parm
);
1285 update_power_state(codec
, 0x14, parm
);
1288 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
1290 set_pin_power_state(codec
, 0x19, &parm
);
1291 /* Smart 5.1 PW2(1bh) */
1292 if (smart51_enabled(codec
))
1293 set_pin_power_state(codec
, 0x1b, &parm
);
1294 update_power_state(codec
, 0x18, parm
);
1295 update_power_state(codec
, 0x11, parm
);
1297 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
1299 set_pin_power_state(codec
, 0x23, &parm
);
1300 /* Smart 5.1 PW1(1ah) */
1301 if (smart51_enabled(codec
))
1302 set_pin_power_state(codec
, 0x1a, &parm
);
1303 update_power_state(codec
, 0x27, parm
);
1305 /* Smart 5.1 PW5(1eh) */
1306 if (smart51_enabled(codec
))
1307 set_pin_power_state(codec
, 0x1e, &parm
);
1308 update_power_state(codec
, 0x25, parm
);
1311 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
1312 present
= snd_hda_jack_detect(codec
, 0x1c);
1317 present
= snd_hda_jack_detect(codec
, 0x1d);
1318 if (!spec
->gen
.indep_hp_enabled
&& present
)
1323 parm
= mono_out
? AC_PWRST_D0
: AC_PWRST_D3
;
1324 update_power_state(codec
, 0x28, parm
);
1325 update_power_state(codec
, 0x29, parm
);
1326 update_power_state(codec
, 0x2a, parm
);
1328 /* PW 3/4 (1ch/1dh) */
1330 set_pin_power_state(codec
, 0x1c, &parm
);
1331 set_pin_power_state(codec
, 0x1d, &parm
);
1332 /* HP Independent Mode, power on AOW3 */
1333 if (spec
->gen
.indep_hp_enabled
)
1334 update_power_state(codec
, 0x25, parm
);
1336 /* force to D0 for internal Speaker */
1337 /* MW0 (16h), AOW0 (10h) */
1338 update_power_state(codec
, 0x16, imux_is_smixer
? AC_PWRST_D0
: parm
);
1339 update_power_state(codec
, 0x10, mono_out
? AC_PWRST_D0
: parm
);
1342 static int patch_vt1716S(struct hda_codec
*codec
)
1344 struct via_spec
*spec
;
1347 /* create a codec specific record */
1348 spec
= via_new_spec(codec
);
1352 spec
->gen
.mixer_nid
= 0x16;
1353 override_mic_boost(codec
, 0x1a, 0, 3, 40);
1354 override_mic_boost(codec
, 0x1e, 0, 3, 40);
1356 /* automatic parse from the BIOS config */
1357 err
= via_parse_auto_config(codec
);
1363 spec
->init_verbs
[spec
->num_iverbs
++] = vt1716S_init_verbs
;
1365 spec
->mixers
[spec
->num_mixers
++] = vt1716s_dmic_mixer
;
1366 spec
->mixers
[spec
->num_mixers
++] = vt1716S_mono_out_mixer
;
1368 codec
->patch_ops
= via_patch_ops
;
1370 spec
->set_widgets_power_state
= set_widgets_power_state_vt1716S
;
1376 static const struct hda_verb vt2002P_init_verbs
[] = {
1377 /* Class-D speaker related verbs */
1381 /* Enable Boost Volume backdoor */
1383 /* Enable AOW0 to MW9 */
1388 static const struct hda_verb vt1802_init_verbs
[] = {
1389 /* Enable Boost Volume backdoor */
1391 /* Enable AOW0 to MW9 */
1396 static void set_widgets_power_state_vt2002P(struct hda_codec
*codec
)
1398 struct via_spec
*spec
= codec
->spec
;
1401 unsigned int present
;
1402 /* MUX9 (1eh) = stereo mixer */
1404 snd_hda_codec_read(codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
1406 /* PW 5/6/7 (29h/2ah/2bh) */
1408 set_pin_power_state(codec
, 0x29, &parm
);
1409 set_pin_power_state(codec
, 0x2a, &parm
);
1410 set_pin_power_state(codec
, 0x2b, &parm
);
1412 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
1413 update_power_state(codec
, 0x1e, parm
);
1414 update_power_state(codec
, 0x1f, parm
);
1415 update_power_state(codec
, 0x10, parm
);
1416 update_power_state(codec
, 0x11, parm
);
1420 update_power_state(codec
, 0x8, parm
);
1422 if (spec
->codec_type
== VT1802
) {
1423 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1425 set_pin_power_state(codec
, 0x28, &parm
);
1426 update_power_state(codec
, 0x18, parm
);
1427 update_power_state(codec
, 0x38, parm
);
1429 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
1431 set_pin_power_state(codec
, 0x26, &parm
);
1432 update_power_state(codec
, 0x1c, parm
);
1433 update_power_state(codec
, 0x37, parm
);
1436 if (spec
->codec_type
== VT1802
) {
1437 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1439 set_pin_power_state(codec
, 0x25, &parm
);
1440 update_power_state(codec
, 0x15, parm
);
1441 update_power_state(codec
, 0x35, parm
);
1443 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
1445 set_pin_power_state(codec
, 0x25, &parm
);
1446 update_power_state(codec
, 0x19, parm
);
1447 update_power_state(codec
, 0x35, parm
);
1450 if (spec
->gen
.indep_hp_enabled
)
1451 update_power_state(codec
, 0x9, AC_PWRST_D0
);
1454 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
1455 present
= snd_hda_jack_detect(codec
, 0x25);
1458 set_pin_power_state(codec
, 0x24, &parm
);
1459 parm
= present
? AC_PWRST_D3
: AC_PWRST_D0
;
1460 if (spec
->codec_type
== VT1802
)
1461 update_power_state(codec
, 0x14, parm
);
1463 update_power_state(codec
, 0x18, parm
);
1464 update_power_state(codec
, 0x34, parm
);
1467 present
= snd_hda_jack_detect(codec
, 0x26);
1469 parm
= present
? AC_PWRST_D3
: AC_PWRST_D0
;
1470 if (spec
->codec_type
== VT1802
) {
1471 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
1472 update_power_state(codec
, 0x33, parm
);
1473 update_power_state(codec
, 0x1c, parm
);
1474 update_power_state(codec
, 0x3c, parm
);
1476 /* PW15 (31h), MW8(17h), MUX8(3bh) */
1477 update_power_state(codec
, 0x31, parm
);
1478 update_power_state(codec
, 0x17, parm
);
1479 update_power_state(codec
, 0x3b, parm
);
1482 if (imux_is_smixer
|| !is_aa_path_mute(codec
))
1483 update_power_state(codec
, 0x21, AC_PWRST_D0
);
1485 update_power_state(codec
, 0x21, AC_PWRST_D3
);
1492 VIA_FIXUP_INTMIC_BOOST
,
1496 static void via_fixup_intmic_boost(struct hda_codec
*codec
,
1497 const struct hda_fixup
*fix
, int action
)
1499 if (action
== HDA_FIXUP_ACT_PRE_PROBE
)
1500 override_mic_boost(codec
, 0x30, 0, 2, 40);
1503 static const struct hda_fixup via_fixups
[] = {
1504 [VIA_FIXUP_INTMIC_BOOST
] = {
1505 .type
= HDA_FIXUP_FUNC
,
1506 .v
.func
= via_fixup_intmic_boost
,
1508 [VIA_FIXUP_ASUS_G75
] = {
1509 .type
= HDA_FIXUP_PINS
,
1510 .v
.pins
= (const struct hda_pintbl
[]) {
1511 /* set 0x24 and 0x33 as speakers */
1512 { 0x24, 0x991301f0 },
1513 { 0x33, 0x991301f1 }, /* subwoofer */
1519 static const struct snd_pci_quirk vt2002p_fixups
[] = {
1520 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75
),
1521 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST
),
1525 /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
1526 * Replace this with mixer NID 0x1c
1528 static void fix_vt1802_connections(struct hda_codec
*codec
)
1530 static hda_nid_t conn_24
[] = { 0x14, 0x1c };
1531 static hda_nid_t conn_33
[] = { 0x1c };
1533 snd_hda_override_conn_list(codec
, 0x24, ARRAY_SIZE(conn_24
), conn_24
);
1534 snd_hda_override_conn_list(codec
, 0x33, ARRAY_SIZE(conn_33
), conn_33
);
1537 /* patch for vt2002P */
1538 static int patch_vt2002P(struct hda_codec
*codec
)
1540 struct via_spec
*spec
;
1543 /* create a codec specific record */
1544 spec
= via_new_spec(codec
);
1548 spec
->gen
.mixer_nid
= 0x21;
1549 override_mic_boost(codec
, 0x2b, 0, 3, 40);
1550 override_mic_boost(codec
, 0x29, 0, 3, 40);
1551 if (spec
->codec_type
== VT1802
)
1552 fix_vt1802_connections(codec
);
1553 add_secret_dac_path(codec
);
1555 snd_hda_pick_fixup(codec
, NULL
, vt2002p_fixups
, via_fixups
);
1556 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
1558 /* automatic parse from the BIOS config */
1559 err
= via_parse_auto_config(codec
);
1565 if (spec
->codec_type
== VT1802
)
1566 spec
->init_verbs
[spec
->num_iverbs
++] = vt1802_init_verbs
;
1568 spec
->init_verbs
[spec
->num_iverbs
++] = vt2002P_init_verbs
;
1570 codec
->patch_ops
= via_patch_ops
;
1572 spec
->set_widgets_power_state
= set_widgets_power_state_vt2002P
;
1578 static const struct hda_verb vt1812_init_verbs
[] = {
1579 /* Enable Boost Volume backdoor */
1581 /* Enable AOW0 to MW9 */
1586 static void set_widgets_power_state_vt1812(struct hda_codec
*codec
)
1588 struct via_spec
*spec
= codec
->spec
;
1590 unsigned int present
;
1592 /* PW 5/6/7 (29h/2ah/2bh) */
1594 set_pin_power_state(codec
, 0x29, &parm
);
1595 set_pin_power_state(codec
, 0x2a, &parm
);
1596 set_pin_power_state(codec
, 0x2b, &parm
);
1598 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1599 update_power_state(codec
, 0x1e, parm
);
1600 update_power_state(codec
, 0x1f, parm
);
1601 update_power_state(codec
, 0x10, parm
);
1602 update_power_state(codec
, 0x11, parm
);
1606 update_power_state(codec
, 0x8, AC_PWRST_D0
);
1608 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1610 set_pin_power_state(codec
, 0x28, &parm
);
1611 update_power_state(codec
, 0x18, parm
);
1612 update_power_state(codec
, 0x38, parm
);
1614 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1616 set_pin_power_state(codec
, 0x25, &parm
);
1617 update_power_state(codec
, 0x15, parm
);
1618 update_power_state(codec
, 0x35, parm
);
1619 if (spec
->gen
.indep_hp_enabled
)
1620 update_power_state(codec
, 0x9, AC_PWRST_D0
);
1622 /* Internal Speaker */
1623 /* PW0 (24h), MW0(14h), MUX0(34h) */
1624 present
= snd_hda_jack_detect(codec
, 0x25);
1627 set_pin_power_state(codec
, 0x24, &parm
);
1629 update_power_state(codec
, 0x14, AC_PWRST_D3
);
1630 update_power_state(codec
, 0x34, AC_PWRST_D3
);
1632 update_power_state(codec
, 0x14, AC_PWRST_D0
);
1633 update_power_state(codec
, 0x34, AC_PWRST_D0
);
1638 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1639 present
= snd_hda_jack_detect(codec
, 0x28);
1642 set_pin_power_state(codec
, 0x31, &parm
);
1644 update_power_state(codec
, 0x1c, AC_PWRST_D3
);
1645 update_power_state(codec
, 0x3c, AC_PWRST_D3
);
1646 update_power_state(codec
, 0x3e, AC_PWRST_D3
);
1648 update_power_state(codec
, 0x1c, AC_PWRST_D0
);
1649 update_power_state(codec
, 0x3c, AC_PWRST_D0
);
1650 update_power_state(codec
, 0x3e, AC_PWRST_D0
);
1653 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1655 set_pin_power_state(codec
, 0x33, &parm
);
1656 update_power_state(codec
, 0x1d, parm
);
1657 update_power_state(codec
, 0x3d, parm
);
1661 /* patch for vt1812 */
1662 static int patch_vt1812(struct hda_codec
*codec
)
1664 struct via_spec
*spec
;
1667 /* create a codec specific record */
1668 spec
= via_new_spec(codec
);
1672 spec
->gen
.mixer_nid
= 0x21;
1673 override_mic_boost(codec
, 0x2b, 0, 3, 40);
1674 override_mic_boost(codec
, 0x29, 0, 3, 40);
1675 add_secret_dac_path(codec
);
1677 /* automatic parse from the BIOS config */
1678 err
= via_parse_auto_config(codec
);
1684 spec
->init_verbs
[spec
->num_iverbs
++] = vt1812_init_verbs
;
1686 codec
->patch_ops
= via_patch_ops
;
1688 spec
->set_widgets_power_state
= set_widgets_power_state_vt1812
;
1692 /* patch for vt3476 */
1694 static const struct hda_verb vt3476_init_verbs
[] = {
1695 /* Enable DMic 8/16/32K */
1697 /* Enable Boost Volume backdoor */
1699 /* Enable AOW-MW9 path */
1704 static void set_widgets_power_state_vt3476(struct hda_codec
*codec
)
1706 struct via_spec
*spec
= codec
->spec
;
1708 unsigned int parm
, parm2
;
1709 /* MUX10 (1eh) = stereo mixer */
1711 snd_hda_codec_read(codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 4;
1713 /* PW 5/6/7 (29h/2ah/2bh) */
1715 set_pin_power_state(codec
, 0x29, &parm
);
1716 set_pin_power_state(codec
, 0x2a, &parm
);
1717 set_pin_power_state(codec
, 0x2b, &parm
);
1720 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1721 update_power_state(codec
, 0x1e, parm
);
1722 update_power_state(codec
, 0x1f, parm
);
1723 update_power_state(codec
, 0x10, parm
);
1724 update_power_state(codec
, 0x11, parm
);
1727 /* PW3 (27h), MW3(37h), AOW3 (bh) */
1728 if (spec
->codec_type
== VT1705CF
) {
1730 update_power_state(codec
, 0x27, parm
);
1731 update_power_state(codec
, 0x37, parm
);
1734 set_pin_power_state(codec
, 0x27, &parm
);
1735 update_power_state(codec
, 0x37, parm
);
1738 /* PW2 (26h), MW2(36h), AOW2 (ah) */
1740 set_pin_power_state(codec
, 0x26, &parm
);
1741 update_power_state(codec
, 0x36, parm
);
1742 if (smart51_enabled(codec
)) {
1743 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
1744 set_pin_power_state(codec
, 0x2b, &parm
);
1745 update_power_state(codec
, 0x3b, parm
);
1746 update_power_state(codec
, 0x1b, parm
);
1748 update_conv_power_state(codec
, 0xa, parm
, 2);
1750 /* PW1 (25h), MW1(35h), AOW1 (9h) */
1752 set_pin_power_state(codec
, 0x25, &parm
);
1753 update_power_state(codec
, 0x35, parm
);
1754 if (smart51_enabled(codec
)) {
1755 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
1756 set_pin_power_state(codec
, 0x2a, &parm
);
1757 update_power_state(codec
, 0x3a, parm
);
1758 update_power_state(codec
, 0x1a, parm
);
1760 update_conv_power_state(codec
, 0x9, parm
, 1);
1762 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
1764 set_pin_power_state(codec
, 0x28, &parm
);
1765 update_power_state(codec
, 0x38, parm
);
1766 update_power_state(codec
, 0x18, parm
);
1767 if (spec
->gen
.indep_hp_enabled
)
1768 update_conv_power_state(codec
, 0xb, parm
, 3);
1769 parm2
= parm
; /* for pin 0x0b */
1771 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
1773 set_pin_power_state(codec
, 0x24, &parm
);
1774 update_power_state(codec
, 0x34, parm
);
1775 if (!spec
->gen
.indep_hp_enabled
&& parm2
!= AC_PWRST_D3
)
1777 update_conv_power_state(codec
, 0x8, parm
, 0);
1778 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1779 update_power_state(codec
, 0x3f, imux_is_smixer
? AC_PWRST_D0
: parm
);
1782 static int patch_vt3476(struct hda_codec
*codec
)
1784 struct via_spec
*spec
;
1787 /* create a codec specific record */
1788 spec
= via_new_spec(codec
);
1792 spec
->gen
.mixer_nid
= 0x3f;
1793 add_secret_dac_path(codec
);
1795 /* automatic parse from the BIOS config */
1796 err
= via_parse_auto_config(codec
);
1802 spec
->init_verbs
[spec
->num_iverbs
++] = vt3476_init_verbs
;
1804 codec
->patch_ops
= via_patch_ops
;
1806 spec
->set_widgets_power_state
= set_widgets_power_state_vt3476
;
1814 static const struct hda_codec_preset snd_hda_preset_via
[] = {
1815 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
1816 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
1817 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
1818 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
1819 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
1820 .patch
= patch_vt1709
},
1821 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
1822 .patch
= patch_vt1709
},
1823 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
1824 .patch
= patch_vt1709
},
1825 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
1826 .patch
= patch_vt1709
},
1827 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
1828 .patch
= patch_vt1709
},
1829 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
1830 .patch
= patch_vt1709
},
1831 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
1832 .patch
= patch_vt1709
},
1833 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
1834 .patch
= patch_vt1709
},
1835 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
1836 .patch
= patch_vt1708B
},
1837 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
1838 .patch
= patch_vt1708B
},
1839 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
1840 .patch
= patch_vt1708B
},
1841 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
1842 .patch
= patch_vt1708B
},
1843 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
1844 .patch
= patch_vt1708B
},
1845 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
1846 .patch
= patch_vt1708B
},
1847 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
1848 .patch
= patch_vt1708B
},
1849 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
1850 .patch
= patch_vt1708B
},
1851 { .id
= 0x11060397, .name
= "VT1708S",
1852 .patch
= patch_vt1708S
},
1853 { .id
= 0x11061397, .name
= "VT1708S",
1854 .patch
= patch_vt1708S
},
1855 { .id
= 0x11062397, .name
= "VT1708S",
1856 .patch
= patch_vt1708S
},
1857 { .id
= 0x11063397, .name
= "VT1708S",
1858 .patch
= patch_vt1708S
},
1859 { .id
= 0x11064397, .name
= "VT1705",
1860 .patch
= patch_vt1708S
},
1861 { .id
= 0x11065397, .name
= "VT1708S",
1862 .patch
= patch_vt1708S
},
1863 { .id
= 0x11066397, .name
= "VT1708S",
1864 .patch
= patch_vt1708S
},
1865 { .id
= 0x11067397, .name
= "VT1708S",
1866 .patch
= patch_vt1708S
},
1867 { .id
= 0x11060398, .name
= "VT1702",
1868 .patch
= patch_vt1702
},
1869 { .id
= 0x11061398, .name
= "VT1702",
1870 .patch
= patch_vt1702
},
1871 { .id
= 0x11062398, .name
= "VT1702",
1872 .patch
= patch_vt1702
},
1873 { .id
= 0x11063398, .name
= "VT1702",
1874 .patch
= patch_vt1702
},
1875 { .id
= 0x11064398, .name
= "VT1702",
1876 .patch
= patch_vt1702
},
1877 { .id
= 0x11065398, .name
= "VT1702",
1878 .patch
= patch_vt1702
},
1879 { .id
= 0x11066398, .name
= "VT1702",
1880 .patch
= patch_vt1702
},
1881 { .id
= 0x11067398, .name
= "VT1702",
1882 .patch
= patch_vt1702
},
1883 { .id
= 0x11060428, .name
= "VT1718S",
1884 .patch
= patch_vt1718S
},
1885 { .id
= 0x11064428, .name
= "VT1718S",
1886 .patch
= patch_vt1718S
},
1887 { .id
= 0x11060441, .name
= "VT2020",
1888 .patch
= patch_vt1718S
},
1889 { .id
= 0x11064441, .name
= "VT1828S",
1890 .patch
= patch_vt1718S
},
1891 { .id
= 0x11060433, .name
= "VT1716S",
1892 .patch
= patch_vt1716S
},
1893 { .id
= 0x1106a721, .name
= "VT1716S",
1894 .patch
= patch_vt1716S
},
1895 { .id
= 0x11060438, .name
= "VT2002P", .patch
= patch_vt2002P
},
1896 { .id
= 0x11064438, .name
= "VT2002P", .patch
= patch_vt2002P
},
1897 { .id
= 0x11060448, .name
= "VT1812", .patch
= patch_vt1812
},
1898 { .id
= 0x11060440, .name
= "VT1818S",
1899 .patch
= patch_vt1708S
},
1900 { .id
= 0x11060446, .name
= "VT1802",
1901 .patch
= patch_vt2002P
},
1902 { .id
= 0x11068446, .name
= "VT1802",
1903 .patch
= patch_vt2002P
},
1904 { .id
= 0x11064760, .name
= "VT1705CF",
1905 .patch
= patch_vt3476
},
1906 { .id
= 0x11064761, .name
= "VT1708SCE",
1907 .patch
= patch_vt3476
},
1908 { .id
= 0x11064762, .name
= "VT1808",
1909 .patch
= patch_vt3476
},
1913 MODULE_ALIAS("snd-hda-codec-id:1106*");
1915 static struct hda_codec_preset_list via_list
= {
1916 .preset
= snd_hda_preset_via
,
1917 .owner
= THIS_MODULE
,
1920 MODULE_LICENSE("GPL");
1921 MODULE_DESCRIPTION("VIA HD-audio codec");
1923 static int __init
patch_via_init(void)
1925 return snd_hda_add_codec_preset(&via_list
);
1928 static void __exit
patch_via_exit(void)
1930 snd_hda_delete_codec_preset(&via_list
);
1933 module_init(patch_via_init
)
1934 module_exit(patch_via_exit
)