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_AMP_FLAG
;
462 knew
->private_value
= val
;
466 static struct snd_kcontrol_new
*via_clone_control(struct via_spec
*spec
,
467 struct snd_kcontrol_new
*tmpl
)
469 struct snd_kcontrol_new
*knew
;
471 snd_array_init(&spec
->kctls
, sizeof(*knew
), 32);
472 knew
= snd_array_new(&spec
->kctls
);
476 knew
->name
= kstrdup(tmpl
->name
, GFP_KERNEL
);
482 static void via_free_kctls(struct hda_codec
*codec
)
484 struct via_spec
*spec
= codec
->spec
;
486 if (spec
->kctls
.list
) {
487 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
489 for (i
= 0; i
< spec
->kctls
.used
; i
++)
492 snd_array_free(&spec
->kctls
);
495 /* create input playback/capture controls for the given pin */
496 static int via_new_analog_input(struct via_spec
*spec
, const char *ctlname
,
497 int idx
, int mix_nid
)
502 sprintf(name
, "%s Playback Volume", ctlname
);
503 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
504 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
507 sprintf(name
, "%s Playback Switch", ctlname
);
508 err
= via_add_control(spec
, VIA_CTL_WIDGET_ANALOG_MUTE
, name
,
509 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
515 static void via_auto_set_output_and_unmute(struct hda_codec
*codec
,
516 hda_nid_t nid
, int pin_type
,
520 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
522 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
524 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
525 snd_hda_codec_write(codec
, nid
, 0,
526 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
530 static void via_auto_init_multi_out(struct hda_codec
*codec
)
532 struct via_spec
*spec
= codec
->spec
;
535 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
536 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
538 via_auto_set_output_and_unmute(codec
, nid
, PIN_OUT
, i
);
542 static void via_auto_init_hp_out(struct hda_codec
*codec
)
544 struct via_spec
*spec
= codec
->spec
;
548 for (i
= 0; i
< spec
->autocfg
.hp_outs
; i
++) {
549 pin
= spec
->autocfg
.hp_pins
[i
];
550 if (pin
) /* connect to front */
551 via_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, 0);
555 static void via_auto_init_analog_input(struct hda_codec
*codec
)
557 struct via_spec
*spec
= codec
->spec
;
560 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
561 hda_nid_t nid
= spec
->autocfg
.input_pins
[i
];
563 snd_hda_codec_write(codec
, nid
, 0,
564 AC_VERB_SET_PIN_WIDGET_CONTROL
,
565 (i
<= AUTO_PIN_FRONT_MIC
?
566 PIN_VREF50
: PIN_IN
));
571 static int is_smart51_pins(struct via_spec
*spec
, hda_nid_t pin
);
573 static void set_pin_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
574 unsigned int *affected_parm
)
577 unsigned def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
578 unsigned no_presence
= (def_conf
& AC_DEFCFG_MISC
)
579 >> AC_DEFCFG_MISC_SHIFT
580 & AC_DEFCFG_MISC_NO_PRESENCE
; /* do not support pin sense */
581 unsigned present
= snd_hda_jack_detect(codec
, nid
);
582 struct via_spec
*spec
= codec
->spec
;
583 if ((spec
->smart51_enabled
&& is_smart51_pins(spec
, nid
))
584 || ((no_presence
|| present
)
585 && get_defcfg_connect(def_conf
) != AC_JACK_PORT_NONE
)) {
586 *affected_parm
= AC_PWRST_D0
; /* if it's connected */
591 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
594 static void set_jack_power_state(struct hda_codec
*codec
)
596 struct via_spec
*spec
= codec
->spec
;
600 if (spec
->codec_type
== VT1702
) {
601 imux_is_smixer
= snd_hda_codec_read(
602 codec
, 0x13, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
604 /* PW 1/2/5 (14h/15h/18h) */
606 set_pin_power_state(codec
, 0x14, &parm
);
607 set_pin_power_state(codec
, 0x15, &parm
);
608 set_pin_power_state(codec
, 0x18, &parm
);
610 parm
= AC_PWRST_D0
; /* SW0 = stereo mixer (idx 3) */
611 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
612 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
614 snd_hda_codec_write(codec
, 0x12, 0, AC_VERB_SET_POWER_STATE
,
616 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
,
618 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_POWER_STATE
,
622 /* PW 3/4 (16h/17h) */
624 set_pin_power_state(codec
, 0x16, &parm
);
625 set_pin_power_state(codec
, 0x17, &parm
);
626 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
627 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_POWER_STATE
,
628 imux_is_smixer
? AC_PWRST_D0
: parm
);
629 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
631 snd_hda_codec_write(codec
, 0x1d, 0, AC_VERB_SET_POWER_STATE
,
633 } else if (spec
->codec_type
== VT1708B_8CH
634 || spec
->codec_type
== VT1708B_4CH
635 || spec
->codec_type
== VT1708S
) {
636 /* SW0 (17h) = stereo mixer */
637 int is_8ch
= spec
->codec_type
!= VT1708B_4CH
;
638 imux_is_smixer
= snd_hda_codec_read(
639 codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00)
640 == ((spec
->codec_type
== VT1708S
) ? 5 : 0);
642 /* PW 1/2/5 (1ah/1bh/1eh) */
644 set_pin_power_state(codec
, 0x1a, &parm
);
645 set_pin_power_state(codec
, 0x1b, &parm
);
646 set_pin_power_state(codec
, 0x1e, &parm
);
649 /* SW0 (17h), AIW 0/1 (13h/14h) */
650 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_POWER_STATE
,
652 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
654 snd_hda_codec_write(codec
, 0x14, 0, AC_VERB_SET_POWER_STATE
,
658 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
660 set_pin_power_state(codec
, 0x19, &parm
);
661 snd_hda_codec_write(codec
, 0x18, 0, AC_VERB_SET_POWER_STATE
,
663 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
,
666 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
669 set_pin_power_state(codec
, 0x22, &parm
);
670 snd_hda_codec_write(codec
, 0x26, 0,
671 AC_VERB_SET_POWER_STATE
, parm
);
672 snd_hda_codec_write(codec
, 0x24, 0,
673 AC_VERB_SET_POWER_STATE
, parm
);
676 /* PW 3/4/7 (1ch/1dh/23h) */
678 /* force to D0 for internal Speaker */
679 set_pin_power_state(codec
, 0x1c, &parm
);
680 set_pin_power_state(codec
, 0x1d, &parm
);
682 set_pin_power_state(codec
, 0x23, &parm
);
683 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
684 snd_hda_codec_write(codec
, 0x16, 0, AC_VERB_SET_POWER_STATE
,
685 imux_is_smixer
? AC_PWRST_D0
: parm
);
686 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
689 snd_hda_codec_write(codec
, 0x25, 0,
690 AC_VERB_SET_POWER_STATE
, parm
);
691 snd_hda_codec_write(codec
, 0x27, 0,
692 AC_VERB_SET_POWER_STATE
, parm
);
694 } else if (spec
->codec_type
== VT1718S
) {
695 /* MUX6 (1eh) = stereo mixer */
696 imux_is_smixer
= snd_hda_codec_read(
697 codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
699 /* PW 5/6/7 (29h/2ah/2bh) */
701 set_pin_power_state(codec
, 0x29, &parm
);
702 set_pin_power_state(codec
, 0x2a, &parm
);
703 set_pin_power_state(codec
, 0x2b, &parm
);
706 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
707 snd_hda_codec_write(codec
, 0x1e, 0, AC_VERB_SET_POWER_STATE
,
709 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
,
711 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
713 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
,
717 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
719 set_pin_power_state(codec
, 0x27, &parm
);
720 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_POWER_STATE
,
722 snd_hda_codec_write(codec
, 0xb, 0, AC_VERB_SET_POWER_STATE
,
725 /* PW2 (26h), AOW2 (ah) */
727 set_pin_power_state(codec
, 0x26, &parm
);
728 snd_hda_codec_write(codec
, 0xa, 0, AC_VERB_SET_POWER_STATE
,
731 /* PW0/1 (24h/25h) */
733 set_pin_power_state(codec
, 0x24, &parm
);
734 set_pin_power_state(codec
, 0x25, &parm
);
735 if (!spec
->hp_independent_mode
) /* check for redirected HP */
736 set_pin_power_state(codec
, 0x28, &parm
);
737 snd_hda_codec_write(codec
, 0x8, 0, AC_VERB_SET_POWER_STATE
,
739 snd_hda_codec_write(codec
, 0x9, 0, AC_VERB_SET_POWER_STATE
,
741 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
742 snd_hda_codec_write(codec
, 0x21, 0, AC_VERB_SET_POWER_STATE
,
743 imux_is_smixer
? AC_PWRST_D0
: parm
);
744 if (spec
->hp_independent_mode
) {
745 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
747 set_pin_power_state(codec
, 0x28, &parm
);
748 snd_hda_codec_write(codec
, 0x1b, 0,
749 AC_VERB_SET_POWER_STATE
, parm
);
750 snd_hda_codec_write(codec
, 0x34, 0,
751 AC_VERB_SET_POWER_STATE
, parm
);
752 snd_hda_codec_write(codec
, 0xc, 0,
753 AC_VERB_SET_POWER_STATE
, parm
);
755 } else if (spec
->codec_type
== VT1716S
) {
756 unsigned int mono_out
, present
;
757 /* SW0 (17h) = stereo mixer */
758 imux_is_smixer
= snd_hda_codec_read(
759 codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
761 /* PW 1/2/5 (1ah/1bh/1eh) */
763 set_pin_power_state(codec
, 0x1a, &parm
);
764 set_pin_power_state(codec
, 0x1b, &parm
);
765 set_pin_power_state(codec
, 0x1e, &parm
);
768 /* SW0 (17h), AIW0(13h) */
769 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_POWER_STATE
,
771 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
775 set_pin_power_state(codec
, 0x1e, &parm
);
777 if (spec
->dmic_enabled
)
778 set_pin_power_state(codec
, 0x22, &parm
);
782 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
784 /* SW2(26h), AIW1(14h) */
785 snd_hda_codec_write(codec
, 0x26, 0, AC_VERB_SET_POWER_STATE
,
787 snd_hda_codec_write(codec
, 0x14, 0, AC_VERB_SET_POWER_STATE
,
791 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
793 set_pin_power_state(codec
, 0x19, &parm
);
794 /* Smart 5.1 PW2(1bh) */
795 if (spec
->smart51_enabled
)
796 set_pin_power_state(codec
, 0x1b, &parm
);
797 snd_hda_codec_write(codec
, 0x18, 0, AC_VERB_SET_POWER_STATE
,
799 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
,
802 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
804 set_pin_power_state(codec
, 0x23, &parm
);
805 /* Smart 5.1 PW1(1ah) */
806 if (spec
->smart51_enabled
)
807 set_pin_power_state(codec
, 0x1a, &parm
);
808 snd_hda_codec_write(codec
, 0x27, 0, AC_VERB_SET_POWER_STATE
,
811 /* Smart 5.1 PW5(1eh) */
812 if (spec
->smart51_enabled
)
813 set_pin_power_state(codec
, 0x1e, &parm
);
814 snd_hda_codec_write(codec
, 0x25, 0, AC_VERB_SET_POWER_STATE
,
818 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
819 present
= snd_hda_jack_detect(codec
, 0x1c);
823 present
= snd_hda_jack_detect(codec
, 0x1d);
824 if (!spec
->hp_independent_mode
&& present
)
829 parm
= mono_out
? AC_PWRST_D0
: AC_PWRST_D3
;
830 snd_hda_codec_write(codec
, 0x28, 0, AC_VERB_SET_POWER_STATE
,
832 snd_hda_codec_write(codec
, 0x29, 0, AC_VERB_SET_POWER_STATE
,
834 snd_hda_codec_write(codec
, 0x2a, 0, AC_VERB_SET_POWER_STATE
,
837 /* PW 3/4 (1ch/1dh) */
839 set_pin_power_state(codec
, 0x1c, &parm
);
840 set_pin_power_state(codec
, 0x1d, &parm
);
841 /* HP Independent Mode, power on AOW3 */
842 if (spec
->hp_independent_mode
)
843 snd_hda_codec_write(codec
, 0x25, 0,
844 AC_VERB_SET_POWER_STATE
, parm
);
846 /* force to D0 for internal Speaker */
847 /* MW0 (16h), AOW0 (10h) */
848 snd_hda_codec_write(codec
, 0x16, 0, AC_VERB_SET_POWER_STATE
,
849 imux_is_smixer
? AC_PWRST_D0
: parm
);
850 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
851 mono_out
? AC_PWRST_D0
: parm
);
852 } else if (spec
->codec_type
== VT2002P
) {
853 unsigned int present
;
854 /* MUX9 (1eh) = stereo mixer */
855 imux_is_smixer
= snd_hda_codec_read(
856 codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
858 /* PW 5/6/7 (29h/2ah/2bh) */
860 set_pin_power_state(codec
, 0x29, &parm
);
861 set_pin_power_state(codec
, 0x2a, &parm
);
862 set_pin_power_state(codec
, 0x2b, &parm
);
865 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
866 snd_hda_codec_write(codec
, 0x1e, 0,
867 AC_VERB_SET_POWER_STATE
, parm
);
868 snd_hda_codec_write(codec
, 0x1f, 0,
869 AC_VERB_SET_POWER_STATE
, parm
);
870 snd_hda_codec_write(codec
, 0x10, 0,
871 AC_VERB_SET_POWER_STATE
, parm
);
872 snd_hda_codec_write(codec
, 0x11, 0,
873 AC_VERB_SET_POWER_STATE
, parm
);
877 snd_hda_codec_write(codec
, 0x8, 0,
878 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
880 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
882 set_pin_power_state(codec
, 0x26, &parm
);
883 snd_hda_codec_write(codec
, 0x1c, 0,
884 AC_VERB_SET_POWER_STATE
, parm
);
885 snd_hda_codec_write(codec
, 0x37,
886 0, AC_VERB_SET_POWER_STATE
, parm
);
888 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
890 set_pin_power_state(codec
, 0x25, &parm
);
891 snd_hda_codec_write(codec
, 0x19, 0,
892 AC_VERB_SET_POWER_STATE
, parm
);
893 snd_hda_codec_write(codec
, 0x35, 0,
894 AC_VERB_SET_POWER_STATE
, parm
);
895 if (spec
->hp_independent_mode
) {
896 snd_hda_codec_write(codec
, 0x9, 0,
897 AC_VERB_SET_POWER_STATE
, parm
);
901 /* PW0 (24h), MW0(18h), MUX0(34h) */
902 present
= snd_hda_jack_detect(codec
, 0x25);
904 set_pin_power_state(codec
, 0x24, &parm
);
908 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
911 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
915 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
918 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
922 /* PW15 (31h), MW8(17h), MUX8(3bh) */
923 present
= snd_hda_jack_detect(codec
, 0x26);
925 set_pin_power_state(codec
, 0x31, &parm
);
929 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
932 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
936 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
939 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
943 if (imux_is_smixer
|| !is_aa_path_mute(codec
))
946 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
950 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
951 } else if (spec
->codec_type
== VT1812
) {
952 unsigned int present
;
953 /* MUX10 (1eh) = stereo mixer */
954 imux_is_smixer
= snd_hda_codec_read(
955 codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
957 /* PW 5/6/7 (29h/2ah/2bh) */
959 set_pin_power_state(codec
, 0x29, &parm
);
960 set_pin_power_state(codec
, 0x2a, &parm
);
961 set_pin_power_state(codec
, 0x2b, &parm
);
964 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
965 snd_hda_codec_write(codec
, 0x1e, 0,
966 AC_VERB_SET_POWER_STATE
, parm
);
967 snd_hda_codec_write(codec
, 0x1f, 0,
968 AC_VERB_SET_POWER_STATE
, parm
);
969 snd_hda_codec_write(codec
, 0x10, 0,
970 AC_VERB_SET_POWER_STATE
, parm
);
971 snd_hda_codec_write(codec
, 0x11, 0,
972 AC_VERB_SET_POWER_STATE
, parm
);
976 snd_hda_codec_write(codec
, 0x8, 0,
977 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
979 /* PW4 (28h), MW4 (18h), MUX4(38h) */
981 set_pin_power_state(codec
, 0x28, &parm
);
982 snd_hda_codec_write(codec
, 0x18, 0,
983 AC_VERB_SET_POWER_STATE
, parm
);
984 snd_hda_codec_write(codec
, 0x38, 0,
985 AC_VERB_SET_POWER_STATE
, parm
);
987 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
989 set_pin_power_state(codec
, 0x25, &parm
);
990 snd_hda_codec_write(codec
, 0x15, 0,
991 AC_VERB_SET_POWER_STATE
, parm
);
992 snd_hda_codec_write(codec
, 0x35, 0,
993 AC_VERB_SET_POWER_STATE
, parm
);
994 if (spec
->hp_independent_mode
) {
995 snd_hda_codec_write(codec
, 0x9, 0,
996 AC_VERB_SET_POWER_STATE
, parm
);
999 /* Internal Speaker */
1000 /* PW0 (24h), MW0(14h), MUX0(34h) */
1001 present
= snd_hda_jack_detect(codec
, 0x25);
1003 set_pin_power_state(codec
, 0x24, &parm
);
1005 snd_hda_codec_write(codec
, 0x14, 0,
1006 AC_VERB_SET_POWER_STATE
,
1008 snd_hda_codec_write(codec
, 0x34, 0,
1009 AC_VERB_SET_POWER_STATE
,
1012 snd_hda_codec_write(codec
, 0x14, 0,
1013 AC_VERB_SET_POWER_STATE
,
1015 snd_hda_codec_write(codec
, 0x34, 0,
1016 AC_VERB_SET_POWER_STATE
,
1020 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1021 present
= snd_hda_jack_detect(codec
, 0x28);
1023 set_pin_power_state(codec
, 0x31, &parm
);
1025 snd_hda_codec_write(codec
, 0x1c, 0,
1026 AC_VERB_SET_POWER_STATE
,
1028 snd_hda_codec_write(codec
, 0x3c, 0,
1029 AC_VERB_SET_POWER_STATE
,
1031 snd_hda_codec_write(codec
, 0x3e, 0,
1032 AC_VERB_SET_POWER_STATE
,
1035 snd_hda_codec_write(codec
, 0x1c, 0,
1036 AC_VERB_SET_POWER_STATE
,
1038 snd_hda_codec_write(codec
, 0x3c, 0,
1039 AC_VERB_SET_POWER_STATE
,
1041 snd_hda_codec_write(codec
, 0x3e, 0,
1042 AC_VERB_SET_POWER_STATE
,
1046 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1048 set_pin_power_state(codec
, 0x33, &parm
);
1049 snd_hda_codec_write(codec
, 0x1d, 0,
1050 AC_VERB_SET_POWER_STATE
, parm
);
1051 snd_hda_codec_write(codec
, 0x3d, 0,
1052 AC_VERB_SET_POWER_STATE
, parm
);
1055 if (imux_is_smixer
|| !is_aa_path_mute(codec
))
1056 snd_hda_codec_write(
1058 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
1060 snd_hda_codec_write(
1062 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
1067 * input MUX handling
1069 static int via_mux_enum_info(struct snd_kcontrol
*kcontrol
,
1070 struct snd_ctl_elem_info
*uinfo
)
1072 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1073 struct via_spec
*spec
= codec
->spec
;
1074 return snd_hda_input_mux_info(spec
->input_mux
, uinfo
);
1077 static int via_mux_enum_get(struct snd_kcontrol
*kcontrol
,
1078 struct snd_ctl_elem_value
*ucontrol
)
1080 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1081 struct via_spec
*spec
= codec
->spec
;
1082 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1084 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
1088 static int via_mux_enum_put(struct snd_kcontrol
*kcontrol
,
1089 struct snd_ctl_elem_value
*ucontrol
)
1091 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1092 struct via_spec
*spec
= codec
->spec
;
1093 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1095 if (!spec
->mux_nids
[adc_idx
])
1097 /* switch to D0 beofre change index */
1098 if (snd_hda_codec_read(codec
, spec
->mux_nids
[adc_idx
], 0,
1099 AC_VERB_GET_POWER_STATE
, 0x00) != AC_PWRST_D0
)
1100 snd_hda_codec_write(codec
, spec
->mux_nids
[adc_idx
], 0,
1101 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
1102 /* update jack power state */
1103 set_jack_power_state(codec
);
1105 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
1106 spec
->mux_nids
[adc_idx
],
1107 &spec
->cur_mux
[adc_idx
]);
1110 static int via_independent_hp_info(struct snd_kcontrol
*kcontrol
,
1111 struct snd_ctl_elem_info
*uinfo
)
1113 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1114 struct via_spec
*spec
= codec
->spec
;
1115 return snd_hda_input_mux_info(spec
->hp_mux
, uinfo
);
1118 static int via_independent_hp_get(struct snd_kcontrol
*kcontrol
,
1119 struct snd_ctl_elem_value
*ucontrol
)
1121 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1122 hda_nid_t nid
= kcontrol
->private_value
;
1123 unsigned int pinsel
;
1125 /* use !! to translate conn sel 2 for VT1718S */
1126 pinsel
= !!snd_hda_codec_read(codec
, nid
, 0,
1127 AC_VERB_GET_CONNECT_SEL
,
1129 ucontrol
->value
.enumerated
.item
[0] = pinsel
;
1134 static void activate_ctl(struct hda_codec
*codec
, const char *name
, int active
)
1136 struct snd_kcontrol
*ctl
= snd_hda_find_mixer_ctl(codec
, name
);
1138 ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1139 ctl
->vd
[0].access
|= active
1140 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1141 snd_ctl_notify(codec
->bus
->card
,
1142 SNDRV_CTL_EVENT_MASK_VALUE
, &ctl
->id
);
1146 static hda_nid_t
side_mute_channel(struct via_spec
*spec
)
1148 switch (spec
->codec_type
) {
1149 case VT1708
: return 0x1b;
1150 case VT1709_10CH
: return 0x29;
1151 case VT1708B_8CH
: /* fall thru */
1152 case VT1708S
: return 0x27;
1157 static int update_side_mute_status(struct hda_codec
*codec
)
1159 /* mute side channel */
1160 struct via_spec
*spec
= codec
->spec
;
1161 unsigned int parm
= spec
->hp_independent_mode
1162 ? AMP_OUT_MUTE
: AMP_OUT_UNMUTE
;
1163 hda_nid_t sw3
= side_mute_channel(spec
);
1166 snd_hda_codec_write(codec
, sw3
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
1171 static int via_independent_hp_put(struct snd_kcontrol
*kcontrol
,
1172 struct snd_ctl_elem_value
*ucontrol
)
1174 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1175 struct via_spec
*spec
= codec
->spec
;
1176 hda_nid_t nid
= kcontrol
->private_value
;
1177 unsigned int pinsel
= ucontrol
->value
.enumerated
.item
[0];
1178 /* Get Independent Mode index of headphone pin widget */
1179 spec
->hp_independent_mode
= spec
->hp_independent_mode_index
== pinsel
1181 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, pinsel
);
1183 if (spec
->multiout
.hp_nid
&& spec
->multiout
.hp_nid
1184 != spec
->multiout
.dac_nids
[HDA_FRONT
])
1185 snd_hda_codec_setup_stream(codec
, spec
->multiout
.hp_nid
,
1188 update_side_mute_status(codec
);
1189 /* update HP volume/swtich active state */
1190 if (spec
->codec_type
== VT1708S
1191 || spec
->codec_type
== VT1702
1192 || spec
->codec_type
== VT1718S
1193 || spec
->codec_type
== VT1716S
1194 || spec
->codec_type
== VT2002P
1195 || spec
->codec_type
== VT1812
) {
1196 activate_ctl(codec
, "Headphone Playback Volume",
1197 spec
->hp_independent_mode
);
1198 activate_ctl(codec
, "Headphone Playback Switch",
1199 spec
->hp_independent_mode
);
1204 static struct snd_kcontrol_new via_hp_mixer
[2] = {
1206 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1207 .name
= "Independent HP",
1208 .info
= via_independent_hp_info
,
1209 .get
= via_independent_hp_get
,
1210 .put
= via_independent_hp_put
,
1213 .iface
= NID_MAPPING
,
1214 .name
= "Independent HP",
1218 static int via_hp_build(struct hda_codec
*codec
)
1220 struct via_spec
*spec
= codec
->spec
;
1221 struct snd_kcontrol_new
*knew
;
1224 hda_nid_t conn
[HDA_MAX_CONNECTIONS
];
1226 switch (spec
->codec_type
) {
1237 nid
= spec
->autocfg
.hp_pins
[0];
1241 nums
= snd_hda_get_connections(codec
, nid
, conn
, HDA_MAX_CONNECTIONS
);
1245 knew
= via_clone_control(spec
, &via_hp_mixer
[0]);
1249 knew
->subdevice
= HDA_SUBDEV_NID_FLAG
| nid
;
1250 knew
->private_value
= nid
;
1252 knew
= via_clone_control(spec
, &via_hp_mixer
[1]);
1255 knew
->subdevice
= side_mute_channel(spec
);
1260 static void notify_aa_path_ctls(struct hda_codec
*codec
)
1263 struct snd_ctl_elem_id id
;
1264 const char *labels
[] = {"Mic", "Front Mic", "Line"};
1266 memset(&id
, 0, sizeof(id
));
1267 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
1268 for (i
= 0; i
< ARRAY_SIZE(labels
); i
++) {
1269 sprintf(id
.name
, "%s Playback Volume", labels
[i
]);
1270 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
1275 static void mute_aa_path(struct hda_codec
*codec
, int mute
)
1277 struct via_spec
*spec
= codec
->spec
;
1278 hda_nid_t nid_mixer
;
1282 /* get nid of MW0 and start & end index */
1283 switch (spec
->codec_type
) {
1306 /* check AA path's mute status */
1307 for (i
= start_idx
; i
<= end_idx
; i
++) {
1308 int val
= mute
? HDA_AMP_MUTE
: HDA_AMP_UNMUTE
;
1309 snd_hda_codec_amp_stereo(codec
, nid_mixer
, HDA_INPUT
, i
,
1313 static int is_smart51_pins(struct via_spec
*spec
, hda_nid_t pin
)
1317 for (index
= AUTO_PIN_MIC
; index
< AUTO_PIN_FRONT_LINE
; index
++) {
1318 if (pin
== spec
->autocfg
.input_pins
[index
]) {
1326 static int via_smart51_info(struct snd_kcontrol
*kcontrol
,
1327 struct snd_ctl_elem_info
*uinfo
)
1329 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1331 uinfo
->value
.integer
.min
= 0;
1332 uinfo
->value
.integer
.max
= 1;
1336 static int via_smart51_get(struct snd_kcontrol
*kcontrol
,
1337 struct snd_ctl_elem_value
*ucontrol
)
1339 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1340 struct via_spec
*spec
= codec
->spec
;
1341 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
1345 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
1346 hda_nid_t nid
= spec
->autocfg
.input_pins
[index
[i
]];
1349 snd_hda_codec_read(codec
, nid
, 0,
1350 AC_VERB_GET_PIN_WIDGET_CONTROL
,
1352 if (i
== AUTO_PIN_FRONT_MIC
1353 && spec
->hp_independent_mode
1354 && spec
->codec_type
!= VT1718S
)
1355 continue; /* ignore FMic for independent HP */
1356 if (ctl
& AC_PINCTL_IN_EN
1357 && !(ctl
& AC_PINCTL_OUT_EN
))
1361 *ucontrol
->value
.integer
.value
= on
;
1365 static int via_smart51_put(struct snd_kcontrol
*kcontrol
,
1366 struct snd_ctl_elem_value
*ucontrol
)
1368 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1369 struct via_spec
*spec
= codec
->spec
;
1370 int out_in
= *ucontrol
->value
.integer
.value
1371 ? AC_PINCTL_OUT_EN
: AC_PINCTL_IN_EN
;
1372 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
1375 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
1376 hda_nid_t nid
= spec
->autocfg
.input_pins
[index
[i
]];
1377 if (i
== AUTO_PIN_FRONT_MIC
1378 && spec
->hp_independent_mode
1379 && spec
->codec_type
!= VT1718S
)
1380 continue; /* don't retask FMic for independent HP */
1382 unsigned int parm
= snd_hda_codec_read(
1384 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
1385 parm
&= ~(AC_PINCTL_IN_EN
| AC_PINCTL_OUT_EN
);
1387 snd_hda_codec_write(codec
, nid
, 0,
1388 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1390 if (out_in
== AC_PINCTL_OUT_EN
) {
1391 mute_aa_path(codec
, 1);
1392 notify_aa_path_ctls(codec
);
1394 if (spec
->codec_type
== VT1718S
)
1395 snd_hda_codec_amp_stereo(
1396 codec
, nid
, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
1399 if (i
== AUTO_PIN_FRONT_MIC
) {
1400 if (spec
->codec_type
== VT1708S
1401 || spec
->codec_type
== VT1716S
) {
1402 /* input = index 1 (AOW3) */
1403 snd_hda_codec_write(
1405 AC_VERB_SET_CONNECT_SEL
, 1);
1406 snd_hda_codec_amp_stereo(
1407 codec
, nid
, HDA_OUTPUT
,
1408 0, HDA_AMP_MUTE
, HDA_AMP_UNMUTE
);
1412 spec
->smart51_enabled
= *ucontrol
->value
.integer
.value
;
1413 set_jack_power_state(codec
);
1417 static struct snd_kcontrol_new via_smart51_mixer
[2] = {
1419 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1420 .name
= "Smart 5.1",
1422 .info
= via_smart51_info
,
1423 .get
= via_smart51_get
,
1424 .put
= via_smart51_put
,
1427 .iface
= NID_MAPPING
,
1428 .name
= "Smart 5.1",
1432 static int via_smart51_build(struct via_spec
*spec
)
1434 struct snd_kcontrol_new
*knew
;
1435 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
1439 knew
= via_clone_control(spec
, &via_smart51_mixer
[0]);
1443 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
1444 nid
= spec
->autocfg
.input_pins
[index
[i
]];
1446 knew
= via_clone_control(spec
, &via_smart51_mixer
[1]);
1449 knew
->subdevice
= nid
;
1456 /* capture mixer elements */
1457 static struct snd_kcontrol_new vt1708_capture_mixer
[] = {
1458 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT
),
1459 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT
),
1460 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT
),
1461 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT
),
1463 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1464 /* The multiple "Capture Source" controls confuse alsamixer
1465 * So call somewhat different..
1467 /* .name = "Capture Source", */
1468 .name
= "Input Source",
1470 .info
= via_mux_enum_info
,
1471 .get
= via_mux_enum_get
,
1472 .put
= via_mux_enum_put
,
1477 /* check AA path's mute statue */
1478 static int is_aa_path_mute(struct hda_codec
*codec
)
1481 hda_nid_t nid_mixer
;
1485 struct via_spec
*spec
= codec
->spec
;
1486 /* get nid of MW0 and start & end index */
1487 switch (spec
->codec_type
) {
1515 /* check AA path's mute status */
1516 for (i
= start_idx
; i
<= end_idx
; i
++) {
1517 unsigned int con_list
= snd_hda_codec_read(
1518 codec
, nid_mixer
, 0, AC_VERB_GET_CONNECT_LIST
, i
/4*4);
1519 int shift
= 8 * (i
% 4);
1520 hda_nid_t nid_pin
= (con_list
& (0xff << shift
)) >> shift
;
1521 unsigned int defconf
= snd_hda_codec_get_pincfg(codec
, nid_pin
);
1522 if (get_defcfg_connect(defconf
) == AC_JACK_PORT_COMPLEX
) {
1523 /* check mute status while the pin is connected */
1524 int mute_l
= snd_hda_codec_amp_read(codec
, nid_mixer
, 0,
1526 int mute_r
= snd_hda_codec_amp_read(codec
, nid_mixer
, 1,
1528 if (!mute_l
|| !mute_r
) {
1537 /* enter/exit analog low-current mode */
1538 static void analog_low_current_mode(struct hda_codec
*codec
, int stream_idle
)
1540 struct via_spec
*spec
= codec
->spec
;
1541 static int saved_stream_idle
= 1; /* saved stream idle status */
1542 int enable
= is_aa_path_mute(codec
);
1543 unsigned int verb
= 0;
1544 unsigned int parm
= 0;
1546 if (stream_idle
== -1) /* stream status did not change */
1547 enable
= enable
&& saved_stream_idle
;
1549 enable
= enable
&& stream_idle
;
1550 saved_stream_idle
= stream_idle
;
1553 /* decide low current mode's verb & parameter */
1554 switch (spec
->codec_type
) {
1558 parm
= enable
? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1564 parm
= enable
? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1568 parm
= enable
? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1573 parm
= enable
? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1576 return; /* other codecs are not supported */
1579 snd_hda_codec_write(codec
, codec
->afg
, 0, verb
, parm
);
1583 * generic initialization of ADC, input mixers and output mixers
1585 static struct hda_verb vt1708_volume_init_verbs
[] = {
1587 * Unmute ADC0-1 and set the default input to mic-in
1589 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1590 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1593 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1596 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1597 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1598 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1599 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1600 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1601 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1604 * Set up output mixers (0x19 - 0x1b)
1606 /* set vol=0 to output mixers */
1607 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1608 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1609 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1611 /* Setup default input MW0 to PW4 */
1612 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
1613 /* PW9 Output enable */
1614 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1618 static int via_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1619 struct hda_codec
*codec
,
1620 struct snd_pcm_substream
*substream
)
1622 struct via_spec
*spec
= codec
->spec
;
1623 int idle
= substream
->pstr
->substream_opened
== 1
1624 && substream
->ref_count
== 0;
1625 analog_low_current_mode(codec
, idle
);
1626 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
1630 static void playback_multi_pcm_prep_0(struct hda_codec
*codec
,
1631 unsigned int stream_tag
,
1632 unsigned int format
,
1633 struct snd_pcm_substream
*substream
)
1635 struct via_spec
*spec
= codec
->spec
;
1636 struct hda_multi_out
*mout
= &spec
->multiout
;
1637 hda_nid_t
*nids
= mout
->dac_nids
;
1638 int chs
= substream
->runtime
->channels
;
1641 mutex_lock(&codec
->spdif_mutex
);
1642 if (mout
->dig_out_nid
&& mout
->dig_out_used
!= HDA_DIG_EXCLUSIVE
) {
1644 snd_hda_is_supported_format(codec
, mout
->dig_out_nid
,
1646 !(codec
->spdif_status
& IEC958_AES0_NONAUDIO
)) {
1647 mout
->dig_out_used
= HDA_DIG_ANALOG_DUP
;
1648 /* turn off SPDIF once; otherwise the IEC958 bits won't
1650 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1651 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1652 AC_VERB_SET_DIGI_CONVERT_1
,
1654 ~AC_DIG1_ENABLE
& 0xff);
1655 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1656 stream_tag
, 0, format
);
1657 /* turn on again (if needed) */
1658 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1659 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1660 AC_VERB_SET_DIGI_CONVERT_1
,
1661 codec
->spdif_ctls
& 0xff);
1663 mout
->dig_out_used
= 0;
1664 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1668 mutex_unlock(&codec
->spdif_mutex
);
1671 snd_hda_codec_setup_stream(codec
, nids
[HDA_FRONT
], stream_tag
,
1674 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
]
1675 && !spec
->hp_independent_mode
)
1676 /* headphone out will just decode front left/right (stereo) */
1677 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
, stream_tag
,
1680 /* extra outputs copied from front */
1681 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1682 if (mout
->extra_out_nid
[i
])
1683 snd_hda_codec_setup_stream(codec
,
1684 mout
->extra_out_nid
[i
],
1685 stream_tag
, 0, format
);
1688 for (i
= 1; i
< mout
->num_dacs
; i
++) {
1689 if (chs
>= (i
+ 1) * 2) /* independent out */
1690 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1692 else /* copy front */
1693 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1698 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1699 struct hda_codec
*codec
,
1700 unsigned int stream_tag
,
1701 unsigned int format
,
1702 struct snd_pcm_substream
*substream
)
1704 struct via_spec
*spec
= codec
->spec
;
1705 struct hda_multi_out
*mout
= &spec
->multiout
;
1706 hda_nid_t
*nids
= mout
->dac_nids
;
1708 if (substream
->number
== 0)
1709 playback_multi_pcm_prep_0(codec
, stream_tag
, format
,
1712 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1713 spec
->hp_independent_mode
)
1714 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1715 stream_tag
, 0, format
);
1717 vt1708_start_hp_work(spec
);
1721 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1722 struct hda_codec
*codec
,
1723 struct snd_pcm_substream
*substream
)
1725 struct via_spec
*spec
= codec
->spec
;
1726 struct hda_multi_out
*mout
= &spec
->multiout
;
1727 hda_nid_t
*nids
= mout
->dac_nids
;
1730 if (substream
->number
== 0) {
1731 for (i
= 0; i
< mout
->num_dacs
; i
++)
1732 snd_hda_codec_setup_stream(codec
, nids
[i
], 0, 0, 0);
1734 if (mout
->hp_nid
&& !spec
->hp_independent_mode
)
1735 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1738 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1739 if (mout
->extra_out_nid
[i
])
1740 snd_hda_codec_setup_stream(codec
,
1741 mout
->extra_out_nid
[i
],
1743 mutex_lock(&codec
->spdif_mutex
);
1744 if (mout
->dig_out_nid
&&
1745 mout
->dig_out_used
== HDA_DIG_ANALOG_DUP
) {
1746 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1748 mout
->dig_out_used
= 0;
1750 mutex_unlock(&codec
->spdif_mutex
);
1752 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1753 spec
->hp_independent_mode
)
1754 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1757 vt1708_stop_hp_work(spec
);
1764 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1765 struct hda_codec
*codec
,
1766 struct snd_pcm_substream
*substream
)
1768 struct via_spec
*spec
= codec
->spec
;
1769 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
1772 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
1773 struct hda_codec
*codec
,
1774 struct snd_pcm_substream
*substream
)
1776 struct via_spec
*spec
= codec
->spec
;
1777 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
1780 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1781 struct hda_codec
*codec
,
1782 unsigned int stream_tag
,
1783 unsigned int format
,
1784 struct snd_pcm_substream
*substream
)
1786 struct via_spec
*spec
= codec
->spec
;
1787 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
1788 stream_tag
, format
, substream
);
1791 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1792 struct hda_codec
*codec
,
1793 struct snd_pcm_substream
*substream
)
1795 struct via_spec
*spec
= codec
->spec
;
1796 snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
1803 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1804 struct hda_codec
*codec
,
1805 unsigned int stream_tag
,
1806 unsigned int format
,
1807 struct snd_pcm_substream
*substream
)
1809 struct via_spec
*spec
= codec
->spec
;
1811 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
1812 stream_tag
, 0, format
);
1816 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1817 struct hda_codec
*codec
,
1818 struct snd_pcm_substream
*substream
)
1820 struct via_spec
*spec
= codec
->spec
;
1821 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
1825 static struct hda_pcm_stream vt1708_pcm_analog_playback
= {
1829 .nid
= 0x10, /* NID to query formats and rates */
1831 .open
= via_playback_pcm_open
,
1832 .prepare
= via_playback_multi_pcm_prepare
,
1833 .cleanup
= via_playback_multi_pcm_cleanup
1837 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
1841 .nid
= 0x10, /* NID to query formats and rates */
1842 /* We got noisy outputs on the right channel on VT1708 when
1843 * 24bit samples are used. Until any workaround is found,
1844 * disable the 24bit format, so far.
1846 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1848 .open
= via_playback_pcm_open
,
1849 .prepare
= via_playback_multi_pcm_prepare
,
1850 .cleanup
= via_playback_multi_pcm_cleanup
1854 static struct hda_pcm_stream vt1708_pcm_analog_capture
= {
1858 .nid
= 0x15, /* NID to query formats and rates */
1860 .prepare
= via_capture_pcm_prepare
,
1861 .cleanup
= via_capture_pcm_cleanup
1865 static struct hda_pcm_stream vt1708_pcm_digital_playback
= {
1869 /* NID is set in via_build_pcms */
1871 .open
= via_dig_playback_pcm_open
,
1872 .close
= via_dig_playback_pcm_close
,
1873 .prepare
= via_dig_playback_pcm_prepare
,
1874 .cleanup
= via_dig_playback_pcm_cleanup
1878 static struct hda_pcm_stream vt1708_pcm_digital_capture
= {
1884 static int via_build_controls(struct hda_codec
*codec
)
1886 struct via_spec
*spec
= codec
->spec
;
1887 struct snd_kcontrol
*kctl
;
1888 struct snd_kcontrol_new
*knew
;
1891 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1892 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1897 if (spec
->multiout
.dig_out_nid
) {
1898 err
= snd_hda_create_spdif_out_ctls(codec
,
1899 spec
->multiout
.dig_out_nid
);
1902 err
= snd_hda_create_spdif_share_sw(codec
,
1906 spec
->multiout
.share_spdif
= 1;
1908 if (spec
->dig_in_nid
) {
1909 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1914 /* assign Capture Source enums to NID */
1915 kctl
= snd_hda_find_mixer_ctl(codec
, "Input Source");
1916 for (i
= 0; kctl
&& i
< kctl
->count
; i
++) {
1917 err
= snd_hda_add_nid(codec
, kctl
, i
, spec
->mux_nids
[i
]);
1922 /* other nid->control mapping */
1923 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1924 for (knew
= spec
->mixers
[i
]; knew
->name
; knew
++) {
1925 if (knew
->iface
!= NID_MAPPING
)
1927 kctl
= snd_hda_find_mixer_ctl(codec
, knew
->name
);
1930 err
= snd_hda_add_nid(codec
, kctl
, 0,
1935 /* init power states */
1936 set_jack_power_state(codec
);
1937 analog_low_current_mode(codec
, 1);
1939 via_free_kctls(codec
); /* no longer needed */
1943 static int via_build_pcms(struct hda_codec
*codec
)
1945 struct via_spec
*spec
= codec
->spec
;
1946 struct hda_pcm
*info
= spec
->pcm_rec
;
1948 codec
->num_pcms
= 1;
1949 codec
->pcm_info
= info
;
1951 info
->name
= spec
->stream_name_analog
;
1952 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1953 *(spec
->stream_analog_playback
);
1954 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1955 spec
->multiout
.dac_nids
[0];
1956 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *(spec
->stream_analog_capture
);
1957 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
1959 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
1960 spec
->multiout
.max_channels
;
1962 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
1965 info
->name
= spec
->stream_name_digital
;
1966 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
1967 if (spec
->multiout
.dig_out_nid
) {
1968 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1969 *(spec
->stream_digital_playback
);
1970 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1971 spec
->multiout
.dig_out_nid
;
1973 if (spec
->dig_in_nid
) {
1974 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
1975 *(spec
->stream_digital_capture
);
1976 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
1984 static void via_free(struct hda_codec
*codec
)
1986 struct via_spec
*spec
= codec
->spec
;
1991 via_free_kctls(codec
);
1992 vt1708_stop_hp_work(spec
);
1996 /* mute internal speaker if HP is plugged */
1997 static void via_hp_automute(struct hda_codec
*codec
)
1999 unsigned int present
= 0;
2000 struct via_spec
*spec
= codec
->spec
;
2002 present
= snd_hda_jack_detect(codec
, spec
->autocfg
.hp_pins
[0]);
2004 if (!spec
->hp_independent_mode
) {
2005 struct snd_ctl_elem_id id
;
2007 snd_hda_codec_amp_stereo(
2008 codec
, spec
->autocfg
.line_out_pins
[0], HDA_OUTPUT
, 0,
2009 HDA_AMP_MUTE
, present
? HDA_AMP_MUTE
: 0);
2011 memset(&id
, 0, sizeof(id
));
2012 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
2013 strcpy(id
.name
, "Front Playback Switch");
2014 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
2019 /* mute mono out if HP or Line out is plugged */
2020 static void via_mono_automute(struct hda_codec
*codec
)
2022 unsigned int hp_present
, lineout_present
;
2023 struct via_spec
*spec
= codec
->spec
;
2025 if (spec
->codec_type
!= VT1716S
)
2028 lineout_present
= snd_hda_jack_detect(codec
,
2029 spec
->autocfg
.line_out_pins
[0]);
2031 /* Mute Mono Out if Line Out is plugged */
2032 if (lineout_present
) {
2033 snd_hda_codec_amp_stereo(
2034 codec
, 0x2A, HDA_OUTPUT
, 0, HDA_AMP_MUTE
, HDA_AMP_MUTE
);
2038 hp_present
= snd_hda_jack_detect(codec
, spec
->autocfg
.hp_pins
[0]);
2040 if (!spec
->hp_independent_mode
)
2041 snd_hda_codec_amp_stereo(
2042 codec
, 0x2A, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
2043 hp_present
? HDA_AMP_MUTE
: 0);
2046 static void via_gpio_control(struct hda_codec
*codec
)
2048 unsigned int gpio_data
;
2049 unsigned int vol_counter
;
2051 unsigned int master_vol
;
2053 struct via_spec
*spec
= codec
->spec
;
2055 gpio_data
= snd_hda_codec_read(codec
, codec
->afg
, 0,
2056 AC_VERB_GET_GPIO_DATA
, 0) & 0x03;
2058 vol_counter
= (snd_hda_codec_read(codec
, codec
->afg
, 0,
2059 0xF84, 0) & 0x3F0000) >> 16;
2061 vol
= vol_counter
& 0x1F;
2062 master_vol
= snd_hda_codec_read(codec
, 0x1A, 0,
2063 AC_VERB_GET_AMP_GAIN_MUTE
,
2066 if (gpio_data
== 0x02) {
2067 /* unmute line out */
2068 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
2069 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
2071 if (vol_counter
& 0x20) {
2072 /* decrease volume */
2073 if (vol
> master_vol
)
2075 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
,
2079 /* increase volume */
2080 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
, 0,
2082 ((master_vol
+vol
) > 0x2A) ? 0x2A :
2085 } else if (!(gpio_data
& 0x02)) {
2087 snd_hda_codec_amp_stereo(codec
,
2088 spec
->autocfg
.line_out_pins
[0],
2089 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
2094 /* mute Internal-Speaker if HP is plugged */
2095 static void via_speaker_automute(struct hda_codec
*codec
)
2097 unsigned int hp_present
;
2098 struct via_spec
*spec
= codec
->spec
;
2100 if (spec
->codec_type
!= VT2002P
&& spec
->codec_type
!= VT1812
)
2103 hp_present
= snd_hda_jack_detect(codec
, spec
->autocfg
.hp_pins
[0]);
2105 if (!spec
->hp_independent_mode
) {
2106 struct snd_ctl_elem_id id
;
2107 snd_hda_codec_amp_stereo(
2108 codec
, spec
->autocfg
.speaker_pins
[0], HDA_OUTPUT
, 0,
2109 HDA_AMP_MUTE
, hp_present
? HDA_AMP_MUTE
: 0);
2111 memset(&id
, 0, sizeof(id
));
2112 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
2113 strcpy(id
.name
, "Speaker Playback Switch");
2114 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
2119 /* mute line-out and internal speaker if HP is plugged */
2120 static void via_hp_bind_automute(struct hda_codec
*codec
)
2122 /* use long instead of int below just to avoid an internal compiler
2123 * error with gcc 4.0.x
2125 unsigned long hp_present
, present
= 0;
2126 struct via_spec
*spec
= codec
->spec
;
2129 if (!spec
->autocfg
.hp_pins
[0] || !spec
->autocfg
.line_out_pins
[0])
2132 hp_present
= snd_hda_jack_detect(codec
, spec
->autocfg
.hp_pins
[0]);
2134 present
= snd_hda_jack_detect(codec
, spec
->autocfg
.line_out_pins
[0]);
2136 if (!spec
->hp_independent_mode
) {
2137 /* Mute Line-Outs */
2138 for (i
= 0; i
< spec
->autocfg
.line_outs
; i
++)
2139 snd_hda_codec_amp_stereo(
2140 codec
, spec
->autocfg
.line_out_pins
[i
],
2142 HDA_AMP_MUTE
, hp_present
? HDA_AMP_MUTE
: 0);
2144 present
= hp_present
;
2147 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++)
2148 snd_hda_codec_amp_stereo(
2149 codec
, spec
->autocfg
.speaker_pins
[i
], HDA_OUTPUT
, 0,
2150 HDA_AMP_MUTE
, present
? HDA_AMP_MUTE
: 0);
2154 /* unsolicited event for jack sensing */
2155 static void via_unsol_event(struct hda_codec
*codec
,
2159 if (res
& VIA_HP_EVENT
)
2160 via_hp_automute(codec
);
2161 if (res
& VIA_GPIO_EVENT
)
2162 via_gpio_control(codec
);
2163 if (res
& VIA_JACK_EVENT
)
2164 set_jack_power_state(codec
);
2165 if (res
& VIA_MONO_EVENT
)
2166 via_mono_automute(codec
);
2167 if (res
& VIA_SPEAKER_EVENT
)
2168 via_speaker_automute(codec
);
2169 if (res
& VIA_BIND_HP_EVENT
)
2170 via_hp_bind_automute(codec
);
2173 static int via_init(struct hda_codec
*codec
)
2175 struct via_spec
*spec
= codec
->spec
;
2177 for (i
= 0; i
< spec
->num_iverbs
; i
++)
2178 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
2180 spec
->codec_type
= get_codec_type(codec
);
2181 if (spec
->codec_type
== VT1708BCE
)
2182 spec
->codec_type
= VT1708S
; /* VT1708BCE & VT1708S are almost
2184 /* Lydia Add for EAPD enable */
2185 if (!spec
->dig_in_nid
) { /* No Digital In connection */
2186 if (spec
->dig_in_pin
) {
2187 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
2188 AC_VERB_SET_PIN_WIDGET_CONTROL
,
2190 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
2191 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
2193 } else /* enable SPDIF-input pin */
2194 snd_hda_codec_write(codec
, spec
->autocfg
.dig_in_pin
, 0,
2195 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
2197 /* assign slave outs */
2198 if (spec
->slave_dig_outs
[0])
2199 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
2204 #ifdef SND_HDA_NEEDS_RESUME
2205 static int via_suspend(struct hda_codec
*codec
, pm_message_t state
)
2207 struct via_spec
*spec
= codec
->spec
;
2208 vt1708_stop_hp_work(spec
);
2213 #ifdef CONFIG_SND_HDA_POWER_SAVE
2214 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
2216 struct via_spec
*spec
= codec
->spec
;
2217 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
2223 static struct hda_codec_ops via_patch_ops
= {
2224 .build_controls
= via_build_controls
,
2225 .build_pcms
= via_build_pcms
,
2228 #ifdef SND_HDA_NEEDS_RESUME
2229 .suspend
= via_suspend
,
2231 #ifdef CONFIG_SND_HDA_POWER_SAVE
2232 .check_power_status
= via_check_power_status
,
2236 /* fill in the dac_nids table from the parsed pin configuration */
2237 static int vt1708_auto_fill_dac_nids(struct via_spec
*spec
,
2238 const struct auto_pin_cfg
*cfg
)
2243 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2245 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2247 for (i
= 0; i
< 4; i
++) {
2248 nid
= cfg
->line_out_pins
[i
];
2250 /* config dac list */
2252 case AUTO_SEQ_FRONT
:
2253 spec
->multiout
.dac_nids
[i
] = 0x10;
2255 case AUTO_SEQ_CENLFE
:
2256 spec
->multiout
.dac_nids
[i
] = 0x12;
2258 case AUTO_SEQ_SURROUND
:
2259 spec
->multiout
.dac_nids
[i
] = 0x11;
2262 spec
->multiout
.dac_nids
[i
] = 0x13;
2271 /* add playback controls from the parsed DAC table */
2272 static int vt1708_auto_create_multi_out_ctls(struct via_spec
*spec
,
2273 const struct auto_pin_cfg
*cfg
)
2276 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2277 hda_nid_t nid
, nid_vol
, nid_vols
[] = {0x17, 0x19, 0x1a, 0x1b};
2280 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2281 nid
= cfg
->line_out_pins
[i
];
2286 nid_vol
= nid_vols
[i
];
2288 if (i
== AUTO_SEQ_CENLFE
) {
2290 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2291 "Center Playback Volume",
2292 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2296 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2297 "LFE Playback Volume",
2298 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2302 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2303 "Center Playback Switch",
2304 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2308 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2309 "LFE Playback Switch",
2310 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2314 } else if (i
== AUTO_SEQ_FRONT
) {
2315 /* add control to mixer index 0 */
2316 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2317 "Master Front Playback Volume",
2318 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2322 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2323 "Master Front Playback Switch",
2324 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2329 /* add control to PW3 */
2330 sprintf(name
, "%s Playback Volume", chname
[i
]);
2331 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2332 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2336 sprintf(name
, "%s Playback Switch", chname
[i
]);
2337 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2338 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2343 sprintf(name
, "%s Playback Volume", chname
[i
]);
2344 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2345 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2349 sprintf(name
, "%s Playback Switch", chname
[i
]);
2350 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2351 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2361 static void create_hp_imux(struct via_spec
*spec
)
2364 struct hda_input_mux
*imux
= &spec
->private_imux
[1];
2365 static const char *texts
[] = { "OFF", "ON", NULL
};
2367 /* for hp mode select */
2369 while (texts
[i
] != NULL
) {
2370 imux
->items
[imux
->num_items
].label
= texts
[i
];
2371 imux
->items
[imux
->num_items
].index
= i
;
2376 spec
->hp_mux
= &spec
->private_imux
[1];
2379 static int vt1708_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2386 spec
->multiout
.hp_nid
= VT1708_HP_NID
; /* AOW3 */
2387 spec
->hp_independent_mode_index
= 1;
2389 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2390 "Headphone Playback Volume",
2391 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2394 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2395 "Headphone Playback Switch",
2396 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2400 create_hp_imux(spec
);
2405 /* create playback/capture controls for input pins */
2406 static int vt1708_auto_create_analog_input_ctls(struct via_spec
*spec
,
2407 const struct auto_pin_cfg
*cfg
)
2409 static char *labels
[] = {
2410 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2412 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2413 int i
, err
, idx
= 0;
2415 /* for internal loopback recording select */
2416 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2417 imux
->items
[imux
->num_items
].index
= idx
;
2420 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2421 if (!cfg
->input_pins
[i
])
2424 switch (cfg
->input_pins
[i
]) {
2425 case 0x1d: /* Mic */
2429 case 0x1e: /* Line In */
2433 case 0x21: /* Front Mic */
2441 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x17);
2444 imux
->items
[imux
->num_items
].label
= labels
[i
];
2445 imux
->items
[imux
->num_items
].index
= idx
;
2451 #ifdef CONFIG_SND_HDA_POWER_SAVE
2452 static struct hda_amp_list vt1708_loopbacks
[] = {
2453 { 0x17, HDA_INPUT
, 1 },
2454 { 0x17, HDA_INPUT
, 2 },
2455 { 0x17, HDA_INPUT
, 3 },
2456 { 0x17, HDA_INPUT
, 4 },
2461 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
2463 unsigned int def_conf
;
2464 unsigned char seqassoc
;
2466 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
2467 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
2468 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
2469 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
2470 && (seqassoc
== 0xf0 || seqassoc
== 0xff)) {
2471 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
2472 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
2478 static int vt1708_jack_detectect_get(struct snd_kcontrol
*kcontrol
,
2479 struct snd_ctl_elem_value
*ucontrol
)
2481 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2482 struct via_spec
*spec
= codec
->spec
;
2484 if (spec
->codec_type
!= VT1708
)
2486 spec
->vt1708_jack_detectect
=
2487 !((snd_hda_codec_read(codec
, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2488 ucontrol
->value
.integer
.value
[0] = spec
->vt1708_jack_detectect
;
2492 static int vt1708_jack_detectect_put(struct snd_kcontrol
*kcontrol
,
2493 struct snd_ctl_elem_value
*ucontrol
)
2495 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2496 struct via_spec
*spec
= codec
->spec
;
2499 if (spec
->codec_type
!= VT1708
)
2501 spec
->vt1708_jack_detectect
= ucontrol
->value
.integer
.value
[0];
2502 change
= (0x1 & (snd_hda_codec_read(codec
, 0x1, 0, 0xf84, 0) >> 8))
2503 == !spec
->vt1708_jack_detectect
;
2504 if (spec
->vt1708_jack_detectect
) {
2505 mute_aa_path(codec
, 1);
2506 notify_aa_path_ctls(codec
);
2511 static struct snd_kcontrol_new vt1708_jack_detectect
[] = {
2513 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2514 .name
= "Jack Detect",
2516 .info
= snd_ctl_boolean_mono_info
,
2517 .get
= vt1708_jack_detectect_get
,
2518 .put
= vt1708_jack_detectect_put
,
2523 static int vt1708_parse_auto_config(struct hda_codec
*codec
)
2525 struct via_spec
*spec
= codec
->spec
;
2528 /* Add HP and CD pin config connect bit re-config action */
2529 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
2530 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
2532 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2535 err
= vt1708_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2538 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2539 return 0; /* can't find valid BIOS pin config */
2541 err
= vt1708_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2544 err
= vt1708_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2547 err
= vt1708_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2550 /* add jack detect on/off control */
2551 err
= snd_hda_add_new_ctls(codec
, vt1708_jack_detectect
);
2555 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2557 if (spec
->autocfg
.dig_outs
)
2558 spec
->multiout
.dig_out_nid
= VT1708_DIGOUT_NID
;
2559 spec
->dig_in_pin
= VT1708_DIGIN_PIN
;
2560 if (spec
->autocfg
.dig_in_pin
)
2561 spec
->dig_in_nid
= VT1708_DIGIN_NID
;
2563 if (spec
->kctls
.list
)
2564 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2566 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_volume_init_verbs
;
2568 spec
->input_mux
= &spec
->private_imux
[0];
2571 via_hp_build(codec
);
2573 via_smart51_build(spec
);
2577 /* init callback for auto-configuration model -- overriding the default init */
2578 static int via_auto_init(struct hda_codec
*codec
)
2580 struct via_spec
*spec
= codec
->spec
;
2583 via_auto_init_multi_out(codec
);
2584 via_auto_init_hp_out(codec
);
2585 via_auto_init_analog_input(codec
);
2586 if (spec
->codec_type
== VT2002P
|| spec
->codec_type
== VT1812
) {
2587 via_hp_bind_automute(codec
);
2589 via_hp_automute(codec
);
2590 via_speaker_automute(codec
);
2596 static void vt1708_update_hp_jack_state(struct work_struct
*work
)
2598 struct via_spec
*spec
= container_of(work
, struct via_spec
,
2599 vt1708_hp_work
.work
);
2600 if (spec
->codec_type
!= VT1708
)
2602 /* if jack state toggled */
2603 if (spec
->vt1708_hp_present
2604 != snd_hda_jack_detect(spec
->codec
, spec
->autocfg
.hp_pins
[0])) {
2605 spec
->vt1708_hp_present
^= 1;
2606 via_hp_automute(spec
->codec
);
2608 vt1708_start_hp_work(spec
);
2611 static int get_mux_nids(struct hda_codec
*codec
)
2613 struct via_spec
*spec
= codec
->spec
;
2614 hda_nid_t nid
, conn
[8];
2618 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
2619 nid
= spec
->adc_nids
[i
];
2621 type
= get_wcaps_type(get_wcaps(codec
, nid
));
2622 if (type
== AC_WID_PIN
)
2624 n
= snd_hda_get_connections(codec
, nid
, conn
,
2629 spec
->mux_nids
[i
] = nid
;
2638 static int patch_vt1708(struct hda_codec
*codec
)
2640 struct via_spec
*spec
;
2643 /* create a codec specific record */
2644 spec
= via_new_spec(codec
);
2648 /* automatic parse from the BIOS config */
2649 err
= vt1708_parse_auto_config(codec
);
2654 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2655 "from BIOS. Using genenic mode...\n");
2659 spec
->stream_name_analog
= "VT1708 Analog";
2660 spec
->stream_analog_playback
= &vt1708_pcm_analog_playback
;
2661 /* disable 32bit format on VT1708 */
2662 if (codec
->vendor_id
== 0x11061708)
2663 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
2664 spec
->stream_analog_capture
= &vt1708_pcm_analog_capture
;
2666 spec
->stream_name_digital
= "VT1708 Digital";
2667 spec
->stream_digital_playback
= &vt1708_pcm_digital_playback
;
2668 spec
->stream_digital_capture
= &vt1708_pcm_digital_capture
;
2671 if (!spec
->adc_nids
&& spec
->input_mux
) {
2672 spec
->adc_nids
= vt1708_adc_nids
;
2673 spec
->num_adc_nids
= ARRAY_SIZE(vt1708_adc_nids
);
2674 get_mux_nids(codec
);
2675 spec
->mixers
[spec
->num_mixers
] = vt1708_capture_mixer
;
2679 codec
->patch_ops
= via_patch_ops
;
2681 codec
->patch_ops
.init
= via_auto_init
;
2682 #ifdef CONFIG_SND_HDA_POWER_SAVE
2683 spec
->loopback
.amplist
= vt1708_loopbacks
;
2685 INIT_DELAYED_WORK(&spec
->vt1708_hp_work
, vt1708_update_hp_jack_state
);
2689 /* capture mixer elements */
2690 static struct snd_kcontrol_new vt1709_capture_mixer
[] = {
2691 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT
),
2692 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT
),
2693 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT
),
2694 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT
),
2695 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT
),
2696 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT
),
2698 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2699 /* The multiple "Capture Source" controls confuse alsamixer
2700 * So call somewhat different..
2702 /* .name = "Capture Source", */
2703 .name
= "Input Source",
2705 .info
= via_mux_enum_info
,
2706 .get
= via_mux_enum_get
,
2707 .put
= via_mux_enum_put
,
2712 static struct hda_verb vt1709_uniwill_init_verbs
[] = {
2713 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
,
2714 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
2719 * generic initialization of ADC, input mixers and output mixers
2721 static struct hda_verb vt1709_10ch_volume_init_verbs
[] = {
2723 * Unmute ADC0-2 and set the default input to mic-in
2725 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2726 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2727 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2730 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2733 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2734 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2735 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2736 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2737 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2738 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2741 * Set up output selector (0x1a, 0x1b, 0x29)
2743 /* set vol=0 to output mixers */
2744 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2745 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2746 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2749 * Unmute PW3 and PW4
2751 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2752 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2754 /* Set input of PW4 as MW0 */
2755 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
2756 /* PW9 Output enable */
2757 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2761 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback
= {
2765 .nid
= 0x10, /* NID to query formats and rates */
2767 .open
= via_playback_pcm_open
,
2768 .prepare
= via_playback_multi_pcm_prepare
,
2769 .cleanup
= via_playback_multi_pcm_cleanup
,
2773 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback
= {
2777 .nid
= 0x10, /* NID to query formats and rates */
2779 .open
= via_playback_pcm_open
,
2780 .prepare
= via_playback_multi_pcm_prepare
,
2781 .cleanup
= via_playback_multi_pcm_cleanup
,
2785 static struct hda_pcm_stream vt1709_pcm_analog_capture
= {
2789 .nid
= 0x14, /* NID to query formats and rates */
2791 .prepare
= via_capture_pcm_prepare
,
2792 .cleanup
= via_capture_pcm_cleanup
2796 static struct hda_pcm_stream vt1709_pcm_digital_playback
= {
2800 /* NID is set in via_build_pcms */
2802 .open
= via_dig_playback_pcm_open
,
2803 .close
= via_dig_playback_pcm_close
2807 static struct hda_pcm_stream vt1709_pcm_digital_capture
= {
2813 static int vt1709_auto_fill_dac_nids(struct via_spec
*spec
,
2814 const struct auto_pin_cfg
*cfg
)
2819 if (cfg
->line_outs
== 4) /* 10 channels */
2820 spec
->multiout
.num_dacs
= cfg
->line_outs
+1; /* AOW0~AOW4 */
2821 else if (cfg
->line_outs
== 3) /* 6 channels */
2822 spec
->multiout
.num_dacs
= cfg
->line_outs
; /* AOW0~AOW2 */
2824 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2826 if (cfg
->line_outs
== 4) { /* 10 channels */
2827 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2828 nid
= cfg
->line_out_pins
[i
];
2830 /* config dac list */
2832 case AUTO_SEQ_FRONT
:
2834 spec
->multiout
.dac_nids
[i
] = 0x10;
2836 case AUTO_SEQ_CENLFE
:
2838 spec
->multiout
.dac_nids
[i
] = 0x12;
2840 case AUTO_SEQ_SURROUND
:
2842 spec
->multiout
.dac_nids
[i
] = 0x11;
2846 spec
->multiout
.dac_nids
[i
] = 0x27;
2853 spec
->multiout
.dac_nids
[cfg
->line_outs
] = 0x28; /* AOW4 */
2855 } else if (cfg
->line_outs
== 3) { /* 6 channels */
2856 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2857 nid
= cfg
->line_out_pins
[i
];
2859 /* config dac list */
2861 case AUTO_SEQ_FRONT
:
2863 spec
->multiout
.dac_nids
[i
] = 0x10;
2865 case AUTO_SEQ_CENLFE
:
2867 spec
->multiout
.dac_nids
[i
] = 0x12;
2869 case AUTO_SEQ_SURROUND
:
2871 spec
->multiout
.dac_nids
[i
] = 0x11;
2883 /* add playback controls from the parsed DAC table */
2884 static int vt1709_auto_create_multi_out_ctls(struct via_spec
*spec
,
2885 const struct auto_pin_cfg
*cfg
)
2888 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2889 hda_nid_t nid
, nid_vol
, nid_vols
[] = {0x18, 0x1a, 0x1b, 0x29};
2892 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2893 nid
= cfg
->line_out_pins
[i
];
2898 nid_vol
= nid_vols
[i
];
2900 if (i
== AUTO_SEQ_CENLFE
) {
2902 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2903 "Center Playback Volume",
2904 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2908 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2909 "LFE Playback Volume",
2910 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2914 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2915 "Center Playback Switch",
2916 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2920 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2921 "LFE Playback Switch",
2922 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2926 } else if (i
== AUTO_SEQ_FRONT
) {
2927 /* ADD control to mixer index 0 */
2928 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2929 "Master Front Playback Volume",
2930 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2934 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2935 "Master Front Playback Switch",
2936 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2941 /* add control to PW3 */
2942 sprintf(name
, "%s Playback Volume", chname
[i
]);
2943 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2944 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2948 sprintf(name
, "%s Playback Switch", chname
[i
]);
2949 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2950 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2954 } else if (i
== AUTO_SEQ_SURROUND
) {
2955 sprintf(name
, "%s Playback Volume", chname
[i
]);
2956 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2957 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2961 sprintf(name
, "%s Playback Switch", chname
[i
]);
2962 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2963 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2967 } else if (i
== AUTO_SEQ_SIDE
) {
2968 sprintf(name
, "%s Playback Volume", chname
[i
]);
2969 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2970 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2974 sprintf(name
, "%s Playback Switch", chname
[i
]);
2975 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2976 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2986 static int vt1709_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2993 if (spec
->multiout
.num_dacs
== 5) /* 10 channels */
2994 spec
->multiout
.hp_nid
= VT1709_HP_DAC_NID
;
2995 else if (spec
->multiout
.num_dacs
== 3) /* 6 channels */
2996 spec
->multiout
.hp_nid
= 0;
2997 spec
->hp_independent_mode_index
= 1;
2999 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3000 "Headphone Playback Volume",
3001 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3004 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3005 "Headphone Playback Switch",
3006 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3013 /* create playback/capture controls for input pins */
3014 static int vt1709_auto_create_analog_input_ctls(struct via_spec
*spec
,
3015 const struct auto_pin_cfg
*cfg
)
3017 static char *labels
[] = {
3018 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3020 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3021 int i
, err
, idx
= 0;
3023 /* for internal loopback recording select */
3024 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3025 imux
->items
[imux
->num_items
].index
= idx
;
3028 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3029 if (!cfg
->input_pins
[i
])
3032 switch (cfg
->input_pins
[i
]) {
3033 case 0x1d: /* Mic */
3037 case 0x1e: /* Line In */
3041 case 0x21: /* Front Mic */
3049 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x18);
3052 imux
->items
[imux
->num_items
].label
= labels
[i
];
3053 imux
->items
[imux
->num_items
].index
= idx
;
3059 static int vt1709_parse_auto_config(struct hda_codec
*codec
)
3061 struct via_spec
*spec
= codec
->spec
;
3064 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3067 err
= vt1709_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3070 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3071 return 0; /* can't find valid BIOS pin config */
3073 err
= vt1709_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
3076 err
= vt1709_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3079 err
= vt1709_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3083 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3085 if (spec
->autocfg
.dig_outs
)
3086 spec
->multiout
.dig_out_nid
= VT1709_DIGOUT_NID
;
3087 spec
->dig_in_pin
= VT1709_DIGIN_PIN
;
3088 if (spec
->autocfg
.dig_in_pin
)
3089 spec
->dig_in_nid
= VT1709_DIGIN_NID
;
3091 if (spec
->kctls
.list
)
3092 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3094 spec
->input_mux
= &spec
->private_imux
[0];
3097 via_hp_build(codec
);
3099 via_smart51_build(spec
);
3103 #ifdef CONFIG_SND_HDA_POWER_SAVE
3104 static struct hda_amp_list vt1709_loopbacks
[] = {
3105 { 0x18, HDA_INPUT
, 1 },
3106 { 0x18, HDA_INPUT
, 2 },
3107 { 0x18, HDA_INPUT
, 3 },
3108 { 0x18, HDA_INPUT
, 4 },
3113 static int patch_vt1709_10ch(struct hda_codec
*codec
)
3115 struct via_spec
*spec
;
3118 /* create a codec specific record */
3119 spec
= via_new_spec(codec
);
3123 err
= vt1709_parse_auto_config(codec
);
3128 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
3129 "Using genenic mode...\n");
3132 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_10ch_volume_init_verbs
;
3133 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
3135 spec
->stream_name_analog
= "VT1709 Analog";
3136 spec
->stream_analog_playback
= &vt1709_10ch_pcm_analog_playback
;
3137 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
3139 spec
->stream_name_digital
= "VT1709 Digital";
3140 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
3141 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
3144 if (!spec
->adc_nids
&& spec
->input_mux
) {
3145 spec
->adc_nids
= vt1709_adc_nids
;
3146 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
3147 get_mux_nids(codec
);
3148 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
3152 codec
->patch_ops
= via_patch_ops
;
3154 codec
->patch_ops
.init
= via_auto_init
;
3155 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3156 #ifdef CONFIG_SND_HDA_POWER_SAVE
3157 spec
->loopback
.amplist
= vt1709_loopbacks
;
3163 * generic initialization of ADC, input mixers and output mixers
3165 static struct hda_verb vt1709_6ch_volume_init_verbs
[] = {
3167 * Unmute ADC0-2 and set the default input to mic-in
3169 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3170 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3171 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3174 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3177 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3178 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3179 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3180 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3181 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3182 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3185 * Set up output selector (0x1a, 0x1b, 0x29)
3187 /* set vol=0 to output mixers */
3188 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3189 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3190 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3193 * Unmute PW3 and PW4
3195 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3196 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3198 /* Set input of PW4 as MW0 */
3199 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
3200 /* PW9 Output enable */
3201 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3205 static int patch_vt1709_6ch(struct hda_codec
*codec
)
3207 struct via_spec
*spec
;
3210 /* create a codec specific record */
3211 spec
= via_new_spec(codec
);
3215 err
= vt1709_parse_auto_config(codec
);
3220 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
3221 "Using genenic mode...\n");
3224 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_6ch_volume_init_verbs
;
3225 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
3227 spec
->stream_name_analog
= "VT1709 Analog";
3228 spec
->stream_analog_playback
= &vt1709_6ch_pcm_analog_playback
;
3229 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
3231 spec
->stream_name_digital
= "VT1709 Digital";
3232 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
3233 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
3236 if (!spec
->adc_nids
&& spec
->input_mux
) {
3237 spec
->adc_nids
= vt1709_adc_nids
;
3238 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
3239 get_mux_nids(codec
);
3240 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
3244 codec
->patch_ops
= via_patch_ops
;
3246 codec
->patch_ops
.init
= via_auto_init
;
3247 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3248 #ifdef CONFIG_SND_HDA_POWER_SAVE
3249 spec
->loopback
.amplist
= vt1709_loopbacks
;
3254 /* capture mixer elements */
3255 static struct snd_kcontrol_new vt1708B_capture_mixer
[] = {
3256 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
3257 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
3258 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
3259 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
3261 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3262 /* The multiple "Capture Source" controls confuse alsamixer
3263 * So call somewhat different..
3265 /* .name = "Capture Source", */
3266 .name
= "Input Source",
3268 .info
= via_mux_enum_info
,
3269 .get
= via_mux_enum_get
,
3270 .put
= via_mux_enum_put
,
3275 * generic initialization of ADC, input mixers and output mixers
3277 static struct hda_verb vt1708B_8ch_volume_init_verbs
[] = {
3279 * Unmute ADC0-1 and set the default input to mic-in
3281 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3282 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3285 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3288 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3289 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3290 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3291 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3292 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3293 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3296 * Set up output mixers
3298 /* set vol=0 to output mixers */
3299 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3300 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3301 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3303 /* Setup default input to PW4 */
3304 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0},
3305 /* PW9 Output enable */
3306 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3307 /* PW10 Input enable */
3308 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
3312 static struct hda_verb vt1708B_4ch_volume_init_verbs
[] = {
3314 * Unmute ADC0-1 and set the default input to mic-in
3316 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3317 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3320 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3323 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3324 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3325 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3326 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3327 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3328 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3331 * Set up output mixers
3333 /* set vol=0 to output mixers */
3334 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3335 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3336 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3338 /* Setup default input of PW4 to MW0 */
3339 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
3340 /* PW9 Output enable */
3341 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3342 /* PW10 Input enable */
3343 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
3347 static struct hda_verb vt1708B_uniwill_init_verbs
[] = {
3348 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
3349 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
3350 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3351 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3352 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3353 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3354 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3355 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3356 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3360 static int via_pcm_open_close(struct hda_pcm_stream
*hinfo
,
3361 struct hda_codec
*codec
,
3362 struct snd_pcm_substream
*substream
)
3364 int idle
= substream
->pstr
->substream_opened
== 1
3365 && substream
->ref_count
== 0;
3367 analog_low_current_mode(codec
, idle
);
3371 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback
= {
3375 .nid
= 0x10, /* NID to query formats and rates */
3377 .open
= via_playback_pcm_open
,
3378 .prepare
= via_playback_multi_pcm_prepare
,
3379 .cleanup
= via_playback_multi_pcm_cleanup
,
3380 .close
= via_pcm_open_close
3384 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback
= {
3388 .nid
= 0x10, /* NID to query formats and rates */
3390 .open
= via_playback_pcm_open
,
3391 .prepare
= via_playback_multi_pcm_prepare
,
3392 .cleanup
= via_playback_multi_pcm_cleanup
3396 static struct hda_pcm_stream vt1708B_pcm_analog_capture
= {
3400 .nid
= 0x13, /* NID to query formats and rates */
3402 .open
= via_pcm_open_close
,
3403 .prepare
= via_capture_pcm_prepare
,
3404 .cleanup
= via_capture_pcm_cleanup
,
3405 .close
= via_pcm_open_close
3409 static struct hda_pcm_stream vt1708B_pcm_digital_playback
= {
3413 /* NID is set in via_build_pcms */
3415 .open
= via_dig_playback_pcm_open
,
3416 .close
= via_dig_playback_pcm_close
,
3417 .prepare
= via_dig_playback_pcm_prepare
,
3418 .cleanup
= via_dig_playback_pcm_cleanup
3422 static struct hda_pcm_stream vt1708B_pcm_digital_capture
= {
3428 /* fill in the dac_nids table from the parsed pin configuration */
3429 static int vt1708B_auto_fill_dac_nids(struct via_spec
*spec
,
3430 const struct auto_pin_cfg
*cfg
)
3435 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3437 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3439 for (i
= 0; i
< 4; i
++) {
3440 nid
= cfg
->line_out_pins
[i
];
3442 /* config dac list */
3444 case AUTO_SEQ_FRONT
:
3445 spec
->multiout
.dac_nids
[i
] = 0x10;
3447 case AUTO_SEQ_CENLFE
:
3448 spec
->multiout
.dac_nids
[i
] = 0x24;
3450 case AUTO_SEQ_SURROUND
:
3451 spec
->multiout
.dac_nids
[i
] = 0x11;
3454 spec
->multiout
.dac_nids
[i
] = 0x25;
3463 /* add playback controls from the parsed DAC table */
3464 static int vt1708B_auto_create_multi_out_ctls(struct via_spec
*spec
,
3465 const struct auto_pin_cfg
*cfg
)
3468 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
3469 hda_nid_t nid_vols
[] = {0x16, 0x18, 0x26, 0x27};
3470 hda_nid_t nid
, nid_vol
= 0;
3473 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
3474 nid
= cfg
->line_out_pins
[i
];
3479 nid_vol
= nid_vols
[i
];
3481 if (i
== AUTO_SEQ_CENLFE
) {
3483 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3484 "Center Playback Volume",
3485 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3489 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3490 "LFE Playback Volume",
3491 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3495 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3496 "Center Playback Switch",
3497 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3501 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3502 "LFE Playback Switch",
3503 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3507 } else if (i
== AUTO_SEQ_FRONT
) {
3508 /* add control to mixer index 0 */
3509 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3510 "Master Front Playback Volume",
3511 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3515 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3516 "Master Front Playback Switch",
3517 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3522 /* add control to PW3 */
3523 sprintf(name
, "%s Playback Volume", chname
[i
]);
3524 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3525 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
3529 sprintf(name
, "%s Playback Switch", chname
[i
]);
3530 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3531 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
3536 sprintf(name
, "%s Playback Volume", chname
[i
]);
3537 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3538 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3542 sprintf(name
, "%s Playback Switch", chname
[i
]);
3543 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3544 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3554 static int vt1708B_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3561 spec
->multiout
.hp_nid
= VT1708B_HP_NID
; /* AOW3 */
3562 spec
->hp_independent_mode_index
= 1;
3564 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3565 "Headphone Playback Volume",
3566 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3569 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3570 "Headphone Playback Switch",
3571 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3575 create_hp_imux(spec
);
3580 /* create playback/capture controls for input pins */
3581 static int vt1708B_auto_create_analog_input_ctls(struct via_spec
*spec
,
3582 const struct auto_pin_cfg
*cfg
)
3584 static char *labels
[] = {
3585 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3587 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3588 int i
, err
, idx
= 0;
3590 /* for internal loopback recording select */
3591 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3592 imux
->items
[imux
->num_items
].index
= idx
;
3595 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3596 if (!cfg
->input_pins
[i
])
3599 switch (cfg
->input_pins
[i
]) {
3600 case 0x1a: /* Mic */
3604 case 0x1b: /* Line In */
3608 case 0x1e: /* Front Mic */
3616 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
3619 imux
->items
[imux
->num_items
].label
= labels
[i
];
3620 imux
->items
[imux
->num_items
].index
= idx
;
3626 static int vt1708B_parse_auto_config(struct hda_codec
*codec
)
3628 struct via_spec
*spec
= codec
->spec
;
3631 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3634 err
= vt1708B_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3637 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3638 return 0; /* can't find valid BIOS pin config */
3640 err
= vt1708B_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
3643 err
= vt1708B_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3646 err
= vt1708B_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3650 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3652 if (spec
->autocfg
.dig_outs
)
3653 spec
->multiout
.dig_out_nid
= VT1708B_DIGOUT_NID
;
3654 spec
->dig_in_pin
= VT1708B_DIGIN_PIN
;
3655 if (spec
->autocfg
.dig_in_pin
)
3656 spec
->dig_in_nid
= VT1708B_DIGIN_NID
;
3658 if (spec
->kctls
.list
)
3659 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3661 spec
->input_mux
= &spec
->private_imux
[0];
3664 via_hp_build(codec
);
3666 via_smart51_build(spec
);
3670 #ifdef CONFIG_SND_HDA_POWER_SAVE
3671 static struct hda_amp_list vt1708B_loopbacks
[] = {
3672 { 0x16, HDA_INPUT
, 1 },
3673 { 0x16, HDA_INPUT
, 2 },
3674 { 0x16, HDA_INPUT
, 3 },
3675 { 0x16, HDA_INPUT
, 4 },
3679 static int patch_vt1708S(struct hda_codec
*codec
);
3680 static int patch_vt1708B_8ch(struct hda_codec
*codec
)
3682 struct via_spec
*spec
;
3685 if (get_codec_type(codec
) == VT1708BCE
)
3686 return patch_vt1708S(codec
);
3687 /* create a codec specific record */
3688 spec
= via_new_spec(codec
);
3692 /* automatic parse from the BIOS config */
3693 err
= vt1708B_parse_auto_config(codec
);
3698 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3699 "from BIOS. Using genenic mode...\n");
3702 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_8ch_volume_init_verbs
;
3703 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
3705 spec
->stream_name_analog
= "VT1708B Analog";
3706 spec
->stream_analog_playback
= &vt1708B_8ch_pcm_analog_playback
;
3707 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
3709 spec
->stream_name_digital
= "VT1708B Digital";
3710 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
3711 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
3713 if (!spec
->adc_nids
&& spec
->input_mux
) {
3714 spec
->adc_nids
= vt1708B_adc_nids
;
3715 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
3716 get_mux_nids(codec
);
3717 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
3721 codec
->patch_ops
= via_patch_ops
;
3723 codec
->patch_ops
.init
= via_auto_init
;
3724 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3725 #ifdef CONFIG_SND_HDA_POWER_SAVE
3726 spec
->loopback
.amplist
= vt1708B_loopbacks
;
3732 static int patch_vt1708B_4ch(struct hda_codec
*codec
)
3734 struct via_spec
*spec
;
3737 /* create a codec specific record */
3738 spec
= via_new_spec(codec
);
3742 /* automatic parse from the BIOS config */
3743 err
= vt1708B_parse_auto_config(codec
);
3748 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3749 "from BIOS. Using genenic mode...\n");
3752 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_4ch_volume_init_verbs
;
3753 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
3755 spec
->stream_name_analog
= "VT1708B Analog";
3756 spec
->stream_analog_playback
= &vt1708B_4ch_pcm_analog_playback
;
3757 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
3759 spec
->stream_name_digital
= "VT1708B Digital";
3760 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
3761 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
3763 if (!spec
->adc_nids
&& spec
->input_mux
) {
3764 spec
->adc_nids
= vt1708B_adc_nids
;
3765 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
3766 get_mux_nids(codec
);
3767 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
3771 codec
->patch_ops
= via_patch_ops
;
3773 codec
->patch_ops
.init
= via_auto_init
;
3774 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3775 #ifdef CONFIG_SND_HDA_POWER_SAVE
3776 spec
->loopback
.amplist
= vt1708B_loopbacks
;
3782 /* Patch for VT1708S */
3784 /* capture mixer elements */
3785 static struct snd_kcontrol_new vt1708S_capture_mixer
[] = {
3786 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
3787 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
3788 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
3789 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
3790 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT
),
3791 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3794 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3795 /* The multiple "Capture Source" controls confuse alsamixer
3796 * So call somewhat different..
3798 /* .name = "Capture Source", */
3799 .name
= "Input Source",
3801 .info
= via_mux_enum_info
,
3802 .get
= via_mux_enum_get
,
3803 .put
= via_mux_enum_put
,
3808 static struct hda_verb vt1708S_volume_init_verbs
[] = {
3809 /* Unmute ADC0-1 and set the default input to mic-in */
3810 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3811 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3813 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3814 * analog-loopback mixer widget */
3815 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3816 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3817 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3818 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3819 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3820 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3822 /* Setup default input of PW4 to MW0 */
3823 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
3824 /* PW9, PW10 Output enable */
3825 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3826 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3827 /* Enable Mic Boost Volume backdoor */
3829 /* don't bybass mixer */
3834 static struct hda_verb vt1708S_uniwill_init_verbs
[] = {
3835 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
3836 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
3837 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3838 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3839 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3840 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3841 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3842 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3843 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3847 static struct hda_pcm_stream vt1708S_pcm_analog_playback
= {
3851 .nid
= 0x10, /* NID to query formats and rates */
3853 .open
= via_playback_pcm_open
,
3854 .prepare
= via_playback_multi_pcm_prepare
,
3855 .cleanup
= via_playback_multi_pcm_cleanup
,
3856 .close
= via_pcm_open_close
3860 static struct hda_pcm_stream vt1708S_pcm_analog_capture
= {
3864 .nid
= 0x13, /* NID to query formats and rates */
3866 .open
= via_pcm_open_close
,
3867 .prepare
= via_capture_pcm_prepare
,
3868 .cleanup
= via_capture_pcm_cleanup
,
3869 .close
= via_pcm_open_close
3873 static struct hda_pcm_stream vt1708S_pcm_digital_playback
= {
3877 /* NID is set in via_build_pcms */
3879 .open
= via_dig_playback_pcm_open
,
3880 .close
= via_dig_playback_pcm_close
,
3881 .prepare
= via_dig_playback_pcm_prepare
,
3882 .cleanup
= via_dig_playback_pcm_cleanup
3886 /* fill in the dac_nids table from the parsed pin configuration */
3887 static int vt1708S_auto_fill_dac_nids(struct via_spec
*spec
,
3888 const struct auto_pin_cfg
*cfg
)
3893 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3895 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3897 for (i
= 0; i
< 4; i
++) {
3898 nid
= cfg
->line_out_pins
[i
];
3900 /* config dac list */
3902 case AUTO_SEQ_FRONT
:
3903 spec
->multiout
.dac_nids
[i
] = 0x10;
3905 case AUTO_SEQ_CENLFE
:
3906 spec
->multiout
.dac_nids
[i
] = 0x24;
3908 case AUTO_SEQ_SURROUND
:
3909 spec
->multiout
.dac_nids
[i
] = 0x11;
3912 spec
->multiout
.dac_nids
[i
] = 0x25;
3921 /* add playback controls from the parsed DAC table */
3922 static int vt1708S_auto_create_multi_out_ctls(struct via_spec
*spec
,
3923 const struct auto_pin_cfg
*cfg
)
3926 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
3927 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x24, 0x25};
3928 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x26, 0x27};
3929 hda_nid_t nid
, nid_vol
, nid_mute
;
3932 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
3933 nid
= cfg
->line_out_pins
[i
];
3938 nid_vol
= nid_vols
[i
];
3939 nid_mute
= nid_mutes
[i
];
3941 if (i
== AUTO_SEQ_CENLFE
) {
3943 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3944 "Center Playback Volume",
3945 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3949 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3950 "LFE Playback Volume",
3951 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3955 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3956 "Center Playback Switch",
3957 HDA_COMPOSE_AMP_VAL(nid_mute
,
3962 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3963 "LFE Playback Switch",
3964 HDA_COMPOSE_AMP_VAL(nid_mute
,
3969 } else if (i
== AUTO_SEQ_FRONT
) {
3970 /* add control to mixer index 0 */
3971 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3972 "Master Front Playback Volume",
3973 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3977 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3978 "Master Front Playback Switch",
3979 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3985 sprintf(name
, "%s Playback Volume", chname
[i
]);
3986 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3987 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3991 sprintf(name
, "%s Playback Switch", chname
[i
]);
3992 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3993 HDA_COMPOSE_AMP_VAL(nid_mute
,
3999 sprintf(name
, "%s Playback Volume", chname
[i
]);
4000 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
4001 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
4005 sprintf(name
, "%s Playback Switch", chname
[i
]);
4006 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
4007 HDA_COMPOSE_AMP_VAL(nid_mute
,
4018 static int vt1708S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
4025 spec
->multiout
.hp_nid
= VT1708S_HP_NID
; /* AOW3 */
4026 spec
->hp_independent_mode_index
= 1;
4028 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4029 "Headphone Playback Volume",
4030 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
4034 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4035 "Headphone Playback Switch",
4036 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
4040 create_hp_imux(spec
);
4045 /* create playback/capture controls for input pins */
4046 static int vt1708S_auto_create_analog_input_ctls(struct via_spec
*spec
,
4047 const struct auto_pin_cfg
*cfg
)
4049 static char *labels
[] = {
4050 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4052 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
4053 int i
, err
, idx
= 0;
4055 /* for internal loopback recording select */
4056 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
4057 imux
->items
[imux
->num_items
].index
= 5;
4060 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
4061 if (!cfg
->input_pins
[i
])
4064 switch (cfg
->input_pins
[i
]) {
4065 case 0x1a: /* Mic */
4069 case 0x1b: /* Line In */
4073 case 0x1e: /* Front Mic */
4081 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
4084 imux
->items
[imux
->num_items
].label
= labels
[i
];
4085 imux
->items
[imux
->num_items
].index
= idx
-1;
4091 /* fill out digital output widgets; one for master and one for slave outputs */
4092 static void fill_dig_outs(struct hda_codec
*codec
)
4094 struct via_spec
*spec
= codec
->spec
;
4097 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
4101 nid
= spec
->autocfg
.dig_out_pins
[i
];
4104 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
4107 if (!spec
->multiout
.dig_out_nid
)
4108 spec
->multiout
.dig_out_nid
= nid
;
4110 spec
->slave_dig_outs
[0] = nid
;
4111 break; /* at most two dig outs */
4116 static int vt1708S_parse_auto_config(struct hda_codec
*codec
)
4118 struct via_spec
*spec
= codec
->spec
;
4121 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
4124 err
= vt1708S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
4127 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
4128 return 0; /* can't find valid BIOS pin config */
4130 err
= vt1708S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
4133 err
= vt1708S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
4136 err
= vt1708S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
4140 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4142 fill_dig_outs(codec
);
4144 if (spec
->kctls
.list
)
4145 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
4147 spec
->input_mux
= &spec
->private_imux
[0];
4150 via_hp_build(codec
);
4152 via_smart51_build(spec
);
4156 #ifdef CONFIG_SND_HDA_POWER_SAVE
4157 static struct hda_amp_list vt1708S_loopbacks
[] = {
4158 { 0x16, HDA_INPUT
, 1 },
4159 { 0x16, HDA_INPUT
, 2 },
4160 { 0x16, HDA_INPUT
, 3 },
4161 { 0x16, HDA_INPUT
, 4 },
4166 static void override_mic_boost(struct hda_codec
*codec
, hda_nid_t pin
,
4167 int offset
, int num_steps
, int step_size
)
4169 snd_hda_override_amp_caps(codec
, pin
, HDA_INPUT
,
4170 (offset
<< AC_AMPCAP_OFFSET_SHIFT
) |
4171 (num_steps
<< AC_AMPCAP_NUM_STEPS_SHIFT
) |
4172 (step_size
<< AC_AMPCAP_STEP_SIZE_SHIFT
) |
4173 (0 << AC_AMPCAP_MUTE_SHIFT
));
4176 static int patch_vt1708S(struct hda_codec
*codec
)
4178 struct via_spec
*spec
;
4181 /* create a codec specific record */
4182 spec
= via_new_spec(codec
);
4186 /* automatic parse from the BIOS config */
4187 err
= vt1708S_parse_auto_config(codec
);
4192 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
4193 "from BIOS. Using genenic mode...\n");
4196 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_volume_init_verbs
;
4197 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_uniwill_init_verbs
;
4199 if (codec
->vendor_id
== 0x11060440)
4200 spec
->stream_name_analog
= "VT1818S Analog";
4202 spec
->stream_name_analog
= "VT1708S Analog";
4203 spec
->stream_analog_playback
= &vt1708S_pcm_analog_playback
;
4204 spec
->stream_analog_capture
= &vt1708S_pcm_analog_capture
;
4206 if (codec
->vendor_id
== 0x11060440)
4207 spec
->stream_name_digital
= "VT1818S Digital";
4209 spec
->stream_name_digital
= "VT1708S Digital";
4210 spec
->stream_digital_playback
= &vt1708S_pcm_digital_playback
;
4212 if (!spec
->adc_nids
&& spec
->input_mux
) {
4213 spec
->adc_nids
= vt1708S_adc_nids
;
4214 spec
->num_adc_nids
= ARRAY_SIZE(vt1708S_adc_nids
);
4215 get_mux_nids(codec
);
4216 override_mic_boost(codec
, 0x1a, 0, 3, 40);
4217 override_mic_boost(codec
, 0x1e, 0, 3, 40);
4218 spec
->mixers
[spec
->num_mixers
] = vt1708S_capture_mixer
;
4222 codec
->patch_ops
= via_patch_ops
;
4224 codec
->patch_ops
.init
= via_auto_init
;
4225 codec
->patch_ops
.unsol_event
= via_unsol_event
;
4226 #ifdef CONFIG_SND_HDA_POWER_SAVE
4227 spec
->loopback
.amplist
= vt1708S_loopbacks
;
4230 /* correct names for VT1708BCE */
4231 if (get_codec_type(codec
) == VT1708BCE
) {
4232 kfree(codec
->chip_name
);
4233 codec
->chip_name
= kstrdup("VT1708BCE", GFP_KERNEL
);
4234 snprintf(codec
->bus
->card
->mixername
,
4235 sizeof(codec
->bus
->card
->mixername
),
4236 "%s %s", codec
->vendor_name
, codec
->chip_name
);
4237 spec
->stream_name_analog
= "VT1708BCE Analog";
4238 spec
->stream_name_digital
= "VT1708BCE Digital";
4243 /* Patch for VT1702 */
4245 /* capture mixer elements */
4246 static struct snd_kcontrol_new vt1702_capture_mixer
[] = {
4247 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT
),
4248 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT
),
4249 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT
),
4250 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT
),
4251 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT
),
4252 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT
),
4253 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4256 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
4257 /* The multiple "Capture Source" controls confuse alsamixer
4258 * So call somewhat different..
4260 /* .name = "Capture Source", */
4261 .name
= "Input Source",
4263 .info
= via_mux_enum_info
,
4264 .get
= via_mux_enum_get
,
4265 .put
= via_mux_enum_put
,
4270 static struct hda_verb vt1702_volume_init_verbs
[] = {
4272 * Unmute ADC0-1 and set the default input to mic-in
4274 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4275 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4276 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4279 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4282 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4283 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4284 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
4285 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
4286 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
4287 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
4289 /* Setup default input of PW4 to MW0 */
4290 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x1},
4291 /* PW6 PW7 Output enable */
4292 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
4293 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
4301 static struct hda_verb vt1702_uniwill_init_verbs
[] = {
4302 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE
,
4303 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
4304 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4305 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4306 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4307 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4311 static struct hda_pcm_stream vt1702_pcm_analog_playback
= {
4315 .nid
= 0x10, /* NID to query formats and rates */
4317 .open
= via_playback_pcm_open
,
4318 .prepare
= via_playback_multi_pcm_prepare
,
4319 .cleanup
= via_playback_multi_pcm_cleanup
,
4320 .close
= via_pcm_open_close
4324 static struct hda_pcm_stream vt1702_pcm_analog_capture
= {
4328 .nid
= 0x12, /* NID to query formats and rates */
4330 .open
= via_pcm_open_close
,
4331 .prepare
= via_capture_pcm_prepare
,
4332 .cleanup
= via_capture_pcm_cleanup
,
4333 .close
= via_pcm_open_close
4337 static struct hda_pcm_stream vt1702_pcm_digital_playback
= {
4341 /* NID is set in via_build_pcms */
4343 .open
= via_dig_playback_pcm_open
,
4344 .close
= via_dig_playback_pcm_close
,
4345 .prepare
= via_dig_playback_pcm_prepare
,
4346 .cleanup
= via_dig_playback_pcm_cleanup
4350 /* fill in the dac_nids table from the parsed pin configuration */
4351 static int vt1702_auto_fill_dac_nids(struct via_spec
*spec
,
4352 const struct auto_pin_cfg
*cfg
)
4354 spec
->multiout
.num_dacs
= 1;
4355 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
4357 if (cfg
->line_out_pins
[0]) {
4358 /* config dac list */
4359 spec
->multiout
.dac_nids
[0] = 0x10;
4365 /* add playback controls from the parsed DAC table */
4366 static int vt1702_auto_create_line_out_ctls(struct via_spec
*spec
,
4367 const struct auto_pin_cfg
*cfg
)
4371 if (!cfg
->line_out_pins
[0])
4374 /* add control to mixer index 0 */
4375 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4376 "Master Front Playback Volume",
4377 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
4380 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4381 "Master Front Playback Switch",
4382 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
4387 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4388 "Front Playback Volume",
4389 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
));
4392 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4393 "Front Playback Switch",
4394 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT
));
4401 static int vt1702_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
4404 struct hda_input_mux
*imux
;
4405 static const char *texts
[] = { "ON", "OFF", NULL
};
4408 spec
->multiout
.hp_nid
= 0x1D;
4409 spec
->hp_independent_mode_index
= 0;
4411 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4412 "Headphone Playback Volume",
4413 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT
));
4417 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4418 "Headphone Playback Switch",
4419 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
4423 imux
= &spec
->private_imux
[1];
4425 /* for hp mode select */
4427 while (texts
[i
] != NULL
) {
4428 imux
->items
[imux
->num_items
].label
= texts
[i
];
4429 imux
->items
[imux
->num_items
].index
= i
;
4434 spec
->hp_mux
= &spec
->private_imux
[1];
4438 /* create playback/capture controls for input pins */
4439 static int vt1702_auto_create_analog_input_ctls(struct via_spec
*spec
,
4440 const struct auto_pin_cfg
*cfg
)
4442 static char *labels
[] = {
4443 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4445 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
4446 int i
, err
, idx
= 0;
4448 /* for internal loopback recording select */
4449 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
4450 imux
->items
[imux
->num_items
].index
= 3;
4453 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
4454 if (!cfg
->input_pins
[i
])
4457 switch (cfg
->input_pins
[i
]) {
4458 case 0x14: /* Mic */
4462 case 0x15: /* Line In */
4466 case 0x18: /* Front Mic */
4470 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x1A);
4473 imux
->items
[imux
->num_items
].label
= labels
[i
];
4474 imux
->items
[imux
->num_items
].index
= idx
-1;
4480 static int vt1702_parse_auto_config(struct hda_codec
*codec
)
4482 struct via_spec
*spec
= codec
->spec
;
4485 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
4488 err
= vt1702_auto_fill_dac_nids(spec
, &spec
->autocfg
);
4491 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
4492 return 0; /* can't find valid BIOS pin config */
4494 err
= vt1702_auto_create_line_out_ctls(spec
, &spec
->autocfg
);
4497 err
= vt1702_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
4500 /* limit AA path volume to 0 dB */
4501 snd_hda_override_amp_caps(codec
, 0x1A, HDA_INPUT
,
4502 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
4503 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
4504 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
4505 (1 << AC_AMPCAP_MUTE_SHIFT
));
4506 err
= vt1702_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
4510 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4512 fill_dig_outs(codec
);
4514 if (spec
->kctls
.list
)
4515 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
4517 spec
->input_mux
= &spec
->private_imux
[0];
4520 via_hp_build(codec
);
4525 #ifdef CONFIG_SND_HDA_POWER_SAVE
4526 static struct hda_amp_list vt1702_loopbacks
[] = {
4527 { 0x1A, HDA_INPUT
, 1 },
4528 { 0x1A, HDA_INPUT
, 2 },
4529 { 0x1A, HDA_INPUT
, 3 },
4530 { 0x1A, HDA_INPUT
, 4 },
4535 static int patch_vt1702(struct hda_codec
*codec
)
4537 struct via_spec
*spec
;
4540 /* create a codec specific record */
4541 spec
= via_new_spec(codec
);
4545 /* automatic parse from the BIOS config */
4546 err
= vt1702_parse_auto_config(codec
);
4551 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
4552 "from BIOS. Using genenic mode...\n");
4555 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_volume_init_verbs
;
4556 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_uniwill_init_verbs
;
4558 spec
->stream_name_analog
= "VT1702 Analog";
4559 spec
->stream_analog_playback
= &vt1702_pcm_analog_playback
;
4560 spec
->stream_analog_capture
= &vt1702_pcm_analog_capture
;
4562 spec
->stream_name_digital
= "VT1702 Digital";
4563 spec
->stream_digital_playback
= &vt1702_pcm_digital_playback
;
4565 if (!spec
->adc_nids
&& spec
->input_mux
) {
4566 spec
->adc_nids
= vt1702_adc_nids
;
4567 spec
->num_adc_nids
= ARRAY_SIZE(vt1702_adc_nids
);
4568 get_mux_nids(codec
);
4569 spec
->mixers
[spec
->num_mixers
] = vt1702_capture_mixer
;
4573 codec
->patch_ops
= via_patch_ops
;
4575 codec
->patch_ops
.init
= via_auto_init
;
4576 codec
->patch_ops
.unsol_event
= via_unsol_event
;
4577 #ifdef CONFIG_SND_HDA_POWER_SAVE
4578 spec
->loopback
.amplist
= vt1702_loopbacks
;
4584 /* Patch for VT1718S */
4586 /* capture mixer elements */
4587 static struct snd_kcontrol_new vt1718S_capture_mixer
[] = {
4588 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT
),
4589 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT
),
4590 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT
),
4591 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT
),
4592 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT
),
4593 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4596 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
4597 /* The multiple "Capture Source" controls confuse alsamixer
4598 * So call somewhat different..
4600 .name
= "Input Source",
4602 .info
= via_mux_enum_info
,
4603 .get
= via_mux_enum_get
,
4604 .put
= via_mux_enum_put
,
4609 static struct hda_verb vt1718S_volume_init_verbs
[] = {
4611 * Unmute ADC0-1 and set the default input to mic-in
4613 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4614 {0x11, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4617 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4620 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4621 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
4622 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4623 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
4624 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
4625 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(5)},
4627 /* Setup default input of Front HP to MW9 */
4628 {0x28, AC_VERB_SET_CONNECT_SEL
, 0x1},
4629 /* PW9 PW10 Output enable */
4630 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_OUT_EN
},
4631 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_OUT_EN
},
4632 /* PW11 Input enable */
4633 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_IN_EN
},
4634 /* Enable Boost Volume backdoor */
4636 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4637 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4638 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4639 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4640 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4641 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4642 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
4643 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4644 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4645 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
4646 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4647 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4648 {0x34, AC_VERB_SET_CONNECT_SEL
, 0x2},
4649 {0x35, AC_VERB_SET_CONNECT_SEL
, 0x1},
4650 /* Unmute MW4's index 0 */
4651 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4656 static struct hda_verb vt1718S_uniwill_init_verbs
[] = {
4657 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE
,
4658 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
4659 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4660 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4661 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4662 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4663 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4664 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4665 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4669 static struct hda_pcm_stream vt1718S_pcm_analog_playback
= {
4673 .nid
= 0x8, /* NID to query formats and rates */
4675 .open
= via_playback_pcm_open
,
4676 .prepare
= via_playback_multi_pcm_prepare
,
4677 .cleanup
= via_playback_multi_pcm_cleanup
,
4678 .close
= via_pcm_open_close
,
4682 static struct hda_pcm_stream vt1718S_pcm_analog_capture
= {
4686 .nid
= 0x10, /* NID to query formats and rates */
4688 .open
= via_pcm_open_close
,
4689 .prepare
= via_capture_pcm_prepare
,
4690 .cleanup
= via_capture_pcm_cleanup
,
4691 .close
= via_pcm_open_close
,
4695 static struct hda_pcm_stream vt1718S_pcm_digital_playback
= {
4699 /* NID is set in via_build_pcms */
4701 .open
= via_dig_playback_pcm_open
,
4702 .close
= via_dig_playback_pcm_close
,
4703 .prepare
= via_dig_playback_pcm_prepare
,
4704 .cleanup
= via_dig_playback_pcm_cleanup
4708 static struct hda_pcm_stream vt1718S_pcm_digital_capture
= {
4714 /* fill in the dac_nids table from the parsed pin configuration */
4715 static int vt1718S_auto_fill_dac_nids(struct via_spec
*spec
,
4716 const struct auto_pin_cfg
*cfg
)
4721 spec
->multiout
.num_dacs
= cfg
->line_outs
;
4723 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
4725 for (i
= 0; i
< 4; i
++) {
4726 nid
= cfg
->line_out_pins
[i
];
4728 /* config dac list */
4730 case AUTO_SEQ_FRONT
:
4731 spec
->multiout
.dac_nids
[i
] = 0x8;
4733 case AUTO_SEQ_CENLFE
:
4734 spec
->multiout
.dac_nids
[i
] = 0xa;
4736 case AUTO_SEQ_SURROUND
:
4737 spec
->multiout
.dac_nids
[i
] = 0x9;
4740 spec
->multiout
.dac_nids
[i
] = 0xb;
4749 /* add playback controls from the parsed DAC table */
4750 static int vt1718S_auto_create_multi_out_ctls(struct via_spec
*spec
,
4751 const struct auto_pin_cfg
*cfg
)
4754 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
4755 hda_nid_t nid_vols
[] = {0x8, 0x9, 0xa, 0xb};
4756 hda_nid_t nid_mutes
[] = {0x24, 0x25, 0x26, 0x27};
4757 hda_nid_t nid
, nid_vol
, nid_mute
= 0;
4760 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
4761 nid
= cfg
->line_out_pins
[i
];
4765 nid_vol
= nid_vols
[i
];
4766 nid_mute
= nid_mutes
[i
];
4768 if (i
== AUTO_SEQ_CENLFE
) {
4770 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4771 "Center Playback Volume",
4772 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
4776 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4777 "LFE Playback Volume",
4778 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
4782 err
= via_add_control(
4783 spec
, VIA_CTL_WIDGET_MUTE
,
4784 "Center Playback Switch",
4785 HDA_COMPOSE_AMP_VAL(nid_mute
, 1, 0,
4789 err
= via_add_control(
4790 spec
, VIA_CTL_WIDGET_MUTE
,
4791 "LFE Playback Switch",
4792 HDA_COMPOSE_AMP_VAL(nid_mute
, 2, 0,
4796 } else if (i
== AUTO_SEQ_FRONT
) {
4798 sprintf(name
, "%s Playback Volume", chname
[i
]);
4799 err
= via_add_control(
4800 spec
, VIA_CTL_WIDGET_VOL
, name
,
4801 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0, HDA_OUTPUT
));
4804 sprintf(name
, "%s Playback Switch", chname
[i
]);
4805 err
= via_add_control(
4806 spec
, VIA_CTL_WIDGET_MUTE
, name
,
4807 HDA_COMPOSE_AMP_VAL(nid_mute
, 3, 0,
4812 sprintf(name
, "%s Playback Volume", chname
[i
]);
4813 err
= via_add_control(
4814 spec
, VIA_CTL_WIDGET_VOL
, name
,
4815 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0, HDA_OUTPUT
));
4818 sprintf(name
, "%s Playback Switch", chname
[i
]);
4819 err
= via_add_control(
4820 spec
, VIA_CTL_WIDGET_MUTE
, name
,
4821 HDA_COMPOSE_AMP_VAL(nid_mute
, 3, 0,
4830 static int vt1718S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
4837 spec
->multiout
.hp_nid
= 0xc; /* AOW4 */
4838 spec
->hp_independent_mode_index
= 1;
4840 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4841 "Headphone Playback Volume",
4842 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT
));
4846 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4847 "Headphone Playback Switch",
4848 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
4852 create_hp_imux(spec
);
4856 /* create playback/capture controls for input pins */
4857 static int vt1718S_auto_create_analog_input_ctls(struct via_spec
*spec
,
4858 const struct auto_pin_cfg
*cfg
)
4860 static char *labels
[] = {
4861 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4863 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
4864 int i
, err
, idx
= 0;
4866 /* for internal loopback recording select */
4867 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
4868 imux
->items
[imux
->num_items
].index
= 5;
4871 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
4872 if (!cfg
->input_pins
[i
])
4875 switch (cfg
->input_pins
[i
]) {
4876 case 0x2b: /* Mic */
4880 case 0x2a: /* Line In */
4884 case 0x29: /* Front Mic */
4892 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x21);
4895 imux
->items
[imux
->num_items
].label
= labels
[i
];
4896 imux
->items
[imux
->num_items
].index
= idx
;
4902 static int vt1718S_parse_auto_config(struct hda_codec
*codec
)
4904 struct via_spec
*spec
= codec
->spec
;
4907 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
4911 err
= vt1718S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
4914 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
4915 return 0; /* can't find valid BIOS pin config */
4917 err
= vt1718S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
4920 err
= vt1718S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
4923 err
= vt1718S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
4927 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4929 fill_dig_outs(codec
);
4931 if (spec
->autocfg
.dig_in_pin
&& codec
->vendor_id
== 0x11060428)
4932 spec
->dig_in_nid
= 0x13;
4934 if (spec
->kctls
.list
)
4935 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
4937 spec
->input_mux
= &spec
->private_imux
[0];
4940 via_hp_build(codec
);
4942 via_smart51_build(spec
);
4947 #ifdef CONFIG_SND_HDA_POWER_SAVE
4948 static struct hda_amp_list vt1718S_loopbacks
[] = {
4949 { 0x21, HDA_INPUT
, 1 },
4950 { 0x21, HDA_INPUT
, 2 },
4951 { 0x21, HDA_INPUT
, 3 },
4952 { 0x21, HDA_INPUT
, 4 },
4957 static int patch_vt1718S(struct hda_codec
*codec
)
4959 struct via_spec
*spec
;
4962 /* create a codec specific record */
4963 spec
= via_new_spec(codec
);
4967 /* automatic parse from the BIOS config */
4968 err
= vt1718S_parse_auto_config(codec
);
4973 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
4974 "from BIOS. Using genenic mode...\n");
4977 spec
->init_verbs
[spec
->num_iverbs
++] = vt1718S_volume_init_verbs
;
4978 spec
->init_verbs
[spec
->num_iverbs
++] = vt1718S_uniwill_init_verbs
;
4980 if (codec
->vendor_id
== 0x11060441)
4981 spec
->stream_name_analog
= "VT2020 Analog";
4982 else if (codec
->vendor_id
== 0x11064441)
4983 spec
->stream_name_analog
= "VT1828S Analog";
4985 spec
->stream_name_analog
= "VT1718S Analog";
4986 spec
->stream_analog_playback
= &vt1718S_pcm_analog_playback
;
4987 spec
->stream_analog_capture
= &vt1718S_pcm_analog_capture
;
4989 if (codec
->vendor_id
== 0x11060441)
4990 spec
->stream_name_digital
= "VT2020 Digital";
4991 else if (codec
->vendor_id
== 0x11064441)
4992 spec
->stream_name_digital
= "VT1828S Digital";
4994 spec
->stream_name_digital
= "VT1718S Digital";
4995 spec
->stream_digital_playback
= &vt1718S_pcm_digital_playback
;
4996 if (codec
->vendor_id
== 0x11060428 || codec
->vendor_id
== 0x11060441)
4997 spec
->stream_digital_capture
= &vt1718S_pcm_digital_capture
;
4999 if (!spec
->adc_nids
&& spec
->input_mux
) {
5000 spec
->adc_nids
= vt1718S_adc_nids
;
5001 spec
->num_adc_nids
= ARRAY_SIZE(vt1718S_adc_nids
);
5002 get_mux_nids(codec
);
5003 override_mic_boost(codec
, 0x2b, 0, 3, 40);
5004 override_mic_boost(codec
, 0x29, 0, 3, 40);
5005 spec
->mixers
[spec
->num_mixers
] = vt1718S_capture_mixer
;
5009 codec
->patch_ops
= via_patch_ops
;
5011 codec
->patch_ops
.init
= via_auto_init
;
5012 codec
->patch_ops
.unsol_event
= via_unsol_event
;
5014 #ifdef CONFIG_SND_HDA_POWER_SAVE
5015 spec
->loopback
.amplist
= vt1718S_loopbacks
;
5021 /* Patch for VT1716S */
5023 static int vt1716s_dmic_info(struct snd_kcontrol
*kcontrol
,
5024 struct snd_ctl_elem_info
*uinfo
)
5026 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
5028 uinfo
->value
.integer
.min
= 0;
5029 uinfo
->value
.integer
.max
= 1;
5033 static int vt1716s_dmic_get(struct snd_kcontrol
*kcontrol
,
5034 struct snd_ctl_elem_value
*ucontrol
)
5036 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5039 index
= snd_hda_codec_read(codec
, 0x26, 0,
5040 AC_VERB_GET_CONNECT_SEL
, 0);
5042 *ucontrol
->value
.integer
.value
= index
;
5047 static int vt1716s_dmic_put(struct snd_kcontrol
*kcontrol
,
5048 struct snd_ctl_elem_value
*ucontrol
)
5050 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
5051 struct via_spec
*spec
= codec
->spec
;
5052 int index
= *ucontrol
->value
.integer
.value
;
5054 snd_hda_codec_write(codec
, 0x26, 0,
5055 AC_VERB_SET_CONNECT_SEL
, index
);
5056 spec
->dmic_enabled
= index
;
5057 set_jack_power_state(codec
);
5062 /* capture mixer elements */
5063 static struct snd_kcontrol_new vt1716S_capture_mixer
[] = {
5064 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
5065 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
5066 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
5067 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
5068 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT
),
5069 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5072 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
5073 .name
= "Input Source",
5075 .info
= via_mux_enum_info
,
5076 .get
= via_mux_enum_get
,
5077 .put
= via_mux_enum_put
,
5082 static struct snd_kcontrol_new vt1716s_dmic_mixer
[] = {
5083 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT
),
5085 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
5086 .name
= "Digital Mic Capture Switch",
5087 .subdevice
= HDA_SUBDEV_NID_FLAG
| 0x26,
5089 .info
= vt1716s_dmic_info
,
5090 .get
= vt1716s_dmic_get
,
5091 .put
= vt1716s_dmic_put
,
5097 /* mono-out mixer elements */
5098 static struct snd_kcontrol_new vt1716S_mono_out_mixer
[] = {
5099 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT
),
5103 static struct hda_verb vt1716S_volume_init_verbs
[] = {
5105 * Unmute ADC0-1 and set the default input to mic-in
5107 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5108 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5111 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5114 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5115 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
5116 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5117 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
5118 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
5119 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
5121 /* MUX Indices: Stereo Mixer = 5 */
5122 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x5},
5124 /* Setup default input of PW4 to MW0 */
5125 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
5127 /* Setup default input of SW1 as MW0 */
5128 {0x18, AC_VERB_SET_CONNECT_SEL
, 0x1},
5130 /* Setup default input of SW4 as AOW0 */
5131 {0x28, AC_VERB_SET_CONNECT_SEL
, 0x1},
5133 /* PW9 PW10 Output enable */
5134 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
5135 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
5137 /* Unmute SW1, PW12 */
5138 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5139 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
5140 /* PW12 Output enable */
5141 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
5142 /* Enable Boost Volume backdoor */
5144 /* don't bybass mixer */
5146 /* Enable mono output */
5152 static struct hda_verb vt1716S_uniwill_init_verbs
[] = {
5153 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
5154 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
5155 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5156 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5157 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5158 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
,
5159 AC_USRSP_EN
| VIA_MONO_EVENT
| VIA_JACK_EVENT
},
5160 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5161 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5165 static struct hda_pcm_stream vt1716S_pcm_analog_playback
= {
5169 .nid
= 0x10, /* NID to query formats and rates */
5171 .open
= via_playback_pcm_open
,
5172 .prepare
= via_playback_multi_pcm_prepare
,
5173 .cleanup
= via_playback_multi_pcm_cleanup
,
5174 .close
= via_pcm_open_close
,
5178 static struct hda_pcm_stream vt1716S_pcm_analog_capture
= {
5182 .nid
= 0x13, /* NID to query formats and rates */
5184 .open
= via_pcm_open_close
,
5185 .prepare
= via_capture_pcm_prepare
,
5186 .cleanup
= via_capture_pcm_cleanup
,
5187 .close
= via_pcm_open_close
,
5191 static struct hda_pcm_stream vt1716S_pcm_digital_playback
= {
5195 /* NID is set in via_build_pcms */
5197 .open
= via_dig_playback_pcm_open
,
5198 .close
= via_dig_playback_pcm_close
,
5199 .prepare
= via_dig_playback_pcm_prepare
,
5200 .cleanup
= via_dig_playback_pcm_cleanup
5204 /* fill in the dac_nids table from the parsed pin configuration */
5205 static int vt1716S_auto_fill_dac_nids(struct via_spec
*spec
,
5206 const struct auto_pin_cfg
*cfg
)
5210 spec
->multiout
.num_dacs
= cfg
->line_outs
;
5212 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
5214 for (i
= 0; i
< 3; i
++) {
5215 nid
= cfg
->line_out_pins
[i
];
5217 /* config dac list */
5219 case AUTO_SEQ_FRONT
:
5220 spec
->multiout
.dac_nids
[i
] = 0x10;
5222 case AUTO_SEQ_CENLFE
:
5223 spec
->multiout
.dac_nids
[i
] = 0x25;
5225 case AUTO_SEQ_SURROUND
:
5226 spec
->multiout
.dac_nids
[i
] = 0x11;
5235 /* add playback controls from the parsed DAC table */
5236 static int vt1716S_auto_create_multi_out_ctls(struct via_spec
*spec
,
5237 const struct auto_pin_cfg
*cfg
)
5240 static const char *chname
[3] = { "Front", "Surround", "C/LFE" };
5241 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x25};
5242 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x27};
5243 hda_nid_t nid
, nid_vol
, nid_mute
;
5246 for (i
= 0; i
<= AUTO_SEQ_CENLFE
; i
++) {
5247 nid
= cfg
->line_out_pins
[i
];
5252 nid_vol
= nid_vols
[i
];
5253 nid_mute
= nid_mutes
[i
];
5255 if (i
== AUTO_SEQ_CENLFE
) {
5256 err
= via_add_control(
5257 spec
, VIA_CTL_WIDGET_VOL
,
5258 "Center Playback Volume",
5259 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0, HDA_OUTPUT
));
5262 err
= via_add_control(
5263 spec
, VIA_CTL_WIDGET_VOL
,
5264 "LFE Playback Volume",
5265 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0, HDA_OUTPUT
));
5268 err
= via_add_control(
5269 spec
, VIA_CTL_WIDGET_MUTE
,
5270 "Center Playback Switch",
5271 HDA_COMPOSE_AMP_VAL(nid_mute
, 1, 0,
5275 err
= via_add_control(
5276 spec
, VIA_CTL_WIDGET_MUTE
,
5277 "LFE Playback Switch",
5278 HDA_COMPOSE_AMP_VAL(nid_mute
, 2, 0,
5282 } else if (i
== AUTO_SEQ_FRONT
) {
5284 err
= via_add_control(
5285 spec
, VIA_CTL_WIDGET_VOL
,
5286 "Master Front Playback Volume",
5287 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT
));
5290 err
= via_add_control(
5291 spec
, VIA_CTL_WIDGET_MUTE
,
5292 "Master Front Playback Switch",
5293 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT
));
5297 sprintf(name
, "%s Playback Volume", chname
[i
]);
5298 err
= via_add_control(
5299 spec
, VIA_CTL_WIDGET_VOL
, name
,
5300 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0, HDA_OUTPUT
));
5303 sprintf(name
, "%s Playback Switch", chname
[i
]);
5304 err
= via_add_control(
5305 spec
, VIA_CTL_WIDGET_MUTE
, name
,
5306 HDA_COMPOSE_AMP_VAL(nid_mute
, 3, 0,
5311 sprintf(name
, "%s Playback Volume", chname
[i
]);
5312 err
= via_add_control(
5313 spec
, VIA_CTL_WIDGET_VOL
, name
,
5314 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0, HDA_OUTPUT
));
5317 sprintf(name
, "%s Playback Switch", chname
[i
]);
5318 err
= via_add_control(
5319 spec
, VIA_CTL_WIDGET_MUTE
, name
,
5320 HDA_COMPOSE_AMP_VAL(nid_mute
, 3, 0,
5329 static int vt1716S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
5336 spec
->multiout
.hp_nid
= 0x25; /* AOW3 */
5337 spec
->hp_independent_mode_index
= 1;
5339 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
5340 "Headphone Playback Volume",
5341 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
5345 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
5346 "Headphone Playback Switch",
5347 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
5351 create_hp_imux(spec
);
5355 /* create playback/capture controls for input pins */
5356 static int vt1716S_auto_create_analog_input_ctls(struct via_spec
*spec
,
5357 const struct auto_pin_cfg
*cfg
)
5359 static char *labels
[] = {
5360 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5362 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
5363 int i
, err
, idx
= 0;
5365 /* for internal loopback recording select */
5366 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
5367 imux
->items
[imux
->num_items
].index
= 5;
5370 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
5371 if (!cfg
->input_pins
[i
])
5374 switch (cfg
->input_pins
[i
]) {
5375 case 0x1a: /* Mic */
5379 case 0x1b: /* Line In */
5383 case 0x1e: /* Front Mic */
5391 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
5394 imux
->items
[imux
->num_items
].label
= labels
[i
];
5395 imux
->items
[imux
->num_items
].index
= idx
-1;
5401 static int vt1716S_parse_auto_config(struct hda_codec
*codec
)
5403 struct via_spec
*spec
= codec
->spec
;
5406 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
5409 err
= vt1716S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
5412 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
5413 return 0; /* can't find valid BIOS pin config */
5415 err
= vt1716S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
5418 err
= vt1716S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
5421 err
= vt1716S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
5425 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
5427 fill_dig_outs(codec
);
5429 if (spec
->kctls
.list
)
5430 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
5432 spec
->input_mux
= &spec
->private_imux
[0];
5435 via_hp_build(codec
);
5437 via_smart51_build(spec
);
5442 #ifdef CONFIG_SND_HDA_POWER_SAVE
5443 static struct hda_amp_list vt1716S_loopbacks
[] = {
5444 { 0x16, HDA_INPUT
, 1 },
5445 { 0x16, HDA_INPUT
, 2 },
5446 { 0x16, HDA_INPUT
, 3 },
5447 { 0x16, HDA_INPUT
, 4 },
5452 static int patch_vt1716S(struct hda_codec
*codec
)
5454 struct via_spec
*spec
;
5457 /* create a codec specific record */
5458 spec
= via_new_spec(codec
);
5462 /* automatic parse from the BIOS config */
5463 err
= vt1716S_parse_auto_config(codec
);
5468 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
5469 "from BIOS. Using genenic mode...\n");
5472 spec
->init_verbs
[spec
->num_iverbs
++] = vt1716S_volume_init_verbs
;
5473 spec
->init_verbs
[spec
->num_iverbs
++] = vt1716S_uniwill_init_verbs
;
5475 spec
->stream_name_analog
= "VT1716S Analog";
5476 spec
->stream_analog_playback
= &vt1716S_pcm_analog_playback
;
5477 spec
->stream_analog_capture
= &vt1716S_pcm_analog_capture
;
5479 spec
->stream_name_digital
= "VT1716S Digital";
5480 spec
->stream_digital_playback
= &vt1716S_pcm_digital_playback
;
5482 if (!spec
->adc_nids
&& spec
->input_mux
) {
5483 spec
->adc_nids
= vt1716S_adc_nids
;
5484 spec
->num_adc_nids
= ARRAY_SIZE(vt1716S_adc_nids
);
5485 get_mux_nids(codec
);
5486 override_mic_boost(codec
, 0x1a, 0, 3, 40);
5487 override_mic_boost(codec
, 0x1e, 0, 3, 40);
5488 spec
->mixers
[spec
->num_mixers
] = vt1716S_capture_mixer
;
5492 spec
->mixers
[spec
->num_mixers
] = vt1716s_dmic_mixer
;
5495 spec
->mixers
[spec
->num_mixers
++] = vt1716S_mono_out_mixer
;
5497 codec
->patch_ops
= via_patch_ops
;
5499 codec
->patch_ops
.init
= via_auto_init
;
5500 codec
->patch_ops
.unsol_event
= via_unsol_event
;
5502 #ifdef CONFIG_SND_HDA_POWER_SAVE
5503 spec
->loopback
.amplist
= vt1716S_loopbacks
;
5511 /* capture mixer elements */
5512 static struct snd_kcontrol_new vt2002P_capture_mixer
[] = {
5513 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT
),
5514 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT
),
5515 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT
),
5516 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT
),
5517 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT
),
5518 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5521 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
5522 /* The multiple "Capture Source" controls confuse alsamixer
5523 * So call somewhat different..
5525 /* .name = "Capture Source", */
5526 .name
= "Input Source",
5528 .info
= via_mux_enum_info
,
5529 .get
= via_mux_enum_get
,
5530 .put
= via_mux_enum_put
,
5535 static struct hda_verb vt2002P_volume_init_verbs
[] = {
5537 * Unmute ADC0-1 and set the default input to mic-in
5539 {0x8, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5540 {0x9, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5543 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5546 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5547 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
5548 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5549 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
5550 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
5551 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
5553 /* MUX Indices: Mic = 0 */
5554 {0x1e, AC_VERB_SET_CONNECT_SEL
, 0},
5555 {0x1f, AC_VERB_SET_CONNECT_SEL
, 0},
5557 /* PW9 Output enable */
5558 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_OUT_EN
},
5560 /* Enable Boost Volume backdoor */
5563 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5564 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5565 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5566 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5567 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5568 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5569 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5570 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5571 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5573 /* set MUX0/1/4/8 = 0 (AOW0) */
5574 {0x34, AC_VERB_SET_CONNECT_SEL
, 0},
5575 {0x35, AC_VERB_SET_CONNECT_SEL
, 0},
5576 {0x37, AC_VERB_SET_CONNECT_SEL
, 0},
5577 {0x3b, AC_VERB_SET_CONNECT_SEL
, 0},
5579 /* set PW0 index=0 (MW0) */
5580 {0x24, AC_VERB_SET_CONNECT_SEL
, 0},
5582 /* Enable AOW0 to MW9 */
5588 static struct hda_verb vt2002P_uniwill_init_verbs
[] = {
5589 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE
,
5590 AC_USRSP_EN
| VIA_JACK_EVENT
| VIA_BIND_HP_EVENT
},
5591 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE
,
5592 AC_USRSP_EN
| VIA_JACK_EVENT
| VIA_BIND_HP_EVENT
},
5593 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5594 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5595 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5599 static struct hda_pcm_stream vt2002P_pcm_analog_playback
= {
5603 .nid
= 0x8, /* NID to query formats and rates */
5605 .open
= via_playback_pcm_open
,
5606 .prepare
= via_playback_multi_pcm_prepare
,
5607 .cleanup
= via_playback_multi_pcm_cleanup
,
5608 .close
= via_pcm_open_close
,
5612 static struct hda_pcm_stream vt2002P_pcm_analog_capture
= {
5616 .nid
= 0x10, /* NID to query formats and rates */
5618 .open
= via_pcm_open_close
,
5619 .prepare
= via_capture_pcm_prepare
,
5620 .cleanup
= via_capture_pcm_cleanup
,
5621 .close
= via_pcm_open_close
,
5625 static struct hda_pcm_stream vt2002P_pcm_digital_playback
= {
5629 /* NID is set in via_build_pcms */
5631 .open
= via_dig_playback_pcm_open
,
5632 .close
= via_dig_playback_pcm_close
,
5633 .prepare
= via_dig_playback_pcm_prepare
,
5634 .cleanup
= via_dig_playback_pcm_cleanup
5638 /* fill in the dac_nids table from the parsed pin configuration */
5639 static int vt2002P_auto_fill_dac_nids(struct via_spec
*spec
,
5640 const struct auto_pin_cfg
*cfg
)
5642 spec
->multiout
.num_dacs
= 1;
5643 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
5644 if (cfg
->line_out_pins
[0])
5645 spec
->multiout
.dac_nids
[0] = 0x8;
5649 /* add playback controls from the parsed DAC table */
5650 static int vt2002P_auto_create_multi_out_ctls(struct via_spec
*spec
,
5651 const struct auto_pin_cfg
*cfg
)
5655 if (!cfg
->line_out_pins
[0])
5659 /* Line-Out: PortE */
5660 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
5661 "Master Front Playback Volume",
5662 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT
));
5665 err
= via_add_control(spec
, VIA_CTL_WIDGET_BIND_PIN_MUTE
,
5666 "Master Front Playback Switch",
5667 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT
));
5674 static int vt2002P_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
5681 spec
->multiout
.hp_nid
= 0x9;
5682 spec
->hp_independent_mode_index
= 1;
5684 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
5685 "Headphone Playback Volume",
5686 HDA_COMPOSE_AMP_VAL(
5687 spec
->multiout
.hp_nid
, 3, 0, HDA_OUTPUT
));
5691 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
5692 "Headphone Playback Switch",
5693 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
5697 create_hp_imux(spec
);
5701 /* create playback/capture controls for input pins */
5702 static int vt2002P_auto_create_analog_input_ctls(struct via_spec
*spec
,
5703 const struct auto_pin_cfg
*cfg
)
5705 static char *labels
[] = {
5706 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5708 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
5709 int i
, err
, idx
= 0;
5711 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
5712 if (!cfg
->input_pins
[i
])
5715 switch (cfg
->input_pins
[i
]) {
5716 case 0x2b: /* Mic */
5720 case 0x2a: /* Line In */
5724 case 0x29: /* Front Mic */
5728 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x21);
5731 imux
->items
[imux
->num_items
].label
= labels
[i
];
5732 imux
->items
[imux
->num_items
].index
= idx
;
5736 /* build volume/mute control of loopback */
5737 err
= via_new_analog_input(spec
, "Stereo Mixer", 3, 0x21);
5741 /* for internal loopback recording select */
5742 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
5743 imux
->items
[imux
->num_items
].index
= 3;
5746 /* for digital mic select */
5747 imux
->items
[imux
->num_items
].label
= "Digital Mic";
5748 imux
->items
[imux
->num_items
].index
= 4;
5754 static int vt2002P_parse_auto_config(struct hda_codec
*codec
)
5756 struct via_spec
*spec
= codec
->spec
;
5760 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
5764 err
= vt2002P_auto_fill_dac_nids(spec
, &spec
->autocfg
);
5768 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
5769 return 0; /* can't find valid BIOS pin config */
5771 err
= vt2002P_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
5774 err
= vt2002P_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
5777 err
= vt2002P_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
5781 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
5783 fill_dig_outs(codec
);
5785 if (spec
->kctls
.list
)
5786 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
5788 spec
->input_mux
= &spec
->private_imux
[0];
5791 via_hp_build(codec
);
5796 #ifdef CONFIG_SND_HDA_POWER_SAVE
5797 static struct hda_amp_list vt2002P_loopbacks
[] = {
5798 { 0x21, HDA_INPUT
, 0 },
5799 { 0x21, HDA_INPUT
, 1 },
5800 { 0x21, HDA_INPUT
, 2 },
5806 /* patch for vt2002P */
5807 static int patch_vt2002P(struct hda_codec
*codec
)
5809 struct via_spec
*spec
;
5812 /* create a codec specific record */
5813 spec
= via_new_spec(codec
);
5817 /* automatic parse from the BIOS config */
5818 err
= vt2002P_parse_auto_config(codec
);
5823 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
5824 "from BIOS. Using genenic mode...\n");
5827 spec
->init_verbs
[spec
->num_iverbs
++] = vt2002P_volume_init_verbs
;
5828 spec
->init_verbs
[spec
->num_iverbs
++] = vt2002P_uniwill_init_verbs
;
5830 spec
->stream_name_analog
= "VT2002P Analog";
5831 spec
->stream_analog_playback
= &vt2002P_pcm_analog_playback
;
5832 spec
->stream_analog_capture
= &vt2002P_pcm_analog_capture
;
5834 spec
->stream_name_digital
= "VT2002P Digital";
5835 spec
->stream_digital_playback
= &vt2002P_pcm_digital_playback
;
5837 if (!spec
->adc_nids
&& spec
->input_mux
) {
5838 spec
->adc_nids
= vt2002P_adc_nids
;
5839 spec
->num_adc_nids
= ARRAY_SIZE(vt2002P_adc_nids
);
5840 get_mux_nids(codec
);
5841 override_mic_boost(codec
, 0x2b, 0, 3, 40);
5842 override_mic_boost(codec
, 0x29, 0, 3, 40);
5843 spec
->mixers
[spec
->num_mixers
] = vt2002P_capture_mixer
;
5847 codec
->patch_ops
= via_patch_ops
;
5849 codec
->patch_ops
.init
= via_auto_init
;
5850 codec
->patch_ops
.unsol_event
= via_unsol_event
;
5852 #ifdef CONFIG_SND_HDA_POWER_SAVE
5853 spec
->loopback
.amplist
= vt2002P_loopbacks
;
5861 /* capture mixer elements */
5862 static struct snd_kcontrol_new vt1812_capture_mixer
[] = {
5863 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT
),
5864 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT
),
5865 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT
),
5866 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT
),
5867 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT
),
5868 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5871 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
5872 /* The multiple "Capture Source" controls confuse alsamixer
5873 * So call somewhat different..
5875 .name
= "Input Source",
5877 .info
= via_mux_enum_info
,
5878 .get
= via_mux_enum_get
,
5879 .put
= via_mux_enum_put
,
5884 static struct hda_verb vt1812_volume_init_verbs
[] = {
5886 * Unmute ADC0-1 and set the default input to mic-in
5888 {0x8, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5889 {0x9, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5892 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5895 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5896 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
5897 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5898 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
5899 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
5900 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
5902 /* MUX Indices: Mic = 0 */
5903 {0x1e, AC_VERB_SET_CONNECT_SEL
, 0},
5904 {0x1f, AC_VERB_SET_CONNECT_SEL
, 0},
5906 /* PW9 Output enable */
5907 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_OUT_EN
},
5909 /* Enable Boost Volume backdoor */
5912 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5913 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5914 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5915 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5916 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5917 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5918 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5919 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5920 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5921 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5922 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5924 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5925 {0x34, AC_VERB_SET_CONNECT_SEL
, 0},
5926 {0x35, AC_VERB_SET_CONNECT_SEL
, 0},
5927 {0x38, AC_VERB_SET_CONNECT_SEL
, 0},
5928 {0x3c, AC_VERB_SET_CONNECT_SEL
, 0},
5929 {0x3d, AC_VERB_SET_CONNECT_SEL
, 0},
5931 /* Enable AOW0 to MW9 */
5937 static struct hda_verb vt1812_uniwill_init_verbs
[] = {
5938 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE
,
5939 AC_USRSP_EN
| VIA_JACK_EVENT
| VIA_BIND_HP_EVENT
},
5940 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5941 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE
,
5942 AC_USRSP_EN
| VIA_JACK_EVENT
| VIA_BIND_HP_EVENT
},
5943 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5944 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5945 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5949 static struct hda_pcm_stream vt1812_pcm_analog_playback
= {
5953 .nid
= 0x8, /* NID to query formats and rates */
5955 .open
= via_playback_pcm_open
,
5956 .prepare
= via_playback_multi_pcm_prepare
,
5957 .cleanup
= via_playback_multi_pcm_cleanup
,
5958 .close
= via_pcm_open_close
,
5962 static struct hda_pcm_stream vt1812_pcm_analog_capture
= {
5966 .nid
= 0x10, /* NID to query formats and rates */
5968 .open
= via_pcm_open_close
,
5969 .prepare
= via_capture_pcm_prepare
,
5970 .cleanup
= via_capture_pcm_cleanup
,
5971 .close
= via_pcm_open_close
,
5975 static struct hda_pcm_stream vt1812_pcm_digital_playback
= {
5979 /* NID is set in via_build_pcms */
5981 .open
= via_dig_playback_pcm_open
,
5982 .close
= via_dig_playback_pcm_close
,
5983 .prepare
= via_dig_playback_pcm_prepare
,
5984 .cleanup
= via_dig_playback_pcm_cleanup
5987 /* fill in the dac_nids table from the parsed pin configuration */
5988 static int vt1812_auto_fill_dac_nids(struct via_spec
*spec
,
5989 const struct auto_pin_cfg
*cfg
)
5991 spec
->multiout
.num_dacs
= 1;
5992 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
5993 if (cfg
->line_out_pins
[0])
5994 spec
->multiout
.dac_nids
[0] = 0x8;
5999 /* add playback controls from the parsed DAC table */
6000 static int vt1812_auto_create_multi_out_ctls(struct via_spec
*spec
,
6001 const struct auto_pin_cfg
*cfg
)
6005 if (!cfg
->line_out_pins
[0])
6008 /* Line-Out: PortE */
6009 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
6010 "Front Playback Volume",
6011 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT
));
6014 err
= via_add_control(spec
, VIA_CTL_WIDGET_BIND_PIN_MUTE
,
6015 "Front Playback Switch",
6016 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT
));
6023 static int vt1812_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
6030 spec
->multiout
.hp_nid
= 0x9;
6031 spec
->hp_independent_mode_index
= 1;
6034 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
6035 "Headphone Playback Volume",
6036 HDA_COMPOSE_AMP_VAL(
6037 spec
->multiout
.hp_nid
, 3, 0, HDA_OUTPUT
));
6041 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
6042 "Headphone Playback Switch",
6043 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
6047 create_hp_imux(spec
);
6051 /* create playback/capture controls for input pins */
6052 static int vt1812_auto_create_analog_input_ctls(struct via_spec
*spec
,
6053 const struct auto_pin_cfg
*cfg
)
6055 static char *labels
[] = {
6056 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
6058 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
6059 int i
, err
, idx
= 0;
6061 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
6062 if (!cfg
->input_pins
[i
])
6065 switch (cfg
->input_pins
[i
]) {
6066 case 0x2b: /* Mic */
6070 case 0x2a: /* Line In */
6074 case 0x29: /* Front Mic */
6078 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x21);
6081 imux
->items
[imux
->num_items
].label
= labels
[i
];
6082 imux
->items
[imux
->num_items
].index
= idx
;
6085 /* build volume/mute control of loopback */
6086 err
= via_new_analog_input(spec
, "Stereo Mixer", 5, 0x21);
6090 /* for internal loopback recording select */
6091 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
6092 imux
->items
[imux
->num_items
].index
= 5;
6095 /* for digital mic select */
6096 imux
->items
[imux
->num_items
].label
= "Digital Mic";
6097 imux
->items
[imux
->num_items
].index
= 6;
6103 static int vt1812_parse_auto_config(struct hda_codec
*codec
)
6105 struct via_spec
*spec
= codec
->spec
;
6109 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
6112 fill_dig_outs(codec
);
6113 err
= vt1812_auto_fill_dac_nids(spec
, &spec
->autocfg
);
6117 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_outs
)
6118 return 0; /* can't find valid BIOS pin config */
6120 err
= vt1812_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
6123 err
= vt1812_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
6126 err
= vt1812_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
6130 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
6132 fill_dig_outs(codec
);
6134 if (spec
->kctls
.list
)
6135 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
6137 spec
->input_mux
= &spec
->private_imux
[0];
6140 via_hp_build(codec
);
6145 #ifdef CONFIG_SND_HDA_POWER_SAVE
6146 static struct hda_amp_list vt1812_loopbacks
[] = {
6147 { 0x21, HDA_INPUT
, 0 },
6148 { 0x21, HDA_INPUT
, 1 },
6149 { 0x21, HDA_INPUT
, 2 },
6155 /* patch for vt1812 */
6156 static int patch_vt1812(struct hda_codec
*codec
)
6158 struct via_spec
*spec
;
6161 /* create a codec specific record */
6162 spec
= via_new_spec(codec
);
6166 /* automatic parse from the BIOS config */
6167 err
= vt1812_parse_auto_config(codec
);
6172 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
6173 "from BIOS. Using genenic mode...\n");
6177 spec
->init_verbs
[spec
->num_iverbs
++] = vt1812_volume_init_verbs
;
6178 spec
->init_verbs
[spec
->num_iverbs
++] = vt1812_uniwill_init_verbs
;
6180 spec
->stream_name_analog
= "VT1812 Analog";
6181 spec
->stream_analog_playback
= &vt1812_pcm_analog_playback
;
6182 spec
->stream_analog_capture
= &vt1812_pcm_analog_capture
;
6184 spec
->stream_name_digital
= "VT1812 Digital";
6185 spec
->stream_digital_playback
= &vt1812_pcm_digital_playback
;
6188 if (!spec
->adc_nids
&& spec
->input_mux
) {
6189 spec
->adc_nids
= vt1812_adc_nids
;
6190 spec
->num_adc_nids
= ARRAY_SIZE(vt1812_adc_nids
);
6191 get_mux_nids(codec
);
6192 override_mic_boost(codec
, 0x2b, 0, 3, 40);
6193 override_mic_boost(codec
, 0x29, 0, 3, 40);
6194 spec
->mixers
[spec
->num_mixers
] = vt1812_capture_mixer
;
6198 codec
->patch_ops
= via_patch_ops
;
6200 codec
->patch_ops
.init
= via_auto_init
;
6201 codec
->patch_ops
.unsol_event
= via_unsol_event
;
6203 #ifdef CONFIG_SND_HDA_POWER_SAVE
6204 spec
->loopback
.amplist
= vt1812_loopbacks
;
6213 static struct hda_codec_preset snd_hda_preset_via
[] = {
6214 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
6215 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
6216 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
6217 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
6218 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
6219 .patch
= patch_vt1709_10ch
},
6220 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
6221 .patch
= patch_vt1709_10ch
},
6222 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
6223 .patch
= patch_vt1709_10ch
},
6224 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
6225 .patch
= patch_vt1709_10ch
},
6226 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
6227 .patch
= patch_vt1709_6ch
},
6228 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
6229 .patch
= patch_vt1709_6ch
},
6230 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
6231 .patch
= patch_vt1709_6ch
},
6232 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
6233 .patch
= patch_vt1709_6ch
},
6234 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
6235 .patch
= patch_vt1708B_8ch
},
6236 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
6237 .patch
= patch_vt1708B_8ch
},
6238 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
6239 .patch
= patch_vt1708B_8ch
},
6240 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
6241 .patch
= patch_vt1708B_8ch
},
6242 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
6243 .patch
= patch_vt1708B_4ch
},
6244 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
6245 .patch
= patch_vt1708B_4ch
},
6246 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
6247 .patch
= patch_vt1708B_4ch
},
6248 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
6249 .patch
= patch_vt1708B_4ch
},
6250 { .id
= 0x11060397, .name
= "VT1708S",
6251 .patch
= patch_vt1708S
},
6252 { .id
= 0x11061397, .name
= "VT1708S",
6253 .patch
= patch_vt1708S
},
6254 { .id
= 0x11062397, .name
= "VT1708S",
6255 .patch
= patch_vt1708S
},
6256 { .id
= 0x11063397, .name
= "VT1708S",
6257 .patch
= patch_vt1708S
},
6258 { .id
= 0x11064397, .name
= "VT1708S",
6259 .patch
= patch_vt1708S
},
6260 { .id
= 0x11065397, .name
= "VT1708S",
6261 .patch
= patch_vt1708S
},
6262 { .id
= 0x11066397, .name
= "VT1708S",
6263 .patch
= patch_vt1708S
},
6264 { .id
= 0x11067397, .name
= "VT1708S",
6265 .patch
= patch_vt1708S
},
6266 { .id
= 0x11060398, .name
= "VT1702",
6267 .patch
= patch_vt1702
},
6268 { .id
= 0x11061398, .name
= "VT1702",
6269 .patch
= patch_vt1702
},
6270 { .id
= 0x11062398, .name
= "VT1702",
6271 .patch
= patch_vt1702
},
6272 { .id
= 0x11063398, .name
= "VT1702",
6273 .patch
= patch_vt1702
},
6274 { .id
= 0x11064398, .name
= "VT1702",
6275 .patch
= patch_vt1702
},
6276 { .id
= 0x11065398, .name
= "VT1702",
6277 .patch
= patch_vt1702
},
6278 { .id
= 0x11066398, .name
= "VT1702",
6279 .patch
= patch_vt1702
},
6280 { .id
= 0x11067398, .name
= "VT1702",
6281 .patch
= patch_vt1702
},
6282 { .id
= 0x11060428, .name
= "VT1718S",
6283 .patch
= patch_vt1718S
},
6284 { .id
= 0x11064428, .name
= "VT1718S",
6285 .patch
= patch_vt1718S
},
6286 { .id
= 0x11060441, .name
= "VT2020",
6287 .patch
= patch_vt1718S
},
6288 { .id
= 0x11064441, .name
= "VT1828S",
6289 .patch
= patch_vt1718S
},
6290 { .id
= 0x11060433, .name
= "VT1716S",
6291 .patch
= patch_vt1716S
},
6292 { .id
= 0x1106a721, .name
= "VT1716S",
6293 .patch
= patch_vt1716S
},
6294 { .id
= 0x11060438, .name
= "VT2002P", .patch
= patch_vt2002P
},
6295 { .id
= 0x11064438, .name
= "VT2002P", .patch
= patch_vt2002P
},
6296 { .id
= 0x11060448, .name
= "VT1812", .patch
= patch_vt1812
},
6297 { .id
= 0x11060440, .name
= "VT1818S",
6298 .patch
= patch_vt1708S
},
6302 MODULE_ALIAS("snd-hda-codec-id:1106*");
6304 static struct hda_codec_preset_list via_list
= {
6305 .preset
= snd_hda_preset_via
,
6306 .owner
= THIS_MODULE
,
6309 MODULE_LICENSE("GPL");
6310 MODULE_DESCRIPTION("VIA HD-audio codec");
6312 static int __init
patch_via_init(void)
6314 return snd_hda_add_codec_preset(&via_list
);
6317 static void __exit
patch_via_exit(void)
6319 snd_hda_delete_codec_preset(&via_list
);
6322 module_init(patch_via_init
)
6323 module_exit(patch_via_exit
)