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"
61 #define VT1708_HP_PIN_NID 0x20
62 #define VT1708_CD_PIN_NID 0x24
84 #define VT2002P_COMPATIBLE(spec) \
85 ((spec)->codec_type == VT2002P ||\
86 (spec)->codec_type == VT1812 ||\
87 (spec)->codec_type == VT1802)
89 #define MAX_NID_PATH_DEPTH 5
91 /* output-path: DAC -> ... -> pin
92 * idx[] contains the source index number of the next widget;
93 * e.g. idx[0] is the index of the DAC selected by path[1] widget
94 * multi[] indicates whether it's a selector widget with multi-connectors
95 * (i.e. the connection selection is mandatory)
96 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
100 hda_nid_t path
[MAX_NID_PATH_DEPTH
];
101 unsigned char idx
[MAX_NID_PATH_DEPTH
];
102 unsigned char multi
[MAX_NID_PATH_DEPTH
];
103 unsigned int vol_ctl
;
104 unsigned int mute_ctl
;
109 hda_nid_t pin
; /* input-pin or aa-mix */
110 int adc_idx
; /* ADC index to be used */
111 int mux_idx
; /* MUX index (if any) */
112 const char *label
; /* input-source label */
115 #define VIA_MAX_ADCS 3
118 STREAM_MULTI_OUT
= (1 << 0),
119 STREAM_INDEP_HP
= (1 << 1),
123 struct hda_gen_spec gen
;
125 /* codec parameterization */
126 const struct snd_kcontrol_new
*mixers
[6];
127 unsigned int num_mixers
;
129 const struct hda_verb
*init_verbs
[5];
130 unsigned int num_iverbs
;
132 char stream_name_analog
[32];
133 char stream_name_hp
[32];
134 const struct hda_pcm_stream
*stream_analog_playback
;
135 const struct hda_pcm_stream
*stream_analog_capture
;
137 char stream_name_digital
[32];
138 const struct hda_pcm_stream
*stream_digital_playback
;
139 const struct hda_pcm_stream
*stream_digital_capture
;
142 struct hda_multi_out multiout
;
143 hda_nid_t slave_dig_outs
[2];
144 hda_nid_t hp_dac_nid
;
145 hda_nid_t speaker_dac_nid
;
146 int hp_indep_shared
; /* indep HP-DAC is shared with side ch */
147 int opened_streams
; /* STREAM_* bits */
148 int active_streams
; /* STREAM_* bits */
149 int aamix_mode
; /* loopback is enabled for output-path? */
152 * There are different output-paths depending on the setup.
153 * out_path, hp_path and speaker_path are primary paths. If both
154 * direct DAC and aa-loopback routes are available, these contain
155 * the former paths. Meanwhile *_mix_path contain the paths with
156 * loopback mixer. (Since the loopback is only for front channel,
157 * no out_mix_path for surround channels.)
158 * The HP output has another path, hp_indep_path, which is used in
159 * the independent-HP mode.
161 struct nid_path out_path
[HDA_SIDE
+ 1];
162 struct nid_path out_mix_path
;
163 struct nid_path hp_path
;
164 struct nid_path hp_mix_path
;
165 struct nid_path hp_indep_path
;
166 struct nid_path speaker_path
;
167 struct nid_path speaker_mix_path
;
170 unsigned int num_adc_nids
;
171 hda_nid_t adc_nids
[VIA_MAX_ADCS
];
172 hda_nid_t mux_nids
[VIA_MAX_ADCS
];
173 hda_nid_t aa_mix_nid
;
174 hda_nid_t dig_in_nid
;
179 struct via_input inputs
[AUTO_CFG_MAX_INS
+ 1];
180 unsigned int cur_mux
[VIA_MAX_ADCS
];
182 /* dynamic DAC switching */
183 unsigned int cur_dac_stream_tag
;
184 unsigned int cur_dac_format
;
185 unsigned int cur_hp_stream_tag
;
186 unsigned int cur_hp_format
;
188 /* dynamic ADC switching */
190 unsigned int cur_adc_stream_tag
;
191 unsigned int cur_adc_format
;
193 /* PCM information */
194 struct hda_pcm pcm_rec
[3];
196 /* dynamic controls, init_verbs and input_mux */
197 struct auto_pin_cfg autocfg
;
198 struct snd_array kctls
;
199 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
202 unsigned int hp_independent_mode
;
203 unsigned int dmic_enabled
;
204 unsigned int no_pin_power_ctl
;
205 enum VIA_HDA_CODEC codec_type
;
207 /* analog low-power control */
211 unsigned int smart51_nums
;
212 hda_nid_t smart51_pins
[2];
214 const char *smart51_labels
[2];
215 unsigned int smart51_enabled
;
217 /* work to check hp jack state */
218 struct hda_codec
*codec
;
219 struct delayed_work vt1708_hp_work
;
221 int vt1708_jack_detect
;
222 int vt1708_hp_present
;
224 void (*set_widgets_power_state
)(struct hda_codec
*codec
);
225 unsigned int dac_stream_tag
[4];
227 struct hda_loopback_check loopback
;
229 struct hda_amp_list loopback_list
[8];
231 /* bind capture-volume */
232 struct hda_bind_ctls
*bind_cap_vol
;
233 struct hda_bind_ctls
*bind_cap_sw
;
235 struct mutex config_mutex
;
238 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
);
239 static struct via_spec
* via_new_spec(struct hda_codec
*codec
)
241 struct via_spec
*spec
;
243 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
247 snd_array_init(&spec
->kctls
, sizeof(struct snd_kcontrol_new
), 32);
248 mutex_init(&spec
->config_mutex
);
251 spec
->codec_type
= get_codec_type(codec
);
252 /* VT1708BCE & VT1708S are almost same */
253 if (spec
->codec_type
== VT1708BCE
)
254 spec
->codec_type
= VT1708S
;
255 snd_hda_gen_init(&spec
->gen
);
259 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
)
261 u32 vendor_id
= codec
->vendor_id
;
262 u16 ven_id
= vendor_id
>> 16;
263 u16 dev_id
= vendor_id
& 0xffff;
264 enum VIA_HDA_CODEC codec_type
;
267 if (ven_id
!= 0x1106)
268 codec_type
= UNKNOWN
;
269 else if (dev_id
>= 0x1708 && dev_id
<= 0x170b)
271 else if (dev_id
>= 0xe710 && dev_id
<= 0xe713)
272 codec_type
= VT1709_10CH
;
273 else if (dev_id
>= 0xe714 && dev_id
<= 0xe717)
274 codec_type
= VT1709_6CH
;
275 else if (dev_id
>= 0xe720 && dev_id
<= 0xe723) {
276 codec_type
= VT1708B_8CH
;
277 if (snd_hda_param_read(codec
, 0x16, AC_PAR_CONNLIST_LEN
) == 0x7)
278 codec_type
= VT1708BCE
;
279 } else if (dev_id
>= 0xe724 && dev_id
<= 0xe727)
280 codec_type
= VT1708B_4CH
;
281 else if ((dev_id
& 0xfff) == 0x397
282 && (dev_id
>> 12) < 8)
283 codec_type
= VT1708S
;
284 else if ((dev_id
& 0xfff) == 0x398
285 && (dev_id
>> 12) < 8)
287 else if ((dev_id
& 0xfff) == 0x428
288 && (dev_id
>> 12) < 8)
289 codec_type
= VT1718S
;
290 else if (dev_id
== 0x0433 || dev_id
== 0xa721)
291 codec_type
= VT1716S
;
292 else if (dev_id
== 0x0441 || dev_id
== 0x4441)
293 codec_type
= VT1718S
;
294 else if (dev_id
== 0x0438 || dev_id
== 0x4438)
295 codec_type
= VT2002P
;
296 else if (dev_id
== 0x0448)
298 else if (dev_id
== 0x0440)
299 codec_type
= VT1708S
;
300 else if ((dev_id
& 0xfff) == 0x446)
302 else if (dev_id
== 0x4760)
303 codec_type
= VT1705CF
;
304 else if (dev_id
== 0x4761 || dev_id
== 0x4762)
307 codec_type
= UNKNOWN
;
311 #define VIA_JACK_EVENT 0x20
312 #define VIA_HP_EVENT 0x01
313 #define VIA_LINE_EVENT 0x03
318 VIA_CTL_WIDGET_ANALOG_MUTE
,
321 static void analog_low_current_mode(struct hda_codec
*codec
);
322 static bool is_aa_path_mute(struct hda_codec
*codec
);
324 #define hp_detect_with_aa(codec) \
325 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
326 !is_aa_path_mute(codec))
328 static void vt1708_stop_hp_work(struct via_spec
*spec
)
330 if (spec
->codec_type
!= VT1708
|| spec
->autocfg
.hp_pins
[0] == 0)
332 if (spec
->hp_work_active
) {
333 snd_hda_codec_write(spec
->codec
, 0x1, 0, 0xf81, 1);
334 cancel_delayed_work_sync(&spec
->vt1708_hp_work
);
335 spec
->hp_work_active
= 0;
339 static void vt1708_update_hp_work(struct via_spec
*spec
)
341 if (spec
->codec_type
!= VT1708
|| spec
->autocfg
.hp_pins
[0] == 0)
343 if (spec
->vt1708_jack_detect
&&
344 (spec
->active_streams
|| hp_detect_with_aa(spec
->codec
))) {
345 if (!spec
->hp_work_active
) {
346 snd_hda_codec_write(spec
->codec
, 0x1, 0, 0xf81, 0);
347 schedule_delayed_work(&spec
->vt1708_hp_work
,
348 msecs_to_jiffies(100));
349 spec
->hp_work_active
= 1;
351 } else if (!hp_detect_with_aa(spec
->codec
))
352 vt1708_stop_hp_work(spec
);
355 static void set_widgets_power_state(struct hda_codec
*codec
)
357 struct via_spec
*spec
= codec
->spec
;
358 if (spec
->set_widgets_power_state
)
359 spec
->set_widgets_power_state(codec
);
362 static int analog_input_switch_put(struct snd_kcontrol
*kcontrol
,
363 struct snd_ctl_elem_value
*ucontrol
)
365 int change
= snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
366 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
368 set_widgets_power_state(codec
);
369 analog_low_current_mode(snd_kcontrol_chip(kcontrol
));
370 vt1708_update_hp_work(codec
->spec
);
374 /* modify .put = snd_hda_mixer_amp_switch_put */
375 #define ANALOG_INPUT_MUTE \
376 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
379 .info = snd_hda_mixer_amp_switch_info, \
380 .get = snd_hda_mixer_amp_switch_get, \
381 .put = analog_input_switch_put, \
382 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
384 static const struct snd_kcontrol_new via_control_templates
[] = {
385 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
386 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
391 /* add dynamic controls */
392 static struct snd_kcontrol_new
*__via_clone_ctl(struct via_spec
*spec
,
393 const struct snd_kcontrol_new
*tmpl
,
396 struct snd_kcontrol_new
*knew
;
398 knew
= snd_array_new(&spec
->kctls
);
405 knew
->name
= kstrdup(name
, GFP_KERNEL
);
412 static int __via_add_control(struct via_spec
*spec
, int type
, const char *name
,
413 int idx
, unsigned long val
)
415 struct snd_kcontrol_new
*knew
;
417 knew
= __via_clone_ctl(spec
, &via_control_templates
[type
], name
);
421 if (get_amp_nid_(val
))
422 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
423 knew
->private_value
= val
;
427 #define via_add_control(spec, type, name, val) \
428 __via_add_control(spec, type, name, 0, val)
430 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
432 static void via_free_kctls(struct hda_codec
*codec
)
434 struct via_spec
*spec
= codec
->spec
;
436 if (spec
->kctls
.list
) {
437 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
439 for (i
= 0; i
< spec
->kctls
.used
; i
++)
442 snd_array_free(&spec
->kctls
);
445 /* create input playback/capture controls for the given pin */
446 static int via_new_analog_input(struct via_spec
*spec
, const char *ctlname
,
447 int type_idx
, int idx
, int mix_nid
)
452 sprintf(name
, "%s Playback Volume", ctlname
);
453 err
= __via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
, type_idx
,
454 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
457 sprintf(name
, "%s Playback Switch", ctlname
);
458 err
= __via_add_control(spec
, VIA_CTL_WIDGET_ANALOG_MUTE
, name
, type_idx
,
459 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
465 #define get_connection_index(codec, mux, nid) \
466 snd_hda_get_conn_index(codec, mux, nid, 0)
468 static bool check_amp_caps(struct hda_codec
*codec
, hda_nid_t nid
, int dir
,
474 caps
= get_wcaps(codec
, nid
);
475 if (dir
== HDA_INPUT
)
476 caps
&= AC_WCAP_IN_AMP
;
478 caps
&= AC_WCAP_OUT_AMP
;
481 if (query_amp_caps(codec
, nid
, dir
) & mask
)
486 #define have_mute(codec, nid, dir) \
487 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
489 /* enable/disable the output-route mixers */
490 static void activate_output_mix(struct hda_codec
*codec
, struct nid_path
*path
,
491 hda_nid_t mix_nid
, int idx
, bool enable
)
497 num
= snd_hda_get_num_conns(codec
, mix_nid
);
498 for (i
= 0; i
< num
; i
++) {
500 val
= AMP_IN_UNMUTE(i
);
502 val
= AMP_IN_MUTE(i
);
503 snd_hda_codec_write(codec
, mix_nid
, 0,
504 AC_VERB_SET_AMP_GAIN_MUTE
, val
);
508 /* enable/disable the output-route */
509 static void activate_output_path(struct hda_codec
*codec
, struct nid_path
*path
,
510 bool enable
, bool force
)
512 struct via_spec
*spec
= codec
->spec
;
514 for (i
= 0; i
< path
->depth
; i
++) {
516 int idx
= path
->idx
[i
];
518 if (i
< path
->depth
- 1)
519 dst
= path
->path
[i
+ 1];
522 if (enable
&& path
->multi
[i
])
523 snd_hda_codec_write(codec
, dst
, 0,
524 AC_VERB_SET_CONNECT_SEL
, idx
);
525 if (!force
&& (dst
== spec
->aa_mix_nid
))
527 if (have_mute(codec
, dst
, HDA_INPUT
))
528 activate_output_mix(codec
, path
, dst
, idx
, enable
);
529 if (!force
&& (src
== path
->vol_ctl
|| src
== path
->mute_ctl
))
531 if (have_mute(codec
, src
, HDA_OUTPUT
)) {
532 int val
= enable
? AMP_OUT_UNMUTE
: AMP_OUT_MUTE
;
533 snd_hda_codec_write(codec
, src
, 0,
534 AC_VERB_SET_AMP_GAIN_MUTE
, val
);
539 /* set the given pin as output */
540 static void init_output_pin(struct hda_codec
*codec
, hda_nid_t pin
,
545 snd_hda_set_pin_ctl(codec
, pin
, pin_type
);
546 if (snd_hda_query_pin_caps(codec
, pin
) & AC_PINCAP_EAPD
)
547 snd_hda_codec_write(codec
, pin
, 0,
548 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
551 static void via_auto_init_output(struct hda_codec
*codec
,
552 struct nid_path
*path
, int pin_type
)
559 pin
= path
->path
[path
->depth
- 1];
561 init_output_pin(codec
, pin
, pin_type
);
562 if (get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
)
563 caps
= query_amp_caps(codec
, pin
, HDA_OUTPUT
);
566 if (caps
& AC_AMPCAP_MUTE
) {
568 val
= (caps
& AC_AMPCAP_OFFSET
) >> AC_AMPCAP_OFFSET_SHIFT
;
569 snd_hda_codec_write(codec
, pin
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
572 activate_output_path(codec
, path
, true, true); /* force on */
575 static void via_auto_init_multi_out(struct hda_codec
*codec
)
577 struct via_spec
*spec
= codec
->spec
;
578 struct nid_path
*path
;
581 for (i
= 0; i
< spec
->autocfg
.line_outs
+ spec
->smart51_nums
; i
++) {
582 path
= &spec
->out_path
[i
];
583 if (!i
&& spec
->aamix_mode
&& spec
->out_mix_path
.depth
)
584 path
= &spec
->out_mix_path
;
585 via_auto_init_output(codec
, path
, PIN_OUT
);
589 /* deactivate the inactive headphone-paths */
590 static void deactivate_hp_paths(struct hda_codec
*codec
)
592 struct via_spec
*spec
= codec
->spec
;
593 int shared
= spec
->hp_indep_shared
;
595 if (spec
->hp_independent_mode
) {
596 activate_output_path(codec
, &spec
->hp_path
, false, false);
597 activate_output_path(codec
, &spec
->hp_mix_path
, false, false);
599 activate_output_path(codec
, &spec
->out_path
[shared
],
601 } else if (spec
->aamix_mode
|| !spec
->hp_path
.depth
) {
602 activate_output_path(codec
, &spec
->hp_indep_path
, false, false);
603 activate_output_path(codec
, &spec
->hp_path
, false, false);
605 activate_output_path(codec
, &spec
->hp_indep_path
, false, false);
606 activate_output_path(codec
, &spec
->hp_mix_path
, false, false);
610 static void via_auto_init_hp_out(struct hda_codec
*codec
)
612 struct via_spec
*spec
= codec
->spec
;
614 if (!spec
->hp_path
.depth
) {
615 via_auto_init_output(codec
, &spec
->hp_mix_path
, PIN_HP
);
618 deactivate_hp_paths(codec
);
619 if (spec
->hp_independent_mode
)
620 via_auto_init_output(codec
, &spec
->hp_indep_path
, PIN_HP
);
621 else if (spec
->aamix_mode
)
622 via_auto_init_output(codec
, &spec
->hp_mix_path
, PIN_HP
);
624 via_auto_init_output(codec
, &spec
->hp_path
, PIN_HP
);
627 static void via_auto_init_speaker_out(struct hda_codec
*codec
)
629 struct via_spec
*spec
= codec
->spec
;
631 if (!spec
->autocfg
.speaker_outs
)
633 if (!spec
->speaker_path
.depth
) {
634 via_auto_init_output(codec
, &spec
->speaker_mix_path
, PIN_OUT
);
637 if (!spec
->aamix_mode
) {
638 activate_output_path(codec
, &spec
->speaker_mix_path
,
640 via_auto_init_output(codec
, &spec
->speaker_path
, PIN_OUT
);
642 activate_output_path(codec
, &spec
->speaker_path
, false, false);
643 via_auto_init_output(codec
, &spec
->speaker_mix_path
, PIN_OUT
);
647 static bool is_smart51_pins(struct hda_codec
*codec
, hda_nid_t pin
);
648 static void via_hp_automute(struct hda_codec
*codec
);
650 static void via_auto_init_analog_input(struct hda_codec
*codec
)
652 struct via_spec
*spec
= codec
->spec
;
653 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
654 hda_nid_t conn
[HDA_MAX_CONNECTIONS
];
659 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
660 hda_nid_t nid
= spec
->adc_nids
[i
];
661 if (!(get_wcaps(codec
, nid
) & AC_WCAP_IN_AMP
) ||
662 !(query_amp_caps(codec
, nid
, HDA_INPUT
) & AC_AMPCAP_MUTE
))
664 snd_hda_codec_write(codec
, spec
->adc_nids
[i
], 0,
665 AC_VERB_SET_AMP_GAIN_MUTE
,
670 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
671 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
672 if (spec
->smart51_enabled
&& is_smart51_pins(codec
, nid
))
676 if (cfg
->inputs
[i
].type
== AUTO_PIN_MIC
)
677 ctl
|= snd_hda_get_default_vref(codec
, nid
);
679 snd_hda_set_pin_ctl(codec
, nid
, ctl
);
683 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
684 int adc_idx
= spec
->inputs
[spec
->cur_mux
[i
]].adc_idx
;
685 /* secondary ADCs must have the unique MUX */
686 if (i
> 0 && !spec
->mux_nids
[i
])
688 if (spec
->mux_nids
[adc_idx
]) {
689 int mux_idx
= spec
->inputs
[spec
->cur_mux
[i
]].mux_idx
;
690 snd_hda_codec_write(codec
, spec
->mux_nids
[adc_idx
], 0,
691 AC_VERB_SET_CONNECT_SEL
,
694 if (spec
->dyn_adc_switch
)
695 break; /* only one input-src */
699 if (!spec
->aa_mix_nid
)
701 num_conns
= snd_hda_get_connections(codec
, spec
->aa_mix_nid
, conn
,
703 for (i
= 0; i
< num_conns
; i
++) {
704 unsigned int caps
= get_wcaps(codec
, conn
[i
]);
705 if (get_wcaps_type(caps
) == AC_WID_PIN
)
706 snd_hda_codec_write(codec
, spec
->aa_mix_nid
, 0,
707 AC_VERB_SET_AMP_GAIN_MUTE
,
712 static void update_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
715 if (snd_hda_codec_read(codec
, nid
, 0,
716 AC_VERB_GET_POWER_STATE
, 0) == parm
)
718 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
721 static void update_conv_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
722 unsigned int parm
, unsigned int index
)
724 struct via_spec
*spec
= codec
->spec
;
726 if (snd_hda_codec_read(codec
, nid
, 0,
727 AC_VERB_GET_POWER_STATE
, 0) == parm
)
729 format
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_CONV
, 0);
730 if (format
&& (spec
->dac_stream_tag
[index
] != format
))
731 spec
->dac_stream_tag
[index
] = format
;
733 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
734 if (parm
== AC_PWRST_D0
) {
735 format
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_CONV
, 0);
736 if (!format
&& (spec
->dac_stream_tag
[index
] != format
))
737 snd_hda_codec_write(codec
, nid
, 0,
738 AC_VERB_SET_CHANNEL_STREAMID
,
739 spec
->dac_stream_tag
[index
]);
743 static void set_pin_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
744 unsigned int *affected_parm
)
747 unsigned def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
748 unsigned no_presence
= (def_conf
& AC_DEFCFG_MISC
)
749 >> AC_DEFCFG_MISC_SHIFT
750 & AC_DEFCFG_MISC_NO_PRESENCE
; /* do not support pin sense */
751 struct via_spec
*spec
= codec
->spec
;
752 unsigned present
= 0;
754 no_presence
|= spec
->no_pin_power_ctl
;
756 present
= snd_hda_jack_detect(codec
, nid
);
757 if ((spec
->smart51_enabled
&& is_smart51_pins(codec
, nid
))
758 || ((no_presence
|| present
)
759 && get_defcfg_connect(def_conf
) != AC_JACK_PORT_NONE
)) {
760 *affected_parm
= AC_PWRST_D0
; /* if it's connected */
765 update_power_state(codec
, nid
, parm
);
768 static int via_pin_power_ctl_info(struct snd_kcontrol
*kcontrol
,
769 struct snd_ctl_elem_info
*uinfo
)
771 return snd_hda_enum_bool_helper_info(kcontrol
, uinfo
);
774 static int via_pin_power_ctl_get(struct snd_kcontrol
*kcontrol
,
775 struct snd_ctl_elem_value
*ucontrol
)
777 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
778 struct via_spec
*spec
= codec
->spec
;
779 ucontrol
->value
.enumerated
.item
[0] = !spec
->no_pin_power_ctl
;
783 static int via_pin_power_ctl_put(struct snd_kcontrol
*kcontrol
,
784 struct snd_ctl_elem_value
*ucontrol
)
786 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
787 struct via_spec
*spec
= codec
->spec
;
788 unsigned int val
= !ucontrol
->value
.enumerated
.item
[0];
790 if (val
== spec
->no_pin_power_ctl
)
792 spec
->no_pin_power_ctl
= val
;
793 set_widgets_power_state(codec
);
794 analog_low_current_mode(codec
);
798 static const struct snd_kcontrol_new via_pin_power_ctl_enum
= {
799 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
800 .name
= "Dynamic Power-Control",
801 .info
= via_pin_power_ctl_info
,
802 .get
= via_pin_power_ctl_get
,
803 .put
= via_pin_power_ctl_put
,
807 static int via_independent_hp_info(struct snd_kcontrol
*kcontrol
,
808 struct snd_ctl_elem_info
*uinfo
)
810 static const char * const texts
[] = { "OFF", "ON" };
812 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
814 uinfo
->value
.enumerated
.items
= 2;
815 if (uinfo
->value
.enumerated
.item
>= 2)
816 uinfo
->value
.enumerated
.item
= 1;
817 strcpy(uinfo
->value
.enumerated
.name
,
818 texts
[uinfo
->value
.enumerated
.item
]);
822 static int via_independent_hp_get(struct snd_kcontrol
*kcontrol
,
823 struct snd_ctl_elem_value
*ucontrol
)
825 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
826 struct via_spec
*spec
= codec
->spec
;
828 ucontrol
->value
.enumerated
.item
[0] = spec
->hp_independent_mode
;
832 /* adjust spec->multiout setup according to the current flags */
833 static void setup_playback_multi_pcm(struct via_spec
*spec
)
835 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
836 spec
->multiout
.num_dacs
= cfg
->line_outs
+ spec
->smart51_nums
;
837 spec
->multiout
.hp_nid
= 0;
838 if (!spec
->hp_independent_mode
) {
839 if (!spec
->hp_indep_shared
)
840 spec
->multiout
.hp_nid
= spec
->hp_dac_nid
;
842 if (spec
->hp_indep_shared
)
843 spec
->multiout
.num_dacs
= cfg
->line_outs
- 1;
847 /* update DAC setups according to indep-HP switch;
848 * this function is called only when indep-HP is modified
850 static void switch_indep_hp_dacs(struct hda_codec
*codec
)
852 struct via_spec
*spec
= codec
->spec
;
853 int shared
= spec
->hp_indep_shared
;
854 hda_nid_t shared_dac
, hp_dac
;
856 if (!spec
->opened_streams
)
859 shared_dac
= shared
? spec
->multiout
.dac_nids
[shared
] : 0;
860 hp_dac
= spec
->hp_dac_nid
;
861 if (spec
->hp_independent_mode
) {
862 /* switch to indep-HP mode */
863 if (spec
->active_streams
& STREAM_MULTI_OUT
) {
864 __snd_hda_codec_cleanup_stream(codec
, hp_dac
, 1);
865 __snd_hda_codec_cleanup_stream(codec
, shared_dac
, 1);
867 if (spec
->active_streams
& STREAM_INDEP_HP
)
868 snd_hda_codec_setup_stream(codec
, hp_dac
,
869 spec
->cur_hp_stream_tag
, 0,
870 spec
->cur_hp_format
);
872 /* back to HP or shared-DAC */
873 if (spec
->active_streams
& STREAM_INDEP_HP
)
874 __snd_hda_codec_cleanup_stream(codec
, hp_dac
, 1);
875 if (spec
->active_streams
& STREAM_MULTI_OUT
) {
878 if (shared_dac
) { /* reset mutli-ch DAC */
881 } else { /* reset HP DAC */
885 snd_hda_codec_setup_stream(codec
, dac
,
886 spec
->cur_dac_stream_tag
, ch
,
887 spec
->cur_dac_format
);
890 setup_playback_multi_pcm(spec
);
893 static int via_independent_hp_put(struct snd_kcontrol
*kcontrol
,
894 struct snd_ctl_elem_value
*ucontrol
)
896 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
897 struct via_spec
*spec
= codec
->spec
;
900 mutex_lock(&spec
->config_mutex
);
901 cur
= !!ucontrol
->value
.enumerated
.item
[0];
902 if (spec
->hp_independent_mode
== cur
) {
903 mutex_unlock(&spec
->config_mutex
);
906 spec
->hp_independent_mode
= cur
;
907 shared
= spec
->hp_indep_shared
;
908 deactivate_hp_paths(codec
);
910 activate_output_path(codec
, &spec
->hp_indep_path
, true, false);
913 activate_output_path(codec
, &spec
->out_path
[shared
],
915 if (spec
->aamix_mode
|| !spec
->hp_path
.depth
)
916 activate_output_path(codec
, &spec
->hp_mix_path
,
919 activate_output_path(codec
, &spec
->hp_path
,
923 switch_indep_hp_dacs(codec
);
924 mutex_unlock(&spec
->config_mutex
);
926 /* update jack power state */
927 set_widgets_power_state(codec
);
928 via_hp_automute(codec
);
932 static const struct snd_kcontrol_new via_hp_mixer
= {
933 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
934 .name
= "Independent HP",
935 .info
= via_independent_hp_info
,
936 .get
= via_independent_hp_get
,
937 .put
= via_independent_hp_put
,
940 static int via_hp_build(struct hda_codec
*codec
)
942 struct via_spec
*spec
= codec
->spec
;
943 struct snd_kcontrol_new
*knew
;
946 nid
= spec
->autocfg
.hp_pins
[0];
947 knew
= via_clone_control(spec
, &via_hp_mixer
);
951 knew
->subdevice
= HDA_SUBDEV_NID_FLAG
| nid
;
956 static void notify_aa_path_ctls(struct hda_codec
*codec
)
958 struct via_spec
*spec
= codec
->spec
;
961 for (i
= 0; i
< spec
->smart51_nums
; i
++) {
962 struct snd_kcontrol
*ctl
;
963 struct snd_ctl_elem_id id
;
964 memset(&id
, 0, sizeof(id
));
965 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
966 sprintf(id
.name
, "%s Playback Volume", spec
->smart51_labels
[i
]);
967 ctl
= snd_hda_find_mixer_ctl(codec
, id
.name
);
969 snd_ctl_notify(codec
->bus
->card
,
970 SNDRV_CTL_EVENT_MASK_VALUE
,
975 static void mute_aa_path(struct hda_codec
*codec
, int mute
)
977 struct via_spec
*spec
= codec
->spec
;
978 int val
= mute
? HDA_AMP_MUTE
: HDA_AMP_UNMUTE
;
981 /* check AA path's mute status */
982 for (i
= 0; i
< spec
->smart51_nums
; i
++) {
983 if (spec
->smart51_idxs
[i
] < 0)
985 snd_hda_codec_amp_stereo(codec
, spec
->aa_mix_nid
,
986 HDA_INPUT
, spec
->smart51_idxs
[i
],
991 static bool is_smart51_pins(struct hda_codec
*codec
, hda_nid_t pin
)
993 struct via_spec
*spec
= codec
->spec
;
996 for (i
= 0; i
< spec
->smart51_nums
; i
++)
997 if (spec
->smart51_pins
[i
] == pin
)
1002 static int via_smart51_get(struct snd_kcontrol
*kcontrol
,
1003 struct snd_ctl_elem_value
*ucontrol
)
1005 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1006 struct via_spec
*spec
= codec
->spec
;
1008 *ucontrol
->value
.integer
.value
= spec
->smart51_enabled
;
1012 static int via_smart51_put(struct snd_kcontrol
*kcontrol
,
1013 struct snd_ctl_elem_value
*ucontrol
)
1015 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1016 struct via_spec
*spec
= codec
->spec
;
1017 int out_in
= *ucontrol
->value
.integer
.value
1018 ? AC_PINCTL_OUT_EN
: AC_PINCTL_IN_EN
;
1021 for (i
= 0; i
< spec
->smart51_nums
; i
++) {
1022 hda_nid_t nid
= spec
->smart51_pins
[i
];
1025 parm
= snd_hda_codec_read(codec
, nid
, 0,
1026 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
1027 parm
&= ~(AC_PINCTL_IN_EN
| AC_PINCTL_OUT_EN
);
1029 snd_hda_set_pin_ctl(codec
, nid
, parm
);
1030 if (out_in
== AC_PINCTL_OUT_EN
) {
1031 mute_aa_path(codec
, 1);
1032 notify_aa_path_ctls(codec
);
1035 spec
->smart51_enabled
= *ucontrol
->value
.integer
.value
;
1036 set_widgets_power_state(codec
);
1040 static const struct snd_kcontrol_new via_smart51_mixer
= {
1041 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1042 .name
= "Smart 5.1",
1044 .info
= snd_ctl_boolean_mono_info
,
1045 .get
= via_smart51_get
,
1046 .put
= via_smart51_put
,
1049 static int via_smart51_build(struct hda_codec
*codec
)
1051 struct via_spec
*spec
= codec
->spec
;
1053 if (!spec
->smart51_nums
)
1055 if (!via_clone_control(spec
, &via_smart51_mixer
))
1060 /* check AA path's mute status */
1061 static bool is_aa_path_mute(struct hda_codec
*codec
)
1063 struct via_spec
*spec
= codec
->spec
;
1064 const struct hda_amp_list
*p
;
1067 for (i
= 0; i
< spec
->num_loopbacks
; i
++) {
1068 p
= &spec
->loopback_list
[i
];
1069 for (ch
= 0; ch
< 2; ch
++) {
1070 v
= snd_hda_codec_amp_read(codec
, p
->nid
, ch
, p
->dir
,
1072 if (!(v
& HDA_AMP_MUTE
) && v
> 0)
1079 /* enter/exit analog low-current mode */
1080 static void __analog_low_current_mode(struct hda_codec
*codec
, bool force
)
1082 struct via_spec
*spec
= codec
->spec
;
1084 unsigned int verb
, parm
;
1086 if (spec
->no_pin_power_ctl
)
1089 enable
= is_aa_path_mute(codec
) && !spec
->opened_streams
;
1090 if (enable
== spec
->alc_mode
&& !force
)
1092 spec
->alc_mode
= enable
;
1094 /* decide low current mode's verb & parameter */
1095 switch (spec
->codec_type
) {
1099 parm
= enable
? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1105 parm
= enable
? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1109 parm
= enable
? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1115 parm
= enable
? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1120 parm
= enable
? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1123 return; /* other codecs are not supported */
1126 snd_hda_codec_write(codec
, codec
->afg
, 0, verb
, parm
);
1129 static void analog_low_current_mode(struct hda_codec
*codec
)
1131 return __analog_low_current_mode(codec
, false);
1135 * generic initialization of ADC, input mixers and output mixers
1137 static const struct hda_verb vt1708_init_verbs
[] = {
1138 /* power down jack detect function */
1143 static void set_stream_open(struct hda_codec
*codec
, int bit
, bool active
)
1145 struct via_spec
*spec
= codec
->spec
;
1148 spec
->opened_streams
|= bit
;
1150 spec
->opened_streams
&= ~bit
;
1151 analog_low_current_mode(codec
);
1154 static int via_playback_multi_pcm_open(struct hda_pcm_stream
*hinfo
,
1155 struct hda_codec
*codec
,
1156 struct snd_pcm_substream
*substream
)
1158 struct via_spec
*spec
= codec
->spec
;
1159 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1162 spec
->multiout
.num_dacs
= cfg
->line_outs
+ spec
->smart51_nums
;
1163 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1164 set_stream_open(codec
, STREAM_MULTI_OUT
, true);
1165 err
= snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
1168 set_stream_open(codec
, STREAM_MULTI_OUT
, false);
1174 static int via_playback_multi_pcm_close(struct hda_pcm_stream
*hinfo
,
1175 struct hda_codec
*codec
,
1176 struct snd_pcm_substream
*substream
)
1178 set_stream_open(codec
, STREAM_MULTI_OUT
, false);
1182 static int via_playback_hp_pcm_open(struct hda_pcm_stream
*hinfo
,
1183 struct hda_codec
*codec
,
1184 struct snd_pcm_substream
*substream
)
1186 struct via_spec
*spec
= codec
->spec
;
1188 if (snd_BUG_ON(!spec
->hp_dac_nid
))
1190 set_stream_open(codec
, STREAM_INDEP_HP
, true);
1194 static int via_playback_hp_pcm_close(struct hda_pcm_stream
*hinfo
,
1195 struct hda_codec
*codec
,
1196 struct snd_pcm_substream
*substream
)
1198 set_stream_open(codec
, STREAM_INDEP_HP
, false);
1202 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1203 struct hda_codec
*codec
,
1204 unsigned int stream_tag
,
1205 unsigned int format
,
1206 struct snd_pcm_substream
*substream
)
1208 struct via_spec
*spec
= codec
->spec
;
1210 mutex_lock(&spec
->config_mutex
);
1211 setup_playback_multi_pcm(spec
);
1212 snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
, stream_tag
,
1214 /* remember for dynamic DAC switch with indep-HP */
1215 spec
->active_streams
|= STREAM_MULTI_OUT
;
1216 spec
->cur_dac_stream_tag
= stream_tag
;
1217 spec
->cur_dac_format
= format
;
1218 mutex_unlock(&spec
->config_mutex
);
1219 vt1708_update_hp_work(spec
);
1223 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1224 struct hda_codec
*codec
,
1225 unsigned int stream_tag
,
1226 unsigned int format
,
1227 struct snd_pcm_substream
*substream
)
1229 struct via_spec
*spec
= codec
->spec
;
1231 mutex_lock(&spec
->config_mutex
);
1232 if (spec
->hp_independent_mode
)
1233 snd_hda_codec_setup_stream(codec
, spec
->hp_dac_nid
,
1234 stream_tag
, 0, format
);
1235 spec
->active_streams
|= STREAM_INDEP_HP
;
1236 spec
->cur_hp_stream_tag
= stream_tag
;
1237 spec
->cur_hp_format
= format
;
1238 mutex_unlock(&spec
->config_mutex
);
1239 vt1708_update_hp_work(spec
);
1243 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1244 struct hda_codec
*codec
,
1245 struct snd_pcm_substream
*substream
)
1247 struct via_spec
*spec
= codec
->spec
;
1249 mutex_lock(&spec
->config_mutex
);
1250 snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
1251 spec
->active_streams
&= ~STREAM_MULTI_OUT
;
1252 mutex_unlock(&spec
->config_mutex
);
1253 vt1708_update_hp_work(spec
);
1257 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1258 struct hda_codec
*codec
,
1259 struct snd_pcm_substream
*substream
)
1261 struct via_spec
*spec
= codec
->spec
;
1263 mutex_lock(&spec
->config_mutex
);
1264 if (spec
->hp_independent_mode
)
1265 snd_hda_codec_setup_stream(codec
, spec
->hp_dac_nid
, 0, 0, 0);
1266 spec
->active_streams
&= ~STREAM_INDEP_HP
;
1267 mutex_unlock(&spec
->config_mutex
);
1268 vt1708_update_hp_work(spec
);
1275 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1276 struct hda_codec
*codec
,
1277 struct snd_pcm_substream
*substream
)
1279 struct via_spec
*spec
= codec
->spec
;
1280 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
1283 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
1284 struct hda_codec
*codec
,
1285 struct snd_pcm_substream
*substream
)
1287 struct via_spec
*spec
= codec
->spec
;
1288 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
1291 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1292 struct hda_codec
*codec
,
1293 unsigned int stream_tag
,
1294 unsigned int format
,
1295 struct snd_pcm_substream
*substream
)
1297 struct via_spec
*spec
= codec
->spec
;
1298 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
1299 stream_tag
, format
, substream
);
1302 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1303 struct hda_codec
*codec
,
1304 struct snd_pcm_substream
*substream
)
1306 struct via_spec
*spec
= codec
->spec
;
1307 snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
1314 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1315 struct hda_codec
*codec
,
1316 unsigned int stream_tag
,
1317 unsigned int format
,
1318 struct snd_pcm_substream
*substream
)
1320 struct via_spec
*spec
= codec
->spec
;
1322 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
1323 stream_tag
, 0, format
);
1327 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1328 struct hda_codec
*codec
,
1329 struct snd_pcm_substream
*substream
)
1331 struct via_spec
*spec
= codec
->spec
;
1332 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
1336 /* analog capture with dynamic ADC switching */
1337 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1338 struct hda_codec
*codec
,
1339 unsigned int stream_tag
,
1340 unsigned int format
,
1341 struct snd_pcm_substream
*substream
)
1343 struct via_spec
*spec
= codec
->spec
;
1344 int adc_idx
= spec
->inputs
[spec
->cur_mux
[0]].adc_idx
;
1346 mutex_lock(&spec
->config_mutex
);
1347 spec
->cur_adc
= spec
->adc_nids
[adc_idx
];
1348 spec
->cur_adc_stream_tag
= stream_tag
;
1349 spec
->cur_adc_format
= format
;
1350 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
1351 mutex_unlock(&spec
->config_mutex
);
1355 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1356 struct hda_codec
*codec
,
1357 struct snd_pcm_substream
*substream
)
1359 struct via_spec
*spec
= codec
->spec
;
1361 mutex_lock(&spec
->config_mutex
);
1362 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
1364 mutex_unlock(&spec
->config_mutex
);
1368 /* re-setup the stream if running; called from input-src put */
1369 static bool via_dyn_adc_pcm_resetup(struct hda_codec
*codec
, int cur
)
1371 struct via_spec
*spec
= codec
->spec
;
1372 int adc_idx
= spec
->inputs
[cur
].adc_idx
;
1373 hda_nid_t adc
= spec
->adc_nids
[adc_idx
];
1376 mutex_lock(&spec
->config_mutex
);
1377 if (spec
->cur_adc
&& spec
->cur_adc
!= adc
) {
1378 /* stream is running, let's swap the current ADC */
1379 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
1380 spec
->cur_adc
= adc
;
1381 snd_hda_codec_setup_stream(codec
, adc
,
1382 spec
->cur_adc_stream_tag
, 0,
1383 spec
->cur_adc_format
);
1386 mutex_unlock(&spec
->config_mutex
);
1390 static const struct hda_pcm_stream via_pcm_analog_playback
= {
1394 /* NID is set in via_build_pcms */
1396 .open
= via_playback_multi_pcm_open
,
1397 .close
= via_playback_multi_pcm_close
,
1398 .prepare
= via_playback_multi_pcm_prepare
,
1399 .cleanup
= via_playback_multi_pcm_cleanup
1403 static const struct hda_pcm_stream via_pcm_hp_playback
= {
1407 /* NID is set in via_build_pcms */
1409 .open
= via_playback_hp_pcm_open
,
1410 .close
= via_playback_hp_pcm_close
,
1411 .prepare
= via_playback_hp_pcm_prepare
,
1412 .cleanup
= via_playback_hp_pcm_cleanup
1416 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
1420 /* NID is set in via_build_pcms */
1421 /* We got noisy outputs on the right channel on VT1708 when
1422 * 24bit samples are used. Until any workaround is found,
1423 * disable the 24bit format, so far.
1425 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1427 .open
= via_playback_multi_pcm_open
,
1428 .close
= via_playback_multi_pcm_close
,
1429 .prepare
= via_playback_multi_pcm_prepare
,
1430 .cleanup
= via_playback_multi_pcm_cleanup
1434 static const struct hda_pcm_stream via_pcm_analog_capture
= {
1435 .substreams
= 1, /* will be changed in via_build_pcms() */
1438 /* NID is set in via_build_pcms */
1440 .prepare
= via_capture_pcm_prepare
,
1441 .cleanup
= via_capture_pcm_cleanup
1445 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture
= {
1449 /* NID is set in via_build_pcms */
1451 .prepare
= via_dyn_adc_capture_pcm_prepare
,
1452 .cleanup
= via_dyn_adc_capture_pcm_cleanup
,
1456 static const struct hda_pcm_stream via_pcm_digital_playback
= {
1460 /* NID is set in via_build_pcms */
1462 .open
= via_dig_playback_pcm_open
,
1463 .close
= via_dig_playback_pcm_close
,
1464 .prepare
= via_dig_playback_pcm_prepare
,
1465 .cleanup
= via_dig_playback_pcm_cleanup
1469 static const struct hda_pcm_stream via_pcm_digital_capture
= {
1476 * slave controls for virtual master
1478 static const char * const via_slave_pfxs
[] = {
1479 "Front", "Surround", "Center", "LFE", "Side",
1480 "Headphone", "Speaker", "Bass Speaker",
1484 static int via_build_controls(struct hda_codec
*codec
)
1486 struct via_spec
*spec
= codec
->spec
;
1487 struct snd_kcontrol
*kctl
;
1490 spec
->no_pin_power_ctl
= 1;
1491 if (spec
->set_widgets_power_state
)
1492 if (!via_clone_control(spec
, &via_pin_power_ctl_enum
))
1495 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1496 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1501 if (spec
->multiout
.dig_out_nid
) {
1502 err
= snd_hda_create_spdif_out_ctls(codec
,
1503 spec
->multiout
.dig_out_nid
,
1504 spec
->multiout
.dig_out_nid
);
1507 err
= snd_hda_create_spdif_share_sw(codec
,
1511 spec
->multiout
.share_spdif
= 1;
1513 if (spec
->dig_in_nid
) {
1514 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1519 /* if we have no master control, let's create it */
1520 if (!snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
1521 unsigned int vmaster_tlv
[4];
1522 snd_hda_set_vmaster_tlv(codec
, spec
->multiout
.dac_nids
[0],
1523 HDA_OUTPUT
, vmaster_tlv
);
1524 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
1525 vmaster_tlv
, via_slave_pfxs
,
1530 if (!snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
1531 err
= snd_hda_add_vmaster(codec
, "Master Playback Switch",
1532 NULL
, via_slave_pfxs
,
1538 /* assign Capture Source enums to NID */
1539 kctl
= snd_hda_find_mixer_ctl(codec
, "Input Source");
1540 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1541 if (!spec
->mux_nids
[i
])
1543 err
= snd_hda_add_nid(codec
, kctl
, i
, spec
->mux_nids
[i
]);
1548 via_free_kctls(codec
); /* no longer needed */
1550 err
= snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
1557 static int via_build_pcms(struct hda_codec
*codec
)
1559 struct via_spec
*spec
= codec
->spec
;
1560 struct hda_pcm
*info
= spec
->pcm_rec
;
1562 codec
->num_pcms
= 0;
1563 codec
->pcm_info
= info
;
1565 if (spec
->multiout
.num_dacs
|| spec
->num_adc_nids
) {
1566 snprintf(spec
->stream_name_analog
,
1567 sizeof(spec
->stream_name_analog
),
1568 "%s Analog", codec
->chip_name
);
1569 info
->name
= spec
->stream_name_analog
;
1571 if (spec
->multiout
.num_dacs
) {
1572 if (!spec
->stream_analog_playback
)
1573 spec
->stream_analog_playback
=
1574 &via_pcm_analog_playback
;
1575 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1576 *spec
->stream_analog_playback
;
1577 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1578 spec
->multiout
.dac_nids
[0];
1579 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
1580 spec
->multiout
.max_channels
;
1581 if (spec
->autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
1582 && spec
->autocfg
.line_outs
== 2)
1583 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].chmap
=
1587 if (!spec
->stream_analog_capture
) {
1588 if (spec
->dyn_adc_switch
)
1589 spec
->stream_analog_capture
=
1590 &via_pcm_dyn_adc_analog_capture
;
1592 spec
->stream_analog_capture
=
1593 &via_pcm_analog_capture
;
1595 if (spec
->num_adc_nids
) {
1596 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
1597 *spec
->stream_analog_capture
;
1598 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
1600 if (!spec
->dyn_adc_switch
)
1601 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
1608 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
1609 snprintf(spec
->stream_name_digital
,
1610 sizeof(spec
->stream_name_digital
),
1611 "%s Digital", codec
->chip_name
);
1612 info
->name
= spec
->stream_name_digital
;
1613 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
1614 if (spec
->multiout
.dig_out_nid
) {
1615 if (!spec
->stream_digital_playback
)
1616 spec
->stream_digital_playback
=
1617 &via_pcm_digital_playback
;
1618 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1619 *spec
->stream_digital_playback
;
1620 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1621 spec
->multiout
.dig_out_nid
;
1623 if (spec
->dig_in_nid
) {
1624 if (!spec
->stream_digital_capture
)
1625 spec
->stream_digital_capture
=
1626 &via_pcm_digital_capture
;
1627 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
1628 *spec
->stream_digital_capture
;
1629 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
1636 if (spec
->hp_dac_nid
) {
1637 snprintf(spec
->stream_name_hp
, sizeof(spec
->stream_name_hp
),
1638 "%s HP", codec
->chip_name
);
1639 info
->name
= spec
->stream_name_hp
;
1640 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = via_pcm_hp_playback
;
1641 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1649 static void via_free(struct hda_codec
*codec
)
1651 struct via_spec
*spec
= codec
->spec
;
1656 via_free_kctls(codec
);
1657 vt1708_stop_hp_work(spec
);
1658 kfree(spec
->bind_cap_vol
);
1659 kfree(spec
->bind_cap_sw
);
1660 snd_hda_gen_free(&spec
->gen
);
1664 /* mute/unmute outputs */
1665 static void toggle_output_mutes(struct hda_codec
*codec
, int num_pins
,
1666 hda_nid_t
*pins
, bool mute
)
1669 for (i
= 0; i
< num_pins
; i
++) {
1670 unsigned int parm
= snd_hda_codec_read(codec
, pins
[i
], 0,
1671 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
1672 if (parm
& AC_PINCTL_IN_EN
)
1675 parm
&= ~AC_PINCTL_OUT_EN
;
1677 parm
|= AC_PINCTL_OUT_EN
;
1678 snd_hda_set_pin_ctl(codec
, pins
[i
], parm
);
1682 /* mute internal speaker if line-out is plugged */
1683 static void via_line_automute(struct hda_codec
*codec
, int present
)
1685 struct via_spec
*spec
= codec
->spec
;
1687 if (!spec
->autocfg
.speaker_outs
)
1690 present
= snd_hda_jack_detect(codec
,
1691 spec
->autocfg
.line_out_pins
[0]);
1692 toggle_output_mutes(codec
, spec
->autocfg
.speaker_outs
,
1693 spec
->autocfg
.speaker_pins
,
1697 /* mute internal speaker if HP is plugged */
1698 static void via_hp_automute(struct hda_codec
*codec
)
1702 struct via_spec
*spec
= codec
->spec
;
1704 if (!spec
->hp_independent_mode
&& spec
->autocfg
.hp_pins
[0] &&
1705 (spec
->codec_type
!= VT1708
|| spec
->vt1708_jack_detect
) &&
1706 is_jack_detectable(codec
, spec
->autocfg
.hp_pins
[0]))
1707 present
= snd_hda_jack_detect(codec
, spec
->autocfg
.hp_pins
[0]);
1709 if (spec
->smart51_enabled
)
1710 nums
= spec
->autocfg
.line_outs
+ spec
->smart51_nums
;
1712 nums
= spec
->autocfg
.line_outs
;
1713 toggle_output_mutes(codec
, nums
, spec
->autocfg
.line_out_pins
, present
);
1715 via_line_automute(codec
, present
);
1719 static int via_suspend(struct hda_codec
*codec
)
1721 struct via_spec
*spec
= codec
->spec
;
1722 vt1708_stop_hp_work(spec
);
1724 if (spec
->codec_type
== VT1802
) {
1725 /* Fix pop noise on headphones */
1727 for (i
= 0; i
< spec
->autocfg
.hp_outs
; i
++)
1728 snd_hda_set_pin_ctl(codec
, spec
->autocfg
.hp_pins
[i
], 0);
1736 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
1738 struct via_spec
*spec
= codec
->spec
;
1739 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
1746 static int via_init(struct hda_codec
*codec
);
1748 static const struct hda_codec_ops via_patch_ops
= {
1749 .build_controls
= via_build_controls
,
1750 .build_pcms
= via_build_pcms
,
1753 .unsol_event
= snd_hda_jack_unsol_event
,
1755 .suspend
= via_suspend
,
1756 .check_power_status
= via_check_power_status
,
1760 static bool is_empty_dac(struct hda_codec
*codec
, hda_nid_t dac
)
1762 struct via_spec
*spec
= codec
->spec
;
1765 for (i
= 0; i
< spec
->multiout
.num_dacs
; i
++) {
1766 if (spec
->multiout
.dac_nids
[i
] == dac
)
1769 if (spec
->hp_dac_nid
== dac
)
1774 static bool __parse_output_path(struct hda_codec
*codec
, hda_nid_t nid
,
1775 hda_nid_t target_dac
, int with_aa_mix
,
1776 struct nid_path
*path
, int depth
)
1778 struct via_spec
*spec
= codec
->spec
;
1782 if (nid
== spec
->aa_mix_nid
) {
1785 with_aa_mix
= 2; /* mark aa-mix is included */
1788 nums
= snd_hda_get_connections(codec
, nid
, conn
, ARRAY_SIZE(conn
));
1789 for (i
= 0; i
< nums
; i
++) {
1790 if (get_wcaps_type(get_wcaps(codec
, conn
[i
])) != AC_WID_AUD_OUT
)
1792 if (conn
[i
] == target_dac
|| is_empty_dac(codec
, conn
[i
])) {
1793 /* aa-mix is requested but not included? */
1794 if (!(spec
->aa_mix_nid
&& with_aa_mix
== 1))
1798 if (depth
>= MAX_NID_PATH_DEPTH
)
1800 for (i
= 0; i
< nums
; i
++) {
1802 type
= get_wcaps_type(get_wcaps(codec
, conn
[i
]));
1803 if (type
== AC_WID_AUD_OUT
)
1805 if (__parse_output_path(codec
, conn
[i
], target_dac
,
1806 with_aa_mix
, path
, depth
+ 1))
1812 path
->path
[path
->depth
] = conn
[i
];
1813 path
->idx
[path
->depth
] = i
;
1814 if (nums
> 1 && get_wcaps_type(get_wcaps(codec
, nid
)) != AC_WID_AUD_MIX
)
1815 path
->multi
[path
->depth
] = 1;
1820 static bool parse_output_path(struct hda_codec
*codec
, hda_nid_t nid
,
1821 hda_nid_t target_dac
, int with_aa_mix
,
1822 struct nid_path
*path
)
1824 if (__parse_output_path(codec
, nid
, target_dac
, with_aa_mix
, path
, 1)) {
1825 path
->path
[path
->depth
] = nid
;
1827 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1828 path
->depth
, path
->path
[0], path
->path
[1],
1829 path
->path
[2], path
->path
[3], path
->path
[4]);
1835 static int via_auto_fill_dac_nids(struct hda_codec
*codec
)
1837 struct via_spec
*spec
= codec
->spec
;
1838 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1842 spec
->multiout
.num_dacs
= 0;
1843 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1844 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1846 nid
= cfg
->line_out_pins
[i
];
1849 if (parse_output_path(codec
, nid
, 0, 0, &spec
->out_path
[i
]))
1850 dac
= spec
->out_path
[i
].path
[0];
1851 if (!i
&& parse_output_path(codec
, nid
, dac
, 1,
1852 &spec
->out_mix_path
))
1853 dac
= spec
->out_mix_path
.path
[0];
1855 spec
->private_dac_nids
[spec
->multiout
.num_dacs
++] = dac
;
1857 if (!spec
->out_path
[0].depth
&& spec
->out_mix_path
.depth
) {
1858 spec
->out_path
[0] = spec
->out_mix_path
;
1859 spec
->out_mix_path
.depth
= 0;
1864 static int create_ch_ctls(struct hda_codec
*codec
, const char *pfx
,
1865 int chs
, bool check_dac
, struct nid_path
*path
)
1867 struct via_spec
*spec
= codec
->spec
;
1869 hda_nid_t dac
, pin
, sel
, nid
;
1872 dac
= check_dac
? path
->path
[0] : 0;
1873 pin
= path
->path
[path
->depth
- 1];
1874 sel
= path
->depth
> 1 ? path
->path
[1] : 0;
1876 if (dac
&& check_amp_caps(codec
, dac
, HDA_OUTPUT
, AC_AMPCAP_NUM_STEPS
))
1878 else if (check_amp_caps(codec
, pin
, HDA_OUTPUT
, AC_AMPCAP_NUM_STEPS
))
1880 else if (check_amp_caps(codec
, sel
, HDA_OUTPUT
, AC_AMPCAP_NUM_STEPS
))
1885 sprintf(name
, "%s Playback Volume", pfx
);
1886 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1887 HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
));
1890 path
->vol_ctl
= nid
;
1893 if (dac
&& check_amp_caps(codec
, dac
, HDA_OUTPUT
, AC_AMPCAP_MUTE
))
1895 else if (check_amp_caps(codec
, pin
, HDA_OUTPUT
, AC_AMPCAP_MUTE
))
1897 else if (check_amp_caps(codec
, sel
, HDA_OUTPUT
, AC_AMPCAP_MUTE
))
1902 sprintf(name
, "%s Playback Switch", pfx
);
1903 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1904 HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
));
1907 path
->mute_ctl
= nid
;
1912 static void mangle_smart51(struct hda_codec
*codec
)
1914 struct via_spec
*spec
= codec
->spec
;
1915 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1916 struct auto_pin_cfg_item
*ins
= cfg
->inputs
;
1917 int i
, j
, nums
, attr
;
1918 int pins
[AUTO_CFG_MAX_INS
];
1920 for (attr
= INPUT_PIN_ATTR_REAR
; attr
>= INPUT_PIN_ATTR_NORMAL
; attr
--) {
1922 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1924 if (ins
[i
].type
> AUTO_PIN_LINE_IN
)
1926 def
= snd_hda_codec_get_pincfg(codec
, ins
[i
].pin
);
1927 if (snd_hda_get_input_pin_attr(def
) != attr
)
1929 for (j
= 0; j
< nums
; j
++)
1930 if (ins
[pins
[j
]].type
< ins
[i
].type
) {
1931 memmove(pins
+ j
+ 1, pins
+ j
,
1932 (nums
- j
) * sizeof(int));
1938 if (cfg
->line_outs
+ nums
< 3)
1940 for (i
= 0; i
< nums
; i
++) {
1941 hda_nid_t pin
= ins
[pins
[i
]].pin
;
1942 spec
->smart51_pins
[spec
->smart51_nums
++] = pin
;
1943 cfg
->line_out_pins
[cfg
->line_outs
++] = pin
;
1944 if (cfg
->line_outs
== 3)
1951 static void copy_path_mixer_ctls(struct nid_path
*dst
, struct nid_path
*src
)
1953 dst
->vol_ctl
= src
->vol_ctl
;
1954 dst
->mute_ctl
= src
->mute_ctl
;
1957 /* add playback controls from the parsed DAC table */
1958 static int via_auto_create_multi_out_ctls(struct hda_codec
*codec
)
1960 struct via_spec
*spec
= codec
->spec
;
1961 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1962 struct nid_path
*path
;
1963 static const char * const chname
[4] = {
1964 "Front", "Surround", NULL
/* "CLFE" */, "Side"
1970 old_line_outs
= cfg
->line_outs
;
1971 if (cfg
->line_outs
== 1)
1972 mangle_smart51(codec
);
1974 err
= via_auto_fill_dac_nids(codec
);
1978 if (spec
->multiout
.num_dacs
< 3) {
1979 spec
->smart51_nums
= 0;
1980 cfg
->line_outs
= old_line_outs
;
1982 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1984 pin
= cfg
->line_out_pins
[i
];
1985 dac
= spec
->multiout
.dac_nids
[i
];
1988 path
= spec
->out_path
+ i
;
1989 if (i
== HDA_CLFE
) {
1990 err
= create_ch_ctls(codec
, "Center", 1, true, path
);
1993 err
= create_ch_ctls(codec
, "LFE", 2, true, path
);
1997 const char *pfx
= chname
[i
];
1998 if (cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
1999 cfg
->line_outs
<= 2)
2000 pfx
= i
? "Bass Speaker" : "Speaker";
2001 err
= create_ch_ctls(codec
, pfx
, 3, true, path
);
2005 if (path
!= spec
->out_path
+ i
)
2006 copy_path_mixer_ctls(&spec
->out_path
[i
], path
);
2007 if (path
== spec
->out_path
&& spec
->out_mix_path
.depth
)
2008 copy_path_mixer_ctls(&spec
->out_mix_path
, path
);
2011 idx
= get_connection_index(codec
, spec
->aa_mix_nid
,
2012 spec
->multiout
.dac_nids
[0]);
2014 /* add control to mixer */
2016 name
= spec
->out_mix_path
.depth
?
2017 "PCM Loopback Playback Volume" : "PCM Playback Volume";
2018 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2019 HDA_COMPOSE_AMP_VAL(spec
->aa_mix_nid
, 3,
2023 name
= spec
->out_mix_path
.depth
?
2024 "PCM Loopback Playback Switch" : "PCM Playback Switch";
2025 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2026 HDA_COMPOSE_AMP_VAL(spec
->aa_mix_nid
, 3,
2032 cfg
->line_outs
= old_line_outs
;
2037 static int via_auto_create_hp_ctls(struct hda_codec
*codec
, hda_nid_t pin
)
2039 struct via_spec
*spec
= codec
->spec
;
2040 struct nid_path
*path
;
2047 if (!parse_output_path(codec
, pin
, 0, 0, &spec
->hp_indep_path
)) {
2048 for (i
= HDA_SIDE
; i
>= HDA_CLFE
; i
--) {
2049 if (i
< spec
->multiout
.num_dacs
&&
2050 parse_output_path(codec
, pin
,
2051 spec
->multiout
.dac_nids
[i
], 0,
2052 &spec
->hp_indep_path
)) {
2053 spec
->hp_indep_shared
= i
;
2058 if (spec
->hp_indep_path
.depth
) {
2059 spec
->hp_dac_nid
= spec
->hp_indep_path
.path
[0];
2060 if (!spec
->hp_indep_shared
)
2061 spec
->hp_path
= spec
->hp_indep_path
;
2063 /* optionally check front-path w/o AA-mix */
2064 if (!spec
->hp_path
.depth
)
2065 parse_output_path(codec
, pin
,
2066 spec
->multiout
.dac_nids
[HDA_FRONT
], 0,
2069 if (!parse_output_path(codec
, pin
, spec
->multiout
.dac_nids
[HDA_FRONT
],
2070 1, &spec
->hp_mix_path
) && !spec
->hp_path
.depth
)
2073 if (spec
->hp_path
.depth
) {
2074 path
= &spec
->hp_path
;
2077 path
= &spec
->hp_mix_path
;
2080 err
= create_ch_ctls(codec
, "Headphone", 3, check_dac
, path
);
2084 copy_path_mixer_ctls(&spec
->hp_mix_path
, path
);
2086 copy_path_mixer_ctls(&spec
->hp_path
, path
);
2087 if (spec
->hp_indep_path
.depth
)
2088 copy_path_mixer_ctls(&spec
->hp_indep_path
, path
);
2092 static int via_auto_create_speaker_ctls(struct hda_codec
*codec
)
2094 struct via_spec
*spec
= codec
->spec
;
2095 struct nid_path
*path
;
2097 hda_nid_t pin
, dac
= 0;
2100 pin
= spec
->autocfg
.speaker_pins
[0];
2101 if (!spec
->autocfg
.speaker_outs
|| !pin
)
2104 if (parse_output_path(codec
, pin
, 0, 0, &spec
->speaker_path
))
2105 dac
= spec
->speaker_path
.path
[0];
2107 parse_output_path(codec
, pin
,
2108 spec
->multiout
.dac_nids
[HDA_FRONT
], 0,
2109 &spec
->speaker_path
);
2110 if (!parse_output_path(codec
, pin
, spec
->multiout
.dac_nids
[HDA_FRONT
],
2111 1, &spec
->speaker_mix_path
) && !dac
)
2114 /* no AA-path for front? */
2115 if (!spec
->out_mix_path
.depth
&& spec
->speaker_mix_path
.depth
)
2118 spec
->speaker_dac_nid
= dac
;
2119 spec
->multiout
.extra_out_nid
[0] = dac
;
2121 path
= &spec
->speaker_path
;
2124 path
= &spec
->speaker_mix_path
;
2127 err
= create_ch_ctls(codec
, "Speaker", 3, check_dac
, path
);
2131 copy_path_mixer_ctls(&spec
->speaker_mix_path
, path
);
2133 copy_path_mixer_ctls(&spec
->speaker_path
, path
);
2137 #define via_aamix_ctl_info via_pin_power_ctl_info
2139 static int via_aamix_ctl_get(struct snd_kcontrol
*kcontrol
,
2140 struct snd_ctl_elem_value
*ucontrol
)
2142 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2143 struct via_spec
*spec
= codec
->spec
;
2144 ucontrol
->value
.enumerated
.item
[0] = spec
->aamix_mode
;
2148 static void update_aamix_paths(struct hda_codec
*codec
, int do_mix
,
2149 struct nid_path
*nomix
, struct nid_path
*mix
)
2152 activate_output_path(codec
, nomix
, false, false);
2153 activate_output_path(codec
, mix
, true, false);
2155 activate_output_path(codec
, mix
, false, false);
2156 activate_output_path(codec
, nomix
, true, false);
2160 static int via_aamix_ctl_put(struct snd_kcontrol
*kcontrol
,
2161 struct snd_ctl_elem_value
*ucontrol
)
2163 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2164 struct via_spec
*spec
= codec
->spec
;
2165 unsigned int val
= ucontrol
->value
.enumerated
.item
[0];
2167 if (val
== spec
->aamix_mode
)
2169 spec
->aamix_mode
= val
;
2170 /* update front path */
2171 update_aamix_paths(codec
, val
, &spec
->out_path
[0], &spec
->out_mix_path
);
2172 /* update HP path */
2173 if (!spec
->hp_independent_mode
) {
2174 update_aamix_paths(codec
, val
, &spec
->hp_path
,
2175 &spec
->hp_mix_path
);
2177 /* update speaker path */
2178 update_aamix_paths(codec
, val
, &spec
->speaker_path
,
2179 &spec
->speaker_mix_path
);
2183 static const struct snd_kcontrol_new via_aamix_ctl_enum
= {
2184 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2185 .name
= "Loopback Mixing",
2186 .info
= via_aamix_ctl_info
,
2187 .get
= via_aamix_ctl_get
,
2188 .put
= via_aamix_ctl_put
,
2191 static int via_auto_create_loopback_switch(struct hda_codec
*codec
)
2193 struct via_spec
*spec
= codec
->spec
;
2195 if (!spec
->aa_mix_nid
)
2196 return 0; /* no loopback switching available */
2197 if (!(spec
->out_mix_path
.depth
|| spec
->hp_mix_path
.depth
||
2198 spec
->speaker_path
.depth
))
2199 return 0; /* no loopback switching available */
2200 if (!via_clone_control(spec
, &via_aamix_ctl_enum
))
2206 static int via_fill_adcs(struct hda_codec
*codec
)
2208 struct via_spec
*spec
= codec
->spec
;
2209 hda_nid_t nid
= codec
->start_nid
;
2212 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
2213 unsigned int wcaps
= get_wcaps(codec
, nid
);
2214 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
2216 if (wcaps
& AC_WCAP_DIGITAL
)
2218 if (!(wcaps
& AC_WCAP_CONN_LIST
))
2220 if (spec
->num_adc_nids
>= ARRAY_SIZE(spec
->adc_nids
))
2222 spec
->adc_nids
[spec
->num_adc_nids
++] = nid
;
2227 /* input-src control */
2228 static int via_mux_enum_info(struct snd_kcontrol
*kcontrol
,
2229 struct snd_ctl_elem_info
*uinfo
)
2231 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2232 struct via_spec
*spec
= codec
->spec
;
2234 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2236 uinfo
->value
.enumerated
.items
= spec
->num_inputs
;
2237 if (uinfo
->value
.enumerated
.item
>= spec
->num_inputs
)
2238 uinfo
->value
.enumerated
.item
= spec
->num_inputs
- 1;
2239 strcpy(uinfo
->value
.enumerated
.name
,
2240 spec
->inputs
[uinfo
->value
.enumerated
.item
].label
);
2244 static int via_mux_enum_get(struct snd_kcontrol
*kcontrol
,
2245 struct snd_ctl_elem_value
*ucontrol
)
2247 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2248 struct via_spec
*spec
= codec
->spec
;
2249 unsigned int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
2251 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[idx
];
2255 static int via_mux_enum_put(struct snd_kcontrol
*kcontrol
,
2256 struct snd_ctl_elem_value
*ucontrol
)
2258 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2259 struct via_spec
*spec
= codec
->spec
;
2260 unsigned int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
2264 cur
= ucontrol
->value
.enumerated
.item
[0];
2265 if (cur
< 0 || cur
>= spec
->num_inputs
)
2267 if (spec
->cur_mux
[idx
] == cur
)
2269 spec
->cur_mux
[idx
] = cur
;
2270 if (spec
->dyn_adc_switch
) {
2271 int adc_idx
= spec
->inputs
[cur
].adc_idx
;
2272 mux
= spec
->mux_nids
[adc_idx
];
2273 via_dyn_adc_pcm_resetup(codec
, cur
);
2275 mux
= spec
->mux_nids
[idx
];
2276 if (snd_BUG_ON(!mux
))
2281 /* switch to D0 beofre change index */
2282 update_power_state(codec
, mux
, AC_PWRST_D0
);
2283 snd_hda_codec_write(codec
, mux
, 0,
2284 AC_VERB_SET_CONNECT_SEL
,
2285 spec
->inputs
[cur
].mux_idx
);
2288 /* update jack power state */
2289 set_widgets_power_state(codec
);
2293 static const struct snd_kcontrol_new via_input_src_ctl
= {
2294 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2295 /* The multiple "Capture Source" controls confuse alsamixer
2296 * So call somewhat different..
2298 /* .name = "Capture Source", */
2299 .name
= "Input Source",
2300 .info
= via_mux_enum_info
,
2301 .get
= via_mux_enum_get
,
2302 .put
= via_mux_enum_put
,
2305 static int create_input_src_ctls(struct hda_codec
*codec
, int count
)
2307 struct via_spec
*spec
= codec
->spec
;
2308 struct snd_kcontrol_new
*knew
;
2310 if (spec
->num_inputs
<= 1 || !count
)
2311 return 0; /* no need for single src */
2313 knew
= via_clone_control(spec
, &via_input_src_ctl
);
2316 knew
->count
= count
;
2320 /* add the powersave loopback-list entry */
2321 static void add_loopback_list(struct via_spec
*spec
, hda_nid_t mix
, int idx
)
2323 struct hda_amp_list
*list
;
2325 if (spec
->num_loopbacks
>= ARRAY_SIZE(spec
->loopback_list
) - 1)
2327 list
= spec
->loopback_list
+ spec
->num_loopbacks
;
2329 list
->dir
= HDA_INPUT
;
2331 spec
->num_loopbacks
++;
2332 spec
->loopback
.amplist
= spec
->loopback_list
;
2335 static bool is_reachable_nid(struct hda_codec
*codec
, hda_nid_t src
,
2338 return snd_hda_get_conn_index(codec
, src
, dst
, 1) >= 0;
2341 /* add the input-route to the given pin */
2342 static bool add_input_route(struct hda_codec
*codec
, hda_nid_t pin
)
2344 struct via_spec
*spec
= codec
->spec
;
2347 spec
->inputs
[spec
->num_inputs
].adc_idx
= -1;
2348 spec
->inputs
[spec
->num_inputs
].pin
= pin
;
2349 for (c
= 0; c
< spec
->num_adc_nids
; c
++) {
2350 if (spec
->mux_nids
[c
]) {
2351 idx
= get_connection_index(codec
, spec
->mux_nids
[c
],
2355 spec
->inputs
[spec
->num_inputs
].mux_idx
= idx
;
2357 if (!is_reachable_nid(codec
, spec
->adc_nids
[c
], pin
))
2360 spec
->inputs
[spec
->num_inputs
].adc_idx
= c
;
2361 /* Can primary ADC satisfy all inputs? */
2362 if (!spec
->dyn_adc_switch
&&
2363 spec
->num_inputs
> 0 && spec
->inputs
[0].adc_idx
!= c
) {
2364 snd_printd(KERN_INFO
2365 "via: dynamic ADC switching enabled\n");
2366 spec
->dyn_adc_switch
= 1;
2373 static int get_mux_nids(struct hda_codec
*codec
);
2375 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2376 static int parse_analog_inputs(struct hda_codec
*codec
)
2378 struct via_spec
*spec
= codec
->spec
;
2379 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2382 err
= via_fill_adcs(codec
);
2385 err
= get_mux_nids(codec
);
2389 /* fill all input-routes */
2390 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2391 if (add_input_route(codec
, cfg
->inputs
[i
].pin
))
2392 spec
->inputs
[spec
->num_inputs
++].label
=
2393 hda_get_autocfg_input_label(codec
, cfg
, i
);
2396 /* check for internal loopback recording */
2397 if (spec
->aa_mix_nid
&&
2398 add_input_route(codec
, spec
->aa_mix_nid
))
2399 spec
->inputs
[spec
->num_inputs
++].label
= "Stereo Mixer";
2404 /* create analog-loopback volume/switch controls */
2405 static int create_loopback_ctls(struct hda_codec
*codec
)
2407 struct via_spec
*spec
= codec
->spec
;
2408 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2409 const char *prev_label
= NULL
;
2413 if (!spec
->aa_mix_nid
)
2416 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2417 hda_nid_t pin
= cfg
->inputs
[i
].pin
;
2418 const char *label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
2420 if (prev_label
&& !strcmp(label
, prev_label
))
2425 idx
= get_connection_index(codec
, spec
->aa_mix_nid
, pin
);
2427 err
= via_new_analog_input(spec
, label
, type_idx
,
2428 idx
, spec
->aa_mix_nid
);
2431 add_loopback_list(spec
, spec
->aa_mix_nid
, idx
);
2434 /* remember the label for smart51 control */
2435 for (j
= 0; j
< spec
->smart51_nums
; j
++) {
2436 if (spec
->smart51_pins
[j
] == pin
) {
2437 spec
->smart51_idxs
[j
] = idx
;
2438 spec
->smart51_labels
[j
] = label
;
2446 /* create mic-boost controls (if present) */
2447 static int create_mic_boost_ctls(struct hda_codec
*codec
)
2449 struct via_spec
*spec
= codec
->spec
;
2450 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2451 const char *prev_label
= NULL
;
2455 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2456 hda_nid_t pin
= cfg
->inputs
[i
].pin
;
2461 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
2463 caps
= query_amp_caps(codec
, pin
, HDA_INPUT
);
2464 if (caps
== -1 || !(caps
& AC_AMPCAP_NUM_STEPS
))
2466 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
2467 if (prev_label
&& !strcmp(label
, prev_label
))
2472 snprintf(name
, sizeof(name
), "%s Boost Volume", label
);
2473 err
= __via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
, type_idx
,
2474 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_INPUT
));
2481 /* create capture and input-src controls for multiple streams */
2482 static int create_multi_adc_ctls(struct hda_codec
*codec
)
2484 struct via_spec
*spec
= codec
->spec
;
2487 /* create capture mixer elements */
2488 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
2489 hda_nid_t adc
= spec
->adc_nids
[i
];
2490 err
= __via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2491 "Capture Volume", i
,
2492 HDA_COMPOSE_AMP_VAL(adc
, 3, 0,
2496 err
= __via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2497 "Capture Switch", i
,
2498 HDA_COMPOSE_AMP_VAL(adc
, 3, 0,
2504 /* input-source control */
2505 for (i
= 0; i
< spec
->num_adc_nids
; i
++)
2506 if (!spec
->mux_nids
[i
])
2508 err
= create_input_src_ctls(codec
, i
);
2514 /* bind capture volume/switch */
2515 static struct snd_kcontrol_new via_bind_cap_vol_ctl
=
2516 HDA_BIND_VOL("Capture Volume", 0);
2517 static struct snd_kcontrol_new via_bind_cap_sw_ctl
=
2518 HDA_BIND_SW("Capture Switch", 0);
2520 static int init_bind_ctl(struct via_spec
*spec
, struct hda_bind_ctls
**ctl_ret
,
2521 struct hda_ctl_ops
*ops
)
2523 struct hda_bind_ctls
*ctl
;
2526 ctl
= kzalloc(sizeof(*ctl
) + sizeof(long) * 4, GFP_KERNEL
);
2530 for (i
= 0; i
< spec
->num_adc_nids
; i
++)
2532 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
], 3, 0, HDA_INPUT
);
2537 /* create capture and input-src controls for dynamic ADC-switch case */
2538 static int create_dyn_adc_ctls(struct hda_codec
*codec
)
2540 struct via_spec
*spec
= codec
->spec
;
2541 struct snd_kcontrol_new
*knew
;
2544 /* set up the bind capture ctls */
2545 err
= init_bind_ctl(spec
, &spec
->bind_cap_vol
, &snd_hda_bind_vol
);
2548 err
= init_bind_ctl(spec
, &spec
->bind_cap_sw
, &snd_hda_bind_sw
);
2552 /* create capture mixer elements */
2553 knew
= via_clone_control(spec
, &via_bind_cap_vol_ctl
);
2556 knew
->private_value
= (long)spec
->bind_cap_vol
;
2558 knew
= via_clone_control(spec
, &via_bind_cap_sw_ctl
);
2561 knew
->private_value
= (long)spec
->bind_cap_sw
;
2563 /* input-source control */
2564 err
= create_input_src_ctls(codec
, 1);
2570 /* parse and create capture-related stuff */
2571 static int via_auto_create_analog_input_ctls(struct hda_codec
*codec
)
2573 struct via_spec
*spec
= codec
->spec
;
2576 err
= parse_analog_inputs(codec
);
2579 if (spec
->dyn_adc_switch
)
2580 err
= create_dyn_adc_ctls(codec
);
2582 err
= create_multi_adc_ctls(codec
);
2585 err
= create_loopback_ctls(codec
);
2588 err
= create_mic_boost_ctls(codec
);
2594 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
2596 unsigned int def_conf
;
2597 unsigned char seqassoc
;
2599 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
2600 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
2601 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
2602 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
2603 && (seqassoc
== 0xf0 || seqassoc
== 0xff)) {
2604 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
2605 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
2611 static int vt1708_jack_detect_get(struct snd_kcontrol
*kcontrol
,
2612 struct snd_ctl_elem_value
*ucontrol
)
2614 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2615 struct via_spec
*spec
= codec
->spec
;
2617 if (spec
->codec_type
!= VT1708
)
2619 ucontrol
->value
.integer
.value
[0] = spec
->vt1708_jack_detect
;
2623 static int vt1708_jack_detect_put(struct snd_kcontrol
*kcontrol
,
2624 struct snd_ctl_elem_value
*ucontrol
)
2626 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2627 struct via_spec
*spec
= codec
->spec
;
2630 if (spec
->codec_type
!= VT1708
)
2632 val
= !!ucontrol
->value
.integer
.value
[0];
2633 if (spec
->vt1708_jack_detect
== val
)
2635 spec
->vt1708_jack_detect
= val
;
2636 if (spec
->vt1708_jack_detect
&&
2637 snd_hda_get_bool_hint(codec
, "analog_loopback_hp_detect") != 1) {
2638 mute_aa_path(codec
, 1);
2639 notify_aa_path_ctls(codec
);
2641 via_hp_automute(codec
);
2642 vt1708_update_hp_work(spec
);
2646 static const struct snd_kcontrol_new vt1708_jack_detect_ctl
= {
2647 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2648 .name
= "Jack Detect",
2650 .info
= snd_ctl_boolean_mono_info
,
2651 .get
= vt1708_jack_detect_get
,
2652 .put
= vt1708_jack_detect_put
,
2655 static void fill_dig_outs(struct hda_codec
*codec
);
2656 static void fill_dig_in(struct hda_codec
*codec
);
2658 static int via_parse_auto_config(struct hda_codec
*codec
)
2660 struct via_spec
*spec
= codec
->spec
;
2663 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2666 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2669 err
= via_auto_create_multi_out_ctls(codec
);
2672 err
= via_auto_create_hp_ctls(codec
, spec
->autocfg
.hp_pins
[0]);
2675 err
= via_auto_create_speaker_ctls(codec
);
2678 err
= via_auto_create_loopback_switch(codec
);
2681 err
= via_auto_create_analog_input_ctls(codec
);
2685 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2687 fill_dig_outs(codec
);
2690 if (spec
->kctls
.list
)
2691 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2694 if (spec
->hp_dac_nid
&& spec
->hp_mix_path
.depth
) {
2695 err
= via_hp_build(codec
);
2700 err
= via_smart51_build(codec
);
2704 /* assign slave outs */
2705 if (spec
->slave_dig_outs
[0])
2706 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
2711 static void via_auto_init_dig_outs(struct hda_codec
*codec
)
2713 struct via_spec
*spec
= codec
->spec
;
2714 if (spec
->multiout
.dig_out_nid
)
2715 init_output_pin(codec
, spec
->autocfg
.dig_out_pins
[0], PIN_OUT
);
2716 if (spec
->slave_dig_outs
[0])
2717 init_output_pin(codec
, spec
->autocfg
.dig_out_pins
[1], PIN_OUT
);
2720 static void via_auto_init_dig_in(struct hda_codec
*codec
)
2722 struct via_spec
*spec
= codec
->spec
;
2723 if (!spec
->dig_in_nid
)
2725 snd_hda_set_pin_ctl(codec
, spec
->autocfg
.dig_in_pin
, PIN_IN
);
2728 static void via_jack_output_event(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
)
2730 set_widgets_power_state(codec
);
2731 via_hp_automute(codec
);
2734 static void via_jack_powerstate_event(struct hda_codec
*codec
, struct hda_jack_tbl
*tbl
)
2736 set_widgets_power_state(codec
);
2739 /* initialize the unsolicited events */
2740 static void via_auto_init_unsol_event(struct hda_codec
*codec
)
2742 struct via_spec
*spec
= codec
->spec
;
2743 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2746 hda_jack_callback cb
;
2748 if (cfg
->hp_pins
[0] && is_jack_detectable(codec
, cfg
->hp_pins
[0]))
2749 snd_hda_jack_detect_enable_callback(codec
, cfg
->hp_pins
[0],
2750 VIA_HP_EVENT
| VIA_JACK_EVENT
,
2751 via_jack_output_event
);
2753 if (cfg
->speaker_pins
[0])
2754 ev
= VIA_LINE_EVENT
;
2757 cb
= ev
? via_jack_output_event
: via_jack_powerstate_event
;
2759 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2760 if (cfg
->line_out_pins
[i
] &&
2761 is_jack_detectable(codec
, cfg
->line_out_pins
[i
]))
2762 snd_hda_jack_detect_enable_callback(codec
, cfg
->line_out_pins
[i
],
2763 ev
| VIA_JACK_EVENT
, cb
);
2766 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2767 if (is_jack_detectable(codec
, cfg
->inputs
[i
].pin
))
2768 snd_hda_jack_detect_enable_callback(codec
, cfg
->inputs
[i
].pin
,
2770 via_jack_powerstate_event
);
2774 static int via_init(struct hda_codec
*codec
)
2776 struct via_spec
*spec
= codec
->spec
;
2779 for (i
= 0; i
< spec
->num_iverbs
; i
++)
2780 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
2782 /* init power states */
2783 set_widgets_power_state(codec
);
2784 __analog_low_current_mode(codec
, true);
2786 via_auto_init_multi_out(codec
);
2787 via_auto_init_hp_out(codec
);
2788 via_auto_init_speaker_out(codec
);
2789 via_auto_init_analog_input(codec
);
2790 via_auto_init_dig_outs(codec
);
2791 via_auto_init_dig_in(codec
);
2793 via_auto_init_unsol_event(codec
);
2795 via_hp_automute(codec
);
2796 vt1708_update_hp_work(spec
);
2801 static void vt1708_update_hp_jack_state(struct work_struct
*work
)
2803 struct via_spec
*spec
= container_of(work
, struct via_spec
,
2804 vt1708_hp_work
.work
);
2805 if (spec
->codec_type
!= VT1708
)
2807 snd_hda_jack_set_dirty_all(spec
->codec
);
2808 /* if jack state toggled */
2809 if (spec
->vt1708_hp_present
2810 != snd_hda_jack_detect(spec
->codec
, spec
->autocfg
.hp_pins
[0])) {
2811 spec
->vt1708_hp_present
^= 1;
2812 via_hp_automute(spec
->codec
);
2814 if (spec
->vt1708_jack_detect
)
2815 schedule_delayed_work(&spec
->vt1708_hp_work
,
2816 msecs_to_jiffies(100));
2819 static int get_mux_nids(struct hda_codec
*codec
)
2821 struct via_spec
*spec
= codec
->spec
;
2822 hda_nid_t nid
, conn
[8];
2826 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
2827 nid
= spec
->adc_nids
[i
];
2829 type
= get_wcaps_type(get_wcaps(codec
, nid
));
2830 if (type
== AC_WID_PIN
)
2832 n
= snd_hda_get_connections(codec
, nid
, conn
,
2837 spec
->mux_nids
[i
] = nid
;
2846 static int patch_vt1708(struct hda_codec
*codec
)
2848 struct via_spec
*spec
;
2851 /* create a codec specific record */
2852 spec
= via_new_spec(codec
);
2856 spec
->aa_mix_nid
= 0x17;
2858 /* Add HP and CD pin config connect bit re-config action */
2859 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
2860 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
2862 /* automatic parse from the BIOS config */
2863 err
= via_parse_auto_config(codec
);
2869 /* add jack detect on/off control */
2870 if (!via_clone_control(spec
, &vt1708_jack_detect_ctl
))
2873 /* disable 32bit format on VT1708 */
2874 if (codec
->vendor_id
== 0x11061708)
2875 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
2877 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_init_verbs
;
2879 codec
->patch_ops
= via_patch_ops
;
2881 INIT_DELAYED_WORK(&spec
->vt1708_hp_work
, vt1708_update_hp_jack_state
);
2885 static int patch_vt1709(struct hda_codec
*codec
)
2887 struct via_spec
*spec
;
2890 /* create a codec specific record */
2891 spec
= via_new_spec(codec
);
2895 spec
->aa_mix_nid
= 0x18;
2897 err
= via_parse_auto_config(codec
);
2903 codec
->patch_ops
= via_patch_ops
;
2908 static void set_widgets_power_state_vt1708B(struct hda_codec
*codec
)
2910 struct via_spec
*spec
= codec
->spec
;
2914 if ((spec
->codec_type
!= VT1708B_4CH
) &&
2915 (codec
->vendor_id
!= 0x11064397))
2918 /* SW0 (17h) = stereo mixer */
2920 (snd_hda_codec_read(codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00)
2921 == ((spec
->codec_type
== VT1708S
) ? 5 : 0));
2923 /* PW 1/2/5 (1ah/1bh/1eh) */
2925 set_pin_power_state(codec
, 0x1a, &parm
);
2926 set_pin_power_state(codec
, 0x1b, &parm
);
2927 set_pin_power_state(codec
, 0x1e, &parm
);
2930 /* SW0 (17h), AIW 0/1 (13h/14h) */
2931 update_power_state(codec
, 0x17, parm
);
2932 update_power_state(codec
, 0x13, parm
);
2933 update_power_state(codec
, 0x14, parm
);
2936 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2938 set_pin_power_state(codec
, 0x19, &parm
);
2939 if (spec
->smart51_enabled
)
2940 set_pin_power_state(codec
, 0x1b, &parm
);
2941 update_power_state(codec
, 0x18, parm
);
2942 update_power_state(codec
, 0x11, parm
);
2944 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2947 set_pin_power_state(codec
, 0x22, &parm
);
2948 if (spec
->smart51_enabled
)
2949 set_pin_power_state(codec
, 0x1a, &parm
);
2950 update_power_state(codec
, 0x26, parm
);
2951 update_power_state(codec
, 0x24, parm
);
2952 } else if (codec
->vendor_id
== 0x11064397) {
2953 /* PW7(23h), SW2(27h), AOW2(25h) */
2955 set_pin_power_state(codec
, 0x23, &parm
);
2956 if (spec
->smart51_enabled
)
2957 set_pin_power_state(codec
, 0x1a, &parm
);
2958 update_power_state(codec
, 0x27, parm
);
2959 update_power_state(codec
, 0x25, parm
);
2962 /* PW 3/4/7 (1ch/1dh/23h) */
2964 /* force to D0 for internal Speaker */
2965 set_pin_power_state(codec
, 0x1c, &parm
);
2966 set_pin_power_state(codec
, 0x1d, &parm
);
2968 set_pin_power_state(codec
, 0x23, &parm
);
2970 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2971 update_power_state(codec
, 0x16, imux_is_smixer
? AC_PWRST_D0
: parm
);
2972 update_power_state(codec
, 0x10, parm
);
2974 update_power_state(codec
, 0x25, parm
);
2975 update_power_state(codec
, 0x27, parm
);
2976 } else if (codec
->vendor_id
== 0x11064397 && spec
->hp_independent_mode
)
2977 update_power_state(codec
, 0x25, parm
);
2980 static int patch_vt1708S(struct hda_codec
*codec
);
2981 static int patch_vt1708B(struct hda_codec
*codec
)
2983 struct via_spec
*spec
;
2986 if (get_codec_type(codec
) == VT1708BCE
)
2987 return patch_vt1708S(codec
);
2989 /* create a codec specific record */
2990 spec
= via_new_spec(codec
);
2994 spec
->aa_mix_nid
= 0x16;
2996 /* automatic parse from the BIOS config */
2997 err
= via_parse_auto_config(codec
);
3003 codec
->patch_ops
= via_patch_ops
;
3005 spec
->set_widgets_power_state
= set_widgets_power_state_vt1708B
;
3010 /* Patch for VT1708S */
3011 static const struct hda_verb vt1708S_init_verbs
[] = {
3012 /* Enable Mic Boost Volume backdoor */
3014 /* don't bybass mixer */
3019 /* fill out digital output widgets; one for master and one for slave outputs */
3020 static void fill_dig_outs(struct hda_codec
*codec
)
3022 struct via_spec
*spec
= codec
->spec
;
3025 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
3029 nid
= spec
->autocfg
.dig_out_pins
[i
];
3032 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
3035 if (!spec
->multiout
.dig_out_nid
)
3036 spec
->multiout
.dig_out_nid
= nid
;
3038 spec
->slave_dig_outs
[0] = nid
;
3039 break; /* at most two dig outs */
3044 static void fill_dig_in(struct hda_codec
*codec
)
3046 struct via_spec
*spec
= codec
->spec
;
3050 if (!spec
->autocfg
.dig_in_pin
)
3053 dig_nid
= codec
->start_nid
;
3054 for (i
= 0; i
< codec
->num_nodes
; i
++, dig_nid
++) {
3055 unsigned int wcaps
= get_wcaps(codec
, dig_nid
);
3056 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
3058 if (!(wcaps
& AC_WCAP_DIGITAL
))
3060 if (!(wcaps
& AC_WCAP_CONN_LIST
))
3062 err
= get_connection_index(codec
, dig_nid
,
3063 spec
->autocfg
.dig_in_pin
);
3065 spec
->dig_in_nid
= dig_nid
;
3071 static void override_mic_boost(struct hda_codec
*codec
, hda_nid_t pin
,
3072 int offset
, int num_steps
, int step_size
)
3074 snd_hda_override_amp_caps(codec
, pin
, HDA_INPUT
,
3075 (offset
<< AC_AMPCAP_OFFSET_SHIFT
) |
3076 (num_steps
<< AC_AMPCAP_NUM_STEPS_SHIFT
) |
3077 (step_size
<< AC_AMPCAP_STEP_SIZE_SHIFT
) |
3078 (0 << AC_AMPCAP_MUTE_SHIFT
));
3081 static int patch_vt1708S(struct hda_codec
*codec
)
3083 struct via_spec
*spec
;
3086 /* create a codec specific record */
3087 spec
= via_new_spec(codec
);
3091 spec
->aa_mix_nid
= 0x16;
3092 override_mic_boost(codec
, 0x1a, 0, 3, 40);
3093 override_mic_boost(codec
, 0x1e, 0, 3, 40);
3095 /* automatic parse from the BIOS config */
3096 err
= via_parse_auto_config(codec
);
3102 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_init_verbs
;
3104 codec
->patch_ops
= via_patch_ops
;
3106 /* correct names for VT1708BCE */
3107 if (get_codec_type(codec
) == VT1708BCE
) {
3108 kfree(codec
->chip_name
);
3109 codec
->chip_name
= kstrdup("VT1708BCE", GFP_KERNEL
);
3110 snprintf(codec
->bus
->card
->mixername
,
3111 sizeof(codec
->bus
->card
->mixername
),
3112 "%s %s", codec
->vendor_name
, codec
->chip_name
);
3114 /* correct names for VT1705 */
3115 if (codec
->vendor_id
== 0x11064397) {
3116 kfree(codec
->chip_name
);
3117 codec
->chip_name
= kstrdup("VT1705", GFP_KERNEL
);
3118 snprintf(codec
->bus
->card
->mixername
,
3119 sizeof(codec
->bus
->card
->mixername
),
3120 "%s %s", codec
->vendor_name
, codec
->chip_name
);
3122 spec
->set_widgets_power_state
= set_widgets_power_state_vt1708B
;
3126 /* Patch for VT1702 */
3128 static const struct hda_verb vt1702_init_verbs
[] = {
3136 static void set_widgets_power_state_vt1702(struct hda_codec
*codec
)
3138 int imux_is_smixer
=
3139 snd_hda_codec_read(codec
, 0x13, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
3142 /* PW 1/2/5 (14h/15h/18h) */
3144 set_pin_power_state(codec
, 0x14, &parm
);
3145 set_pin_power_state(codec
, 0x15, &parm
);
3146 set_pin_power_state(codec
, 0x18, &parm
);
3148 parm
= AC_PWRST_D0
; /* SW0 (13h) = stereo mixer (idx 3) */
3149 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3150 update_power_state(codec
, 0x13, parm
);
3151 update_power_state(codec
, 0x12, parm
);
3152 update_power_state(codec
, 0x1f, parm
);
3153 update_power_state(codec
, 0x20, parm
);
3156 /* PW 3/4 (16h/17h) */
3158 set_pin_power_state(codec
, 0x17, &parm
);
3159 set_pin_power_state(codec
, 0x16, &parm
);
3160 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3161 update_power_state(codec
, 0x1a, imux_is_smixer
? AC_PWRST_D0
: parm
);
3162 update_power_state(codec
, 0x10, parm
);
3163 update_power_state(codec
, 0x1d, parm
);
3166 static int patch_vt1702(struct hda_codec
*codec
)
3168 struct via_spec
*spec
;
3171 /* create a codec specific record */
3172 spec
= via_new_spec(codec
);
3176 spec
->aa_mix_nid
= 0x1a;
3178 /* limit AA path volume to 0 dB */
3179 snd_hda_override_amp_caps(codec
, 0x1A, HDA_INPUT
,
3180 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
3181 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
3182 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
3183 (1 << AC_AMPCAP_MUTE_SHIFT
));
3185 /* automatic parse from the BIOS config */
3186 err
= via_parse_auto_config(codec
);
3192 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_init_verbs
;
3194 codec
->patch_ops
= via_patch_ops
;
3196 spec
->set_widgets_power_state
= set_widgets_power_state_vt1702
;
3200 /* Patch for VT1718S */
3202 static const struct hda_verb vt1718S_init_verbs
[] = {
3203 /* Enable MW0 adjust Gain 5 */
3205 /* Enable Boost Volume backdoor */
3211 static void set_widgets_power_state_vt1718S(struct hda_codec
*codec
)
3213 struct via_spec
*spec
= codec
->spec
;
3215 unsigned int parm
, parm2
;
3216 /* MUX6 (1eh) = stereo mixer */
3218 snd_hda_codec_read(codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
3220 /* PW 5/6/7 (29h/2ah/2bh) */
3222 set_pin_power_state(codec
, 0x29, &parm
);
3223 set_pin_power_state(codec
, 0x2a, &parm
);
3224 set_pin_power_state(codec
, 0x2b, &parm
);
3227 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3228 update_power_state(codec
, 0x1e, parm
);
3229 update_power_state(codec
, 0x1f, parm
);
3230 update_power_state(codec
, 0x10, parm
);
3231 update_power_state(codec
, 0x11, parm
);
3234 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3236 set_pin_power_state(codec
, 0x27, &parm
);
3237 update_power_state(codec
, 0x1a, parm
);
3238 parm2
= parm
; /* for pin 0x0b */
3240 /* PW2 (26h), AOW2 (ah) */
3242 set_pin_power_state(codec
, 0x26, &parm
);
3243 if (spec
->smart51_enabled
)
3244 set_pin_power_state(codec
, 0x2b, &parm
);
3245 update_power_state(codec
, 0xa, parm
);
3247 /* PW0 (24h), AOW0 (8h) */
3249 set_pin_power_state(codec
, 0x24, &parm
);
3250 if (!spec
->hp_independent_mode
) /* check for redirected HP */
3251 set_pin_power_state(codec
, 0x28, &parm
);
3252 update_power_state(codec
, 0x8, parm
);
3253 if (!spec
->hp_independent_mode
&& parm2
!= AC_PWRST_D3
)
3255 update_power_state(codec
, 0xb, parm
);
3256 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3257 update_power_state(codec
, 0x21, imux_is_smixer
? AC_PWRST_D0
: parm
);
3259 /* PW1 (25h), AOW1 (9h) */
3261 set_pin_power_state(codec
, 0x25, &parm
);
3262 if (spec
->smart51_enabled
)
3263 set_pin_power_state(codec
, 0x2a, &parm
);
3264 update_power_state(codec
, 0x9, parm
);
3266 if (spec
->hp_independent_mode
) {
3267 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3269 set_pin_power_state(codec
, 0x28, &parm
);
3270 update_power_state(codec
, 0x1b, parm
);
3271 update_power_state(codec
, 0x34, parm
);
3272 update_power_state(codec
, 0xc, parm
);
3276 /* Add a connection to the primary DAC from AA-mixer for some codecs
3277 * This isn't listed from the raw info, but the chip has a secret connection.
3279 static int add_secret_dac_path(struct hda_codec
*codec
)
3281 struct via_spec
*spec
= codec
->spec
;
3286 if (!spec
->aa_mix_nid
)
3288 nums
= snd_hda_get_connections(codec
, spec
->aa_mix_nid
, conn
,
3289 ARRAY_SIZE(conn
) - 1);
3290 for (i
= 0; i
< nums
; i
++) {
3291 if (get_wcaps_type(get_wcaps(codec
, conn
[i
])) == AC_WID_AUD_OUT
)
3295 /* find the primary DAC and add to the connection list */
3296 nid
= codec
->start_nid
;
3297 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
3298 unsigned int caps
= get_wcaps(codec
, nid
);
3299 if (get_wcaps_type(caps
) == AC_WID_AUD_OUT
&&
3300 !(caps
& AC_WCAP_DIGITAL
)) {
3302 return snd_hda_override_conn_list(codec
,
3311 static int patch_vt1718S(struct hda_codec
*codec
)
3313 struct via_spec
*spec
;
3316 /* create a codec specific record */
3317 spec
= via_new_spec(codec
);
3321 spec
->aa_mix_nid
= 0x21;
3322 override_mic_boost(codec
, 0x2b, 0, 3, 40);
3323 override_mic_boost(codec
, 0x29, 0, 3, 40);
3324 add_secret_dac_path(codec
);
3326 /* automatic parse from the BIOS config */
3327 err
= via_parse_auto_config(codec
);
3333 spec
->init_verbs
[spec
->num_iverbs
++] = vt1718S_init_verbs
;
3335 codec
->patch_ops
= via_patch_ops
;
3337 spec
->set_widgets_power_state
= set_widgets_power_state_vt1718S
;
3342 /* Patch for VT1716S */
3344 static int vt1716s_dmic_info(struct snd_kcontrol
*kcontrol
,
3345 struct snd_ctl_elem_info
*uinfo
)
3347 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
3349 uinfo
->value
.integer
.min
= 0;
3350 uinfo
->value
.integer
.max
= 1;
3354 static int vt1716s_dmic_get(struct snd_kcontrol
*kcontrol
,
3355 struct snd_ctl_elem_value
*ucontrol
)
3357 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3360 index
= snd_hda_codec_read(codec
, 0x26, 0,
3361 AC_VERB_GET_CONNECT_SEL
, 0);
3363 *ucontrol
->value
.integer
.value
= index
;
3368 static int vt1716s_dmic_put(struct snd_kcontrol
*kcontrol
,
3369 struct snd_ctl_elem_value
*ucontrol
)
3371 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3372 struct via_spec
*spec
= codec
->spec
;
3373 int index
= *ucontrol
->value
.integer
.value
;
3375 snd_hda_codec_write(codec
, 0x26, 0,
3376 AC_VERB_SET_CONNECT_SEL
, index
);
3377 spec
->dmic_enabled
= index
;
3378 set_widgets_power_state(codec
);
3382 static const struct snd_kcontrol_new vt1716s_dmic_mixer
[] = {
3383 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT
),
3385 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3386 .name
= "Digital Mic Capture Switch",
3387 .subdevice
= HDA_SUBDEV_NID_FLAG
| 0x26,
3389 .info
= vt1716s_dmic_info
,
3390 .get
= vt1716s_dmic_get
,
3391 .put
= vt1716s_dmic_put
,
3397 /* mono-out mixer elements */
3398 static const struct snd_kcontrol_new vt1716S_mono_out_mixer
[] = {
3399 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT
),
3403 static const struct hda_verb vt1716S_init_verbs
[] = {
3404 /* Enable Boost Volume backdoor */
3406 /* don't bybass mixer */
3408 /* Enable mono output */
3413 static void set_widgets_power_state_vt1716S(struct hda_codec
*codec
)
3415 struct via_spec
*spec
= codec
->spec
;
3418 unsigned int mono_out
, present
;
3419 /* SW0 (17h) = stereo mixer */
3421 (snd_hda_codec_read(codec
, 0x17, 0,
3422 AC_VERB_GET_CONNECT_SEL
, 0x00) == 5);
3424 /* PW 1/2/5 (1ah/1bh/1eh) */
3426 set_pin_power_state(codec
, 0x1a, &parm
);
3427 set_pin_power_state(codec
, 0x1b, &parm
);
3428 set_pin_power_state(codec
, 0x1e, &parm
);
3431 /* SW0 (17h), AIW0(13h) */
3432 update_power_state(codec
, 0x17, parm
);
3433 update_power_state(codec
, 0x13, parm
);
3436 set_pin_power_state(codec
, 0x1e, &parm
);
3438 if (spec
->dmic_enabled
)
3439 set_pin_power_state(codec
, 0x22, &parm
);
3441 update_power_state(codec
, 0x22, AC_PWRST_D3
);
3443 /* SW2(26h), AIW1(14h) */
3444 update_power_state(codec
, 0x26, parm
);
3445 update_power_state(codec
, 0x14, parm
);
3448 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3450 set_pin_power_state(codec
, 0x19, &parm
);
3451 /* Smart 5.1 PW2(1bh) */
3452 if (spec
->smart51_enabled
)
3453 set_pin_power_state(codec
, 0x1b, &parm
);
3454 update_power_state(codec
, 0x18, parm
);
3455 update_power_state(codec
, 0x11, parm
);
3457 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3459 set_pin_power_state(codec
, 0x23, &parm
);
3460 /* Smart 5.1 PW1(1ah) */
3461 if (spec
->smart51_enabled
)
3462 set_pin_power_state(codec
, 0x1a, &parm
);
3463 update_power_state(codec
, 0x27, parm
);
3465 /* Smart 5.1 PW5(1eh) */
3466 if (spec
->smart51_enabled
)
3467 set_pin_power_state(codec
, 0x1e, &parm
);
3468 update_power_state(codec
, 0x25, parm
);
3471 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3472 present
= snd_hda_jack_detect(codec
, 0x1c);
3477 present
= snd_hda_jack_detect(codec
, 0x1d);
3478 if (!spec
->hp_independent_mode
&& present
)
3483 parm
= mono_out
? AC_PWRST_D0
: AC_PWRST_D3
;
3484 update_power_state(codec
, 0x28, parm
);
3485 update_power_state(codec
, 0x29, parm
);
3486 update_power_state(codec
, 0x2a, parm
);
3488 /* PW 3/4 (1ch/1dh) */
3490 set_pin_power_state(codec
, 0x1c, &parm
);
3491 set_pin_power_state(codec
, 0x1d, &parm
);
3492 /* HP Independent Mode, power on AOW3 */
3493 if (spec
->hp_independent_mode
)
3494 update_power_state(codec
, 0x25, parm
);
3496 /* force to D0 for internal Speaker */
3497 /* MW0 (16h), AOW0 (10h) */
3498 update_power_state(codec
, 0x16, imux_is_smixer
? AC_PWRST_D0
: parm
);
3499 update_power_state(codec
, 0x10, mono_out
? AC_PWRST_D0
: parm
);
3502 static int patch_vt1716S(struct hda_codec
*codec
)
3504 struct via_spec
*spec
;
3507 /* create a codec specific record */
3508 spec
= via_new_spec(codec
);
3512 spec
->aa_mix_nid
= 0x16;
3513 override_mic_boost(codec
, 0x1a, 0, 3, 40);
3514 override_mic_boost(codec
, 0x1e, 0, 3, 40);
3516 /* automatic parse from the BIOS config */
3517 err
= via_parse_auto_config(codec
);
3523 spec
->init_verbs
[spec
->num_iverbs
++] = vt1716S_init_verbs
;
3525 spec
->mixers
[spec
->num_mixers
] = vt1716s_dmic_mixer
;
3528 spec
->mixers
[spec
->num_mixers
++] = vt1716S_mono_out_mixer
;
3530 codec
->patch_ops
= via_patch_ops
;
3532 spec
->set_widgets_power_state
= set_widgets_power_state_vt1716S
;
3538 static const struct hda_verb vt2002P_init_verbs
[] = {
3539 /* Class-D speaker related verbs */
3543 /* Enable Boost Volume backdoor */
3545 /* Enable AOW0 to MW9 */
3550 static const struct hda_verb vt1802_init_verbs
[] = {
3551 /* Enable Boost Volume backdoor */
3553 /* Enable AOW0 to MW9 */
3558 static void set_widgets_power_state_vt2002P(struct hda_codec
*codec
)
3560 struct via_spec
*spec
= codec
->spec
;
3563 unsigned int present
;
3564 /* MUX9 (1eh) = stereo mixer */
3566 snd_hda_codec_read(codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
3568 /* PW 5/6/7 (29h/2ah/2bh) */
3570 set_pin_power_state(codec
, 0x29, &parm
);
3571 set_pin_power_state(codec
, 0x2a, &parm
);
3572 set_pin_power_state(codec
, 0x2b, &parm
);
3574 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3575 update_power_state(codec
, 0x1e, parm
);
3576 update_power_state(codec
, 0x1f, parm
);
3577 update_power_state(codec
, 0x10, parm
);
3578 update_power_state(codec
, 0x11, parm
);
3582 update_power_state(codec
, 0x8, parm
);
3584 if (spec
->codec_type
== VT1802
) {
3585 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3587 set_pin_power_state(codec
, 0x28, &parm
);
3588 update_power_state(codec
, 0x18, parm
);
3589 update_power_state(codec
, 0x38, parm
);
3591 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3593 set_pin_power_state(codec
, 0x26, &parm
);
3594 update_power_state(codec
, 0x1c, parm
);
3595 update_power_state(codec
, 0x37, parm
);
3598 if (spec
->codec_type
== VT1802
) {
3599 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3601 set_pin_power_state(codec
, 0x25, &parm
);
3602 update_power_state(codec
, 0x15, parm
);
3603 update_power_state(codec
, 0x35, parm
);
3605 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3607 set_pin_power_state(codec
, 0x25, &parm
);
3608 update_power_state(codec
, 0x19, parm
);
3609 update_power_state(codec
, 0x35, parm
);
3612 if (spec
->hp_independent_mode
)
3613 update_power_state(codec
, 0x9, AC_PWRST_D0
);
3616 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3617 present
= snd_hda_jack_detect(codec
, 0x25);
3620 set_pin_power_state(codec
, 0x24, &parm
);
3621 parm
= present
? AC_PWRST_D3
: AC_PWRST_D0
;
3622 if (spec
->codec_type
== VT1802
)
3623 update_power_state(codec
, 0x14, parm
);
3625 update_power_state(codec
, 0x18, parm
);
3626 update_power_state(codec
, 0x34, parm
);
3629 present
= snd_hda_jack_detect(codec
, 0x26);
3631 parm
= present
? AC_PWRST_D3
: AC_PWRST_D0
;
3632 if (spec
->codec_type
== VT1802
) {
3633 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3634 update_power_state(codec
, 0x33, parm
);
3635 update_power_state(codec
, 0x1c, parm
);
3636 update_power_state(codec
, 0x3c, parm
);
3638 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3639 update_power_state(codec
, 0x31, parm
);
3640 update_power_state(codec
, 0x17, parm
);
3641 update_power_state(codec
, 0x3b, parm
);
3644 if (imux_is_smixer
|| !is_aa_path_mute(codec
))
3645 update_power_state(codec
, 0x21, AC_PWRST_D0
);
3647 update_power_state(codec
, 0x21, AC_PWRST_D3
);
3654 VIA_FIXUP_INTMIC_BOOST
,
3658 static void via_fixup_intmic_boost(struct hda_codec
*codec
,
3659 const struct hda_fixup
*fix
, int action
)
3661 if (action
== HDA_FIXUP_ACT_PRE_PROBE
)
3662 override_mic_boost(codec
, 0x30, 0, 2, 40);
3665 static const struct hda_fixup via_fixups
[] = {
3666 [VIA_FIXUP_INTMIC_BOOST
] = {
3667 .type
= HDA_FIXUP_FUNC
,
3668 .v
.func
= via_fixup_intmic_boost
,
3670 [VIA_FIXUP_ASUS_G75
] = {
3671 .type
= HDA_FIXUP_PINS
,
3672 .v
.pins
= (const struct hda_pintbl
[]) {
3673 /* set 0x24 and 0x33 as speakers */
3674 { 0x24, 0x991301f0 },
3675 { 0x33, 0x991301f1 }, /* subwoofer */
3681 static const struct snd_pci_quirk vt2002p_fixups
[] = {
3682 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75
),
3683 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST
),
3687 /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
3688 * Replace this with mixer NID 0x1c
3690 static void fix_vt1802_connections(struct hda_codec
*codec
)
3692 static hda_nid_t conn_24
[] = { 0x14, 0x1c };
3693 static hda_nid_t conn_33
[] = { 0x1c };
3695 snd_hda_override_conn_list(codec
, 0x24, ARRAY_SIZE(conn_24
), conn_24
);
3696 snd_hda_override_conn_list(codec
, 0x33, ARRAY_SIZE(conn_33
), conn_33
);
3699 /* patch for vt2002P */
3700 static int patch_vt2002P(struct hda_codec
*codec
)
3702 struct via_spec
*spec
;
3705 /* create a codec specific record */
3706 spec
= via_new_spec(codec
);
3710 spec
->aa_mix_nid
= 0x21;
3711 override_mic_boost(codec
, 0x2b, 0, 3, 40);
3712 override_mic_boost(codec
, 0x29, 0, 3, 40);
3713 if (spec
->codec_type
== VT1802
)
3714 fix_vt1802_connections(codec
);
3715 add_secret_dac_path(codec
);
3717 snd_hda_pick_fixup(codec
, NULL
, vt2002p_fixups
, via_fixups
);
3718 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_PRE_PROBE
);
3720 /* automatic parse from the BIOS config */
3721 err
= via_parse_auto_config(codec
);
3727 if (spec
->codec_type
== VT1802
)
3728 spec
->init_verbs
[spec
->num_iverbs
++] = vt1802_init_verbs
;
3730 spec
->init_verbs
[spec
->num_iverbs
++] = vt2002P_init_verbs
;
3732 codec
->patch_ops
= via_patch_ops
;
3734 spec
->set_widgets_power_state
= set_widgets_power_state_vt2002P
;
3740 static const struct hda_verb vt1812_init_verbs
[] = {
3741 /* Enable Boost Volume backdoor */
3743 /* Enable AOW0 to MW9 */
3748 static void set_widgets_power_state_vt1812(struct hda_codec
*codec
)
3750 struct via_spec
*spec
= codec
->spec
;
3752 unsigned int present
;
3754 /* PW 5/6/7 (29h/2ah/2bh) */
3756 set_pin_power_state(codec
, 0x29, &parm
);
3757 set_pin_power_state(codec
, 0x2a, &parm
);
3758 set_pin_power_state(codec
, 0x2b, &parm
);
3760 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3761 update_power_state(codec
, 0x1e, parm
);
3762 update_power_state(codec
, 0x1f, parm
);
3763 update_power_state(codec
, 0x10, parm
);
3764 update_power_state(codec
, 0x11, parm
);
3768 update_power_state(codec
, 0x8, AC_PWRST_D0
);
3770 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3772 set_pin_power_state(codec
, 0x28, &parm
);
3773 update_power_state(codec
, 0x18, parm
);
3774 update_power_state(codec
, 0x38, parm
);
3776 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3778 set_pin_power_state(codec
, 0x25, &parm
);
3779 update_power_state(codec
, 0x15, parm
);
3780 update_power_state(codec
, 0x35, parm
);
3781 if (spec
->hp_independent_mode
)
3782 update_power_state(codec
, 0x9, AC_PWRST_D0
);
3784 /* Internal Speaker */
3785 /* PW0 (24h), MW0(14h), MUX0(34h) */
3786 present
= snd_hda_jack_detect(codec
, 0x25);
3789 set_pin_power_state(codec
, 0x24, &parm
);
3791 update_power_state(codec
, 0x14, AC_PWRST_D3
);
3792 update_power_state(codec
, 0x34, AC_PWRST_D3
);
3794 update_power_state(codec
, 0x14, AC_PWRST_D0
);
3795 update_power_state(codec
, 0x34, AC_PWRST_D0
);
3800 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3801 present
= snd_hda_jack_detect(codec
, 0x28);
3804 set_pin_power_state(codec
, 0x31, &parm
);
3806 update_power_state(codec
, 0x1c, AC_PWRST_D3
);
3807 update_power_state(codec
, 0x3c, AC_PWRST_D3
);
3808 update_power_state(codec
, 0x3e, AC_PWRST_D3
);
3810 update_power_state(codec
, 0x1c, AC_PWRST_D0
);
3811 update_power_state(codec
, 0x3c, AC_PWRST_D0
);
3812 update_power_state(codec
, 0x3e, AC_PWRST_D0
);
3815 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3817 set_pin_power_state(codec
, 0x33, &parm
);
3818 update_power_state(codec
, 0x1d, parm
);
3819 update_power_state(codec
, 0x3d, parm
);
3823 /* patch for vt1812 */
3824 static int patch_vt1812(struct hda_codec
*codec
)
3826 struct via_spec
*spec
;
3829 /* create a codec specific record */
3830 spec
= via_new_spec(codec
);
3834 spec
->aa_mix_nid
= 0x21;
3835 override_mic_boost(codec
, 0x2b, 0, 3, 40);
3836 override_mic_boost(codec
, 0x29, 0, 3, 40);
3837 add_secret_dac_path(codec
);
3839 /* automatic parse from the BIOS config */
3840 err
= via_parse_auto_config(codec
);
3846 spec
->init_verbs
[spec
->num_iverbs
++] = vt1812_init_verbs
;
3848 codec
->patch_ops
= via_patch_ops
;
3850 spec
->set_widgets_power_state
= set_widgets_power_state_vt1812
;
3854 /* patch for vt3476 */
3856 static const struct hda_verb vt3476_init_verbs
[] = {
3857 /* Enable DMic 8/16/32K */
3859 /* Enable Boost Volume backdoor */
3861 /* Enable AOW-MW9 path */
3866 static void set_widgets_power_state_vt3476(struct hda_codec
*codec
)
3868 struct via_spec
*spec
= codec
->spec
;
3870 unsigned int parm
, parm2
;
3871 /* MUX10 (1eh) = stereo mixer */
3873 snd_hda_codec_read(codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 4;
3875 /* PW 5/6/7 (29h/2ah/2bh) */
3877 set_pin_power_state(codec
, 0x29, &parm
);
3878 set_pin_power_state(codec
, 0x2a, &parm
);
3879 set_pin_power_state(codec
, 0x2b, &parm
);
3882 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3883 update_power_state(codec
, 0x1e, parm
);
3884 update_power_state(codec
, 0x1f, parm
);
3885 update_power_state(codec
, 0x10, parm
);
3886 update_power_state(codec
, 0x11, parm
);
3889 /* PW3 (27h), MW3(37h), AOW3 (bh) */
3890 if (spec
->codec_type
== VT1705CF
) {
3892 update_power_state(codec
, 0x27, parm
);
3893 update_power_state(codec
, 0x37, parm
);
3896 set_pin_power_state(codec
, 0x27, &parm
);
3897 update_power_state(codec
, 0x37, parm
);
3900 /* PW2 (26h), MW2(36h), AOW2 (ah) */
3902 set_pin_power_state(codec
, 0x26, &parm
);
3903 update_power_state(codec
, 0x36, parm
);
3904 if (spec
->smart51_enabled
) {
3905 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
3906 set_pin_power_state(codec
, 0x2b, &parm
);
3907 update_power_state(codec
, 0x3b, parm
);
3908 update_power_state(codec
, 0x1b, parm
);
3910 update_conv_power_state(codec
, 0xa, parm
, 2);
3912 /* PW1 (25h), MW1(35h), AOW1 (9h) */
3914 set_pin_power_state(codec
, 0x25, &parm
);
3915 update_power_state(codec
, 0x35, parm
);
3916 if (spec
->smart51_enabled
) {
3917 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
3918 set_pin_power_state(codec
, 0x2a, &parm
);
3919 update_power_state(codec
, 0x3a, parm
);
3920 update_power_state(codec
, 0x1a, parm
);
3922 update_conv_power_state(codec
, 0x9, parm
, 1);
3924 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
3926 set_pin_power_state(codec
, 0x28, &parm
);
3927 update_power_state(codec
, 0x38, parm
);
3928 update_power_state(codec
, 0x18, parm
);
3929 if (spec
->hp_independent_mode
)
3930 update_conv_power_state(codec
, 0xb, parm
, 3);
3931 parm2
= parm
; /* for pin 0x0b */
3933 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
3935 set_pin_power_state(codec
, 0x24, &parm
);
3936 update_power_state(codec
, 0x34, parm
);
3937 if (!spec
->hp_independent_mode
&& parm2
!= AC_PWRST_D3
)
3939 update_conv_power_state(codec
, 0x8, parm
, 0);
3940 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3941 update_power_state(codec
, 0x3f, imux_is_smixer
? AC_PWRST_D0
: parm
);
3944 static int patch_vt3476(struct hda_codec
*codec
)
3946 struct via_spec
*spec
;
3949 /* create a codec specific record */
3950 spec
= via_new_spec(codec
);
3954 spec
->aa_mix_nid
= 0x3f;
3955 add_secret_dac_path(codec
);
3957 /* automatic parse from the BIOS config */
3958 err
= via_parse_auto_config(codec
);
3964 spec
->init_verbs
[spec
->num_iverbs
++] = vt3476_init_verbs
;
3966 codec
->patch_ops
= via_patch_ops
;
3968 spec
->set_widgets_power_state
= set_widgets_power_state_vt3476
;
3976 static const struct hda_codec_preset snd_hda_preset_via
[] = {
3977 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
3978 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
3979 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
3980 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
3981 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
3982 .patch
= patch_vt1709
},
3983 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
3984 .patch
= patch_vt1709
},
3985 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
3986 .patch
= patch_vt1709
},
3987 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
3988 .patch
= patch_vt1709
},
3989 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
3990 .patch
= patch_vt1709
},
3991 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
3992 .patch
= patch_vt1709
},
3993 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
3994 .patch
= patch_vt1709
},
3995 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
3996 .patch
= patch_vt1709
},
3997 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
3998 .patch
= patch_vt1708B
},
3999 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
4000 .patch
= patch_vt1708B
},
4001 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
4002 .patch
= patch_vt1708B
},
4003 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
4004 .patch
= patch_vt1708B
},
4005 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
4006 .patch
= patch_vt1708B
},
4007 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
4008 .patch
= patch_vt1708B
},
4009 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
4010 .patch
= patch_vt1708B
},
4011 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
4012 .patch
= patch_vt1708B
},
4013 { .id
= 0x11060397, .name
= "VT1708S",
4014 .patch
= patch_vt1708S
},
4015 { .id
= 0x11061397, .name
= "VT1708S",
4016 .patch
= patch_vt1708S
},
4017 { .id
= 0x11062397, .name
= "VT1708S",
4018 .patch
= patch_vt1708S
},
4019 { .id
= 0x11063397, .name
= "VT1708S",
4020 .patch
= patch_vt1708S
},
4021 { .id
= 0x11064397, .name
= "VT1705",
4022 .patch
= patch_vt1708S
},
4023 { .id
= 0x11065397, .name
= "VT1708S",
4024 .patch
= patch_vt1708S
},
4025 { .id
= 0x11066397, .name
= "VT1708S",
4026 .patch
= patch_vt1708S
},
4027 { .id
= 0x11067397, .name
= "VT1708S",
4028 .patch
= patch_vt1708S
},
4029 { .id
= 0x11060398, .name
= "VT1702",
4030 .patch
= patch_vt1702
},
4031 { .id
= 0x11061398, .name
= "VT1702",
4032 .patch
= patch_vt1702
},
4033 { .id
= 0x11062398, .name
= "VT1702",
4034 .patch
= patch_vt1702
},
4035 { .id
= 0x11063398, .name
= "VT1702",
4036 .patch
= patch_vt1702
},
4037 { .id
= 0x11064398, .name
= "VT1702",
4038 .patch
= patch_vt1702
},
4039 { .id
= 0x11065398, .name
= "VT1702",
4040 .patch
= patch_vt1702
},
4041 { .id
= 0x11066398, .name
= "VT1702",
4042 .patch
= patch_vt1702
},
4043 { .id
= 0x11067398, .name
= "VT1702",
4044 .patch
= patch_vt1702
},
4045 { .id
= 0x11060428, .name
= "VT1718S",
4046 .patch
= patch_vt1718S
},
4047 { .id
= 0x11064428, .name
= "VT1718S",
4048 .patch
= patch_vt1718S
},
4049 { .id
= 0x11060441, .name
= "VT2020",
4050 .patch
= patch_vt1718S
},
4051 { .id
= 0x11064441, .name
= "VT1828S",
4052 .patch
= patch_vt1718S
},
4053 { .id
= 0x11060433, .name
= "VT1716S",
4054 .patch
= patch_vt1716S
},
4055 { .id
= 0x1106a721, .name
= "VT1716S",
4056 .patch
= patch_vt1716S
},
4057 { .id
= 0x11060438, .name
= "VT2002P", .patch
= patch_vt2002P
},
4058 { .id
= 0x11064438, .name
= "VT2002P", .patch
= patch_vt2002P
},
4059 { .id
= 0x11060448, .name
= "VT1812", .patch
= patch_vt1812
},
4060 { .id
= 0x11060440, .name
= "VT1818S",
4061 .patch
= patch_vt1708S
},
4062 { .id
= 0x11060446, .name
= "VT1802",
4063 .patch
= patch_vt2002P
},
4064 { .id
= 0x11068446, .name
= "VT1802",
4065 .patch
= patch_vt2002P
},
4066 { .id
= 0x11064760, .name
= "VT1705CF",
4067 .patch
= patch_vt3476
},
4068 { .id
= 0x11064761, .name
= "VT1708SCE",
4069 .patch
= patch_vt3476
},
4070 { .id
= 0x11064762, .name
= "VT1808",
4071 .patch
= patch_vt3476
},
4075 MODULE_ALIAS("snd-hda-codec-id:1106*");
4077 static struct hda_codec_preset_list via_list
= {
4078 .preset
= snd_hda_preset_via
,
4079 .owner
= THIS_MODULE
,
4082 MODULE_LICENSE("GPL");
4083 MODULE_DESCRIPTION("VIA HD-audio codec");
4085 static int __init
patch_via_init(void)
4087 return snd_hda_add_codec_preset(&via_list
);
4090 static void __exit
patch_via_exit(void)
4092 snd_hda_delete_codec_preset(&via_list
);
4095 module_init(patch_via_init
)
4096 module_exit(patch_via_exit
)