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
.pcm_playback_hook
= via_playback_pcm_hook
;
143 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
)
145 u32 vendor_id
= codec
->vendor_id
;
146 u16 ven_id
= vendor_id
>> 16;
147 u16 dev_id
= vendor_id
& 0xffff;
148 enum VIA_HDA_CODEC codec_type
;
151 if (ven_id
!= 0x1106)
152 codec_type
= UNKNOWN
;
153 else if (dev_id
>= 0x1708 && dev_id
<= 0x170b)
155 else if (dev_id
>= 0xe710 && dev_id
<= 0xe713)
156 codec_type
= VT1709_10CH
;
157 else if (dev_id
>= 0xe714 && dev_id
<= 0xe717)
158 codec_type
= VT1709_6CH
;
159 else if (dev_id
>= 0xe720 && dev_id
<= 0xe723) {
160 codec_type
= VT1708B_8CH
;
161 if (snd_hda_param_read(codec
, 0x16, AC_PAR_CONNLIST_LEN
) == 0x7)
162 codec_type
= VT1708BCE
;
163 } else if (dev_id
>= 0xe724 && dev_id
<= 0xe727)
164 codec_type
= VT1708B_4CH
;
165 else if ((dev_id
& 0xfff) == 0x397
166 && (dev_id
>> 12) < 8)
167 codec_type
= VT1708S
;
168 else if ((dev_id
& 0xfff) == 0x398
169 && (dev_id
>> 12) < 8)
171 else if ((dev_id
& 0xfff) == 0x428
172 && (dev_id
>> 12) < 8)
173 codec_type
= VT1718S
;
174 else if (dev_id
== 0x0433 || dev_id
== 0xa721)
175 codec_type
= VT1716S
;
176 else if (dev_id
== 0x0441 || dev_id
== 0x4441)
177 codec_type
= VT1718S
;
178 else if (dev_id
== 0x0438 || dev_id
== 0x4438)
179 codec_type
= VT2002P
;
180 else if (dev_id
== 0x0448)
182 else if (dev_id
== 0x0440)
183 codec_type
= VT1708S
;
184 else if ((dev_id
& 0xfff) == 0x446)
186 else if (dev_id
== 0x4760)
187 codec_type
= VT1705CF
;
188 else if (dev_id
== 0x4761 || dev_id
== 0x4762)
191 codec_type
= UNKNOWN
;
195 static void analog_low_current_mode(struct hda_codec
*codec
);
196 static bool is_aa_path_mute(struct hda_codec
*codec
);
198 #define hp_detect_with_aa(codec) \
199 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
200 !is_aa_path_mute(codec))
202 static void vt1708_stop_hp_work(struct hda_codec
*codec
)
204 struct via_spec
*spec
= codec
->spec
;
205 if (spec
->codec_type
!= VT1708
|| !spec
->gen
.autocfg
.hp_outs
)
207 if (spec
->hp_work_active
) {
208 snd_hda_codec_write(codec
, 0x1, 0, 0xf81, 1);
209 cancel_delayed_work_sync(&codec
->jackpoll_work
);
210 spec
->hp_work_active
= false;
211 codec
->jackpoll_interval
= 0;
215 static void vt1708_update_hp_work(struct hda_codec
*codec
)
217 struct via_spec
*spec
= codec
->spec
;
218 if (spec
->codec_type
!= VT1708
|| !spec
->gen
.autocfg
.hp_outs
)
220 if (spec
->vt1708_jack_detect
) {
221 if (!spec
->hp_work_active
) {
222 codec
->jackpoll_interval
= msecs_to_jiffies(100);
223 snd_hda_codec_write(codec
, 0x1, 0, 0xf81, 0);
224 queue_delayed_work(codec
->bus
->workq
,
225 &codec
->jackpoll_work
, 0);
226 spec
->hp_work_active
= true;
228 } else if (!hp_detect_with_aa(codec
))
229 vt1708_stop_hp_work(codec
);
232 static void set_widgets_power_state(struct hda_codec
*codec
)
234 struct via_spec
*spec
= codec
->spec
;
235 if (spec
->set_widgets_power_state
)
236 spec
->set_widgets_power_state(codec
);
239 static void update_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
242 if (snd_hda_check_power_state(codec
, nid
, parm
))
244 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
247 static void update_conv_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
248 unsigned int parm
, unsigned int index
)
250 struct via_spec
*spec
= codec
->spec
;
253 if (snd_hda_check_power_state(codec
, nid
, parm
))
255 format
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_CONV
, 0);
256 if (format
&& (spec
->dac_stream_tag
[index
] != format
))
257 spec
->dac_stream_tag
[index
] = format
;
259 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
260 if (parm
== AC_PWRST_D0
) {
261 format
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_CONV
, 0);
262 if (!format
&& (spec
->dac_stream_tag
[index
] != format
))
263 snd_hda_codec_write(codec
, nid
, 0,
264 AC_VERB_SET_CHANNEL_STREAMID
,
265 spec
->dac_stream_tag
[index
]);
269 static bool smart51_enabled(struct hda_codec
*codec
)
271 struct via_spec
*spec
= codec
->spec
;
272 return spec
->gen
.ext_channel_count
> 2;
275 static bool is_smart51_pins(struct hda_codec
*codec
, hda_nid_t pin
)
277 struct via_spec
*spec
= codec
->spec
;
280 for (i
= 0; i
< spec
->gen
.multi_ios
; i
++)
281 if (spec
->gen
.multi_io
[i
].pin
== pin
)
286 static void set_pin_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
287 unsigned int *affected_parm
)
290 unsigned def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
291 unsigned no_presence
= (def_conf
& AC_DEFCFG_MISC
)
292 >> AC_DEFCFG_MISC_SHIFT
293 & AC_DEFCFG_MISC_NO_PRESENCE
; /* do not support pin sense */
294 struct via_spec
*spec
= codec
->spec
;
295 unsigned present
= 0;
297 no_presence
|= spec
->no_pin_power_ctl
;
299 present
= snd_hda_jack_detect(codec
, nid
);
300 if ((smart51_enabled(codec
) && is_smart51_pins(codec
, nid
))
301 || ((no_presence
|| present
)
302 && get_defcfg_connect(def_conf
) != AC_JACK_PORT_NONE
)) {
303 *affected_parm
= AC_PWRST_D0
; /* if it's connected */
308 update_power_state(codec
, nid
, parm
);
311 static int via_pin_power_ctl_info(struct snd_kcontrol
*kcontrol
,
312 struct snd_ctl_elem_info
*uinfo
)
314 return snd_hda_enum_bool_helper_info(kcontrol
, uinfo
);
317 static int via_pin_power_ctl_get(struct snd_kcontrol
*kcontrol
,
318 struct snd_ctl_elem_value
*ucontrol
)
320 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
321 struct via_spec
*spec
= codec
->spec
;
322 ucontrol
->value
.enumerated
.item
[0] = !spec
->no_pin_power_ctl
;
326 static int via_pin_power_ctl_put(struct snd_kcontrol
*kcontrol
,
327 struct snd_ctl_elem_value
*ucontrol
)
329 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
330 struct via_spec
*spec
= codec
->spec
;
331 unsigned int val
= !ucontrol
->value
.enumerated
.item
[0];
333 if (val
== spec
->no_pin_power_ctl
)
335 spec
->no_pin_power_ctl
= val
;
336 set_widgets_power_state(codec
);
337 analog_low_current_mode(codec
);
341 static const struct snd_kcontrol_new via_pin_power_ctl_enum
[] = {
343 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
344 .name
= "Dynamic Power-Control",
345 .info
= via_pin_power_ctl_info
,
346 .get
= via_pin_power_ctl_get
,
347 .put
= via_pin_power_ctl_put
,
353 /* check AA path's mute status */
354 static bool is_aa_path_mute(struct hda_codec
*codec
)
356 struct via_spec
*spec
= codec
->spec
;
357 const struct hda_amp_list
*p
;
360 p
= spec
->gen
.loopback
.amplist
;
363 for (; p
->nid
; p
++) {
364 for (ch
= 0; ch
< 2; ch
++) {
365 v
= snd_hda_codec_amp_read(codec
, p
->nid
, ch
, p
->dir
,
367 if (!(v
& HDA_AMP_MUTE
) && v
> 0)
374 /* enter/exit analog low-current mode */
375 static void __analog_low_current_mode(struct hda_codec
*codec
, bool force
)
377 struct via_spec
*spec
= codec
->spec
;
379 unsigned int verb
, parm
;
381 if (spec
->no_pin_power_ctl
)
384 enable
= is_aa_path_mute(codec
) && !spec
->gen
.active_streams
;
385 if (enable
== spec
->alc_mode
&& !force
)
387 spec
->alc_mode
= enable
;
389 /* decide low current mode's verb & parameter */
390 switch (spec
->codec_type
) {
394 parm
= enable
? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
400 parm
= enable
? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
404 parm
= enable
? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
410 parm
= enable
? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
415 parm
= enable
? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
418 return; /* other codecs are not supported */
421 snd_hda_codec_write(codec
, codec
->afg
, 0, verb
, parm
);
424 static void analog_low_current_mode(struct hda_codec
*codec
)
426 return __analog_low_current_mode(codec
, false);
429 static int via_build_controls(struct hda_codec
*codec
)
431 struct via_spec
*spec
= codec
->spec
;
434 err
= snd_hda_gen_build_controls(codec
);
438 if (spec
->set_widgets_power_state
)
439 spec
->mixers
[spec
->num_mixers
++] = via_pin_power_ctl_enum
;
441 for (i
= 0; i
< spec
->num_mixers
; i
++) {
442 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
450 static void via_playback_pcm_hook(struct hda_pcm_stream
*hinfo
,
451 struct hda_codec
*codec
,
452 struct snd_pcm_substream
*substream
,
455 analog_low_current_mode(codec
);
456 vt1708_update_hp_work(codec
);
459 static void via_free(struct hda_codec
*codec
)
461 struct via_spec
*spec
= codec
->spec
;
466 vt1708_stop_hp_work(codec
);
467 snd_hda_gen_spec_free(&spec
->gen
);
472 static int via_suspend(struct hda_codec
*codec
)
474 struct via_spec
*spec
= codec
->spec
;
475 vt1708_stop_hp_work(codec
);
477 if (spec
->codec_type
== VT1802
) {
478 /* Fix pop noise on headphones */
480 for (i
= 0; i
< spec
->gen
.autocfg
.hp_outs
; i
++)
481 snd_hda_set_pin_ctl(codec
, spec
->gen
.autocfg
.hp_pins
[i
], 0);
489 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
491 struct via_spec
*spec
= codec
->spec
;
492 set_widgets_power_state(codec
);
493 analog_low_current_mode(codec
);
494 vt1708_update_hp_work(codec
);
495 return snd_hda_check_amp_list_power(codec
, &spec
->gen
.loopback
, nid
);
502 static int via_init(struct hda_codec
*codec
);
504 static const struct hda_codec_ops via_patch_ops
= {
505 .build_controls
= via_build_controls
,
506 .build_pcms
= snd_hda_gen_build_pcms
,
509 .unsol_event
= snd_hda_jack_unsol_event
,
511 .suspend
= via_suspend
,
512 .check_power_status
= via_check_power_status
,
517 static const struct hda_verb vt1708_init_verbs
[] = {
518 /* power down jack detect function */
522 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
524 unsigned int def_conf
;
525 unsigned char seqassoc
;
527 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
528 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
529 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
530 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
531 && (seqassoc
== 0xf0 || seqassoc
== 0xff)) {
532 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
533 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
539 static int vt1708_jack_detect_get(struct snd_kcontrol
*kcontrol
,
540 struct snd_ctl_elem_value
*ucontrol
)
542 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
543 struct via_spec
*spec
= codec
->spec
;
545 if (spec
->codec_type
!= VT1708
)
547 ucontrol
->value
.integer
.value
[0] = spec
->vt1708_jack_detect
;
551 static int vt1708_jack_detect_put(struct snd_kcontrol
*kcontrol
,
552 struct snd_ctl_elem_value
*ucontrol
)
554 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
555 struct via_spec
*spec
= codec
->spec
;
558 if (spec
->codec_type
!= VT1708
)
560 val
= !!ucontrol
->value
.integer
.value
[0];
561 if (spec
->vt1708_jack_detect
== val
)
563 spec
->vt1708_jack_detect
= val
;
564 vt1708_update_hp_work(codec
);
568 static const struct snd_kcontrol_new vt1708_jack_detect_ctl
[] = {
570 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
571 .name
= "Jack Detect",
573 .info
= snd_ctl_boolean_mono_info
,
574 .get
= vt1708_jack_detect_get
,
575 .put
= vt1708_jack_detect_put
,
580 static void via_hp_automute(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
)
582 set_widgets_power_state(codec
);
583 snd_hda_gen_hp_automute(codec
, tbl
);
586 static void via_line_automute(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
)
588 set_widgets_power_state(codec
);
589 snd_hda_gen_line_automute(codec
, tbl
);
592 static void via_jack_powerstate_event(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
)
594 set_widgets_power_state(codec
);
597 #define VIA_JACK_EVENT (HDA_GEN_LAST_EVENT + 1)
599 static void via_set_jack_unsol_events(struct hda_codec
*codec
)
601 struct via_spec
*spec
= codec
->spec
;
602 struct auto_pin_cfg
*cfg
= &spec
->gen
.autocfg
;
606 spec
->gen
.hp_automute_hook
= via_hp_automute
;
607 if (cfg
->speaker_pins
[0])
608 spec
->gen
.line_automute_hook
= via_line_automute
;
610 for (i
= 0; i
< cfg
->line_outs
; i
++) {
611 pin
= cfg
->line_out_pins
[i
];
612 if (pin
&& !snd_hda_jack_tbl_get(codec
, pin
) &&
613 is_jack_detectable(codec
, pin
))
614 snd_hda_jack_detect_enable_callback(codec
, pin
,
616 via_jack_powerstate_event
);
619 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
620 pin
= cfg
->line_out_pins
[i
];
621 if (pin
&& !snd_hda_jack_tbl_get(codec
, pin
) &&
622 is_jack_detectable(codec
, pin
))
623 snd_hda_jack_detect_enable_callback(codec
, pin
,
625 via_jack_powerstate_event
);
629 static const struct badness_table via_main_out_badness
= {
630 .no_primary_dac
= 0x10000,
632 .shared_primary
= 0x10000,
635 .shared_surr_main
= 0x20,
637 static const struct badness_table via_extra_out_badness
= {
638 .no_primary_dac
= 0x4000,
640 .shared_primary
= 0x12,
643 .shared_surr_main
= 0x10,
646 static int via_parse_auto_config(struct hda_codec
*codec
)
648 struct via_spec
*spec
= codec
->spec
;
651 spec
->gen
.main_out_badness
= &via_main_out_badness
;
652 spec
->gen
.extra_out_badness
= &via_extra_out_badness
;
654 err
= snd_hda_parse_pin_defcfg(codec
, &spec
->gen
.autocfg
, NULL
, 0);
658 err
= snd_hda_gen_parse_auto_config(codec
, &spec
->gen
.autocfg
);
662 via_set_jack_unsol_events(codec
);
666 static int via_init(struct hda_codec
*codec
)
668 struct via_spec
*spec
= codec
->spec
;
671 for (i
= 0; i
< spec
->num_iverbs
; i
++)
672 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
674 /* init power states */
675 set_widgets_power_state(codec
);
676 __analog_low_current_mode(codec
, true);
678 snd_hda_gen_init(codec
);
680 vt1708_update_hp_work(codec
);
685 static int vt1708_build_controls(struct hda_codec
*codec
)
687 /* In order not to create "Phantom Jack" controls,
688 temporary enable jackpoll */
690 int old_interval
= codec
->jackpoll_interval
;
691 codec
->jackpoll_interval
= msecs_to_jiffies(100);
692 err
= via_build_controls(codec
);
693 codec
->jackpoll_interval
= old_interval
;
697 static int vt1708_build_pcms(struct hda_codec
*codec
)
699 struct via_spec
*spec
= codec
->spec
;
702 err
= snd_hda_gen_build_pcms(codec
);
703 if (err
< 0 || codec
->vendor_id
!= 0x11061708)
706 /* We got noisy outputs on the right channel on VT1708 when
707 * 24bit samples are used. Until any workaround is found,
708 * disable the 24bit format, so far.
710 for (i
= 0; i
< codec
->num_pcms
; i
++) {
711 struct hda_pcm
*info
= &spec
->gen
.pcm_rec
[i
];
712 if (!info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].substreams
||
713 info
->pcm_type
!= HDA_PCM_TYPE_AUDIO
)
715 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].formats
=
716 SNDRV_PCM_FMTBIT_S16_LE
;
722 static int patch_vt1708(struct hda_codec
*codec
)
724 struct via_spec
*spec
;
727 /* create a codec specific record */
728 spec
= via_new_spec(codec
);
732 spec
->gen
.mixer_nid
= 0x17;
734 /* set jackpoll_interval while parsing the codec */
735 codec
->jackpoll_interval
= msecs_to_jiffies(100);
736 spec
->vt1708_jack_detect
= 1;
738 /* don't support the input jack switching due to lack of unsol event */
739 /* (it may work with polling, though, but it needs testing) */
740 spec
->gen
.suppress_auto_mic
= 1;
742 /* Add HP and CD pin config connect bit re-config action */
743 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
744 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
746 /* automatic parse from the BIOS config */
747 err
= via_parse_auto_config(codec
);
753 /* add jack detect on/off control */
754 spec
->mixers
[spec
->num_mixers
++] = vt1708_jack_detect_ctl
;
756 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_init_verbs
;
758 codec
->patch_ops
= via_patch_ops
;
759 codec
->patch_ops
.build_controls
= vt1708_build_controls
;
760 codec
->patch_ops
.build_pcms
= vt1708_build_pcms
;
762 /* clear jackpoll_interval again; it's set dynamically */
763 codec
->jackpoll_interval
= 0;
768 static int patch_vt1709(struct hda_codec
*codec
)
770 struct via_spec
*spec
;
773 /* create a codec specific record */
774 spec
= via_new_spec(codec
);
778 spec
->gen
.mixer_nid
= 0x18;
780 err
= via_parse_auto_config(codec
);
786 codec
->patch_ops
= via_patch_ops
;
791 static void set_widgets_power_state_vt1708B(struct hda_codec
*codec
)
793 struct via_spec
*spec
= codec
->spec
;
797 if ((spec
->codec_type
!= VT1708B_4CH
) &&
798 (codec
->vendor_id
!= 0x11064397))
801 /* SW0 (17h) = stereo mixer */
803 (snd_hda_codec_read(codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00)
804 == ((spec
->codec_type
== VT1708S
) ? 5 : 0));
806 /* PW 1/2/5 (1ah/1bh/1eh) */
808 set_pin_power_state(codec
, 0x1a, &parm
);
809 set_pin_power_state(codec
, 0x1b, &parm
);
810 set_pin_power_state(codec
, 0x1e, &parm
);
813 /* SW0 (17h), AIW 0/1 (13h/14h) */
814 update_power_state(codec
, 0x17, parm
);
815 update_power_state(codec
, 0x13, parm
);
816 update_power_state(codec
, 0x14, parm
);
819 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
821 set_pin_power_state(codec
, 0x19, &parm
);
822 if (smart51_enabled(codec
))
823 set_pin_power_state(codec
, 0x1b, &parm
);
824 update_power_state(codec
, 0x18, parm
);
825 update_power_state(codec
, 0x11, parm
);
827 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
830 set_pin_power_state(codec
, 0x22, &parm
);
831 if (smart51_enabled(codec
))
832 set_pin_power_state(codec
, 0x1a, &parm
);
833 update_power_state(codec
, 0x26, parm
);
834 update_power_state(codec
, 0x24, parm
);
835 } else if (codec
->vendor_id
== 0x11064397) {
836 /* PW7(23h), SW2(27h), AOW2(25h) */
838 set_pin_power_state(codec
, 0x23, &parm
);
839 if (smart51_enabled(codec
))
840 set_pin_power_state(codec
, 0x1a, &parm
);
841 update_power_state(codec
, 0x27, parm
);
842 update_power_state(codec
, 0x25, parm
);
845 /* PW 3/4/7 (1ch/1dh/23h) */
847 /* force to D0 for internal Speaker */
848 set_pin_power_state(codec
, 0x1c, &parm
);
849 set_pin_power_state(codec
, 0x1d, &parm
);
851 set_pin_power_state(codec
, 0x23, &parm
);
853 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
854 update_power_state(codec
, 0x16, imux_is_smixer
? AC_PWRST_D0
: parm
);
855 update_power_state(codec
, 0x10, parm
);
857 update_power_state(codec
, 0x25, parm
);
858 update_power_state(codec
, 0x27, parm
);
859 } else if (codec
->vendor_id
== 0x11064397 && spec
->gen
.indep_hp_enabled
)
860 update_power_state(codec
, 0x25, parm
);
863 static int patch_vt1708S(struct hda_codec
*codec
);
864 static int patch_vt1708B(struct hda_codec
*codec
)
866 struct via_spec
*spec
;
869 if (get_codec_type(codec
) == VT1708BCE
)
870 return patch_vt1708S(codec
);
872 /* create a codec specific record */
873 spec
= via_new_spec(codec
);
877 spec
->gen
.mixer_nid
= 0x16;
879 /* automatic parse from the BIOS config */
880 err
= via_parse_auto_config(codec
);
886 codec
->patch_ops
= via_patch_ops
;
888 spec
->set_widgets_power_state
= set_widgets_power_state_vt1708B
;
893 /* Patch for VT1708S */
894 static const struct hda_verb vt1708S_init_verbs
[] = {
895 /* Enable Mic Boost Volume backdoor */
897 /* don't bybass mixer */
902 static void override_mic_boost(struct hda_codec
*codec
, hda_nid_t pin
,
903 int offset
, int num_steps
, int step_size
)
905 snd_hda_override_amp_caps(codec
, pin
, HDA_INPUT
,
906 (offset
<< AC_AMPCAP_OFFSET_SHIFT
) |
907 (num_steps
<< AC_AMPCAP_NUM_STEPS_SHIFT
) |
908 (step_size
<< AC_AMPCAP_STEP_SIZE_SHIFT
) |
909 (0 << AC_AMPCAP_MUTE_SHIFT
));
912 static int patch_vt1708S(struct hda_codec
*codec
)
914 struct via_spec
*spec
;
917 /* create a codec specific record */
918 spec
= via_new_spec(codec
);
922 spec
->gen
.mixer_nid
= 0x16;
923 override_mic_boost(codec
, 0x1a, 0, 3, 40);
924 override_mic_boost(codec
, 0x1e, 0, 3, 40);
926 /* correct names for VT1708BCE */
927 if (get_codec_type(codec
) == VT1708BCE
) {
928 kfree(codec
->chip_name
);
929 codec
->chip_name
= kstrdup("VT1708BCE", GFP_KERNEL
);
930 snprintf(codec
->bus
->card
->mixername
,
931 sizeof(codec
->bus
->card
->mixername
),
932 "%s %s", codec
->vendor_name
, codec
->chip_name
);
934 /* correct names for VT1705 */
935 if (codec
->vendor_id
== 0x11064397) {
936 kfree(codec
->chip_name
);
937 codec
->chip_name
= kstrdup("VT1705", GFP_KERNEL
);
938 snprintf(codec
->bus
->card
->mixername
,
939 sizeof(codec
->bus
->card
->mixername
),
940 "%s %s", codec
->vendor_name
, codec
->chip_name
);
943 /* automatic parse from the BIOS config */
944 err
= via_parse_auto_config(codec
);
950 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_init_verbs
;
952 codec
->patch_ops
= via_patch_ops
;
954 spec
->set_widgets_power_state
= set_widgets_power_state_vt1708B
;
958 /* Patch for VT1702 */
960 static const struct hda_verb vt1702_init_verbs
[] = {
968 static void set_widgets_power_state_vt1702(struct hda_codec
*codec
)
971 snd_hda_codec_read(codec
, 0x13, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
974 /* PW 1/2/5 (14h/15h/18h) */
976 set_pin_power_state(codec
, 0x14, &parm
);
977 set_pin_power_state(codec
, 0x15, &parm
);
978 set_pin_power_state(codec
, 0x18, &parm
);
980 parm
= AC_PWRST_D0
; /* SW0 (13h) = stereo mixer (idx 3) */
981 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
982 update_power_state(codec
, 0x13, parm
);
983 update_power_state(codec
, 0x12, parm
);
984 update_power_state(codec
, 0x1f, parm
);
985 update_power_state(codec
, 0x20, parm
);
988 /* PW 3/4 (16h/17h) */
990 set_pin_power_state(codec
, 0x17, &parm
);
991 set_pin_power_state(codec
, 0x16, &parm
);
992 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
993 update_power_state(codec
, 0x1a, imux_is_smixer
? AC_PWRST_D0
: parm
);
994 update_power_state(codec
, 0x10, parm
);
995 update_power_state(codec
, 0x1d, parm
);
998 static int patch_vt1702(struct hda_codec
*codec
)
1000 struct via_spec
*spec
;
1003 /* create a codec specific record */
1004 spec
= via_new_spec(codec
);
1008 spec
->gen
.mixer_nid
= 0x1a;
1010 /* limit AA path volume to 0 dB */
1011 snd_hda_override_amp_caps(codec
, 0x1A, HDA_INPUT
,
1012 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
1013 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
1014 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
1015 (1 << AC_AMPCAP_MUTE_SHIFT
));
1017 /* automatic parse from the BIOS config */
1018 err
= via_parse_auto_config(codec
);
1024 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_init_verbs
;
1026 codec
->patch_ops
= via_patch_ops
;
1028 spec
->set_widgets_power_state
= set_widgets_power_state_vt1702
;
1032 /* Patch for VT1718S */
1034 static const struct hda_verb vt1718S_init_verbs
[] = {
1035 /* Enable MW0 adjust Gain 5 */
1037 /* Enable Boost Volume backdoor */
1043 static void set_widgets_power_state_vt1718S(struct hda_codec
*codec
)
1045 struct via_spec
*spec
= codec
->spec
;
1047 unsigned int parm
, parm2
;
1048 /* MUX6 (1eh) = stereo mixer */
1050 snd_hda_codec_read(codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
1052 /* PW 5/6/7 (29h/2ah/2bh) */
1054 set_pin_power_state(codec
, 0x29, &parm
);
1055 set_pin_power_state(codec
, 0x2a, &parm
);
1056 set_pin_power_state(codec
, 0x2b, &parm
);
1059 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
1060 update_power_state(codec
, 0x1e, parm
);
1061 update_power_state(codec
, 0x1f, parm
);
1062 update_power_state(codec
, 0x10, parm
);
1063 update_power_state(codec
, 0x11, parm
);
1066 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
1068 set_pin_power_state(codec
, 0x27, &parm
);
1069 update_power_state(codec
, 0x1a, parm
);
1070 parm2
= parm
; /* for pin 0x0b */
1072 /* PW2 (26h), AOW2 (ah) */
1074 set_pin_power_state(codec
, 0x26, &parm
);
1075 if (smart51_enabled(codec
))
1076 set_pin_power_state(codec
, 0x2b, &parm
);
1077 update_power_state(codec
, 0xa, parm
);
1079 /* PW0 (24h), AOW0 (8h) */
1081 set_pin_power_state(codec
, 0x24, &parm
);
1082 if (!spec
->gen
.indep_hp_enabled
) /* check for redirected HP */
1083 set_pin_power_state(codec
, 0x28, &parm
);
1084 update_power_state(codec
, 0x8, parm
);
1085 if (!spec
->gen
.indep_hp_enabled
&& parm2
!= AC_PWRST_D3
)
1087 update_power_state(codec
, 0xb, parm
);
1088 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1089 update_power_state(codec
, 0x21, imux_is_smixer
? AC_PWRST_D0
: parm
);
1091 /* PW1 (25h), AOW1 (9h) */
1093 set_pin_power_state(codec
, 0x25, &parm
);
1094 if (smart51_enabled(codec
))
1095 set_pin_power_state(codec
, 0x2a, &parm
);
1096 update_power_state(codec
, 0x9, parm
);
1098 if (spec
->gen
.indep_hp_enabled
) {
1099 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
1101 set_pin_power_state(codec
, 0x28, &parm
);
1102 update_power_state(codec
, 0x1b, parm
);
1103 update_power_state(codec
, 0x34, parm
);
1104 update_power_state(codec
, 0xc, parm
);
1108 /* Add a connection to the primary DAC from AA-mixer for some codecs
1109 * This isn't listed from the raw info, but the chip has a secret connection.
1111 static int add_secret_dac_path(struct hda_codec
*codec
)
1113 struct via_spec
*spec
= codec
->spec
;
1118 if (!spec
->gen
.mixer_nid
)
1120 nums
= snd_hda_get_connections(codec
, spec
->gen
.mixer_nid
, conn
,
1121 ARRAY_SIZE(conn
) - 1);
1122 for (i
= 0; i
< nums
; i
++) {
1123 if (get_wcaps_type(get_wcaps(codec
, conn
[i
])) == AC_WID_AUD_OUT
)
1127 /* find the primary DAC and add to the connection list */
1128 nid
= codec
->start_nid
;
1129 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
1130 unsigned int caps
= get_wcaps(codec
, nid
);
1131 if (get_wcaps_type(caps
) == AC_WID_AUD_OUT
&&
1132 !(caps
& AC_WCAP_DIGITAL
)) {
1134 return snd_hda_override_conn_list(codec
,
1135 spec
->gen
.mixer_nid
,
1143 static int patch_vt1718S(struct hda_codec
*codec
)
1145 struct via_spec
*spec
;
1148 /* create a codec specific record */
1149 spec
= via_new_spec(codec
);
1153 spec
->gen
.mixer_nid
= 0x21;
1154 override_mic_boost(codec
, 0x2b, 0, 3, 40);
1155 override_mic_boost(codec
, 0x29, 0, 3, 40);
1156 add_secret_dac_path(codec
);
1158 /* automatic parse from the BIOS config */
1159 err
= via_parse_auto_config(codec
);
1165 spec
->init_verbs
[spec
->num_iverbs
++] = vt1718S_init_verbs
;
1167 codec
->patch_ops
= via_patch_ops
;
1169 spec
->set_widgets_power_state
= set_widgets_power_state_vt1718S
;
1174 /* Patch for VT1716S */
1176 static int vt1716s_dmic_info(struct snd_kcontrol
*kcontrol
,
1177 struct snd_ctl_elem_info
*uinfo
)
1179 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1181 uinfo
->value
.integer
.min
= 0;
1182 uinfo
->value
.integer
.max
= 1;
1186 static int vt1716s_dmic_get(struct snd_kcontrol
*kcontrol
,
1187 struct snd_ctl_elem_value
*ucontrol
)
1189 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1192 index
= snd_hda_codec_read(codec
, 0x26, 0,
1193 AC_VERB_GET_CONNECT_SEL
, 0);
1195 *ucontrol
->value
.integer
.value
= index
;
1200 static int vt1716s_dmic_put(struct snd_kcontrol
*kcontrol
,
1201 struct snd_ctl_elem_value
*ucontrol
)
1203 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1204 struct via_spec
*spec
= codec
->spec
;
1205 int index
= *ucontrol
->value
.integer
.value
;
1207 snd_hda_codec_write(codec
, 0x26, 0,
1208 AC_VERB_SET_CONNECT_SEL
, index
);
1209 spec
->dmic_enabled
= index
;
1210 set_widgets_power_state(codec
);
1214 static const struct snd_kcontrol_new vt1716s_dmic_mixer
[] = {
1215 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT
),
1217 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1218 .name
= "Digital Mic Capture Switch",
1219 .subdevice
= HDA_SUBDEV_NID_FLAG
| 0x26,
1221 .info
= vt1716s_dmic_info
,
1222 .get
= vt1716s_dmic_get
,
1223 .put
= vt1716s_dmic_put
,
1229 /* mono-out mixer elements */
1230 static const struct snd_kcontrol_new vt1716S_mono_out_mixer
[] = {
1231 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT
),
1235 static const struct hda_verb vt1716S_init_verbs
[] = {
1236 /* Enable Boost Volume backdoor */
1238 /* don't bybass mixer */
1240 /* Enable mono output */
1245 static void set_widgets_power_state_vt1716S(struct hda_codec
*codec
)
1247 struct via_spec
*spec
= codec
->spec
;
1250 unsigned int mono_out
, present
;
1251 /* SW0 (17h) = stereo mixer */
1253 (snd_hda_codec_read(codec
, 0x17, 0,
1254 AC_VERB_GET_CONNECT_SEL
, 0x00) == 5);
1256 /* PW 1/2/5 (1ah/1bh/1eh) */
1258 set_pin_power_state(codec
, 0x1a, &parm
);
1259 set_pin_power_state(codec
, 0x1b, &parm
);
1260 set_pin_power_state(codec
, 0x1e, &parm
);
1263 /* SW0 (17h), AIW0(13h) */
1264 update_power_state(codec
, 0x17, parm
);
1265 update_power_state(codec
, 0x13, parm
);
1268 set_pin_power_state(codec
, 0x1e, &parm
);
1270 if (spec
->dmic_enabled
)
1271 set_pin_power_state(codec
, 0x22, &parm
);
1273 update_power_state(codec
, 0x22, AC_PWRST_D3
);
1275 /* SW2(26h), AIW1(14h) */
1276 update_power_state(codec
, 0x26, parm
);
1277 update_power_state(codec
, 0x14, parm
);
1280 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
1282 set_pin_power_state(codec
, 0x19, &parm
);
1283 /* Smart 5.1 PW2(1bh) */
1284 if (smart51_enabled(codec
))
1285 set_pin_power_state(codec
, 0x1b, &parm
);
1286 update_power_state(codec
, 0x18, parm
);
1287 update_power_state(codec
, 0x11, parm
);
1289 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
1291 set_pin_power_state(codec
, 0x23, &parm
);
1292 /* Smart 5.1 PW1(1ah) */
1293 if (smart51_enabled(codec
))
1294 set_pin_power_state(codec
, 0x1a, &parm
);
1295 update_power_state(codec
, 0x27, parm
);
1297 /* Smart 5.1 PW5(1eh) */
1298 if (smart51_enabled(codec
))
1299 set_pin_power_state(codec
, 0x1e, &parm
);
1300 update_power_state(codec
, 0x25, parm
);
1303 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
1304 present
= snd_hda_jack_detect(codec
, 0x1c);
1309 present
= snd_hda_jack_detect(codec
, 0x1d);
1310 if (!spec
->gen
.indep_hp_enabled
&& present
)
1315 parm
= mono_out
? AC_PWRST_D0
: AC_PWRST_D3
;
1316 update_power_state(codec
, 0x28, parm
);
1317 update_power_state(codec
, 0x29, parm
);
1318 update_power_state(codec
, 0x2a, parm
);
1320 /* PW 3/4 (1ch/1dh) */
1322 set_pin_power_state(codec
, 0x1c, &parm
);
1323 set_pin_power_state(codec
, 0x1d, &parm
);
1324 /* HP Independent Mode, power on AOW3 */
1325 if (spec
->gen
.indep_hp_enabled
)
1326 update_power_state(codec
, 0x25, parm
);
1328 /* force to D0 for internal Speaker */
1329 /* MW0 (16h), AOW0 (10h) */
1330 update_power_state(codec
, 0x16, imux_is_smixer
? AC_PWRST_D0
: parm
);
1331 update_power_state(codec
, 0x10, mono_out
? AC_PWRST_D0
: parm
);
1334 static int patch_vt1716S(struct hda_codec
*codec
)
1336 struct via_spec
*spec
;
1339 /* create a codec specific record */
1340 spec
= via_new_spec(codec
);
1344 spec
->gen
.mixer_nid
= 0x16;
1345 override_mic_boost(codec
, 0x1a, 0, 3, 40);
1346 override_mic_boost(codec
, 0x1e, 0, 3, 40);
1348 /* automatic parse from the BIOS config */
1349 err
= via_parse_auto_config(codec
);
1355 spec
->init_verbs
[spec
->num_iverbs
++] = vt1716S_init_verbs
;
1357 spec
->mixers
[spec
->num_mixers
++] = vt1716s_dmic_mixer
;
1358 spec
->mixers
[spec
->num_mixers
++] = vt1716S_mono_out_mixer
;
1360 codec
->patch_ops
= via_patch_ops
;
1362 spec
->set_widgets_power_state
= set_widgets_power_state_vt1716S
;
1368 static const struct hda_verb vt2002P_init_verbs
[] = {
1369 /* Class-D speaker related verbs */
1373 /* Enable Boost Volume backdoor */
1375 /* Enable AOW0 to MW9 */
1380 static const struct hda_verb vt1802_init_verbs
[] = {
1381 /* Enable Boost Volume backdoor */
1383 /* Enable AOW0 to MW9 */
1388 static void set_widgets_power_state_vt2002P(struct hda_codec
*codec
)
1390 struct via_spec
*spec
= codec
->spec
;
1393 unsigned int present
;
1394 /* MUX9 (1eh) = stereo mixer */
1396 snd_hda_codec_read(codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
1398 /* PW 5/6/7 (29h/2ah/2bh) */
1400 set_pin_power_state(codec
, 0x29, &parm
);
1401 set_pin_power_state(codec
, 0x2a, &parm
);
1402 set_pin_power_state(codec
, 0x2b, &parm
);
1404 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
1405 update_power_state(codec
, 0x1e, parm
);
1406 update_power_state(codec
, 0x1f, parm
);
1407 update_power_state(codec
, 0x10, parm
);
1408 update_power_state(codec
, 0x11, parm
);
1412 update_power_state(codec
, 0x8, parm
);
1414 if (spec
->codec_type
== VT1802
) {
1415 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1417 set_pin_power_state(codec
, 0x28, &parm
);
1418 update_power_state(codec
, 0x18, parm
);
1419 update_power_state(codec
, 0x38, parm
);
1421 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
1423 set_pin_power_state(codec
, 0x26, &parm
);
1424 update_power_state(codec
, 0x1c, parm
);
1425 update_power_state(codec
, 0x37, parm
);
1428 if (spec
->codec_type
== VT1802
) {
1429 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1431 set_pin_power_state(codec
, 0x25, &parm
);
1432 update_power_state(codec
, 0x15, parm
);
1433 update_power_state(codec
, 0x35, parm
);
1435 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
1437 set_pin_power_state(codec
, 0x25, &parm
);
1438 update_power_state(codec
, 0x19, parm
);
1439 update_power_state(codec
, 0x35, parm
);
1442 if (spec
->gen
.indep_hp_enabled
)
1443 update_power_state(codec
, 0x9, AC_PWRST_D0
);
1446 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
1447 present
= snd_hda_jack_detect(codec
, 0x25);
1450 set_pin_power_state(codec
, 0x24, &parm
);
1451 parm
= present
? AC_PWRST_D3
: AC_PWRST_D0
;
1452 if (spec
->codec_type
== VT1802
)
1453 update_power_state(codec
, 0x14, parm
);
1455 update_power_state(codec
, 0x18, parm
);
1456 update_power_state(codec
, 0x34, parm
);
1459 present
= snd_hda_jack_detect(codec
, 0x26);
1461 parm
= present
? AC_PWRST_D3
: AC_PWRST_D0
;
1462 if (spec
->codec_type
== VT1802
) {
1463 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
1464 update_power_state(codec
, 0x33, parm
);
1465 update_power_state(codec
, 0x1c, parm
);
1466 update_power_state(codec
, 0x3c, parm
);
1468 /* PW15 (31h), MW8(17h), MUX8(3bh) */
1469 update_power_state(codec
, 0x31, parm
);
1470 update_power_state(codec
, 0x17, parm
);
1471 update_power_state(codec
, 0x3b, parm
);
1474 if (imux_is_smixer
|| !is_aa_path_mute(codec
))
1475 update_power_state(codec
, 0x21, AC_PWRST_D0
);
1477 update_power_state(codec
, 0x21, AC_PWRST_D3
);
1484 VIA_FIXUP_INTMIC_BOOST
,
1488 static void via_fixup_intmic_boost(struct hda_codec
*codec
,
1489 const struct hda_fixup
*fix
, int action
)
1491 if (action
== HDA_FIXUP_ACT_PRE_PROBE
)
1492 override_mic_boost(codec
, 0x30, 0, 2, 40);
1495 static const struct hda_fixup via_fixups
[] = {
1496 [VIA_FIXUP_INTMIC_BOOST
] = {
1497 .type
= HDA_FIXUP_FUNC
,
1498 .v
.func
= via_fixup_intmic_boost
,
1500 [VIA_FIXUP_ASUS_G75
] = {
1501 .type
= HDA_FIXUP_PINS
,
1502 .v
.pins
= (const struct hda_pintbl
[]) {
1503 /* set 0x24 and 0x33 as speakers */
1504 { 0x24, 0x991301f0 },
1505 { 0x33, 0x991301f1 }, /* subwoofer */
1511 static const struct snd_pci_quirk vt2002p_fixups
[] = {
1512 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75
),
1513 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST
),
1517 /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
1518 * Replace this with mixer NID 0x1c
1520 static void fix_vt1802_connections(struct hda_codec
*codec
)
1522 static hda_nid_t conn_24
[] = { 0x14, 0x1c };
1523 static hda_nid_t conn_33
[] = { 0x1c };
1525 snd_hda_override_conn_list(codec
, 0x24, ARRAY_SIZE(conn_24
), conn_24
);
1526 snd_hda_override_conn_list(codec
, 0x33, ARRAY_SIZE(conn_33
), conn_33
);
1529 /* patch for vt2002P */
1530 static int patch_vt2002P(struct hda_codec
*codec
)
1532 struct via_spec
*spec
;
1535 /* create a codec specific record */
1536 spec
= via_new_spec(codec
);
1540 spec
->gen
.mixer_nid
= 0x21;
1541 override_mic_boost(codec
, 0x2b, 0, 3, 40);
1542 override_mic_boost(codec
, 0x29, 0, 3, 40);
1543 if (spec
->codec_type
== VT1802
)
1544 fix_vt1802_connections(codec
);
1545 add_secret_dac_path(codec
);
1547 snd_hda_pick_fixup(codec
, NULL
, vt2002p_fixups
, via_fixups
);
1548 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
1550 /* automatic parse from the BIOS config */
1551 err
= via_parse_auto_config(codec
);
1557 if (spec
->codec_type
== VT1802
)
1558 spec
->init_verbs
[spec
->num_iverbs
++] = vt1802_init_verbs
;
1560 spec
->init_verbs
[spec
->num_iverbs
++] = vt2002P_init_verbs
;
1562 codec
->patch_ops
= via_patch_ops
;
1564 spec
->set_widgets_power_state
= set_widgets_power_state_vt2002P
;
1570 static const struct hda_verb vt1812_init_verbs
[] = {
1571 /* Enable Boost Volume backdoor */
1573 /* Enable AOW0 to MW9 */
1578 static void set_widgets_power_state_vt1812(struct hda_codec
*codec
)
1580 struct via_spec
*spec
= codec
->spec
;
1582 unsigned int present
;
1584 /* PW 5/6/7 (29h/2ah/2bh) */
1586 set_pin_power_state(codec
, 0x29, &parm
);
1587 set_pin_power_state(codec
, 0x2a, &parm
);
1588 set_pin_power_state(codec
, 0x2b, &parm
);
1590 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1591 update_power_state(codec
, 0x1e, parm
);
1592 update_power_state(codec
, 0x1f, parm
);
1593 update_power_state(codec
, 0x10, parm
);
1594 update_power_state(codec
, 0x11, parm
);
1598 update_power_state(codec
, 0x8, AC_PWRST_D0
);
1600 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1602 set_pin_power_state(codec
, 0x28, &parm
);
1603 update_power_state(codec
, 0x18, parm
);
1604 update_power_state(codec
, 0x38, parm
);
1606 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1608 set_pin_power_state(codec
, 0x25, &parm
);
1609 update_power_state(codec
, 0x15, parm
);
1610 update_power_state(codec
, 0x35, parm
);
1611 if (spec
->gen
.indep_hp_enabled
)
1612 update_power_state(codec
, 0x9, AC_PWRST_D0
);
1614 /* Internal Speaker */
1615 /* PW0 (24h), MW0(14h), MUX0(34h) */
1616 present
= snd_hda_jack_detect(codec
, 0x25);
1619 set_pin_power_state(codec
, 0x24, &parm
);
1621 update_power_state(codec
, 0x14, AC_PWRST_D3
);
1622 update_power_state(codec
, 0x34, AC_PWRST_D3
);
1624 update_power_state(codec
, 0x14, AC_PWRST_D0
);
1625 update_power_state(codec
, 0x34, AC_PWRST_D0
);
1630 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1631 present
= snd_hda_jack_detect(codec
, 0x28);
1634 set_pin_power_state(codec
, 0x31, &parm
);
1636 update_power_state(codec
, 0x1c, AC_PWRST_D3
);
1637 update_power_state(codec
, 0x3c, AC_PWRST_D3
);
1638 update_power_state(codec
, 0x3e, AC_PWRST_D3
);
1640 update_power_state(codec
, 0x1c, AC_PWRST_D0
);
1641 update_power_state(codec
, 0x3c, AC_PWRST_D0
);
1642 update_power_state(codec
, 0x3e, AC_PWRST_D0
);
1645 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1647 set_pin_power_state(codec
, 0x33, &parm
);
1648 update_power_state(codec
, 0x1d, parm
);
1649 update_power_state(codec
, 0x3d, parm
);
1653 /* patch for vt1812 */
1654 static int patch_vt1812(struct hda_codec
*codec
)
1656 struct via_spec
*spec
;
1659 /* create a codec specific record */
1660 spec
= via_new_spec(codec
);
1664 spec
->gen
.mixer_nid
= 0x21;
1665 override_mic_boost(codec
, 0x2b, 0, 3, 40);
1666 override_mic_boost(codec
, 0x29, 0, 3, 40);
1667 add_secret_dac_path(codec
);
1669 /* automatic parse from the BIOS config */
1670 err
= via_parse_auto_config(codec
);
1676 spec
->init_verbs
[spec
->num_iverbs
++] = vt1812_init_verbs
;
1678 codec
->patch_ops
= via_patch_ops
;
1680 spec
->set_widgets_power_state
= set_widgets_power_state_vt1812
;
1684 /* patch for vt3476 */
1686 static const struct hda_verb vt3476_init_verbs
[] = {
1687 /* Enable DMic 8/16/32K */
1689 /* Enable Boost Volume backdoor */
1691 /* Enable AOW-MW9 path */
1696 static void set_widgets_power_state_vt3476(struct hda_codec
*codec
)
1698 struct via_spec
*spec
= codec
->spec
;
1700 unsigned int parm
, parm2
;
1701 /* MUX10 (1eh) = stereo mixer */
1703 snd_hda_codec_read(codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 4;
1705 /* PW 5/6/7 (29h/2ah/2bh) */
1707 set_pin_power_state(codec
, 0x29, &parm
);
1708 set_pin_power_state(codec
, 0x2a, &parm
);
1709 set_pin_power_state(codec
, 0x2b, &parm
);
1712 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1713 update_power_state(codec
, 0x1e, parm
);
1714 update_power_state(codec
, 0x1f, parm
);
1715 update_power_state(codec
, 0x10, parm
);
1716 update_power_state(codec
, 0x11, parm
);
1719 /* PW3 (27h), MW3(37h), AOW3 (bh) */
1720 if (spec
->codec_type
== VT1705CF
) {
1722 update_power_state(codec
, 0x27, parm
);
1723 update_power_state(codec
, 0x37, parm
);
1726 set_pin_power_state(codec
, 0x27, &parm
);
1727 update_power_state(codec
, 0x37, parm
);
1730 /* PW2 (26h), MW2(36h), AOW2 (ah) */
1732 set_pin_power_state(codec
, 0x26, &parm
);
1733 update_power_state(codec
, 0x36, parm
);
1734 if (smart51_enabled(codec
)) {
1735 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
1736 set_pin_power_state(codec
, 0x2b, &parm
);
1737 update_power_state(codec
, 0x3b, parm
);
1738 update_power_state(codec
, 0x1b, parm
);
1740 update_conv_power_state(codec
, 0xa, parm
, 2);
1742 /* PW1 (25h), MW1(35h), AOW1 (9h) */
1744 set_pin_power_state(codec
, 0x25, &parm
);
1745 update_power_state(codec
, 0x35, parm
);
1746 if (smart51_enabled(codec
)) {
1747 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
1748 set_pin_power_state(codec
, 0x2a, &parm
);
1749 update_power_state(codec
, 0x3a, parm
);
1750 update_power_state(codec
, 0x1a, parm
);
1752 update_conv_power_state(codec
, 0x9, parm
, 1);
1754 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
1756 set_pin_power_state(codec
, 0x28, &parm
);
1757 update_power_state(codec
, 0x38, parm
);
1758 update_power_state(codec
, 0x18, parm
);
1759 if (spec
->gen
.indep_hp_enabled
)
1760 update_conv_power_state(codec
, 0xb, parm
, 3);
1761 parm2
= parm
; /* for pin 0x0b */
1763 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
1765 set_pin_power_state(codec
, 0x24, &parm
);
1766 update_power_state(codec
, 0x34, parm
);
1767 if (!spec
->gen
.indep_hp_enabled
&& parm2
!= AC_PWRST_D3
)
1769 update_conv_power_state(codec
, 0x8, parm
, 0);
1770 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1771 update_power_state(codec
, 0x3f, imux_is_smixer
? AC_PWRST_D0
: parm
);
1774 static int patch_vt3476(struct hda_codec
*codec
)
1776 struct via_spec
*spec
;
1779 /* create a codec specific record */
1780 spec
= via_new_spec(codec
);
1784 spec
->gen
.mixer_nid
= 0x3f;
1785 add_secret_dac_path(codec
);
1787 /* automatic parse from the BIOS config */
1788 err
= via_parse_auto_config(codec
);
1794 spec
->init_verbs
[spec
->num_iverbs
++] = vt3476_init_verbs
;
1796 codec
->patch_ops
= via_patch_ops
;
1798 spec
->set_widgets_power_state
= set_widgets_power_state_vt3476
;
1806 static const struct hda_codec_preset snd_hda_preset_via
[] = {
1807 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
1808 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
1809 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
1810 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
1811 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
1812 .patch
= patch_vt1709
},
1813 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
1814 .patch
= patch_vt1709
},
1815 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
1816 .patch
= patch_vt1709
},
1817 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
1818 .patch
= patch_vt1709
},
1819 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
1820 .patch
= patch_vt1709
},
1821 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
1822 .patch
= patch_vt1709
},
1823 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
1824 .patch
= patch_vt1709
},
1825 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
1826 .patch
= patch_vt1709
},
1827 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
1828 .patch
= patch_vt1708B
},
1829 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
1830 .patch
= patch_vt1708B
},
1831 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
1832 .patch
= patch_vt1708B
},
1833 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
1834 .patch
= patch_vt1708B
},
1835 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
1836 .patch
= patch_vt1708B
},
1837 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
1838 .patch
= patch_vt1708B
},
1839 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
1840 .patch
= patch_vt1708B
},
1841 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
1842 .patch
= patch_vt1708B
},
1843 { .id
= 0x11060397, .name
= "VT1708S",
1844 .patch
= patch_vt1708S
},
1845 { .id
= 0x11061397, .name
= "VT1708S",
1846 .patch
= patch_vt1708S
},
1847 { .id
= 0x11062397, .name
= "VT1708S",
1848 .patch
= patch_vt1708S
},
1849 { .id
= 0x11063397, .name
= "VT1708S",
1850 .patch
= patch_vt1708S
},
1851 { .id
= 0x11064397, .name
= "VT1705",
1852 .patch
= patch_vt1708S
},
1853 { .id
= 0x11065397, .name
= "VT1708S",
1854 .patch
= patch_vt1708S
},
1855 { .id
= 0x11066397, .name
= "VT1708S",
1856 .patch
= patch_vt1708S
},
1857 { .id
= 0x11067397, .name
= "VT1708S",
1858 .patch
= patch_vt1708S
},
1859 { .id
= 0x11060398, .name
= "VT1702",
1860 .patch
= patch_vt1702
},
1861 { .id
= 0x11061398, .name
= "VT1702",
1862 .patch
= patch_vt1702
},
1863 { .id
= 0x11062398, .name
= "VT1702",
1864 .patch
= patch_vt1702
},
1865 { .id
= 0x11063398, .name
= "VT1702",
1866 .patch
= patch_vt1702
},
1867 { .id
= 0x11064398, .name
= "VT1702",
1868 .patch
= patch_vt1702
},
1869 { .id
= 0x11065398, .name
= "VT1702",
1870 .patch
= patch_vt1702
},
1871 { .id
= 0x11066398, .name
= "VT1702",
1872 .patch
= patch_vt1702
},
1873 { .id
= 0x11067398, .name
= "VT1702",
1874 .patch
= patch_vt1702
},
1875 { .id
= 0x11060428, .name
= "VT1718S",
1876 .patch
= patch_vt1718S
},
1877 { .id
= 0x11064428, .name
= "VT1718S",
1878 .patch
= patch_vt1718S
},
1879 { .id
= 0x11060441, .name
= "VT2020",
1880 .patch
= patch_vt1718S
},
1881 { .id
= 0x11064441, .name
= "VT1828S",
1882 .patch
= patch_vt1718S
},
1883 { .id
= 0x11060433, .name
= "VT1716S",
1884 .patch
= patch_vt1716S
},
1885 { .id
= 0x1106a721, .name
= "VT1716S",
1886 .patch
= patch_vt1716S
},
1887 { .id
= 0x11060438, .name
= "VT2002P", .patch
= patch_vt2002P
},
1888 { .id
= 0x11064438, .name
= "VT2002P", .patch
= patch_vt2002P
},
1889 { .id
= 0x11060448, .name
= "VT1812", .patch
= patch_vt1812
},
1890 { .id
= 0x11060440, .name
= "VT1818S",
1891 .patch
= patch_vt1708S
},
1892 { .id
= 0x11060446, .name
= "VT1802",
1893 .patch
= patch_vt2002P
},
1894 { .id
= 0x11068446, .name
= "VT1802",
1895 .patch
= patch_vt2002P
},
1896 { .id
= 0x11064760, .name
= "VT1705CF",
1897 .patch
= patch_vt3476
},
1898 { .id
= 0x11064761, .name
= "VT1708SCE",
1899 .patch
= patch_vt3476
},
1900 { .id
= 0x11064762, .name
= "VT1808",
1901 .patch
= patch_vt3476
},
1905 MODULE_ALIAS("snd-hda-codec-id:1106*");
1907 static struct hda_codec_preset_list via_list
= {
1908 .preset
= snd_hda_preset_via
,
1909 .owner
= THIS_MODULE
,
1912 MODULE_LICENSE("GPL");
1913 MODULE_DESCRIPTION("VIA HD-audio codec");
1915 static int __init
patch_via_init(void)
1917 return snd_hda_add_codec_preset(&via_list
);
1920 static void __exit
patch_via_exit(void)
1922 snd_hda_delete_codec_preset(&via_list
);
1925 module_init(patch_via_init
)
1926 module_exit(patch_via_exit
)