2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <sound/core.h>
53 #include <sound/asoundef.h>
54 #include "hda_codec.h"
55 #include "hda_local.h"
57 #define NID_MAPPING (-1)
60 #define AMP_VAL_IDX_SHIFT 19
61 #define AMP_VAL_IDX_MASK (0x0f<<19)
64 #define VT1708_HP_NID 0x13
65 #define VT1708_DIGOUT_NID 0x14
66 #define VT1708_DIGIN_NID 0x16
67 #define VT1708_DIGIN_PIN 0x26
68 #define VT1708_HP_PIN_NID 0x20
69 #define VT1708_CD_PIN_NID 0x24
71 #define VT1709_HP_DAC_NID 0x28
72 #define VT1709_DIGOUT_NID 0x13
73 #define VT1709_DIGIN_NID 0x17
74 #define VT1709_DIGIN_PIN 0x25
76 #define VT1708B_HP_NID 0x25
77 #define VT1708B_DIGOUT_NID 0x12
78 #define VT1708B_DIGIN_NID 0x15
79 #define VT1708B_DIGIN_PIN 0x21
81 #define VT1708S_HP_NID 0x25
82 #define VT1708S_DIGOUT_NID 0x12
84 #define VT1702_HP_NID 0x17
85 #define VT1702_DIGOUT_NID 0x11
105 /* codec parameterization */
106 struct snd_kcontrol_new
*mixers
[6];
107 unsigned int num_mixers
;
109 struct hda_verb
*init_verbs
[5];
110 unsigned int num_iverbs
;
112 char *stream_name_analog
;
113 struct hda_pcm_stream
*stream_analog_playback
;
114 struct hda_pcm_stream
*stream_analog_capture
;
116 char *stream_name_digital
;
117 struct hda_pcm_stream
*stream_digital_playback
;
118 struct hda_pcm_stream
*stream_digital_capture
;
121 struct hda_multi_out multiout
;
122 hda_nid_t slave_dig_outs
[2];
125 unsigned int num_adc_nids
;
127 hda_nid_t mux_nids
[3];
128 hda_nid_t dig_in_nid
;
129 hda_nid_t dig_in_pin
;
132 const struct hda_input_mux
*input_mux
;
133 unsigned int cur_mux
[3];
135 /* PCM information */
136 struct hda_pcm pcm_rec
[3];
138 /* dynamic controls, init_verbs and input_mux */
139 struct auto_pin_cfg autocfg
;
140 struct snd_array kctls
;
141 struct hda_input_mux private_imux
[2];
142 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
145 const struct hda_input_mux
*hp_mux
;
146 unsigned int hp_independent_mode
;
147 unsigned int hp_independent_mode_index
;
148 unsigned int smart51_enabled
;
149 unsigned int dmic_enabled
;
150 enum VIA_HDA_CODEC codec_type
;
152 /* work to check hp jack state */
153 struct hda_codec
*codec
;
154 struct delayed_work vt1708_hp_work
;
155 int vt1708_jack_detectect
;
156 int vt1708_hp_present
;
157 #ifdef CONFIG_SND_HDA_POWER_SAVE
158 struct hda_loopback_check loopback
;
162 static struct via_spec
* via_new_spec(struct hda_codec
*codec
)
164 struct via_spec
*spec
;
166 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
175 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
)
177 u32 vendor_id
= codec
->vendor_id
;
178 u16 ven_id
= vendor_id
>> 16;
179 u16 dev_id
= vendor_id
& 0xffff;
180 enum VIA_HDA_CODEC codec_type
;
183 if (ven_id
!= 0x1106)
184 codec_type
= UNKNOWN
;
185 else if (dev_id
>= 0x1708 && dev_id
<= 0x170b)
187 else if (dev_id
>= 0xe710 && dev_id
<= 0xe713)
188 codec_type
= VT1709_10CH
;
189 else if (dev_id
>= 0xe714 && dev_id
<= 0xe717)
190 codec_type
= VT1709_6CH
;
191 else if (dev_id
>= 0xe720 && dev_id
<= 0xe723) {
192 codec_type
= VT1708B_8CH
;
193 if (snd_hda_param_read(codec
, 0x16, AC_PAR_CONNLIST_LEN
) == 0x7)
194 codec_type
= VT1708BCE
;
195 } else if (dev_id
>= 0xe724 && dev_id
<= 0xe727)
196 codec_type
= VT1708B_4CH
;
197 else if ((dev_id
& 0xfff) == 0x397
198 && (dev_id
>> 12) < 8)
199 codec_type
= VT1708S
;
200 else if ((dev_id
& 0xfff) == 0x398
201 && (dev_id
>> 12) < 8)
203 else if ((dev_id
& 0xfff) == 0x428
204 && (dev_id
>> 12) < 8)
205 codec_type
= VT1718S
;
206 else if (dev_id
== 0x0433 || dev_id
== 0xa721)
207 codec_type
= VT1716S
;
208 else if (dev_id
== 0x0441 || dev_id
== 0x4441)
209 codec_type
= VT1718S
;
210 else if (dev_id
== 0x0438 || dev_id
== 0x4438)
211 codec_type
= VT2002P
;
212 else if (dev_id
== 0x0448)
214 else if (dev_id
== 0x0440)
215 codec_type
= VT1708S
;
217 codec_type
= UNKNOWN
;
221 #define VIA_HP_EVENT 0x01
222 #define VIA_GPIO_EVENT 0x02
223 #define VIA_JACK_EVENT 0x04
224 #define VIA_MONO_EVENT 0x08
225 #define VIA_SPEAKER_EVENT 0x10
226 #define VIA_BIND_HP_EVENT 0x20
231 VIA_CTL_WIDGET_ANALOG_MUTE
,
232 VIA_CTL_WIDGET_BIND_PIN_MUTE
,
242 static void analog_low_current_mode(struct hda_codec
*codec
, int stream_idle
);
243 static void set_jack_power_state(struct hda_codec
*codec
);
244 static int is_aa_path_mute(struct hda_codec
*codec
);
246 static void vt1708_start_hp_work(struct via_spec
*spec
)
248 if (spec
->codec_type
!= VT1708
|| spec
->autocfg
.hp_pins
[0] == 0)
250 snd_hda_codec_write(spec
->codec
, 0x1, 0, 0xf81,
251 !spec
->vt1708_jack_detectect
);
252 if (!delayed_work_pending(&spec
->vt1708_hp_work
))
253 schedule_delayed_work(&spec
->vt1708_hp_work
,
254 msecs_to_jiffies(100));
257 static void vt1708_stop_hp_work(struct via_spec
*spec
)
259 if (spec
->codec_type
!= VT1708
|| spec
->autocfg
.hp_pins
[0] == 0)
261 if (snd_hda_get_bool_hint(spec
->codec
, "analog_loopback_hp_detect") == 1
262 && !is_aa_path_mute(spec
->codec
))
264 snd_hda_codec_write(spec
->codec
, 0x1, 0, 0xf81,
265 !spec
->vt1708_jack_detectect
);
266 cancel_delayed_work(&spec
->vt1708_hp_work
);
267 flush_scheduled_work();
271 static int analog_input_switch_put(struct snd_kcontrol
*kcontrol
,
272 struct snd_ctl_elem_value
*ucontrol
)
274 int change
= snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
275 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
277 set_jack_power_state(codec
);
278 analog_low_current_mode(snd_kcontrol_chip(kcontrol
), -1);
279 if (snd_hda_get_bool_hint(codec
, "analog_loopback_hp_detect") == 1) {
280 if (is_aa_path_mute(codec
))
281 vt1708_start_hp_work(codec
->spec
);
283 vt1708_stop_hp_work(codec
->spec
);
288 /* modify .put = snd_hda_mixer_amp_switch_put */
289 #define ANALOG_INPUT_MUTE \
290 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
293 .info = snd_hda_mixer_amp_switch_info, \
294 .get = snd_hda_mixer_amp_switch_get, \
295 .put = analog_input_switch_put, \
296 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
298 static void via_hp_bind_automute(struct hda_codec
*codec
);
300 static int bind_pin_switch_put(struct snd_kcontrol
*kcontrol
,
301 struct snd_ctl_elem_value
*ucontrol
)
303 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
304 struct via_spec
*spec
= codec
->spec
;
308 long *valp
= ucontrol
->value
.integer
.value
;
310 if (strstr(kcontrol
->id
.name
, "Switch") == NULL
) {
311 snd_printd("Invalid control!\n");
314 change
= snd_hda_mixer_amp_switch_put(kcontrol
,
317 lmute
= *valp
? 0 : HDA_AMP_MUTE
;
319 rmute
= *valp
? 0 : HDA_AMP_MUTE
;
322 if (!spec
->hp_independent_mode
) {
323 for (i
= 0; i
< spec
->autocfg
.hp_outs
; i
++) {
324 snd_hda_codec_amp_update(
325 codec
, spec
->autocfg
.hp_pins
[i
],
326 0, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
328 snd_hda_codec_amp_update(
329 codec
, spec
->autocfg
.hp_pins
[i
],
330 1, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
335 if (!lmute
&& !rmute
) {
337 for (i
= 0; i
< spec
->autocfg
.line_outs
; i
++)
338 snd_hda_codec_amp_stereo(
339 codec
, spec
->autocfg
.line_out_pins
[i
],
340 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
342 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++)
343 snd_hda_codec_amp_stereo(
344 codec
, spec
->autocfg
.speaker_pins
[i
],
345 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
347 via_hp_bind_automute(codec
);
351 /* Mute all left channels */
352 for (i
= 1; i
< spec
->autocfg
.line_outs
; i
++)
353 snd_hda_codec_amp_update(
355 spec
->autocfg
.line_out_pins
[i
],
356 0, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
358 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++)
359 snd_hda_codec_amp_update(
361 spec
->autocfg
.speaker_pins
[i
],
362 0, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
366 /* mute all right channels */
367 for (i
= 1; i
< spec
->autocfg
.line_outs
; i
++)
368 snd_hda_codec_amp_update(
370 spec
->autocfg
.line_out_pins
[i
],
371 1, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
373 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++)
374 snd_hda_codec_amp_update(
376 spec
->autocfg
.speaker_pins
[i
],
377 1, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
384 #define BIND_PIN_MUTE \
385 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
388 .info = snd_hda_mixer_amp_switch_info, \
389 .get = snd_hda_mixer_amp_switch_get, \
390 .put = bind_pin_switch_put, \
391 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
393 static struct snd_kcontrol_new via_control_templates
[] = {
394 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
395 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
400 static hda_nid_t vt1708_adc_nids
[2] = {
405 static hda_nid_t vt1709_adc_nids
[3] = {
410 static hda_nid_t vt1708B_adc_nids
[2] = {
415 static hda_nid_t vt1708S_adc_nids
[2] = {
420 static hda_nid_t vt1702_adc_nids
[3] = {
425 static hda_nid_t vt1718S_adc_nids
[2] = {
430 static hda_nid_t vt1716S_adc_nids
[2] = {
435 static hda_nid_t vt2002P_adc_nids
[2] = {
440 static hda_nid_t vt1812_adc_nids
[2] = {
446 /* add dynamic controls */
447 static int via_add_control(struct via_spec
*spec
, int type
, const char *name
,
450 struct snd_kcontrol_new
*knew
;
452 snd_array_init(&spec
->kctls
, sizeof(*knew
), 32);
453 knew
= snd_array_new(&spec
->kctls
);
456 *knew
= via_control_templates
[type
];
457 knew
->name
= kstrdup(name
, GFP_KERNEL
);
460 if (get_amp_nid_(val
))
461 knew
->subdevice
= HDA_SUBDEV_NID_FLAG
|
462 HDA_SUBDEV_AMP_FLAG
|
464 knew
->private_value
= val
;
468 static struct snd_kcontrol_new
*via_clone_control(struct via_spec
*spec
,
469 struct snd_kcontrol_new
*tmpl
)
471 struct snd_kcontrol_new
*knew
;
473 snd_array_init(&spec
->kctls
, sizeof(*knew
), 32);
474 knew
= snd_array_new(&spec
->kctls
);
478 knew
->name
= kstrdup(tmpl
->name
, GFP_KERNEL
);
484 static void via_free_kctls(struct hda_codec
*codec
)
486 struct via_spec
*spec
= codec
->spec
;
488 if (spec
->kctls
.list
) {
489 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
491 for (i
= 0; i
< spec
->kctls
.used
; i
++)
494 snd_array_free(&spec
->kctls
);
497 /* create input playback/capture controls for the given pin */
498 static int via_new_analog_input(struct via_spec
*spec
, const char *ctlname
,
499 int idx
, int mix_nid
)
504 sprintf(name
, "%s Playback Volume", ctlname
);
505 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
506 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
509 sprintf(name
, "%s Playback Switch", ctlname
);
510 err
= via_add_control(spec
, VIA_CTL_WIDGET_ANALOG_MUTE
, name
,
511 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
517 static void via_auto_set_output_and_unmute(struct hda_codec
*codec
,
518 hda_nid_t nid
, int pin_type
,
522 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
524 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
526 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
527 snd_hda_codec_write(codec
, nid
, 0,
528 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
532 static void via_auto_init_multi_out(struct hda_codec
*codec
)
534 struct via_spec
*spec
= codec
->spec
;
537 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
538 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
540 via_auto_set_output_and_unmute(codec
, nid
, PIN_OUT
, i
);
544 static void via_auto_init_hp_out(struct hda_codec
*codec
)
546 struct via_spec
*spec
= codec
->spec
;
550 for (i
= 0; i
< spec
->autocfg
.hp_outs
; i
++) {
551 pin
= spec
->autocfg
.hp_pins
[i
];
552 if (pin
) /* connect to front */
553 via_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, 0);
557 static void via_auto_init_analog_input(struct hda_codec
*codec
)
559 struct via_spec
*spec
= codec
->spec
;
562 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
563 hda_nid_t nid
= spec
->autocfg
.input_pins
[i
];
565 snd_hda_codec_write(codec
, nid
, 0,
566 AC_VERB_SET_PIN_WIDGET_CONTROL
,
567 (i
<= AUTO_PIN_FRONT_MIC
?
568 PIN_VREF50
: PIN_IN
));
573 static int is_smart51_pins(struct via_spec
*spec
, hda_nid_t pin
);
575 static void set_pin_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
576 unsigned int *affected_parm
)
579 unsigned def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
580 unsigned no_presence
= (def_conf
& AC_DEFCFG_MISC
)
581 >> AC_DEFCFG_MISC_SHIFT
582 & AC_DEFCFG_MISC_NO_PRESENCE
; /* do not support pin sense */
583 unsigned present
= snd_hda_jack_detect(codec
, nid
);
584 struct via_spec
*spec
= codec
->spec
;
585 if ((spec
->smart51_enabled
&& is_smart51_pins(spec
, nid
))
586 || ((no_presence
|| present
)
587 && get_defcfg_connect(def_conf
) != AC_JACK_PORT_NONE
)) {
588 *affected_parm
= AC_PWRST_D0
; /* if it's connected */
593 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
596 static void set_jack_power_state(struct hda_codec
*codec
)
598 struct via_spec
*spec
= codec
->spec
;
602 if (spec
->codec_type
== VT1702
) {
603 imux_is_smixer
= snd_hda_codec_read(
604 codec
, 0x13, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
606 /* PW 1/2/5 (14h/15h/18h) */
608 set_pin_power_state(codec
, 0x14, &parm
);
609 set_pin_power_state(codec
, 0x15, &parm
);
610 set_pin_power_state(codec
, 0x18, &parm
);
612 parm
= AC_PWRST_D0
; /* SW0 = stereo mixer (idx 3) */
613 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
614 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
616 snd_hda_codec_write(codec
, 0x12, 0, AC_VERB_SET_POWER_STATE
,
618 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
,
620 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_POWER_STATE
,
624 /* PW 3/4 (16h/17h) */
626 set_pin_power_state(codec
, 0x16, &parm
);
627 set_pin_power_state(codec
, 0x17, &parm
);
628 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
629 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_POWER_STATE
,
630 imux_is_smixer
? AC_PWRST_D0
: parm
);
631 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
633 snd_hda_codec_write(codec
, 0x1d, 0, AC_VERB_SET_POWER_STATE
,
635 } else if (spec
->codec_type
== VT1708B_8CH
636 || spec
->codec_type
== VT1708B_4CH
637 || spec
->codec_type
== VT1708S
) {
638 /* SW0 (17h) = stereo mixer */
639 int is_8ch
= spec
->codec_type
!= VT1708B_4CH
;
640 imux_is_smixer
= snd_hda_codec_read(
641 codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00)
642 == ((spec
->codec_type
== VT1708S
) ? 5 : 0);
644 /* PW 1/2/5 (1ah/1bh/1eh) */
646 set_pin_power_state(codec
, 0x1a, &parm
);
647 set_pin_power_state(codec
, 0x1b, &parm
);
648 set_pin_power_state(codec
, 0x1e, &parm
);
651 /* SW0 (17h), AIW 0/1 (13h/14h) */
652 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_POWER_STATE
,
654 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
656 snd_hda_codec_write(codec
, 0x14, 0, AC_VERB_SET_POWER_STATE
,
660 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
662 set_pin_power_state(codec
, 0x19, &parm
);
663 snd_hda_codec_write(codec
, 0x18, 0, AC_VERB_SET_POWER_STATE
,
665 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
,
668 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
671 set_pin_power_state(codec
, 0x22, &parm
);
672 snd_hda_codec_write(codec
, 0x26, 0,
673 AC_VERB_SET_POWER_STATE
, parm
);
674 snd_hda_codec_write(codec
, 0x24, 0,
675 AC_VERB_SET_POWER_STATE
, parm
);
678 /* PW 3/4/7 (1ch/1dh/23h) */
680 /* force to D0 for internal Speaker */
681 set_pin_power_state(codec
, 0x1c, &parm
);
682 set_pin_power_state(codec
, 0x1d, &parm
);
684 set_pin_power_state(codec
, 0x23, &parm
);
685 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
686 snd_hda_codec_write(codec
, 0x16, 0, AC_VERB_SET_POWER_STATE
,
687 imux_is_smixer
? AC_PWRST_D0
: parm
);
688 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
691 snd_hda_codec_write(codec
, 0x25, 0,
692 AC_VERB_SET_POWER_STATE
, parm
);
693 snd_hda_codec_write(codec
, 0x27, 0,
694 AC_VERB_SET_POWER_STATE
, parm
);
696 } else if (spec
->codec_type
== VT1718S
) {
697 /* MUX6 (1eh) = stereo mixer */
698 imux_is_smixer
= snd_hda_codec_read(
699 codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
701 /* PW 5/6/7 (29h/2ah/2bh) */
703 set_pin_power_state(codec
, 0x29, &parm
);
704 set_pin_power_state(codec
, 0x2a, &parm
);
705 set_pin_power_state(codec
, 0x2b, &parm
);
708 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
709 snd_hda_codec_write(codec
, 0x1e, 0, AC_VERB_SET_POWER_STATE
,
711 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
,
713 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
715 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
,
719 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
721 set_pin_power_state(codec
, 0x27, &parm
);
722 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_POWER_STATE
,
724 snd_hda_codec_write(codec
, 0xb, 0, AC_VERB_SET_POWER_STATE
,
727 /* PW2 (26h), AOW2 (ah) */
729 set_pin_power_state(codec
, 0x26, &parm
);
730 snd_hda_codec_write(codec
, 0xa, 0, AC_VERB_SET_POWER_STATE
,
733 /* PW0/1 (24h/25h) */
735 set_pin_power_state(codec
, 0x24, &parm
);
736 set_pin_power_state(codec
, 0x25, &parm
);
737 if (!spec
->hp_independent_mode
) /* check for redirected HP */
738 set_pin_power_state(codec
, 0x28, &parm
);
739 snd_hda_codec_write(codec
, 0x8, 0, AC_VERB_SET_POWER_STATE
,
741 snd_hda_codec_write(codec
, 0x9, 0, AC_VERB_SET_POWER_STATE
,
743 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
744 snd_hda_codec_write(codec
, 0x21, 0, AC_VERB_SET_POWER_STATE
,
745 imux_is_smixer
? AC_PWRST_D0
: parm
);
746 if (spec
->hp_independent_mode
) {
747 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
749 set_pin_power_state(codec
, 0x28, &parm
);
750 snd_hda_codec_write(codec
, 0x1b, 0,
751 AC_VERB_SET_POWER_STATE
, parm
);
752 snd_hda_codec_write(codec
, 0x34, 0,
753 AC_VERB_SET_POWER_STATE
, parm
);
754 snd_hda_codec_write(codec
, 0xc, 0,
755 AC_VERB_SET_POWER_STATE
, parm
);
757 } else if (spec
->codec_type
== VT1716S
) {
758 unsigned int mono_out
, present
;
759 /* SW0 (17h) = stereo mixer */
760 imux_is_smixer
= snd_hda_codec_read(
761 codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
763 /* PW 1/2/5 (1ah/1bh/1eh) */
765 set_pin_power_state(codec
, 0x1a, &parm
);
766 set_pin_power_state(codec
, 0x1b, &parm
);
767 set_pin_power_state(codec
, 0x1e, &parm
);
770 /* SW0 (17h), AIW0(13h) */
771 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_POWER_STATE
,
773 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
777 set_pin_power_state(codec
, 0x1e, &parm
);
779 if (spec
->dmic_enabled
)
780 set_pin_power_state(codec
, 0x22, &parm
);
784 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
786 /* SW2(26h), AIW1(14h) */
787 snd_hda_codec_write(codec
, 0x26, 0, AC_VERB_SET_POWER_STATE
,
789 snd_hda_codec_write(codec
, 0x14, 0, AC_VERB_SET_POWER_STATE
,
793 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
795 set_pin_power_state(codec
, 0x19, &parm
);
796 /* Smart 5.1 PW2(1bh) */
797 if (spec
->smart51_enabled
)
798 set_pin_power_state(codec
, 0x1b, &parm
);
799 snd_hda_codec_write(codec
, 0x18, 0, AC_VERB_SET_POWER_STATE
,
801 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
,
804 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
806 set_pin_power_state(codec
, 0x23, &parm
);
807 /* Smart 5.1 PW1(1ah) */
808 if (spec
->smart51_enabled
)
809 set_pin_power_state(codec
, 0x1a, &parm
);
810 snd_hda_codec_write(codec
, 0x27, 0, AC_VERB_SET_POWER_STATE
,
813 /* Smart 5.1 PW5(1eh) */
814 if (spec
->smart51_enabled
)
815 set_pin_power_state(codec
, 0x1e, &parm
);
816 snd_hda_codec_write(codec
, 0x25, 0, AC_VERB_SET_POWER_STATE
,
820 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
821 present
= snd_hda_jack_detect(codec
, 0x1c);
825 present
= snd_hda_jack_detect(codec
, 0x1d);
826 if (!spec
->hp_independent_mode
&& present
)
831 parm
= mono_out
? AC_PWRST_D0
: AC_PWRST_D3
;
832 snd_hda_codec_write(codec
, 0x28, 0, AC_VERB_SET_POWER_STATE
,
834 snd_hda_codec_write(codec
, 0x29, 0, AC_VERB_SET_POWER_STATE
,
836 snd_hda_codec_write(codec
, 0x2a, 0, AC_VERB_SET_POWER_STATE
,
839 /* PW 3/4 (1ch/1dh) */
841 set_pin_power_state(codec
, 0x1c, &parm
);
842 set_pin_power_state(codec
, 0x1d, &parm
);
843 /* HP Independent Mode, power on AOW3 */
844 if (spec
->hp_independent_mode
)
845 snd_hda_codec_write(codec
, 0x25, 0,
846 AC_VERB_SET_POWER_STATE
, parm
);
848 /* force to D0 for internal Speaker */
849 /* MW0 (16h), AOW0 (10h) */
850 snd_hda_codec_write(codec
, 0x16, 0, AC_VERB_SET_POWER_STATE
,
851 imux_is_smixer
? AC_PWRST_D0
: parm
);
852 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
853 mono_out
? AC_PWRST_D0
: parm
);
854 } else if (spec
->codec_type
== VT2002P
) {
855 unsigned int present
;
856 /* MUX9 (1eh) = stereo mixer */
857 imux_is_smixer
= snd_hda_codec_read(
858 codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
860 /* PW 5/6/7 (29h/2ah/2bh) */
862 set_pin_power_state(codec
, 0x29, &parm
);
863 set_pin_power_state(codec
, 0x2a, &parm
);
864 set_pin_power_state(codec
, 0x2b, &parm
);
867 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
868 snd_hda_codec_write(codec
, 0x1e, 0,
869 AC_VERB_SET_POWER_STATE
, parm
);
870 snd_hda_codec_write(codec
, 0x1f, 0,
871 AC_VERB_SET_POWER_STATE
, parm
);
872 snd_hda_codec_write(codec
, 0x10, 0,
873 AC_VERB_SET_POWER_STATE
, parm
);
874 snd_hda_codec_write(codec
, 0x11, 0,
875 AC_VERB_SET_POWER_STATE
, parm
);
879 snd_hda_codec_write(codec
, 0x8, 0,
880 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
882 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
884 set_pin_power_state(codec
, 0x26, &parm
);
885 snd_hda_codec_write(codec
, 0x1c, 0,
886 AC_VERB_SET_POWER_STATE
, parm
);
887 snd_hda_codec_write(codec
, 0x37,
888 0, AC_VERB_SET_POWER_STATE
, parm
);
890 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
892 set_pin_power_state(codec
, 0x25, &parm
);
893 snd_hda_codec_write(codec
, 0x19, 0,
894 AC_VERB_SET_POWER_STATE
, parm
);
895 snd_hda_codec_write(codec
, 0x35, 0,
896 AC_VERB_SET_POWER_STATE
, parm
);
897 if (spec
->hp_independent_mode
) {
898 snd_hda_codec_write(codec
, 0x9, 0,
899 AC_VERB_SET_POWER_STATE
, parm
);
903 /* PW0 (24h), MW0(18h), MUX0(34h) */
904 present
= snd_hda_jack_detect(codec
, 0x25);
906 set_pin_power_state(codec
, 0x24, &parm
);
910 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
913 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
917 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
920 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
924 /* PW15 (31h), MW8(17h), MUX8(3bh) */
925 present
= snd_hda_jack_detect(codec
, 0x26);
927 set_pin_power_state(codec
, 0x31, &parm
);
931 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
934 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
938 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
941 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
945 if (imux_is_smixer
|| !is_aa_path_mute(codec
))
948 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
952 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
953 } else if (spec
->codec_type
== VT1812
) {
954 unsigned int present
;
955 /* MUX10 (1eh) = stereo mixer */
956 imux_is_smixer
= snd_hda_codec_read(
957 codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
959 /* PW 5/6/7 (29h/2ah/2bh) */
961 set_pin_power_state(codec
, 0x29, &parm
);
962 set_pin_power_state(codec
, 0x2a, &parm
);
963 set_pin_power_state(codec
, 0x2b, &parm
);
966 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
967 snd_hda_codec_write(codec
, 0x1e, 0,
968 AC_VERB_SET_POWER_STATE
, parm
);
969 snd_hda_codec_write(codec
, 0x1f, 0,
970 AC_VERB_SET_POWER_STATE
, parm
);
971 snd_hda_codec_write(codec
, 0x10, 0,
972 AC_VERB_SET_POWER_STATE
, parm
);
973 snd_hda_codec_write(codec
, 0x11, 0,
974 AC_VERB_SET_POWER_STATE
, parm
);
978 snd_hda_codec_write(codec
, 0x8, 0,
979 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
981 /* PW4 (28h), MW4 (18h), MUX4(38h) */
983 set_pin_power_state(codec
, 0x28, &parm
);
984 snd_hda_codec_write(codec
, 0x18, 0,
985 AC_VERB_SET_POWER_STATE
, parm
);
986 snd_hda_codec_write(codec
, 0x38, 0,
987 AC_VERB_SET_POWER_STATE
, parm
);
989 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
991 set_pin_power_state(codec
, 0x25, &parm
);
992 snd_hda_codec_write(codec
, 0x15, 0,
993 AC_VERB_SET_POWER_STATE
, parm
);
994 snd_hda_codec_write(codec
, 0x35, 0,
995 AC_VERB_SET_POWER_STATE
, parm
);
996 if (spec
->hp_independent_mode
) {
997 snd_hda_codec_write(codec
, 0x9, 0,
998 AC_VERB_SET_POWER_STATE
, parm
);
1001 /* Internal Speaker */
1002 /* PW0 (24h), MW0(14h), MUX0(34h) */
1003 present
= snd_hda_jack_detect(codec
, 0x25);
1005 set_pin_power_state(codec
, 0x24, &parm
);
1007 snd_hda_codec_write(codec
, 0x14, 0,
1008 AC_VERB_SET_POWER_STATE
,
1010 snd_hda_codec_write(codec
, 0x34, 0,
1011 AC_VERB_SET_POWER_STATE
,
1014 snd_hda_codec_write(codec
, 0x14, 0,
1015 AC_VERB_SET_POWER_STATE
,
1017 snd_hda_codec_write(codec
, 0x34, 0,
1018 AC_VERB_SET_POWER_STATE
,
1022 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1023 present
= snd_hda_jack_detect(codec
, 0x28);
1025 set_pin_power_state(codec
, 0x31, &parm
);
1027 snd_hda_codec_write(codec
, 0x1c, 0,
1028 AC_VERB_SET_POWER_STATE
,
1030 snd_hda_codec_write(codec
, 0x3c, 0,
1031 AC_VERB_SET_POWER_STATE
,
1033 snd_hda_codec_write(codec
, 0x3e, 0,
1034 AC_VERB_SET_POWER_STATE
,
1037 snd_hda_codec_write(codec
, 0x1c, 0,
1038 AC_VERB_SET_POWER_STATE
,
1040 snd_hda_codec_write(codec
, 0x3c, 0,
1041 AC_VERB_SET_POWER_STATE
,
1043 snd_hda_codec_write(codec
, 0x3e, 0,
1044 AC_VERB_SET_POWER_STATE
,
1048 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1050 set_pin_power_state(codec
, 0x33, &parm
);
1051 snd_hda_codec_write(codec
, 0x1d, 0,
1052 AC_VERB_SET_POWER_STATE
, parm
);
1053 snd_hda_codec_write(codec
, 0x3d, 0,
1054 AC_VERB_SET_POWER_STATE
, parm
);
1057 if (imux_is_smixer
|| !is_aa_path_mute(codec
))
1058 snd_hda_codec_write(
1060 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
1062 snd_hda_codec_write(
1064 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
1069 * input MUX handling
1071 static int via_mux_enum_info(struct snd_kcontrol
*kcontrol
,
1072 struct snd_ctl_elem_info
*uinfo
)
1074 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1075 struct via_spec
*spec
= codec
->spec
;
1076 return snd_hda_input_mux_info(spec
->input_mux
, uinfo
);
1079 static int via_mux_enum_get(struct snd_kcontrol
*kcontrol
,
1080 struct snd_ctl_elem_value
*ucontrol
)
1082 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1083 struct via_spec
*spec
= codec
->spec
;
1084 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1086 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
1090 static int via_mux_enum_put(struct snd_kcontrol
*kcontrol
,
1091 struct snd_ctl_elem_value
*ucontrol
)
1093 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1094 struct via_spec
*spec
= codec
->spec
;
1095 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1097 if (!spec
->mux_nids
[adc_idx
])
1099 /* switch to D0 beofre change index */
1100 if (snd_hda_codec_read(codec
, spec
->mux_nids
[adc_idx
], 0,
1101 AC_VERB_GET_POWER_STATE
, 0x00) != AC_PWRST_D0
)
1102 snd_hda_codec_write(codec
, spec
->mux_nids
[adc_idx
], 0,
1103 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
1104 /* update jack power state */
1105 set_jack_power_state(codec
);
1107 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
1108 spec
->mux_nids
[adc_idx
],
1109 &spec
->cur_mux
[adc_idx
]);
1112 static int via_independent_hp_info(struct snd_kcontrol
*kcontrol
,
1113 struct snd_ctl_elem_info
*uinfo
)
1115 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1116 struct via_spec
*spec
= codec
->spec
;
1117 return snd_hda_input_mux_info(spec
->hp_mux
, uinfo
);
1120 static int via_independent_hp_get(struct snd_kcontrol
*kcontrol
,
1121 struct snd_ctl_elem_value
*ucontrol
)
1123 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1124 hda_nid_t nid
= kcontrol
->private_value
;
1125 unsigned int pinsel
;
1127 /* use !! to translate conn sel 2 for VT1718S */
1128 pinsel
= !!snd_hda_codec_read(codec
, nid
, 0,
1129 AC_VERB_GET_CONNECT_SEL
,
1131 ucontrol
->value
.enumerated
.item
[0] = pinsel
;
1136 static void activate_ctl(struct hda_codec
*codec
, const char *name
, int active
)
1138 struct snd_kcontrol
*ctl
= snd_hda_find_mixer_ctl(codec
, name
);
1140 ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1141 ctl
->vd
[0].access
|= active
1142 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1143 snd_ctl_notify(codec
->bus
->card
,
1144 SNDRV_CTL_EVENT_MASK_VALUE
, &ctl
->id
);
1148 static hda_nid_t
side_mute_channel(struct via_spec
*spec
)
1150 switch (spec
->codec_type
) {
1151 case VT1708
: return 0x1b;
1152 case VT1709_10CH
: return 0x29;
1153 case VT1708B_8CH
: /* fall thru */
1154 case VT1708S
: return 0x27;
1159 static int update_side_mute_status(struct hda_codec
*codec
)
1161 /* mute side channel */
1162 struct via_spec
*spec
= codec
->spec
;
1163 unsigned int parm
= spec
->hp_independent_mode
1164 ? AMP_OUT_MUTE
: AMP_OUT_UNMUTE
;
1165 hda_nid_t sw3
= side_mute_channel(spec
);
1168 snd_hda_codec_write(codec
, sw3
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
1173 static int via_independent_hp_put(struct snd_kcontrol
*kcontrol
,
1174 struct snd_ctl_elem_value
*ucontrol
)
1176 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1177 struct via_spec
*spec
= codec
->spec
;
1178 hda_nid_t nid
= kcontrol
->private_value
;
1179 unsigned int pinsel
= ucontrol
->value
.enumerated
.item
[0];
1180 /* Get Independent Mode index of headphone pin widget */
1181 spec
->hp_independent_mode
= spec
->hp_independent_mode_index
== pinsel
1183 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, pinsel
);
1185 if (spec
->multiout
.hp_nid
&& spec
->multiout
.hp_nid
1186 != spec
->multiout
.dac_nids
[HDA_FRONT
])
1187 snd_hda_codec_setup_stream(codec
, spec
->multiout
.hp_nid
,
1190 update_side_mute_status(codec
);
1191 /* update HP volume/swtich active state */
1192 if (spec
->codec_type
== VT1708S
1193 || spec
->codec_type
== VT1702
1194 || spec
->codec_type
== VT1718S
1195 || spec
->codec_type
== VT1716S
1196 || spec
->codec_type
== VT2002P
1197 || spec
->codec_type
== VT1812
) {
1198 activate_ctl(codec
, "Headphone Playback Volume",
1199 spec
->hp_independent_mode
);
1200 activate_ctl(codec
, "Headphone Playback Switch",
1201 spec
->hp_independent_mode
);
1206 static struct snd_kcontrol_new via_hp_mixer
[2] = {
1208 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1209 .name
= "Independent HP",
1210 .info
= via_independent_hp_info
,
1211 .get
= via_independent_hp_get
,
1212 .put
= via_independent_hp_put
,
1215 .iface
= NID_MAPPING
,
1216 .name
= "Independent HP",
1220 static int via_hp_build(struct via_spec
*spec
)
1222 struct snd_kcontrol_new
*knew
;
1225 knew
= via_clone_control(spec
, &via_hp_mixer
[0]);
1229 switch (spec
->codec_type
) {
1240 nid
= spec
->autocfg
.hp_pins
[0];
1244 knew
->subdevice
= HDA_SUBDEV_NID_FLAG
| nid
;
1245 knew
->private_value
= nid
;
1247 knew
= via_clone_control(spec
, &via_hp_mixer
[1]);
1250 knew
->subdevice
= side_mute_channel(spec
);
1255 static void notify_aa_path_ctls(struct hda_codec
*codec
)
1258 struct snd_ctl_elem_id id
;
1259 const char *labels
[] = {"Mic", "Front Mic", "Line"};
1261 memset(&id
, 0, sizeof(id
));
1262 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
1263 for (i
= 0; i
< ARRAY_SIZE(labels
); i
++) {
1264 sprintf(id
.name
, "%s Playback Volume", labels
[i
]);
1265 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
1270 static void mute_aa_path(struct hda_codec
*codec
, int mute
)
1272 struct via_spec
*spec
= codec
->spec
;
1273 hda_nid_t nid_mixer
;
1277 /* get nid of MW0 and start & end index */
1278 switch (spec
->codec_type
) {
1301 /* check AA path's mute status */
1302 for (i
= start_idx
; i
<= end_idx
; i
++) {
1303 int val
= mute
? HDA_AMP_MUTE
: HDA_AMP_UNMUTE
;
1304 snd_hda_codec_amp_stereo(codec
, nid_mixer
, HDA_INPUT
, i
,
1308 static int is_smart51_pins(struct via_spec
*spec
, hda_nid_t pin
)
1312 for (index
= AUTO_PIN_MIC
; index
< AUTO_PIN_FRONT_LINE
; index
++) {
1313 if (pin
== spec
->autocfg
.input_pins
[index
]) {
1321 static int via_smart51_info(struct snd_kcontrol
*kcontrol
,
1322 struct snd_ctl_elem_info
*uinfo
)
1324 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1326 uinfo
->value
.integer
.min
= 0;
1327 uinfo
->value
.integer
.max
= 1;
1331 static int via_smart51_get(struct snd_kcontrol
*kcontrol
,
1332 struct snd_ctl_elem_value
*ucontrol
)
1334 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1335 struct via_spec
*spec
= codec
->spec
;
1336 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
1340 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
1341 hda_nid_t nid
= spec
->autocfg
.input_pins
[index
[i
]];
1344 snd_hda_codec_read(codec
, nid
, 0,
1345 AC_VERB_GET_PIN_WIDGET_CONTROL
,
1347 if (i
== AUTO_PIN_FRONT_MIC
1348 && spec
->hp_independent_mode
1349 && spec
->codec_type
!= VT1718S
)
1350 continue; /* ignore FMic for independent HP */
1351 if (ctl
& AC_PINCTL_IN_EN
1352 && !(ctl
& AC_PINCTL_OUT_EN
))
1356 *ucontrol
->value
.integer
.value
= on
;
1360 static int via_smart51_put(struct snd_kcontrol
*kcontrol
,
1361 struct snd_ctl_elem_value
*ucontrol
)
1363 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1364 struct via_spec
*spec
= codec
->spec
;
1365 int out_in
= *ucontrol
->value
.integer
.value
1366 ? AC_PINCTL_OUT_EN
: AC_PINCTL_IN_EN
;
1367 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
1370 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
1371 hda_nid_t nid
= spec
->autocfg
.input_pins
[index
[i
]];
1372 if (i
== AUTO_PIN_FRONT_MIC
1373 && spec
->hp_independent_mode
1374 && spec
->codec_type
!= VT1718S
)
1375 continue; /* don't retask FMic for independent HP */
1377 unsigned int parm
= snd_hda_codec_read(
1379 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
1380 parm
&= ~(AC_PINCTL_IN_EN
| AC_PINCTL_OUT_EN
);
1382 snd_hda_codec_write(codec
, nid
, 0,
1383 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1385 if (out_in
== AC_PINCTL_OUT_EN
) {
1386 mute_aa_path(codec
, 1);
1387 notify_aa_path_ctls(codec
);
1389 if (spec
->codec_type
== VT1718S
)
1390 snd_hda_codec_amp_stereo(
1391 codec
, nid
, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
1394 if (i
== AUTO_PIN_FRONT_MIC
) {
1395 if (spec
->codec_type
== VT1708S
1396 || spec
->codec_type
== VT1716S
) {
1397 /* input = index 1 (AOW3) */
1398 snd_hda_codec_write(
1400 AC_VERB_SET_CONNECT_SEL
, 1);
1401 snd_hda_codec_amp_stereo(
1402 codec
, nid
, HDA_OUTPUT
,
1403 0, HDA_AMP_MUTE
, HDA_AMP_UNMUTE
);
1407 spec
->smart51_enabled
= *ucontrol
->value
.integer
.value
;
1408 set_jack_power_state(codec
);
1412 static struct snd_kcontrol_new via_smart51_mixer
[2] = {
1414 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1415 .name
= "Smart 5.1",
1417 .info
= via_smart51_info
,
1418 .get
= via_smart51_get
,
1419 .put
= via_smart51_put
,
1422 .iface
= NID_MAPPING
,
1423 .name
= "Smart 5.1",
1427 static int via_smart51_build(struct via_spec
*spec
)
1429 struct snd_kcontrol_new
*knew
;
1430 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
1434 knew
= via_clone_control(spec
, &via_smart51_mixer
[0]);
1438 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
1439 nid
= spec
->autocfg
.input_pins
[index
[i
]];
1441 knew
= via_clone_control(spec
, &via_smart51_mixer
[1]);
1444 knew
->subdevice
= nid
;
1451 /* capture mixer elements */
1452 static struct snd_kcontrol_new vt1708_capture_mixer
[] = {
1453 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT
),
1454 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT
),
1455 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT
),
1456 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT
),
1458 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1459 /* The multiple "Capture Source" controls confuse alsamixer
1460 * So call somewhat different..
1462 /* .name = "Capture Source", */
1463 .name
= "Input Source",
1465 .info
= via_mux_enum_info
,
1466 .get
= via_mux_enum_get
,
1467 .put
= via_mux_enum_put
,
1472 /* check AA path's mute statue */
1473 static int is_aa_path_mute(struct hda_codec
*codec
)
1476 hda_nid_t nid_mixer
;
1480 struct via_spec
*spec
= codec
->spec
;
1481 /* get nid of MW0 and start & end index */
1482 switch (spec
->codec_type
) {
1510 /* check AA path's mute status */
1511 for (i
= start_idx
; i
<= end_idx
; i
++) {
1512 unsigned int con_list
= snd_hda_codec_read(
1513 codec
, nid_mixer
, 0, AC_VERB_GET_CONNECT_LIST
, i
/4*4);
1514 int shift
= 8 * (i
% 4);
1515 hda_nid_t nid_pin
= (con_list
& (0xff << shift
)) >> shift
;
1516 unsigned int defconf
= snd_hda_codec_get_pincfg(codec
, nid_pin
);
1517 if (get_defcfg_connect(defconf
) == AC_JACK_PORT_COMPLEX
) {
1518 /* check mute status while the pin is connected */
1519 int mute_l
= snd_hda_codec_amp_read(codec
, nid_mixer
, 0,
1521 int mute_r
= snd_hda_codec_amp_read(codec
, nid_mixer
, 1,
1523 if (!mute_l
|| !mute_r
) {
1532 /* enter/exit analog low-current mode */
1533 static void analog_low_current_mode(struct hda_codec
*codec
, int stream_idle
)
1535 struct via_spec
*spec
= codec
->spec
;
1536 static int saved_stream_idle
= 1; /* saved stream idle status */
1537 int enable
= is_aa_path_mute(codec
);
1538 unsigned int verb
= 0;
1539 unsigned int parm
= 0;
1541 if (stream_idle
== -1) /* stream status did not change */
1542 enable
= enable
&& saved_stream_idle
;
1544 enable
= enable
&& stream_idle
;
1545 saved_stream_idle
= stream_idle
;
1548 /* decide low current mode's verb & parameter */
1549 switch (spec
->codec_type
) {
1553 parm
= enable
? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1559 parm
= enable
? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1563 parm
= enable
? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1568 parm
= enable
? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1571 return; /* other codecs are not supported */
1574 snd_hda_codec_write(codec
, codec
->afg
, 0, verb
, parm
);
1578 * generic initialization of ADC, input mixers and output mixers
1580 static struct hda_verb vt1708_volume_init_verbs
[] = {
1582 * Unmute ADC0-1 and set the default input to mic-in
1584 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1585 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1588 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1591 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1592 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1593 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1594 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1595 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1596 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1599 * Set up output mixers (0x19 - 0x1b)
1601 /* set vol=0 to output mixers */
1602 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1603 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1604 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1606 /* Setup default input MW0 to PW4 */
1607 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
1608 /* PW9 Output enable */
1609 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1613 static int via_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1614 struct hda_codec
*codec
,
1615 struct snd_pcm_substream
*substream
)
1617 struct via_spec
*spec
= codec
->spec
;
1618 int idle
= substream
->pstr
->substream_opened
== 1
1619 && substream
->ref_count
== 0;
1620 analog_low_current_mode(codec
, idle
);
1621 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
1625 static void playback_multi_pcm_prep_0(struct hda_codec
*codec
,
1626 unsigned int stream_tag
,
1627 unsigned int format
,
1628 struct snd_pcm_substream
*substream
)
1630 struct via_spec
*spec
= codec
->spec
;
1631 struct hda_multi_out
*mout
= &spec
->multiout
;
1632 hda_nid_t
*nids
= mout
->dac_nids
;
1633 int chs
= substream
->runtime
->channels
;
1636 mutex_lock(&codec
->spdif_mutex
);
1637 if (mout
->dig_out_nid
&& mout
->dig_out_used
!= HDA_DIG_EXCLUSIVE
) {
1639 snd_hda_is_supported_format(codec
, mout
->dig_out_nid
,
1641 !(codec
->spdif_status
& IEC958_AES0_NONAUDIO
)) {
1642 mout
->dig_out_used
= HDA_DIG_ANALOG_DUP
;
1643 /* turn off SPDIF once; otherwise the IEC958 bits won't
1645 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1646 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1647 AC_VERB_SET_DIGI_CONVERT_1
,
1649 ~AC_DIG1_ENABLE
& 0xff);
1650 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1651 stream_tag
, 0, format
);
1652 /* turn on again (if needed) */
1653 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1654 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1655 AC_VERB_SET_DIGI_CONVERT_1
,
1656 codec
->spdif_ctls
& 0xff);
1658 mout
->dig_out_used
= 0;
1659 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1663 mutex_unlock(&codec
->spdif_mutex
);
1666 snd_hda_codec_setup_stream(codec
, nids
[HDA_FRONT
], stream_tag
,
1669 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
]
1670 && !spec
->hp_independent_mode
)
1671 /* headphone out will just decode front left/right (stereo) */
1672 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
, stream_tag
,
1675 /* extra outputs copied from front */
1676 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1677 if (mout
->extra_out_nid
[i
])
1678 snd_hda_codec_setup_stream(codec
,
1679 mout
->extra_out_nid
[i
],
1680 stream_tag
, 0, format
);
1683 for (i
= 1; i
< mout
->num_dacs
; i
++) {
1684 if (chs
>= (i
+ 1) * 2) /* independent out */
1685 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1687 else /* copy front */
1688 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1693 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1694 struct hda_codec
*codec
,
1695 unsigned int stream_tag
,
1696 unsigned int format
,
1697 struct snd_pcm_substream
*substream
)
1699 struct via_spec
*spec
= codec
->spec
;
1700 struct hda_multi_out
*mout
= &spec
->multiout
;
1701 hda_nid_t
*nids
= mout
->dac_nids
;
1703 if (substream
->number
== 0)
1704 playback_multi_pcm_prep_0(codec
, stream_tag
, format
,
1707 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1708 spec
->hp_independent_mode
)
1709 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1710 stream_tag
, 0, format
);
1712 vt1708_start_hp_work(spec
);
1716 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1717 struct hda_codec
*codec
,
1718 struct snd_pcm_substream
*substream
)
1720 struct via_spec
*spec
= codec
->spec
;
1721 struct hda_multi_out
*mout
= &spec
->multiout
;
1722 hda_nid_t
*nids
= mout
->dac_nids
;
1725 if (substream
->number
== 0) {
1726 for (i
= 0; i
< mout
->num_dacs
; i
++)
1727 snd_hda_codec_setup_stream(codec
, nids
[i
], 0, 0, 0);
1729 if (mout
->hp_nid
&& !spec
->hp_independent_mode
)
1730 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1733 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1734 if (mout
->extra_out_nid
[i
])
1735 snd_hda_codec_setup_stream(codec
,
1736 mout
->extra_out_nid
[i
],
1738 mutex_lock(&codec
->spdif_mutex
);
1739 if (mout
->dig_out_nid
&&
1740 mout
->dig_out_used
== HDA_DIG_ANALOG_DUP
) {
1741 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1743 mout
->dig_out_used
= 0;
1745 mutex_unlock(&codec
->spdif_mutex
);
1747 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1748 spec
->hp_independent_mode
)
1749 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1752 vt1708_stop_hp_work(spec
);
1759 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1760 struct hda_codec
*codec
,
1761 struct snd_pcm_substream
*substream
)
1763 struct via_spec
*spec
= codec
->spec
;
1764 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
1767 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
1768 struct hda_codec
*codec
,
1769 struct snd_pcm_substream
*substream
)
1771 struct via_spec
*spec
= codec
->spec
;
1772 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
1775 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1776 struct hda_codec
*codec
,
1777 unsigned int stream_tag
,
1778 unsigned int format
,
1779 struct snd_pcm_substream
*substream
)
1781 struct via_spec
*spec
= codec
->spec
;
1782 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
1783 stream_tag
, format
, substream
);
1786 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1787 struct hda_codec
*codec
,
1788 struct snd_pcm_substream
*substream
)
1790 struct via_spec
*spec
= codec
->spec
;
1791 snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
1798 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1799 struct hda_codec
*codec
,
1800 unsigned int stream_tag
,
1801 unsigned int format
,
1802 struct snd_pcm_substream
*substream
)
1804 struct via_spec
*spec
= codec
->spec
;
1806 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
1807 stream_tag
, 0, format
);
1811 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1812 struct hda_codec
*codec
,
1813 struct snd_pcm_substream
*substream
)
1815 struct via_spec
*spec
= codec
->spec
;
1816 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
1820 static struct hda_pcm_stream vt1708_pcm_analog_playback
= {
1824 .nid
= 0x10, /* NID to query formats and rates */
1826 .open
= via_playback_pcm_open
,
1827 .prepare
= via_playback_multi_pcm_prepare
,
1828 .cleanup
= via_playback_multi_pcm_cleanup
1832 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
1836 .nid
= 0x10, /* NID to query formats and rates */
1837 /* We got noisy outputs on the right channel on VT1708 when
1838 * 24bit samples are used. Until any workaround is found,
1839 * disable the 24bit format, so far.
1841 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1843 .open
= via_playback_pcm_open
,
1844 .prepare
= via_playback_multi_pcm_prepare
,
1845 .cleanup
= via_playback_multi_pcm_cleanup
1849 static struct hda_pcm_stream vt1708_pcm_analog_capture
= {
1853 .nid
= 0x15, /* NID to query formats and rates */
1855 .prepare
= via_capture_pcm_prepare
,
1856 .cleanup
= via_capture_pcm_cleanup
1860 static struct hda_pcm_stream vt1708_pcm_digital_playback
= {
1864 /* NID is set in via_build_pcms */
1866 .open
= via_dig_playback_pcm_open
,
1867 .close
= via_dig_playback_pcm_close
,
1868 .prepare
= via_dig_playback_pcm_prepare
,
1869 .cleanup
= via_dig_playback_pcm_cleanup
1873 static struct hda_pcm_stream vt1708_pcm_digital_capture
= {
1879 static int via_build_controls(struct hda_codec
*codec
)
1881 struct via_spec
*spec
= codec
->spec
;
1882 struct snd_kcontrol
*kctl
;
1883 struct snd_kcontrol_new
*knew
;
1886 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1887 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1892 if (spec
->multiout
.dig_out_nid
) {
1893 err
= snd_hda_create_spdif_out_ctls(codec
,
1894 spec
->multiout
.dig_out_nid
);
1897 err
= snd_hda_create_spdif_share_sw(codec
,
1901 spec
->multiout
.share_spdif
= 1;
1903 if (spec
->dig_in_nid
) {
1904 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1909 /* assign Capture Source enums to NID */
1910 kctl
= snd_hda_find_mixer_ctl(codec
, "Input Source");
1911 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1912 err
= snd_hda_add_nids(codec
, kctl
, i
, spec
->mux_nids
,
1913 spec
->input_mux
->num_items
);
1918 /* other nid->control mapping */
1919 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1920 for (knew
= spec
->mixers
[i
]; knew
->name
; knew
++) {
1921 if (knew
->iface
!= NID_MAPPING
)
1923 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1926 err
= snd_hda_add_nid(codec
, kctl
, 0,
1931 /* init power states */
1932 set_jack_power_state(codec
);
1933 analog_low_current_mode(codec
, 1);
1935 via_free_kctls(codec
); /* no longer needed */
1939 static int via_build_pcms(struct hda_codec
*codec
)
1941 struct via_spec
*spec
= codec
->spec
;
1942 struct hda_pcm
*info
= spec
->pcm_rec
;
1944 codec
->num_pcms
= 1;
1945 codec
->pcm_info
= info
;
1947 info
->name
= spec
->stream_name_analog
;
1948 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1949 *(spec
->stream_analog_playback
);
1950 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1951 spec
->multiout
.dac_nids
[0];
1952 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *(spec
->stream_analog_capture
);
1953 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
1955 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
1956 spec
->multiout
.max_channels
;
1958 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
1961 info
->name
= spec
->stream_name_digital
;
1962 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
1963 if (spec
->multiout
.dig_out_nid
) {
1964 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1965 *(spec
->stream_digital_playback
);
1966 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1967 spec
->multiout
.dig_out_nid
;
1969 if (spec
->dig_in_nid
) {
1970 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
1971 *(spec
->stream_digital_capture
);
1972 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
1980 static void via_free(struct hda_codec
*codec
)
1982 struct via_spec
*spec
= codec
->spec
;
1987 via_free_kctls(codec
);
1988 vt1708_stop_hp_work(spec
);
1992 /* mute internal speaker if HP is plugged */
1993 static void via_hp_automute(struct hda_codec
*codec
)
1995 unsigned int present
= 0;
1996 struct via_spec
*spec
= codec
->spec
;
1998 present
= snd_hda_jack_detect(codec
, spec
->autocfg
.hp_pins
[0]);
2000 if (!spec
->hp_independent_mode
) {
2001 struct snd_ctl_elem_id id
;
2003 snd_hda_codec_amp_stereo(
2004 codec
, spec
->autocfg
.line_out_pins
[0], HDA_OUTPUT
, 0,
2005 HDA_AMP_MUTE
, present
? HDA_AMP_MUTE
: 0);
2007 memset(&id
, 0, sizeof(id
));
2008 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
2009 strcpy(id
.name
, "Front Playback Switch");
2010 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
2015 /* mute mono out if HP or Line out is plugged */
2016 static void via_mono_automute(struct hda_codec
*codec
)
2018 unsigned int hp_present
, lineout_present
;
2019 struct via_spec
*spec
= codec
->spec
;
2021 if (spec
->codec_type
!= VT1716S
)
2024 lineout_present
= snd_hda_jack_detect(codec
,
2025 spec
->autocfg
.line_out_pins
[0]);
2027 /* Mute Mono Out if Line Out is plugged */
2028 if (lineout_present
) {
2029 snd_hda_codec_amp_stereo(
2030 codec
, 0x2A, HDA_OUTPUT
, 0, HDA_AMP_MUTE
, HDA_AMP_MUTE
);
2034 hp_present
= snd_hda_jack_detect(codec
, spec
->autocfg
.hp_pins
[0]);
2036 if (!spec
->hp_independent_mode
)
2037 snd_hda_codec_amp_stereo(
2038 codec
, 0x2A, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
2039 hp_present
? HDA_AMP_MUTE
: 0);
2042 static void via_gpio_control(struct hda_codec
*codec
)
2044 unsigned int gpio_data
;
2045 unsigned int vol_counter
;
2047 unsigned int master_vol
;
2049 struct via_spec
*spec
= codec
->spec
;
2051 gpio_data
= snd_hda_codec_read(codec
, codec
->afg
, 0,
2052 AC_VERB_GET_GPIO_DATA
, 0) & 0x03;
2054 vol_counter
= (snd_hda_codec_read(codec
, codec
->afg
, 0,
2055 0xF84, 0) & 0x3F0000) >> 16;
2057 vol
= vol_counter
& 0x1F;
2058 master_vol
= snd_hda_codec_read(codec
, 0x1A, 0,
2059 AC_VERB_GET_AMP_GAIN_MUTE
,
2062 if (gpio_data
== 0x02) {
2063 /* unmute line out */
2064 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
2065 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
2067 if (vol_counter
& 0x20) {
2068 /* decrease volume */
2069 if (vol
> master_vol
)
2071 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
,
2075 /* increase volume */
2076 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
, 0,
2078 ((master_vol
+vol
) > 0x2A) ? 0x2A :
2081 } else if (!(gpio_data
& 0x02)) {
2083 snd_hda_codec_amp_stereo(codec
,
2084 spec
->autocfg
.line_out_pins
[0],
2085 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
2090 /* mute Internal-Speaker if HP is plugged */
2091 static void via_speaker_automute(struct hda_codec
*codec
)
2093 unsigned int hp_present
;
2094 struct via_spec
*spec
= codec
->spec
;
2096 if (spec
->codec_type
!= VT2002P
&& spec
->codec_type
!= VT1812
)
2099 hp_present
= snd_hda_jack_detect(codec
, spec
->autocfg
.hp_pins
[0]);
2101 if (!spec
->hp_independent_mode
) {
2102 struct snd_ctl_elem_id id
;
2103 snd_hda_codec_amp_stereo(
2104 codec
, spec
->autocfg
.speaker_pins
[0], HDA_OUTPUT
, 0,
2105 HDA_AMP_MUTE
, hp_present
? HDA_AMP_MUTE
: 0);
2107 memset(&id
, 0, sizeof(id
));
2108 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
2109 strcpy(id
.name
, "Speaker Playback Switch");
2110 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
2115 /* mute line-out and internal speaker if HP is plugged */
2116 static void via_hp_bind_automute(struct hda_codec
*codec
)
2118 /* use long instead of int below just to avoid an internal compiler
2119 * error with gcc 4.0.x
2121 unsigned long hp_present
, present
= 0;
2122 struct via_spec
*spec
= codec
->spec
;
2125 if (!spec
->autocfg
.hp_pins
[0] || !spec
->autocfg
.line_out_pins
[0])
2128 hp_present
= snd_hda_jack_detect(codec
, spec
->autocfg
.hp_pins
[0]);
2130 present
= snd_hda_jack_detect(codec
, spec
->autocfg
.line_out_pins
[0]);
2132 if (!spec
->hp_independent_mode
) {
2133 /* Mute Line-Outs */
2134 for (i
= 0; i
< spec
->autocfg
.line_outs
; i
++)
2135 snd_hda_codec_amp_stereo(
2136 codec
, spec
->autocfg
.line_out_pins
[i
],
2138 HDA_AMP_MUTE
, hp_present
? HDA_AMP_MUTE
: 0);
2140 present
= hp_present
;
2143 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++)
2144 snd_hda_codec_amp_stereo(
2145 codec
, spec
->autocfg
.speaker_pins
[i
], HDA_OUTPUT
, 0,
2146 HDA_AMP_MUTE
, present
? HDA_AMP_MUTE
: 0);
2150 /* unsolicited event for jack sensing */
2151 static void via_unsol_event(struct hda_codec
*codec
,
2155 if (res
& VIA_HP_EVENT
)
2156 via_hp_automute(codec
);
2157 if (res
& VIA_GPIO_EVENT
)
2158 via_gpio_control(codec
);
2159 if (res
& VIA_JACK_EVENT
)
2160 set_jack_power_state(codec
);
2161 if (res
& VIA_MONO_EVENT
)
2162 via_mono_automute(codec
);
2163 if (res
& VIA_SPEAKER_EVENT
)
2164 via_speaker_automute(codec
);
2165 if (res
& VIA_BIND_HP_EVENT
)
2166 via_hp_bind_automute(codec
);
2169 static int via_init(struct hda_codec
*codec
)
2171 struct via_spec
*spec
= codec
->spec
;
2173 for (i
= 0; i
< spec
->num_iverbs
; i
++)
2174 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
2176 spec
->codec_type
= get_codec_type(codec
);
2177 if (spec
->codec_type
== VT1708BCE
)
2178 spec
->codec_type
= VT1708S
; /* VT1708BCE & VT1708S are almost
2180 /* Lydia Add for EAPD enable */
2181 if (!spec
->dig_in_nid
) { /* No Digital In connection */
2182 if (spec
->dig_in_pin
) {
2183 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
2184 AC_VERB_SET_PIN_WIDGET_CONTROL
,
2186 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
2187 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
2189 } else /* enable SPDIF-input pin */
2190 snd_hda_codec_write(codec
, spec
->autocfg
.dig_in_pin
, 0,
2191 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
2193 /* assign slave outs */
2194 if (spec
->slave_dig_outs
[0])
2195 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
2200 #ifdef SND_HDA_NEEDS_RESUME
2201 static int via_suspend(struct hda_codec
*codec
, pm_message_t state
)
2203 struct via_spec
*spec
= codec
->spec
;
2204 vt1708_stop_hp_work(spec
);
2209 #ifdef CONFIG_SND_HDA_POWER_SAVE
2210 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
2212 struct via_spec
*spec
= codec
->spec
;
2213 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
2219 static struct hda_codec_ops via_patch_ops
= {
2220 .build_controls
= via_build_controls
,
2221 .build_pcms
= via_build_pcms
,
2224 #ifdef SND_HDA_NEEDS_RESUME
2225 .suspend
= via_suspend
,
2227 #ifdef CONFIG_SND_HDA_POWER_SAVE
2228 .check_power_status
= via_check_power_status
,
2232 /* fill in the dac_nids table from the parsed pin configuration */
2233 static int vt1708_auto_fill_dac_nids(struct via_spec
*spec
,
2234 const struct auto_pin_cfg
*cfg
)
2239 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2241 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2243 for (i
= 0; i
< 4; i
++) {
2244 nid
= cfg
->line_out_pins
[i
];
2246 /* config dac list */
2248 case AUTO_SEQ_FRONT
:
2249 spec
->multiout
.dac_nids
[i
] = 0x10;
2251 case AUTO_SEQ_CENLFE
:
2252 spec
->multiout
.dac_nids
[i
] = 0x12;
2254 case AUTO_SEQ_SURROUND
:
2255 spec
->multiout
.dac_nids
[i
] = 0x11;
2258 spec
->multiout
.dac_nids
[i
] = 0x13;
2267 /* add playback controls from the parsed DAC table */
2268 static int vt1708_auto_create_multi_out_ctls(struct via_spec
*spec
,
2269 const struct auto_pin_cfg
*cfg
)
2272 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2273 hda_nid_t nid
, nid_vol
, nid_vols
[] = {0x17, 0x19, 0x1a, 0x1b};
2276 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2277 nid
= cfg
->line_out_pins
[i
];
2282 nid_vol
= nid_vols
[i
];
2284 if (i
== AUTO_SEQ_CENLFE
) {
2286 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2287 "Center Playback Volume",
2288 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2292 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2293 "LFE Playback Volume",
2294 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2298 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2299 "Center Playback Switch",
2300 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2304 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2305 "LFE Playback Switch",
2306 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2310 } else if (i
== AUTO_SEQ_FRONT
) {
2311 /* add control to mixer index 0 */
2312 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2313 "Master Front Playback Volume",
2314 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2318 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2319 "Master Front Playback Switch",
2320 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2325 /* add control to PW3 */
2326 sprintf(name
, "%s Playback Volume", chname
[i
]);
2327 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2328 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2332 sprintf(name
, "%s Playback Switch", chname
[i
]);
2333 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2334 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2339 sprintf(name
, "%s Playback Volume", chname
[i
]);
2340 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2341 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2345 sprintf(name
, "%s Playback Switch", chname
[i
]);
2346 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2347 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2357 static void create_hp_imux(struct via_spec
*spec
)
2360 struct hda_input_mux
*imux
= &spec
->private_imux
[1];
2361 static const char *texts
[] = { "OFF", "ON", NULL
};
2363 /* for hp mode select */
2365 while (texts
[i
] != NULL
) {
2366 imux
->items
[imux
->num_items
].label
= texts
[i
];
2367 imux
->items
[imux
->num_items
].index
= i
;
2372 spec
->hp_mux
= &spec
->private_imux
[1];
2375 static int vt1708_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2382 spec
->multiout
.hp_nid
= VT1708_HP_NID
; /* AOW3 */
2383 spec
->hp_independent_mode_index
= 1;
2385 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2386 "Headphone Playback Volume",
2387 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2390 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2391 "Headphone Playback Switch",
2392 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2396 create_hp_imux(spec
);
2401 /* create playback/capture controls for input pins */
2402 static int vt1708_auto_create_analog_input_ctls(struct via_spec
*spec
,
2403 const struct auto_pin_cfg
*cfg
)
2405 static char *labels
[] = {
2406 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2408 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2409 int i
, err
, idx
= 0;
2411 /* for internal loopback recording select */
2412 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2413 imux
->items
[imux
->num_items
].index
= idx
;
2416 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2417 if (!cfg
->input_pins
[i
])
2420 switch (cfg
->input_pins
[i
]) {
2421 case 0x1d: /* Mic */
2425 case 0x1e: /* Line In */
2429 case 0x21: /* Front Mic */
2437 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x17);
2440 imux
->items
[imux
->num_items
].label
= labels
[i
];
2441 imux
->items
[imux
->num_items
].index
= idx
;
2447 #ifdef CONFIG_SND_HDA_POWER_SAVE
2448 static struct hda_amp_list vt1708_loopbacks
[] = {
2449 { 0x17, HDA_INPUT
, 1 },
2450 { 0x17, HDA_INPUT
, 2 },
2451 { 0x17, HDA_INPUT
, 3 },
2452 { 0x17, HDA_INPUT
, 4 },
2457 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
2459 unsigned int def_conf
;
2460 unsigned char seqassoc
;
2462 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
2463 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
2464 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
2465 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
2466 && (seqassoc
== 0xf0 || seqassoc
== 0xff)) {
2467 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
2468 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
2474 static int vt1708_jack_detectect_get(struct snd_kcontrol
*kcontrol
,
2475 struct snd_ctl_elem_value
*ucontrol
)
2477 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2478 struct via_spec
*spec
= codec
->spec
;
2480 if (spec
->codec_type
!= VT1708
)
2482 spec
->vt1708_jack_detectect
=
2483 !((snd_hda_codec_read(codec
, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2484 ucontrol
->value
.integer
.value
[0] = spec
->vt1708_jack_detectect
;
2488 static int vt1708_jack_detectect_put(struct snd_kcontrol
*kcontrol
,
2489 struct snd_ctl_elem_value
*ucontrol
)
2491 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2492 struct via_spec
*spec
= codec
->spec
;
2495 if (spec
->codec_type
!= VT1708
)
2497 spec
->vt1708_jack_detectect
= ucontrol
->value
.integer
.value
[0];
2498 change
= (0x1 & (snd_hda_codec_read(codec
, 0x1, 0, 0xf84, 0) >> 8))
2499 == !spec
->vt1708_jack_detectect
;
2500 if (spec
->vt1708_jack_detectect
) {
2501 mute_aa_path(codec
, 1);
2502 notify_aa_path_ctls(codec
);
2507 static struct snd_kcontrol_new vt1708_jack_detectect
[] = {
2509 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2510 .name
= "Jack Detect",
2512 .info
= snd_ctl_boolean_mono_info
,
2513 .get
= vt1708_jack_detectect_get
,
2514 .put
= vt1708_jack_detectect_put
,
2519 static int vt1708_parse_auto_config(struct hda_codec
*codec
)
2521 struct via_spec
*spec
= codec
->spec
;
2524 /* Add HP and CD pin config connect bit re-config action */
2525 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
2526 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
2528 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2531 err
= vt1708_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2534 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2535 return 0; /* can't find valid BIOS pin config */
2537 err
= vt1708_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2540 err
= vt1708_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2543 err
= vt1708_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2546 /* add jack detect on/off control */
2547 err
= snd_hda_add_new_ctls(codec
, vt1708_jack_detectect
);
2551 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2553 if (spec
->autocfg
.dig_outs
)
2554 spec
->multiout
.dig_out_nid
= VT1708_DIGOUT_NID
;
2555 spec
->dig_in_pin
= VT1708_DIGIN_PIN
;
2556 if (spec
->autocfg
.dig_in_pin
)
2557 spec
->dig_in_nid
= VT1708_DIGIN_NID
;
2559 if (spec
->kctls
.list
)
2560 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2562 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_volume_init_verbs
;
2564 spec
->input_mux
= &spec
->private_imux
[0];
2569 via_smart51_build(spec
);
2573 /* init callback for auto-configuration model -- overriding the default init */
2574 static int via_auto_init(struct hda_codec
*codec
)
2576 struct via_spec
*spec
= codec
->spec
;
2579 via_auto_init_multi_out(codec
);
2580 via_auto_init_hp_out(codec
);
2581 via_auto_init_analog_input(codec
);
2582 if (spec
->codec_type
== VT2002P
|| spec
->codec_type
== VT1812
) {
2583 via_hp_bind_automute(codec
);
2585 via_hp_automute(codec
);
2586 via_speaker_automute(codec
);
2592 static void vt1708_update_hp_jack_state(struct work_struct
*work
)
2594 struct via_spec
*spec
= container_of(work
, struct via_spec
,
2595 vt1708_hp_work
.work
);
2596 if (spec
->codec_type
!= VT1708
)
2598 /* if jack state toggled */
2599 if (spec
->vt1708_hp_present
2600 != snd_hda_jack_detect(spec
->codec
, spec
->autocfg
.hp_pins
[0])) {
2601 spec
->vt1708_hp_present
^= 1;
2602 via_hp_automute(spec
->codec
);
2604 vt1708_start_hp_work(spec
);
2607 static int get_mux_nids(struct hda_codec
*codec
)
2609 struct via_spec
*spec
= codec
->spec
;
2610 hda_nid_t nid
, conn
[8];
2614 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
2615 nid
= spec
->adc_nids
[i
];
2617 type
= get_wcaps_type(get_wcaps(codec
, nid
));
2618 if (type
== AC_WID_PIN
)
2620 n
= snd_hda_get_connections(codec
, nid
, conn
,
2625 spec
->mux_nids
[i
] = nid
;
2634 static int patch_vt1708(struct hda_codec
*codec
)
2636 struct via_spec
*spec
;
2639 /* create a codec specific record */
2640 spec
= via_new_spec(codec
);
2644 /* automatic parse from the BIOS config */
2645 err
= vt1708_parse_auto_config(codec
);
2650 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2651 "from BIOS. Using genenic mode...\n");
2655 spec
->stream_name_analog
= "VT1708 Analog";
2656 spec
->stream_analog_playback
= &vt1708_pcm_analog_playback
;
2657 /* disable 32bit format on VT1708 */
2658 if (codec
->vendor_id
== 0x11061708)
2659 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
2660 spec
->stream_analog_capture
= &vt1708_pcm_analog_capture
;
2662 spec
->stream_name_digital
= "VT1708 Digital";
2663 spec
->stream_digital_playback
= &vt1708_pcm_digital_playback
;
2664 spec
->stream_digital_capture
= &vt1708_pcm_digital_capture
;
2667 if (!spec
->adc_nids
&& spec
->input_mux
) {
2668 spec
->adc_nids
= vt1708_adc_nids
;
2669 spec
->num_adc_nids
= ARRAY_SIZE(vt1708_adc_nids
);
2670 get_mux_nids(codec
);
2671 spec
->mixers
[spec
->num_mixers
] = vt1708_capture_mixer
;
2675 codec
->patch_ops
= via_patch_ops
;
2677 codec
->patch_ops
.init
= via_auto_init
;
2678 #ifdef CONFIG_SND_HDA_POWER_SAVE
2679 spec
->loopback
.amplist
= vt1708_loopbacks
;
2681 INIT_DELAYED_WORK(&spec
->vt1708_hp_work
, vt1708_update_hp_jack_state
);
2685 /* capture mixer elements */
2686 static struct snd_kcontrol_new vt1709_capture_mixer
[] = {
2687 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT
),
2688 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT
),
2689 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT
),
2690 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT
),
2691 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT
),
2692 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT
),
2694 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2695 /* The multiple "Capture Source" controls confuse alsamixer
2696 * So call somewhat different..
2698 /* .name = "Capture Source", */
2699 .name
= "Input Source",
2701 .info
= via_mux_enum_info
,
2702 .get
= via_mux_enum_get
,
2703 .put
= via_mux_enum_put
,
2708 static struct hda_verb vt1709_uniwill_init_verbs
[] = {
2709 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
,
2710 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
2715 * generic initialization of ADC, input mixers and output mixers
2717 static struct hda_verb vt1709_10ch_volume_init_verbs
[] = {
2719 * Unmute ADC0-2 and set the default input to mic-in
2721 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2722 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2723 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2726 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2729 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2730 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2731 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2732 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2733 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2734 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2737 * Set up output selector (0x1a, 0x1b, 0x29)
2739 /* set vol=0 to output mixers */
2740 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2741 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2742 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2745 * Unmute PW3 and PW4
2747 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2748 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2750 /* Set input of PW4 as MW0 */
2751 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
2752 /* PW9 Output enable */
2753 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2757 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback
= {
2761 .nid
= 0x10, /* NID to query formats and rates */
2763 .open
= via_playback_pcm_open
,
2764 .prepare
= via_playback_multi_pcm_prepare
,
2765 .cleanup
= via_playback_multi_pcm_cleanup
,
2769 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback
= {
2773 .nid
= 0x10, /* NID to query formats and rates */
2775 .open
= via_playback_pcm_open
,
2776 .prepare
= via_playback_multi_pcm_prepare
,
2777 .cleanup
= via_playback_multi_pcm_cleanup
,
2781 static struct hda_pcm_stream vt1709_pcm_analog_capture
= {
2785 .nid
= 0x14, /* NID to query formats and rates */
2787 .prepare
= via_capture_pcm_prepare
,
2788 .cleanup
= via_capture_pcm_cleanup
2792 static struct hda_pcm_stream vt1709_pcm_digital_playback
= {
2796 /* NID is set in via_build_pcms */
2798 .open
= via_dig_playback_pcm_open
,
2799 .close
= via_dig_playback_pcm_close
2803 static struct hda_pcm_stream vt1709_pcm_digital_capture
= {
2809 static int vt1709_auto_fill_dac_nids(struct via_spec
*spec
,
2810 const struct auto_pin_cfg
*cfg
)
2815 if (cfg
->line_outs
== 4) /* 10 channels */
2816 spec
->multiout
.num_dacs
= cfg
->line_outs
+1; /* AOW0~AOW4 */
2817 else if (cfg
->line_outs
== 3) /* 6 channels */
2818 spec
->multiout
.num_dacs
= cfg
->line_outs
; /* AOW0~AOW2 */
2820 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2822 if (cfg
->line_outs
== 4) { /* 10 channels */
2823 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2824 nid
= cfg
->line_out_pins
[i
];
2826 /* config dac list */
2828 case AUTO_SEQ_FRONT
:
2830 spec
->multiout
.dac_nids
[i
] = 0x10;
2832 case AUTO_SEQ_CENLFE
:
2834 spec
->multiout
.dac_nids
[i
] = 0x12;
2836 case AUTO_SEQ_SURROUND
:
2838 spec
->multiout
.dac_nids
[i
] = 0x11;
2842 spec
->multiout
.dac_nids
[i
] = 0x27;
2849 spec
->multiout
.dac_nids
[cfg
->line_outs
] = 0x28; /* AOW4 */
2851 } else if (cfg
->line_outs
== 3) { /* 6 channels */
2852 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2853 nid
= cfg
->line_out_pins
[i
];
2855 /* config dac list */
2857 case AUTO_SEQ_FRONT
:
2859 spec
->multiout
.dac_nids
[i
] = 0x10;
2861 case AUTO_SEQ_CENLFE
:
2863 spec
->multiout
.dac_nids
[i
] = 0x12;
2865 case AUTO_SEQ_SURROUND
:
2867 spec
->multiout
.dac_nids
[i
] = 0x11;
2879 /* add playback controls from the parsed DAC table */
2880 static int vt1709_auto_create_multi_out_ctls(struct via_spec
*spec
,
2881 const struct auto_pin_cfg
*cfg
)
2884 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2885 hda_nid_t nid
, nid_vol
, nid_vols
[] = {0x18, 0x1a, 0x1b, 0x29};
2888 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2889 nid
= cfg
->line_out_pins
[i
];
2894 nid_vol
= nid_vols
[i
];
2896 if (i
== AUTO_SEQ_CENLFE
) {
2898 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2899 "Center Playback Volume",
2900 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2904 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2905 "LFE Playback Volume",
2906 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2910 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2911 "Center Playback Switch",
2912 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2916 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2917 "LFE Playback Switch",
2918 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2922 } else if (i
== AUTO_SEQ_FRONT
) {
2923 /* ADD control to mixer index 0 */
2924 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2925 "Master Front Playback Volume",
2926 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2930 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2931 "Master Front Playback Switch",
2932 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2937 /* add control to PW3 */
2938 sprintf(name
, "%s Playback Volume", chname
[i
]);
2939 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2940 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2944 sprintf(name
, "%s Playback Switch", chname
[i
]);
2945 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2946 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2950 } else if (i
== AUTO_SEQ_SURROUND
) {
2951 sprintf(name
, "%s Playback Volume", chname
[i
]);
2952 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2953 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2957 sprintf(name
, "%s Playback Switch", chname
[i
]);
2958 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2959 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2963 } else if (i
== AUTO_SEQ_SIDE
) {
2964 sprintf(name
, "%s Playback Volume", chname
[i
]);
2965 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2966 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2970 sprintf(name
, "%s Playback Switch", chname
[i
]);
2971 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2972 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2982 static int vt1709_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2989 if (spec
->multiout
.num_dacs
== 5) /* 10 channels */
2990 spec
->multiout
.hp_nid
= VT1709_HP_DAC_NID
;
2991 else if (spec
->multiout
.num_dacs
== 3) /* 6 channels */
2992 spec
->multiout
.hp_nid
= 0;
2993 spec
->hp_independent_mode_index
= 1;
2995 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2996 "Headphone Playback Volume",
2997 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3000 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3001 "Headphone Playback Switch",
3002 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3009 /* create playback/capture controls for input pins */
3010 static int vt1709_auto_create_analog_input_ctls(struct via_spec
*spec
,
3011 const struct auto_pin_cfg
*cfg
)
3013 static char *labels
[] = {
3014 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3016 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3017 int i
, err
, idx
= 0;
3019 /* for internal loopback recording select */
3020 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3021 imux
->items
[imux
->num_items
].index
= idx
;
3024 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3025 if (!cfg
->input_pins
[i
])
3028 switch (cfg
->input_pins
[i
]) {
3029 case 0x1d: /* Mic */
3033 case 0x1e: /* Line In */
3037 case 0x21: /* Front Mic */
3045 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x18);
3048 imux
->items
[imux
->num_items
].label
= labels
[i
];
3049 imux
->items
[imux
->num_items
].index
= idx
;
3055 static int vt1709_parse_auto_config(struct hda_codec
*codec
)
3057 struct via_spec
*spec
= codec
->spec
;
3060 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3063 err
= vt1709_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3066 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3067 return 0; /* can't find valid BIOS pin config */
3069 err
= vt1709_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
3072 err
= vt1709_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3075 err
= vt1709_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3079 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3081 if (spec
->autocfg
.dig_outs
)
3082 spec
->multiout
.dig_out_nid
= VT1709_DIGOUT_NID
;
3083 spec
->dig_in_pin
= VT1709_DIGIN_PIN
;
3084 if (spec
->autocfg
.dig_in_pin
)
3085 spec
->dig_in_nid
= VT1709_DIGIN_NID
;
3087 if (spec
->kctls
.list
)
3088 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3090 spec
->input_mux
= &spec
->private_imux
[0];
3095 via_smart51_build(spec
);
3099 #ifdef CONFIG_SND_HDA_POWER_SAVE
3100 static struct hda_amp_list vt1709_loopbacks
[] = {
3101 { 0x18, HDA_INPUT
, 1 },
3102 { 0x18, HDA_INPUT
, 2 },
3103 { 0x18, HDA_INPUT
, 3 },
3104 { 0x18, HDA_INPUT
, 4 },
3109 static int patch_vt1709_10ch(struct hda_codec
*codec
)
3111 struct via_spec
*spec
;
3114 /* create a codec specific record */
3115 spec
= via_new_spec(codec
);
3119 err
= vt1709_parse_auto_config(codec
);
3124 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
3125 "Using genenic mode...\n");
3128 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_10ch_volume_init_verbs
;
3129 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
3131 spec
->stream_name_analog
= "VT1709 Analog";
3132 spec
->stream_analog_playback
= &vt1709_10ch_pcm_analog_playback
;
3133 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
3135 spec
->stream_name_digital
= "VT1709 Digital";
3136 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
3137 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
3140 if (!spec
->adc_nids
&& spec
->input_mux
) {
3141 spec
->adc_nids
= vt1709_adc_nids
;
3142 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
3143 get_mux_nids(codec
);
3144 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
3148 codec
->patch_ops
= via_patch_ops
;
3150 codec
->patch_ops
.init
= via_auto_init
;
3151 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3152 #ifdef CONFIG_SND_HDA_POWER_SAVE
3153 spec
->loopback
.amplist
= vt1709_loopbacks
;
3159 * generic initialization of ADC, input mixers and output mixers
3161 static struct hda_verb vt1709_6ch_volume_init_verbs
[] = {
3163 * Unmute ADC0-2 and set the default input to mic-in
3165 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3166 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3167 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3170 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3173 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3174 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3175 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3176 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3177 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3178 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3181 * Set up output selector (0x1a, 0x1b, 0x29)
3183 /* set vol=0 to output mixers */
3184 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3185 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3186 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3189 * Unmute PW3 and PW4
3191 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3192 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3194 /* Set input of PW4 as MW0 */
3195 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
3196 /* PW9 Output enable */
3197 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3201 static int patch_vt1709_6ch(struct hda_codec
*codec
)
3203 struct via_spec
*spec
;
3206 /* create a codec specific record */
3207 spec
= via_new_spec(codec
);
3211 err
= vt1709_parse_auto_config(codec
);
3216 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
3217 "Using genenic mode...\n");
3220 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_6ch_volume_init_verbs
;
3221 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
3223 spec
->stream_name_analog
= "VT1709 Analog";
3224 spec
->stream_analog_playback
= &vt1709_6ch_pcm_analog_playback
;
3225 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
3227 spec
->stream_name_digital
= "VT1709 Digital";
3228 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
3229 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
3232 if (!spec
->adc_nids
&& spec
->input_mux
) {
3233 spec
->adc_nids
= vt1709_adc_nids
;
3234 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
3235 get_mux_nids(codec
);
3236 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
3240 codec
->patch_ops
= via_patch_ops
;
3242 codec
->patch_ops
.init
= via_auto_init
;
3243 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3244 #ifdef CONFIG_SND_HDA_POWER_SAVE
3245 spec
->loopback
.amplist
= vt1709_loopbacks
;
3250 /* capture mixer elements */
3251 static struct snd_kcontrol_new vt1708B_capture_mixer
[] = {
3252 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
3253 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
3254 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
3255 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
3257 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3258 /* The multiple "Capture Source" controls confuse alsamixer
3259 * So call somewhat different..
3261 /* .name = "Capture Source", */
3262 .name
= "Input Source",
3264 .info
= via_mux_enum_info
,
3265 .get
= via_mux_enum_get
,
3266 .put
= via_mux_enum_put
,
3271 * generic initialization of ADC, input mixers and output mixers
3273 static struct hda_verb vt1708B_8ch_volume_init_verbs
[] = {
3275 * Unmute ADC0-1 and set the default input to mic-in
3277 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3278 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3281 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3284 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3285 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3286 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3287 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3288 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3289 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3292 * Set up output mixers
3294 /* set vol=0 to output mixers */
3295 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3296 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3297 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3299 /* Setup default input to PW4 */
3300 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0},
3301 /* PW9 Output enable */
3302 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3303 /* PW10 Input enable */
3304 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
3308 static struct hda_verb vt1708B_4ch_volume_init_verbs
[] = {
3310 * Unmute ADC0-1 and set the default input to mic-in
3312 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3313 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3316 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3319 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3320 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3321 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3322 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3323 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3324 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3327 * Set up output mixers
3329 /* set vol=0 to output mixers */
3330 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3331 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3332 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3334 /* Setup default input of PW4 to MW0 */
3335 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
3336 /* PW9 Output enable */
3337 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3338 /* PW10 Input enable */
3339 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
3343 static struct hda_verb vt1708B_uniwill_init_verbs
[] = {
3344 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
3345 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
3346 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3347 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3348 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3349 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3350 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3351 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3352 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3356 static int via_pcm_open_close(struct hda_pcm_stream
*hinfo
,
3357 struct hda_codec
*codec
,
3358 struct snd_pcm_substream
*substream
)
3360 int idle
= substream
->pstr
->substream_opened
== 1
3361 && substream
->ref_count
== 0;
3363 analog_low_current_mode(codec
, idle
);
3367 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback
= {
3371 .nid
= 0x10, /* NID to query formats and rates */
3373 .open
= via_playback_pcm_open
,
3374 .prepare
= via_playback_multi_pcm_prepare
,
3375 .cleanup
= via_playback_multi_pcm_cleanup
,
3376 .close
= via_pcm_open_close
3380 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback
= {
3384 .nid
= 0x10, /* NID to query formats and rates */
3386 .open
= via_playback_pcm_open
,
3387 .prepare
= via_playback_multi_pcm_prepare
,
3388 .cleanup
= via_playback_multi_pcm_cleanup
3392 static struct hda_pcm_stream vt1708B_pcm_analog_capture
= {
3396 .nid
= 0x13, /* NID to query formats and rates */
3398 .open
= via_pcm_open_close
,
3399 .prepare
= via_capture_pcm_prepare
,
3400 .cleanup
= via_capture_pcm_cleanup
,
3401 .close
= via_pcm_open_close
3405 static struct hda_pcm_stream vt1708B_pcm_digital_playback
= {
3409 /* NID is set in via_build_pcms */
3411 .open
= via_dig_playback_pcm_open
,
3412 .close
= via_dig_playback_pcm_close
,
3413 .prepare
= via_dig_playback_pcm_prepare
,
3414 .cleanup
= via_dig_playback_pcm_cleanup
3418 static struct hda_pcm_stream vt1708B_pcm_digital_capture
= {
3424 /* fill in the dac_nids table from the parsed pin configuration */
3425 static int vt1708B_auto_fill_dac_nids(struct via_spec
*spec
,
3426 const struct auto_pin_cfg
*cfg
)
3431 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3433 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3435 for (i
= 0; i
< 4; i
++) {
3436 nid
= cfg
->line_out_pins
[i
];
3438 /* config dac list */
3440 case AUTO_SEQ_FRONT
:
3441 spec
->multiout
.dac_nids
[i
] = 0x10;
3443 case AUTO_SEQ_CENLFE
:
3444 spec
->multiout
.dac_nids
[i
] = 0x24;
3446 case AUTO_SEQ_SURROUND
:
3447 spec
->multiout
.dac_nids
[i
] = 0x11;
3450 spec
->multiout
.dac_nids
[i
] = 0x25;
3459 /* add playback controls from the parsed DAC table */
3460 static int vt1708B_auto_create_multi_out_ctls(struct via_spec
*spec
,
3461 const struct auto_pin_cfg
*cfg
)
3464 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
3465 hda_nid_t nid_vols
[] = {0x16, 0x18, 0x26, 0x27};
3466 hda_nid_t nid
, nid_vol
= 0;
3469 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
3470 nid
= cfg
->line_out_pins
[i
];
3475 nid_vol
= nid_vols
[i
];
3477 if (i
== AUTO_SEQ_CENLFE
) {
3479 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3480 "Center Playback Volume",
3481 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3485 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3486 "LFE Playback Volume",
3487 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3491 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3492 "Center Playback Switch",
3493 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3497 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3498 "LFE Playback Switch",
3499 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3503 } else if (i
== AUTO_SEQ_FRONT
) {
3504 /* add control to mixer index 0 */
3505 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3506 "Master Front Playback Volume",
3507 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3511 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3512 "Master Front Playback Switch",
3513 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3518 /* add control to PW3 */
3519 sprintf(name
, "%s Playback Volume", chname
[i
]);
3520 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3521 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
3525 sprintf(name
, "%s Playback Switch", chname
[i
]);
3526 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3527 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
3532 sprintf(name
, "%s Playback Volume", chname
[i
]);
3533 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3534 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3538 sprintf(name
, "%s Playback Switch", chname
[i
]);
3539 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3540 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3550 static int vt1708B_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3557 spec
->multiout
.hp_nid
= VT1708B_HP_NID
; /* AOW3 */
3558 spec
->hp_independent_mode_index
= 1;
3560 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3561 "Headphone Playback Volume",
3562 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3565 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3566 "Headphone Playback Switch",
3567 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3571 create_hp_imux(spec
);
3576 /* create playback/capture controls for input pins */
3577 static int vt1708B_auto_create_analog_input_ctls(struct via_spec
*spec
,
3578 const struct auto_pin_cfg
*cfg
)
3580 static char *labels
[] = {
3581 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3583 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3584 int i
, err
, idx
= 0;
3586 /* for internal loopback recording select */
3587 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3588 imux
->items
[imux
->num_items
].index
= idx
;
3591 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3592 if (!cfg
->input_pins
[i
])
3595 switch (cfg
->input_pins
[i
]) {
3596 case 0x1a: /* Mic */
3600 case 0x1b: /* Line In */
3604 case 0x1e: /* Front Mic */
3612 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
3615 imux
->items
[imux
->num_items
].label
= labels
[i
];
3616 imux
->items
[imux
->num_items
].index
= idx
;
3622 static int vt1708B_parse_auto_config(struct hda_codec
*codec
)
3624 struct via_spec
*spec
= codec
->spec
;
3627 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3630 err
= vt1708B_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3633 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3634 return 0; /* can't find valid BIOS pin config */
3636 err
= vt1708B_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
3639 err
= vt1708B_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3642 err
= vt1708B_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3646 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3648 if (spec
->autocfg
.dig_outs
)
3649 spec
->multiout
.dig_out_nid
= VT1708B_DIGOUT_NID
;
3650 spec
->dig_in_pin
= VT1708B_DIGIN_PIN
;
3651 if (spec
->autocfg
.dig_in_pin
)
3652 spec
->dig_in_nid
= VT1708B_DIGIN_NID
;
3654 if (spec
->kctls
.list
)
3655 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3657 spec
->input_mux
= &spec
->private_imux
[0];
3662 via_smart51_build(spec
);
3666 #ifdef CONFIG_SND_HDA_POWER_SAVE
3667 static struct hda_amp_list vt1708B_loopbacks
[] = {
3668 { 0x16, HDA_INPUT
, 1 },
3669 { 0x16, HDA_INPUT
, 2 },
3670 { 0x16, HDA_INPUT
, 3 },
3671 { 0x16, HDA_INPUT
, 4 },
3675 static int patch_vt1708S(struct hda_codec
*codec
);
3676 static int patch_vt1708B_8ch(struct hda_codec
*codec
)
3678 struct via_spec
*spec
;
3681 if (get_codec_type(codec
) == VT1708BCE
)
3682 return patch_vt1708S(codec
);
3683 /* create a codec specific record */
3684 spec
= via_new_spec(codec
);
3688 /* automatic parse from the BIOS config */
3689 err
= vt1708B_parse_auto_config(codec
);
3694 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3695 "from BIOS. Using genenic mode...\n");
3698 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_8ch_volume_init_verbs
;
3699 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
3701 spec
->stream_name_analog
= "VT1708B Analog";
3702 spec
->stream_analog_playback
= &vt1708B_8ch_pcm_analog_playback
;
3703 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
3705 spec
->stream_name_digital
= "VT1708B Digital";
3706 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
3707 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
3709 if (!spec
->adc_nids
&& spec
->input_mux
) {
3710 spec
->adc_nids
= vt1708B_adc_nids
;
3711 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
3712 get_mux_nids(codec
);
3713 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
3717 codec
->patch_ops
= via_patch_ops
;
3719 codec
->patch_ops
.init
= via_auto_init
;
3720 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3721 #ifdef CONFIG_SND_HDA_POWER_SAVE
3722 spec
->loopback
.amplist
= vt1708B_loopbacks
;
3728 static int patch_vt1708B_4ch(struct hda_codec
*codec
)
3730 struct via_spec
*spec
;
3733 /* create a codec specific record */
3734 spec
= via_new_spec(codec
);
3738 /* automatic parse from the BIOS config */
3739 err
= vt1708B_parse_auto_config(codec
);
3744 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3745 "from BIOS. Using genenic mode...\n");
3748 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_4ch_volume_init_verbs
;
3749 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
3751 spec
->stream_name_analog
= "VT1708B Analog";
3752 spec
->stream_analog_playback
= &vt1708B_4ch_pcm_analog_playback
;
3753 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
3755 spec
->stream_name_digital
= "VT1708B Digital";
3756 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
3757 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
3759 if (!spec
->adc_nids
&& spec
->input_mux
) {
3760 spec
->adc_nids
= vt1708B_adc_nids
;
3761 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
3762 get_mux_nids(codec
);
3763 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
3767 codec
->patch_ops
= via_patch_ops
;
3769 codec
->patch_ops
.init
= via_auto_init
;
3770 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3771 #ifdef CONFIG_SND_HDA_POWER_SAVE
3772 spec
->loopback
.amplist
= vt1708B_loopbacks
;
3778 /* Patch for VT1708S */
3780 /* capture mixer elements */
3781 static struct snd_kcontrol_new vt1708S_capture_mixer
[] = {
3782 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
3783 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
3784 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
3785 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
3786 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT
),
3787 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3790 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3791 /* The multiple "Capture Source" controls confuse alsamixer
3792 * So call somewhat different..
3794 /* .name = "Capture Source", */
3795 .name
= "Input Source",
3797 .info
= via_mux_enum_info
,
3798 .get
= via_mux_enum_get
,
3799 .put
= via_mux_enum_put
,
3804 static struct hda_verb vt1708S_volume_init_verbs
[] = {
3805 /* Unmute ADC0-1 and set the default input to mic-in */
3806 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3807 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3809 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3810 * analog-loopback mixer widget */
3811 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3812 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3813 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3814 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3815 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3816 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3818 /* Setup default input of PW4 to MW0 */
3819 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
3820 /* PW9, PW10 Output enable */
3821 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3822 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3823 /* Enable Mic Boost Volume backdoor */
3825 /* don't bybass mixer */
3830 static struct hda_verb vt1708S_uniwill_init_verbs
[] = {
3831 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
3832 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
3833 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3834 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3835 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3836 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3837 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3838 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3839 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3843 static struct hda_pcm_stream vt1708S_pcm_analog_playback
= {
3847 .nid
= 0x10, /* NID to query formats and rates */
3849 .open
= via_playback_pcm_open
,
3850 .prepare
= via_playback_multi_pcm_prepare
,
3851 .cleanup
= via_playback_multi_pcm_cleanup
,
3852 .close
= via_pcm_open_close
3856 static struct hda_pcm_stream vt1708S_pcm_analog_capture
= {
3860 .nid
= 0x13, /* NID to query formats and rates */
3862 .open
= via_pcm_open_close
,
3863 .prepare
= via_capture_pcm_prepare
,
3864 .cleanup
= via_capture_pcm_cleanup
,
3865 .close
= via_pcm_open_close
3869 static struct hda_pcm_stream vt1708S_pcm_digital_playback
= {
3873 /* NID is set in via_build_pcms */
3875 .open
= via_dig_playback_pcm_open
,
3876 .close
= via_dig_playback_pcm_close
,
3877 .prepare
= via_dig_playback_pcm_prepare
,
3878 .cleanup
= via_dig_playback_pcm_cleanup
3882 /* fill in the dac_nids table from the parsed pin configuration */
3883 static int vt1708S_auto_fill_dac_nids(struct via_spec
*spec
,
3884 const struct auto_pin_cfg
*cfg
)
3889 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3891 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3893 for (i
= 0; i
< 4; i
++) {
3894 nid
= cfg
->line_out_pins
[i
];
3896 /* config dac list */
3898 case AUTO_SEQ_FRONT
:
3899 spec
->multiout
.dac_nids
[i
] = 0x10;
3901 case AUTO_SEQ_CENLFE
:
3902 spec
->multiout
.dac_nids
[i
] = 0x24;
3904 case AUTO_SEQ_SURROUND
:
3905 spec
->multiout
.dac_nids
[i
] = 0x11;
3908 spec
->multiout
.dac_nids
[i
] = 0x25;
3917 /* add playback controls from the parsed DAC table */
3918 static int vt1708S_auto_create_multi_out_ctls(struct via_spec
*spec
,
3919 const struct auto_pin_cfg
*cfg
)
3922 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
3923 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x24, 0x25};
3924 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x26, 0x27};
3925 hda_nid_t nid
, nid_vol
, nid_mute
;
3928 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
3929 nid
= cfg
->line_out_pins
[i
];
3934 nid_vol
= nid_vols
[i
];
3935 nid_mute
= nid_mutes
[i
];
3937 if (i
== AUTO_SEQ_CENLFE
) {
3939 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3940 "Center Playback Volume",
3941 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3945 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3946 "LFE Playback Volume",
3947 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3951 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3952 "Center Playback Switch",
3953 HDA_COMPOSE_AMP_VAL(nid_mute
,
3958 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3959 "LFE Playback Switch",
3960 HDA_COMPOSE_AMP_VAL(nid_mute
,
3965 } else if (i
== AUTO_SEQ_FRONT
) {
3966 /* add control to mixer index 0 */
3967 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3968 "Master Front Playback Volume",
3969 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3973 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3974 "Master Front Playback Switch",
3975 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3981 sprintf(name
, "%s Playback Volume", chname
[i
]);
3982 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3983 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3987 sprintf(name
, "%s Playback Switch", chname
[i
]);
3988 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3989 HDA_COMPOSE_AMP_VAL(nid_mute
,
3995 sprintf(name
, "%s Playback Volume", chname
[i
]);
3996 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3997 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
4001 sprintf(name
, "%s Playback Switch", chname
[i
]);
4002 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
4003 HDA_COMPOSE_AMP_VAL(nid_mute
,
4014 static int vt1708S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
4021 spec
->multiout
.hp_nid
= VT1708S_HP_NID
; /* AOW3 */
4022 spec
->hp_independent_mode_index
= 1;
4024 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4025 "Headphone Playback Volume",
4026 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
4030 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4031 "Headphone Playback Switch",
4032 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
4036 create_hp_imux(spec
);
4041 /* create playback/capture controls for input pins */
4042 static int vt1708S_auto_create_analog_input_ctls(struct via_spec
*spec
,
4043 const struct auto_pin_cfg
*cfg
)
4045 static char *labels
[] = {
4046 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4048 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
4049 int i
, err
, idx
= 0;
4051 /* for internal loopback recording select */
4052 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
4053 imux
->items
[imux
->num_items
].index
= 5;
4056 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
4057 if (!cfg
->input_pins
[i
])
4060 switch (cfg
->input_pins
[i
]) {
4061 case 0x1a: /* Mic */
4065 case 0x1b: /* Line In */
4069 case 0x1e: /* Front Mic */
4077 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
4080 imux
->items
[imux
->num_items
].label
= labels
[i
];
4081 imux
->items
[imux
->num_items
].index
= idx
-1;
4087 /* fill out digital output widgets; one for master and one for slave outputs */
4088 static void fill_dig_outs(struct hda_codec
*codec
)
4090 struct via_spec
*spec
= codec
->spec
;
4093 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
4097 nid
= spec
->autocfg
.dig_out_pins
[i
];
4100 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
4103 if (!spec
->multiout
.dig_out_nid
)
4104 spec
->multiout
.dig_out_nid
= nid
;
4106 spec
->slave_dig_outs
[0] = nid
;
4107 break; /* at most two dig outs */
4112 static int vt1708S_parse_auto_config(struct hda_codec
*codec
)
4114 struct via_spec
*spec
= codec
->spec
;
4117 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
4120 err
= vt1708S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
4123 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
4124 return 0; /* can't find valid BIOS pin config */
4126 err
= vt1708S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
4129 err
= vt1708S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
4132 err
= vt1708S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
4136 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4138 fill_dig_outs(codec
);
4140 if (spec
->kctls
.list
)
4141 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
4143 spec
->input_mux
= &spec
->private_imux
[0];
4148 via_smart51_build(spec
);
4152 #ifdef CONFIG_SND_HDA_POWER_SAVE
4153 static struct hda_amp_list vt1708S_loopbacks
[] = {
4154 { 0x16, HDA_INPUT
, 1 },
4155 { 0x16, HDA_INPUT
, 2 },
4156 { 0x16, HDA_INPUT
, 3 },
4157 { 0x16, HDA_INPUT
, 4 },
4162 static void override_mic_boost(struct hda_codec
*codec
, hda_nid_t pin
,
4163 int offset
, int num_steps
, int step_size
)
4165 snd_hda_override_amp_caps(codec
, pin
, HDA_INPUT
,
4166 (offset
<< AC_AMPCAP_OFFSET_SHIFT
) |
4167 (num_steps
<< AC_AMPCAP_NUM_STEPS_SHIFT
) |
4168 (step_size
<< AC_AMPCAP_STEP_SIZE_SHIFT
) |
4169 (0 << AC_AMPCAP_MUTE_SHIFT
));
4172 static int patch_vt1708S(struct hda_codec
*codec
)
4174 struct via_spec
*spec
;
4177 /* create a codec specific record */
4178 spec
= via_new_spec(codec
);
4182 /* automatic parse from the BIOS config */
4183 err
= vt1708S_parse_auto_config(codec
);
4188 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
4189 "from BIOS. Using genenic mode...\n");
4192 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_volume_init_verbs
;
4193 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_uniwill_init_verbs
;
4195 if (codec
->vendor_id
== 0x11060440)
4196 spec
->stream_name_analog
= "VT1818S Analog";
4198 spec
->stream_name_analog
= "VT1708S Analog";
4199 spec
->stream_analog_playback
= &vt1708S_pcm_analog_playback
;
4200 spec
->stream_analog_capture
= &vt1708S_pcm_analog_capture
;
4202 if (codec
->vendor_id
== 0x11060440)
4203 spec
->stream_name_digital
= "VT1818S Digital";
4205 spec
->stream_name_digital
= "VT1708S Digital";
4206 spec
->stream_digital_playback
= &vt1708S_pcm_digital_playback
;
4208 if (!spec
->adc_nids
&& spec
->input_mux
) {
4209 spec
->adc_nids
= vt1708S_adc_nids
;
4210 spec
->num_adc_nids
= ARRAY_SIZE(vt1708S_adc_nids
);
4211 get_mux_nids(codec
);
4212 override_mic_boost(codec
, 0x1a, 0, 3, 40);
4213 override_mic_boost(codec
, 0x1e, 0, 3, 40);
4214 spec
->mixers
[spec
->num_mixers
] = vt1708S_capture_mixer
;
4218 codec
->patch_ops
= via_patch_ops
;
4220 codec
->patch_ops
.init
= via_auto_init
;
4221 codec
->patch_ops
.unsol_event
= via_unsol_event
;
4222 #ifdef CONFIG_SND_HDA_POWER_SAVE
4223 spec
->loopback
.amplist
= vt1708S_loopbacks
;
4226 /* correct names for VT1708BCE */
4227 if (get_codec_type(codec
) == VT1708BCE
) {
4228 kfree(codec
->chip_name
);
4229 codec
->chip_name
= kstrdup("VT1708BCE", GFP_KERNEL
);
4230 snprintf(codec
->bus
->card
->mixername
,
4231 sizeof(codec
->bus
->card
->mixername
),
4232 "%s %s", codec
->vendor_name
, codec
->chip_name
);
4233 spec
->stream_name_analog
= "VT1708BCE Analog";
4234 spec
->stream_name_digital
= "VT1708BCE Digital";
4239 /* Patch for VT1702 */
4241 /* capture mixer elements */
4242 static struct snd_kcontrol_new vt1702_capture_mixer
[] = {
4243 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT
),
4244 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT
),
4245 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT
),
4246 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT
),
4247 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT
),
4248 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT
),
4249 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4252 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
4253 /* The multiple "Capture Source" controls confuse alsamixer
4254 * So call somewhat different..
4256 /* .name = "Capture Source", */
4257 .name
= "Input Source",
4259 .info
= via_mux_enum_info
,
4260 .get
= via_mux_enum_get
,
4261 .put
= via_mux_enum_put
,
4266 static struct hda_verb vt1702_volume_init_verbs
[] = {
4268 * Unmute ADC0-1 and set the default input to mic-in
4270 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4271 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4272 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4275 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4278 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4279 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4280 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
4281 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
4282 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
4283 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
4285 /* Setup default input of PW4 to MW0 */
4286 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x1},
4287 /* PW6 PW7 Output enable */
4288 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
4289 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
4297 static struct hda_verb vt1702_uniwill_init_verbs
[] = {
4298 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE
,
4299 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
4300 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4301 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4302 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4303 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4307 static struct hda_pcm_stream vt1702_pcm_analog_playback
= {
4311 .nid
= 0x10, /* NID to query formats and rates */
4313 .open
= via_playback_pcm_open
,
4314 .prepare
= via_playback_multi_pcm_prepare
,
4315 .cleanup
= via_playback_multi_pcm_cleanup
,
4316 .close
= via_pcm_open_close
4320 static struct hda_pcm_stream vt1702_pcm_analog_capture
= {
4324 .nid
= 0x12, /* NID to query formats and rates */
4326 .open
= via_pcm_open_close
,
4327 .prepare
= via_capture_pcm_prepare
,
4328 .cleanup
= via_capture_pcm_cleanup
,
4329 .close
= via_pcm_open_close
4333 static struct hda_pcm_stream vt1702_pcm_digital_playback
= {
4337 /* NID is set in via_build_pcms */
4339 .open
= via_dig_playback_pcm_open
,
4340 .close
= via_dig_playback_pcm_close
,
4341 .prepare
= via_dig_playback_pcm_prepare
,
4342 .cleanup
= via_dig_playback_pcm_cleanup
4346 /* fill in the dac_nids table from the parsed pin configuration */
4347 static int vt1702_auto_fill_dac_nids(struct via_spec
*spec
,
4348 const struct auto_pin_cfg
*cfg
)
4350 spec
->multiout
.num_dacs
= 1;
4351 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
4353 if (cfg
->line_out_pins
[0]) {
4354 /* config dac list */
4355 spec
->multiout
.dac_nids
[0] = 0x10;
4361 /* add playback controls from the parsed DAC table */
4362 static int vt1702_auto_create_line_out_ctls(struct via_spec
*spec
,
4363 const struct auto_pin_cfg
*cfg
)
4367 if (!cfg
->line_out_pins
[0])
4370 /* add control to mixer index 0 */
4371 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4372 "Master Front Playback Volume",
4373 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
4376 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4377 "Master Front Playback Switch",
4378 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
4383 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4384 "Front Playback Volume",
4385 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
));
4388 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4389 "Front Playback Switch",
4390 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT
));
4397 static int vt1702_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
4400 struct hda_input_mux
*imux
;
4401 static const char *texts
[] = { "ON", "OFF", NULL
};
4404 spec
->multiout
.hp_nid
= 0x1D;
4405 spec
->hp_independent_mode_index
= 0;
4407 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4408 "Headphone Playback Volume",
4409 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT
));
4413 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4414 "Headphone Playback Switch",
4415 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
4419 imux
= &spec
->private_imux
[1];
4421 /* for hp mode select */
4423 while (texts
[i
] != NULL
) {
4424 imux
->items
[imux
->num_items
].label
= texts
[i
];
4425 imux
->items
[imux
->num_items
].index
= i
;
4430 spec
->hp_mux
= &spec
->private_imux
[1];
4434 /* create playback/capture controls for input pins */
4435 static int vt1702_auto_create_analog_input_ctls(struct via_spec
*spec
,
4436 const struct auto_pin_cfg
*cfg
)
4438 static char *labels
[] = {
4439 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4441 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
4442 int i
, err
, idx
= 0;
4444 /* for internal loopback recording select */
4445 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
4446 imux
->items
[imux
->num_items
].index
= 3;
4449 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
4450 if (!cfg
->input_pins
[i
])
4453 switch (cfg
->input_pins
[i
]) {
4454 case 0x14: /* Mic */
4458 case 0x15: /* Line In */
4462 case 0x18: /* Front Mic */
4466 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x1A);
4469 imux
->items
[imux
->num_items
].label
= labels
[i
];
4470 imux
->items
[imux
->num_items
].index
= idx
-1;
4476 static int vt1702_parse_auto_config(struct hda_codec
*codec
)
4478 struct via_spec
*spec
= codec
->spec
;
4481 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
4484 err
= vt1702_auto_fill_dac_nids(spec
, &spec
->autocfg
);
4487 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
4488 return 0; /* can't find valid BIOS pin config */
4490 err
= vt1702_auto_create_line_out_ctls(spec
, &spec
->autocfg
);
4493 err
= vt1702_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
4496 /* limit AA path volume to 0 dB */
4497 snd_hda_override_amp_caps(codec
, 0x1A, HDA_INPUT
,
4498 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
4499 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
4500 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
4501 (1 << AC_AMPCAP_MUTE_SHIFT
));
4502 err
= vt1702_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
4506 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4508 fill_dig_outs(codec
);
4510 if (spec
->kctls
.list
)
4511 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
4513 spec
->input_mux
= &spec
->private_imux
[0];
4521 #ifdef CONFIG_SND_HDA_POWER_SAVE
4522 static struct hda_amp_list vt1702_loopbacks
[] = {
4523 { 0x1A, HDA_INPUT
, 1 },
4524 { 0x1A, HDA_INPUT
, 2 },
4525 { 0x1A, HDA_INPUT
, 3 },
4526 { 0x1A, HDA_INPUT
, 4 },
4531 static int patch_vt1702(struct hda_codec
*codec
)
4533 struct via_spec
*spec
;
4536 /* create a codec specific record */
4537 spec
= via_new_spec(codec
);
4541 /* automatic parse from the BIOS config */
4542 err
= vt1702_parse_auto_config(codec
);
4547 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
4548 "from BIOS. Using genenic mode...\n");
4551 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_volume_init_verbs
;
4552 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_uniwill_init_verbs
;
4554 spec
->stream_name_analog
= "VT1702 Analog";
4555 spec
->stream_analog_playback
= &vt1702_pcm_analog_playback
;
4556 spec
->stream_analog_capture
= &vt1702_pcm_analog_capture
;
4558 spec
->stream_name_digital
= "VT1702 Digital";
4559 spec
->stream_digital_playback
= &vt1702_pcm_digital_playback
;
4561 if (!spec
->adc_nids
&& spec
->input_mux
) {
4562 spec
->adc_nids
= vt1702_adc_nids
;
4563 spec
->num_adc_nids
= ARRAY_SIZE(vt1702_adc_nids
);
4564 get_mux_nids(codec
);
4565 spec
->mixers
[spec
->num_mixers
] = vt1702_capture_mixer
;
4569 codec
->patch_ops
= via_patch_ops
;
4571 codec
->patch_ops
.init
= via_auto_init
;
4572 codec
->patch_ops
.unsol_event
= via_unsol_event
;
4573 #ifdef CONFIG_SND_HDA_POWER_SAVE
4574 spec
->loopback
.amplist
= vt1702_loopbacks
;
4580 /* Patch for VT1718S */
4582 /* capture mixer elements */
4583 static struct snd_kcontrol_new vt1718S_capture_mixer
[] = {
4584 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT
),
4585 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT
),
4586 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT
),
4587 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT
),
4588 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT
),
4589 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4592 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
4593 /* The multiple "Capture Source" controls confuse alsamixer
4594 * So call somewhat different..
4596 .name
= "Input Source",
4598 .info
= via_mux_enum_info
,
4599 .get
= via_mux_enum_get
,
4600 .put
= via_mux_enum_put
,
4605 static struct hda_verb vt1718S_volume_init_verbs
[] = {
4607 * Unmute ADC0-1 and set the default input to mic-in
4609 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4610 {0x11, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4613 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4616 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4617 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
4618 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4619 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
4620 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
4621 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(5)},
4623 /* Setup default input of Front HP to MW9 */
4624 {0x28, AC_VERB_SET_CONNECT_SEL
, 0x1},
4625 /* PW9 PW10 Output enable */
4626 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_OUT_EN
},
4627 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_OUT_EN
},
4628 /* PW11 Input enable */
4629 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_IN_EN
},
4630 /* Enable Boost Volume backdoor */
4632 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4633 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4634 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4635 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4636 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4637 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4638 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
4639 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4640 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4641 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
4642 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4643 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4644 {0x34, AC_VERB_SET_CONNECT_SEL
, 0x2},
4645 {0x35, AC_VERB_SET_CONNECT_SEL
, 0x1},
4646 /* Unmute MW4's index 0 */
4647 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4652 static struct hda_verb vt1718S_uniwill_init_verbs
[] = {
4653 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE
,
4654 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
4655 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4656 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4657 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4658 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4659 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4660 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4661 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4665 static struct hda_pcm_stream vt1718S_pcm_analog_playback
= {
4669 .nid
= 0x8, /* NID to query formats and rates */
4671 .open
= via_playback_pcm_open
,
4672 .prepare
= via_playback_multi_pcm_prepare
,
4673 .cleanup
= via_playback_multi_pcm_cleanup
,
4674 .close
= via_pcm_open_close
,
4678 static struct hda_pcm_stream vt1718S_pcm_analog_capture
= {
4682 .nid
= 0x10, /* NID to query formats and rates */
4684 .open
= via_pcm_open_close
,
4685 .prepare
= via_capture_pcm_prepare
,
4686 .cleanup
= via_capture_pcm_cleanup
,
4687 .close
= via_pcm_open_close
,
4691 static struct hda_pcm_stream vt1718S_pcm_digital_playback
= {
4695 /* NID is set in via_build_pcms */
4697 .open
= via_dig_playback_pcm_open
,
4698 .close
= via_dig_playback_pcm_close
,
4699 .prepare
= via_dig_playback_pcm_prepare
,
4700 .cleanup
= via_dig_playback_pcm_cleanup
4704 static struct hda_pcm_stream vt1718S_pcm_digital_capture
= {
4710 /* fill in the dac_nids table from the parsed pin configuration */
4711 static int vt1718S_auto_fill_dac_nids(struct via_spec
*spec
,
4712 const struct auto_pin_cfg
*cfg
)
4717 spec
->multiout
.num_dacs
= cfg
->line_outs
;
4719 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
4721 for (i
= 0; i
< 4; i
++) {
4722 nid
= cfg
->line_out_pins
[i
];
4724 /* config dac list */
4726 case AUTO_SEQ_FRONT
:
4727 spec
->multiout
.dac_nids
[i
] = 0x8;
4729 case AUTO_SEQ_CENLFE
:
4730 spec
->multiout
.dac_nids
[i
] = 0xa;
4732 case AUTO_SEQ_SURROUND
:
4733 spec
->multiout
.dac_nids
[i
] = 0x9;
4736 spec
->multiout
.dac_nids
[i
] = 0xb;
4745 /* add playback controls from the parsed DAC table */
4746 static int vt1718S_auto_create_multi_out_ctls(struct via_spec
*spec
,
4747 const struct auto_pin_cfg
*cfg
)
4750 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
4751 hda_nid_t nid_vols
[] = {0x8, 0x9, 0xa, 0xb};
4752 hda_nid_t nid_mutes
[] = {0x24, 0x25, 0x26, 0x27};
4753 hda_nid_t nid
, nid_vol
, nid_mute
= 0;
4756 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
4757 nid
= cfg
->line_out_pins
[i
];
4761 nid_vol
= nid_vols
[i
];
4762 nid_mute
= nid_mutes
[i
];
4764 if (i
== AUTO_SEQ_CENLFE
) {
4766 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4767 "Center Playback Volume",
4768 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
4772 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4773 "LFE Playback Volume",
4774 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
4778 err
= via_add_control(
4779 spec
, VIA_CTL_WIDGET_MUTE
,
4780 "Center Playback Switch",
4781 HDA_COMPOSE_AMP_VAL(nid_mute
, 1, 0,
4785 err
= via_add_control(
4786 spec
, VIA_CTL_WIDGET_MUTE
,
4787 "LFE Playback Switch",
4788 HDA_COMPOSE_AMP_VAL(nid_mute
, 2, 0,
4792 } else if (i
== AUTO_SEQ_FRONT
) {
4794 sprintf(name
, "%s Playback Volume", chname
[i
]);
4795 err
= via_add_control(
4796 spec
, VIA_CTL_WIDGET_VOL
, name
,
4797 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0, HDA_OUTPUT
));
4800 sprintf(name
, "%s Playback Switch", chname
[i
]);
4801 err
= via_add_control(
4802 spec
, VIA_CTL_WIDGET_MUTE
, name
,
4803 HDA_COMPOSE_AMP_VAL(nid_mute
, 3, 0,
4808 sprintf(name
, "%s Playback Volume", chname
[i
]);
4809 err
= via_add_control(
4810 spec
, VIA_CTL_WIDGET_VOL
, name
,
4811 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0, HDA_OUTPUT
));
4814 sprintf(name
, "%s Playback Switch", chname
[i
]);
4815 err
= via_add_control(
4816 spec
, VIA_CTL_WIDGET_MUTE
, name
,
4817 HDA_COMPOSE_AMP_VAL(nid_mute
, 3, 0,
4826 static int vt1718S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
4833 spec
->multiout
.hp_nid
= 0xc; /* AOW4 */
4834 spec
->hp_independent_mode_index
= 1;
4836 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4837 "Headphone Playback Volume",
4838 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT
));
4842 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4843 "Headphone Playback Switch",
4844 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
4848 create_hp_imux(spec
);
4852 /* create playback/capture controls for input pins */
4853 static int vt1718S_auto_create_analog_input_ctls(struct via_spec
*spec
,
4854 const struct auto_pin_cfg
*cfg
)
4856 static char *labels
[] = {
4857 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4859 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
4860 int i
, err
, idx
= 0;
4862 /* for internal loopback recording select */
4863 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
4864 imux
->items
[imux
->num_items
].index
= 5;
4867 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
4868 if (!cfg
->input_pins
[i
])
4871 switch (cfg
->input_pins
[i
]) {
4872 case 0x2b: /* Mic */
4876 case 0x2a: /* Line In */
4880 case 0x29: /* Front Mic */
4888 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x21);
4891 imux
->items
[imux
->num_items
].label
= labels
[i
];
4892 imux
->items
[imux
->num_items
].index
= idx
;
4898 static int vt1718S_parse_auto_config(struct hda_codec
*codec
)
4900 struct via_spec
*spec
= codec
->spec
;
4903 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
4907 err
= vt1718S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
4910 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
4911 return 0; /* can't find valid BIOS pin config */
4913 err
= vt1718S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
4916 err
= vt1718S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
4919 err
= vt1718S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
4923 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4925 fill_dig_outs(codec
);
4927 if (spec
->autocfg
.dig_in_pin
&& codec
->vendor_id
== 0x11060428)
4928 spec
->dig_in_nid
= 0x13;
4930 if (spec
->kctls
.list
)
4931 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
4933 spec
->input_mux
= &spec
->private_imux
[0];
4938 via_smart51_build(spec
);
4943 #ifdef CONFIG_SND_HDA_POWER_SAVE
4944 static struct hda_amp_list vt1718S_loopbacks
[] = {
4945 { 0x21, HDA_INPUT
, 1 },
4946 { 0x21, HDA_INPUT
, 2 },
4947 { 0x21, HDA_INPUT
, 3 },
4948 { 0x21, HDA_INPUT
, 4 },
4953 static int patch_vt1718S(struct hda_codec
*codec
)
4955 struct via_spec
*spec
;
4958 /* create a codec specific record */
4959 spec
= via_new_spec(codec
);
4963 /* automatic parse from the BIOS config */
4964 err
= vt1718S_parse_auto_config(codec
);
4969 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
4970 "from BIOS. Using genenic mode...\n");
4973 spec
->init_verbs
[spec
->num_iverbs
++] = vt1718S_volume_init_verbs
;
4974 spec
->init_verbs
[spec
->num_iverbs
++] = vt1718S_uniwill_init_verbs
;
4976 if (codec
->vendor_id
== 0x11060441)
4977 spec
->stream_name_analog
= "VT2020 Analog";
4978 else if (codec
->vendor_id
== 0x11064441)
4979 spec
->stream_name_analog
= "VT1828S Analog";
4981 spec
->stream_name_analog
= "VT1718S Analog";
4982 spec
->stream_analog_playback
= &vt1718S_pcm_analog_playback
;
4983 spec
->stream_analog_capture
= &vt1718S_pcm_analog_capture
;
4985 if (codec
->vendor_id
== 0x11060441)
4986 spec
->stream_name_digital
= "VT2020 Digital";
4987 else if (codec
->vendor_id
== 0x11064441)
4988 spec
->stream_name_digital
= "VT1828S Digital";
4990 spec
->stream_name_digital
= "VT1718S Digital";
4991 spec
->stream_digital_playback
= &vt1718S_pcm_digital_playback
;
4992 if (codec
->vendor_id
== 0x11060428 || codec
->vendor_id
== 0x11060441)
4993 spec
->stream_digital_capture
= &vt1718S_pcm_digital_capture
;
4995 if (!spec
->adc_nids
&& spec
->input_mux
) {
4996 spec
->adc_nids
= vt1718S_adc_nids
;
4997 spec
->num_adc_nids
= ARRAY_SIZE(vt1718S_adc_nids
);
4998 get_mux_nids(codec
);
4999 override_mic_boost(codec
, 0x2b, 0, 3, 40);
5000 override_mic_boost(codec
, 0x29, 0, 3, 40);
5001 spec
->mixers
[spec
->num_mixers
] = vt1718S_capture_mixer
;
5005 codec
->patch_ops
= via_patch_ops
;
5007 codec
->patch_ops
.init
= via_auto_init
;
5008 codec
->patch_ops
.unsol_event
= via_unsol_event
;
5010 #ifdef CONFIG_SND_HDA_POWER_SAVE
5011 spec
->loopback
.amplist
= vt1718S_loopbacks
;
5017 /* Patch for VT1716S */
5019 static int vt1716s_dmic_info(struct snd_kcontrol
*kcontrol
,
5020 struct snd_ctl_elem_info
*uinfo
)
5022 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
5024 uinfo
->value
.integer
.min
= 0;
5025 uinfo
->value
.integer
.max
= 1;
5029 static int vt1716s_dmic_get(struct snd_kcontrol
*kcontrol
,
5030 struct snd_ctl_elem_value
*ucontrol
)
5032 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5035 index
= snd_hda_codec_read(codec
, 0x26, 0,
5036 AC_VERB_GET_CONNECT_SEL
, 0);
5038 *ucontrol
->value
.integer
.value
= index
;
5043 static int vt1716s_dmic_put(struct snd_kcontrol
*kcontrol
,
5044 struct snd_ctl_elem_value
*ucontrol
)
5046 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5047 struct via_spec
*spec
= codec
->spec
;
5048 int index
= *ucontrol
->value
.integer
.value
;
5050 snd_hda_codec_write(codec
, 0x26, 0,
5051 AC_VERB_SET_CONNECT_SEL
, index
);
5052 spec
->dmic_enabled
= index
;
5053 set_jack_power_state(codec
);
5058 /* capture mixer elements */
5059 static struct snd_kcontrol_new vt1716S_capture_mixer
[] = {
5060 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
5061 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
5062 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
5063 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
5064 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT
),
5065 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5068 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
5069 .name
= "Input Source",
5071 .info
= via_mux_enum_info
,
5072 .get
= via_mux_enum_get
,
5073 .put
= via_mux_enum_put
,
5078 static struct snd_kcontrol_new vt1716s_dmic_mixer
[] = {
5079 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT
),
5081 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
5082 .name
= "Digital Mic Capture Switch",
5083 .subdevice
= HDA_SUBDEV_NID_FLAG
| 0x26,
5085 .info
= vt1716s_dmic_info
,
5086 .get
= vt1716s_dmic_get
,
5087 .put
= vt1716s_dmic_put
,
5093 /* mono-out mixer elements */
5094 static struct snd_kcontrol_new vt1716S_mono_out_mixer
[] = {
5095 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT
),
5099 static struct hda_verb vt1716S_volume_init_verbs
[] = {
5101 * Unmute ADC0-1 and set the default input to mic-in
5103 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5104 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5107 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5110 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5111 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
5112 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5113 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
5114 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
5115 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
5117 /* MUX Indices: Stereo Mixer = 5 */
5118 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x5},
5120 /* Setup default input of PW4 to MW0 */
5121 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
5123 /* Setup default input of SW1 as MW0 */
5124 {0x18, AC_VERB_SET_CONNECT_SEL
, 0x1},
5126 /* Setup default input of SW4 as AOW0 */
5127 {0x28, AC_VERB_SET_CONNECT_SEL
, 0x1},
5129 /* PW9 PW10 Output enable */
5130 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
5131 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
5133 /* Unmute SW1, PW12 */
5134 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5135 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
5136 /* PW12 Output enable */
5137 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
5138 /* Enable Boost Volume backdoor */
5140 /* don't bybass mixer */
5142 /* Enable mono output */
5148 static struct hda_verb vt1716S_uniwill_init_verbs
[] = {
5149 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
5150 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
5151 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5152 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5153 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5154 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
,
5155 AC_USRSP_EN
| VIA_MONO_EVENT
| VIA_JACK_EVENT
},
5156 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5157 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5161 static struct hda_pcm_stream vt1716S_pcm_analog_playback
= {
5165 .nid
= 0x10, /* NID to query formats and rates */
5167 .open
= via_playback_pcm_open
,
5168 .prepare
= via_playback_multi_pcm_prepare
,
5169 .cleanup
= via_playback_multi_pcm_cleanup
,
5170 .close
= via_pcm_open_close
,
5174 static struct hda_pcm_stream vt1716S_pcm_analog_capture
= {
5178 .nid
= 0x13, /* NID to query formats and rates */
5180 .open
= via_pcm_open_close
,
5181 .prepare
= via_capture_pcm_prepare
,
5182 .cleanup
= via_capture_pcm_cleanup
,
5183 .close
= via_pcm_open_close
,
5187 static struct hda_pcm_stream vt1716S_pcm_digital_playback
= {
5191 /* NID is set in via_build_pcms */
5193 .open
= via_dig_playback_pcm_open
,
5194 .close
= via_dig_playback_pcm_close
,
5195 .prepare
= via_dig_playback_pcm_prepare
,
5196 .cleanup
= via_dig_playback_pcm_cleanup
5200 /* fill in the dac_nids table from the parsed pin configuration */
5201 static int vt1716S_auto_fill_dac_nids(struct via_spec
*spec
,
5202 const struct auto_pin_cfg
*cfg
)
5206 spec
->multiout
.num_dacs
= cfg
->line_outs
;
5208 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
5210 for (i
= 0; i
< 3; i
++) {
5211 nid
= cfg
->line_out_pins
[i
];
5213 /* config dac list */
5215 case AUTO_SEQ_FRONT
:
5216 spec
->multiout
.dac_nids
[i
] = 0x10;
5218 case AUTO_SEQ_CENLFE
:
5219 spec
->multiout
.dac_nids
[i
] = 0x25;
5221 case AUTO_SEQ_SURROUND
:
5222 spec
->multiout
.dac_nids
[i
] = 0x11;
5231 /* add playback controls from the parsed DAC table */
5232 static int vt1716S_auto_create_multi_out_ctls(struct via_spec
*spec
,
5233 const struct auto_pin_cfg
*cfg
)
5236 static const char *chname
[3] = { "Front", "Surround", "C/LFE" };
5237 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x25};
5238 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x27};
5239 hda_nid_t nid
, nid_vol
, nid_mute
;
5242 for (i
= 0; i
<= AUTO_SEQ_CENLFE
; i
++) {
5243 nid
= cfg
->line_out_pins
[i
];
5248 nid_vol
= nid_vols
[i
];
5249 nid_mute
= nid_mutes
[i
];
5251 if (i
== AUTO_SEQ_CENLFE
) {
5252 err
= via_add_control(
5253 spec
, VIA_CTL_WIDGET_VOL
,
5254 "Center Playback Volume",
5255 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0, HDA_OUTPUT
));
5258 err
= via_add_control(
5259 spec
, VIA_CTL_WIDGET_VOL
,
5260 "LFE Playback Volume",
5261 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0, HDA_OUTPUT
));
5264 err
= via_add_control(
5265 spec
, VIA_CTL_WIDGET_MUTE
,
5266 "Center Playback Switch",
5267 HDA_COMPOSE_AMP_VAL(nid_mute
, 1, 0,
5271 err
= via_add_control(
5272 spec
, VIA_CTL_WIDGET_MUTE
,
5273 "LFE Playback Switch",
5274 HDA_COMPOSE_AMP_VAL(nid_mute
, 2, 0,
5278 } else if (i
== AUTO_SEQ_FRONT
) {
5280 err
= via_add_control(
5281 spec
, VIA_CTL_WIDGET_VOL
,
5282 "Master Front Playback Volume",
5283 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT
));
5286 err
= via_add_control(
5287 spec
, VIA_CTL_WIDGET_MUTE
,
5288 "Master Front Playback Switch",
5289 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT
));
5293 sprintf(name
, "%s Playback Volume", chname
[i
]);
5294 err
= via_add_control(
5295 spec
, VIA_CTL_WIDGET_VOL
, name
,
5296 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0, HDA_OUTPUT
));
5299 sprintf(name
, "%s Playback Switch", chname
[i
]);
5300 err
= via_add_control(
5301 spec
, VIA_CTL_WIDGET_MUTE
, name
,
5302 HDA_COMPOSE_AMP_VAL(nid_mute
, 3, 0,
5307 sprintf(name
, "%s Playback Volume", chname
[i
]);
5308 err
= via_add_control(
5309 spec
, VIA_CTL_WIDGET_VOL
, name
,
5310 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0, HDA_OUTPUT
));
5313 sprintf(name
, "%s Playback Switch", chname
[i
]);
5314 err
= via_add_control(
5315 spec
, VIA_CTL_WIDGET_MUTE
, name
,
5316 HDA_COMPOSE_AMP_VAL(nid_mute
, 3, 0,
5325 static int vt1716S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
5332 spec
->multiout
.hp_nid
= 0x25; /* AOW3 */
5333 spec
->hp_independent_mode_index
= 1;
5335 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
5336 "Headphone Playback Volume",
5337 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
5341 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
5342 "Headphone Playback Switch",
5343 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
5347 create_hp_imux(spec
);
5351 /* create playback/capture controls for input pins */
5352 static int vt1716S_auto_create_analog_input_ctls(struct via_spec
*spec
,
5353 const struct auto_pin_cfg
*cfg
)
5355 static char *labels
[] = {
5356 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5358 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
5359 int i
, err
, idx
= 0;
5361 /* for internal loopback recording select */
5362 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
5363 imux
->items
[imux
->num_items
].index
= 5;
5366 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
5367 if (!cfg
->input_pins
[i
])
5370 switch (cfg
->input_pins
[i
]) {
5371 case 0x1a: /* Mic */
5375 case 0x1b: /* Line In */
5379 case 0x1e: /* Front Mic */
5387 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
5390 imux
->items
[imux
->num_items
].label
= labels
[i
];
5391 imux
->items
[imux
->num_items
].index
= idx
-1;
5397 static int vt1716S_parse_auto_config(struct hda_codec
*codec
)
5399 struct via_spec
*spec
= codec
->spec
;
5402 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
5405 err
= vt1716S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
5408 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
5409 return 0; /* can't find valid BIOS pin config */
5411 err
= vt1716S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
5414 err
= vt1716S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
5417 err
= vt1716S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
5421 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
5423 fill_dig_outs(codec
);
5425 if (spec
->kctls
.list
)
5426 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
5428 spec
->input_mux
= &spec
->private_imux
[0];
5433 via_smart51_build(spec
);
5438 #ifdef CONFIG_SND_HDA_POWER_SAVE
5439 static struct hda_amp_list vt1716S_loopbacks
[] = {
5440 { 0x16, HDA_INPUT
, 1 },
5441 { 0x16, HDA_INPUT
, 2 },
5442 { 0x16, HDA_INPUT
, 3 },
5443 { 0x16, HDA_INPUT
, 4 },
5448 static int patch_vt1716S(struct hda_codec
*codec
)
5450 struct via_spec
*spec
;
5453 /* create a codec specific record */
5454 spec
= via_new_spec(codec
);
5458 /* automatic parse from the BIOS config */
5459 err
= vt1716S_parse_auto_config(codec
);
5464 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
5465 "from BIOS. Using genenic mode...\n");
5468 spec
->init_verbs
[spec
->num_iverbs
++] = vt1716S_volume_init_verbs
;
5469 spec
->init_verbs
[spec
->num_iverbs
++] = vt1716S_uniwill_init_verbs
;
5471 spec
->stream_name_analog
= "VT1716S Analog";
5472 spec
->stream_analog_playback
= &vt1716S_pcm_analog_playback
;
5473 spec
->stream_analog_capture
= &vt1716S_pcm_analog_capture
;
5475 spec
->stream_name_digital
= "VT1716S Digital";
5476 spec
->stream_digital_playback
= &vt1716S_pcm_digital_playback
;
5478 if (!spec
->adc_nids
&& spec
->input_mux
) {
5479 spec
->adc_nids
= vt1716S_adc_nids
;
5480 spec
->num_adc_nids
= ARRAY_SIZE(vt1716S_adc_nids
);
5481 get_mux_nids(codec
);
5482 override_mic_boost(codec
, 0x1a, 0, 3, 40);
5483 override_mic_boost(codec
, 0x1e, 0, 3, 40);
5484 spec
->mixers
[spec
->num_mixers
] = vt1716S_capture_mixer
;
5488 spec
->mixers
[spec
->num_mixers
] = vt1716s_dmic_mixer
;
5491 spec
->mixers
[spec
->num_mixers
++] = vt1716S_mono_out_mixer
;
5493 codec
->patch_ops
= via_patch_ops
;
5495 codec
->patch_ops
.init
= via_auto_init
;
5496 codec
->patch_ops
.unsol_event
= via_unsol_event
;
5498 #ifdef CONFIG_SND_HDA_POWER_SAVE
5499 spec
->loopback
.amplist
= vt1716S_loopbacks
;
5507 /* capture mixer elements */
5508 static struct snd_kcontrol_new vt2002P_capture_mixer
[] = {
5509 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT
),
5510 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT
),
5511 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT
),
5512 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT
),
5513 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT
),
5514 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5517 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
5518 /* The multiple "Capture Source" controls confuse alsamixer
5519 * So call somewhat different..
5521 /* .name = "Capture Source", */
5522 .name
= "Input Source",
5524 .info
= via_mux_enum_info
,
5525 .get
= via_mux_enum_get
,
5526 .put
= via_mux_enum_put
,
5531 static struct hda_verb vt2002P_volume_init_verbs
[] = {
5533 * Unmute ADC0-1 and set the default input to mic-in
5535 {0x8, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5536 {0x9, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5539 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5542 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5543 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
5544 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5545 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
5546 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
5547 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
5549 /* MUX Indices: Mic = 0 */
5550 {0x1e, AC_VERB_SET_CONNECT_SEL
, 0},
5551 {0x1f, AC_VERB_SET_CONNECT_SEL
, 0},
5553 /* PW9 Output enable */
5554 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_OUT_EN
},
5556 /* Enable Boost Volume backdoor */
5559 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5560 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5561 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5562 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5563 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5564 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5565 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5566 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5567 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5569 /* set MUX0/1/4/8 = 0 (AOW0) */
5570 {0x34, AC_VERB_SET_CONNECT_SEL
, 0},
5571 {0x35, AC_VERB_SET_CONNECT_SEL
, 0},
5572 {0x37, AC_VERB_SET_CONNECT_SEL
, 0},
5573 {0x3b, AC_VERB_SET_CONNECT_SEL
, 0},
5575 /* set PW0 index=0 (MW0) */
5576 {0x24, AC_VERB_SET_CONNECT_SEL
, 0},
5578 /* Enable AOW0 to MW9 */
5584 static struct hda_verb vt2002P_uniwill_init_verbs
[] = {
5585 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE
,
5586 AC_USRSP_EN
| VIA_JACK_EVENT
| VIA_BIND_HP_EVENT
},
5587 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE
,
5588 AC_USRSP_EN
| VIA_JACK_EVENT
| VIA_BIND_HP_EVENT
},
5589 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5590 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5591 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5595 static struct hda_pcm_stream vt2002P_pcm_analog_playback
= {
5599 .nid
= 0x8, /* NID to query formats and rates */
5601 .open
= via_playback_pcm_open
,
5602 .prepare
= via_playback_multi_pcm_prepare
,
5603 .cleanup
= via_playback_multi_pcm_cleanup
,
5604 .close
= via_pcm_open_close
,
5608 static struct hda_pcm_stream vt2002P_pcm_analog_capture
= {
5612 .nid
= 0x10, /* NID to query formats and rates */
5614 .open
= via_pcm_open_close
,
5615 .prepare
= via_capture_pcm_prepare
,
5616 .cleanup
= via_capture_pcm_cleanup
,
5617 .close
= via_pcm_open_close
,
5621 static struct hda_pcm_stream vt2002P_pcm_digital_playback
= {
5625 /* NID is set in via_build_pcms */
5627 .open
= via_dig_playback_pcm_open
,
5628 .close
= via_dig_playback_pcm_close
,
5629 .prepare
= via_dig_playback_pcm_prepare
,
5630 .cleanup
= via_dig_playback_pcm_cleanup
5634 /* fill in the dac_nids table from the parsed pin configuration */
5635 static int vt2002P_auto_fill_dac_nids(struct via_spec
*spec
,
5636 const struct auto_pin_cfg
*cfg
)
5638 spec
->multiout
.num_dacs
= 1;
5639 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
5640 if (cfg
->line_out_pins
[0])
5641 spec
->multiout
.dac_nids
[0] = 0x8;
5645 /* add playback controls from the parsed DAC table */
5646 static int vt2002P_auto_create_multi_out_ctls(struct via_spec
*spec
,
5647 const struct auto_pin_cfg
*cfg
)
5651 if (!cfg
->line_out_pins
[0])
5655 /* Line-Out: PortE */
5656 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
5657 "Master Front Playback Volume",
5658 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT
));
5661 err
= via_add_control(spec
, VIA_CTL_WIDGET_BIND_PIN_MUTE
,
5662 "Master Front Playback Switch",
5663 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT
));
5670 static int vt2002P_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
5677 spec
->multiout
.hp_nid
= 0x9;
5678 spec
->hp_independent_mode_index
= 1;
5680 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
5681 "Headphone Playback Volume",
5682 HDA_COMPOSE_AMP_VAL(
5683 spec
->multiout
.hp_nid
, 3, 0, HDA_OUTPUT
));
5687 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
5688 "Headphone Playback Switch",
5689 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
5693 create_hp_imux(spec
);
5697 /* create playback/capture controls for input pins */
5698 static int vt2002P_auto_create_analog_input_ctls(struct via_spec
*spec
,
5699 const struct auto_pin_cfg
*cfg
)
5701 static char *labels
[] = {
5702 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5704 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
5705 int i
, err
, idx
= 0;
5707 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
5708 if (!cfg
->input_pins
[i
])
5711 switch (cfg
->input_pins
[i
]) {
5712 case 0x2b: /* Mic */
5716 case 0x2a: /* Line In */
5720 case 0x29: /* Front Mic */
5724 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x21);
5727 imux
->items
[imux
->num_items
].label
= labels
[i
];
5728 imux
->items
[imux
->num_items
].index
= idx
;
5732 /* build volume/mute control of loopback */
5733 err
= via_new_analog_input(spec
, "Stereo Mixer", 3, 0x21);
5737 /* for internal loopback recording select */
5738 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
5739 imux
->items
[imux
->num_items
].index
= 3;
5742 /* for digital mic select */
5743 imux
->items
[imux
->num_items
].label
= "Digital Mic";
5744 imux
->items
[imux
->num_items
].index
= 4;
5750 static int vt2002P_parse_auto_config(struct hda_codec
*codec
)
5752 struct via_spec
*spec
= codec
->spec
;
5756 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
5760 err
= vt2002P_auto_fill_dac_nids(spec
, &spec
->autocfg
);
5764 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
5765 return 0; /* can't find valid BIOS pin config */
5767 err
= vt2002P_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
5770 err
= vt2002P_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
5773 err
= vt2002P_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
5777 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
5779 fill_dig_outs(codec
);
5781 if (spec
->kctls
.list
)
5782 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
5784 spec
->input_mux
= &spec
->private_imux
[0];
5792 #ifdef CONFIG_SND_HDA_POWER_SAVE
5793 static struct hda_amp_list vt2002P_loopbacks
[] = {
5794 { 0x21, HDA_INPUT
, 0 },
5795 { 0x21, HDA_INPUT
, 1 },
5796 { 0x21, HDA_INPUT
, 2 },
5802 /* patch for vt2002P */
5803 static int patch_vt2002P(struct hda_codec
*codec
)
5805 struct via_spec
*spec
;
5808 /* create a codec specific record */
5809 spec
= via_new_spec(codec
);
5813 /* automatic parse from the BIOS config */
5814 err
= vt2002P_parse_auto_config(codec
);
5819 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
5820 "from BIOS. Using genenic mode...\n");
5823 spec
->init_verbs
[spec
->num_iverbs
++] = vt2002P_volume_init_verbs
;
5824 spec
->init_verbs
[spec
->num_iverbs
++] = vt2002P_uniwill_init_verbs
;
5826 spec
->stream_name_analog
= "VT2002P Analog";
5827 spec
->stream_analog_playback
= &vt2002P_pcm_analog_playback
;
5828 spec
->stream_analog_capture
= &vt2002P_pcm_analog_capture
;
5830 spec
->stream_name_digital
= "VT2002P Digital";
5831 spec
->stream_digital_playback
= &vt2002P_pcm_digital_playback
;
5833 if (!spec
->adc_nids
&& spec
->input_mux
) {
5834 spec
->adc_nids
= vt2002P_adc_nids
;
5835 spec
->num_adc_nids
= ARRAY_SIZE(vt2002P_adc_nids
);
5836 get_mux_nids(codec
);
5837 override_mic_boost(codec
, 0x2b, 0, 3, 40);
5838 override_mic_boost(codec
, 0x29, 0, 3, 40);
5839 spec
->mixers
[spec
->num_mixers
] = vt2002P_capture_mixer
;
5843 codec
->patch_ops
= via_patch_ops
;
5845 codec
->patch_ops
.init
= via_auto_init
;
5846 codec
->patch_ops
.unsol_event
= via_unsol_event
;
5848 #ifdef CONFIG_SND_HDA_POWER_SAVE
5849 spec
->loopback
.amplist
= vt2002P_loopbacks
;
5857 /* capture mixer elements */
5858 static struct snd_kcontrol_new vt1812_capture_mixer
[] = {
5859 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT
),
5860 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT
),
5861 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT
),
5862 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT
),
5863 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT
),
5864 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5867 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
5868 /* The multiple "Capture Source" controls confuse alsamixer
5869 * So call somewhat different..
5871 .name
= "Input Source",
5873 .info
= via_mux_enum_info
,
5874 .get
= via_mux_enum_get
,
5875 .put
= via_mux_enum_put
,
5880 static struct hda_verb vt1812_volume_init_verbs
[] = {
5882 * Unmute ADC0-1 and set the default input to mic-in
5884 {0x8, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5885 {0x9, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5888 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5891 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5892 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
5893 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5894 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
5895 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
5896 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
5898 /* MUX Indices: Mic = 0 */
5899 {0x1e, AC_VERB_SET_CONNECT_SEL
, 0},
5900 {0x1f, AC_VERB_SET_CONNECT_SEL
, 0},
5902 /* PW9 Output enable */
5903 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_OUT_EN
},
5905 /* Enable Boost Volume backdoor */
5908 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5909 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5910 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5911 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5912 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5913 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5914 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5915 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5916 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5917 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5918 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5920 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5921 {0x34, AC_VERB_SET_CONNECT_SEL
, 0},
5922 {0x35, AC_VERB_SET_CONNECT_SEL
, 0},
5923 {0x38, AC_VERB_SET_CONNECT_SEL
, 0},
5924 {0x3c, AC_VERB_SET_CONNECT_SEL
, 0},
5925 {0x3d, AC_VERB_SET_CONNECT_SEL
, 0},
5927 /* Enable AOW0 to MW9 */
5933 static struct hda_verb vt1812_uniwill_init_verbs
[] = {
5934 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE
,
5935 AC_USRSP_EN
| VIA_JACK_EVENT
| VIA_BIND_HP_EVENT
},
5936 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5937 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE
,
5938 AC_USRSP_EN
| VIA_JACK_EVENT
| VIA_BIND_HP_EVENT
},
5939 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5940 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5941 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5945 static struct hda_pcm_stream vt1812_pcm_analog_playback
= {
5949 .nid
= 0x8, /* NID to query formats and rates */
5951 .open
= via_playback_pcm_open
,
5952 .prepare
= via_playback_multi_pcm_prepare
,
5953 .cleanup
= via_playback_multi_pcm_cleanup
,
5954 .close
= via_pcm_open_close
,
5958 static struct hda_pcm_stream vt1812_pcm_analog_capture
= {
5962 .nid
= 0x10, /* NID to query formats and rates */
5964 .open
= via_pcm_open_close
,
5965 .prepare
= via_capture_pcm_prepare
,
5966 .cleanup
= via_capture_pcm_cleanup
,
5967 .close
= via_pcm_open_close
,
5971 static struct hda_pcm_stream vt1812_pcm_digital_playback
= {
5975 /* NID is set in via_build_pcms */
5977 .open
= via_dig_playback_pcm_open
,
5978 .close
= via_dig_playback_pcm_close
,
5979 .prepare
= via_dig_playback_pcm_prepare
,
5980 .cleanup
= via_dig_playback_pcm_cleanup
5983 /* fill in the dac_nids table from the parsed pin configuration */
5984 static int vt1812_auto_fill_dac_nids(struct via_spec
*spec
,
5985 const struct auto_pin_cfg
*cfg
)
5987 spec
->multiout
.num_dacs
= 1;
5988 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
5989 if (cfg
->line_out_pins
[0])
5990 spec
->multiout
.dac_nids
[0] = 0x8;
5995 /* add playback controls from the parsed DAC table */
5996 static int vt1812_auto_create_multi_out_ctls(struct via_spec
*spec
,
5997 const struct auto_pin_cfg
*cfg
)
6001 if (!cfg
->line_out_pins
[0])
6004 /* Line-Out: PortE */
6005 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
6006 "Master Front Playback Volume",
6007 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT
));
6010 err
= via_add_control(spec
, VIA_CTL_WIDGET_BIND_PIN_MUTE
,
6011 "Master Front Playback Switch",
6012 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT
));
6019 static int vt1812_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
6026 spec
->multiout
.hp_nid
= 0x9;
6027 spec
->hp_independent_mode_index
= 1;
6030 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
6031 "Headphone Playback Volume",
6032 HDA_COMPOSE_AMP_VAL(
6033 spec
->multiout
.hp_nid
, 3, 0, HDA_OUTPUT
));
6037 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
6038 "Headphone Playback Switch",
6039 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
6043 create_hp_imux(spec
);
6047 /* create playback/capture controls for input pins */
6048 static int vt1812_auto_create_analog_input_ctls(struct via_spec
*spec
,
6049 const struct auto_pin_cfg
*cfg
)
6051 static char *labels
[] = {
6052 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
6054 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
6055 int i
, err
, idx
= 0;
6057 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
6058 if (!cfg
->input_pins
[i
])
6061 switch (cfg
->input_pins
[i
]) {
6062 case 0x2b: /* Mic */
6066 case 0x2a: /* Line In */
6070 case 0x29: /* Front Mic */
6074 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x21);
6077 imux
->items
[imux
->num_items
].label
= labels
[i
];
6078 imux
->items
[imux
->num_items
].index
= idx
;
6081 /* build volume/mute control of loopback */
6082 err
= via_new_analog_input(spec
, "Stereo Mixer", 5, 0x21);
6086 /* for internal loopback recording select */
6087 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
6088 imux
->items
[imux
->num_items
].index
= 5;
6091 /* for digital mic select */
6092 imux
->items
[imux
->num_items
].label
= "Digital Mic";
6093 imux
->items
[imux
->num_items
].index
= 6;
6099 static int vt1812_parse_auto_config(struct hda_codec
*codec
)
6101 struct via_spec
*spec
= codec
->spec
;
6105 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
6108 fill_dig_outs(codec
);
6109 err
= vt1812_auto_fill_dac_nids(spec
, &spec
->autocfg
);
6113 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_outs
)
6114 return 0; /* can't find valid BIOS pin config */
6116 err
= vt1812_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
6119 err
= vt1812_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
6122 err
= vt1812_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
6126 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
6128 fill_dig_outs(codec
);
6130 if (spec
->kctls
.list
)
6131 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
6133 spec
->input_mux
= &spec
->private_imux
[0];
6141 #ifdef CONFIG_SND_HDA_POWER_SAVE
6142 static struct hda_amp_list vt1812_loopbacks
[] = {
6143 { 0x21, HDA_INPUT
, 0 },
6144 { 0x21, HDA_INPUT
, 1 },
6145 { 0x21, HDA_INPUT
, 2 },
6151 /* patch for vt1812 */
6152 static int patch_vt1812(struct hda_codec
*codec
)
6154 struct via_spec
*spec
;
6157 /* create a codec specific record */
6158 spec
= via_new_spec(codec
);
6162 /* automatic parse from the BIOS config */
6163 err
= vt1812_parse_auto_config(codec
);
6168 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
6169 "from BIOS. Using genenic mode...\n");
6173 spec
->init_verbs
[spec
->num_iverbs
++] = vt1812_volume_init_verbs
;
6174 spec
->init_verbs
[spec
->num_iverbs
++] = vt1812_uniwill_init_verbs
;
6176 spec
->stream_name_analog
= "VT1812 Analog";
6177 spec
->stream_analog_playback
= &vt1812_pcm_analog_playback
;
6178 spec
->stream_analog_capture
= &vt1812_pcm_analog_capture
;
6180 spec
->stream_name_digital
= "VT1812 Digital";
6181 spec
->stream_digital_playback
= &vt1812_pcm_digital_playback
;
6184 if (!spec
->adc_nids
&& spec
->input_mux
) {
6185 spec
->adc_nids
= vt1812_adc_nids
;
6186 spec
->num_adc_nids
= ARRAY_SIZE(vt1812_adc_nids
);
6187 get_mux_nids(codec
);
6188 override_mic_boost(codec
, 0x2b, 0, 3, 40);
6189 override_mic_boost(codec
, 0x29, 0, 3, 40);
6190 spec
->mixers
[spec
->num_mixers
] = vt1812_capture_mixer
;
6194 codec
->patch_ops
= via_patch_ops
;
6196 codec
->patch_ops
.init
= via_auto_init
;
6197 codec
->patch_ops
.unsol_event
= via_unsol_event
;
6199 #ifdef CONFIG_SND_HDA_POWER_SAVE
6200 spec
->loopback
.amplist
= vt1812_loopbacks
;
6209 static struct hda_codec_preset snd_hda_preset_via
[] = {
6210 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
6211 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
6212 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
6213 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
6214 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
6215 .patch
= patch_vt1709_10ch
},
6216 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
6217 .patch
= patch_vt1709_10ch
},
6218 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
6219 .patch
= patch_vt1709_10ch
},
6220 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
6221 .patch
= patch_vt1709_10ch
},
6222 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
6223 .patch
= patch_vt1709_6ch
},
6224 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
6225 .patch
= patch_vt1709_6ch
},
6226 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
6227 .patch
= patch_vt1709_6ch
},
6228 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
6229 .patch
= patch_vt1709_6ch
},
6230 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
6231 .patch
= patch_vt1708B_8ch
},
6232 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
6233 .patch
= patch_vt1708B_8ch
},
6234 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
6235 .patch
= patch_vt1708B_8ch
},
6236 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
6237 .patch
= patch_vt1708B_8ch
},
6238 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
6239 .patch
= patch_vt1708B_4ch
},
6240 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
6241 .patch
= patch_vt1708B_4ch
},
6242 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
6243 .patch
= patch_vt1708B_4ch
},
6244 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
6245 .patch
= patch_vt1708B_4ch
},
6246 { .id
= 0x11060397, .name
= "VT1708S",
6247 .patch
= patch_vt1708S
},
6248 { .id
= 0x11061397, .name
= "VT1708S",
6249 .patch
= patch_vt1708S
},
6250 { .id
= 0x11062397, .name
= "VT1708S",
6251 .patch
= patch_vt1708S
},
6252 { .id
= 0x11063397, .name
= "VT1708S",
6253 .patch
= patch_vt1708S
},
6254 { .id
= 0x11064397, .name
= "VT1708S",
6255 .patch
= patch_vt1708S
},
6256 { .id
= 0x11065397, .name
= "VT1708S",
6257 .patch
= patch_vt1708S
},
6258 { .id
= 0x11066397, .name
= "VT1708S",
6259 .patch
= patch_vt1708S
},
6260 { .id
= 0x11067397, .name
= "VT1708S",
6261 .patch
= patch_vt1708S
},
6262 { .id
= 0x11060398, .name
= "VT1702",
6263 .patch
= patch_vt1702
},
6264 { .id
= 0x11061398, .name
= "VT1702",
6265 .patch
= patch_vt1702
},
6266 { .id
= 0x11062398, .name
= "VT1702",
6267 .patch
= patch_vt1702
},
6268 { .id
= 0x11063398, .name
= "VT1702",
6269 .patch
= patch_vt1702
},
6270 { .id
= 0x11064398, .name
= "VT1702",
6271 .patch
= patch_vt1702
},
6272 { .id
= 0x11065398, .name
= "VT1702",
6273 .patch
= patch_vt1702
},
6274 { .id
= 0x11066398, .name
= "VT1702",
6275 .patch
= patch_vt1702
},
6276 { .id
= 0x11067398, .name
= "VT1702",
6277 .patch
= patch_vt1702
},
6278 { .id
= 0x11060428, .name
= "VT1718S",
6279 .patch
= patch_vt1718S
},
6280 { .id
= 0x11064428, .name
= "VT1718S",
6281 .patch
= patch_vt1718S
},
6282 { .id
= 0x11060441, .name
= "VT2020",
6283 .patch
= patch_vt1718S
},
6284 { .id
= 0x11064441, .name
= "VT1828S",
6285 .patch
= patch_vt1718S
},
6286 { .id
= 0x11060433, .name
= "VT1716S",
6287 .patch
= patch_vt1716S
},
6288 { .id
= 0x1106a721, .name
= "VT1716S",
6289 .patch
= patch_vt1716S
},
6290 { .id
= 0x11060438, .name
= "VT2002P", .patch
= patch_vt2002P
},
6291 { .id
= 0x11064438, .name
= "VT2002P", .patch
= patch_vt2002P
},
6292 { .id
= 0x11060448, .name
= "VT1812", .patch
= patch_vt1812
},
6293 { .id
= 0x11060440, .name
= "VT1818S",
6294 .patch
= patch_vt1708S
},
6298 MODULE_ALIAS("snd-hda-codec-id:1106*");
6300 static struct hda_codec_preset_list via_list
= {
6301 .preset
= snd_hda_preset_via
,
6302 .owner
= THIS_MODULE
,
6305 MODULE_LICENSE("GPL");
6306 MODULE_DESCRIPTION("VIA HD-audio codec");
6308 static int __init
patch_via_init(void)
6310 return snd_hda_add_codec_preset(&via_list
);
6313 static void __exit
patch_via_exit(void)
6315 snd_hda_delete_codec_preset(&via_list
);
6318 module_init(patch_via_init
)
6319 module_exit(patch_via_exit
)