2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec
6 * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com>
7 * 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 */
40 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 #include <linux/init.h>
44 #include <linux/delay.h>
45 #include <linux/slab.h>
46 #include <sound/core.h>
47 #include <sound/asoundef.h>
48 #include "hda_codec.h"
49 #include "hda_local.h"
52 #define AMP_VAL_IDX_SHIFT 19
53 #define AMP_VAL_IDX_MASK (0x0f<<19)
56 #define VT1708_HP_NID 0x13
57 #define VT1708_DIGOUT_NID 0x14
58 #define VT1708_DIGIN_NID 0x16
59 #define VT1708_DIGIN_PIN 0x26
60 #define VT1708_HP_PIN_NID 0x20
61 #define VT1708_CD_PIN_NID 0x24
63 #define VT1709_HP_DAC_NID 0x28
64 #define VT1709_DIGOUT_NID 0x13
65 #define VT1709_DIGIN_NID 0x17
66 #define VT1709_DIGIN_PIN 0x25
68 #define VT1708B_HP_NID 0x25
69 #define VT1708B_DIGOUT_NID 0x12
70 #define VT1708B_DIGIN_NID 0x15
71 #define VT1708B_DIGIN_PIN 0x21
73 #define VT1708S_HP_NID 0x25
74 #define VT1708S_DIGOUT_NID 0x12
76 #define VT1702_HP_NID 0x17
77 #define VT1702_DIGOUT_NID 0x11
79 #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
80 #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
81 #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
82 #define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
83 #define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
84 #define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
85 #define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
99 static enum VIA_HDA_CODEC
get_codec_type(u32 vendor_id
)
101 u16 ven_id
= vendor_id
>> 16;
102 u16 dev_id
= vendor_id
& 0xffff;
103 enum VIA_HDA_CODEC codec_type
;
106 if (ven_id
!= 0x1106)
107 codec_type
= UNKNOWN
;
108 else if (dev_id
>= 0x1708 && dev_id
<= 0x170b)
110 else if (dev_id
>= 0xe710 && dev_id
<= 0xe713)
111 codec_type
= VT1709_10CH
;
112 else if (dev_id
>= 0xe714 && dev_id
<= 0xe717)
113 codec_type
= VT1709_6CH
;
114 else if (dev_id
>= 0xe720 && dev_id
<= 0xe723)
115 codec_type
= VT1708B_8CH
;
116 else if (dev_id
>= 0xe724 && dev_id
<= 0xe727)
117 codec_type
= VT1708B_4CH
;
118 else if ((dev_id
& 0xfff) == 0x397
119 && (dev_id
>> 12) < 8)
120 codec_type
= VT1708S
;
121 else if ((dev_id
& 0xfff) == 0x398
122 && (dev_id
>> 12) < 8)
125 codec_type
= UNKNOWN
;
129 #define VIA_HP_EVENT 0x01
130 #define VIA_GPIO_EVENT 0x02
144 /* Some VT1708S based boards gets the micboost setting wrong, so we have
145 * to apply some brute-force and re-write the TLV's by software. */
146 static int mic_boost_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
147 unsigned int size
, unsigned int __user
*_tlv
)
149 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
150 hda_nid_t nid
= get_amp_nid(kcontrol
);
152 if (get_codec_type(codec
->vendor_id
) == VT1708S
153 && (nid
== 0x1a || nid
== 0x1e)) {
154 if (size
< 4 * sizeof(unsigned int))
156 if (put_user(1, _tlv
)) /* SNDRV_CTL_TLVT_DB_SCALE */
158 if (put_user(2 * sizeof(unsigned int), _tlv
+ 1))
160 if (put_user(0, _tlv
+ 2)) /* offset = 0 */
162 if (put_user(1000, _tlv
+ 3)) /* step size = 10 dB */
168 static int mic_boost_volume_info(struct snd_kcontrol
*kcontrol
,
169 struct snd_ctl_elem_info
*uinfo
)
171 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
172 hda_nid_t nid
= get_amp_nid(kcontrol
);
174 if (get_codec_type(codec
->vendor_id
) == VT1708S
175 && (nid
== 0x1a || nid
== 0x1e)) {
176 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
178 uinfo
->value
.integer
.min
= 0;
179 uinfo
->value
.integer
.max
= 3;
184 static struct snd_kcontrol_new vt1708_control_templates
[] = {
185 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
186 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
191 /* codec parameterization */
192 struct snd_kcontrol_new
*mixers
[3];
193 unsigned int num_mixers
;
195 struct hda_verb
*init_verbs
[5];
196 unsigned int num_iverbs
;
198 char *stream_name_analog
;
199 struct hda_pcm_stream
*stream_analog_playback
;
200 struct hda_pcm_stream
*stream_analog_capture
;
202 char *stream_name_digital
;
203 struct hda_pcm_stream
*stream_digital_playback
;
204 struct hda_pcm_stream
*stream_digital_capture
;
207 struct hda_multi_out multiout
;
208 hda_nid_t slave_dig_outs
[2];
211 unsigned int num_adc_nids
;
213 hda_nid_t mux_nids
[3];
214 hda_nid_t dig_in_nid
;
215 hda_nid_t dig_in_pin
;
218 const struct hda_input_mux
*input_mux
;
219 unsigned int cur_mux
[3];
221 /* PCM information */
222 struct hda_pcm pcm_rec
[3];
224 /* dynamic controls, init_verbs and input_mux */
225 struct auto_pin_cfg autocfg
;
226 struct snd_array kctls
;
227 struct hda_input_mux private_imux
[2];
228 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
231 const struct hda_input_mux
*hp_mux
;
232 unsigned int hp_independent_mode
;
234 #ifdef CONFIG_SND_HDA_POWER_SAVE
235 struct hda_loopback_check loopback
;
239 static hda_nid_t vt1708_adc_nids
[2] = {
244 static hda_nid_t vt1709_adc_nids
[3] = {
249 static hda_nid_t vt1708B_adc_nids
[2] = {
254 static hda_nid_t vt1708S_adc_nids
[2] = {
259 static hda_nid_t vt1702_adc_nids
[3] = {
264 /* add dynamic controls */
265 static int via_add_control(struct via_spec
*spec
, int type
, const char *name
,
268 struct snd_kcontrol_new
*knew
;
270 snd_array_init(&spec
->kctls
, sizeof(*knew
), 32);
271 knew
= snd_array_new(&spec
->kctls
);
274 *knew
= vt1708_control_templates
[type
];
275 knew
->name
= kstrdup(name
, GFP_KERNEL
);
278 knew
->private_value
= val
;
282 static void via_free_kctls(struct hda_codec
*codec
)
284 struct via_spec
*spec
= codec
->spec
;
286 if (spec
->kctls
.list
) {
287 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
289 for (i
= 0; i
< spec
->kctls
.used
; i
++)
292 snd_array_free(&spec
->kctls
);
295 /* create input playback/capture controls for the given pin */
296 static int via_new_analog_input(struct via_spec
*spec
, hda_nid_t pin
,
297 const char *ctlname
, int idx
, int mix_nid
)
302 sprintf(name
, "%s Playback Volume", ctlname
);
303 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
304 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
307 sprintf(name
, "%s Playback Switch", ctlname
);
308 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
309 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
315 static void via_auto_set_output_and_unmute(struct hda_codec
*codec
,
316 hda_nid_t nid
, int pin_type
,
320 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
322 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
324 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
325 snd_hda_codec_write(codec
, nid
, 0,
326 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
330 static void via_auto_init_multi_out(struct hda_codec
*codec
)
332 struct via_spec
*spec
= codec
->spec
;
335 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
336 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
338 via_auto_set_output_and_unmute(codec
, nid
, PIN_OUT
, i
);
342 static void via_auto_init_hp_out(struct hda_codec
*codec
)
344 struct via_spec
*spec
= codec
->spec
;
347 pin
= spec
->autocfg
.hp_pins
[0];
348 if (pin
) /* connect to front */
349 via_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, 0);
352 static void via_auto_init_analog_input(struct hda_codec
*codec
)
354 struct via_spec
*spec
= codec
->spec
;
357 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
358 hda_nid_t nid
= spec
->autocfg
.input_pins
[i
];
360 snd_hda_codec_write(codec
, nid
, 0,
361 AC_VERB_SET_PIN_WIDGET_CONTROL
,
362 (i
<= AUTO_PIN_FRONT_MIC
?
363 PIN_VREF50
: PIN_IN
));
370 static int via_mux_enum_info(struct snd_kcontrol
*kcontrol
,
371 struct snd_ctl_elem_info
*uinfo
)
373 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
374 struct via_spec
*spec
= codec
->spec
;
375 return snd_hda_input_mux_info(spec
->input_mux
, uinfo
);
378 static int via_mux_enum_get(struct snd_kcontrol
*kcontrol
,
379 struct snd_ctl_elem_value
*ucontrol
)
381 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
382 struct via_spec
*spec
= codec
->spec
;
383 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
385 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
389 static int via_mux_enum_put(struct snd_kcontrol
*kcontrol
,
390 struct snd_ctl_elem_value
*ucontrol
)
392 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
393 struct via_spec
*spec
= codec
->spec
;
394 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
395 unsigned int vendor_id
= codec
->vendor_id
;
397 if (!spec
->mux_nids
[adc_idx
])
399 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
400 spec
->mux_nids
[adc_idx
],
401 &spec
->cur_mux
[adc_idx
]);
404 static int via_independent_hp_info(struct snd_kcontrol
*kcontrol
,
405 struct snd_ctl_elem_info
*uinfo
)
407 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
408 struct via_spec
*spec
= codec
->spec
;
409 return snd_hda_input_mux_info(spec
->hp_mux
, uinfo
);
412 static int via_independent_hp_get(struct snd_kcontrol
*kcontrol
,
413 struct snd_ctl_elem_value
*ucontrol
)
415 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
416 struct via_spec
*spec
= codec
->spec
;
417 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
418 unsigned int pinsel
= snd_hda_codec_read(codec
, nid
, 0,
419 AC_VERB_GET_CONNECT_SEL
,
422 ucontrol
->value
.enumerated
.item
[0] = pinsel
;
427 static int via_independent_hp_put(struct snd_kcontrol
*kcontrol
,
428 struct snd_ctl_elem_value
*ucontrol
)
430 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
431 struct via_spec
*spec
= codec
->spec
;
432 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
433 unsigned int pinsel
= ucontrol
->value
.enumerated
.item
[0];
434 unsigned int con_nid
= snd_hda_codec_read(codec
, nid
, 0,
435 AC_VERB_GET_CONNECT_LIST
, 0) & 0xff;
437 if (con_nid
== spec
->multiout
.hp_nid
) {
439 if (!spec
->hp_independent_mode
) {
440 if (spec
->multiout
.num_dacs
> 1)
441 spec
->multiout
.num_dacs
-= 1;
442 spec
->hp_independent_mode
= 1;
444 } else if (pinsel
== 1) {
445 if (spec
->hp_independent_mode
) {
446 if (spec
->multiout
.num_dacs
> 1)
447 spec
->multiout
.num_dacs
+= 1;
448 spec
->hp_independent_mode
= 0;
453 if (spec
->hp_independent_mode
) {
454 if (spec
->multiout
.num_dacs
> 1)
455 spec
->multiout
.num_dacs
+= 1;
456 spec
->hp_independent_mode
= 0;
458 } else if (pinsel
== 1) {
459 if (!spec
->hp_independent_mode
) {
460 if (spec
->multiout
.num_dacs
> 1)
461 spec
->multiout
.num_dacs
-= 1;
462 spec
->hp_independent_mode
= 1;
466 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
,
469 if (spec
->multiout
.hp_nid
&&
470 spec
->multiout
.hp_nid
!= spec
->multiout
.dac_nids
[HDA_FRONT
])
471 snd_hda_codec_setup_stream(codec
,
472 spec
->multiout
.hp_nid
,
478 static struct snd_kcontrol_new via_hp_mixer
[] = {
480 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
481 .name
= "Independent HP",
483 .info
= via_independent_hp_info
,
484 .get
= via_independent_hp_get
,
485 .put
= via_independent_hp_put
,
490 /* capture mixer elements */
491 static struct snd_kcontrol_new vt1708_capture_mixer
[] = {
492 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT
),
493 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT
),
494 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT
),
495 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT
),
497 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
498 /* The multiple "Capture Source" controls confuse alsamixer
499 * So call somewhat different..
501 /* .name = "Capture Source", */
502 .name
= "Input Source",
504 .info
= via_mux_enum_info
,
505 .get
= via_mux_enum_get
,
506 .put
= via_mux_enum_put
,
511 * generic initialization of ADC, input mixers and output mixers
513 static struct hda_verb vt1708_volume_init_verbs
[] = {
515 * Unmute ADC0-1 and set the default input to mic-in
517 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
518 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
521 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
524 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
525 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
526 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
527 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
528 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
529 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
532 * Set up output mixers (0x19 - 0x1b)
534 /* set vol=0 to output mixers */
535 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
536 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
537 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
539 /* Setup default input to PW4 */
540 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
541 /* PW9 Output enable */
542 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
546 static int via_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
547 struct hda_codec
*codec
,
548 struct snd_pcm_substream
*substream
)
550 struct via_spec
*spec
= codec
->spec
;
551 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
555 static int via_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
556 struct hda_codec
*codec
,
557 unsigned int stream_tag
,
559 struct snd_pcm_substream
*substream
)
561 struct via_spec
*spec
= codec
->spec
;
562 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
563 stream_tag
, format
, substream
);
566 static int via_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
567 struct hda_codec
*codec
,
568 struct snd_pcm_substream
*substream
)
570 struct via_spec
*spec
= codec
->spec
;
571 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
575 static void playback_multi_pcm_prep_0(struct hda_codec
*codec
,
576 unsigned int stream_tag
,
578 struct snd_pcm_substream
*substream
)
580 struct via_spec
*spec
= codec
->spec
;
581 struct hda_multi_out
*mout
= &spec
->multiout
;
582 hda_nid_t
*nids
= mout
->dac_nids
;
583 int chs
= substream
->runtime
->channels
;
586 mutex_lock(&codec
->spdif_mutex
);
587 if (mout
->dig_out_nid
&& mout
->dig_out_used
!= HDA_DIG_EXCLUSIVE
) {
589 snd_hda_is_supported_format(codec
, mout
->dig_out_nid
,
591 !(codec
->spdif_status
& IEC958_AES0_NONAUDIO
)) {
592 mout
->dig_out_used
= HDA_DIG_ANALOG_DUP
;
593 /* turn off SPDIF once; otherwise the IEC958 bits won't
595 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
596 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
597 AC_VERB_SET_DIGI_CONVERT_1
,
599 ~AC_DIG1_ENABLE
& 0xff);
600 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
601 stream_tag
, 0, format
);
602 /* turn on again (if needed) */
603 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
604 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
605 AC_VERB_SET_DIGI_CONVERT_1
,
606 codec
->spdif_ctls
& 0xff);
608 mout
->dig_out_used
= 0;
609 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
613 mutex_unlock(&codec
->spdif_mutex
);
616 snd_hda_codec_setup_stream(codec
, nids
[HDA_FRONT
], stream_tag
,
619 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
620 !spec
->hp_independent_mode
)
621 /* headphone out will just decode front left/right (stereo) */
622 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
, stream_tag
,
625 /* extra outputs copied from front */
626 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
627 if (mout
->extra_out_nid
[i
])
628 snd_hda_codec_setup_stream(codec
,
629 mout
->extra_out_nid
[i
],
630 stream_tag
, 0, format
);
633 for (i
= 1; i
< mout
->num_dacs
; i
++) {
634 if (chs
>= (i
+ 1) * 2) /* independent out */
635 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
637 else /* copy front */
638 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
643 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
644 struct hda_codec
*codec
,
645 unsigned int stream_tag
,
647 struct snd_pcm_substream
*substream
)
649 struct via_spec
*spec
= codec
->spec
;
650 struct hda_multi_out
*mout
= &spec
->multiout
;
651 hda_nid_t
*nids
= mout
->dac_nids
;
653 if (substream
->number
== 0)
654 playback_multi_pcm_prep_0(codec
, stream_tag
, format
,
657 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
658 spec
->hp_independent_mode
)
659 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
660 stream_tag
, 0, format
);
666 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
667 struct hda_codec
*codec
,
668 struct snd_pcm_substream
*substream
)
670 struct via_spec
*spec
= codec
->spec
;
671 struct hda_multi_out
*mout
= &spec
->multiout
;
672 hda_nid_t
*nids
= mout
->dac_nids
;
675 if (substream
->number
== 0) {
676 for (i
= 0; i
< mout
->num_dacs
; i
++)
677 snd_hda_codec_setup_stream(codec
, nids
[i
], 0, 0, 0);
679 if (mout
->hp_nid
&& !spec
->hp_independent_mode
)
680 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
683 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
684 if (mout
->extra_out_nid
[i
])
685 snd_hda_codec_setup_stream(codec
,
686 mout
->extra_out_nid
[i
],
688 mutex_lock(&codec
->spdif_mutex
);
689 if (mout
->dig_out_nid
&&
690 mout
->dig_out_used
== HDA_DIG_ANALOG_DUP
) {
691 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
693 mout
->dig_out_used
= 0;
695 mutex_unlock(&codec
->spdif_mutex
);
697 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
698 spec
->hp_independent_mode
)
699 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
709 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
710 struct hda_codec
*codec
,
711 struct snd_pcm_substream
*substream
)
713 struct via_spec
*spec
= codec
->spec
;
714 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
717 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
718 struct hda_codec
*codec
,
719 struct snd_pcm_substream
*substream
)
721 struct via_spec
*spec
= codec
->spec
;
722 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
725 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
726 struct hda_codec
*codec
,
727 unsigned int stream_tag
,
729 struct snd_pcm_substream
*substream
)
731 struct via_spec
*spec
= codec
->spec
;
732 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
733 stream_tag
, format
, substream
);
736 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
737 struct hda_codec
*codec
,
738 struct snd_pcm_substream
*substream
)
740 struct via_spec
*spec
= codec
->spec
;
741 snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
748 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
749 struct hda_codec
*codec
,
750 unsigned int stream_tag
,
752 struct snd_pcm_substream
*substream
)
754 struct via_spec
*spec
= codec
->spec
;
756 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
757 stream_tag
, 0, format
);
761 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
762 struct hda_codec
*codec
,
763 struct snd_pcm_substream
*substream
)
765 struct via_spec
*spec
= codec
->spec
;
766 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
770 static struct hda_pcm_stream vt1708_pcm_analog_playback
= {
774 .nid
= 0x10, /* NID to query formats and rates */
776 .open
= via_playback_pcm_open
,
777 .prepare
= via_playback_multi_pcm_prepare
,
778 .cleanup
= via_playback_multi_pcm_cleanup
782 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
786 .nid
= 0x10, /* NID to query formats and rates */
787 /* We got noisy outputs on the right channel on VT1708 when
788 * 24bit samples are used. Until any workaround is found,
789 * disable the 24bit format, so far.
791 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
793 .open
= via_playback_pcm_open
,
794 .prepare
= via_playback_pcm_prepare
,
795 .cleanup
= via_playback_pcm_cleanup
799 static struct hda_pcm_stream vt1708_pcm_analog_capture
= {
803 .nid
= 0x15, /* NID to query formats and rates */
805 .prepare
= via_capture_pcm_prepare
,
806 .cleanup
= via_capture_pcm_cleanup
810 static struct hda_pcm_stream vt1708_pcm_digital_playback
= {
814 /* NID is set in via_build_pcms */
816 .open
= via_dig_playback_pcm_open
,
817 .close
= via_dig_playback_pcm_close
,
818 .prepare
= via_dig_playback_pcm_prepare
,
819 .cleanup
= via_dig_playback_pcm_cleanup
823 static struct hda_pcm_stream vt1708_pcm_digital_capture
= {
829 static int via_build_controls(struct hda_codec
*codec
)
831 struct via_spec
*spec
= codec
->spec
;
835 for (i
= 0; i
< spec
->num_mixers
; i
++) {
836 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
841 if (spec
->multiout
.dig_out_nid
) {
842 err
= snd_hda_create_spdif_out_ctls(codec
,
843 spec
->multiout
.dig_out_nid
);
846 err
= snd_hda_create_spdif_share_sw(codec
,
850 spec
->multiout
.share_spdif
= 1;
852 if (spec
->dig_in_nid
) {
853 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
857 via_free_kctls(codec
); /* no longer needed */
861 static int via_build_pcms(struct hda_codec
*codec
)
863 struct via_spec
*spec
= codec
->spec
;
864 struct hda_pcm
*info
= spec
->pcm_rec
;
867 codec
->pcm_info
= info
;
869 info
->name
= spec
->stream_name_analog
;
870 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *(spec
->stream_analog_playback
);
871 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
872 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *(spec
->stream_analog_capture
);
873 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
875 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
876 spec
->multiout
.max_channels
;
878 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
881 info
->name
= spec
->stream_name_digital
;
882 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
883 if (spec
->multiout
.dig_out_nid
) {
884 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
885 *(spec
->stream_digital_playback
);
886 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
887 spec
->multiout
.dig_out_nid
;
889 if (spec
->dig_in_nid
) {
890 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
891 *(spec
->stream_digital_capture
);
892 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
900 static void via_free(struct hda_codec
*codec
)
902 struct via_spec
*spec
= codec
->spec
;
907 via_free_kctls(codec
);
911 /* mute internal speaker if HP is plugged */
912 static void via_hp_automute(struct hda_codec
*codec
)
914 unsigned int present
;
915 struct via_spec
*spec
= codec
->spec
;
917 present
= snd_hda_codec_read(codec
, spec
->autocfg
.hp_pins
[0], 0,
918 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
919 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
920 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
921 present
? HDA_AMP_MUTE
: 0);
924 static void via_gpio_control(struct hda_codec
*codec
)
926 unsigned int gpio_data
;
927 unsigned int vol_counter
;
929 unsigned int master_vol
;
931 struct via_spec
*spec
= codec
->spec
;
933 gpio_data
= snd_hda_codec_read(codec
, codec
->afg
, 0,
934 AC_VERB_GET_GPIO_DATA
, 0) & 0x03;
936 vol_counter
= (snd_hda_codec_read(codec
, codec
->afg
, 0,
937 0xF84, 0) & 0x3F0000) >> 16;
939 vol
= vol_counter
& 0x1F;
940 master_vol
= snd_hda_codec_read(codec
, 0x1A, 0,
941 AC_VERB_GET_AMP_GAIN_MUTE
,
944 if (gpio_data
== 0x02) {
945 /* unmute line out */
946 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
947 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
949 if (vol_counter
& 0x20) {
950 /* decrease volume */
951 if (vol
> master_vol
)
953 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
,
957 /* increase volume */
958 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
, 0,
960 ((master_vol
+vol
) > 0x2A) ? 0x2A :
963 } else if (!(gpio_data
& 0x02)) {
965 snd_hda_codec_amp_stereo(codec
,
966 spec
->autocfg
.line_out_pins
[0],
967 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
972 /* unsolicited event for jack sensing */
973 static void via_unsol_event(struct hda_codec
*codec
,
977 if (res
== VIA_HP_EVENT
)
978 via_hp_automute(codec
);
979 else if (res
== VIA_GPIO_EVENT
)
980 via_gpio_control(codec
);
983 static int via_init(struct hda_codec
*codec
)
985 struct via_spec
*spec
= codec
->spec
;
987 for (i
= 0; i
< spec
->num_iverbs
; i
++)
988 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
990 /* Lydia Add for EAPD enable */
991 if (!spec
->dig_in_nid
) { /* No Digital In connection */
992 if (spec
->dig_in_pin
) {
993 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
994 AC_VERB_SET_PIN_WIDGET_CONTROL
,
996 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
997 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
999 } else /* enable SPDIF-input pin */
1000 snd_hda_codec_write(codec
, spec
->autocfg
.dig_in_pin
, 0,
1001 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
1003 /* assign slave outs */
1004 if (spec
->slave_dig_outs
[0])
1005 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
1010 #ifdef CONFIG_SND_HDA_POWER_SAVE
1011 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
1013 struct via_spec
*spec
= codec
->spec
;
1014 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
1020 static struct hda_codec_ops via_patch_ops
= {
1021 .build_controls
= via_build_controls
,
1022 .build_pcms
= via_build_pcms
,
1025 #ifdef CONFIG_SND_HDA_POWER_SAVE
1026 .check_power_status
= via_check_power_status
,
1030 /* fill in the dac_nids table from the parsed pin configuration */
1031 static int vt1708_auto_fill_dac_nids(struct via_spec
*spec
,
1032 const struct auto_pin_cfg
*cfg
)
1037 spec
->multiout
.num_dacs
= cfg
->line_outs
;
1039 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1041 for(i
= 0; i
< 4; i
++) {
1042 nid
= cfg
->line_out_pins
[i
];
1044 /* config dac list */
1046 case AUTO_SEQ_FRONT
:
1047 spec
->multiout
.dac_nids
[i
] = 0x10;
1049 case AUTO_SEQ_CENLFE
:
1050 spec
->multiout
.dac_nids
[i
] = 0x12;
1052 case AUTO_SEQ_SURROUND
:
1053 spec
->multiout
.dac_nids
[i
] = 0x11;
1056 spec
->multiout
.dac_nids
[i
] = 0x13;
1065 /* add playback controls from the parsed DAC table */
1066 static int vt1708_auto_create_multi_out_ctls(struct via_spec
*spec
,
1067 const struct auto_pin_cfg
*cfg
)
1070 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1071 hda_nid_t nid
, nid_vol
= 0;
1074 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1075 nid
= cfg
->line_out_pins
[i
];
1080 if (i
!= AUTO_SEQ_FRONT
)
1083 if (i
== AUTO_SEQ_CENLFE
) {
1085 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1086 "Center Playback Volume",
1087 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1091 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1092 "LFE Playback Volume",
1093 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1097 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1098 "Center Playback Switch",
1099 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1103 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1104 "LFE Playback Switch",
1105 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1109 } else if (i
== AUTO_SEQ_FRONT
){
1110 /* add control to mixer index 0 */
1111 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1112 "Master Front Playback Volume",
1113 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1117 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1118 "Master Front Playback Switch",
1119 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1124 /* add control to PW3 */
1125 sprintf(name
, "%s Playback Volume", chname
[i
]);
1126 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1127 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1131 sprintf(name
, "%s Playback Switch", chname
[i
]);
1132 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1133 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1138 sprintf(name
, "%s Playback Volume", chname
[i
]);
1139 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1140 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1144 sprintf(name
, "%s Playback Switch", chname
[i
]);
1145 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1146 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1156 static void create_hp_imux(struct via_spec
*spec
)
1159 struct hda_input_mux
*imux
= &spec
->private_imux
[1];
1160 static const char *texts
[] = { "OFF", "ON", NULL
};
1162 /* for hp mode select */
1164 while (texts
[i
] != NULL
) {
1165 imux
->items
[imux
->num_items
].label
= texts
[i
];
1166 imux
->items
[imux
->num_items
].index
= i
;
1171 spec
->hp_mux
= &spec
->private_imux
[1];
1174 static int vt1708_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1181 spec
->multiout
.hp_nid
= VT1708_HP_NID
; /* AOW3 */
1183 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1184 "Headphone Playback Volume",
1185 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1188 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1189 "Headphone Playback Switch",
1190 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1194 create_hp_imux(spec
);
1199 /* create playback/capture controls for input pins */
1200 static int vt1708_auto_create_analog_input_ctls(struct via_spec
*spec
,
1201 const struct auto_pin_cfg
*cfg
)
1203 static char *labels
[] = {
1204 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1206 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1207 int i
, err
, idx
= 0;
1209 /* for internal loopback recording select */
1210 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1211 imux
->items
[imux
->num_items
].index
= idx
;
1214 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1215 if (!cfg
->input_pins
[i
])
1218 switch (cfg
->input_pins
[i
]) {
1219 case 0x1d: /* Mic */
1223 case 0x1e: /* Line In */
1227 case 0x21: /* Front Mic */
1235 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
1239 imux
->items
[imux
->num_items
].label
= labels
[i
];
1240 imux
->items
[imux
->num_items
].index
= idx
;
1246 #ifdef CONFIG_SND_HDA_POWER_SAVE
1247 static struct hda_amp_list vt1708_loopbacks
[] = {
1248 { 0x17, HDA_INPUT
, 1 },
1249 { 0x17, HDA_INPUT
, 2 },
1250 { 0x17, HDA_INPUT
, 3 },
1251 { 0x17, HDA_INPUT
, 4 },
1256 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
1258 unsigned int def_conf
;
1259 unsigned char seqassoc
;
1261 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
1262 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
1263 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
1264 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
) {
1265 if (seqassoc
== 0xff) {
1266 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
1267 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
1274 static int vt1708_parse_auto_config(struct hda_codec
*codec
)
1276 struct via_spec
*spec
= codec
->spec
;
1279 /* Add HP and CD pin config connect bit re-config action */
1280 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
1281 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
1283 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1286 err
= vt1708_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1289 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1290 return 0; /* can't find valid BIOS pin config */
1292 err
= vt1708_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1295 err
= vt1708_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1298 err
= vt1708_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1302 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1304 if (spec
->autocfg
.dig_outs
)
1305 spec
->multiout
.dig_out_nid
= VT1708_DIGOUT_NID
;
1306 spec
->dig_in_pin
= VT1708_DIGIN_PIN
;
1307 if (spec
->autocfg
.dig_in_pin
)
1308 spec
->dig_in_nid
= VT1708_DIGIN_NID
;
1310 if (spec
->kctls
.list
)
1311 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
1313 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_volume_init_verbs
;
1315 spec
->input_mux
= &spec
->private_imux
[0];
1318 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1323 /* init callback for auto-configuration model -- overriding the default init */
1324 static int via_auto_init(struct hda_codec
*codec
)
1327 via_auto_init_multi_out(codec
);
1328 via_auto_init_hp_out(codec
);
1329 via_auto_init_analog_input(codec
);
1333 static int get_mux_nids(struct hda_codec
*codec
)
1335 struct via_spec
*spec
= codec
->spec
;
1336 hda_nid_t nid
, conn
[8];
1340 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1341 nid
= spec
->adc_nids
[i
];
1343 n
= snd_hda_get_connections(codec
, nid
, conn
,
1348 spec
->mux_nids
[i
] = nid
;
1356 static int patch_vt1708(struct hda_codec
*codec
)
1358 struct via_spec
*spec
;
1361 /* create a codec specific record */
1362 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1368 /* automatic parse from the BIOS config */
1369 err
= vt1708_parse_auto_config(codec
);
1374 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
1375 "from BIOS. Using genenic mode...\n");
1379 spec
->stream_name_analog
= "VT1708 Analog";
1380 spec
->stream_analog_playback
= &vt1708_pcm_analog_playback
;
1381 /* disable 32bit format on VT1708 */
1382 if (codec
->vendor_id
== 0x11061708)
1383 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
1384 spec
->stream_analog_capture
= &vt1708_pcm_analog_capture
;
1386 spec
->stream_name_digital
= "VT1708 Digital";
1387 spec
->stream_digital_playback
= &vt1708_pcm_digital_playback
;
1388 spec
->stream_digital_capture
= &vt1708_pcm_digital_capture
;
1391 if (!spec
->adc_nids
&& spec
->input_mux
) {
1392 spec
->adc_nids
= vt1708_adc_nids
;
1393 spec
->num_adc_nids
= ARRAY_SIZE(vt1708_adc_nids
);
1394 spec
->mixers
[spec
->num_mixers
] = vt1708_capture_mixer
;
1398 codec
->patch_ops
= via_patch_ops
;
1400 codec
->patch_ops
.init
= via_auto_init
;
1401 #ifdef CONFIG_SND_HDA_POWER_SAVE
1402 spec
->loopback
.amplist
= vt1708_loopbacks
;
1408 /* capture mixer elements */
1409 static struct snd_kcontrol_new vt1709_capture_mixer
[] = {
1410 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT
),
1411 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT
),
1412 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT
),
1413 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT
),
1414 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT
),
1415 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT
),
1417 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1418 /* The multiple "Capture Source" controls confuse alsamixer
1419 * So call somewhat different..
1421 /* .name = "Capture Source", */
1422 .name
= "Input Source",
1424 .info
= via_mux_enum_info
,
1425 .get
= via_mux_enum_get
,
1426 .put
= via_mux_enum_put
,
1431 static struct hda_verb vt1709_uniwill_init_verbs
[] = {
1432 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
1437 * generic initialization of ADC, input mixers and output mixers
1439 static struct hda_verb vt1709_10ch_volume_init_verbs
[] = {
1441 * Unmute ADC0-2 and set the default input to mic-in
1443 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1444 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1445 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1448 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1451 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1452 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1453 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1454 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1455 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1456 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1459 * Set up output selector (0x1a, 0x1b, 0x29)
1461 /* set vol=0 to output mixers */
1462 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1463 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1464 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1467 * Unmute PW3 and PW4
1469 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1470 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1472 /* Set input of PW4 as AOW4 */
1473 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
1474 /* PW9 Output enable */
1475 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1479 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback
= {
1483 .nid
= 0x10, /* NID to query formats and rates */
1485 .open
= via_playback_pcm_open
,
1486 .prepare
= via_playback_pcm_prepare
,
1487 .cleanup
= via_playback_pcm_cleanup
1491 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback
= {
1495 .nid
= 0x10, /* NID to query formats and rates */
1497 .open
= via_playback_pcm_open
,
1498 .prepare
= via_playback_pcm_prepare
,
1499 .cleanup
= via_playback_pcm_cleanup
1503 static struct hda_pcm_stream vt1709_pcm_analog_capture
= {
1507 .nid
= 0x14, /* NID to query formats and rates */
1509 .prepare
= via_capture_pcm_prepare
,
1510 .cleanup
= via_capture_pcm_cleanup
1514 static struct hda_pcm_stream vt1709_pcm_digital_playback
= {
1518 /* NID is set in via_build_pcms */
1520 .open
= via_dig_playback_pcm_open
,
1521 .close
= via_dig_playback_pcm_close
1525 static struct hda_pcm_stream vt1709_pcm_digital_capture
= {
1531 static int vt1709_auto_fill_dac_nids(struct via_spec
*spec
,
1532 const struct auto_pin_cfg
*cfg
)
1537 if (cfg
->line_outs
== 4) /* 10 channels */
1538 spec
->multiout
.num_dacs
= cfg
->line_outs
+1; /* AOW0~AOW4 */
1539 else if (cfg
->line_outs
== 3) /* 6 channels */
1540 spec
->multiout
.num_dacs
= cfg
->line_outs
; /* AOW0~AOW2 */
1542 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1544 if (cfg
->line_outs
== 4) { /* 10 channels */
1545 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1546 nid
= cfg
->line_out_pins
[i
];
1548 /* config dac list */
1550 case AUTO_SEQ_FRONT
:
1552 spec
->multiout
.dac_nids
[i
] = 0x10;
1554 case AUTO_SEQ_CENLFE
:
1556 spec
->multiout
.dac_nids
[i
] = 0x12;
1558 case AUTO_SEQ_SURROUND
:
1560 spec
->multiout
.dac_nids
[i
] = 0x11;
1564 spec
->multiout
.dac_nids
[i
] = 0x27;
1571 spec
->multiout
.dac_nids
[cfg
->line_outs
] = 0x28; /* AOW4 */
1573 } else if (cfg
->line_outs
== 3) { /* 6 channels */
1574 for(i
= 0; i
< cfg
->line_outs
; i
++) {
1575 nid
= cfg
->line_out_pins
[i
];
1577 /* config dac list */
1579 case AUTO_SEQ_FRONT
:
1581 spec
->multiout
.dac_nids
[i
] = 0x10;
1583 case AUTO_SEQ_CENLFE
:
1585 spec
->multiout
.dac_nids
[i
] = 0x12;
1587 case AUTO_SEQ_SURROUND
:
1589 spec
->multiout
.dac_nids
[i
] = 0x11;
1601 /* add playback controls from the parsed DAC table */
1602 static int vt1709_auto_create_multi_out_ctls(struct via_spec
*spec
,
1603 const struct auto_pin_cfg
*cfg
)
1606 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1610 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1611 nid
= cfg
->line_out_pins
[i
];
1616 if (i
== AUTO_SEQ_CENLFE
) {
1618 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1619 "Center Playback Volume",
1620 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1624 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1625 "LFE Playback Volume",
1626 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1630 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1631 "Center Playback Switch",
1632 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1636 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1637 "LFE Playback Switch",
1638 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1642 } else if (i
== AUTO_SEQ_FRONT
){
1643 /* add control to mixer index 0 */
1644 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1645 "Master Front Playback Volume",
1646 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1650 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1651 "Master Front Playback Switch",
1652 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1657 /* add control to PW3 */
1658 sprintf(name
, "%s Playback Volume", chname
[i
]);
1659 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1660 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1664 sprintf(name
, "%s Playback Switch", chname
[i
]);
1665 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1666 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1670 } else if (i
== AUTO_SEQ_SURROUND
) {
1671 sprintf(name
, "%s Playback Volume", chname
[i
]);
1672 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1673 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1677 sprintf(name
, "%s Playback Switch", chname
[i
]);
1678 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1679 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1683 } else if (i
== AUTO_SEQ_SIDE
) {
1684 sprintf(name
, "%s Playback Volume", chname
[i
]);
1685 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1686 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1690 sprintf(name
, "%s Playback Switch", chname
[i
]);
1691 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1692 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1702 static int vt1709_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1709 if (spec
->multiout
.num_dacs
== 5) /* 10 channels */
1710 spec
->multiout
.hp_nid
= VT1709_HP_DAC_NID
;
1711 else if (spec
->multiout
.num_dacs
== 3) /* 6 channels */
1712 spec
->multiout
.hp_nid
= 0;
1714 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1715 "Headphone Playback Volume",
1716 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1719 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1720 "Headphone Playback Switch",
1721 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1728 /* create playback/capture controls for input pins */
1729 static int vt1709_auto_create_analog_input_ctls(struct via_spec
*spec
,
1730 const struct auto_pin_cfg
*cfg
)
1732 static char *labels
[] = {
1733 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1735 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1736 int i
, err
, idx
= 0;
1738 /* for internal loopback recording select */
1739 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1740 imux
->items
[imux
->num_items
].index
= idx
;
1743 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1744 if (!cfg
->input_pins
[i
])
1747 switch (cfg
->input_pins
[i
]) {
1748 case 0x1d: /* Mic */
1752 case 0x1e: /* Line In */
1756 case 0x21: /* Front Mic */
1764 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
1768 imux
->items
[imux
->num_items
].label
= labels
[i
];
1769 imux
->items
[imux
->num_items
].index
= idx
;
1775 static int vt1709_parse_auto_config(struct hda_codec
*codec
)
1777 struct via_spec
*spec
= codec
->spec
;
1780 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1783 err
= vt1709_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1786 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1787 return 0; /* can't find valid BIOS pin config */
1789 err
= vt1709_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1792 err
= vt1709_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1795 err
= vt1709_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1799 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1801 if (spec
->autocfg
.dig_outs
)
1802 spec
->multiout
.dig_out_nid
= VT1709_DIGOUT_NID
;
1803 spec
->dig_in_pin
= VT1709_DIGIN_PIN
;
1804 if (spec
->autocfg
.dig_in_pin
)
1805 spec
->dig_in_nid
= VT1709_DIGIN_NID
;
1807 if (spec
->kctls
.list
)
1808 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
1810 spec
->input_mux
= &spec
->private_imux
[0];
1813 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1818 #ifdef CONFIG_SND_HDA_POWER_SAVE
1819 static struct hda_amp_list vt1709_loopbacks
[] = {
1820 { 0x18, HDA_INPUT
, 1 },
1821 { 0x18, HDA_INPUT
, 2 },
1822 { 0x18, HDA_INPUT
, 3 },
1823 { 0x18, HDA_INPUT
, 4 },
1828 static int patch_vt1709_10ch(struct hda_codec
*codec
)
1830 struct via_spec
*spec
;
1833 /* create a codec specific record */
1834 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1840 err
= vt1709_parse_auto_config(codec
);
1845 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
1846 "Using genenic mode...\n");
1849 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_10ch_volume_init_verbs
;
1850 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
1852 spec
->stream_name_analog
= "VT1709 Analog";
1853 spec
->stream_analog_playback
= &vt1709_10ch_pcm_analog_playback
;
1854 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
1856 spec
->stream_name_digital
= "VT1709 Digital";
1857 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
1858 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
1861 if (!spec
->adc_nids
&& spec
->input_mux
) {
1862 spec
->adc_nids
= vt1709_adc_nids
;
1863 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
1864 get_mux_nids(codec
);
1865 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
1869 codec
->patch_ops
= via_patch_ops
;
1871 codec
->patch_ops
.init
= via_auto_init
;
1872 codec
->patch_ops
.unsol_event
= via_unsol_event
;
1873 #ifdef CONFIG_SND_HDA_POWER_SAVE
1874 spec
->loopback
.amplist
= vt1709_loopbacks
;
1880 * generic initialization of ADC, input mixers and output mixers
1882 static struct hda_verb vt1709_6ch_volume_init_verbs
[] = {
1884 * Unmute ADC0-2 and set the default input to mic-in
1886 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1887 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1888 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1891 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1894 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1895 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1896 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1897 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1898 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1899 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1902 * Set up output selector (0x1a, 0x1b, 0x29)
1904 /* set vol=0 to output mixers */
1905 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1906 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1907 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1910 * Unmute PW3 and PW4
1912 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1913 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1915 /* Set input of PW4 as MW0 */
1916 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
1917 /* PW9 Output enable */
1918 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1922 static int patch_vt1709_6ch(struct hda_codec
*codec
)
1924 struct via_spec
*spec
;
1927 /* create a codec specific record */
1928 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1934 err
= vt1709_parse_auto_config(codec
);
1939 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
1940 "Using genenic mode...\n");
1943 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_6ch_volume_init_verbs
;
1944 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
1946 spec
->stream_name_analog
= "VT1709 Analog";
1947 spec
->stream_analog_playback
= &vt1709_6ch_pcm_analog_playback
;
1948 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
1950 spec
->stream_name_digital
= "VT1709 Digital";
1951 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
1952 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
1955 if (!spec
->adc_nids
&& spec
->input_mux
) {
1956 spec
->adc_nids
= vt1709_adc_nids
;
1957 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
1958 get_mux_nids(codec
);
1959 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
1963 codec
->patch_ops
= via_patch_ops
;
1965 codec
->patch_ops
.init
= via_auto_init
;
1966 codec
->patch_ops
.unsol_event
= via_unsol_event
;
1967 #ifdef CONFIG_SND_HDA_POWER_SAVE
1968 spec
->loopback
.amplist
= vt1709_loopbacks
;
1973 /* capture mixer elements */
1974 static struct snd_kcontrol_new vt1708B_capture_mixer
[] = {
1975 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
1976 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
1977 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
1978 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
1980 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1981 /* The multiple "Capture Source" controls confuse alsamixer
1982 * So call somewhat different..
1984 /* .name = "Capture Source", */
1985 .name
= "Input Source",
1987 .info
= via_mux_enum_info
,
1988 .get
= via_mux_enum_get
,
1989 .put
= via_mux_enum_put
,
1994 * generic initialization of ADC, input mixers and output mixers
1996 static struct hda_verb vt1708B_8ch_volume_init_verbs
[] = {
1998 * Unmute ADC0-1 and set the default input to mic-in
2000 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2001 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2004 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2007 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2008 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2009 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2010 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2011 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2012 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2015 * Set up output mixers
2017 /* set vol=0 to output mixers */
2018 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2019 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2020 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2022 /* Setup default input to PW4 */
2023 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x1},
2024 /* PW9 Output enable */
2025 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2026 /* PW10 Input enable */
2027 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2031 static struct hda_verb vt1708B_4ch_volume_init_verbs
[] = {
2033 * Unmute ADC0-1 and set the default input to mic-in
2035 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2036 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2039 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2042 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2043 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2044 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2045 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2046 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2047 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2050 * Set up output mixers
2052 /* set vol=0 to output mixers */
2053 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2054 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2055 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2057 /* Setup default input of PW4 to MW0 */
2058 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2059 /* PW9 Output enable */
2060 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2061 /* PW10 Input enable */
2062 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2066 static struct hda_verb vt1708B_uniwill_init_verbs
[] = {
2067 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2071 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback
= {
2075 .nid
= 0x10, /* NID to query formats and rates */
2077 .open
= via_playback_pcm_open
,
2078 .prepare
= via_playback_multi_pcm_prepare
,
2079 .cleanup
= via_playback_multi_pcm_cleanup
2083 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback
= {
2087 .nid
= 0x10, /* NID to query formats and rates */
2089 .open
= via_playback_pcm_open
,
2090 .prepare
= via_playback_multi_pcm_prepare
,
2091 .cleanup
= via_playback_multi_pcm_cleanup
2095 static struct hda_pcm_stream vt1708B_pcm_analog_capture
= {
2099 .nid
= 0x13, /* NID to query formats and rates */
2101 .prepare
= via_capture_pcm_prepare
,
2102 .cleanup
= via_capture_pcm_cleanup
2106 static struct hda_pcm_stream vt1708B_pcm_digital_playback
= {
2110 /* NID is set in via_build_pcms */
2112 .open
= via_dig_playback_pcm_open
,
2113 .close
= via_dig_playback_pcm_close
,
2114 .prepare
= via_dig_playback_pcm_prepare
,
2115 .cleanup
= via_dig_playback_pcm_cleanup
2119 static struct hda_pcm_stream vt1708B_pcm_digital_capture
= {
2125 /* fill in the dac_nids table from the parsed pin configuration */
2126 static int vt1708B_auto_fill_dac_nids(struct via_spec
*spec
,
2127 const struct auto_pin_cfg
*cfg
)
2132 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2134 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2136 for (i
= 0; i
< 4; i
++) {
2137 nid
= cfg
->line_out_pins
[i
];
2139 /* config dac list */
2141 case AUTO_SEQ_FRONT
:
2142 spec
->multiout
.dac_nids
[i
] = 0x10;
2144 case AUTO_SEQ_CENLFE
:
2145 spec
->multiout
.dac_nids
[i
] = 0x24;
2147 case AUTO_SEQ_SURROUND
:
2148 spec
->multiout
.dac_nids
[i
] = 0x11;
2151 spec
->multiout
.dac_nids
[i
] = 0x25;
2160 /* add playback controls from the parsed DAC table */
2161 static int vt1708B_auto_create_multi_out_ctls(struct via_spec
*spec
,
2162 const struct auto_pin_cfg
*cfg
)
2165 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2166 hda_nid_t nid_vols
[] = {0x16, 0x18, 0x26, 0x27};
2167 hda_nid_t nid
, nid_vol
= 0;
2170 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2171 nid
= cfg
->line_out_pins
[i
];
2176 nid_vol
= nid_vols
[i
];
2178 if (i
== AUTO_SEQ_CENLFE
) {
2180 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2181 "Center Playback Volume",
2182 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2186 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2187 "LFE Playback Volume",
2188 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2192 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2193 "Center Playback Switch",
2194 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2198 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2199 "LFE Playback Switch",
2200 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2204 } else if (i
== AUTO_SEQ_FRONT
) {
2205 /* add control to mixer index 0 */
2206 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2207 "Master Front Playback Volume",
2208 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2212 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2213 "Master Front Playback Switch",
2214 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2219 /* add control to PW3 */
2220 sprintf(name
, "%s Playback Volume", chname
[i
]);
2221 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2222 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2226 sprintf(name
, "%s Playback Switch", chname
[i
]);
2227 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2228 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2233 sprintf(name
, "%s Playback Volume", chname
[i
]);
2234 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2235 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2239 sprintf(name
, "%s Playback Switch", chname
[i
]);
2240 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2241 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2251 static int vt1708B_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2258 spec
->multiout
.hp_nid
= VT1708B_HP_NID
; /* AOW3 */
2260 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2261 "Headphone Playback Volume",
2262 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2265 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2266 "Headphone Playback Switch",
2267 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2271 create_hp_imux(spec
);
2276 /* create playback/capture controls for input pins */
2277 static int vt1708B_auto_create_analog_input_ctls(struct via_spec
*spec
,
2278 const struct auto_pin_cfg
*cfg
)
2280 static char *labels
[] = {
2281 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2283 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2284 int i
, err
, idx
= 0;
2286 /* for internal loopback recording select */
2287 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2288 imux
->items
[imux
->num_items
].index
= idx
;
2291 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2292 if (!cfg
->input_pins
[i
])
2295 switch (cfg
->input_pins
[i
]) {
2296 case 0x1a: /* Mic */
2300 case 0x1b: /* Line In */
2304 case 0x1e: /* Front Mic */
2312 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
2316 imux
->items
[imux
->num_items
].label
= labels
[i
];
2317 imux
->items
[imux
->num_items
].index
= idx
;
2323 static int vt1708B_parse_auto_config(struct hda_codec
*codec
)
2325 struct via_spec
*spec
= codec
->spec
;
2328 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2331 err
= vt1708B_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2334 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2335 return 0; /* can't find valid BIOS pin config */
2337 err
= vt1708B_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2340 err
= vt1708B_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2343 err
= vt1708B_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2347 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2349 if (spec
->autocfg
.dig_outs
)
2350 spec
->multiout
.dig_out_nid
= VT1708B_DIGOUT_NID
;
2351 spec
->dig_in_pin
= VT1708B_DIGIN_PIN
;
2352 if (spec
->autocfg
.dig_in_pin
)
2353 spec
->dig_in_nid
= VT1708B_DIGIN_NID
;
2355 if (spec
->kctls
.list
)
2356 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2358 spec
->input_mux
= &spec
->private_imux
[0];
2361 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2366 #ifdef CONFIG_SND_HDA_POWER_SAVE
2367 static struct hda_amp_list vt1708B_loopbacks
[] = {
2368 { 0x16, HDA_INPUT
, 1 },
2369 { 0x16, HDA_INPUT
, 2 },
2370 { 0x16, HDA_INPUT
, 3 },
2371 { 0x16, HDA_INPUT
, 4 },
2376 static int patch_vt1708B_8ch(struct hda_codec
*codec
)
2378 struct via_spec
*spec
;
2381 /* create a codec specific record */
2382 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2388 /* automatic parse from the BIOS config */
2389 err
= vt1708B_parse_auto_config(codec
);
2394 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2395 "from BIOS. Using genenic mode...\n");
2398 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_8ch_volume_init_verbs
;
2399 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2401 spec
->stream_name_analog
= "VT1708B Analog";
2402 spec
->stream_analog_playback
= &vt1708B_8ch_pcm_analog_playback
;
2403 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2405 spec
->stream_name_digital
= "VT1708B Digital";
2406 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2407 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2409 if (!spec
->adc_nids
&& spec
->input_mux
) {
2410 spec
->adc_nids
= vt1708B_adc_nids
;
2411 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2412 get_mux_nids(codec
);
2413 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2417 codec
->patch_ops
= via_patch_ops
;
2419 codec
->patch_ops
.init
= via_auto_init
;
2420 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2421 #ifdef CONFIG_SND_HDA_POWER_SAVE
2422 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2428 static int patch_vt1708B_4ch(struct hda_codec
*codec
)
2430 struct via_spec
*spec
;
2433 /* create a codec specific record */
2434 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2440 /* automatic parse from the BIOS config */
2441 err
= vt1708B_parse_auto_config(codec
);
2446 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2447 "from BIOS. Using genenic mode...\n");
2450 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_4ch_volume_init_verbs
;
2451 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2453 spec
->stream_name_analog
= "VT1708B Analog";
2454 spec
->stream_analog_playback
= &vt1708B_4ch_pcm_analog_playback
;
2455 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2457 spec
->stream_name_digital
= "VT1708B Digital";
2458 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2459 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2461 if (!spec
->adc_nids
&& spec
->input_mux
) {
2462 spec
->adc_nids
= vt1708B_adc_nids
;
2463 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2464 get_mux_nids(codec
);
2465 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2469 codec
->patch_ops
= via_patch_ops
;
2471 codec
->patch_ops
.init
= via_auto_init
;
2472 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2473 #ifdef CONFIG_SND_HDA_POWER_SAVE
2474 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2480 /* Patch for VT1708S */
2482 /* VT1708S software backdoor based override for buggy hardware micboost
2484 #define MIC_BOOST_VOLUME(xname, nid) { \
2485 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2488 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2489 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2490 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2491 .info = mic_boost_volume_info, \
2492 .get = snd_hda_mixer_amp_volume_get, \
2493 .put = snd_hda_mixer_amp_volume_put, \
2494 .tlv = { .c = mic_boost_tlv }, \
2495 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2497 /* capture mixer elements */
2498 static struct snd_kcontrol_new vt1708S_capture_mixer
[] = {
2499 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
2500 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
2501 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
2502 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
2503 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2504 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2506 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2507 /* The multiple "Capture Source" controls confuse alsamixer
2508 * So call somewhat different..
2510 /* .name = "Capture Source", */
2511 .name
= "Input Source",
2513 .info
= via_mux_enum_info
,
2514 .get
= via_mux_enum_get
,
2515 .put
= via_mux_enum_put
,
2520 static struct hda_verb vt1708S_volume_init_verbs
[] = {
2521 /* Unmute ADC0-1 and set the default input to mic-in */
2522 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2523 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2525 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2526 * analog-loopback mixer widget */
2527 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2528 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2529 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2530 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2531 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2532 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2534 /* Setup default input of PW4 to MW0 */
2535 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2536 /* PW9, PW10 Output enable */
2537 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2538 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2539 /* Enable Mic Boost Volume backdoor */
2544 static struct hda_verb vt1708S_uniwill_init_verbs
[] = {
2545 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2549 static struct hda_pcm_stream vt1708S_pcm_analog_playback
= {
2553 .nid
= 0x10, /* NID to query formats and rates */
2555 .open
= via_playback_pcm_open
,
2556 .prepare
= via_playback_pcm_prepare
,
2557 .cleanup
= via_playback_pcm_cleanup
2561 static struct hda_pcm_stream vt1708S_pcm_analog_capture
= {
2565 .nid
= 0x13, /* NID to query formats and rates */
2567 .prepare
= via_capture_pcm_prepare
,
2568 .cleanup
= via_capture_pcm_cleanup
2572 static struct hda_pcm_stream vt1708S_pcm_digital_playback
= {
2576 /* NID is set in via_build_pcms */
2578 .open
= via_dig_playback_pcm_open
,
2579 .close
= via_dig_playback_pcm_close
,
2580 .prepare
= via_dig_playback_pcm_prepare
,
2581 .cleanup
= via_dig_playback_pcm_cleanup
2585 /* fill in the dac_nids table from the parsed pin configuration */
2586 static int vt1708S_auto_fill_dac_nids(struct via_spec
*spec
,
2587 const struct auto_pin_cfg
*cfg
)
2592 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2594 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2596 for (i
= 0; i
< 4; i
++) {
2597 nid
= cfg
->line_out_pins
[i
];
2599 /* config dac list */
2601 case AUTO_SEQ_FRONT
:
2602 spec
->multiout
.dac_nids
[i
] = 0x10;
2604 case AUTO_SEQ_CENLFE
:
2605 spec
->multiout
.dac_nids
[i
] = 0x24;
2607 case AUTO_SEQ_SURROUND
:
2608 spec
->multiout
.dac_nids
[i
] = 0x11;
2611 spec
->multiout
.dac_nids
[i
] = 0x25;
2620 /* add playback controls from the parsed DAC table */
2621 static int vt1708S_auto_create_multi_out_ctls(struct via_spec
*spec
,
2622 const struct auto_pin_cfg
*cfg
)
2625 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2626 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x24, 0x25};
2627 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x26, 0x27};
2628 hda_nid_t nid
, nid_vol
, nid_mute
;
2631 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2632 nid
= cfg
->line_out_pins
[i
];
2637 nid_vol
= nid_vols
[i
];
2638 nid_mute
= nid_mutes
[i
];
2640 if (i
== AUTO_SEQ_CENLFE
) {
2642 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2643 "Center Playback Volume",
2644 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2648 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2649 "LFE Playback Volume",
2650 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2654 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2655 "Center Playback Switch",
2656 HDA_COMPOSE_AMP_VAL(nid_mute
,
2661 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2662 "LFE Playback Switch",
2663 HDA_COMPOSE_AMP_VAL(nid_mute
,
2668 } else if (i
== AUTO_SEQ_FRONT
) {
2669 /* add control to mixer index 0 */
2670 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2671 "Master Front Playback Volume",
2672 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2676 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2677 "Master Front Playback Switch",
2678 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2684 sprintf(name
, "%s Playback Volume", chname
[i
]);
2685 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2686 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2690 sprintf(name
, "%s Playback Switch", chname
[i
]);
2691 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2692 HDA_COMPOSE_AMP_VAL(nid_mute
,
2698 sprintf(name
, "%s Playback Volume", chname
[i
]);
2699 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2700 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2704 sprintf(name
, "%s Playback Switch", chname
[i
]);
2705 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2706 HDA_COMPOSE_AMP_VAL(nid_mute
,
2717 static int vt1708S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2724 spec
->multiout
.hp_nid
= VT1708S_HP_NID
; /* AOW3 */
2726 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2727 "Headphone Playback Volume",
2728 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
2732 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2733 "Headphone Playback Switch",
2734 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2738 create_hp_imux(spec
);
2743 /* create playback/capture controls for input pins */
2744 static int vt1708S_auto_create_analog_input_ctls(struct via_spec
*spec
,
2745 const struct auto_pin_cfg
*cfg
)
2747 static char *labels
[] = {
2748 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2750 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2751 int i
, err
, idx
= 0;
2753 /* for internal loopback recording select */
2754 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2755 imux
->items
[imux
->num_items
].index
= 5;
2758 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2759 if (!cfg
->input_pins
[i
])
2762 switch (cfg
->input_pins
[i
]) {
2763 case 0x1a: /* Mic */
2767 case 0x1b: /* Line In */
2771 case 0x1e: /* Front Mic */
2779 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
2783 imux
->items
[imux
->num_items
].label
= labels
[i
];
2784 imux
->items
[imux
->num_items
].index
= idx
-1;
2790 /* fill out digital output widgets; one for master and one for slave outputs */
2791 static void fill_dig_outs(struct hda_codec
*codec
)
2793 struct via_spec
*spec
= codec
->spec
;
2796 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
2800 nid
= spec
->autocfg
.dig_out_pins
[i
];
2803 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
2806 if (!spec
->multiout
.dig_out_nid
)
2807 spec
->multiout
.dig_out_nid
= nid
;
2809 spec
->slave_dig_outs
[0] = nid
;
2810 break; /* at most two dig outs */
2815 static int vt1708S_parse_auto_config(struct hda_codec
*codec
)
2817 struct via_spec
*spec
= codec
->spec
;
2820 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2823 err
= vt1708S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2826 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2827 return 0; /* can't find valid BIOS pin config */
2829 err
= vt1708S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2832 err
= vt1708S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2835 err
= vt1708S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2839 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2841 fill_dig_outs(codec
);
2843 if (spec
->kctls
.list
)
2844 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2846 spec
->input_mux
= &spec
->private_imux
[0];
2849 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2854 #ifdef CONFIG_SND_HDA_POWER_SAVE
2855 static struct hda_amp_list vt1708S_loopbacks
[] = {
2856 { 0x16, HDA_INPUT
, 1 },
2857 { 0x16, HDA_INPUT
, 2 },
2858 { 0x16, HDA_INPUT
, 3 },
2859 { 0x16, HDA_INPUT
, 4 },
2864 static int patch_vt1708S(struct hda_codec
*codec
)
2866 struct via_spec
*spec
;
2869 /* create a codec specific record */
2870 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2876 /* automatic parse from the BIOS config */
2877 err
= vt1708S_parse_auto_config(codec
);
2882 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2883 "from BIOS. Using genenic mode...\n");
2886 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_volume_init_verbs
;
2887 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_uniwill_init_verbs
;
2889 spec
->stream_name_analog
= "VT1708S Analog";
2890 spec
->stream_analog_playback
= &vt1708S_pcm_analog_playback
;
2891 spec
->stream_analog_capture
= &vt1708S_pcm_analog_capture
;
2893 spec
->stream_name_digital
= "VT1708S Digital";
2894 spec
->stream_digital_playback
= &vt1708S_pcm_digital_playback
;
2896 if (!spec
->adc_nids
&& spec
->input_mux
) {
2897 spec
->adc_nids
= vt1708S_adc_nids
;
2898 spec
->num_adc_nids
= ARRAY_SIZE(vt1708S_adc_nids
);
2899 get_mux_nids(codec
);
2900 spec
->mixers
[spec
->num_mixers
] = vt1708S_capture_mixer
;
2904 codec
->patch_ops
= via_patch_ops
;
2906 codec
->patch_ops
.init
= via_auto_init
;
2907 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2908 #ifdef CONFIG_SND_HDA_POWER_SAVE
2909 spec
->loopback
.amplist
= vt1708S_loopbacks
;
2915 /* Patch for VT1702 */
2917 /* capture mixer elements */
2918 static struct snd_kcontrol_new vt1702_capture_mixer
[] = {
2919 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT
),
2920 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT
),
2921 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT
),
2922 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT
),
2923 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT
),
2924 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT
),
2925 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2928 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2929 /* The multiple "Capture Source" controls confuse alsamixer
2930 * So call somewhat different..
2932 /* .name = "Capture Source", */
2933 .name
= "Input Source",
2935 .info
= via_mux_enum_info
,
2936 .get
= via_mux_enum_get
,
2937 .put
= via_mux_enum_put
,
2942 static struct hda_verb vt1702_volume_init_verbs
[] = {
2944 * Unmute ADC0-1 and set the default input to mic-in
2946 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2947 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2948 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2951 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2954 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2955 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2956 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2957 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2958 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2959 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
2961 /* Setup default input of PW4 to MW0 */
2962 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x1},
2963 /* PW6 PW7 Output enable */
2964 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2965 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2969 static struct hda_verb vt1702_uniwill_init_verbs
[] = {
2970 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_GPIO_EVENT
},
2971 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2975 static struct hda_pcm_stream vt1702_pcm_analog_playback
= {
2979 .nid
= 0x10, /* NID to query formats and rates */
2981 .open
= via_playback_pcm_open
,
2982 .prepare
= via_playback_multi_pcm_prepare
,
2983 .cleanup
= via_playback_multi_pcm_cleanup
2987 static struct hda_pcm_stream vt1702_pcm_analog_capture
= {
2991 .nid
= 0x12, /* NID to query formats and rates */
2993 .prepare
= via_capture_pcm_prepare
,
2994 .cleanup
= via_capture_pcm_cleanup
2998 static struct hda_pcm_stream vt1702_pcm_digital_playback
= {
3002 /* NID is set in via_build_pcms */
3004 .open
= via_dig_playback_pcm_open
,
3005 .close
= via_dig_playback_pcm_close
,
3006 .prepare
= via_dig_playback_pcm_prepare
,
3007 .cleanup
= via_dig_playback_pcm_cleanup
3011 /* fill in the dac_nids table from the parsed pin configuration */
3012 static int vt1702_auto_fill_dac_nids(struct via_spec
*spec
,
3013 const struct auto_pin_cfg
*cfg
)
3015 spec
->multiout
.num_dacs
= 1;
3016 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3018 if (cfg
->line_out_pins
[0]) {
3019 /* config dac list */
3020 spec
->multiout
.dac_nids
[0] = 0x10;
3026 /* add playback controls from the parsed DAC table */
3027 static int vt1702_auto_create_line_out_ctls(struct via_spec
*spec
,
3028 const struct auto_pin_cfg
*cfg
)
3032 if (!cfg
->line_out_pins
[0])
3035 /* add control to mixer index 0 */
3036 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3037 "Master Front Playback Volume",
3038 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3041 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3042 "Master Front Playback Switch",
3043 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3048 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3049 "Front Playback Volume",
3050 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
));
3053 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3054 "Front Playback Switch",
3055 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT
));
3062 static int vt1702_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3069 spec
->multiout
.hp_nid
= 0x1D;
3071 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3072 "Headphone Playback Volume",
3073 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT
));
3077 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3078 "Headphone Playback Switch",
3079 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3083 create_hp_imux(spec
);
3088 /* create playback/capture controls for input pins */
3089 static int vt1702_auto_create_analog_input_ctls(struct via_spec
*spec
,
3090 const struct auto_pin_cfg
*cfg
)
3092 static char *labels
[] = {
3093 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3095 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3096 int i
, err
, idx
= 0;
3098 /* for internal loopback recording select */
3099 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3100 imux
->items
[imux
->num_items
].index
= 3;
3103 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3104 if (!cfg
->input_pins
[i
])
3107 switch (cfg
->input_pins
[i
]) {
3108 case 0x14: /* Mic */
3112 case 0x15: /* Line In */
3116 case 0x18: /* Front Mic */
3120 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
],
3121 labels
[i
], idx
, 0x1A);
3124 imux
->items
[imux
->num_items
].label
= labels
[i
];
3125 imux
->items
[imux
->num_items
].index
= idx
-1;
3131 static int vt1702_parse_auto_config(struct hda_codec
*codec
)
3133 struct via_spec
*spec
= codec
->spec
;
3136 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3139 err
= vt1702_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3142 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3143 return 0; /* can't find valid BIOS pin config */
3145 err
= vt1702_auto_create_line_out_ctls(spec
, &spec
->autocfg
);
3148 err
= vt1702_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3151 err
= vt1702_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3155 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3157 fill_dig_outs(codec
);
3159 if (spec
->kctls
.list
)
3160 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3162 spec
->input_mux
= &spec
->private_imux
[0];
3165 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3170 #ifdef CONFIG_SND_HDA_POWER_SAVE
3171 static struct hda_amp_list vt1702_loopbacks
[] = {
3172 { 0x1A, HDA_INPUT
, 1 },
3173 { 0x1A, HDA_INPUT
, 2 },
3174 { 0x1A, HDA_INPUT
, 3 },
3175 { 0x1A, HDA_INPUT
, 4 },
3180 static int patch_vt1702(struct hda_codec
*codec
)
3182 struct via_spec
*spec
;
3184 unsigned int response
;
3185 unsigned char control
;
3187 /* create a codec specific record */
3188 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3194 /* automatic parse from the BIOS config */
3195 err
= vt1702_parse_auto_config(codec
);
3200 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3201 "from BIOS. Using genenic mode...\n");
3204 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_volume_init_verbs
;
3205 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_uniwill_init_verbs
;
3207 spec
->stream_name_analog
= "VT1702 Analog";
3208 spec
->stream_analog_playback
= &vt1702_pcm_analog_playback
;
3209 spec
->stream_analog_capture
= &vt1702_pcm_analog_capture
;
3211 spec
->stream_name_digital
= "VT1702 Digital";
3212 spec
->stream_digital_playback
= &vt1702_pcm_digital_playback
;
3214 if (!spec
->adc_nids
&& spec
->input_mux
) {
3215 spec
->adc_nids
= vt1702_adc_nids
;
3216 spec
->num_adc_nids
= ARRAY_SIZE(vt1702_adc_nids
);
3217 get_mux_nids(codec
);
3218 spec
->mixers
[spec
->num_mixers
] = vt1702_capture_mixer
;
3222 codec
->patch_ops
= via_patch_ops
;
3224 codec
->patch_ops
.init
= via_auto_init
;
3225 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3226 #ifdef CONFIG_SND_HDA_POWER_SAVE
3227 spec
->loopback
.amplist
= vt1702_loopbacks
;
3231 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF8C, 0);
3232 control
= (unsigned char)(response
& 0xff);
3234 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF88, control
);
3236 /* Enable GPIO 0&1 for volume&mute control */
3237 /* Enable GPIO 2 for DMIC-DATA */
3238 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF84, 0);
3239 control
= (unsigned char)((response
>> 16) & 0x3f);
3240 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF82, control
);
3248 static struct hda_codec_preset snd_hda_preset_via
[] = {
3249 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
3250 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
3251 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
3252 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
3253 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
3254 .patch
= patch_vt1709_10ch
},
3255 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
3256 .patch
= patch_vt1709_10ch
},
3257 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
3258 .patch
= patch_vt1709_10ch
},
3259 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
3260 .patch
= patch_vt1709_10ch
},
3261 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
3262 .patch
= patch_vt1709_6ch
},
3263 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
3264 .patch
= patch_vt1709_6ch
},
3265 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
3266 .patch
= patch_vt1709_6ch
},
3267 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
3268 .patch
= patch_vt1709_6ch
},
3269 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
3270 .patch
= patch_vt1708B_8ch
},
3271 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
3272 .patch
= patch_vt1708B_8ch
},
3273 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
3274 .patch
= patch_vt1708B_8ch
},
3275 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
3276 .patch
= patch_vt1708B_8ch
},
3277 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
3278 .patch
= patch_vt1708B_4ch
},
3279 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
3280 .patch
= patch_vt1708B_4ch
},
3281 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
3282 .patch
= patch_vt1708B_4ch
},
3283 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
3284 .patch
= patch_vt1708B_4ch
},
3285 { .id
= 0x11060397, .name
= "VT1708S",
3286 .patch
= patch_vt1708S
},
3287 { .id
= 0x11061397, .name
= "VT1708S",
3288 .patch
= patch_vt1708S
},
3289 { .id
= 0x11062397, .name
= "VT1708S",
3290 .patch
= patch_vt1708S
},
3291 { .id
= 0x11063397, .name
= "VT1708S",
3292 .patch
= patch_vt1708S
},
3293 { .id
= 0x11064397, .name
= "VT1708S",
3294 .patch
= patch_vt1708S
},
3295 { .id
= 0x11065397, .name
= "VT1708S",
3296 .patch
= patch_vt1708S
},
3297 { .id
= 0x11066397, .name
= "VT1708S",
3298 .patch
= patch_vt1708S
},
3299 { .id
= 0x11067397, .name
= "VT1708S",
3300 .patch
= patch_vt1708S
},
3301 { .id
= 0x11060398, .name
= "VT1702",
3302 .patch
= patch_vt1702
},
3303 { .id
= 0x11061398, .name
= "VT1702",
3304 .patch
= patch_vt1702
},
3305 { .id
= 0x11062398, .name
= "VT1702",
3306 .patch
= patch_vt1702
},
3307 { .id
= 0x11063398, .name
= "VT1702",
3308 .patch
= patch_vt1702
},
3309 { .id
= 0x11064398, .name
= "VT1702",
3310 .patch
= patch_vt1702
},
3311 { .id
= 0x11065398, .name
= "VT1702",
3312 .patch
= patch_vt1702
},
3313 { .id
= 0x11066398, .name
= "VT1702",
3314 .patch
= patch_vt1702
},
3315 { .id
= 0x11067398, .name
= "VT1702",
3316 .patch
= patch_vt1702
},
3320 MODULE_ALIAS("snd-hda-codec-id:1106*");
3322 static struct hda_codec_preset_list via_list
= {
3323 .preset
= snd_hda_preset_via
,
3324 .owner
= THIS_MODULE
,
3327 MODULE_LICENSE("GPL");
3328 MODULE_DESCRIPTION("VIA HD-audio codec");
3330 static int __init
patch_via_init(void)
3332 return snd_hda_add_codec_preset(&via_list
);
3335 static void __exit
patch_via_exit(void)
3337 snd_hda_delete_codec_preset(&via_list
);
3340 module_init(patch_via_init
)
3341 module_exit(patch_via_exit
)