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
92 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
)
94 u32 vendor_id
= codec
->vendor_id
;
95 u16 ven_id
= vendor_id
>> 16;
96 u16 dev_id
= vendor_id
& 0xffff;
97 enum VIA_HDA_CODEC codec_type
;
100 if (ven_id
!= 0x1106)
101 codec_type
= UNKNOWN
;
102 else if (dev_id
>= 0x1708 && dev_id
<= 0x170b)
104 else if (dev_id
>= 0xe710 && dev_id
<= 0xe713)
105 codec_type
= VT1709_10CH
;
106 else if (dev_id
>= 0xe714 && dev_id
<= 0xe717)
107 codec_type
= VT1709_6CH
;
108 else if (dev_id
>= 0xe720 && dev_id
<= 0xe723) {
109 codec_type
= VT1708B_8CH
;
110 if (snd_hda_param_read(codec
, 0x16, AC_PAR_CONNLIST_LEN
) == 0x7)
111 codec_type
= VT1708BCE
;
112 } else if (dev_id
>= 0xe724 && dev_id
<= 0xe727)
113 codec_type
= VT1708B_4CH
;
114 else if ((dev_id
& 0xfff) == 0x397
115 && (dev_id
>> 12) < 8)
116 codec_type
= VT1708S
;
117 else if ((dev_id
& 0xfff) == 0x398
118 && (dev_id
>> 12) < 8)
121 codec_type
= UNKNOWN
;
125 #define VIA_HP_EVENT 0x01
126 #define VIA_GPIO_EVENT 0x02
140 /* Some VT1708S based boards gets the micboost setting wrong, so we have
141 * to apply some brute-force and re-write the TLV's by software. */
142 static int mic_boost_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
143 unsigned int size
, unsigned int __user
*_tlv
)
145 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
146 hda_nid_t nid
= get_amp_nid(kcontrol
);
148 if (get_codec_type(codec
) == VT1708S
149 && (nid
== 0x1a || nid
== 0x1e)) {
150 if (size
< 4 * sizeof(unsigned int))
152 if (put_user(1, _tlv
)) /* SNDRV_CTL_TLVT_DB_SCALE */
154 if (put_user(2 * sizeof(unsigned int), _tlv
+ 1))
156 if (put_user(0, _tlv
+ 2)) /* offset = 0 */
158 if (put_user(1000, _tlv
+ 3)) /* step size = 10 dB */
164 static int mic_boost_volume_info(struct snd_kcontrol
*kcontrol
,
165 struct snd_ctl_elem_info
*uinfo
)
167 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
168 hda_nid_t nid
= get_amp_nid(kcontrol
);
170 if (get_codec_type(codec
) == VT1708S
171 && (nid
== 0x1a || nid
== 0x1e)) {
172 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
174 uinfo
->value
.integer
.min
= 0;
175 uinfo
->value
.integer
.max
= 3;
180 static struct snd_kcontrol_new vt1708_control_templates
[] = {
181 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
182 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
187 /* codec parameterization */
188 struct snd_kcontrol_new
*mixers
[3];
189 unsigned int num_mixers
;
191 struct hda_verb
*init_verbs
[5];
192 unsigned int num_iverbs
;
194 char *stream_name_analog
;
195 struct hda_pcm_stream
*stream_analog_playback
;
196 struct hda_pcm_stream
*stream_analog_capture
;
198 char *stream_name_digital
;
199 struct hda_pcm_stream
*stream_digital_playback
;
200 struct hda_pcm_stream
*stream_digital_capture
;
203 struct hda_multi_out multiout
;
204 hda_nid_t slave_dig_outs
[2];
207 unsigned int num_adc_nids
;
209 hda_nid_t mux_nids
[3];
210 hda_nid_t dig_in_nid
;
211 hda_nid_t dig_in_pin
;
214 const struct hda_input_mux
*input_mux
;
215 unsigned int cur_mux
[3];
217 /* PCM information */
218 struct hda_pcm pcm_rec
[3];
220 /* dynamic controls, init_verbs and input_mux */
221 struct auto_pin_cfg autocfg
;
222 struct snd_array kctls
;
223 struct hda_input_mux private_imux
[2];
224 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
227 const struct hda_input_mux
*hp_mux
;
228 unsigned int hp_independent_mode
;
230 enum VIA_HDA_CODEC codec_type
;
232 #ifdef CONFIG_SND_HDA_POWER_SAVE
233 struct hda_loopback_check loopback
;
237 static hda_nid_t vt1708_adc_nids
[2] = {
242 static hda_nid_t vt1709_adc_nids
[3] = {
247 static hda_nid_t vt1708B_adc_nids
[2] = {
252 static hda_nid_t vt1708S_adc_nids
[2] = {
257 static hda_nid_t vt1702_adc_nids
[3] = {
262 /* add dynamic controls */
263 static int via_add_control(struct via_spec
*spec
, int type
, const char *name
,
266 struct snd_kcontrol_new
*knew
;
268 snd_array_init(&spec
->kctls
, sizeof(*knew
), 32);
269 knew
= snd_array_new(&spec
->kctls
);
272 *knew
= vt1708_control_templates
[type
];
273 knew
->name
= kstrdup(name
, GFP_KERNEL
);
276 knew
->private_value
= val
;
280 static void via_free_kctls(struct hda_codec
*codec
)
282 struct via_spec
*spec
= codec
->spec
;
284 if (spec
->kctls
.list
) {
285 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
287 for (i
= 0; i
< spec
->kctls
.used
; i
++)
290 snd_array_free(&spec
->kctls
);
293 /* create input playback/capture controls for the given pin */
294 static int via_new_analog_input(struct via_spec
*spec
, hda_nid_t pin
,
295 const char *ctlname
, int idx
, int mix_nid
)
300 sprintf(name
, "%s Playback Volume", ctlname
);
301 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
302 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
305 sprintf(name
, "%s Playback Switch", ctlname
);
306 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
307 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
313 static void via_auto_set_output_and_unmute(struct hda_codec
*codec
,
314 hda_nid_t nid
, int pin_type
,
318 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
320 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
322 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
323 snd_hda_codec_write(codec
, nid
, 0,
324 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
328 static void via_auto_init_multi_out(struct hda_codec
*codec
)
330 struct via_spec
*spec
= codec
->spec
;
333 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
334 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
336 via_auto_set_output_and_unmute(codec
, nid
, PIN_OUT
, i
);
340 static void via_auto_init_hp_out(struct hda_codec
*codec
)
342 struct via_spec
*spec
= codec
->spec
;
345 pin
= spec
->autocfg
.hp_pins
[0];
346 if (pin
) /* connect to front */
347 via_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, 0);
350 static void via_auto_init_analog_input(struct hda_codec
*codec
)
352 struct via_spec
*spec
= codec
->spec
;
355 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
356 hda_nid_t nid
= spec
->autocfg
.input_pins
[i
];
358 snd_hda_codec_write(codec
, nid
, 0,
359 AC_VERB_SET_PIN_WIDGET_CONTROL
,
360 (i
<= AUTO_PIN_FRONT_MIC
?
361 PIN_VREF50
: PIN_IN
));
368 static int via_mux_enum_info(struct snd_kcontrol
*kcontrol
,
369 struct snd_ctl_elem_info
*uinfo
)
371 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
372 struct via_spec
*spec
= codec
->spec
;
373 return snd_hda_input_mux_info(spec
->input_mux
, uinfo
);
376 static int via_mux_enum_get(struct snd_kcontrol
*kcontrol
,
377 struct snd_ctl_elem_value
*ucontrol
)
379 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
380 struct via_spec
*spec
= codec
->spec
;
381 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
383 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
387 static int via_mux_enum_put(struct snd_kcontrol
*kcontrol
,
388 struct snd_ctl_elem_value
*ucontrol
)
390 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
391 struct via_spec
*spec
= codec
->spec
;
392 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
394 if (!spec
->mux_nids
[adc_idx
])
396 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
397 spec
->mux_nids
[adc_idx
],
398 &spec
->cur_mux
[adc_idx
]);
401 static int via_independent_hp_info(struct snd_kcontrol
*kcontrol
,
402 struct snd_ctl_elem_info
*uinfo
)
404 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
405 struct via_spec
*spec
= codec
->spec
;
406 return snd_hda_input_mux_info(spec
->hp_mux
, uinfo
);
409 static int via_independent_hp_get(struct snd_kcontrol
*kcontrol
,
410 struct snd_ctl_elem_value
*ucontrol
)
412 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
413 struct via_spec
*spec
= codec
->spec
;
414 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
415 unsigned int pinsel
= snd_hda_codec_read(codec
, nid
, 0,
416 AC_VERB_GET_CONNECT_SEL
,
419 ucontrol
->value
.enumerated
.item
[0] = pinsel
;
424 static int via_independent_hp_put(struct snd_kcontrol
*kcontrol
,
425 struct snd_ctl_elem_value
*ucontrol
)
427 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
428 struct via_spec
*spec
= codec
->spec
;
429 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
430 unsigned int pinsel
= ucontrol
->value
.enumerated
.item
[0];
431 unsigned int con_nid
= snd_hda_codec_read(codec
, nid
, 0,
432 AC_VERB_GET_CONNECT_LIST
, 0) & 0xff;
434 if (con_nid
== spec
->multiout
.hp_nid
) {
436 if (!spec
->hp_independent_mode
) {
437 if (spec
->multiout
.num_dacs
> 1)
438 spec
->multiout
.num_dacs
-= 1;
439 spec
->hp_independent_mode
= 1;
441 } else if (pinsel
== 1) {
442 if (spec
->hp_independent_mode
) {
443 if (spec
->multiout
.num_dacs
> 1)
444 spec
->multiout
.num_dacs
+= 1;
445 spec
->hp_independent_mode
= 0;
450 if (spec
->hp_independent_mode
) {
451 if (spec
->multiout
.num_dacs
> 1)
452 spec
->multiout
.num_dacs
+= 1;
453 spec
->hp_independent_mode
= 0;
455 } else if (pinsel
== 1) {
456 if (!spec
->hp_independent_mode
) {
457 if (spec
->multiout
.num_dacs
> 1)
458 spec
->multiout
.num_dacs
-= 1;
459 spec
->hp_independent_mode
= 1;
463 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
,
466 if (spec
->multiout
.hp_nid
&&
467 spec
->multiout
.hp_nid
!= spec
->multiout
.dac_nids
[HDA_FRONT
])
468 snd_hda_codec_setup_stream(codec
,
469 spec
->multiout
.hp_nid
,
475 static struct snd_kcontrol_new via_hp_mixer
[] = {
477 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
478 .name
= "Independent HP",
480 .info
= via_independent_hp_info
,
481 .get
= via_independent_hp_get
,
482 .put
= via_independent_hp_put
,
487 /* capture mixer elements */
488 static struct snd_kcontrol_new vt1708_capture_mixer
[] = {
489 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT
),
490 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT
),
491 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT
),
492 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT
),
494 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
495 /* The multiple "Capture Source" controls confuse alsamixer
496 * So call somewhat different..
498 /* .name = "Capture Source", */
499 .name
= "Input Source",
501 .info
= via_mux_enum_info
,
502 .get
= via_mux_enum_get
,
503 .put
= via_mux_enum_put
,
508 * generic initialization of ADC, input mixers and output mixers
510 static struct hda_verb vt1708_volume_init_verbs
[] = {
512 * Unmute ADC0-1 and set the default input to mic-in
514 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
515 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
518 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
521 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
522 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
523 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
524 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
525 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
526 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
529 * Set up output mixers (0x19 - 0x1b)
531 /* set vol=0 to output mixers */
532 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
533 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
534 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
536 /* Setup default input to PW4 */
537 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
538 /* PW9 Output enable */
539 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
543 static int via_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
544 struct hda_codec
*codec
,
545 struct snd_pcm_substream
*substream
)
547 struct via_spec
*spec
= codec
->spec
;
548 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
552 static int via_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
553 struct hda_codec
*codec
,
554 unsigned int stream_tag
,
556 struct snd_pcm_substream
*substream
)
558 struct via_spec
*spec
= codec
->spec
;
559 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
560 stream_tag
, format
, substream
);
563 static int via_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
564 struct hda_codec
*codec
,
565 struct snd_pcm_substream
*substream
)
567 struct via_spec
*spec
= codec
->spec
;
568 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
572 static void playback_multi_pcm_prep_0(struct hda_codec
*codec
,
573 unsigned int stream_tag
,
575 struct snd_pcm_substream
*substream
)
577 struct via_spec
*spec
= codec
->spec
;
578 struct hda_multi_out
*mout
= &spec
->multiout
;
579 hda_nid_t
*nids
= mout
->dac_nids
;
580 int chs
= substream
->runtime
->channels
;
583 mutex_lock(&codec
->spdif_mutex
);
584 if (mout
->dig_out_nid
&& mout
->dig_out_used
!= HDA_DIG_EXCLUSIVE
) {
586 snd_hda_is_supported_format(codec
, mout
->dig_out_nid
,
588 !(codec
->spdif_status
& IEC958_AES0_NONAUDIO
)) {
589 mout
->dig_out_used
= HDA_DIG_ANALOG_DUP
;
590 /* turn off SPDIF once; otherwise the IEC958 bits won't
592 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
593 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
594 AC_VERB_SET_DIGI_CONVERT_1
,
596 ~AC_DIG1_ENABLE
& 0xff);
597 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
598 stream_tag
, 0, format
);
599 /* turn on again (if needed) */
600 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
601 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
602 AC_VERB_SET_DIGI_CONVERT_1
,
603 codec
->spdif_ctls
& 0xff);
605 mout
->dig_out_used
= 0;
606 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
610 mutex_unlock(&codec
->spdif_mutex
);
613 snd_hda_codec_setup_stream(codec
, nids
[HDA_FRONT
], stream_tag
,
616 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
617 !spec
->hp_independent_mode
)
618 /* headphone out will just decode front left/right (stereo) */
619 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
, stream_tag
,
622 /* extra outputs copied from front */
623 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
624 if (mout
->extra_out_nid
[i
])
625 snd_hda_codec_setup_stream(codec
,
626 mout
->extra_out_nid
[i
],
627 stream_tag
, 0, format
);
630 for (i
= 1; i
< mout
->num_dacs
; i
++) {
631 if (chs
>= (i
+ 1) * 2) /* independent out */
632 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
634 else /* copy front */
635 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
640 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
641 struct hda_codec
*codec
,
642 unsigned int stream_tag
,
644 struct snd_pcm_substream
*substream
)
646 struct via_spec
*spec
= codec
->spec
;
647 struct hda_multi_out
*mout
= &spec
->multiout
;
648 hda_nid_t
*nids
= mout
->dac_nids
;
650 if (substream
->number
== 0)
651 playback_multi_pcm_prep_0(codec
, stream_tag
, format
,
654 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
655 spec
->hp_independent_mode
)
656 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
657 stream_tag
, 0, format
);
663 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
664 struct hda_codec
*codec
,
665 struct snd_pcm_substream
*substream
)
667 struct via_spec
*spec
= codec
->spec
;
668 struct hda_multi_out
*mout
= &spec
->multiout
;
669 hda_nid_t
*nids
= mout
->dac_nids
;
672 if (substream
->number
== 0) {
673 for (i
= 0; i
< mout
->num_dacs
; i
++)
674 snd_hda_codec_setup_stream(codec
, nids
[i
], 0, 0, 0);
676 if (mout
->hp_nid
&& !spec
->hp_independent_mode
)
677 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
680 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
681 if (mout
->extra_out_nid
[i
])
682 snd_hda_codec_setup_stream(codec
,
683 mout
->extra_out_nid
[i
],
685 mutex_lock(&codec
->spdif_mutex
);
686 if (mout
->dig_out_nid
&&
687 mout
->dig_out_used
== HDA_DIG_ANALOG_DUP
) {
688 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
690 mout
->dig_out_used
= 0;
692 mutex_unlock(&codec
->spdif_mutex
);
694 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
695 spec
->hp_independent_mode
)
696 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
706 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
707 struct hda_codec
*codec
,
708 struct snd_pcm_substream
*substream
)
710 struct via_spec
*spec
= codec
->spec
;
711 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
714 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
715 struct hda_codec
*codec
,
716 struct snd_pcm_substream
*substream
)
718 struct via_spec
*spec
= codec
->spec
;
719 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
722 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
723 struct hda_codec
*codec
,
724 unsigned int stream_tag
,
726 struct snd_pcm_substream
*substream
)
728 struct via_spec
*spec
= codec
->spec
;
729 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
730 stream_tag
, format
, substream
);
733 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
734 struct hda_codec
*codec
,
735 struct snd_pcm_substream
*substream
)
737 struct via_spec
*spec
= codec
->spec
;
738 snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
745 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
746 struct hda_codec
*codec
,
747 unsigned int stream_tag
,
749 struct snd_pcm_substream
*substream
)
751 struct via_spec
*spec
= codec
->spec
;
753 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
754 stream_tag
, 0, format
);
758 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
759 struct hda_codec
*codec
,
760 struct snd_pcm_substream
*substream
)
762 struct via_spec
*spec
= codec
->spec
;
763 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
767 static struct hda_pcm_stream vt1708_pcm_analog_playback
= {
771 .nid
= 0x10, /* NID to query formats and rates */
773 .open
= via_playback_pcm_open
,
774 .prepare
= via_playback_multi_pcm_prepare
,
775 .cleanup
= via_playback_multi_pcm_cleanup
779 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
783 .nid
= 0x10, /* NID to query formats and rates */
784 /* We got noisy outputs on the right channel on VT1708 when
785 * 24bit samples are used. Until any workaround is found,
786 * disable the 24bit format, so far.
788 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
790 .open
= via_playback_pcm_open
,
791 .prepare
= via_playback_pcm_prepare
,
792 .cleanup
= via_playback_pcm_cleanup
796 static struct hda_pcm_stream vt1708_pcm_analog_capture
= {
800 .nid
= 0x15, /* NID to query formats and rates */
802 .prepare
= via_capture_pcm_prepare
,
803 .cleanup
= via_capture_pcm_cleanup
807 static struct hda_pcm_stream vt1708_pcm_digital_playback
= {
811 /* NID is set in via_build_pcms */
813 .open
= via_dig_playback_pcm_open
,
814 .close
= via_dig_playback_pcm_close
,
815 .prepare
= via_dig_playback_pcm_prepare
,
816 .cleanup
= via_dig_playback_pcm_cleanup
820 static struct hda_pcm_stream vt1708_pcm_digital_capture
= {
826 static int via_build_controls(struct hda_codec
*codec
)
828 struct via_spec
*spec
= codec
->spec
;
832 for (i
= 0; i
< spec
->num_mixers
; i
++) {
833 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
838 if (spec
->multiout
.dig_out_nid
) {
839 err
= snd_hda_create_spdif_out_ctls(codec
,
840 spec
->multiout
.dig_out_nid
);
843 err
= snd_hda_create_spdif_share_sw(codec
,
847 spec
->multiout
.share_spdif
= 1;
849 if (spec
->dig_in_nid
) {
850 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
854 via_free_kctls(codec
); /* no longer needed */
858 static int via_build_pcms(struct hda_codec
*codec
)
860 struct via_spec
*spec
= codec
->spec
;
861 struct hda_pcm
*info
= spec
->pcm_rec
;
864 codec
->pcm_info
= info
;
866 info
->name
= spec
->stream_name_analog
;
867 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *(spec
->stream_analog_playback
);
868 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
869 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *(spec
->stream_analog_capture
);
870 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
872 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
873 spec
->multiout
.max_channels
;
875 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
878 info
->name
= spec
->stream_name_digital
;
879 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
880 if (spec
->multiout
.dig_out_nid
) {
881 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
882 *(spec
->stream_digital_playback
);
883 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
884 spec
->multiout
.dig_out_nid
;
886 if (spec
->dig_in_nid
) {
887 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
888 *(spec
->stream_digital_capture
);
889 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
897 static void via_free(struct hda_codec
*codec
)
899 struct via_spec
*spec
= codec
->spec
;
904 via_free_kctls(codec
);
908 /* mute internal speaker if HP is plugged */
909 static void via_hp_automute(struct hda_codec
*codec
)
911 unsigned int present
;
912 struct via_spec
*spec
= codec
->spec
;
914 present
= snd_hda_codec_read(codec
, spec
->autocfg
.hp_pins
[0], 0,
915 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
916 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
917 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
918 present
? HDA_AMP_MUTE
: 0);
921 static void via_gpio_control(struct hda_codec
*codec
)
923 unsigned int gpio_data
;
924 unsigned int vol_counter
;
926 unsigned int master_vol
;
928 struct via_spec
*spec
= codec
->spec
;
930 gpio_data
= snd_hda_codec_read(codec
, codec
->afg
, 0,
931 AC_VERB_GET_GPIO_DATA
, 0) & 0x03;
933 vol_counter
= (snd_hda_codec_read(codec
, codec
->afg
, 0,
934 0xF84, 0) & 0x3F0000) >> 16;
936 vol
= vol_counter
& 0x1F;
937 master_vol
= snd_hda_codec_read(codec
, 0x1A, 0,
938 AC_VERB_GET_AMP_GAIN_MUTE
,
941 if (gpio_data
== 0x02) {
942 /* unmute line out */
943 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
944 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
946 if (vol_counter
& 0x20) {
947 /* decrease volume */
948 if (vol
> master_vol
)
950 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
,
954 /* increase volume */
955 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
, 0,
957 ((master_vol
+vol
) > 0x2A) ? 0x2A :
960 } else if (!(gpio_data
& 0x02)) {
962 snd_hda_codec_amp_stereo(codec
,
963 spec
->autocfg
.line_out_pins
[0],
964 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
969 /* unsolicited event for jack sensing */
970 static void via_unsol_event(struct hda_codec
*codec
,
974 if (res
== VIA_HP_EVENT
)
975 via_hp_automute(codec
);
976 else if (res
== VIA_GPIO_EVENT
)
977 via_gpio_control(codec
);
980 static int via_init(struct hda_codec
*codec
)
982 struct via_spec
*spec
= codec
->spec
;
984 for (i
= 0; i
< spec
->num_iverbs
; i
++)
985 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
987 spec
->codec_type
= get_codec_type(codec
);
988 if (spec
->codec_type
== VT1708BCE
)
989 spec
->codec_type
= VT1708S
; /* VT1708BCE & VT1708S are almost
991 /* Lydia Add for EAPD enable */
992 if (!spec
->dig_in_nid
) { /* No Digital In connection */
993 if (spec
->dig_in_pin
) {
994 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
995 AC_VERB_SET_PIN_WIDGET_CONTROL
,
997 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
998 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
1000 } else /* enable SPDIF-input pin */
1001 snd_hda_codec_write(codec
, spec
->autocfg
.dig_in_pin
, 0,
1002 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
1004 /* assign slave outs */
1005 if (spec
->slave_dig_outs
[0])
1006 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
1011 #ifdef CONFIG_SND_HDA_POWER_SAVE
1012 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
1014 struct via_spec
*spec
= codec
->spec
;
1015 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
1021 static struct hda_codec_ops via_patch_ops
= {
1022 .build_controls
= via_build_controls
,
1023 .build_pcms
= via_build_pcms
,
1026 #ifdef CONFIG_SND_HDA_POWER_SAVE
1027 .check_power_status
= via_check_power_status
,
1031 /* fill in the dac_nids table from the parsed pin configuration */
1032 static int vt1708_auto_fill_dac_nids(struct via_spec
*spec
,
1033 const struct auto_pin_cfg
*cfg
)
1038 spec
->multiout
.num_dacs
= cfg
->line_outs
;
1040 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1042 for(i
= 0; i
< 4; i
++) {
1043 nid
= cfg
->line_out_pins
[i
];
1045 /* config dac list */
1047 case AUTO_SEQ_FRONT
:
1048 spec
->multiout
.dac_nids
[i
] = 0x10;
1050 case AUTO_SEQ_CENLFE
:
1051 spec
->multiout
.dac_nids
[i
] = 0x12;
1053 case AUTO_SEQ_SURROUND
:
1054 spec
->multiout
.dac_nids
[i
] = 0x11;
1057 spec
->multiout
.dac_nids
[i
] = 0x13;
1066 /* add playback controls from the parsed DAC table */
1067 static int vt1708_auto_create_multi_out_ctls(struct via_spec
*spec
,
1068 const struct auto_pin_cfg
*cfg
)
1071 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1072 hda_nid_t nid
, nid_vol
= 0;
1075 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1076 nid
= cfg
->line_out_pins
[i
];
1081 if (i
!= AUTO_SEQ_FRONT
)
1084 if (i
== AUTO_SEQ_CENLFE
) {
1086 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1087 "Center Playback Volume",
1088 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1092 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1093 "LFE Playback Volume",
1094 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1098 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1099 "Center Playback Switch",
1100 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1104 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1105 "LFE Playback Switch",
1106 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1110 } else if (i
== AUTO_SEQ_FRONT
){
1111 /* add control to mixer index 0 */
1112 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1113 "Master Front Playback Volume",
1114 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1118 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1119 "Master Front Playback Switch",
1120 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1125 /* add control to PW3 */
1126 sprintf(name
, "%s Playback Volume", chname
[i
]);
1127 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1128 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1132 sprintf(name
, "%s Playback Switch", chname
[i
]);
1133 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1134 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1139 sprintf(name
, "%s Playback Volume", chname
[i
]);
1140 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1141 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1145 sprintf(name
, "%s Playback Switch", chname
[i
]);
1146 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1147 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1157 static void create_hp_imux(struct via_spec
*spec
)
1160 struct hda_input_mux
*imux
= &spec
->private_imux
[1];
1161 static const char *texts
[] = { "OFF", "ON", NULL
};
1163 /* for hp mode select */
1165 while (texts
[i
] != NULL
) {
1166 imux
->items
[imux
->num_items
].label
= texts
[i
];
1167 imux
->items
[imux
->num_items
].index
= i
;
1172 spec
->hp_mux
= &spec
->private_imux
[1];
1175 static int vt1708_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1182 spec
->multiout
.hp_nid
= VT1708_HP_NID
; /* AOW3 */
1184 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1185 "Headphone Playback Volume",
1186 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1189 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1190 "Headphone Playback Switch",
1191 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1195 create_hp_imux(spec
);
1200 /* create playback/capture controls for input pins */
1201 static int vt1708_auto_create_analog_input_ctls(struct via_spec
*spec
,
1202 const struct auto_pin_cfg
*cfg
)
1204 static char *labels
[] = {
1205 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1207 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1208 int i
, err
, idx
= 0;
1210 /* for internal loopback recording select */
1211 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1212 imux
->items
[imux
->num_items
].index
= idx
;
1215 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1216 if (!cfg
->input_pins
[i
])
1219 switch (cfg
->input_pins
[i
]) {
1220 case 0x1d: /* Mic */
1224 case 0x1e: /* Line In */
1228 case 0x21: /* Front Mic */
1236 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
1240 imux
->items
[imux
->num_items
].label
= labels
[i
];
1241 imux
->items
[imux
->num_items
].index
= idx
;
1247 #ifdef CONFIG_SND_HDA_POWER_SAVE
1248 static struct hda_amp_list vt1708_loopbacks
[] = {
1249 { 0x17, HDA_INPUT
, 1 },
1250 { 0x17, HDA_INPUT
, 2 },
1251 { 0x17, HDA_INPUT
, 3 },
1252 { 0x17, HDA_INPUT
, 4 },
1257 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
1259 unsigned int def_conf
;
1260 unsigned char seqassoc
;
1262 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
1263 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
1264 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
1265 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
) {
1266 if (seqassoc
== 0xff) {
1267 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
1268 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
1275 static int vt1708_parse_auto_config(struct hda_codec
*codec
)
1277 struct via_spec
*spec
= codec
->spec
;
1280 /* Add HP and CD pin config connect bit re-config action */
1281 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
1282 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
1284 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1287 err
= vt1708_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1290 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1291 return 0; /* can't find valid BIOS pin config */
1293 err
= vt1708_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1296 err
= vt1708_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1299 err
= vt1708_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1303 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1305 if (spec
->autocfg
.dig_outs
)
1306 spec
->multiout
.dig_out_nid
= VT1708_DIGOUT_NID
;
1307 spec
->dig_in_pin
= VT1708_DIGIN_PIN
;
1308 if (spec
->autocfg
.dig_in_pin
)
1309 spec
->dig_in_nid
= VT1708_DIGIN_NID
;
1311 if (spec
->kctls
.list
)
1312 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
1314 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_volume_init_verbs
;
1316 spec
->input_mux
= &spec
->private_imux
[0];
1319 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1324 /* init callback for auto-configuration model -- overriding the default init */
1325 static int via_auto_init(struct hda_codec
*codec
)
1328 via_auto_init_multi_out(codec
);
1329 via_auto_init_hp_out(codec
);
1330 via_auto_init_analog_input(codec
);
1334 static int get_mux_nids(struct hda_codec
*codec
)
1336 struct via_spec
*spec
= codec
->spec
;
1337 hda_nid_t nid
, conn
[8];
1341 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1342 nid
= spec
->adc_nids
[i
];
1344 type
= get_wcaps_type(get_wcaps(codec
, nid
));
1345 if (type
== AC_WID_PIN
)
1347 n
= snd_hda_get_connections(codec
, nid
, conn
,
1352 spec
->mux_nids
[i
] = nid
;
1361 static int patch_vt1708(struct hda_codec
*codec
)
1363 struct via_spec
*spec
;
1366 /* create a codec specific record */
1367 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1373 /* automatic parse from the BIOS config */
1374 err
= vt1708_parse_auto_config(codec
);
1379 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
1380 "from BIOS. Using genenic mode...\n");
1384 spec
->stream_name_analog
= "VT1708 Analog";
1385 spec
->stream_analog_playback
= &vt1708_pcm_analog_playback
;
1386 /* disable 32bit format on VT1708 */
1387 if (codec
->vendor_id
== 0x11061708)
1388 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
1389 spec
->stream_analog_capture
= &vt1708_pcm_analog_capture
;
1391 spec
->stream_name_digital
= "VT1708 Digital";
1392 spec
->stream_digital_playback
= &vt1708_pcm_digital_playback
;
1393 spec
->stream_digital_capture
= &vt1708_pcm_digital_capture
;
1396 if (!spec
->adc_nids
&& spec
->input_mux
) {
1397 spec
->adc_nids
= vt1708_adc_nids
;
1398 spec
->num_adc_nids
= ARRAY_SIZE(vt1708_adc_nids
);
1399 get_mux_nids(codec
);
1400 spec
->mixers
[spec
->num_mixers
] = vt1708_capture_mixer
;
1404 codec
->patch_ops
= via_patch_ops
;
1406 codec
->patch_ops
.init
= via_auto_init
;
1407 #ifdef CONFIG_SND_HDA_POWER_SAVE
1408 spec
->loopback
.amplist
= vt1708_loopbacks
;
1414 /* capture mixer elements */
1415 static struct snd_kcontrol_new vt1709_capture_mixer
[] = {
1416 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT
),
1417 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT
),
1418 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT
),
1419 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT
),
1420 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT
),
1421 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT
),
1423 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1424 /* The multiple "Capture Source" controls confuse alsamixer
1425 * So call somewhat different..
1427 /* .name = "Capture Source", */
1428 .name
= "Input Source",
1430 .info
= via_mux_enum_info
,
1431 .get
= via_mux_enum_get
,
1432 .put
= via_mux_enum_put
,
1437 static struct hda_verb vt1709_uniwill_init_verbs
[] = {
1438 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
1443 * generic initialization of ADC, input mixers and output mixers
1445 static struct hda_verb vt1709_10ch_volume_init_verbs
[] = {
1447 * Unmute ADC0-2 and set the default input to mic-in
1449 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1450 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1451 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1454 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1457 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1458 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1459 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1460 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1461 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1462 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1465 * Set up output selector (0x1a, 0x1b, 0x29)
1467 /* set vol=0 to output mixers */
1468 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1469 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1470 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1473 * Unmute PW3 and PW4
1475 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1476 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1478 /* Set input of PW4 as AOW4 */
1479 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
1480 /* PW9 Output enable */
1481 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1485 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback
= {
1489 .nid
= 0x10, /* NID to query formats and rates */
1491 .open
= via_playback_pcm_open
,
1492 .prepare
= via_playback_pcm_prepare
,
1493 .cleanup
= via_playback_pcm_cleanup
1497 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback
= {
1501 .nid
= 0x10, /* NID to query formats and rates */
1503 .open
= via_playback_pcm_open
,
1504 .prepare
= via_playback_pcm_prepare
,
1505 .cleanup
= via_playback_pcm_cleanup
1509 static struct hda_pcm_stream vt1709_pcm_analog_capture
= {
1513 .nid
= 0x14, /* NID to query formats and rates */
1515 .prepare
= via_capture_pcm_prepare
,
1516 .cleanup
= via_capture_pcm_cleanup
1520 static struct hda_pcm_stream vt1709_pcm_digital_playback
= {
1524 /* NID is set in via_build_pcms */
1526 .open
= via_dig_playback_pcm_open
,
1527 .close
= via_dig_playback_pcm_close
1531 static struct hda_pcm_stream vt1709_pcm_digital_capture
= {
1537 static int vt1709_auto_fill_dac_nids(struct via_spec
*spec
,
1538 const struct auto_pin_cfg
*cfg
)
1543 if (cfg
->line_outs
== 4) /* 10 channels */
1544 spec
->multiout
.num_dacs
= cfg
->line_outs
+1; /* AOW0~AOW4 */
1545 else if (cfg
->line_outs
== 3) /* 6 channels */
1546 spec
->multiout
.num_dacs
= cfg
->line_outs
; /* AOW0~AOW2 */
1548 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1550 if (cfg
->line_outs
== 4) { /* 10 channels */
1551 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1552 nid
= cfg
->line_out_pins
[i
];
1554 /* config dac list */
1556 case AUTO_SEQ_FRONT
:
1558 spec
->multiout
.dac_nids
[i
] = 0x10;
1560 case AUTO_SEQ_CENLFE
:
1562 spec
->multiout
.dac_nids
[i
] = 0x12;
1564 case AUTO_SEQ_SURROUND
:
1566 spec
->multiout
.dac_nids
[i
] = 0x11;
1570 spec
->multiout
.dac_nids
[i
] = 0x27;
1577 spec
->multiout
.dac_nids
[cfg
->line_outs
] = 0x28; /* AOW4 */
1579 } else if (cfg
->line_outs
== 3) { /* 6 channels */
1580 for(i
= 0; i
< cfg
->line_outs
; i
++) {
1581 nid
= cfg
->line_out_pins
[i
];
1583 /* config dac list */
1585 case AUTO_SEQ_FRONT
:
1587 spec
->multiout
.dac_nids
[i
] = 0x10;
1589 case AUTO_SEQ_CENLFE
:
1591 spec
->multiout
.dac_nids
[i
] = 0x12;
1593 case AUTO_SEQ_SURROUND
:
1595 spec
->multiout
.dac_nids
[i
] = 0x11;
1607 /* add playback controls from the parsed DAC table */
1608 static int vt1709_auto_create_multi_out_ctls(struct via_spec
*spec
,
1609 const struct auto_pin_cfg
*cfg
)
1612 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1616 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1617 nid
= cfg
->line_out_pins
[i
];
1622 if (i
== AUTO_SEQ_CENLFE
) {
1624 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1625 "Center Playback Volume",
1626 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1630 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1631 "LFE Playback Volume",
1632 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1636 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1637 "Center Playback Switch",
1638 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1642 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1643 "LFE Playback Switch",
1644 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1648 } else if (i
== AUTO_SEQ_FRONT
){
1649 /* add control to mixer index 0 */
1650 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1651 "Master Front Playback Volume",
1652 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1656 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1657 "Master Front Playback Switch",
1658 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1663 /* add control to PW3 */
1664 sprintf(name
, "%s Playback Volume", chname
[i
]);
1665 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1666 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1670 sprintf(name
, "%s Playback Switch", chname
[i
]);
1671 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1672 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1676 } else if (i
== AUTO_SEQ_SURROUND
) {
1677 sprintf(name
, "%s Playback Volume", chname
[i
]);
1678 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1679 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1683 sprintf(name
, "%s Playback Switch", chname
[i
]);
1684 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1685 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1689 } else if (i
== AUTO_SEQ_SIDE
) {
1690 sprintf(name
, "%s Playback Volume", chname
[i
]);
1691 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1692 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1696 sprintf(name
, "%s Playback Switch", chname
[i
]);
1697 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1698 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1708 static int vt1709_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1715 if (spec
->multiout
.num_dacs
== 5) /* 10 channels */
1716 spec
->multiout
.hp_nid
= VT1709_HP_DAC_NID
;
1717 else if (spec
->multiout
.num_dacs
== 3) /* 6 channels */
1718 spec
->multiout
.hp_nid
= 0;
1720 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1721 "Headphone Playback Volume",
1722 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1725 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1726 "Headphone Playback Switch",
1727 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1734 /* create playback/capture controls for input pins */
1735 static int vt1709_auto_create_analog_input_ctls(struct via_spec
*spec
,
1736 const struct auto_pin_cfg
*cfg
)
1738 static char *labels
[] = {
1739 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1741 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1742 int i
, err
, idx
= 0;
1744 /* for internal loopback recording select */
1745 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1746 imux
->items
[imux
->num_items
].index
= idx
;
1749 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1750 if (!cfg
->input_pins
[i
])
1753 switch (cfg
->input_pins
[i
]) {
1754 case 0x1d: /* Mic */
1758 case 0x1e: /* Line In */
1762 case 0x21: /* Front Mic */
1770 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
1774 imux
->items
[imux
->num_items
].label
= labels
[i
];
1775 imux
->items
[imux
->num_items
].index
= idx
;
1781 static int vt1709_parse_auto_config(struct hda_codec
*codec
)
1783 struct via_spec
*spec
= codec
->spec
;
1786 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1789 err
= vt1709_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1792 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1793 return 0; /* can't find valid BIOS pin config */
1795 err
= vt1709_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1798 err
= vt1709_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1801 err
= vt1709_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1805 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1807 if (spec
->autocfg
.dig_outs
)
1808 spec
->multiout
.dig_out_nid
= VT1709_DIGOUT_NID
;
1809 spec
->dig_in_pin
= VT1709_DIGIN_PIN
;
1810 if (spec
->autocfg
.dig_in_pin
)
1811 spec
->dig_in_nid
= VT1709_DIGIN_NID
;
1813 if (spec
->kctls
.list
)
1814 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
1816 spec
->input_mux
= &spec
->private_imux
[0];
1819 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1824 #ifdef CONFIG_SND_HDA_POWER_SAVE
1825 static struct hda_amp_list vt1709_loopbacks
[] = {
1826 { 0x18, HDA_INPUT
, 1 },
1827 { 0x18, HDA_INPUT
, 2 },
1828 { 0x18, HDA_INPUT
, 3 },
1829 { 0x18, HDA_INPUT
, 4 },
1834 static int patch_vt1709_10ch(struct hda_codec
*codec
)
1836 struct via_spec
*spec
;
1839 /* create a codec specific record */
1840 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1846 err
= vt1709_parse_auto_config(codec
);
1851 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
1852 "Using genenic mode...\n");
1855 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_10ch_volume_init_verbs
;
1856 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
1858 spec
->stream_name_analog
= "VT1709 Analog";
1859 spec
->stream_analog_playback
= &vt1709_10ch_pcm_analog_playback
;
1860 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
1862 spec
->stream_name_digital
= "VT1709 Digital";
1863 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
1864 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
1867 if (!spec
->adc_nids
&& spec
->input_mux
) {
1868 spec
->adc_nids
= vt1709_adc_nids
;
1869 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
1870 get_mux_nids(codec
);
1871 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
1875 codec
->patch_ops
= via_patch_ops
;
1877 codec
->patch_ops
.init
= via_auto_init
;
1878 codec
->patch_ops
.unsol_event
= via_unsol_event
;
1879 #ifdef CONFIG_SND_HDA_POWER_SAVE
1880 spec
->loopback
.amplist
= vt1709_loopbacks
;
1886 * generic initialization of ADC, input mixers and output mixers
1888 static struct hda_verb vt1709_6ch_volume_init_verbs
[] = {
1890 * Unmute ADC0-2 and set the default input to mic-in
1892 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1893 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1894 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1897 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1900 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1901 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1902 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1903 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1904 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1905 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1908 * Set up output selector (0x1a, 0x1b, 0x29)
1910 /* set vol=0 to output mixers */
1911 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1912 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1913 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1916 * Unmute PW3 and PW4
1918 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1919 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1921 /* Set input of PW4 as MW0 */
1922 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
1923 /* PW9 Output enable */
1924 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1928 static int patch_vt1709_6ch(struct hda_codec
*codec
)
1930 struct via_spec
*spec
;
1933 /* create a codec specific record */
1934 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1940 err
= vt1709_parse_auto_config(codec
);
1945 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
1946 "Using genenic mode...\n");
1949 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_6ch_volume_init_verbs
;
1950 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
1952 spec
->stream_name_analog
= "VT1709 Analog";
1953 spec
->stream_analog_playback
= &vt1709_6ch_pcm_analog_playback
;
1954 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
1956 spec
->stream_name_digital
= "VT1709 Digital";
1957 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
1958 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
1961 if (!spec
->adc_nids
&& spec
->input_mux
) {
1962 spec
->adc_nids
= vt1709_adc_nids
;
1963 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
1964 get_mux_nids(codec
);
1965 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
1969 codec
->patch_ops
= via_patch_ops
;
1971 codec
->patch_ops
.init
= via_auto_init
;
1972 codec
->patch_ops
.unsol_event
= via_unsol_event
;
1973 #ifdef CONFIG_SND_HDA_POWER_SAVE
1974 spec
->loopback
.amplist
= vt1709_loopbacks
;
1979 /* capture mixer elements */
1980 static struct snd_kcontrol_new vt1708B_capture_mixer
[] = {
1981 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
1982 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
1983 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
1984 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
1986 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1987 /* The multiple "Capture Source" controls confuse alsamixer
1988 * So call somewhat different..
1990 /* .name = "Capture Source", */
1991 .name
= "Input Source",
1993 .info
= via_mux_enum_info
,
1994 .get
= via_mux_enum_get
,
1995 .put
= via_mux_enum_put
,
2000 * generic initialization of ADC, input mixers and output mixers
2002 static struct hda_verb vt1708B_8ch_volume_init_verbs
[] = {
2004 * Unmute ADC0-1 and set the default input to mic-in
2006 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2007 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2010 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2013 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2014 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2015 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2016 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2017 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2018 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2021 * Set up output mixers
2023 /* set vol=0 to output mixers */
2024 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2025 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2026 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2028 /* Setup default input to PW4 */
2029 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x1},
2030 /* PW9 Output enable */
2031 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2032 /* PW10 Input enable */
2033 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2037 static struct hda_verb vt1708B_4ch_volume_init_verbs
[] = {
2039 * Unmute ADC0-1 and set the default input to mic-in
2041 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2042 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2045 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2048 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2049 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2050 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2051 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2052 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2053 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2056 * Set up output mixers
2058 /* set vol=0 to output mixers */
2059 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2060 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2061 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2063 /* Setup default input of PW4 to MW0 */
2064 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2065 /* PW9 Output enable */
2066 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2067 /* PW10 Input enable */
2068 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2072 static struct hda_verb vt1708B_uniwill_init_verbs
[] = {
2073 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2077 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback
= {
2081 .nid
= 0x10, /* NID to query formats and rates */
2083 .open
= via_playback_pcm_open
,
2084 .prepare
= via_playback_multi_pcm_prepare
,
2085 .cleanup
= via_playback_multi_pcm_cleanup
2089 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback
= {
2093 .nid
= 0x10, /* NID to query formats and rates */
2095 .open
= via_playback_pcm_open
,
2096 .prepare
= via_playback_multi_pcm_prepare
,
2097 .cleanup
= via_playback_multi_pcm_cleanup
2101 static struct hda_pcm_stream vt1708B_pcm_analog_capture
= {
2105 .nid
= 0x13, /* NID to query formats and rates */
2107 .prepare
= via_capture_pcm_prepare
,
2108 .cleanup
= via_capture_pcm_cleanup
2112 static struct hda_pcm_stream vt1708B_pcm_digital_playback
= {
2116 /* NID is set in via_build_pcms */
2118 .open
= via_dig_playback_pcm_open
,
2119 .close
= via_dig_playback_pcm_close
,
2120 .prepare
= via_dig_playback_pcm_prepare
,
2121 .cleanup
= via_dig_playback_pcm_cleanup
2125 static struct hda_pcm_stream vt1708B_pcm_digital_capture
= {
2131 /* fill in the dac_nids table from the parsed pin configuration */
2132 static int vt1708B_auto_fill_dac_nids(struct via_spec
*spec
,
2133 const struct auto_pin_cfg
*cfg
)
2138 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2140 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2142 for (i
= 0; i
< 4; i
++) {
2143 nid
= cfg
->line_out_pins
[i
];
2145 /* config dac list */
2147 case AUTO_SEQ_FRONT
:
2148 spec
->multiout
.dac_nids
[i
] = 0x10;
2150 case AUTO_SEQ_CENLFE
:
2151 spec
->multiout
.dac_nids
[i
] = 0x24;
2153 case AUTO_SEQ_SURROUND
:
2154 spec
->multiout
.dac_nids
[i
] = 0x11;
2157 spec
->multiout
.dac_nids
[i
] = 0x25;
2166 /* add playback controls from the parsed DAC table */
2167 static int vt1708B_auto_create_multi_out_ctls(struct via_spec
*spec
,
2168 const struct auto_pin_cfg
*cfg
)
2171 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2172 hda_nid_t nid_vols
[] = {0x16, 0x18, 0x26, 0x27};
2173 hda_nid_t nid
, nid_vol
= 0;
2176 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2177 nid
= cfg
->line_out_pins
[i
];
2182 nid_vol
= nid_vols
[i
];
2184 if (i
== AUTO_SEQ_CENLFE
) {
2186 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2187 "Center Playback Volume",
2188 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2192 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2193 "LFE Playback Volume",
2194 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2198 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2199 "Center Playback Switch",
2200 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2204 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2205 "LFE Playback Switch",
2206 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2210 } else if (i
== AUTO_SEQ_FRONT
) {
2211 /* add control to mixer index 0 */
2212 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2213 "Master Front Playback Volume",
2214 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2218 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2219 "Master Front Playback Switch",
2220 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2225 /* add control to PW3 */
2226 sprintf(name
, "%s Playback Volume", chname
[i
]);
2227 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2228 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2232 sprintf(name
, "%s Playback Switch", chname
[i
]);
2233 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2234 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2239 sprintf(name
, "%s Playback Volume", chname
[i
]);
2240 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2241 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2245 sprintf(name
, "%s Playback Switch", chname
[i
]);
2246 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2247 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2257 static int vt1708B_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2264 spec
->multiout
.hp_nid
= VT1708B_HP_NID
; /* AOW3 */
2266 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2267 "Headphone Playback Volume",
2268 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2271 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2272 "Headphone Playback Switch",
2273 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2277 create_hp_imux(spec
);
2282 /* create playback/capture controls for input pins */
2283 static int vt1708B_auto_create_analog_input_ctls(struct via_spec
*spec
,
2284 const struct auto_pin_cfg
*cfg
)
2286 static char *labels
[] = {
2287 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2289 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2290 int i
, err
, idx
= 0;
2292 /* for internal loopback recording select */
2293 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2294 imux
->items
[imux
->num_items
].index
= idx
;
2297 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2298 if (!cfg
->input_pins
[i
])
2301 switch (cfg
->input_pins
[i
]) {
2302 case 0x1a: /* Mic */
2306 case 0x1b: /* Line In */
2310 case 0x1e: /* Front Mic */
2318 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
2322 imux
->items
[imux
->num_items
].label
= labels
[i
];
2323 imux
->items
[imux
->num_items
].index
= idx
;
2329 static int vt1708B_parse_auto_config(struct hda_codec
*codec
)
2331 struct via_spec
*spec
= codec
->spec
;
2334 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2337 err
= vt1708B_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2340 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2341 return 0; /* can't find valid BIOS pin config */
2343 err
= vt1708B_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2346 err
= vt1708B_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2349 err
= vt1708B_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2353 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2355 if (spec
->autocfg
.dig_outs
)
2356 spec
->multiout
.dig_out_nid
= VT1708B_DIGOUT_NID
;
2357 spec
->dig_in_pin
= VT1708B_DIGIN_PIN
;
2358 if (spec
->autocfg
.dig_in_pin
)
2359 spec
->dig_in_nid
= VT1708B_DIGIN_NID
;
2361 if (spec
->kctls
.list
)
2362 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2364 spec
->input_mux
= &spec
->private_imux
[0];
2367 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2372 #ifdef CONFIG_SND_HDA_POWER_SAVE
2373 static struct hda_amp_list vt1708B_loopbacks
[] = {
2374 { 0x16, HDA_INPUT
, 1 },
2375 { 0x16, HDA_INPUT
, 2 },
2376 { 0x16, HDA_INPUT
, 3 },
2377 { 0x16, HDA_INPUT
, 4 },
2381 static int patch_vt1708S(struct hda_codec
*codec
);
2382 static int patch_vt1708B_8ch(struct hda_codec
*codec
)
2384 struct via_spec
*spec
;
2387 if (get_codec_type(codec
) == VT1708BCE
)
2388 return patch_vt1708S(codec
);
2389 /* create a codec specific record */
2390 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2396 /* automatic parse from the BIOS config */
2397 err
= vt1708B_parse_auto_config(codec
);
2402 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2403 "from BIOS. Using genenic mode...\n");
2406 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_8ch_volume_init_verbs
;
2407 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2409 spec
->stream_name_analog
= "VT1708B Analog";
2410 spec
->stream_analog_playback
= &vt1708B_8ch_pcm_analog_playback
;
2411 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2413 spec
->stream_name_digital
= "VT1708B Digital";
2414 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2415 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2417 if (!spec
->adc_nids
&& spec
->input_mux
) {
2418 spec
->adc_nids
= vt1708B_adc_nids
;
2419 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2420 get_mux_nids(codec
);
2421 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2425 codec
->patch_ops
= via_patch_ops
;
2427 codec
->patch_ops
.init
= via_auto_init
;
2428 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2429 #ifdef CONFIG_SND_HDA_POWER_SAVE
2430 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2436 static int patch_vt1708B_4ch(struct hda_codec
*codec
)
2438 struct via_spec
*spec
;
2441 /* create a codec specific record */
2442 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2448 /* automatic parse from the BIOS config */
2449 err
= vt1708B_parse_auto_config(codec
);
2454 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2455 "from BIOS. Using genenic mode...\n");
2458 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_4ch_volume_init_verbs
;
2459 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2461 spec
->stream_name_analog
= "VT1708B Analog";
2462 spec
->stream_analog_playback
= &vt1708B_4ch_pcm_analog_playback
;
2463 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2465 spec
->stream_name_digital
= "VT1708B Digital";
2466 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2467 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2469 if (!spec
->adc_nids
&& spec
->input_mux
) {
2470 spec
->adc_nids
= vt1708B_adc_nids
;
2471 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2472 get_mux_nids(codec
);
2473 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2477 codec
->patch_ops
= via_patch_ops
;
2479 codec
->patch_ops
.init
= via_auto_init
;
2480 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2481 #ifdef CONFIG_SND_HDA_POWER_SAVE
2482 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2488 /* Patch for VT1708S */
2490 /* VT1708S software backdoor based override for buggy hardware micboost
2492 #define MIC_BOOST_VOLUME(xname, nid) { \
2493 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2496 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2497 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2498 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2499 .info = mic_boost_volume_info, \
2500 .get = snd_hda_mixer_amp_volume_get, \
2501 .put = snd_hda_mixer_amp_volume_put, \
2502 .tlv = { .c = mic_boost_tlv }, \
2503 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2505 /* capture mixer elements */
2506 static struct snd_kcontrol_new vt1708S_capture_mixer
[] = {
2507 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
2508 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
2509 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
2510 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
2511 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2512 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2514 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2515 /* The multiple "Capture Source" controls confuse alsamixer
2516 * So call somewhat different..
2518 /* .name = "Capture Source", */
2519 .name
= "Input Source",
2521 .info
= via_mux_enum_info
,
2522 .get
= via_mux_enum_get
,
2523 .put
= via_mux_enum_put
,
2528 static struct hda_verb vt1708S_volume_init_verbs
[] = {
2529 /* Unmute ADC0-1 and set the default input to mic-in */
2530 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2531 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2533 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2534 * analog-loopback mixer widget */
2535 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2536 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2537 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2538 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2539 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2540 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2542 /* Setup default input of PW4 to MW0 */
2543 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2544 /* PW9, PW10 Output enable */
2545 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2546 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2547 /* Enable Mic Boost Volume backdoor */
2552 static struct hda_verb vt1708S_uniwill_init_verbs
[] = {
2553 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2557 static struct hda_pcm_stream vt1708S_pcm_analog_playback
= {
2561 .nid
= 0x10, /* NID to query formats and rates */
2563 .open
= via_playback_pcm_open
,
2564 .prepare
= via_playback_pcm_prepare
,
2565 .cleanup
= via_playback_pcm_cleanup
2569 static struct hda_pcm_stream vt1708S_pcm_analog_capture
= {
2573 .nid
= 0x13, /* NID to query formats and rates */
2575 .prepare
= via_capture_pcm_prepare
,
2576 .cleanup
= via_capture_pcm_cleanup
2580 static struct hda_pcm_stream vt1708S_pcm_digital_playback
= {
2584 /* NID is set in via_build_pcms */
2586 .open
= via_dig_playback_pcm_open
,
2587 .close
= via_dig_playback_pcm_close
,
2588 .prepare
= via_dig_playback_pcm_prepare
,
2589 .cleanup
= via_dig_playback_pcm_cleanup
2593 /* fill in the dac_nids table from the parsed pin configuration */
2594 static int vt1708S_auto_fill_dac_nids(struct via_spec
*spec
,
2595 const struct auto_pin_cfg
*cfg
)
2600 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2602 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2604 for (i
= 0; i
< 4; i
++) {
2605 nid
= cfg
->line_out_pins
[i
];
2607 /* config dac list */
2609 case AUTO_SEQ_FRONT
:
2610 spec
->multiout
.dac_nids
[i
] = 0x10;
2612 case AUTO_SEQ_CENLFE
:
2613 spec
->multiout
.dac_nids
[i
] = 0x24;
2615 case AUTO_SEQ_SURROUND
:
2616 spec
->multiout
.dac_nids
[i
] = 0x11;
2619 spec
->multiout
.dac_nids
[i
] = 0x25;
2628 /* add playback controls from the parsed DAC table */
2629 static int vt1708S_auto_create_multi_out_ctls(struct via_spec
*spec
,
2630 const struct auto_pin_cfg
*cfg
)
2633 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2634 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x24, 0x25};
2635 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x26, 0x27};
2636 hda_nid_t nid
, nid_vol
, nid_mute
;
2639 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2640 nid
= cfg
->line_out_pins
[i
];
2645 nid_vol
= nid_vols
[i
];
2646 nid_mute
= nid_mutes
[i
];
2648 if (i
== AUTO_SEQ_CENLFE
) {
2650 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2651 "Center Playback Volume",
2652 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2656 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2657 "LFE Playback Volume",
2658 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2662 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2663 "Center Playback Switch",
2664 HDA_COMPOSE_AMP_VAL(nid_mute
,
2669 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2670 "LFE Playback Switch",
2671 HDA_COMPOSE_AMP_VAL(nid_mute
,
2676 } else if (i
== AUTO_SEQ_FRONT
) {
2677 /* add control to mixer index 0 */
2678 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2679 "Master Front Playback Volume",
2680 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2684 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2685 "Master Front Playback Switch",
2686 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2692 sprintf(name
, "%s Playback Volume", chname
[i
]);
2693 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2694 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2698 sprintf(name
, "%s Playback Switch", chname
[i
]);
2699 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2700 HDA_COMPOSE_AMP_VAL(nid_mute
,
2706 sprintf(name
, "%s Playback Volume", chname
[i
]);
2707 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2708 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2712 sprintf(name
, "%s Playback Switch", chname
[i
]);
2713 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2714 HDA_COMPOSE_AMP_VAL(nid_mute
,
2725 static int vt1708S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2732 spec
->multiout
.hp_nid
= VT1708S_HP_NID
; /* AOW3 */
2734 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2735 "Headphone Playback Volume",
2736 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
2740 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2741 "Headphone Playback Switch",
2742 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2746 create_hp_imux(spec
);
2751 /* create playback/capture controls for input pins */
2752 static int vt1708S_auto_create_analog_input_ctls(struct via_spec
*spec
,
2753 const struct auto_pin_cfg
*cfg
)
2755 static char *labels
[] = {
2756 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2758 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2759 int i
, err
, idx
= 0;
2761 /* for internal loopback recording select */
2762 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2763 imux
->items
[imux
->num_items
].index
= 5;
2766 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2767 if (!cfg
->input_pins
[i
])
2770 switch (cfg
->input_pins
[i
]) {
2771 case 0x1a: /* Mic */
2775 case 0x1b: /* Line In */
2779 case 0x1e: /* Front Mic */
2787 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
2791 imux
->items
[imux
->num_items
].label
= labels
[i
];
2792 imux
->items
[imux
->num_items
].index
= idx
-1;
2798 /* fill out digital output widgets; one for master and one for slave outputs */
2799 static void fill_dig_outs(struct hda_codec
*codec
)
2801 struct via_spec
*spec
= codec
->spec
;
2804 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
2808 nid
= spec
->autocfg
.dig_out_pins
[i
];
2811 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
2814 if (!spec
->multiout
.dig_out_nid
)
2815 spec
->multiout
.dig_out_nid
= nid
;
2817 spec
->slave_dig_outs
[0] = nid
;
2818 break; /* at most two dig outs */
2823 static int vt1708S_parse_auto_config(struct hda_codec
*codec
)
2825 struct via_spec
*spec
= codec
->spec
;
2828 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2831 err
= vt1708S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2834 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2835 return 0; /* can't find valid BIOS pin config */
2837 err
= vt1708S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2840 err
= vt1708S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2843 err
= vt1708S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2847 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2849 fill_dig_outs(codec
);
2851 if (spec
->kctls
.list
)
2852 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2854 spec
->input_mux
= &spec
->private_imux
[0];
2857 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2862 #ifdef CONFIG_SND_HDA_POWER_SAVE
2863 static struct hda_amp_list vt1708S_loopbacks
[] = {
2864 { 0x16, HDA_INPUT
, 1 },
2865 { 0x16, HDA_INPUT
, 2 },
2866 { 0x16, HDA_INPUT
, 3 },
2867 { 0x16, HDA_INPUT
, 4 },
2872 static int patch_vt1708S(struct hda_codec
*codec
)
2874 struct via_spec
*spec
;
2877 /* create a codec specific record */
2878 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2884 /* automatic parse from the BIOS config */
2885 err
= vt1708S_parse_auto_config(codec
);
2890 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2891 "from BIOS. Using genenic mode...\n");
2894 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_volume_init_verbs
;
2895 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_uniwill_init_verbs
;
2897 spec
->stream_name_analog
= "VT1708S Analog";
2898 spec
->stream_analog_playback
= &vt1708S_pcm_analog_playback
;
2899 spec
->stream_analog_capture
= &vt1708S_pcm_analog_capture
;
2901 spec
->stream_name_digital
= "VT1708S Digital";
2902 spec
->stream_digital_playback
= &vt1708S_pcm_digital_playback
;
2904 if (!spec
->adc_nids
&& spec
->input_mux
) {
2905 spec
->adc_nids
= vt1708S_adc_nids
;
2906 spec
->num_adc_nids
= ARRAY_SIZE(vt1708S_adc_nids
);
2907 get_mux_nids(codec
);
2908 spec
->mixers
[spec
->num_mixers
] = vt1708S_capture_mixer
;
2912 codec
->patch_ops
= via_patch_ops
;
2914 codec
->patch_ops
.init
= via_auto_init
;
2915 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2916 #ifdef CONFIG_SND_HDA_POWER_SAVE
2917 spec
->loopback
.amplist
= vt1708S_loopbacks
;
2920 /* correct names for VT1708BCE */
2921 if (get_codec_type(codec
) == VT1708BCE
) {
2922 kfree(codec
->chip_name
);
2923 codec
->chip_name
= kstrdup("VT1708BCE", GFP_KERNEL
);
2924 snprintf(codec
->bus
->card
->mixername
,
2925 sizeof(codec
->bus
->card
->mixername
),
2926 "%s %s", codec
->vendor_name
, codec
->chip_name
);
2927 spec
->stream_name_analog
= "VT1708BCE Analog";
2928 spec
->stream_name_digital
= "VT1708BCE Digital";
2933 /* Patch for VT1702 */
2935 /* capture mixer elements */
2936 static struct snd_kcontrol_new vt1702_capture_mixer
[] = {
2937 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT
),
2938 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT
),
2939 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT
),
2940 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT
),
2941 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT
),
2942 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT
),
2943 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2946 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2947 /* The multiple "Capture Source" controls confuse alsamixer
2948 * So call somewhat different..
2950 /* .name = "Capture Source", */
2951 .name
= "Input Source",
2953 .info
= via_mux_enum_info
,
2954 .get
= via_mux_enum_get
,
2955 .put
= via_mux_enum_put
,
2960 static struct hda_verb vt1702_volume_init_verbs
[] = {
2962 * Unmute ADC0-1 and set the default input to mic-in
2964 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2965 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2966 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2969 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2972 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2973 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2974 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2975 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2976 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2977 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
2979 /* Setup default input of PW4 to MW0 */
2980 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x1},
2981 /* PW6 PW7 Output enable */
2982 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2983 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2987 static struct hda_verb vt1702_uniwill_init_verbs
[] = {
2988 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_GPIO_EVENT
},
2989 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2993 static struct hda_pcm_stream vt1702_pcm_analog_playback
= {
2997 .nid
= 0x10, /* NID to query formats and rates */
2999 .open
= via_playback_pcm_open
,
3000 .prepare
= via_playback_multi_pcm_prepare
,
3001 .cleanup
= via_playback_multi_pcm_cleanup
3005 static struct hda_pcm_stream vt1702_pcm_analog_capture
= {
3009 .nid
= 0x12, /* NID to query formats and rates */
3011 .prepare
= via_capture_pcm_prepare
,
3012 .cleanup
= via_capture_pcm_cleanup
3016 static struct hda_pcm_stream vt1702_pcm_digital_playback
= {
3020 /* NID is set in via_build_pcms */
3022 .open
= via_dig_playback_pcm_open
,
3023 .close
= via_dig_playback_pcm_close
,
3024 .prepare
= via_dig_playback_pcm_prepare
,
3025 .cleanup
= via_dig_playback_pcm_cleanup
3029 /* fill in the dac_nids table from the parsed pin configuration */
3030 static int vt1702_auto_fill_dac_nids(struct via_spec
*spec
,
3031 const struct auto_pin_cfg
*cfg
)
3033 spec
->multiout
.num_dacs
= 1;
3034 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3036 if (cfg
->line_out_pins
[0]) {
3037 /* config dac list */
3038 spec
->multiout
.dac_nids
[0] = 0x10;
3044 /* add playback controls from the parsed DAC table */
3045 static int vt1702_auto_create_line_out_ctls(struct via_spec
*spec
,
3046 const struct auto_pin_cfg
*cfg
)
3050 if (!cfg
->line_out_pins
[0])
3053 /* add control to mixer index 0 */
3054 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3055 "Master Front Playback Volume",
3056 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3059 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3060 "Master Front Playback Switch",
3061 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3066 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3067 "Front Playback Volume",
3068 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
));
3071 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3072 "Front Playback Switch",
3073 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT
));
3080 static int vt1702_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3087 spec
->multiout
.hp_nid
= 0x1D;
3089 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3090 "Headphone Playback Volume",
3091 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT
));
3095 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3096 "Headphone Playback Switch",
3097 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3101 create_hp_imux(spec
);
3106 /* create playback/capture controls for input pins */
3107 static int vt1702_auto_create_analog_input_ctls(struct via_spec
*spec
,
3108 const struct auto_pin_cfg
*cfg
)
3110 static char *labels
[] = {
3111 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3113 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3114 int i
, err
, idx
= 0;
3116 /* for internal loopback recording select */
3117 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3118 imux
->items
[imux
->num_items
].index
= 3;
3121 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3122 if (!cfg
->input_pins
[i
])
3125 switch (cfg
->input_pins
[i
]) {
3126 case 0x14: /* Mic */
3130 case 0x15: /* Line In */
3134 case 0x18: /* Front Mic */
3138 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
],
3139 labels
[i
], idx
, 0x1A);
3142 imux
->items
[imux
->num_items
].label
= labels
[i
];
3143 imux
->items
[imux
->num_items
].index
= idx
-1;
3149 static int vt1702_parse_auto_config(struct hda_codec
*codec
)
3151 struct via_spec
*spec
= codec
->spec
;
3154 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3157 err
= vt1702_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3160 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3161 return 0; /* can't find valid BIOS pin config */
3163 err
= vt1702_auto_create_line_out_ctls(spec
, &spec
->autocfg
);
3166 err
= vt1702_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3169 /* limit AA path volume to 0 dB */
3170 snd_hda_override_amp_caps(codec
, 0x1A, HDA_INPUT
,
3171 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
3172 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
3173 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
3174 (1 << AC_AMPCAP_MUTE_SHIFT
));
3175 err
= vt1702_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3179 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3181 fill_dig_outs(codec
);
3183 if (spec
->kctls
.list
)
3184 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3186 spec
->input_mux
= &spec
->private_imux
[0];
3189 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3194 #ifdef CONFIG_SND_HDA_POWER_SAVE
3195 static struct hda_amp_list vt1702_loopbacks
[] = {
3196 { 0x1A, HDA_INPUT
, 1 },
3197 { 0x1A, HDA_INPUT
, 2 },
3198 { 0x1A, HDA_INPUT
, 3 },
3199 { 0x1A, HDA_INPUT
, 4 },
3204 static int patch_vt1702(struct hda_codec
*codec
)
3206 struct via_spec
*spec
;
3208 unsigned int response
;
3209 unsigned char control
;
3211 /* create a codec specific record */
3212 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3218 /* automatic parse from the BIOS config */
3219 err
= vt1702_parse_auto_config(codec
);
3224 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3225 "from BIOS. Using genenic mode...\n");
3228 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_volume_init_verbs
;
3229 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_uniwill_init_verbs
;
3231 spec
->stream_name_analog
= "VT1702 Analog";
3232 spec
->stream_analog_playback
= &vt1702_pcm_analog_playback
;
3233 spec
->stream_analog_capture
= &vt1702_pcm_analog_capture
;
3235 spec
->stream_name_digital
= "VT1702 Digital";
3236 spec
->stream_digital_playback
= &vt1702_pcm_digital_playback
;
3238 if (!spec
->adc_nids
&& spec
->input_mux
) {
3239 spec
->adc_nids
= vt1702_adc_nids
;
3240 spec
->num_adc_nids
= ARRAY_SIZE(vt1702_adc_nids
);
3241 get_mux_nids(codec
);
3242 spec
->mixers
[spec
->num_mixers
] = vt1702_capture_mixer
;
3246 codec
->patch_ops
= via_patch_ops
;
3248 codec
->patch_ops
.init
= via_auto_init
;
3249 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3250 #ifdef CONFIG_SND_HDA_POWER_SAVE
3251 spec
->loopback
.amplist
= vt1702_loopbacks
;
3255 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF8C, 0);
3256 control
= (unsigned char)(response
& 0xff);
3258 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF88, control
);
3260 /* Enable GPIO 0&1 for volume&mute control */
3261 /* Enable GPIO 2 for DMIC-DATA */
3262 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF84, 0);
3263 control
= (unsigned char)((response
>> 16) & 0x3f);
3264 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF82, control
);
3272 static struct hda_codec_preset snd_hda_preset_via
[] = {
3273 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
3274 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
3275 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
3276 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
3277 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
3278 .patch
= patch_vt1709_10ch
},
3279 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
3280 .patch
= patch_vt1709_10ch
},
3281 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
3282 .patch
= patch_vt1709_10ch
},
3283 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
3284 .patch
= patch_vt1709_10ch
},
3285 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
3286 .patch
= patch_vt1709_6ch
},
3287 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
3288 .patch
= patch_vt1709_6ch
},
3289 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
3290 .patch
= patch_vt1709_6ch
},
3291 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
3292 .patch
= patch_vt1709_6ch
},
3293 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
3294 .patch
= patch_vt1708B_8ch
},
3295 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
3296 .patch
= patch_vt1708B_8ch
},
3297 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
3298 .patch
= patch_vt1708B_8ch
},
3299 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
3300 .patch
= patch_vt1708B_8ch
},
3301 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
3302 .patch
= patch_vt1708B_4ch
},
3303 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
3304 .patch
= patch_vt1708B_4ch
},
3305 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
3306 .patch
= patch_vt1708B_4ch
},
3307 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
3308 .patch
= patch_vt1708B_4ch
},
3309 { .id
= 0x11060397, .name
= "VT1708S",
3310 .patch
= patch_vt1708S
},
3311 { .id
= 0x11061397, .name
= "VT1708S",
3312 .patch
= patch_vt1708S
},
3313 { .id
= 0x11062397, .name
= "VT1708S",
3314 .patch
= patch_vt1708S
},
3315 { .id
= 0x11063397, .name
= "VT1708S",
3316 .patch
= patch_vt1708S
},
3317 { .id
= 0x11064397, .name
= "VT1708S",
3318 .patch
= patch_vt1708S
},
3319 { .id
= 0x11065397, .name
= "VT1708S",
3320 .patch
= patch_vt1708S
},
3321 { .id
= 0x11066397, .name
= "VT1708S",
3322 .patch
= patch_vt1708S
},
3323 { .id
= 0x11067397, .name
= "VT1708S",
3324 .patch
= patch_vt1708S
},
3325 { .id
= 0x11060398, .name
= "VT1702",
3326 .patch
= patch_vt1702
},
3327 { .id
= 0x11061398, .name
= "VT1702",
3328 .patch
= patch_vt1702
},
3329 { .id
= 0x11062398, .name
= "VT1702",
3330 .patch
= patch_vt1702
},
3331 { .id
= 0x11063398, .name
= "VT1702",
3332 .patch
= patch_vt1702
},
3333 { .id
= 0x11064398, .name
= "VT1702",
3334 .patch
= patch_vt1702
},
3335 { .id
= 0x11065398, .name
= "VT1702",
3336 .patch
= patch_vt1702
},
3337 { .id
= 0x11066398, .name
= "VT1702",
3338 .patch
= patch_vt1702
},
3339 { .id
= 0x11067398, .name
= "VT1702",
3340 .patch
= patch_vt1702
},
3344 MODULE_ALIAS("snd-hda-codec-id:1106*");
3346 static struct hda_codec_preset_list via_list
= {
3347 .preset
= snd_hda_preset_via
,
3348 .owner
= THIS_MODULE
,
3351 MODULE_LICENSE("GPL");
3352 MODULE_DESCRIPTION("VIA HD-audio codec");
3354 static int __init
patch_via_init(void)
3356 return snd_hda_add_codec_preset(&via_list
);
3359 static void __exit
patch_via_exit(void)
3361 snd_hda_delete_codec_preset(&via_list
);
3364 module_init(patch_via_init
)
3365 module_exit(patch_via_exit
)