2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <sound/core.h>
53 #include <sound/asoundef.h>
54 #include "hda_codec.h"
55 #include "hda_local.h"
58 #define VT1708_HP_PIN_NID 0x20
59 #define VT1708_CD_PIN_NID 0x24
79 #define VT2002P_COMPATIBLE(spec) \
80 ((spec)->codec_type == VT2002P ||\
81 (spec)->codec_type == VT1812 ||\
82 (spec)->codec_type == VT1802)
84 #define MAX_NID_PATH_DEPTH 5
86 /* output-path: DAC -> ... -> pin
87 * idx[] contains the source index number of the next widget;
88 * e.g. idx[0] is the index of the DAC selected by path[1] widget
89 * multi[] indicates whether it's a selector widget with multi-connectors
90 * (i.e. the connection selection is mandatory)
91 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
95 hda_nid_t path
[MAX_NID_PATH_DEPTH
];
96 unsigned char idx
[MAX_NID_PATH_DEPTH
];
97 unsigned char multi
[MAX_NID_PATH_DEPTH
];
99 unsigned int mute_ctl
;
104 hda_nid_t pin
; /* input-pin or aa-mix */
105 int adc_idx
; /* ADC index to be used */
106 int mux_idx
; /* MUX index (if any) */
107 const char *label
; /* input-source label */
110 #define VIA_MAX_ADCS 3
113 /* codec parameterization */
114 const struct snd_kcontrol_new
*mixers
[6];
115 unsigned int num_mixers
;
117 const struct hda_verb
*init_verbs
[5];
118 unsigned int num_iverbs
;
120 char stream_name_analog
[32];
121 char stream_name_hp
[32];
122 const struct hda_pcm_stream
*stream_analog_playback
;
123 const struct hda_pcm_stream
*stream_analog_capture
;
125 char stream_name_digital
[32];
126 const struct hda_pcm_stream
*stream_digital_playback
;
127 const struct hda_pcm_stream
*stream_digital_capture
;
130 struct hda_multi_out multiout
;
131 hda_nid_t slave_dig_outs
[2];
132 hda_nid_t hp_dac_nid
;
133 bool hp_indep_shared
; /* indep HP-DAC is shared with side ch */
134 int num_active_streams
;
137 struct nid_path out_path
[HDA_SIDE
+ 1];
138 struct nid_path hp_path
;
139 struct nid_path hp_dep_path
;
140 struct nid_path speaker_path
;
143 unsigned int num_adc_nids
;
144 hda_nid_t adc_nids
[VIA_MAX_ADCS
];
145 hda_nid_t mux_nids
[VIA_MAX_ADCS
];
146 hda_nid_t aa_mix_nid
;
147 hda_nid_t dig_in_nid
;
152 struct via_input inputs
[AUTO_CFG_MAX_INS
+ 1];
153 unsigned int cur_mux
[VIA_MAX_ADCS
];
155 /* dynamic ADC switching */
157 unsigned int cur_adc_stream_tag
;
158 unsigned int cur_adc_format
;
160 /* PCM information */
161 struct hda_pcm pcm_rec
[3];
163 /* dynamic controls, init_verbs and input_mux */
164 struct auto_pin_cfg autocfg
;
165 struct snd_array kctls
;
166 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
169 unsigned int hp_independent_mode
;
170 unsigned int dmic_enabled
;
171 unsigned int no_pin_power_ctl
;
172 enum VIA_HDA_CODEC codec_type
;
175 unsigned int smart51_nums
;
176 hda_nid_t smart51_pins
[2];
178 const char *smart51_labels
[2];
179 unsigned int smart51_enabled
;
181 /* work to check hp jack state */
182 struct hda_codec
*codec
;
183 struct delayed_work vt1708_hp_work
;
184 int vt1708_jack_detect
;
185 int vt1708_hp_present
;
187 void (*set_widgets_power_state
)(struct hda_codec
*codec
);
189 struct hda_loopback_check loopback
;
191 struct hda_amp_list loopback_list
[8];
193 /* bind capture-volume */
194 struct hda_bind_ctls
*bind_cap_vol
;
195 struct hda_bind_ctls
*bind_cap_sw
;
198 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
);
199 static struct via_spec
* via_new_spec(struct hda_codec
*codec
)
201 struct via_spec
*spec
;
203 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
209 spec
->codec_type
= get_codec_type(codec
);
210 /* VT1708BCE & VT1708S are almost same */
211 if (spec
->codec_type
== VT1708BCE
)
212 spec
->codec_type
= VT1708S
;
216 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
)
218 u32 vendor_id
= codec
->vendor_id
;
219 u16 ven_id
= vendor_id
>> 16;
220 u16 dev_id
= vendor_id
& 0xffff;
221 enum VIA_HDA_CODEC codec_type
;
224 if (ven_id
!= 0x1106)
225 codec_type
= UNKNOWN
;
226 else if (dev_id
>= 0x1708 && dev_id
<= 0x170b)
228 else if (dev_id
>= 0xe710 && dev_id
<= 0xe713)
229 codec_type
= VT1709_10CH
;
230 else if (dev_id
>= 0xe714 && dev_id
<= 0xe717)
231 codec_type
= VT1709_6CH
;
232 else if (dev_id
>= 0xe720 && dev_id
<= 0xe723) {
233 codec_type
= VT1708B_8CH
;
234 if (snd_hda_param_read(codec
, 0x16, AC_PAR_CONNLIST_LEN
) == 0x7)
235 codec_type
= VT1708BCE
;
236 } else if (dev_id
>= 0xe724 && dev_id
<= 0xe727)
237 codec_type
= VT1708B_4CH
;
238 else if ((dev_id
& 0xfff) == 0x397
239 && (dev_id
>> 12) < 8)
240 codec_type
= VT1708S
;
241 else if ((dev_id
& 0xfff) == 0x398
242 && (dev_id
>> 12) < 8)
244 else if ((dev_id
& 0xfff) == 0x428
245 && (dev_id
>> 12) < 8)
246 codec_type
= VT1718S
;
247 else if (dev_id
== 0x0433 || dev_id
== 0xa721)
248 codec_type
= VT1716S
;
249 else if (dev_id
== 0x0441 || dev_id
== 0x4441)
250 codec_type
= VT1718S
;
251 else if (dev_id
== 0x0438 || dev_id
== 0x4438)
252 codec_type
= VT2002P
;
253 else if (dev_id
== 0x0448)
255 else if (dev_id
== 0x0440)
256 codec_type
= VT1708S
;
257 else if ((dev_id
& 0xfff) == 0x446)
260 codec_type
= UNKNOWN
;
264 #define VIA_JACK_EVENT 0x20
265 #define VIA_HP_EVENT 0x01
266 #define VIA_GPIO_EVENT 0x02
267 #define VIA_LINE_EVENT 0x03
272 VIA_CTL_WIDGET_ANALOG_MUTE
,
275 static void analog_low_current_mode(struct hda_codec
*codec
);
276 static bool is_aa_path_mute(struct hda_codec
*codec
);
278 static void vt1708_start_hp_work(struct via_spec
*spec
)
280 if (spec
->codec_type
!= VT1708
|| spec
->autocfg
.hp_pins
[0] == 0)
282 snd_hda_codec_write(spec
->codec
, 0x1, 0, 0xf81,
283 !spec
->vt1708_jack_detect
);
284 if (!delayed_work_pending(&spec
->vt1708_hp_work
))
285 schedule_delayed_work(&spec
->vt1708_hp_work
,
286 msecs_to_jiffies(100));
289 static void vt1708_stop_hp_work(struct via_spec
*spec
)
291 if (spec
->codec_type
!= VT1708
|| spec
->autocfg
.hp_pins
[0] == 0)
293 if (snd_hda_get_bool_hint(spec
->codec
, "analog_loopback_hp_detect") == 1
294 && !is_aa_path_mute(spec
->codec
))
296 snd_hda_codec_write(spec
->codec
, 0x1, 0, 0xf81,
297 !spec
->vt1708_jack_detect
);
298 cancel_delayed_work_sync(&spec
->vt1708_hp_work
);
301 static void set_widgets_power_state(struct hda_codec
*codec
)
303 struct via_spec
*spec
= codec
->spec
;
304 if (spec
->set_widgets_power_state
)
305 spec
->set_widgets_power_state(codec
);
308 static int analog_input_switch_put(struct snd_kcontrol
*kcontrol
,
309 struct snd_ctl_elem_value
*ucontrol
)
311 int change
= snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
312 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
314 set_widgets_power_state(codec
);
315 analog_low_current_mode(snd_kcontrol_chip(kcontrol
));
316 if (snd_hda_get_bool_hint(codec
, "analog_loopback_hp_detect") == 1) {
317 if (is_aa_path_mute(codec
))
318 vt1708_start_hp_work(codec
->spec
);
320 vt1708_stop_hp_work(codec
->spec
);
325 /* modify .put = snd_hda_mixer_amp_switch_put */
326 #define ANALOG_INPUT_MUTE \
327 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
330 .info = snd_hda_mixer_amp_switch_info, \
331 .get = snd_hda_mixer_amp_switch_get, \
332 .put = analog_input_switch_put, \
333 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
335 static const struct snd_kcontrol_new via_control_templates
[] = {
336 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
337 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
342 /* add dynamic controls */
343 static struct snd_kcontrol_new
*__via_clone_ctl(struct via_spec
*spec
,
344 const struct snd_kcontrol_new
*tmpl
,
347 struct snd_kcontrol_new
*knew
;
349 snd_array_init(&spec
->kctls
, sizeof(*knew
), 32);
350 knew
= snd_array_new(&spec
->kctls
);
357 knew
->name
= kstrdup(name
, GFP_KERNEL
);
364 static int __via_add_control(struct via_spec
*spec
, int type
, const char *name
,
365 int idx
, unsigned long val
)
367 struct snd_kcontrol_new
*knew
;
369 knew
= __via_clone_ctl(spec
, &via_control_templates
[type
], name
);
373 if (get_amp_nid_(val
))
374 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
375 knew
->private_value
= val
;
379 #define via_add_control(spec, type, name, val) \
380 __via_add_control(spec, type, name, 0, val)
382 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
384 static void via_free_kctls(struct hda_codec
*codec
)
386 struct via_spec
*spec
= codec
->spec
;
388 if (spec
->kctls
.list
) {
389 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
391 for (i
= 0; i
< spec
->kctls
.used
; i
++)
394 snd_array_free(&spec
->kctls
);
397 /* create input playback/capture controls for the given pin */
398 static int via_new_analog_input(struct via_spec
*spec
, const char *ctlname
,
399 int type_idx
, int idx
, int mix_nid
)
404 sprintf(name
, "%s Playback Volume", ctlname
);
405 err
= __via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
, type_idx
,
406 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
409 sprintf(name
, "%s Playback Switch", ctlname
);
410 err
= __via_add_control(spec
, VIA_CTL_WIDGET_ANALOG_MUTE
, name
, type_idx
,
411 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
417 #define get_connection_index(codec, mux, nid) \
418 snd_hda_get_conn_index(codec, mux, nid, 0)
420 static bool check_amp_caps(struct hda_codec
*codec
, hda_nid_t nid
, int dir
,
426 caps
= get_wcaps(codec
, nid
);
427 if (dir
== HDA_INPUT
)
428 caps
&= AC_WCAP_IN_AMP
;
430 caps
&= AC_WCAP_OUT_AMP
;
433 if (query_amp_caps(codec
, nid
, dir
) & mask
)
438 #define have_mute(codec, nid, dir) \
439 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
441 /* enable/disable the output-route */
442 static void activate_output_path(struct hda_codec
*codec
, struct nid_path
*path
,
443 bool enable
, bool force
)
446 for (i
= 0; i
< path
->depth
; i
++) {
448 int idx
= path
->idx
[i
];
450 if (i
< path
->depth
- 1)
451 dst
= path
->path
[i
+ 1];
454 if (enable
&& path
->multi
[i
])
455 snd_hda_codec_write(codec
, dst
, 0,
456 AC_VERB_SET_CONNECT_SEL
, idx
);
458 && get_wcaps_type(get_wcaps(codec
, src
)) == AC_WID_AUD_OUT
459 && get_wcaps_type(get_wcaps(codec
, dst
)) == AC_WID_AUD_MIX
)
461 if (have_mute(codec
, dst
, HDA_INPUT
)) {
462 int val
= enable
? AMP_IN_UNMUTE(idx
) :
464 snd_hda_codec_write(codec
, dst
, 0,
465 AC_VERB_SET_AMP_GAIN_MUTE
, val
);
467 if (!force
&& (src
== path
->vol_ctl
|| src
== path
->mute_ctl
))
469 if (have_mute(codec
, src
, HDA_OUTPUT
)) {
470 int val
= enable
? AMP_OUT_UNMUTE
: AMP_OUT_MUTE
;
471 snd_hda_codec_write(codec
, src
, 0,
472 AC_VERB_SET_AMP_GAIN_MUTE
, val
);
477 /* set the given pin as output */
478 static void init_output_pin(struct hda_codec
*codec
, hda_nid_t pin
,
483 snd_hda_codec_write(codec
, pin
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
485 if (snd_hda_query_pin_caps(codec
, pin
) & AC_PINCAP_EAPD
)
486 snd_hda_codec_write(codec
, pin
, 0,
487 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
490 static void via_auto_init_output(struct hda_codec
*codec
,
491 struct nid_path
*path
, int pin_type
,
494 struct via_spec
*spec
= codec
->spec
;
496 hda_nid_t pin
, nid
, pre_nid
;
501 pin
= path
->path
[path
->depth
- 1];
503 init_output_pin(codec
, pin
, pin_type
);
504 caps
= query_amp_caps(codec
, pin
, HDA_OUTPUT
);
505 if (caps
& AC_AMPCAP_MUTE
) {
507 val
= (caps
& AC_AMPCAP_OFFSET
) >> AC_AMPCAP_OFFSET_SHIFT
;
508 snd_hda_codec_write(codec
, pin
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
512 activate_output_path(codec
, path
, true, force
);
514 /* initialize the AA-path */
515 if (!spec
->aa_mix_nid
)
517 for (i
= path
->depth
- 1; i
> 0; i
--) {
519 pre_nid
= path
->path
[i
- 1];
520 idx
= get_connection_index(codec
, nid
, spec
->aa_mix_nid
);
522 if (have_mute(codec
, nid
, HDA_INPUT
)) {
523 snd_hda_codec_write(codec
, nid
, 0,
524 AC_VERB_SET_AMP_GAIN_MUTE
,
526 if (pre_nid
== spec
->multiout
.dac_nids
[0]) {
527 num
= snd_hda_get_conn_list(codec
, nid
,
529 for (j
= 0; j
< num
; j
++) {
532 snd_hda_codec_write(codec
,
534 AC_VERB_SET_AMP_GAIN_MUTE
,
544 static void via_auto_init_multi_out(struct hda_codec
*codec
)
546 struct via_spec
*spec
= codec
->spec
;
549 for (i
= 0; i
< spec
->autocfg
.line_outs
+ spec
->smart51_nums
; i
++)
550 via_auto_init_output(codec
, &spec
->out_path
[i
], PIN_OUT
, true);
553 static void via_auto_init_hp_out(struct hda_codec
*codec
)
555 struct via_spec
*spec
= codec
->spec
;
557 if (!spec
->hp_dac_nid
) {
558 via_auto_init_output(codec
, &spec
->hp_dep_path
, PIN_HP
, true);
561 if (spec
->hp_independent_mode
) {
562 activate_output_path(codec
, &spec
->hp_dep_path
, false, false);
563 via_auto_init_output(codec
, &spec
->hp_path
, PIN_HP
, true);
565 activate_output_path(codec
, &spec
->hp_path
, false, false);
566 via_auto_init_output(codec
, &spec
->hp_dep_path
, PIN_HP
, true);
570 static void via_auto_init_speaker_out(struct hda_codec
*codec
)
572 struct via_spec
*spec
= codec
->spec
;
574 if (spec
->autocfg
.speaker_outs
)
575 via_auto_init_output(codec
, &spec
->speaker_path
, PIN_OUT
, true);
578 static bool is_smart51_pins(struct hda_codec
*codec
, hda_nid_t pin
);
580 static void via_auto_init_analog_input(struct hda_codec
*codec
)
582 struct via_spec
*spec
= codec
->spec
;
583 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
584 hda_nid_t conn
[HDA_MAX_CONNECTIONS
];
589 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
590 snd_hda_codec_write(codec
, spec
->adc_nids
[i
], 0,
591 AC_VERB_SET_AMP_GAIN_MUTE
,
596 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
597 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
598 if (spec
->smart51_enabled
&& is_smart51_pins(codec
, nid
))
600 else if (cfg
->inputs
[i
].type
== AUTO_PIN_MIC
)
604 snd_hda_codec_write(codec
, nid
, 0,
605 AC_VERB_SET_PIN_WIDGET_CONTROL
, ctl
);
609 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
610 int adc_idx
= spec
->inputs
[spec
->cur_mux
[i
]].adc_idx
;
611 if (spec
->mux_nids
[adc_idx
]) {
612 int mux_idx
= spec
->inputs
[spec
->cur_mux
[i
]].mux_idx
;
613 snd_hda_codec_write(codec
, spec
->mux_nids
[adc_idx
], 0,
614 AC_VERB_SET_CONNECT_SEL
,
617 if (spec
->dyn_adc_switch
)
618 break; /* only one input-src */
622 if (!spec
->aa_mix_nid
)
624 num_conns
= snd_hda_get_connections(codec
, spec
->aa_mix_nid
, conn
,
626 for (i
= 0; i
< num_conns
; i
++) {
627 unsigned int caps
= get_wcaps(codec
, conn
[i
]);
628 if (get_wcaps_type(caps
) == AC_WID_PIN
)
629 snd_hda_codec_write(codec
, spec
->aa_mix_nid
, 0,
630 AC_VERB_SET_AMP_GAIN_MUTE
,
635 static void set_pin_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
636 unsigned int *affected_parm
)
639 unsigned def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
640 unsigned no_presence
= (def_conf
& AC_DEFCFG_MISC
)
641 >> AC_DEFCFG_MISC_SHIFT
642 & AC_DEFCFG_MISC_NO_PRESENCE
; /* do not support pin sense */
643 struct via_spec
*spec
= codec
->spec
;
644 unsigned present
= 0;
646 no_presence
|= spec
->no_pin_power_ctl
;
648 present
= snd_hda_jack_detect(codec
, nid
);
649 if ((spec
->smart51_enabled
&& is_smart51_pins(codec
, nid
))
650 || ((no_presence
|| present
)
651 && get_defcfg_connect(def_conf
) != AC_JACK_PORT_NONE
)) {
652 *affected_parm
= AC_PWRST_D0
; /* if it's connected */
657 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
660 static int via_pin_power_ctl_info(struct snd_kcontrol
*kcontrol
,
661 struct snd_ctl_elem_info
*uinfo
)
663 static const char * const texts
[] = {
664 "Disabled", "Enabled"
667 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
669 uinfo
->value
.enumerated
.items
= 2;
670 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
671 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
672 strcpy(uinfo
->value
.enumerated
.name
,
673 texts
[uinfo
->value
.enumerated
.item
]);
677 static int via_pin_power_ctl_get(struct snd_kcontrol
*kcontrol
,
678 struct snd_ctl_elem_value
*ucontrol
)
680 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
681 struct via_spec
*spec
= codec
->spec
;
682 ucontrol
->value
.enumerated
.item
[0] = !spec
->no_pin_power_ctl
;
686 static int via_pin_power_ctl_put(struct snd_kcontrol
*kcontrol
,
687 struct snd_ctl_elem_value
*ucontrol
)
689 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
690 struct via_spec
*spec
= codec
->spec
;
691 unsigned int val
= !ucontrol
->value
.enumerated
.item
[0];
693 if (val
== spec
->no_pin_power_ctl
)
695 spec
->no_pin_power_ctl
= val
;
696 set_widgets_power_state(codec
);
700 static const struct snd_kcontrol_new via_pin_power_ctl_enum
= {
701 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
702 .name
= "Dynamic Power-Control",
703 .info
= via_pin_power_ctl_info
,
704 .get
= via_pin_power_ctl_get
,
705 .put
= via_pin_power_ctl_put
,
709 static int via_independent_hp_info(struct snd_kcontrol
*kcontrol
,
710 struct snd_ctl_elem_info
*uinfo
)
712 static const char * const texts
[] = { "OFF", "ON" };
714 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
716 uinfo
->value
.enumerated
.items
= 2;
717 if (uinfo
->value
.enumerated
.item
>= 2)
718 uinfo
->value
.enumerated
.item
= 1;
719 strcpy(uinfo
->value
.enumerated
.name
,
720 texts
[uinfo
->value
.enumerated
.item
]);
724 static int via_independent_hp_get(struct snd_kcontrol
*kcontrol
,
725 struct snd_ctl_elem_value
*ucontrol
)
727 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
728 struct via_spec
*spec
= codec
->spec
;
730 ucontrol
->value
.enumerated
.item
[0] = spec
->hp_independent_mode
;
734 static int via_independent_hp_put(struct snd_kcontrol
*kcontrol
,
735 struct snd_ctl_elem_value
*ucontrol
)
737 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
738 struct via_spec
*spec
= codec
->spec
;
741 /* no independent-hp status change during PCM playback is running */
742 if (spec
->num_active_streams
)
745 cur
= !!ucontrol
->value
.enumerated
.item
[0];
746 if (spec
->hp_independent_mode
== cur
)
748 spec
->hp_independent_mode
= cur
;
750 activate_output_path(codec
, &spec
->hp_dep_path
, false, false);
751 activate_output_path(codec
, &spec
->hp_path
, true, false);
752 if (spec
->hp_indep_shared
)
753 activate_output_path(codec
, &spec
->out_path
[HDA_SIDE
],
756 activate_output_path(codec
, &spec
->hp_path
, false, false);
757 activate_output_path(codec
, &spec
->hp_dep_path
, true, false);
758 if (spec
->hp_indep_shared
)
759 activate_output_path(codec
, &spec
->out_path
[HDA_SIDE
],
763 /* update jack power state */
764 set_widgets_power_state(codec
);
768 static const struct snd_kcontrol_new via_hp_mixer
= {
769 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
770 .name
= "Independent HP",
771 .info
= via_independent_hp_info
,
772 .get
= via_independent_hp_get
,
773 .put
= via_independent_hp_put
,
776 static int via_hp_build(struct hda_codec
*codec
)
778 struct via_spec
*spec
= codec
->spec
;
779 struct snd_kcontrol_new
*knew
;
782 nid
= spec
->autocfg
.hp_pins
[0];
783 knew
= via_clone_control(spec
, &via_hp_mixer
);
787 knew
->subdevice
= HDA_SUBDEV_NID_FLAG
| nid
;
792 static void notify_aa_path_ctls(struct hda_codec
*codec
)
794 struct via_spec
*spec
= codec
->spec
;
797 for (i
= 0; i
< spec
->smart51_nums
; i
++) {
798 struct snd_kcontrol
*ctl
;
799 struct snd_ctl_elem_id id
;
800 memset(&id
, 0, sizeof(id
));
801 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
802 sprintf(id
.name
, "%s Playback Volume", spec
->smart51_labels
[i
]);
803 ctl
= snd_hda_find_mixer_ctl(codec
, id
.name
);
805 snd_ctl_notify(codec
->bus
->card
,
806 SNDRV_CTL_EVENT_MASK_VALUE
,
811 static void mute_aa_path(struct hda_codec
*codec
, int mute
)
813 struct via_spec
*spec
= codec
->spec
;
814 int val
= mute
? HDA_AMP_MUTE
: HDA_AMP_UNMUTE
;
817 /* check AA path's mute status */
818 for (i
= 0; i
< spec
->smart51_nums
; i
++) {
819 if (spec
->smart51_idxs
[i
] < 0)
821 snd_hda_codec_amp_stereo(codec
, spec
->aa_mix_nid
,
822 HDA_INPUT
, spec
->smart51_idxs
[i
],
827 static bool is_smart51_pins(struct hda_codec
*codec
, hda_nid_t pin
)
829 struct via_spec
*spec
= codec
->spec
;
832 for (i
= 0; i
< spec
->smart51_nums
; i
++)
833 if (spec
->smart51_pins
[i
] == pin
)
838 static int via_smart51_get(struct snd_kcontrol
*kcontrol
,
839 struct snd_ctl_elem_value
*ucontrol
)
841 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
842 struct via_spec
*spec
= codec
->spec
;
844 *ucontrol
->value
.integer
.value
= spec
->smart51_enabled
;
848 static int via_smart51_put(struct snd_kcontrol
*kcontrol
,
849 struct snd_ctl_elem_value
*ucontrol
)
851 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
852 struct via_spec
*spec
= codec
->spec
;
853 int out_in
= *ucontrol
->value
.integer
.value
854 ? AC_PINCTL_OUT_EN
: AC_PINCTL_IN_EN
;
857 for (i
= 0; i
< spec
->smart51_nums
; i
++) {
858 hda_nid_t nid
= spec
->smart51_pins
[i
];
861 parm
= snd_hda_codec_read(codec
, nid
, 0,
862 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
863 parm
&= ~(AC_PINCTL_IN_EN
| AC_PINCTL_OUT_EN
);
865 snd_hda_codec_write(codec
, nid
, 0,
866 AC_VERB_SET_PIN_WIDGET_CONTROL
,
868 if (out_in
== AC_PINCTL_OUT_EN
) {
869 mute_aa_path(codec
, 1);
870 notify_aa_path_ctls(codec
);
873 spec
->smart51_enabled
= *ucontrol
->value
.integer
.value
;
874 set_widgets_power_state(codec
);
878 static const struct snd_kcontrol_new via_smart51_mixer
= {
879 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
882 .info
= snd_ctl_boolean_mono_info
,
883 .get
= via_smart51_get
,
884 .put
= via_smart51_put
,
887 static int via_smart51_build(struct hda_codec
*codec
)
889 struct via_spec
*spec
= codec
->spec
;
891 if (!spec
->smart51_nums
)
893 if (!via_clone_control(spec
, &via_smart51_mixer
))
898 /* check AA path's mute status */
899 static bool is_aa_path_mute(struct hda_codec
*codec
)
901 struct via_spec
*spec
= codec
->spec
;
902 const struct hda_amp_list
*p
;
905 for (i
= 0; i
< spec
->num_loopbacks
; i
++) {
906 p
= &spec
->loopback_list
[i
];
907 for (ch
= 0; ch
< 2; ch
++) {
908 v
= snd_hda_codec_amp_read(codec
, p
->nid
, ch
, p
->dir
,
910 if (!(v
& HDA_AMP_MUTE
) && v
> 0)
917 /* enter/exit analog low-current mode */
918 static void analog_low_current_mode(struct hda_codec
*codec
)
920 struct via_spec
*spec
= codec
->spec
;
922 unsigned int verb
, parm
;
924 enable
= is_aa_path_mute(codec
) && (spec
->num_active_streams
> 0);
926 /* decide low current mode's verb & parameter */
927 switch (spec
->codec_type
) {
931 parm
= enable
? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
937 parm
= enable
? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
941 parm
= enable
? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
947 parm
= enable
? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
950 return; /* other codecs are not supported */
953 snd_hda_codec_write(codec
, codec
->afg
, 0, verb
, parm
);
957 * generic initialization of ADC, input mixers and output mixers
959 static const struct hda_verb vt1708_init_verbs
[] = {
960 /* power down jack detect function */
965 static void set_stream_active(struct hda_codec
*codec
, bool active
)
967 struct via_spec
*spec
= codec
->spec
;
970 spec
->num_active_streams
++;
972 spec
->num_active_streams
--;
973 analog_low_current_mode(codec
);
976 static int via_playback_multi_pcm_open(struct hda_pcm_stream
*hinfo
,
977 struct hda_codec
*codec
,
978 struct snd_pcm_substream
*substream
)
980 struct via_spec
*spec
= codec
->spec
;
981 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
984 spec
->multiout
.hp_nid
= 0;
985 spec
->multiout
.num_dacs
= cfg
->line_outs
+ spec
->smart51_nums
;
986 if (!spec
->hp_independent_mode
) {
987 if (!spec
->hp_indep_shared
)
988 spec
->multiout
.hp_nid
= spec
->hp_dac_nid
;
990 if (spec
->hp_indep_shared
)
991 spec
->multiout
.num_dacs
= cfg
->line_outs
- 1;
993 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
994 set_stream_active(codec
, true);
995 err
= snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
998 spec
->multiout
.hp_nid
= 0;
999 set_stream_active(codec
, false);
1005 static int via_playback_multi_pcm_close(struct hda_pcm_stream
*hinfo
,
1006 struct hda_codec
*codec
,
1007 struct snd_pcm_substream
*substream
)
1009 struct via_spec
*spec
= codec
->spec
;
1011 spec
->multiout
.hp_nid
= 0;
1012 set_stream_active(codec
, false);
1016 static int via_playback_hp_pcm_open(struct hda_pcm_stream
*hinfo
,
1017 struct hda_codec
*codec
,
1018 struct snd_pcm_substream
*substream
)
1020 struct via_spec
*spec
= codec
->spec
;
1022 if (snd_BUG_ON(!spec
->hp_dac_nid
))
1024 if (!spec
->hp_independent_mode
|| spec
->multiout
.hp_nid
)
1026 set_stream_active(codec
, true);
1030 static int via_playback_hp_pcm_close(struct hda_pcm_stream
*hinfo
,
1031 struct hda_codec
*codec
,
1032 struct snd_pcm_substream
*substream
)
1034 set_stream_active(codec
, false);
1038 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1039 struct hda_codec
*codec
,
1040 unsigned int stream_tag
,
1041 unsigned int format
,
1042 struct snd_pcm_substream
*substream
)
1044 struct via_spec
*spec
= codec
->spec
;
1046 snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
, stream_tag
,
1048 vt1708_start_hp_work(spec
);
1052 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1053 struct hda_codec
*codec
,
1054 unsigned int stream_tag
,
1055 unsigned int format
,
1056 struct snd_pcm_substream
*substream
)
1058 struct via_spec
*spec
= codec
->spec
;
1060 snd_hda_codec_setup_stream(codec
, spec
->hp_dac_nid
,
1061 stream_tag
, 0, format
);
1062 vt1708_start_hp_work(spec
);
1066 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1067 struct hda_codec
*codec
,
1068 struct snd_pcm_substream
*substream
)
1070 struct via_spec
*spec
= codec
->spec
;
1072 snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
1073 vt1708_stop_hp_work(spec
);
1077 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1078 struct hda_codec
*codec
,
1079 struct snd_pcm_substream
*substream
)
1081 struct via_spec
*spec
= codec
->spec
;
1083 snd_hda_codec_setup_stream(codec
, spec
->hp_dac_nid
, 0, 0, 0);
1084 vt1708_stop_hp_work(spec
);
1091 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1092 struct hda_codec
*codec
,
1093 struct snd_pcm_substream
*substream
)
1095 struct via_spec
*spec
= codec
->spec
;
1096 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
1099 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
1100 struct hda_codec
*codec
,
1101 struct snd_pcm_substream
*substream
)
1103 struct via_spec
*spec
= codec
->spec
;
1104 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
1107 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1108 struct hda_codec
*codec
,
1109 unsigned int stream_tag
,
1110 unsigned int format
,
1111 struct snd_pcm_substream
*substream
)
1113 struct via_spec
*spec
= codec
->spec
;
1114 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
1115 stream_tag
, format
, substream
);
1118 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1119 struct hda_codec
*codec
,
1120 struct snd_pcm_substream
*substream
)
1122 struct via_spec
*spec
= codec
->spec
;
1123 snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
1130 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1131 struct hda_codec
*codec
,
1132 unsigned int stream_tag
,
1133 unsigned int format
,
1134 struct snd_pcm_substream
*substream
)
1136 struct via_spec
*spec
= codec
->spec
;
1138 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
1139 stream_tag
, 0, format
);
1143 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1144 struct hda_codec
*codec
,
1145 struct snd_pcm_substream
*substream
)
1147 struct via_spec
*spec
= codec
->spec
;
1148 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
1152 /* analog capture with dynamic ADC switching */
1153 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1154 struct hda_codec
*codec
,
1155 unsigned int stream_tag
,
1156 unsigned int format
,
1157 struct snd_pcm_substream
*substream
)
1159 struct via_spec
*spec
= codec
->spec
;
1160 int adc_idx
= spec
->inputs
[spec
->cur_mux
[0]].adc_idx
;
1162 spec
->cur_adc
= spec
->adc_nids
[adc_idx
];
1163 spec
->cur_adc_stream_tag
= stream_tag
;
1164 spec
->cur_adc_format
= format
;
1165 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
1169 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1170 struct hda_codec
*codec
,
1171 struct snd_pcm_substream
*substream
)
1173 struct via_spec
*spec
= codec
->spec
;
1175 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
1180 /* re-setup the stream if running; called from input-src put */
1181 static bool via_dyn_adc_pcm_resetup(struct hda_codec
*codec
, int cur
)
1183 struct via_spec
*spec
= codec
->spec
;
1184 int adc_idx
= spec
->inputs
[cur
].adc_idx
;
1185 hda_nid_t adc
= spec
->adc_nids
[adc_idx
];
1187 if (spec
->cur_adc
&& spec
->cur_adc
!= adc
) {
1188 /* stream is running, let's swap the current ADC */
1189 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
1190 spec
->cur_adc
= adc
;
1191 snd_hda_codec_setup_stream(codec
, adc
,
1192 spec
->cur_adc_stream_tag
, 0,
1193 spec
->cur_adc_format
);
1199 static const struct hda_pcm_stream via_pcm_analog_playback
= {
1203 /* NID is set in via_build_pcms */
1205 .open
= via_playback_multi_pcm_open
,
1206 .close
= via_playback_multi_pcm_close
,
1207 .prepare
= via_playback_multi_pcm_prepare
,
1208 .cleanup
= via_playback_multi_pcm_cleanup
1212 static const struct hda_pcm_stream via_pcm_hp_playback
= {
1216 /* NID is set in via_build_pcms */
1218 .open
= via_playback_hp_pcm_open
,
1219 .close
= via_playback_hp_pcm_close
,
1220 .prepare
= via_playback_hp_pcm_prepare
,
1221 .cleanup
= via_playback_hp_pcm_cleanup
1225 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
1229 /* NID is set in via_build_pcms */
1230 /* We got noisy outputs on the right channel on VT1708 when
1231 * 24bit samples are used. Until any workaround is found,
1232 * disable the 24bit format, so far.
1234 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1236 .open
= via_playback_multi_pcm_open
,
1237 .close
= via_playback_multi_pcm_close
,
1238 .prepare
= via_playback_multi_pcm_prepare
,
1239 .cleanup
= via_playback_multi_pcm_cleanup
1243 static const struct hda_pcm_stream via_pcm_analog_capture
= {
1244 .substreams
= 1, /* will be changed in via_build_pcms() */
1247 /* NID is set in via_build_pcms */
1249 .prepare
= via_capture_pcm_prepare
,
1250 .cleanup
= via_capture_pcm_cleanup
1254 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture
= {
1258 /* NID is set in via_build_pcms */
1260 .prepare
= via_dyn_adc_capture_pcm_prepare
,
1261 .cleanup
= via_dyn_adc_capture_pcm_cleanup
,
1265 static const struct hda_pcm_stream via_pcm_digital_playback
= {
1269 /* NID is set in via_build_pcms */
1271 .open
= via_dig_playback_pcm_open
,
1272 .close
= via_dig_playback_pcm_close
,
1273 .prepare
= via_dig_playback_pcm_prepare
,
1274 .cleanup
= via_dig_playback_pcm_cleanup
1278 static const struct hda_pcm_stream via_pcm_digital_capture
= {
1285 * slave controls for virtual master
1287 static const char * const via_slave_vols
[] = {
1288 "Front Playback Volume",
1289 "Surround Playback Volume",
1290 "Center Playback Volume",
1291 "LFE Playback Volume",
1292 "Side Playback Volume",
1293 "Headphone Playback Volume",
1294 "Speaker Playback Volume",
1298 static const char * const via_slave_sws
[] = {
1299 "Front Playback Switch",
1300 "Surround Playback Switch",
1301 "Center Playback Switch",
1302 "LFE Playback Switch",
1303 "Side Playback Switch",
1304 "Headphone Playback Switch",
1305 "Speaker Playback Switch",
1309 static int via_build_controls(struct hda_codec
*codec
)
1311 struct via_spec
*spec
= codec
->spec
;
1312 struct snd_kcontrol
*kctl
;
1315 if (spec
->set_widgets_power_state
)
1316 if (!via_clone_control(spec
, &via_pin_power_ctl_enum
))
1319 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1320 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1325 if (spec
->multiout
.dig_out_nid
) {
1326 err
= snd_hda_create_spdif_out_ctls(codec
,
1327 spec
->multiout
.dig_out_nid
,
1328 spec
->multiout
.dig_out_nid
);
1331 err
= snd_hda_create_spdif_share_sw(codec
,
1335 spec
->multiout
.share_spdif
= 1;
1337 if (spec
->dig_in_nid
) {
1338 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1343 /* if we have no master control, let's create it */
1344 if (!snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
1345 unsigned int vmaster_tlv
[4];
1346 snd_hda_set_vmaster_tlv(codec
, spec
->multiout
.dac_nids
[0],
1347 HDA_OUTPUT
, vmaster_tlv
);
1348 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
1349 vmaster_tlv
, via_slave_vols
);
1353 if (!snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
1354 err
= snd_hda_add_vmaster(codec
, "Master Playback Switch",
1355 NULL
, via_slave_sws
);
1360 /* assign Capture Source enums to NID */
1361 kctl
= snd_hda_find_mixer_ctl(codec
, "Input Source");
1362 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1363 err
= snd_hda_add_nid(codec
, kctl
, i
, spec
->mux_nids
[i
]);
1368 /* init power states */
1369 set_widgets_power_state(codec
);
1370 analog_low_current_mode(codec
);
1372 via_free_kctls(codec
); /* no longer needed */
1376 static int via_build_pcms(struct hda_codec
*codec
)
1378 struct via_spec
*spec
= codec
->spec
;
1379 struct hda_pcm
*info
= spec
->pcm_rec
;
1381 codec
->num_pcms
= 1;
1382 codec
->pcm_info
= info
;
1384 snprintf(spec
->stream_name_analog
, sizeof(spec
->stream_name_analog
),
1385 "%s Analog", codec
->chip_name
);
1386 info
->name
= spec
->stream_name_analog
;
1388 if (!spec
->stream_analog_playback
)
1389 spec
->stream_analog_playback
= &via_pcm_analog_playback
;
1390 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1391 *spec
->stream_analog_playback
;
1392 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1393 spec
->multiout
.dac_nids
[0];
1394 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
1395 spec
->multiout
.max_channels
;
1397 if (!spec
->stream_analog_capture
) {
1398 if (spec
->dyn_adc_switch
)
1399 spec
->stream_analog_capture
=
1400 &via_pcm_dyn_adc_analog_capture
;
1402 spec
->stream_analog_capture
= &via_pcm_analog_capture
;
1404 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
1405 *spec
->stream_analog_capture
;
1406 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
1407 if (!spec
->dyn_adc_switch
)
1408 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
1411 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
1414 snprintf(spec
->stream_name_digital
,
1415 sizeof(spec
->stream_name_digital
),
1416 "%s Digital", codec
->chip_name
);
1417 info
->name
= spec
->stream_name_digital
;
1418 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
1419 if (spec
->multiout
.dig_out_nid
) {
1420 if (!spec
->stream_digital_playback
)
1421 spec
->stream_digital_playback
=
1422 &via_pcm_digital_playback
;
1423 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1424 *spec
->stream_digital_playback
;
1425 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1426 spec
->multiout
.dig_out_nid
;
1428 if (spec
->dig_in_nid
) {
1429 if (!spec
->stream_digital_capture
)
1430 spec
->stream_digital_capture
=
1431 &via_pcm_digital_capture
;
1432 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
1433 *spec
->stream_digital_capture
;
1434 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
1439 if (spec
->hp_dac_nid
) {
1442 snprintf(spec
->stream_name_hp
, sizeof(spec
->stream_name_hp
),
1443 "%s HP", codec
->chip_name
);
1444 info
->name
= spec
->stream_name_hp
;
1445 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = via_pcm_hp_playback
;
1446 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1452 static void via_free(struct hda_codec
*codec
)
1454 struct via_spec
*spec
= codec
->spec
;
1459 via_free_kctls(codec
);
1460 vt1708_stop_hp_work(spec
);
1461 kfree(spec
->bind_cap_vol
);
1462 kfree(spec
->bind_cap_sw
);
1466 /* mute/unmute outputs */
1467 static void toggle_output_mutes(struct hda_codec
*codec
, int num_pins
,
1468 hda_nid_t
*pins
, bool mute
)
1471 for (i
= 0; i
< num_pins
; i
++)
1472 snd_hda_codec_write(codec
, pins
[i
], 0,
1473 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1474 mute
? 0 : PIN_OUT
);
1477 /* mute internal speaker if line-out is plugged */
1478 static void via_line_automute(struct hda_codec
*codec
, int present
)
1480 struct via_spec
*spec
= codec
->spec
;
1482 if (!spec
->autocfg
.speaker_outs
)
1485 present
= snd_hda_jack_detect(codec
,
1486 spec
->autocfg
.line_out_pins
[0]);
1487 toggle_output_mutes(codec
, spec
->autocfg
.speaker_outs
,
1488 spec
->autocfg
.speaker_pins
,
1492 /* mute internal speaker if HP is plugged */
1493 static void via_hp_automute(struct hda_codec
*codec
)
1496 struct via_spec
*spec
= codec
->spec
;
1498 if (!spec
->hp_independent_mode
&& spec
->autocfg
.hp_pins
[0]) {
1500 present
= snd_hda_jack_detect(codec
, spec
->autocfg
.hp_pins
[0]);
1501 if (spec
->smart51_enabled
)
1502 nums
= spec
->autocfg
.line_outs
+ spec
->smart51_nums
;
1504 nums
= spec
->autocfg
.line_outs
;
1505 toggle_output_mutes(codec
, nums
,
1506 spec
->autocfg
.line_out_pins
,
1509 via_line_automute(codec
, present
);
1512 static void via_gpio_control(struct hda_codec
*codec
)
1514 unsigned int gpio_data
;
1515 unsigned int vol_counter
;
1517 unsigned int master_vol
;
1519 struct via_spec
*spec
= codec
->spec
;
1521 gpio_data
= snd_hda_codec_read(codec
, codec
->afg
, 0,
1522 AC_VERB_GET_GPIO_DATA
, 0) & 0x03;
1524 vol_counter
= (snd_hda_codec_read(codec
, codec
->afg
, 0,
1525 0xF84, 0) & 0x3F0000) >> 16;
1527 vol
= vol_counter
& 0x1F;
1528 master_vol
= snd_hda_codec_read(codec
, 0x1A, 0,
1529 AC_VERB_GET_AMP_GAIN_MUTE
,
1532 if (gpio_data
== 0x02) {
1533 /* unmute line out */
1534 snd_hda_codec_write(codec
, spec
->autocfg
.line_out_pins
[0], 0,
1535 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1537 if (vol_counter
& 0x20) {
1538 /* decrease volume */
1539 if (vol
> master_vol
)
1541 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
,
1545 /* increase volume */
1546 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
, 0,
1548 ((master_vol
+vol
) > 0x2A) ? 0x2A :
1551 } else if (!(gpio_data
& 0x02)) {
1553 snd_hda_codec_write(codec
, spec
->autocfg
.line_out_pins
[0], 0,
1554 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1559 /* unsolicited event for jack sensing */
1560 static void via_unsol_event(struct hda_codec
*codec
,
1565 if (res
& VIA_JACK_EVENT
)
1566 set_widgets_power_state(codec
);
1568 res
&= ~VIA_JACK_EVENT
;
1570 if (res
== VIA_HP_EVENT
)
1571 via_hp_automute(codec
);
1572 else if (res
== VIA_GPIO_EVENT
)
1573 via_gpio_control(codec
);
1574 else if (res
== VIA_LINE_EVENT
)
1575 via_line_automute(codec
, false);
1578 #ifdef SND_HDA_NEEDS_RESUME
1579 static int via_suspend(struct hda_codec
*codec
, pm_message_t state
)
1581 struct via_spec
*spec
= codec
->spec
;
1582 vt1708_stop_hp_work(spec
);
1587 #ifdef CONFIG_SND_HDA_POWER_SAVE
1588 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
1590 struct via_spec
*spec
= codec
->spec
;
1591 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
1598 static int via_init(struct hda_codec
*codec
);
1600 static const struct hda_codec_ops via_patch_ops
= {
1601 .build_controls
= via_build_controls
,
1602 .build_pcms
= via_build_pcms
,
1605 .unsol_event
= via_unsol_event
,
1606 #ifdef SND_HDA_NEEDS_RESUME
1607 .suspend
= via_suspend
,
1609 #ifdef CONFIG_SND_HDA_POWER_SAVE
1610 .check_power_status
= via_check_power_status
,
1614 static bool is_empty_dac(struct hda_codec
*codec
, hda_nid_t dac
)
1616 struct via_spec
*spec
= codec
->spec
;
1619 for (i
= 0; i
< spec
->multiout
.num_dacs
; i
++) {
1620 if (spec
->multiout
.dac_nids
[i
] == dac
)
1623 if (spec
->hp_dac_nid
== dac
)
1628 static bool __parse_output_path(struct hda_codec
*codec
, hda_nid_t nid
,
1629 hda_nid_t target_dac
, struct nid_path
*path
,
1630 int depth
, int wid_type
)
1635 nums
= snd_hda_get_connections(codec
, nid
, conn
, ARRAY_SIZE(conn
));
1636 for (i
= 0; i
< nums
; i
++) {
1637 if (get_wcaps_type(get_wcaps(codec
, conn
[i
])) != AC_WID_AUD_OUT
)
1639 if (conn
[i
] == target_dac
|| is_empty_dac(codec
, conn
[i
]))
1642 if (depth
>= MAX_NID_PATH_DEPTH
)
1644 for (i
= 0; i
< nums
; i
++) {
1646 type
= get_wcaps_type(get_wcaps(codec
, conn
[i
]));
1647 if (type
== AC_WID_AUD_OUT
||
1648 (wid_type
!= -1 && type
!= wid_type
))
1650 if (__parse_output_path(codec
, conn
[i
], target_dac
,
1651 path
, depth
+ 1, AC_WID_AUD_SEL
))
1657 path
->path
[path
->depth
] = conn
[i
];
1658 path
->idx
[path
->depth
] = i
;
1659 if (nums
> 1 && get_wcaps_type(get_wcaps(codec
, nid
)) != AC_WID_AUD_MIX
)
1660 path
->multi
[path
->depth
] = 1;
1665 static bool parse_output_path(struct hda_codec
*codec
, hda_nid_t nid
,
1666 hda_nid_t target_dac
, struct nid_path
*path
)
1668 if (__parse_output_path(codec
, nid
, target_dac
, path
, 1, -1)) {
1669 path
->path
[path
->depth
] = nid
;
1676 static int via_auto_fill_dac_nids(struct hda_codec
*codec
)
1678 struct via_spec
*spec
= codec
->spec
;
1679 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1683 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1684 spec
->multiout
.num_dacs
= cfg
->line_outs
;
1685 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1686 nid
= cfg
->line_out_pins
[i
];
1689 if (parse_output_path(codec
, nid
, 0, &spec
->out_path
[i
]))
1690 spec
->private_dac_nids
[i
] = spec
->out_path
[i
].path
[0];
1695 static int create_ch_ctls(struct hda_codec
*codec
, const char *pfx
,
1696 int chs
, bool check_dac
, struct nid_path
*path
)
1698 struct via_spec
*spec
= codec
->spec
;
1700 hda_nid_t dac
, pin
, sel
, nid
;
1703 dac
= check_dac
? path
->path
[0] : 0;
1704 pin
= path
->path
[path
->depth
- 1];
1705 sel
= path
->depth
> 1 ? path
->path
[1] : 0;
1707 if (dac
&& check_amp_caps(codec
, dac
, HDA_OUTPUT
, AC_AMPCAP_NUM_STEPS
))
1709 else if (check_amp_caps(codec
, pin
, HDA_OUTPUT
, AC_AMPCAP_NUM_STEPS
))
1711 else if (check_amp_caps(codec
, sel
, HDA_OUTPUT
, AC_AMPCAP_NUM_STEPS
))
1716 sprintf(name
, "%s Playback Volume", pfx
);
1717 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1718 HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
));
1721 path
->vol_ctl
= nid
;
1724 if (dac
&& check_amp_caps(codec
, dac
, HDA_OUTPUT
, AC_AMPCAP_MUTE
))
1726 else if (check_amp_caps(codec
, pin
, HDA_OUTPUT
, AC_AMPCAP_MUTE
))
1728 else if (check_amp_caps(codec
, sel
, HDA_OUTPUT
, AC_AMPCAP_MUTE
))
1733 sprintf(name
, "%s Playback Switch", pfx
);
1734 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1735 HDA_COMPOSE_AMP_VAL(nid
, chs
, 0, HDA_OUTPUT
));
1738 path
->mute_ctl
= nid
;
1743 static void mangle_smart51(struct hda_codec
*codec
)
1745 struct via_spec
*spec
= codec
->spec
;
1746 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1747 struct auto_pin_cfg_item
*ins
= cfg
->inputs
;
1748 int i
, j
, nums
, attr
;
1749 int pins
[AUTO_CFG_MAX_INS
];
1751 for (attr
= INPUT_PIN_ATTR_REAR
; attr
>= INPUT_PIN_ATTR_NORMAL
; attr
--) {
1753 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1755 if (ins
[i
].type
> AUTO_PIN_LINE_IN
)
1757 def
= snd_hda_codec_get_pincfg(codec
, ins
[i
].pin
);
1758 if (snd_hda_get_input_pin_attr(def
) != attr
)
1760 for (j
= 0; j
< nums
; j
++)
1761 if (ins
[pins
[j
]].type
< ins
[i
].type
) {
1762 memmove(pins
+ j
+ 1, pins
+ j
,
1763 (nums
- j
- 1) * sizeof(int));
1769 if (cfg
->line_outs
+ nums
< 3)
1771 for (i
= 0; i
< nums
; i
++) {
1772 hda_nid_t pin
= ins
[pins
[i
]].pin
;
1773 spec
->smart51_pins
[spec
->smart51_nums
++] = pin
;
1774 cfg
->line_out_pins
[cfg
->line_outs
++] = pin
;
1775 if (cfg
->line_outs
== 3)
1782 /* add playback controls from the parsed DAC table */
1783 static int via_auto_create_multi_out_ctls(struct hda_codec
*codec
)
1785 struct via_spec
*spec
= codec
->spec
;
1786 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1787 static const char * const chname
[4] = {
1788 "Front", "Surround", "C/LFE", "Side"
1794 old_line_outs
= cfg
->line_outs
;
1795 if (cfg
->line_outs
== 1)
1796 mangle_smart51(codec
);
1798 err
= via_auto_fill_dac_nids(codec
);
1802 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1804 pin
= cfg
->line_out_pins
[i
];
1805 dac
= spec
->multiout
.dac_nids
[i
];
1808 if (i
== HDA_CLFE
) {
1809 err
= create_ch_ctls(codec
, "Center", 1, true,
1810 &spec
->out_path
[i
]);
1813 err
= create_ch_ctls(codec
, "LFE", 2, true,
1814 &spec
->out_path
[i
]);
1818 const char *pfx
= chname
[i
];
1819 if (cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
1820 cfg
->line_outs
== 1)
1822 err
= create_ch_ctls(codec
, pfx
, 3, true,
1823 &spec
->out_path
[i
]);
1829 idx
= get_connection_index(codec
, spec
->aa_mix_nid
,
1830 spec
->multiout
.dac_nids
[0]);
1831 if (idx
< 0 && spec
->dac_mixer_idx
)
1832 idx
= spec
->dac_mixer_idx
;
1834 /* add control to mixer */
1835 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1836 "PCM Playback Volume",
1837 HDA_COMPOSE_AMP_VAL(spec
->aa_mix_nid
, 3,
1841 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1842 "PCM Playback Switch",
1843 HDA_COMPOSE_AMP_VAL(spec
->aa_mix_nid
, 3,
1849 cfg
->line_outs
= old_line_outs
;
1854 static int via_auto_create_hp_ctls(struct hda_codec
*codec
, hda_nid_t pin
)
1856 struct via_spec
*spec
= codec
->spec
;
1857 struct nid_path
*path
;
1864 if (parse_output_path(codec
, pin
, 0, &spec
->hp_path
))
1865 spec
->hp_dac_nid
= spec
->hp_path
.path
[0];
1866 else if (spec
->multiout
.dac_nids
[HDA_SIDE
] &&
1867 parse_output_path(codec
, pin
,
1868 spec
->multiout
.dac_nids
[HDA_SIDE
],
1870 spec
->hp_dac_nid
= spec
->hp_path
.path
[0];
1871 spec
->hp_indep_shared
= true;
1874 if (!parse_output_path(codec
, pin
, spec
->multiout
.dac_nids
[HDA_FRONT
],
1875 &spec
->hp_dep_path
) &&
1879 if (spec
->hp_dac_nid
&& !spec
->hp_indep_shared
) {
1880 path
= &spec
->hp_path
;
1883 path
= &spec
->hp_dep_path
;
1886 err
= create_ch_ctls(codec
, "Headphone", 3, check_dac
, path
);
1889 if (spec
->hp_dac_nid
) {
1890 spec
->hp_dep_path
.vol_ctl
= spec
->hp_path
.vol_ctl
;
1891 spec
->hp_dep_path
.mute_ctl
= spec
->hp_path
.mute_ctl
;
1897 static int via_auto_create_speaker_ctls(struct hda_codec
*codec
)
1899 struct via_spec
*spec
= codec
->spec
;
1902 pin
= spec
->autocfg
.speaker_pins
[0];
1903 if (!spec
->autocfg
.speaker_outs
|| !pin
)
1906 if (parse_output_path(codec
, pin
, 0, &spec
->speaker_path
)) {
1907 dac
= spec
->speaker_path
.path
[0];
1908 spec
->multiout
.extra_out_nid
[0] = dac
;
1909 return create_ch_ctls(codec
, "Speaker", 3, true,
1910 &spec
->speaker_path
);
1912 if (parse_output_path(codec
, pin
, spec
->multiout
.dac_nids
[HDA_FRONT
],
1913 &spec
->speaker_path
))
1914 return create_ch_ctls(codec
, "Speaker", 3, false,
1915 &spec
->speaker_path
);
1921 static int via_fill_adcs(struct hda_codec
*codec
)
1923 struct via_spec
*spec
= codec
->spec
;
1924 hda_nid_t nid
= codec
->start_nid
;
1927 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
1928 unsigned int wcaps
= get_wcaps(codec
, nid
);
1929 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
1931 if (wcaps
& AC_WCAP_DIGITAL
)
1933 if (!(wcaps
& AC_WCAP_CONN_LIST
))
1935 if (spec
->num_adc_nids
>= ARRAY_SIZE(spec
->adc_nids
))
1937 spec
->adc_nids
[spec
->num_adc_nids
++] = nid
;
1942 /* input-src control */
1943 static int via_mux_enum_info(struct snd_kcontrol
*kcontrol
,
1944 struct snd_ctl_elem_info
*uinfo
)
1946 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1947 struct via_spec
*spec
= codec
->spec
;
1949 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1951 uinfo
->value
.enumerated
.items
= spec
->num_inputs
;
1952 if (uinfo
->value
.enumerated
.item
>= spec
->num_inputs
)
1953 uinfo
->value
.enumerated
.item
= spec
->num_inputs
- 1;
1954 strcpy(uinfo
->value
.enumerated
.name
,
1955 spec
->inputs
[uinfo
->value
.enumerated
.item
].label
);
1959 static int via_mux_enum_get(struct snd_kcontrol
*kcontrol
,
1960 struct snd_ctl_elem_value
*ucontrol
)
1962 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1963 struct via_spec
*spec
= codec
->spec
;
1964 unsigned int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1966 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[idx
];
1970 static int via_mux_enum_put(struct snd_kcontrol
*kcontrol
,
1971 struct snd_ctl_elem_value
*ucontrol
)
1973 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1974 struct via_spec
*spec
= codec
->spec
;
1975 unsigned int idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1979 cur
= ucontrol
->value
.enumerated
.item
[0];
1980 if (cur
< 0 || cur
>= spec
->num_inputs
)
1982 if (spec
->cur_mux
[idx
] == cur
)
1984 spec
->cur_mux
[idx
] = cur
;
1985 if (spec
->dyn_adc_switch
) {
1986 int adc_idx
= spec
->inputs
[cur
].adc_idx
;
1987 mux
= spec
->mux_nids
[adc_idx
];
1988 via_dyn_adc_pcm_resetup(codec
, cur
);
1990 mux
= spec
->mux_nids
[idx
];
1991 if (snd_BUG_ON(!mux
))
1996 /* switch to D0 beofre change index */
1997 if (snd_hda_codec_read(codec
, mux
, 0,
1998 AC_VERB_GET_POWER_STATE
, 0x00) != AC_PWRST_D0
)
1999 snd_hda_codec_write(codec
, mux
, 0,
2000 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
2001 snd_hda_codec_write(codec
, mux
, 0,
2002 AC_VERB_SET_CONNECT_SEL
,
2003 spec
->inputs
[cur
].mux_idx
);
2006 /* update jack power state */
2007 set_widgets_power_state(codec
);
2011 static const struct snd_kcontrol_new via_input_src_ctl
= {
2012 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2013 /* The multiple "Capture Source" controls confuse alsamixer
2014 * So call somewhat different..
2016 /* .name = "Capture Source", */
2017 .name
= "Input Source",
2018 .info
= via_mux_enum_info
,
2019 .get
= via_mux_enum_get
,
2020 .put
= via_mux_enum_put
,
2023 static int create_input_src_ctls(struct hda_codec
*codec
, int count
)
2025 struct via_spec
*spec
= codec
->spec
;
2026 struct snd_kcontrol_new
*knew
;
2028 if (spec
->num_inputs
<= 1 || !count
)
2029 return 0; /* no need for single src */
2031 knew
= via_clone_control(spec
, &via_input_src_ctl
);
2034 knew
->count
= count
;
2038 /* add the powersave loopback-list entry */
2039 static void add_loopback_list(struct via_spec
*spec
, hda_nid_t mix
, int idx
)
2041 struct hda_amp_list
*list
;
2043 if (spec
->num_loopbacks
>= ARRAY_SIZE(spec
->loopback_list
) - 1)
2045 list
= spec
->loopback_list
+ spec
->num_loopbacks
;
2047 list
->dir
= HDA_INPUT
;
2049 spec
->num_loopbacks
++;
2050 spec
->loopback
.amplist
= spec
->loopback_list
;
2053 static bool is_reachable_nid(struct hda_codec
*codec
, hda_nid_t src
,
2056 return snd_hda_get_conn_index(codec
, src
, dst
, 1) >= 0;
2059 /* add the input-route to the given pin */
2060 static bool add_input_route(struct hda_codec
*codec
, hda_nid_t pin
)
2062 struct via_spec
*spec
= codec
->spec
;
2065 spec
->inputs
[spec
->num_inputs
].adc_idx
= -1;
2066 spec
->inputs
[spec
->num_inputs
].pin
= pin
;
2067 for (c
= 0; c
< spec
->num_adc_nids
; c
++) {
2068 if (spec
->mux_nids
[c
]) {
2069 idx
= get_connection_index(codec
, spec
->mux_nids
[c
],
2073 spec
->inputs
[spec
->num_inputs
].mux_idx
= idx
;
2075 if (!is_reachable_nid(codec
, spec
->adc_nids
[c
], pin
))
2078 spec
->inputs
[spec
->num_inputs
].adc_idx
= c
;
2079 /* Can primary ADC satisfy all inputs? */
2080 if (!spec
->dyn_adc_switch
&&
2081 spec
->num_inputs
> 0 && spec
->inputs
[0].adc_idx
!= c
) {
2082 snd_printd(KERN_INFO
2083 "via: dynamic ADC switching enabled\n");
2084 spec
->dyn_adc_switch
= 1;
2091 static int get_mux_nids(struct hda_codec
*codec
);
2093 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2094 static int parse_analog_inputs(struct hda_codec
*codec
)
2096 struct via_spec
*spec
= codec
->spec
;
2097 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2100 err
= via_fill_adcs(codec
);
2103 err
= get_mux_nids(codec
);
2107 /* fill all input-routes */
2108 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2109 if (add_input_route(codec
, cfg
->inputs
[i
].pin
))
2110 spec
->inputs
[spec
->num_inputs
++].label
=
2111 hda_get_autocfg_input_label(codec
, cfg
, i
);
2114 /* check for internal loopback recording */
2115 if (spec
->aa_mix_nid
&&
2116 add_input_route(codec
, spec
->aa_mix_nid
))
2117 spec
->inputs
[spec
->num_inputs
++].label
= "Stereo Mixer";
2122 /* create analog-loopback volume/switch controls */
2123 static int create_loopback_ctls(struct hda_codec
*codec
)
2125 struct via_spec
*spec
= codec
->spec
;
2126 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2127 const char *prev_label
= NULL
;
2131 if (!spec
->aa_mix_nid
)
2134 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2135 hda_nid_t pin
= cfg
->inputs
[i
].pin
;
2136 const char *label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
2138 if (prev_label
&& !strcmp(label
, prev_label
))
2143 idx
= get_connection_index(codec
, spec
->aa_mix_nid
, pin
);
2145 err
= via_new_analog_input(spec
, label
, type_idx
,
2146 idx
, spec
->aa_mix_nid
);
2149 add_loopback_list(spec
, spec
->aa_mix_nid
, idx
);
2152 /* remember the label for smart51 control */
2153 for (j
= 0; j
< spec
->smart51_nums
; j
++) {
2154 if (spec
->smart51_pins
[j
] == pin
) {
2155 spec
->smart51_idxs
[j
] = idx
;
2156 spec
->smart51_labels
[j
] = label
;
2164 /* create mic-boost controls (if present) */
2165 static int create_mic_boost_ctls(struct hda_codec
*codec
)
2167 struct via_spec
*spec
= codec
->spec
;
2168 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2171 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2172 hda_nid_t pin
= cfg
->inputs
[i
].pin
;
2177 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
2179 caps
= query_amp_caps(codec
, pin
, HDA_INPUT
);
2180 if (caps
== -1 || !(caps
& AC_AMPCAP_NUM_STEPS
))
2182 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
2183 snprintf(name
, sizeof(name
), "%s Boost Volume", label
);
2184 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2185 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_INPUT
));
2192 /* create capture and input-src controls for multiple streams */
2193 static int create_multi_adc_ctls(struct hda_codec
*codec
)
2195 struct via_spec
*spec
= codec
->spec
;
2198 /* create capture mixer elements */
2199 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
2200 hda_nid_t adc
= spec
->adc_nids
[i
];
2201 err
= __via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2202 "Capture Volume", i
,
2203 HDA_COMPOSE_AMP_VAL(adc
, 3, 0,
2207 err
= __via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2208 "Capture Switch", i
,
2209 HDA_COMPOSE_AMP_VAL(adc
, 3, 0,
2215 /* input-source control */
2216 for (i
= 0; i
< spec
->num_adc_nids
; i
++)
2217 if (!spec
->mux_nids
[i
])
2219 err
= create_input_src_ctls(codec
, i
);
2225 /* bind capture volume/switch */
2226 static struct snd_kcontrol_new via_bind_cap_vol_ctl
=
2227 HDA_BIND_VOL("Capture Volume", 0);
2228 static struct snd_kcontrol_new via_bind_cap_sw_ctl
=
2229 HDA_BIND_SW("Capture Switch", 0);
2231 static int init_bind_ctl(struct via_spec
*spec
, struct hda_bind_ctls
**ctl_ret
,
2232 struct hda_ctl_ops
*ops
)
2234 struct hda_bind_ctls
*ctl
;
2237 ctl
= kzalloc(sizeof(*ctl
) + sizeof(long) * 4, GFP_KERNEL
);
2241 for (i
= 0; i
< spec
->num_adc_nids
; i
++)
2243 HDA_COMPOSE_AMP_VAL(spec
->adc_nids
[i
], 3, 0, HDA_INPUT
);
2248 /* create capture and input-src controls for dynamic ADC-switch case */
2249 static int create_dyn_adc_ctls(struct hda_codec
*codec
)
2251 struct via_spec
*spec
= codec
->spec
;
2252 struct snd_kcontrol_new
*knew
;
2255 /* set up the bind capture ctls */
2256 err
= init_bind_ctl(spec
, &spec
->bind_cap_vol
, &snd_hda_bind_vol
);
2259 err
= init_bind_ctl(spec
, &spec
->bind_cap_sw
, &snd_hda_bind_sw
);
2263 /* create capture mixer elements */
2264 knew
= via_clone_control(spec
, &via_bind_cap_vol_ctl
);
2267 knew
->private_value
= (long)spec
->bind_cap_vol
;
2269 knew
= via_clone_control(spec
, &via_bind_cap_sw_ctl
);
2272 knew
->private_value
= (long)spec
->bind_cap_sw
;
2274 /* input-source control */
2275 err
= create_input_src_ctls(codec
, 1);
2281 /* parse and create capture-related stuff */
2282 static int via_auto_create_analog_input_ctls(struct hda_codec
*codec
)
2284 struct via_spec
*spec
= codec
->spec
;
2287 err
= parse_analog_inputs(codec
);
2290 if (spec
->dyn_adc_switch
)
2291 err
= create_dyn_adc_ctls(codec
);
2293 err
= create_multi_adc_ctls(codec
);
2296 err
= create_loopback_ctls(codec
);
2299 err
= create_mic_boost_ctls(codec
);
2305 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
2307 unsigned int def_conf
;
2308 unsigned char seqassoc
;
2310 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
2311 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
2312 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
2313 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
2314 && (seqassoc
== 0xf0 || seqassoc
== 0xff)) {
2315 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
2316 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
2322 static int vt1708_jack_detect_get(struct snd_kcontrol
*kcontrol
,
2323 struct snd_ctl_elem_value
*ucontrol
)
2325 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2326 struct via_spec
*spec
= codec
->spec
;
2328 if (spec
->codec_type
!= VT1708
)
2330 spec
->vt1708_jack_detect
=
2331 !((snd_hda_codec_read(codec
, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2332 ucontrol
->value
.integer
.value
[0] = spec
->vt1708_jack_detect
;
2336 static int vt1708_jack_detect_put(struct snd_kcontrol
*kcontrol
,
2337 struct snd_ctl_elem_value
*ucontrol
)
2339 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2340 struct via_spec
*spec
= codec
->spec
;
2343 if (spec
->codec_type
!= VT1708
)
2345 spec
->vt1708_jack_detect
= ucontrol
->value
.integer
.value
[0];
2346 change
= (0x1 & (snd_hda_codec_read(codec
, 0x1, 0, 0xf84, 0) >> 8))
2347 == !spec
->vt1708_jack_detect
;
2348 if (spec
->vt1708_jack_detect
) {
2349 mute_aa_path(codec
, 1);
2350 notify_aa_path_ctls(codec
);
2355 static const struct snd_kcontrol_new vt1708_jack_detect_ctl
= {
2356 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2357 .name
= "Jack Detect",
2359 .info
= snd_ctl_boolean_mono_info
,
2360 .get
= vt1708_jack_detect_get
,
2361 .put
= vt1708_jack_detect_put
,
2364 static void fill_dig_outs(struct hda_codec
*codec
);
2365 static void fill_dig_in(struct hda_codec
*codec
);
2367 static int via_parse_auto_config(struct hda_codec
*codec
)
2369 struct via_spec
*spec
= codec
->spec
;
2372 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2375 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2378 err
= via_auto_create_multi_out_ctls(codec
);
2381 err
= via_auto_create_hp_ctls(codec
, spec
->autocfg
.hp_pins
[0]);
2384 err
= via_auto_create_speaker_ctls(codec
);
2387 err
= via_auto_create_analog_input_ctls(codec
);
2391 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2393 fill_dig_outs(codec
);
2396 if (spec
->kctls
.list
)
2397 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2400 if (spec
->hp_dac_nid
&& spec
->hp_dep_path
.depth
) {
2401 err
= via_hp_build(codec
);
2406 err
= via_smart51_build(codec
);
2410 /* assign slave outs */
2411 if (spec
->slave_dig_outs
[0])
2412 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
2417 static void via_auto_init_dig_outs(struct hda_codec
*codec
)
2419 struct via_spec
*spec
= codec
->spec
;
2420 if (spec
->multiout
.dig_out_nid
)
2421 init_output_pin(codec
, spec
->autocfg
.dig_out_pins
[0], PIN_OUT
);
2422 if (spec
->slave_dig_outs
[0])
2423 init_output_pin(codec
, spec
->autocfg
.dig_out_pins
[1], PIN_OUT
);
2426 static void via_auto_init_dig_in(struct hda_codec
*codec
)
2428 struct via_spec
*spec
= codec
->spec
;
2429 if (!spec
->dig_in_nid
)
2431 snd_hda_codec_write(codec
, spec
->autocfg
.dig_in_pin
, 0,
2432 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
2435 /* initialize the unsolicited events */
2436 static void via_auto_init_unsol_event(struct hda_codec
*codec
)
2438 struct via_spec
*spec
= codec
->spec
;
2439 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2443 if (cfg
->hp_pins
[0] && is_jack_detectable(codec
, cfg
->hp_pins
[0]))
2444 snd_hda_codec_write(codec
, cfg
->hp_pins
[0], 0,
2445 AC_VERB_SET_UNSOLICITED_ENABLE
,
2446 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
);
2448 if (cfg
->speaker_pins
[0])
2449 ev
= VIA_LINE_EVENT
;
2452 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2453 if (cfg
->line_out_pins
[i
] &&
2454 is_jack_detectable(codec
, cfg
->line_out_pins
[i
]))
2455 snd_hda_codec_write(codec
, cfg
->line_out_pins
[i
], 0,
2456 AC_VERB_SET_UNSOLICITED_ENABLE
,
2457 AC_USRSP_EN
| ev
| VIA_JACK_EVENT
);
2460 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
2461 if (is_jack_detectable(codec
, cfg
->inputs
[i
].pin
))
2462 snd_hda_codec_write(codec
, cfg
->inputs
[i
].pin
, 0,
2463 AC_VERB_SET_UNSOLICITED_ENABLE
,
2464 AC_USRSP_EN
| VIA_JACK_EVENT
);
2468 static int via_init(struct hda_codec
*codec
)
2470 struct via_spec
*spec
= codec
->spec
;
2473 for (i
= 0; i
< spec
->num_iverbs
; i
++)
2474 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
2476 via_auto_init_multi_out(codec
);
2477 via_auto_init_hp_out(codec
);
2478 via_auto_init_speaker_out(codec
);
2479 via_auto_init_analog_input(codec
);
2480 via_auto_init_dig_outs(codec
);
2481 via_auto_init_dig_in(codec
);
2483 via_auto_init_unsol_event(codec
);
2485 via_hp_automute(codec
);
2486 via_line_automute(codec
, false);
2491 static void vt1708_update_hp_jack_state(struct work_struct
*work
)
2493 struct via_spec
*spec
= container_of(work
, struct via_spec
,
2494 vt1708_hp_work
.work
);
2495 if (spec
->codec_type
!= VT1708
)
2497 /* if jack state toggled */
2498 if (spec
->vt1708_hp_present
2499 != snd_hda_jack_detect(spec
->codec
, spec
->autocfg
.hp_pins
[0])) {
2500 spec
->vt1708_hp_present
^= 1;
2501 via_hp_automute(spec
->codec
);
2503 vt1708_start_hp_work(spec
);
2506 static int get_mux_nids(struct hda_codec
*codec
)
2508 struct via_spec
*spec
= codec
->spec
;
2509 hda_nid_t nid
, conn
[8];
2513 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
2514 nid
= spec
->adc_nids
[i
];
2516 type
= get_wcaps_type(get_wcaps(codec
, nid
));
2517 if (type
== AC_WID_PIN
)
2519 n
= snd_hda_get_connections(codec
, nid
, conn
,
2524 spec
->mux_nids
[i
] = nid
;
2533 static int patch_vt1708(struct hda_codec
*codec
)
2535 struct via_spec
*spec
;
2538 /* create a codec specific record */
2539 spec
= via_new_spec(codec
);
2543 spec
->aa_mix_nid
= 0x17;
2545 /* Add HP and CD pin config connect bit re-config action */
2546 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
2547 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
2549 /* automatic parse from the BIOS config */
2550 err
= via_parse_auto_config(codec
);
2556 /* add jack detect on/off control */
2557 if (!via_clone_control(spec
, &vt1708_jack_detect_ctl
))
2560 /* disable 32bit format on VT1708 */
2561 if (codec
->vendor_id
== 0x11061708)
2562 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
2564 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_init_verbs
;
2566 codec
->patch_ops
= via_patch_ops
;
2568 INIT_DELAYED_WORK(&spec
->vt1708_hp_work
, vt1708_update_hp_jack_state
);
2572 static int patch_vt1709(struct hda_codec
*codec
)
2574 struct via_spec
*spec
;
2577 /* create a codec specific record */
2578 spec
= via_new_spec(codec
);
2582 spec
->aa_mix_nid
= 0x18;
2584 err
= via_parse_auto_config(codec
);
2590 codec
->patch_ops
= via_patch_ops
;
2595 static void set_widgets_power_state_vt1708B(struct hda_codec
*codec
)
2597 struct via_spec
*spec
= codec
->spec
;
2601 if ((spec
->codec_type
!= VT1708B_4CH
) &&
2602 (codec
->vendor_id
!= 0x11064397))
2605 /* SW0 (17h) = stereo mixer */
2607 (snd_hda_codec_read(codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00)
2608 == ((spec
->codec_type
== VT1708S
) ? 5 : 0));
2610 /* PW 1/2/5 (1ah/1bh/1eh) */
2612 set_pin_power_state(codec
, 0x1a, &parm
);
2613 set_pin_power_state(codec
, 0x1b, &parm
);
2614 set_pin_power_state(codec
, 0x1e, &parm
);
2617 /* SW0 (17h), AIW 0/1 (13h/14h) */
2618 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_POWER_STATE
, parm
);
2619 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
, parm
);
2620 snd_hda_codec_write(codec
, 0x14, 0, AC_VERB_SET_POWER_STATE
, parm
);
2623 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2625 set_pin_power_state(codec
, 0x19, &parm
);
2626 if (spec
->smart51_enabled
)
2627 set_pin_power_state(codec
, 0x1b, &parm
);
2628 snd_hda_codec_write(codec
, 0x18, 0, AC_VERB_SET_POWER_STATE
, parm
);
2629 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
, parm
);
2631 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2634 set_pin_power_state(codec
, 0x22, &parm
);
2635 if (spec
->smart51_enabled
)
2636 set_pin_power_state(codec
, 0x1a, &parm
);
2637 snd_hda_codec_write(codec
, 0x26, 0,
2638 AC_VERB_SET_POWER_STATE
, parm
);
2639 snd_hda_codec_write(codec
, 0x24, 0,
2640 AC_VERB_SET_POWER_STATE
, parm
);
2641 } else if (codec
->vendor_id
== 0x11064397) {
2642 /* PW7(23h), SW2(27h), AOW2(25h) */
2644 set_pin_power_state(codec
, 0x23, &parm
);
2645 if (spec
->smart51_enabled
)
2646 set_pin_power_state(codec
, 0x1a, &parm
);
2647 snd_hda_codec_write(codec
, 0x27, 0,
2648 AC_VERB_SET_POWER_STATE
, parm
);
2649 snd_hda_codec_write(codec
, 0x25, 0,
2650 AC_VERB_SET_POWER_STATE
, parm
);
2653 /* PW 3/4/7 (1ch/1dh/23h) */
2655 /* force to D0 for internal Speaker */
2656 set_pin_power_state(codec
, 0x1c, &parm
);
2657 set_pin_power_state(codec
, 0x1d, &parm
);
2659 set_pin_power_state(codec
, 0x23, &parm
);
2661 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2662 snd_hda_codec_write(codec
, 0x16, 0, AC_VERB_SET_POWER_STATE
,
2663 imux_is_smixer
? AC_PWRST_D0
: parm
);
2664 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
, parm
);
2666 snd_hda_codec_write(codec
, 0x25, 0,
2667 AC_VERB_SET_POWER_STATE
, parm
);
2668 snd_hda_codec_write(codec
, 0x27, 0,
2669 AC_VERB_SET_POWER_STATE
, parm
);
2670 } else if (codec
->vendor_id
== 0x11064397 && spec
->hp_independent_mode
)
2671 snd_hda_codec_write(codec
, 0x25, 0,
2672 AC_VERB_SET_POWER_STATE
, parm
);
2675 static int patch_vt1708S(struct hda_codec
*codec
);
2676 static int patch_vt1708B(struct hda_codec
*codec
)
2678 struct via_spec
*spec
;
2681 if (get_codec_type(codec
) == VT1708BCE
)
2682 return patch_vt1708S(codec
);
2684 /* create a codec specific record */
2685 spec
= via_new_spec(codec
);
2689 spec
->aa_mix_nid
= 0x16;
2691 /* automatic parse from the BIOS config */
2692 err
= via_parse_auto_config(codec
);
2698 codec
->patch_ops
= via_patch_ops
;
2700 spec
->set_widgets_power_state
= set_widgets_power_state_vt1708B
;
2705 /* Patch for VT1708S */
2706 static const struct hda_verb vt1708S_init_verbs
[] = {
2707 /* Enable Mic Boost Volume backdoor */
2709 /* don't bybass mixer */
2714 /* fill out digital output widgets; one for master and one for slave outputs */
2715 static void fill_dig_outs(struct hda_codec
*codec
)
2717 struct via_spec
*spec
= codec
->spec
;
2720 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
2724 nid
= spec
->autocfg
.dig_out_pins
[i
];
2727 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
2730 if (!spec
->multiout
.dig_out_nid
)
2731 spec
->multiout
.dig_out_nid
= nid
;
2733 spec
->slave_dig_outs
[0] = nid
;
2734 break; /* at most two dig outs */
2739 static void fill_dig_in(struct hda_codec
*codec
)
2741 struct via_spec
*spec
= codec
->spec
;
2745 if (!spec
->autocfg
.dig_in_pin
)
2748 dig_nid
= codec
->start_nid
;
2749 for (i
= 0; i
< codec
->num_nodes
; i
++, dig_nid
++) {
2750 unsigned int wcaps
= get_wcaps(codec
, dig_nid
);
2751 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
2753 if (!(wcaps
& AC_WCAP_DIGITAL
))
2755 if (!(wcaps
& AC_WCAP_CONN_LIST
))
2757 err
= get_connection_index(codec
, dig_nid
,
2758 spec
->autocfg
.dig_in_pin
);
2760 spec
->dig_in_nid
= dig_nid
;
2766 static void override_mic_boost(struct hda_codec
*codec
, hda_nid_t pin
,
2767 int offset
, int num_steps
, int step_size
)
2769 snd_hda_override_amp_caps(codec
, pin
, HDA_INPUT
,
2770 (offset
<< AC_AMPCAP_OFFSET_SHIFT
) |
2771 (num_steps
<< AC_AMPCAP_NUM_STEPS_SHIFT
) |
2772 (step_size
<< AC_AMPCAP_STEP_SIZE_SHIFT
) |
2773 (0 << AC_AMPCAP_MUTE_SHIFT
));
2776 static int patch_vt1708S(struct hda_codec
*codec
)
2778 struct via_spec
*spec
;
2781 /* create a codec specific record */
2782 spec
= via_new_spec(codec
);
2786 spec
->aa_mix_nid
= 0x16;
2787 override_mic_boost(codec
, 0x1a, 0, 3, 40);
2788 override_mic_boost(codec
, 0x1e, 0, 3, 40);
2790 /* automatic parse from the BIOS config */
2791 err
= via_parse_auto_config(codec
);
2797 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_init_verbs
;
2799 codec
->patch_ops
= via_patch_ops
;
2801 /* correct names for VT1708BCE */
2802 if (get_codec_type(codec
) == VT1708BCE
) {
2803 kfree(codec
->chip_name
);
2804 codec
->chip_name
= kstrdup("VT1708BCE", GFP_KERNEL
);
2805 snprintf(codec
->bus
->card
->mixername
,
2806 sizeof(codec
->bus
->card
->mixername
),
2807 "%s %s", codec
->vendor_name
, codec
->chip_name
);
2809 /* correct names for VT1705 */
2810 if (codec
->vendor_id
== 0x11064397) {
2811 kfree(codec
->chip_name
);
2812 codec
->chip_name
= kstrdup("VT1705", GFP_KERNEL
);
2813 snprintf(codec
->bus
->card
->mixername
,
2814 sizeof(codec
->bus
->card
->mixername
),
2815 "%s %s", codec
->vendor_name
, codec
->chip_name
);
2817 spec
->set_widgets_power_state
= set_widgets_power_state_vt1708B
;
2821 /* Patch for VT1702 */
2823 static const struct hda_verb vt1702_init_verbs
[] = {
2831 static void set_widgets_power_state_vt1702(struct hda_codec
*codec
)
2833 int imux_is_smixer
=
2834 snd_hda_codec_read(codec
, 0x13, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
2837 /* PW 1/2/5 (14h/15h/18h) */
2839 set_pin_power_state(codec
, 0x14, &parm
);
2840 set_pin_power_state(codec
, 0x15, &parm
);
2841 set_pin_power_state(codec
, 0x18, &parm
);
2843 parm
= AC_PWRST_D0
; /* SW0 (13h) = stereo mixer (idx 3) */
2844 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
2845 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
, parm
);
2846 snd_hda_codec_write(codec
, 0x12, 0, AC_VERB_SET_POWER_STATE
, parm
);
2847 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
, parm
);
2848 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_POWER_STATE
, parm
);
2851 /* PW 3/4 (16h/17h) */
2853 set_pin_power_state(codec
, 0x17, &parm
);
2854 set_pin_power_state(codec
, 0x16, &parm
);
2855 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
2856 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_POWER_STATE
,
2857 imux_is_smixer
? AC_PWRST_D0
: parm
);
2858 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
, parm
);
2859 snd_hda_codec_write(codec
, 0x1d, 0, AC_VERB_SET_POWER_STATE
, parm
);
2862 static int patch_vt1702(struct hda_codec
*codec
)
2864 struct via_spec
*spec
;
2867 /* create a codec specific record */
2868 spec
= via_new_spec(codec
);
2872 spec
->aa_mix_nid
= 0x1a;
2874 /* limit AA path volume to 0 dB */
2875 snd_hda_override_amp_caps(codec
, 0x1A, HDA_INPUT
,
2876 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
2877 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
2878 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
2879 (1 << AC_AMPCAP_MUTE_SHIFT
));
2881 /* automatic parse from the BIOS config */
2882 err
= via_parse_auto_config(codec
);
2888 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_init_verbs
;
2890 codec
->patch_ops
= via_patch_ops
;
2892 spec
->set_widgets_power_state
= set_widgets_power_state_vt1702
;
2896 /* Patch for VT1718S */
2898 static const struct hda_verb vt1718S_init_verbs
[] = {
2899 /* Enable MW0 adjust Gain 5 */
2901 /* Enable Boost Volume backdoor */
2907 static void set_widgets_power_state_vt1718S(struct hda_codec
*codec
)
2909 struct via_spec
*spec
= codec
->spec
;
2912 /* MUX6 (1eh) = stereo mixer */
2914 snd_hda_codec_read(codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
2916 /* PW 5/6/7 (29h/2ah/2bh) */
2918 set_pin_power_state(codec
, 0x29, &parm
);
2919 set_pin_power_state(codec
, 0x2a, &parm
);
2920 set_pin_power_state(codec
, 0x2b, &parm
);
2923 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
2924 snd_hda_codec_write(codec
, 0x1e, 0, AC_VERB_SET_POWER_STATE
, parm
);
2925 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
, parm
);
2926 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
, parm
);
2927 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
, parm
);
2930 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
2932 set_pin_power_state(codec
, 0x27, &parm
);
2933 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_POWER_STATE
, parm
);
2934 snd_hda_codec_write(codec
, 0xb, 0, AC_VERB_SET_POWER_STATE
, parm
);
2936 /* PW2 (26h), AOW2 (ah) */
2938 set_pin_power_state(codec
, 0x26, &parm
);
2939 if (spec
->smart51_enabled
)
2940 set_pin_power_state(codec
, 0x2b, &parm
);
2941 snd_hda_codec_write(codec
, 0xa, 0, AC_VERB_SET_POWER_STATE
, parm
);
2943 /* PW0 (24h), AOW0 (8h) */
2945 set_pin_power_state(codec
, 0x24, &parm
);
2946 if (!spec
->hp_independent_mode
) /* check for redirected HP */
2947 set_pin_power_state(codec
, 0x28, &parm
);
2948 snd_hda_codec_write(codec
, 0x8, 0, AC_VERB_SET_POWER_STATE
, parm
);
2949 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
2950 snd_hda_codec_write(codec
, 0x21, 0, AC_VERB_SET_POWER_STATE
,
2951 imux_is_smixer
? AC_PWRST_D0
: parm
);
2953 /* PW1 (25h), AOW1 (9h) */
2955 set_pin_power_state(codec
, 0x25, &parm
);
2956 if (spec
->smart51_enabled
)
2957 set_pin_power_state(codec
, 0x2a, &parm
);
2958 snd_hda_codec_write(codec
, 0x9, 0, AC_VERB_SET_POWER_STATE
, parm
);
2960 if (spec
->hp_independent_mode
) {
2961 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
2963 set_pin_power_state(codec
, 0x28, &parm
);
2964 snd_hda_codec_write(codec
, 0x1b, 0,
2965 AC_VERB_SET_POWER_STATE
, parm
);
2966 snd_hda_codec_write(codec
, 0x34, 0,
2967 AC_VERB_SET_POWER_STATE
, parm
);
2968 snd_hda_codec_write(codec
, 0xc, 0,
2969 AC_VERB_SET_POWER_STATE
, parm
);
2973 static int patch_vt1718S(struct hda_codec
*codec
)
2975 struct via_spec
*spec
;
2978 /* create a codec specific record */
2979 spec
= via_new_spec(codec
);
2983 spec
->aa_mix_nid
= 0x21;
2984 override_mic_boost(codec
, 0x2b, 0, 3, 40);
2985 override_mic_boost(codec
, 0x29, 0, 3, 40);
2986 spec
->dac_mixer_idx
= 5;
2988 /* automatic parse from the BIOS config */
2989 err
= via_parse_auto_config(codec
);
2995 spec
->init_verbs
[spec
->num_iverbs
++] = vt1718S_init_verbs
;
2997 codec
->patch_ops
= via_patch_ops
;
2999 spec
->set_widgets_power_state
= set_widgets_power_state_vt1718S
;
3004 /* Patch for VT1716S */
3006 static int vt1716s_dmic_info(struct snd_kcontrol
*kcontrol
,
3007 struct snd_ctl_elem_info
*uinfo
)
3009 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
3011 uinfo
->value
.integer
.min
= 0;
3012 uinfo
->value
.integer
.max
= 1;
3016 static int vt1716s_dmic_get(struct snd_kcontrol
*kcontrol
,
3017 struct snd_ctl_elem_value
*ucontrol
)
3019 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3022 index
= snd_hda_codec_read(codec
, 0x26, 0,
3023 AC_VERB_GET_CONNECT_SEL
, 0);
3025 *ucontrol
->value
.integer
.value
= index
;
3030 static int vt1716s_dmic_put(struct snd_kcontrol
*kcontrol
,
3031 struct snd_ctl_elem_value
*ucontrol
)
3033 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3034 struct via_spec
*spec
= codec
->spec
;
3035 int index
= *ucontrol
->value
.integer
.value
;
3037 snd_hda_codec_write(codec
, 0x26, 0,
3038 AC_VERB_SET_CONNECT_SEL
, index
);
3039 spec
->dmic_enabled
= index
;
3040 set_widgets_power_state(codec
);
3044 static const struct snd_kcontrol_new vt1716s_dmic_mixer
[] = {
3045 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT
),
3047 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3048 .name
= "Digital Mic Capture Switch",
3049 .subdevice
= HDA_SUBDEV_NID_FLAG
| 0x26,
3051 .info
= vt1716s_dmic_info
,
3052 .get
= vt1716s_dmic_get
,
3053 .put
= vt1716s_dmic_put
,
3059 /* mono-out mixer elements */
3060 static const struct snd_kcontrol_new vt1716S_mono_out_mixer
[] = {
3061 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT
),
3065 static const struct hda_verb vt1716S_init_verbs
[] = {
3066 /* Enable Boost Volume backdoor */
3068 /* don't bybass mixer */
3070 /* Enable mono output */
3075 static void set_widgets_power_state_vt1716S(struct hda_codec
*codec
)
3077 struct via_spec
*spec
= codec
->spec
;
3080 unsigned int mono_out
, present
;
3081 /* SW0 (17h) = stereo mixer */
3083 (snd_hda_codec_read(codec
, 0x17, 0,
3084 AC_VERB_GET_CONNECT_SEL
, 0x00) == 5);
3086 /* PW 1/2/5 (1ah/1bh/1eh) */
3088 set_pin_power_state(codec
, 0x1a, &parm
);
3089 set_pin_power_state(codec
, 0x1b, &parm
);
3090 set_pin_power_state(codec
, 0x1e, &parm
);
3093 /* SW0 (17h), AIW0(13h) */
3094 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_POWER_STATE
, parm
);
3095 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
, parm
);
3098 set_pin_power_state(codec
, 0x1e, &parm
);
3100 if (spec
->dmic_enabled
)
3101 set_pin_power_state(codec
, 0x22, &parm
);
3103 snd_hda_codec_write(codec
, 0x22, 0,
3104 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
3106 /* SW2(26h), AIW1(14h) */
3107 snd_hda_codec_write(codec
, 0x26, 0, AC_VERB_SET_POWER_STATE
, parm
);
3108 snd_hda_codec_write(codec
, 0x14, 0, AC_VERB_SET_POWER_STATE
, parm
);
3111 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3113 set_pin_power_state(codec
, 0x19, &parm
);
3114 /* Smart 5.1 PW2(1bh) */
3115 if (spec
->smart51_enabled
)
3116 set_pin_power_state(codec
, 0x1b, &parm
);
3117 snd_hda_codec_write(codec
, 0x18, 0, AC_VERB_SET_POWER_STATE
, parm
);
3118 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
, parm
);
3120 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3122 set_pin_power_state(codec
, 0x23, &parm
);
3123 /* Smart 5.1 PW1(1ah) */
3124 if (spec
->smart51_enabled
)
3125 set_pin_power_state(codec
, 0x1a, &parm
);
3126 snd_hda_codec_write(codec
, 0x27, 0, AC_VERB_SET_POWER_STATE
, parm
);
3128 /* Smart 5.1 PW5(1eh) */
3129 if (spec
->smart51_enabled
)
3130 set_pin_power_state(codec
, 0x1e, &parm
);
3131 snd_hda_codec_write(codec
, 0x25, 0, AC_VERB_SET_POWER_STATE
, parm
);
3134 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3135 present
= snd_hda_jack_detect(codec
, 0x1c);
3140 present
= snd_hda_jack_detect(codec
, 0x1d);
3141 if (!spec
->hp_independent_mode
&& present
)
3146 parm
= mono_out
? AC_PWRST_D0
: AC_PWRST_D3
;
3147 snd_hda_codec_write(codec
, 0x28, 0, AC_VERB_SET_POWER_STATE
, parm
);
3148 snd_hda_codec_write(codec
, 0x29, 0, AC_VERB_SET_POWER_STATE
, parm
);
3149 snd_hda_codec_write(codec
, 0x2a, 0, AC_VERB_SET_POWER_STATE
, parm
);
3151 /* PW 3/4 (1ch/1dh) */
3153 set_pin_power_state(codec
, 0x1c, &parm
);
3154 set_pin_power_state(codec
, 0x1d, &parm
);
3155 /* HP Independent Mode, power on AOW3 */
3156 if (spec
->hp_independent_mode
)
3157 snd_hda_codec_write(codec
, 0x25, 0,
3158 AC_VERB_SET_POWER_STATE
, parm
);
3160 /* force to D0 for internal Speaker */
3161 /* MW0 (16h), AOW0 (10h) */
3162 snd_hda_codec_write(codec
, 0x16, 0, AC_VERB_SET_POWER_STATE
,
3163 imux_is_smixer
? AC_PWRST_D0
: parm
);
3164 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
3165 mono_out
? AC_PWRST_D0
: parm
);
3168 static int patch_vt1716S(struct hda_codec
*codec
)
3170 struct via_spec
*spec
;
3173 /* create a codec specific record */
3174 spec
= via_new_spec(codec
);
3178 spec
->aa_mix_nid
= 0x16;
3179 override_mic_boost(codec
, 0x1a, 0, 3, 40);
3180 override_mic_boost(codec
, 0x1e, 0, 3, 40);
3182 /* automatic parse from the BIOS config */
3183 err
= via_parse_auto_config(codec
);
3189 spec
->init_verbs
[spec
->num_iverbs
++] = vt1716S_init_verbs
;
3191 spec
->mixers
[spec
->num_mixers
] = vt1716s_dmic_mixer
;
3194 spec
->mixers
[spec
->num_mixers
++] = vt1716S_mono_out_mixer
;
3196 codec
->patch_ops
= via_patch_ops
;
3198 spec
->set_widgets_power_state
= set_widgets_power_state_vt1716S
;
3204 static const struct hda_verb vt2002P_init_verbs
[] = {
3205 /* Class-D speaker related verbs */
3209 /* Enable Boost Volume backdoor */
3211 /* Enable AOW0 to MW9 */
3216 static const struct hda_verb vt1802_init_verbs
[] = {
3217 /* Enable Boost Volume backdoor */
3219 /* Enable AOW0 to MW9 */
3224 static void set_widgets_power_state_vt2002P(struct hda_codec
*codec
)
3226 struct via_spec
*spec
= codec
->spec
;
3229 unsigned int present
;
3230 /* MUX9 (1eh) = stereo mixer */
3232 snd_hda_codec_read(codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
3234 /* PW 5/6/7 (29h/2ah/2bh) */
3236 set_pin_power_state(codec
, 0x29, &parm
);
3237 set_pin_power_state(codec
, 0x2a, &parm
);
3238 set_pin_power_state(codec
, 0x2b, &parm
);
3240 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3241 snd_hda_codec_write(codec
, 0x1e, 0, AC_VERB_SET_POWER_STATE
, parm
);
3242 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
, parm
);
3243 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
, parm
);
3244 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
, parm
);
3248 snd_hda_codec_write(codec
, 0x8, 0, AC_VERB_SET_POWER_STATE
, parm
);
3250 if (spec
->codec_type
== VT1802
) {
3251 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3253 set_pin_power_state(codec
, 0x28, &parm
);
3254 snd_hda_codec_write(codec
, 0x18, 0,
3255 AC_VERB_SET_POWER_STATE
, parm
);
3256 snd_hda_codec_write(codec
, 0x38, 0,
3257 AC_VERB_SET_POWER_STATE
, parm
);
3259 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3261 set_pin_power_state(codec
, 0x26, &parm
);
3262 snd_hda_codec_write(codec
, 0x1c, 0,
3263 AC_VERB_SET_POWER_STATE
, parm
);
3264 snd_hda_codec_write(codec
, 0x37, 0,
3265 AC_VERB_SET_POWER_STATE
, parm
);
3268 if (spec
->codec_type
== VT1802
) {
3269 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3271 set_pin_power_state(codec
, 0x25, &parm
);
3272 snd_hda_codec_write(codec
, 0x15, 0,
3273 AC_VERB_SET_POWER_STATE
, parm
);
3274 snd_hda_codec_write(codec
, 0x35, 0,
3275 AC_VERB_SET_POWER_STATE
, parm
);
3277 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3279 set_pin_power_state(codec
, 0x25, &parm
);
3280 snd_hda_codec_write(codec
, 0x19, 0,
3281 AC_VERB_SET_POWER_STATE
, parm
);
3282 snd_hda_codec_write(codec
, 0x35, 0,
3283 AC_VERB_SET_POWER_STATE
, parm
);
3286 if (spec
->hp_independent_mode
)
3287 snd_hda_codec_write(codec
, 0x9, 0,
3288 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
3291 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3292 present
= snd_hda_jack_detect(codec
, 0x25);
3295 set_pin_power_state(codec
, 0x24, &parm
);
3296 parm
= present
? AC_PWRST_D3
: AC_PWRST_D0
;
3297 if (spec
->codec_type
== VT1802
)
3298 snd_hda_codec_write(codec
, 0x14, 0,
3299 AC_VERB_SET_POWER_STATE
, parm
);
3301 snd_hda_codec_write(codec
, 0x18, 0,
3302 AC_VERB_SET_POWER_STATE
, parm
);
3303 snd_hda_codec_write(codec
, 0x34, 0, AC_VERB_SET_POWER_STATE
, parm
);
3306 present
= snd_hda_jack_detect(codec
, 0x26);
3308 parm
= present
? AC_PWRST_D3
: AC_PWRST_D0
;
3309 if (spec
->codec_type
== VT1802
) {
3310 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3311 snd_hda_codec_write(codec
, 0x33, 0,
3312 AC_VERB_SET_POWER_STATE
, parm
);
3313 snd_hda_codec_write(codec
, 0x1c, 0,
3314 AC_VERB_SET_POWER_STATE
, parm
);
3315 snd_hda_codec_write(codec
, 0x3c, 0,
3316 AC_VERB_SET_POWER_STATE
, parm
);
3318 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3319 snd_hda_codec_write(codec
, 0x31, 0,
3320 AC_VERB_SET_POWER_STATE
, parm
);
3321 snd_hda_codec_write(codec
, 0x17, 0,
3322 AC_VERB_SET_POWER_STATE
, parm
);
3323 snd_hda_codec_write(codec
, 0x3b, 0,
3324 AC_VERB_SET_POWER_STATE
, parm
);
3327 if (imux_is_smixer
|| !is_aa_path_mute(codec
))
3328 snd_hda_codec_write(codec
, 0x21, 0,
3329 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
3331 snd_hda_codec_write(codec
, 0x21, 0,
3332 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
3335 /* patch for vt2002P */
3336 static int patch_vt2002P(struct hda_codec
*codec
)
3338 struct via_spec
*spec
;
3341 /* create a codec specific record */
3342 spec
= via_new_spec(codec
);
3346 spec
->aa_mix_nid
= 0x21;
3347 override_mic_boost(codec
, 0x2b, 0, 3, 40);
3348 override_mic_boost(codec
, 0x29, 0, 3, 40);
3350 /* automatic parse from the BIOS config */
3351 err
= via_parse_auto_config(codec
);
3357 if (spec
->codec_type
== VT1802
)
3358 spec
->init_verbs
[spec
->num_iverbs
++] = vt1802_init_verbs
;
3360 spec
->init_verbs
[spec
->num_iverbs
++] = vt2002P_init_verbs
;
3362 codec
->patch_ops
= via_patch_ops
;
3364 spec
->set_widgets_power_state
= set_widgets_power_state_vt2002P
;
3370 static const struct hda_verb vt1812_init_verbs
[] = {
3371 /* Enable Boost Volume backdoor */
3373 /* Enable AOW0 to MW9 */
3378 static void set_widgets_power_state_vt1812(struct hda_codec
*codec
)
3380 struct via_spec
*spec
= codec
->spec
;
3381 int imux_is_smixer
=
3382 snd_hda_codec_read(codec
, 0x13, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
3384 unsigned int present
;
3385 /* MUX10 (1eh) = stereo mixer */
3387 snd_hda_codec_read(codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
3389 /* PW 5/6/7 (29h/2ah/2bh) */
3391 set_pin_power_state(codec
, 0x29, &parm
);
3392 set_pin_power_state(codec
, 0x2a, &parm
);
3393 set_pin_power_state(codec
, 0x2b, &parm
);
3395 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3396 snd_hda_codec_write(codec
, 0x1e, 0, AC_VERB_SET_POWER_STATE
, parm
);
3397 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
, parm
);
3398 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
, parm
);
3399 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
, parm
);
3403 snd_hda_codec_write(codec
, 0x8, 0,
3404 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
3406 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3408 set_pin_power_state(codec
, 0x28, &parm
);
3409 snd_hda_codec_write(codec
, 0x18, 0, AC_VERB_SET_POWER_STATE
, parm
);
3410 snd_hda_codec_write(codec
, 0x38, 0, AC_VERB_SET_POWER_STATE
, parm
);
3412 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3414 set_pin_power_state(codec
, 0x25, &parm
);
3415 snd_hda_codec_write(codec
, 0x15, 0, AC_VERB_SET_POWER_STATE
, parm
);
3416 snd_hda_codec_write(codec
, 0x35, 0, AC_VERB_SET_POWER_STATE
, parm
);
3417 if (spec
->hp_independent_mode
)
3418 snd_hda_codec_write(codec
, 0x9, 0,
3419 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
3421 /* Internal Speaker */
3422 /* PW0 (24h), MW0(14h), MUX0(34h) */
3423 present
= snd_hda_jack_detect(codec
, 0x25);
3426 set_pin_power_state(codec
, 0x24, &parm
);
3428 snd_hda_codec_write(codec
, 0x14, 0,
3429 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
3430 snd_hda_codec_write(codec
, 0x34, 0,
3431 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
3433 snd_hda_codec_write(codec
, 0x14, 0,
3434 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
3435 snd_hda_codec_write(codec
, 0x34, 0,
3436 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
3441 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3442 present
= snd_hda_jack_detect(codec
, 0x28);
3445 set_pin_power_state(codec
, 0x31, &parm
);
3447 snd_hda_codec_write(codec
, 0x1c, 0,
3448 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
3449 snd_hda_codec_write(codec
, 0x3c, 0,
3450 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
3451 snd_hda_codec_write(codec
, 0x3e, 0,
3452 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
3454 snd_hda_codec_write(codec
, 0x1c, 0,
3455 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
3456 snd_hda_codec_write(codec
, 0x3c, 0,
3457 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
3458 snd_hda_codec_write(codec
, 0x3e, 0,
3459 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
3462 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3464 set_pin_power_state(codec
, 0x33, &parm
);
3465 snd_hda_codec_write(codec
, 0x1d, 0, AC_VERB_SET_POWER_STATE
, parm
);
3466 snd_hda_codec_write(codec
, 0x3d, 0, AC_VERB_SET_POWER_STATE
, parm
);
3470 /* patch for vt1812 */
3471 static int patch_vt1812(struct hda_codec
*codec
)
3473 struct via_spec
*spec
;
3476 /* create a codec specific record */
3477 spec
= via_new_spec(codec
);
3481 spec
->aa_mix_nid
= 0x21;
3482 override_mic_boost(codec
, 0x2b, 0, 3, 40);
3483 override_mic_boost(codec
, 0x29, 0, 3, 40);
3485 /* automatic parse from the BIOS config */
3486 err
= via_parse_auto_config(codec
);
3492 spec
->init_verbs
[spec
->num_iverbs
++] = vt1812_init_verbs
;
3494 codec
->patch_ops
= via_patch_ops
;
3496 spec
->set_widgets_power_state
= set_widgets_power_state_vt1812
;
3503 static const struct hda_codec_preset snd_hda_preset_via
[] = {
3504 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
3505 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
3506 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
3507 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
3508 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
3509 .patch
= patch_vt1709
},
3510 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
3511 .patch
= patch_vt1709
},
3512 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
3513 .patch
= patch_vt1709
},
3514 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
3515 .patch
= patch_vt1709
},
3516 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
3517 .patch
= patch_vt1709
},
3518 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
3519 .patch
= patch_vt1709
},
3520 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
3521 .patch
= patch_vt1709
},
3522 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
3523 .patch
= patch_vt1709
},
3524 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
3525 .patch
= patch_vt1708B
},
3526 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
3527 .patch
= patch_vt1708B
},
3528 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
3529 .patch
= patch_vt1708B
},
3530 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
3531 .patch
= patch_vt1708B
},
3532 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
3533 .patch
= patch_vt1708B
},
3534 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
3535 .patch
= patch_vt1708B
},
3536 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
3537 .patch
= patch_vt1708B
},
3538 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
3539 .patch
= patch_vt1708B
},
3540 { .id
= 0x11060397, .name
= "VT1708S",
3541 .patch
= patch_vt1708S
},
3542 { .id
= 0x11061397, .name
= "VT1708S",
3543 .patch
= patch_vt1708S
},
3544 { .id
= 0x11062397, .name
= "VT1708S",
3545 .patch
= patch_vt1708S
},
3546 { .id
= 0x11063397, .name
= "VT1708S",
3547 .patch
= patch_vt1708S
},
3548 { .id
= 0x11064397, .name
= "VT1705",
3549 .patch
= patch_vt1708S
},
3550 { .id
= 0x11065397, .name
= "VT1708S",
3551 .patch
= patch_vt1708S
},
3552 { .id
= 0x11066397, .name
= "VT1708S",
3553 .patch
= patch_vt1708S
},
3554 { .id
= 0x11067397, .name
= "VT1708S",
3555 .patch
= patch_vt1708S
},
3556 { .id
= 0x11060398, .name
= "VT1702",
3557 .patch
= patch_vt1702
},
3558 { .id
= 0x11061398, .name
= "VT1702",
3559 .patch
= patch_vt1702
},
3560 { .id
= 0x11062398, .name
= "VT1702",
3561 .patch
= patch_vt1702
},
3562 { .id
= 0x11063398, .name
= "VT1702",
3563 .patch
= patch_vt1702
},
3564 { .id
= 0x11064398, .name
= "VT1702",
3565 .patch
= patch_vt1702
},
3566 { .id
= 0x11065398, .name
= "VT1702",
3567 .patch
= patch_vt1702
},
3568 { .id
= 0x11066398, .name
= "VT1702",
3569 .patch
= patch_vt1702
},
3570 { .id
= 0x11067398, .name
= "VT1702",
3571 .patch
= patch_vt1702
},
3572 { .id
= 0x11060428, .name
= "VT1718S",
3573 .patch
= patch_vt1718S
},
3574 { .id
= 0x11064428, .name
= "VT1718S",
3575 .patch
= patch_vt1718S
},
3576 { .id
= 0x11060441, .name
= "VT2020",
3577 .patch
= patch_vt1718S
},
3578 { .id
= 0x11064441, .name
= "VT1828S",
3579 .patch
= patch_vt1718S
},
3580 { .id
= 0x11060433, .name
= "VT1716S",
3581 .patch
= patch_vt1716S
},
3582 { .id
= 0x1106a721, .name
= "VT1716S",
3583 .patch
= patch_vt1716S
},
3584 { .id
= 0x11060438, .name
= "VT2002P", .patch
= patch_vt2002P
},
3585 { .id
= 0x11064438, .name
= "VT2002P", .patch
= patch_vt2002P
},
3586 { .id
= 0x11060448, .name
= "VT1812", .patch
= patch_vt1812
},
3587 { .id
= 0x11060440, .name
= "VT1818S",
3588 .patch
= patch_vt1708S
},
3589 { .id
= 0x11060446, .name
= "VT1802",
3590 .patch
= patch_vt2002P
},
3591 { .id
= 0x11068446, .name
= "VT1802",
3592 .patch
= patch_vt2002P
},
3596 MODULE_ALIAS("snd-hda-codec-id:1106*");
3598 static struct hda_codec_preset_list via_list
= {
3599 .preset
= snd_hda_preset_via
,
3600 .owner
= THIS_MODULE
,
3603 MODULE_LICENSE("GPL");
3604 MODULE_DESCRIPTION("VIA HD-audio codec");
3606 static int __init
patch_via_init(void)
3608 return snd_hda_add_codec_preset(&via_list
);
3611 static void __exit
patch_via_exit(void)
3613 snd_hda_delete_codec_preset(&via_list
);
3616 module_init(patch_via_init
)
3617 module_exit(patch_via_exit
)