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
);
396 if (!spec
->mux_nids
[adc_idx
])
398 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
399 spec
->mux_nids
[adc_idx
],
400 &spec
->cur_mux
[adc_idx
]);
403 static int via_independent_hp_info(struct snd_kcontrol
*kcontrol
,
404 struct snd_ctl_elem_info
*uinfo
)
406 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
407 struct via_spec
*spec
= codec
->spec
;
408 return snd_hda_input_mux_info(spec
->hp_mux
, uinfo
);
411 static int via_independent_hp_get(struct snd_kcontrol
*kcontrol
,
412 struct snd_ctl_elem_value
*ucontrol
)
414 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
415 struct via_spec
*spec
= codec
->spec
;
416 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
417 unsigned int pinsel
= snd_hda_codec_read(codec
, nid
, 0,
418 AC_VERB_GET_CONNECT_SEL
,
421 ucontrol
->value
.enumerated
.item
[0] = pinsel
;
426 static int via_independent_hp_put(struct snd_kcontrol
*kcontrol
,
427 struct snd_ctl_elem_value
*ucontrol
)
429 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
430 struct via_spec
*spec
= codec
->spec
;
431 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
432 unsigned int pinsel
= ucontrol
->value
.enumerated
.item
[0];
433 unsigned int con_nid
= snd_hda_codec_read(codec
, nid
, 0,
434 AC_VERB_GET_CONNECT_LIST
, 0) & 0xff;
436 if (con_nid
== spec
->multiout
.hp_nid
) {
438 if (!spec
->hp_independent_mode
) {
439 if (spec
->multiout
.num_dacs
> 1)
440 spec
->multiout
.num_dacs
-= 1;
441 spec
->hp_independent_mode
= 1;
443 } else if (pinsel
== 1) {
444 if (spec
->hp_independent_mode
) {
445 if (spec
->multiout
.num_dacs
> 1)
446 spec
->multiout
.num_dacs
+= 1;
447 spec
->hp_independent_mode
= 0;
452 if (spec
->hp_independent_mode
) {
453 if (spec
->multiout
.num_dacs
> 1)
454 spec
->multiout
.num_dacs
+= 1;
455 spec
->hp_independent_mode
= 0;
457 } else if (pinsel
== 1) {
458 if (!spec
->hp_independent_mode
) {
459 if (spec
->multiout
.num_dacs
> 1)
460 spec
->multiout
.num_dacs
-= 1;
461 spec
->hp_independent_mode
= 1;
465 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
,
468 if (spec
->multiout
.hp_nid
&&
469 spec
->multiout
.hp_nid
!= spec
->multiout
.dac_nids
[HDA_FRONT
])
470 snd_hda_codec_setup_stream(codec
,
471 spec
->multiout
.hp_nid
,
477 static struct snd_kcontrol_new via_hp_mixer
[] = {
479 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
480 .name
= "Independent HP",
482 .info
= via_independent_hp_info
,
483 .get
= via_independent_hp_get
,
484 .put
= via_independent_hp_put
,
489 /* capture mixer elements */
490 static struct snd_kcontrol_new vt1708_capture_mixer
[] = {
491 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT
),
492 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT
),
493 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT
),
494 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT
),
496 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
497 /* The multiple "Capture Source" controls confuse alsamixer
498 * So call somewhat different..
500 /* .name = "Capture Source", */
501 .name
= "Input Source",
503 .info
= via_mux_enum_info
,
504 .get
= via_mux_enum_get
,
505 .put
= via_mux_enum_put
,
510 * generic initialization of ADC, input mixers and output mixers
512 static struct hda_verb vt1708_volume_init_verbs
[] = {
514 * Unmute ADC0-1 and set the default input to mic-in
516 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
517 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
520 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
523 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
524 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
525 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
526 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
527 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
528 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
531 * Set up output mixers (0x19 - 0x1b)
533 /* set vol=0 to output mixers */
534 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
535 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
536 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
538 /* Setup default input to PW4 */
539 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
540 /* PW9 Output enable */
541 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
545 static int via_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
546 struct hda_codec
*codec
,
547 struct snd_pcm_substream
*substream
)
549 struct via_spec
*spec
= codec
->spec
;
550 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
554 static int via_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
555 struct hda_codec
*codec
,
556 unsigned int stream_tag
,
558 struct snd_pcm_substream
*substream
)
560 struct via_spec
*spec
= codec
->spec
;
561 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
562 stream_tag
, format
, substream
);
565 static int via_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
566 struct hda_codec
*codec
,
567 struct snd_pcm_substream
*substream
)
569 struct via_spec
*spec
= codec
->spec
;
570 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
574 static void playback_multi_pcm_prep_0(struct hda_codec
*codec
,
575 unsigned int stream_tag
,
577 struct snd_pcm_substream
*substream
)
579 struct via_spec
*spec
= codec
->spec
;
580 struct hda_multi_out
*mout
= &spec
->multiout
;
581 hda_nid_t
*nids
= mout
->dac_nids
;
582 int chs
= substream
->runtime
->channels
;
585 mutex_lock(&codec
->spdif_mutex
);
586 if (mout
->dig_out_nid
&& mout
->dig_out_used
!= HDA_DIG_EXCLUSIVE
) {
588 snd_hda_is_supported_format(codec
, mout
->dig_out_nid
,
590 !(codec
->spdif_status
& IEC958_AES0_NONAUDIO
)) {
591 mout
->dig_out_used
= HDA_DIG_ANALOG_DUP
;
592 /* turn off SPDIF once; otherwise the IEC958 bits won't
594 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
595 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
596 AC_VERB_SET_DIGI_CONVERT_1
,
598 ~AC_DIG1_ENABLE
& 0xff);
599 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
600 stream_tag
, 0, format
);
601 /* turn on again (if needed) */
602 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
603 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
604 AC_VERB_SET_DIGI_CONVERT_1
,
605 codec
->spdif_ctls
& 0xff);
607 mout
->dig_out_used
= 0;
608 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
612 mutex_unlock(&codec
->spdif_mutex
);
615 snd_hda_codec_setup_stream(codec
, nids
[HDA_FRONT
], stream_tag
,
618 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
619 !spec
->hp_independent_mode
)
620 /* headphone out will just decode front left/right (stereo) */
621 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
, stream_tag
,
624 /* extra outputs copied from front */
625 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
626 if (mout
->extra_out_nid
[i
])
627 snd_hda_codec_setup_stream(codec
,
628 mout
->extra_out_nid
[i
],
629 stream_tag
, 0, format
);
632 for (i
= 1; i
< mout
->num_dacs
; i
++) {
633 if (chs
>= (i
+ 1) * 2) /* independent out */
634 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
636 else /* copy front */
637 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
642 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
643 struct hda_codec
*codec
,
644 unsigned int stream_tag
,
646 struct snd_pcm_substream
*substream
)
648 struct via_spec
*spec
= codec
->spec
;
649 struct hda_multi_out
*mout
= &spec
->multiout
;
650 hda_nid_t
*nids
= mout
->dac_nids
;
652 if (substream
->number
== 0)
653 playback_multi_pcm_prep_0(codec
, stream_tag
, format
,
656 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
657 spec
->hp_independent_mode
)
658 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
659 stream_tag
, 0, format
);
665 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
666 struct hda_codec
*codec
,
667 struct snd_pcm_substream
*substream
)
669 struct via_spec
*spec
= codec
->spec
;
670 struct hda_multi_out
*mout
= &spec
->multiout
;
671 hda_nid_t
*nids
= mout
->dac_nids
;
674 if (substream
->number
== 0) {
675 for (i
= 0; i
< mout
->num_dacs
; i
++)
676 snd_hda_codec_setup_stream(codec
, nids
[i
], 0, 0, 0);
678 if (mout
->hp_nid
&& !spec
->hp_independent_mode
)
679 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
682 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
683 if (mout
->extra_out_nid
[i
])
684 snd_hda_codec_setup_stream(codec
,
685 mout
->extra_out_nid
[i
],
687 mutex_lock(&codec
->spdif_mutex
);
688 if (mout
->dig_out_nid
&&
689 mout
->dig_out_used
== HDA_DIG_ANALOG_DUP
) {
690 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
692 mout
->dig_out_used
= 0;
694 mutex_unlock(&codec
->spdif_mutex
);
696 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
697 spec
->hp_independent_mode
)
698 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
708 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
709 struct hda_codec
*codec
,
710 struct snd_pcm_substream
*substream
)
712 struct via_spec
*spec
= codec
->spec
;
713 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
716 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
717 struct hda_codec
*codec
,
718 struct snd_pcm_substream
*substream
)
720 struct via_spec
*spec
= codec
->spec
;
721 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
724 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
725 struct hda_codec
*codec
,
726 unsigned int stream_tag
,
728 struct snd_pcm_substream
*substream
)
730 struct via_spec
*spec
= codec
->spec
;
731 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
732 stream_tag
, format
, substream
);
735 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
736 struct hda_codec
*codec
,
737 struct snd_pcm_substream
*substream
)
739 struct via_spec
*spec
= codec
->spec
;
740 snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
747 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
748 struct hda_codec
*codec
,
749 unsigned int stream_tag
,
751 struct snd_pcm_substream
*substream
)
753 struct via_spec
*spec
= codec
->spec
;
755 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
756 stream_tag
, 0, format
);
760 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
761 struct hda_codec
*codec
,
762 struct snd_pcm_substream
*substream
)
764 struct via_spec
*spec
= codec
->spec
;
765 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
769 static struct hda_pcm_stream vt1708_pcm_analog_playback
= {
773 .nid
= 0x10, /* NID to query formats and rates */
775 .open
= via_playback_pcm_open
,
776 .prepare
= via_playback_multi_pcm_prepare
,
777 .cleanup
= via_playback_multi_pcm_cleanup
781 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
785 .nid
= 0x10, /* NID to query formats and rates */
786 /* We got noisy outputs on the right channel on VT1708 when
787 * 24bit samples are used. Until any workaround is found,
788 * disable the 24bit format, so far.
790 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
792 .open
= via_playback_pcm_open
,
793 .prepare
= via_playback_pcm_prepare
,
794 .cleanup
= via_playback_pcm_cleanup
798 static struct hda_pcm_stream vt1708_pcm_analog_capture
= {
802 .nid
= 0x15, /* NID to query formats and rates */
804 .prepare
= via_capture_pcm_prepare
,
805 .cleanup
= via_capture_pcm_cleanup
809 static struct hda_pcm_stream vt1708_pcm_digital_playback
= {
813 /* NID is set in via_build_pcms */
815 .open
= via_dig_playback_pcm_open
,
816 .close
= via_dig_playback_pcm_close
,
817 .prepare
= via_dig_playback_pcm_prepare
,
818 .cleanup
= via_dig_playback_pcm_cleanup
822 static struct hda_pcm_stream vt1708_pcm_digital_capture
= {
828 static int via_build_controls(struct hda_codec
*codec
)
830 struct via_spec
*spec
= codec
->spec
;
834 for (i
= 0; i
< spec
->num_mixers
; i
++) {
835 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
840 if (spec
->multiout
.dig_out_nid
) {
841 err
= snd_hda_create_spdif_out_ctls(codec
,
842 spec
->multiout
.dig_out_nid
);
845 err
= snd_hda_create_spdif_share_sw(codec
,
849 spec
->multiout
.share_spdif
= 1;
851 if (spec
->dig_in_nid
) {
852 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
856 via_free_kctls(codec
); /* no longer needed */
860 static int via_build_pcms(struct hda_codec
*codec
)
862 struct via_spec
*spec
= codec
->spec
;
863 struct hda_pcm
*info
= spec
->pcm_rec
;
866 codec
->pcm_info
= info
;
868 info
->name
= spec
->stream_name_analog
;
869 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *(spec
->stream_analog_playback
);
870 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
871 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *(spec
->stream_analog_capture
);
872 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
874 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
875 spec
->multiout
.max_channels
;
877 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
880 info
->name
= spec
->stream_name_digital
;
881 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
882 if (spec
->multiout
.dig_out_nid
) {
883 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
884 *(spec
->stream_digital_playback
);
885 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
886 spec
->multiout
.dig_out_nid
;
888 if (spec
->dig_in_nid
) {
889 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
890 *(spec
->stream_digital_capture
);
891 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
899 static void via_free(struct hda_codec
*codec
)
901 struct via_spec
*spec
= codec
->spec
;
906 via_free_kctls(codec
);
910 /* mute internal speaker if HP is plugged */
911 static void via_hp_automute(struct hda_codec
*codec
)
913 unsigned int present
;
914 struct via_spec
*spec
= codec
->spec
;
916 present
= snd_hda_codec_read(codec
, spec
->autocfg
.hp_pins
[0], 0,
917 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
918 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
919 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
920 present
? HDA_AMP_MUTE
: 0);
923 static void via_gpio_control(struct hda_codec
*codec
)
925 unsigned int gpio_data
;
926 unsigned int vol_counter
;
928 unsigned int master_vol
;
930 struct via_spec
*spec
= codec
->spec
;
932 gpio_data
= snd_hda_codec_read(codec
, codec
->afg
, 0,
933 AC_VERB_GET_GPIO_DATA
, 0) & 0x03;
935 vol_counter
= (snd_hda_codec_read(codec
, codec
->afg
, 0,
936 0xF84, 0) & 0x3F0000) >> 16;
938 vol
= vol_counter
& 0x1F;
939 master_vol
= snd_hda_codec_read(codec
, 0x1A, 0,
940 AC_VERB_GET_AMP_GAIN_MUTE
,
943 if (gpio_data
== 0x02) {
944 /* unmute line out */
945 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
946 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
948 if (vol_counter
& 0x20) {
949 /* decrease volume */
950 if (vol
> master_vol
)
952 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
,
956 /* increase volume */
957 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
, 0,
959 ((master_vol
+vol
) > 0x2A) ? 0x2A :
962 } else if (!(gpio_data
& 0x02)) {
964 snd_hda_codec_amp_stereo(codec
,
965 spec
->autocfg
.line_out_pins
[0],
966 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
971 /* unsolicited event for jack sensing */
972 static void via_unsol_event(struct hda_codec
*codec
,
976 if (res
== VIA_HP_EVENT
)
977 via_hp_automute(codec
);
978 else if (res
== VIA_GPIO_EVENT
)
979 via_gpio_control(codec
);
982 static int via_init(struct hda_codec
*codec
)
984 struct via_spec
*spec
= codec
->spec
;
986 for (i
= 0; i
< spec
->num_iverbs
; i
++)
987 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
989 /* Lydia Add for EAPD enable */
990 if (!spec
->dig_in_nid
) { /* No Digital In connection */
991 if (spec
->dig_in_pin
) {
992 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
993 AC_VERB_SET_PIN_WIDGET_CONTROL
,
995 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
996 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
998 } else /* enable SPDIF-input pin */
999 snd_hda_codec_write(codec
, spec
->autocfg
.dig_in_pin
, 0,
1000 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
1002 /* assign slave outs */
1003 if (spec
->slave_dig_outs
[0])
1004 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
1009 #ifdef CONFIG_SND_HDA_POWER_SAVE
1010 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
1012 struct via_spec
*spec
= codec
->spec
;
1013 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
1019 static struct hda_codec_ops via_patch_ops
= {
1020 .build_controls
= via_build_controls
,
1021 .build_pcms
= via_build_pcms
,
1024 #ifdef CONFIG_SND_HDA_POWER_SAVE
1025 .check_power_status
= via_check_power_status
,
1029 /* fill in the dac_nids table from the parsed pin configuration */
1030 static int vt1708_auto_fill_dac_nids(struct via_spec
*spec
,
1031 const struct auto_pin_cfg
*cfg
)
1036 spec
->multiout
.num_dacs
= cfg
->line_outs
;
1038 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1040 for(i
= 0; i
< 4; i
++) {
1041 nid
= cfg
->line_out_pins
[i
];
1043 /* config dac list */
1045 case AUTO_SEQ_FRONT
:
1046 spec
->multiout
.dac_nids
[i
] = 0x10;
1048 case AUTO_SEQ_CENLFE
:
1049 spec
->multiout
.dac_nids
[i
] = 0x12;
1051 case AUTO_SEQ_SURROUND
:
1052 spec
->multiout
.dac_nids
[i
] = 0x11;
1055 spec
->multiout
.dac_nids
[i
] = 0x13;
1064 /* add playback controls from the parsed DAC table */
1065 static int vt1708_auto_create_multi_out_ctls(struct via_spec
*spec
,
1066 const struct auto_pin_cfg
*cfg
)
1069 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1070 hda_nid_t nid
, nid_vol
= 0;
1073 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1074 nid
= cfg
->line_out_pins
[i
];
1079 if (i
!= AUTO_SEQ_FRONT
)
1082 if (i
== AUTO_SEQ_CENLFE
) {
1084 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1085 "Center Playback Volume",
1086 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1090 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1091 "LFE Playback Volume",
1092 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1096 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1097 "Center Playback Switch",
1098 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1102 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1103 "LFE Playback Switch",
1104 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1108 } else if (i
== AUTO_SEQ_FRONT
){
1109 /* add control to mixer index 0 */
1110 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1111 "Master Front Playback Volume",
1112 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1116 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1117 "Master Front Playback Switch",
1118 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1123 /* add control to PW3 */
1124 sprintf(name
, "%s Playback Volume", chname
[i
]);
1125 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1126 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1130 sprintf(name
, "%s Playback Switch", chname
[i
]);
1131 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1132 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1137 sprintf(name
, "%s Playback Volume", chname
[i
]);
1138 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1139 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1143 sprintf(name
, "%s Playback Switch", chname
[i
]);
1144 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1145 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1155 static void create_hp_imux(struct via_spec
*spec
)
1158 struct hda_input_mux
*imux
= &spec
->private_imux
[1];
1159 static const char *texts
[] = { "OFF", "ON", NULL
};
1161 /* for hp mode select */
1163 while (texts
[i
] != NULL
) {
1164 imux
->items
[imux
->num_items
].label
= texts
[i
];
1165 imux
->items
[imux
->num_items
].index
= i
;
1170 spec
->hp_mux
= &spec
->private_imux
[1];
1173 static int vt1708_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1180 spec
->multiout
.hp_nid
= VT1708_HP_NID
; /* AOW3 */
1182 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1183 "Headphone Playback Volume",
1184 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1187 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1188 "Headphone Playback Switch",
1189 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1193 create_hp_imux(spec
);
1198 /* create playback/capture controls for input pins */
1199 static int vt1708_auto_create_analog_input_ctls(struct via_spec
*spec
,
1200 const struct auto_pin_cfg
*cfg
)
1202 static char *labels
[] = {
1203 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1205 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1206 int i
, err
, idx
= 0;
1208 /* for internal loopback recording select */
1209 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1210 imux
->items
[imux
->num_items
].index
= idx
;
1213 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1214 if (!cfg
->input_pins
[i
])
1217 switch (cfg
->input_pins
[i
]) {
1218 case 0x1d: /* Mic */
1222 case 0x1e: /* Line In */
1226 case 0x21: /* Front Mic */
1234 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
1238 imux
->items
[imux
->num_items
].label
= labels
[i
];
1239 imux
->items
[imux
->num_items
].index
= idx
;
1245 #ifdef CONFIG_SND_HDA_POWER_SAVE
1246 static struct hda_amp_list vt1708_loopbacks
[] = {
1247 { 0x17, HDA_INPUT
, 1 },
1248 { 0x17, HDA_INPUT
, 2 },
1249 { 0x17, HDA_INPUT
, 3 },
1250 { 0x17, HDA_INPUT
, 4 },
1255 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
1257 unsigned int def_conf
;
1258 unsigned char seqassoc
;
1260 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
1261 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
1262 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
1263 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
) {
1264 if (seqassoc
== 0xff) {
1265 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
1266 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
1273 static int vt1708_parse_auto_config(struct hda_codec
*codec
)
1275 struct via_spec
*spec
= codec
->spec
;
1278 /* Add HP and CD pin config connect bit re-config action */
1279 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
1280 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
1282 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1285 err
= vt1708_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1288 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1289 return 0; /* can't find valid BIOS pin config */
1291 err
= vt1708_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1294 err
= vt1708_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1297 err
= vt1708_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1301 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1303 if (spec
->autocfg
.dig_outs
)
1304 spec
->multiout
.dig_out_nid
= VT1708_DIGOUT_NID
;
1305 spec
->dig_in_pin
= VT1708_DIGIN_PIN
;
1306 if (spec
->autocfg
.dig_in_pin
)
1307 spec
->dig_in_nid
= VT1708_DIGIN_NID
;
1309 if (spec
->kctls
.list
)
1310 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
1312 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_volume_init_verbs
;
1314 spec
->input_mux
= &spec
->private_imux
[0];
1317 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1322 /* init callback for auto-configuration model -- overriding the default init */
1323 static int via_auto_init(struct hda_codec
*codec
)
1326 via_auto_init_multi_out(codec
);
1327 via_auto_init_hp_out(codec
);
1328 via_auto_init_analog_input(codec
);
1332 static int get_mux_nids(struct hda_codec
*codec
)
1334 struct via_spec
*spec
= codec
->spec
;
1335 hda_nid_t nid
, conn
[8];
1339 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1340 nid
= spec
->adc_nids
[i
];
1342 type
= (get_wcaps(codec
, nid
) & AC_WCAP_TYPE
)
1343 >> AC_WCAP_TYPE_SHIFT
;
1344 if (type
== AC_WID_PIN
)
1346 n
= snd_hda_get_connections(codec
, nid
, conn
,
1351 spec
->mux_nids
[i
] = nid
;
1360 static int patch_vt1708(struct hda_codec
*codec
)
1362 struct via_spec
*spec
;
1365 /* create a codec specific record */
1366 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1372 /* automatic parse from the BIOS config */
1373 err
= vt1708_parse_auto_config(codec
);
1378 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
1379 "from BIOS. Using genenic mode...\n");
1383 spec
->stream_name_analog
= "VT1708 Analog";
1384 spec
->stream_analog_playback
= &vt1708_pcm_analog_playback
;
1385 /* disable 32bit format on VT1708 */
1386 if (codec
->vendor_id
== 0x11061708)
1387 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
1388 spec
->stream_analog_capture
= &vt1708_pcm_analog_capture
;
1390 spec
->stream_name_digital
= "VT1708 Digital";
1391 spec
->stream_digital_playback
= &vt1708_pcm_digital_playback
;
1392 spec
->stream_digital_capture
= &vt1708_pcm_digital_capture
;
1395 if (!spec
->adc_nids
&& spec
->input_mux
) {
1396 spec
->adc_nids
= vt1708_adc_nids
;
1397 spec
->num_adc_nids
= ARRAY_SIZE(vt1708_adc_nids
);
1398 spec
->mixers
[spec
->num_mixers
] = vt1708_capture_mixer
;
1402 codec
->patch_ops
= via_patch_ops
;
1404 codec
->patch_ops
.init
= via_auto_init
;
1405 #ifdef CONFIG_SND_HDA_POWER_SAVE
1406 spec
->loopback
.amplist
= vt1708_loopbacks
;
1412 /* capture mixer elements */
1413 static struct snd_kcontrol_new vt1709_capture_mixer
[] = {
1414 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT
),
1415 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT
),
1416 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT
),
1417 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT
),
1418 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT
),
1419 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT
),
1421 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1422 /* The multiple "Capture Source" controls confuse alsamixer
1423 * So call somewhat different..
1425 /* .name = "Capture Source", */
1426 .name
= "Input Source",
1428 .info
= via_mux_enum_info
,
1429 .get
= via_mux_enum_get
,
1430 .put
= via_mux_enum_put
,
1435 static struct hda_verb vt1709_uniwill_init_verbs
[] = {
1436 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
1441 * generic initialization of ADC, input mixers and output mixers
1443 static struct hda_verb vt1709_10ch_volume_init_verbs
[] = {
1445 * Unmute ADC0-2 and set the default input to mic-in
1447 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1448 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1449 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1452 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1455 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1456 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1457 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1458 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1459 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1460 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1463 * Set up output selector (0x1a, 0x1b, 0x29)
1465 /* set vol=0 to output mixers */
1466 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1467 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1468 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1471 * Unmute PW3 and PW4
1473 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1474 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1476 /* Set input of PW4 as AOW4 */
1477 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
1478 /* PW9 Output enable */
1479 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1483 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback
= {
1487 .nid
= 0x10, /* NID to query formats and rates */
1489 .open
= via_playback_pcm_open
,
1490 .prepare
= via_playback_pcm_prepare
,
1491 .cleanup
= via_playback_pcm_cleanup
1495 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback
= {
1499 .nid
= 0x10, /* NID to query formats and rates */
1501 .open
= via_playback_pcm_open
,
1502 .prepare
= via_playback_pcm_prepare
,
1503 .cleanup
= via_playback_pcm_cleanup
1507 static struct hda_pcm_stream vt1709_pcm_analog_capture
= {
1511 .nid
= 0x14, /* NID to query formats and rates */
1513 .prepare
= via_capture_pcm_prepare
,
1514 .cleanup
= via_capture_pcm_cleanup
1518 static struct hda_pcm_stream vt1709_pcm_digital_playback
= {
1522 /* NID is set in via_build_pcms */
1524 .open
= via_dig_playback_pcm_open
,
1525 .close
= via_dig_playback_pcm_close
1529 static struct hda_pcm_stream vt1709_pcm_digital_capture
= {
1535 static int vt1709_auto_fill_dac_nids(struct via_spec
*spec
,
1536 const struct auto_pin_cfg
*cfg
)
1541 if (cfg
->line_outs
== 4) /* 10 channels */
1542 spec
->multiout
.num_dacs
= cfg
->line_outs
+1; /* AOW0~AOW4 */
1543 else if (cfg
->line_outs
== 3) /* 6 channels */
1544 spec
->multiout
.num_dacs
= cfg
->line_outs
; /* AOW0~AOW2 */
1546 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1548 if (cfg
->line_outs
== 4) { /* 10 channels */
1549 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1550 nid
= cfg
->line_out_pins
[i
];
1552 /* config dac list */
1554 case AUTO_SEQ_FRONT
:
1556 spec
->multiout
.dac_nids
[i
] = 0x10;
1558 case AUTO_SEQ_CENLFE
:
1560 spec
->multiout
.dac_nids
[i
] = 0x12;
1562 case AUTO_SEQ_SURROUND
:
1564 spec
->multiout
.dac_nids
[i
] = 0x11;
1568 spec
->multiout
.dac_nids
[i
] = 0x27;
1575 spec
->multiout
.dac_nids
[cfg
->line_outs
] = 0x28; /* AOW4 */
1577 } else if (cfg
->line_outs
== 3) { /* 6 channels */
1578 for(i
= 0; i
< cfg
->line_outs
; i
++) {
1579 nid
= cfg
->line_out_pins
[i
];
1581 /* config dac list */
1583 case AUTO_SEQ_FRONT
:
1585 spec
->multiout
.dac_nids
[i
] = 0x10;
1587 case AUTO_SEQ_CENLFE
:
1589 spec
->multiout
.dac_nids
[i
] = 0x12;
1591 case AUTO_SEQ_SURROUND
:
1593 spec
->multiout
.dac_nids
[i
] = 0x11;
1605 /* add playback controls from the parsed DAC table */
1606 static int vt1709_auto_create_multi_out_ctls(struct via_spec
*spec
,
1607 const struct auto_pin_cfg
*cfg
)
1610 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1614 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1615 nid
= cfg
->line_out_pins
[i
];
1620 if (i
== AUTO_SEQ_CENLFE
) {
1622 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1623 "Center Playback Volume",
1624 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1628 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1629 "LFE Playback Volume",
1630 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1634 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1635 "Center Playback Switch",
1636 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1640 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1641 "LFE Playback Switch",
1642 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1646 } else if (i
== AUTO_SEQ_FRONT
){
1647 /* add control to mixer index 0 */
1648 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1649 "Master Front Playback Volume",
1650 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1654 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1655 "Master Front Playback Switch",
1656 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1661 /* add control to PW3 */
1662 sprintf(name
, "%s Playback Volume", chname
[i
]);
1663 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1664 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1668 sprintf(name
, "%s Playback Switch", chname
[i
]);
1669 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1670 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1674 } else if (i
== AUTO_SEQ_SURROUND
) {
1675 sprintf(name
, "%s Playback Volume", chname
[i
]);
1676 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1677 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1681 sprintf(name
, "%s Playback Switch", chname
[i
]);
1682 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1683 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1687 } else if (i
== AUTO_SEQ_SIDE
) {
1688 sprintf(name
, "%s Playback Volume", chname
[i
]);
1689 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1690 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1694 sprintf(name
, "%s Playback Switch", chname
[i
]);
1695 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1696 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1706 static int vt1709_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1713 if (spec
->multiout
.num_dacs
== 5) /* 10 channels */
1714 spec
->multiout
.hp_nid
= VT1709_HP_DAC_NID
;
1715 else if (spec
->multiout
.num_dacs
== 3) /* 6 channels */
1716 spec
->multiout
.hp_nid
= 0;
1718 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1719 "Headphone Playback Volume",
1720 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1723 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1724 "Headphone Playback Switch",
1725 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1732 /* create playback/capture controls for input pins */
1733 static int vt1709_auto_create_analog_input_ctls(struct via_spec
*spec
,
1734 const struct auto_pin_cfg
*cfg
)
1736 static char *labels
[] = {
1737 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1739 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1740 int i
, err
, idx
= 0;
1742 /* for internal loopback recording select */
1743 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1744 imux
->items
[imux
->num_items
].index
= idx
;
1747 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1748 if (!cfg
->input_pins
[i
])
1751 switch (cfg
->input_pins
[i
]) {
1752 case 0x1d: /* Mic */
1756 case 0x1e: /* Line In */
1760 case 0x21: /* Front Mic */
1768 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
1772 imux
->items
[imux
->num_items
].label
= labels
[i
];
1773 imux
->items
[imux
->num_items
].index
= idx
;
1779 static int vt1709_parse_auto_config(struct hda_codec
*codec
)
1781 struct via_spec
*spec
= codec
->spec
;
1784 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1787 err
= vt1709_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1790 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1791 return 0; /* can't find valid BIOS pin config */
1793 err
= vt1709_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1796 err
= vt1709_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1799 err
= vt1709_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1803 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1805 if (spec
->autocfg
.dig_outs
)
1806 spec
->multiout
.dig_out_nid
= VT1709_DIGOUT_NID
;
1807 spec
->dig_in_pin
= VT1709_DIGIN_PIN
;
1808 if (spec
->autocfg
.dig_in_pin
)
1809 spec
->dig_in_nid
= VT1709_DIGIN_NID
;
1811 if (spec
->kctls
.list
)
1812 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
1814 spec
->input_mux
= &spec
->private_imux
[0];
1817 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1822 #ifdef CONFIG_SND_HDA_POWER_SAVE
1823 static struct hda_amp_list vt1709_loopbacks
[] = {
1824 { 0x18, HDA_INPUT
, 1 },
1825 { 0x18, HDA_INPUT
, 2 },
1826 { 0x18, HDA_INPUT
, 3 },
1827 { 0x18, HDA_INPUT
, 4 },
1832 static int patch_vt1709_10ch(struct hda_codec
*codec
)
1834 struct via_spec
*spec
;
1837 /* create a codec specific record */
1838 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1844 err
= vt1709_parse_auto_config(codec
);
1849 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
1850 "Using genenic mode...\n");
1853 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_10ch_volume_init_verbs
;
1854 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
1856 spec
->stream_name_analog
= "VT1709 Analog";
1857 spec
->stream_analog_playback
= &vt1709_10ch_pcm_analog_playback
;
1858 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
1860 spec
->stream_name_digital
= "VT1709 Digital";
1861 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
1862 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
1865 if (!spec
->adc_nids
&& spec
->input_mux
) {
1866 spec
->adc_nids
= vt1709_adc_nids
;
1867 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
1868 get_mux_nids(codec
);
1869 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
1873 codec
->patch_ops
= via_patch_ops
;
1875 codec
->patch_ops
.init
= via_auto_init
;
1876 codec
->patch_ops
.unsol_event
= via_unsol_event
;
1877 #ifdef CONFIG_SND_HDA_POWER_SAVE
1878 spec
->loopback
.amplist
= vt1709_loopbacks
;
1884 * generic initialization of ADC, input mixers and output mixers
1886 static struct hda_verb vt1709_6ch_volume_init_verbs
[] = {
1888 * Unmute ADC0-2 and set the default input to mic-in
1890 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1891 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1892 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1895 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1898 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1899 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1900 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1901 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1902 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1903 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1906 * Set up output selector (0x1a, 0x1b, 0x29)
1908 /* set vol=0 to output mixers */
1909 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1910 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1911 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1914 * Unmute PW3 and PW4
1916 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1917 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1919 /* Set input of PW4 as MW0 */
1920 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
1921 /* PW9 Output enable */
1922 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1926 static int patch_vt1709_6ch(struct hda_codec
*codec
)
1928 struct via_spec
*spec
;
1931 /* create a codec specific record */
1932 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1938 err
= vt1709_parse_auto_config(codec
);
1943 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
1944 "Using genenic mode...\n");
1947 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_6ch_volume_init_verbs
;
1948 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
1950 spec
->stream_name_analog
= "VT1709 Analog";
1951 spec
->stream_analog_playback
= &vt1709_6ch_pcm_analog_playback
;
1952 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
1954 spec
->stream_name_digital
= "VT1709 Digital";
1955 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
1956 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
1959 if (!spec
->adc_nids
&& spec
->input_mux
) {
1960 spec
->adc_nids
= vt1709_adc_nids
;
1961 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
1962 get_mux_nids(codec
);
1963 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
1967 codec
->patch_ops
= via_patch_ops
;
1969 codec
->patch_ops
.init
= via_auto_init
;
1970 codec
->patch_ops
.unsol_event
= via_unsol_event
;
1971 #ifdef CONFIG_SND_HDA_POWER_SAVE
1972 spec
->loopback
.amplist
= vt1709_loopbacks
;
1977 /* capture mixer elements */
1978 static struct snd_kcontrol_new vt1708B_capture_mixer
[] = {
1979 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
1980 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
1981 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
1982 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
1984 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1985 /* The multiple "Capture Source" controls confuse alsamixer
1986 * So call somewhat different..
1988 /* .name = "Capture Source", */
1989 .name
= "Input Source",
1991 .info
= via_mux_enum_info
,
1992 .get
= via_mux_enum_get
,
1993 .put
= via_mux_enum_put
,
1998 * generic initialization of ADC, input mixers and output mixers
2000 static struct hda_verb vt1708B_8ch_volume_init_verbs
[] = {
2002 * Unmute ADC0-1 and set the default input to mic-in
2004 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2005 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2008 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2011 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2012 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2013 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2014 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2015 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2016 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2019 * Set up output mixers
2021 /* set vol=0 to output mixers */
2022 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2023 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2024 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2026 /* Setup default input to PW4 */
2027 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x1},
2028 /* PW9 Output enable */
2029 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2030 /* PW10 Input enable */
2031 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2035 static struct hda_verb vt1708B_4ch_volume_init_verbs
[] = {
2037 * Unmute ADC0-1 and set the default input to mic-in
2039 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2040 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2043 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2046 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2047 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2048 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2049 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2050 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2051 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2054 * Set up output mixers
2056 /* set vol=0 to output mixers */
2057 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2058 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2059 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2061 /* Setup default input of PW4 to MW0 */
2062 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2063 /* PW9 Output enable */
2064 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2065 /* PW10 Input enable */
2066 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2070 static struct hda_verb vt1708B_uniwill_init_verbs
[] = {
2071 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2075 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback
= {
2079 .nid
= 0x10, /* NID to query formats and rates */
2081 .open
= via_playback_pcm_open
,
2082 .prepare
= via_playback_multi_pcm_prepare
,
2083 .cleanup
= via_playback_multi_pcm_cleanup
2087 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback
= {
2091 .nid
= 0x10, /* NID to query formats and rates */
2093 .open
= via_playback_pcm_open
,
2094 .prepare
= via_playback_multi_pcm_prepare
,
2095 .cleanup
= via_playback_multi_pcm_cleanup
2099 static struct hda_pcm_stream vt1708B_pcm_analog_capture
= {
2103 .nid
= 0x13, /* NID to query formats and rates */
2105 .prepare
= via_capture_pcm_prepare
,
2106 .cleanup
= via_capture_pcm_cleanup
2110 static struct hda_pcm_stream vt1708B_pcm_digital_playback
= {
2114 /* NID is set in via_build_pcms */
2116 .open
= via_dig_playback_pcm_open
,
2117 .close
= via_dig_playback_pcm_close
,
2118 .prepare
= via_dig_playback_pcm_prepare
,
2119 .cleanup
= via_dig_playback_pcm_cleanup
2123 static struct hda_pcm_stream vt1708B_pcm_digital_capture
= {
2129 /* fill in the dac_nids table from the parsed pin configuration */
2130 static int vt1708B_auto_fill_dac_nids(struct via_spec
*spec
,
2131 const struct auto_pin_cfg
*cfg
)
2136 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2138 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2140 for (i
= 0; i
< 4; i
++) {
2141 nid
= cfg
->line_out_pins
[i
];
2143 /* config dac list */
2145 case AUTO_SEQ_FRONT
:
2146 spec
->multiout
.dac_nids
[i
] = 0x10;
2148 case AUTO_SEQ_CENLFE
:
2149 spec
->multiout
.dac_nids
[i
] = 0x24;
2151 case AUTO_SEQ_SURROUND
:
2152 spec
->multiout
.dac_nids
[i
] = 0x11;
2155 spec
->multiout
.dac_nids
[i
] = 0x25;
2164 /* add playback controls from the parsed DAC table */
2165 static int vt1708B_auto_create_multi_out_ctls(struct via_spec
*spec
,
2166 const struct auto_pin_cfg
*cfg
)
2169 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2170 hda_nid_t nid_vols
[] = {0x16, 0x18, 0x26, 0x27};
2171 hda_nid_t nid
, nid_vol
= 0;
2174 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2175 nid
= cfg
->line_out_pins
[i
];
2180 nid_vol
= nid_vols
[i
];
2182 if (i
== AUTO_SEQ_CENLFE
) {
2184 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2185 "Center Playback Volume",
2186 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2190 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2191 "LFE Playback Volume",
2192 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2196 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2197 "Center Playback Switch",
2198 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2202 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2203 "LFE Playback Switch",
2204 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2208 } else if (i
== AUTO_SEQ_FRONT
) {
2209 /* add control to mixer index 0 */
2210 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2211 "Master Front Playback Volume",
2212 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2216 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2217 "Master Front Playback Switch",
2218 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2223 /* add control to PW3 */
2224 sprintf(name
, "%s Playback Volume", chname
[i
]);
2225 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2226 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2230 sprintf(name
, "%s Playback Switch", chname
[i
]);
2231 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2232 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2237 sprintf(name
, "%s Playback Volume", chname
[i
]);
2238 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2239 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2243 sprintf(name
, "%s Playback Switch", chname
[i
]);
2244 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2245 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2255 static int vt1708B_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2262 spec
->multiout
.hp_nid
= VT1708B_HP_NID
; /* AOW3 */
2264 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2265 "Headphone Playback Volume",
2266 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2269 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2270 "Headphone Playback Switch",
2271 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2275 create_hp_imux(spec
);
2280 /* create playback/capture controls for input pins */
2281 static int vt1708B_auto_create_analog_input_ctls(struct via_spec
*spec
,
2282 const struct auto_pin_cfg
*cfg
)
2284 static char *labels
[] = {
2285 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2287 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2288 int i
, err
, idx
= 0;
2290 /* for internal loopback recording select */
2291 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2292 imux
->items
[imux
->num_items
].index
= idx
;
2295 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2296 if (!cfg
->input_pins
[i
])
2299 switch (cfg
->input_pins
[i
]) {
2300 case 0x1a: /* Mic */
2304 case 0x1b: /* Line In */
2308 case 0x1e: /* Front Mic */
2316 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
2320 imux
->items
[imux
->num_items
].label
= labels
[i
];
2321 imux
->items
[imux
->num_items
].index
= idx
;
2327 static int vt1708B_parse_auto_config(struct hda_codec
*codec
)
2329 struct via_spec
*spec
= codec
->spec
;
2332 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2335 err
= vt1708B_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2338 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2339 return 0; /* can't find valid BIOS pin config */
2341 err
= vt1708B_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2344 err
= vt1708B_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2347 err
= vt1708B_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2351 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2353 if (spec
->autocfg
.dig_outs
)
2354 spec
->multiout
.dig_out_nid
= VT1708B_DIGOUT_NID
;
2355 spec
->dig_in_pin
= VT1708B_DIGIN_PIN
;
2356 if (spec
->autocfg
.dig_in_pin
)
2357 spec
->dig_in_nid
= VT1708B_DIGIN_NID
;
2359 if (spec
->kctls
.list
)
2360 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2362 spec
->input_mux
= &spec
->private_imux
[0];
2365 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2370 #ifdef CONFIG_SND_HDA_POWER_SAVE
2371 static struct hda_amp_list vt1708B_loopbacks
[] = {
2372 { 0x16, HDA_INPUT
, 1 },
2373 { 0x16, HDA_INPUT
, 2 },
2374 { 0x16, HDA_INPUT
, 3 },
2375 { 0x16, HDA_INPUT
, 4 },
2380 static int patch_vt1708B_8ch(struct hda_codec
*codec
)
2382 struct via_spec
*spec
;
2385 /* create a codec specific record */
2386 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2392 /* automatic parse from the BIOS config */
2393 err
= vt1708B_parse_auto_config(codec
);
2398 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2399 "from BIOS. Using genenic mode...\n");
2402 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_8ch_volume_init_verbs
;
2403 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2405 spec
->stream_name_analog
= "VT1708B Analog";
2406 spec
->stream_analog_playback
= &vt1708B_8ch_pcm_analog_playback
;
2407 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2409 spec
->stream_name_digital
= "VT1708B Digital";
2410 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2411 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2413 if (!spec
->adc_nids
&& spec
->input_mux
) {
2414 spec
->adc_nids
= vt1708B_adc_nids
;
2415 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2416 get_mux_nids(codec
);
2417 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2421 codec
->patch_ops
= via_patch_ops
;
2423 codec
->patch_ops
.init
= via_auto_init
;
2424 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2425 #ifdef CONFIG_SND_HDA_POWER_SAVE
2426 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2432 static int patch_vt1708B_4ch(struct hda_codec
*codec
)
2434 struct via_spec
*spec
;
2437 /* create a codec specific record */
2438 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2444 /* automatic parse from the BIOS config */
2445 err
= vt1708B_parse_auto_config(codec
);
2450 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2451 "from BIOS. Using genenic mode...\n");
2454 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_4ch_volume_init_verbs
;
2455 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2457 spec
->stream_name_analog
= "VT1708B Analog";
2458 spec
->stream_analog_playback
= &vt1708B_4ch_pcm_analog_playback
;
2459 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2461 spec
->stream_name_digital
= "VT1708B Digital";
2462 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2463 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2465 if (!spec
->adc_nids
&& spec
->input_mux
) {
2466 spec
->adc_nids
= vt1708B_adc_nids
;
2467 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2468 get_mux_nids(codec
);
2469 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2473 codec
->patch_ops
= via_patch_ops
;
2475 codec
->patch_ops
.init
= via_auto_init
;
2476 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2477 #ifdef CONFIG_SND_HDA_POWER_SAVE
2478 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2484 /* Patch for VT1708S */
2486 /* VT1708S software backdoor based override for buggy hardware micboost
2488 #define MIC_BOOST_VOLUME(xname, nid) { \
2489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2492 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2493 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2494 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2495 .info = mic_boost_volume_info, \
2496 .get = snd_hda_mixer_amp_volume_get, \
2497 .put = snd_hda_mixer_amp_volume_put, \
2498 .tlv = { .c = mic_boost_tlv }, \
2499 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2501 /* capture mixer elements */
2502 static struct snd_kcontrol_new vt1708S_capture_mixer
[] = {
2503 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
2504 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
2505 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
2506 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
2507 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2508 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2510 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2511 /* The multiple "Capture Source" controls confuse alsamixer
2512 * So call somewhat different..
2514 /* .name = "Capture Source", */
2515 .name
= "Input Source",
2517 .info
= via_mux_enum_info
,
2518 .get
= via_mux_enum_get
,
2519 .put
= via_mux_enum_put
,
2524 static struct hda_verb vt1708S_volume_init_verbs
[] = {
2525 /* Unmute ADC0-1 and set the default input to mic-in */
2526 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2527 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2529 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2530 * analog-loopback mixer widget */
2531 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2532 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2533 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2534 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2535 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2536 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2538 /* Setup default input of PW4 to MW0 */
2539 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2540 /* PW9, PW10 Output enable */
2541 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2542 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2543 /* Enable Mic Boost Volume backdoor */
2548 static struct hda_verb vt1708S_uniwill_init_verbs
[] = {
2549 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2553 static struct hda_pcm_stream vt1708S_pcm_analog_playback
= {
2557 .nid
= 0x10, /* NID to query formats and rates */
2559 .open
= via_playback_pcm_open
,
2560 .prepare
= via_playback_pcm_prepare
,
2561 .cleanup
= via_playback_pcm_cleanup
2565 static struct hda_pcm_stream vt1708S_pcm_analog_capture
= {
2569 .nid
= 0x13, /* NID to query formats and rates */
2571 .prepare
= via_capture_pcm_prepare
,
2572 .cleanup
= via_capture_pcm_cleanup
2576 static struct hda_pcm_stream vt1708S_pcm_digital_playback
= {
2580 /* NID is set in via_build_pcms */
2582 .open
= via_dig_playback_pcm_open
,
2583 .close
= via_dig_playback_pcm_close
,
2584 .prepare
= via_dig_playback_pcm_prepare
,
2585 .cleanup
= via_dig_playback_pcm_cleanup
2589 /* fill in the dac_nids table from the parsed pin configuration */
2590 static int vt1708S_auto_fill_dac_nids(struct via_spec
*spec
,
2591 const struct auto_pin_cfg
*cfg
)
2596 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2598 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2600 for (i
= 0; i
< 4; i
++) {
2601 nid
= cfg
->line_out_pins
[i
];
2603 /* config dac list */
2605 case AUTO_SEQ_FRONT
:
2606 spec
->multiout
.dac_nids
[i
] = 0x10;
2608 case AUTO_SEQ_CENLFE
:
2609 spec
->multiout
.dac_nids
[i
] = 0x24;
2611 case AUTO_SEQ_SURROUND
:
2612 spec
->multiout
.dac_nids
[i
] = 0x11;
2615 spec
->multiout
.dac_nids
[i
] = 0x25;
2624 /* add playback controls from the parsed DAC table */
2625 static int vt1708S_auto_create_multi_out_ctls(struct via_spec
*spec
,
2626 const struct auto_pin_cfg
*cfg
)
2629 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2630 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x24, 0x25};
2631 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x26, 0x27};
2632 hda_nid_t nid
, nid_vol
, nid_mute
;
2635 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2636 nid
= cfg
->line_out_pins
[i
];
2641 nid_vol
= nid_vols
[i
];
2642 nid_mute
= nid_mutes
[i
];
2644 if (i
== AUTO_SEQ_CENLFE
) {
2646 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2647 "Center Playback Volume",
2648 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2652 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2653 "LFE Playback Volume",
2654 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2658 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2659 "Center Playback Switch",
2660 HDA_COMPOSE_AMP_VAL(nid_mute
,
2665 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2666 "LFE Playback Switch",
2667 HDA_COMPOSE_AMP_VAL(nid_mute
,
2672 } else if (i
== AUTO_SEQ_FRONT
) {
2673 /* add control to mixer index 0 */
2674 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2675 "Master Front Playback Volume",
2676 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2680 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2681 "Master Front Playback Switch",
2682 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2688 sprintf(name
, "%s Playback Volume", chname
[i
]);
2689 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2690 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2694 sprintf(name
, "%s Playback Switch", chname
[i
]);
2695 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2696 HDA_COMPOSE_AMP_VAL(nid_mute
,
2702 sprintf(name
, "%s Playback Volume", chname
[i
]);
2703 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2704 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2708 sprintf(name
, "%s Playback Switch", chname
[i
]);
2709 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2710 HDA_COMPOSE_AMP_VAL(nid_mute
,
2721 static int vt1708S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2728 spec
->multiout
.hp_nid
= VT1708S_HP_NID
; /* AOW3 */
2730 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2731 "Headphone Playback Volume",
2732 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
2736 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2737 "Headphone Playback Switch",
2738 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2742 create_hp_imux(spec
);
2747 /* create playback/capture controls for input pins */
2748 static int vt1708S_auto_create_analog_input_ctls(struct via_spec
*spec
,
2749 const struct auto_pin_cfg
*cfg
)
2751 static char *labels
[] = {
2752 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2754 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2755 int i
, err
, idx
= 0;
2757 /* for internal loopback recording select */
2758 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2759 imux
->items
[imux
->num_items
].index
= 5;
2762 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2763 if (!cfg
->input_pins
[i
])
2766 switch (cfg
->input_pins
[i
]) {
2767 case 0x1a: /* Mic */
2771 case 0x1b: /* Line In */
2775 case 0x1e: /* Front Mic */
2783 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
2787 imux
->items
[imux
->num_items
].label
= labels
[i
];
2788 imux
->items
[imux
->num_items
].index
= idx
-1;
2794 /* fill out digital output widgets; one for master and one for slave outputs */
2795 static void fill_dig_outs(struct hda_codec
*codec
)
2797 struct via_spec
*spec
= codec
->spec
;
2800 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
2804 nid
= spec
->autocfg
.dig_out_pins
[i
];
2807 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
2810 if (!spec
->multiout
.dig_out_nid
)
2811 spec
->multiout
.dig_out_nid
= nid
;
2813 spec
->slave_dig_outs
[0] = nid
;
2814 break; /* at most two dig outs */
2819 static int vt1708S_parse_auto_config(struct hda_codec
*codec
)
2821 struct via_spec
*spec
= codec
->spec
;
2824 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2827 err
= vt1708S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2830 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2831 return 0; /* can't find valid BIOS pin config */
2833 err
= vt1708S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2836 err
= vt1708S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2839 err
= vt1708S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2843 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2845 fill_dig_outs(codec
);
2847 if (spec
->kctls
.list
)
2848 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2850 spec
->input_mux
= &spec
->private_imux
[0];
2853 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2858 #ifdef CONFIG_SND_HDA_POWER_SAVE
2859 static struct hda_amp_list vt1708S_loopbacks
[] = {
2860 { 0x16, HDA_INPUT
, 1 },
2861 { 0x16, HDA_INPUT
, 2 },
2862 { 0x16, HDA_INPUT
, 3 },
2863 { 0x16, HDA_INPUT
, 4 },
2868 static int patch_vt1708S(struct hda_codec
*codec
)
2870 struct via_spec
*spec
;
2873 /* create a codec specific record */
2874 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2880 /* automatic parse from the BIOS config */
2881 err
= vt1708S_parse_auto_config(codec
);
2886 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2887 "from BIOS. Using genenic mode...\n");
2890 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_volume_init_verbs
;
2891 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_uniwill_init_verbs
;
2893 spec
->stream_name_analog
= "VT1708S Analog";
2894 spec
->stream_analog_playback
= &vt1708S_pcm_analog_playback
;
2895 spec
->stream_analog_capture
= &vt1708S_pcm_analog_capture
;
2897 spec
->stream_name_digital
= "VT1708S Digital";
2898 spec
->stream_digital_playback
= &vt1708S_pcm_digital_playback
;
2900 if (!spec
->adc_nids
&& spec
->input_mux
) {
2901 spec
->adc_nids
= vt1708S_adc_nids
;
2902 spec
->num_adc_nids
= ARRAY_SIZE(vt1708S_adc_nids
);
2903 get_mux_nids(codec
);
2904 spec
->mixers
[spec
->num_mixers
] = vt1708S_capture_mixer
;
2908 codec
->patch_ops
= via_patch_ops
;
2910 codec
->patch_ops
.init
= via_auto_init
;
2911 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2912 #ifdef CONFIG_SND_HDA_POWER_SAVE
2913 spec
->loopback
.amplist
= vt1708S_loopbacks
;
2919 /* Patch for VT1702 */
2921 /* capture mixer elements */
2922 static struct snd_kcontrol_new vt1702_capture_mixer
[] = {
2923 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT
),
2924 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT
),
2925 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT
),
2926 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT
),
2927 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT
),
2928 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT
),
2929 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2932 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2933 /* The multiple "Capture Source" controls confuse alsamixer
2934 * So call somewhat different..
2936 /* .name = "Capture Source", */
2937 .name
= "Input Source",
2939 .info
= via_mux_enum_info
,
2940 .get
= via_mux_enum_get
,
2941 .put
= via_mux_enum_put
,
2946 static struct hda_verb vt1702_volume_init_verbs
[] = {
2948 * Unmute ADC0-1 and set the default input to mic-in
2950 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2951 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2952 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2955 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2958 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2959 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2960 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2961 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2962 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2963 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
2965 /* Setup default input of PW4 to MW0 */
2966 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x1},
2967 /* PW6 PW7 Output enable */
2968 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2969 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2973 static struct hda_verb vt1702_uniwill_init_verbs
[] = {
2974 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_GPIO_EVENT
},
2975 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2979 static struct hda_pcm_stream vt1702_pcm_analog_playback
= {
2983 .nid
= 0x10, /* NID to query formats and rates */
2985 .open
= via_playback_pcm_open
,
2986 .prepare
= via_playback_multi_pcm_prepare
,
2987 .cleanup
= via_playback_multi_pcm_cleanup
2991 static struct hda_pcm_stream vt1702_pcm_analog_capture
= {
2995 .nid
= 0x12, /* NID to query formats and rates */
2997 .prepare
= via_capture_pcm_prepare
,
2998 .cleanup
= via_capture_pcm_cleanup
3002 static struct hda_pcm_stream vt1702_pcm_digital_playback
= {
3006 /* NID is set in via_build_pcms */
3008 .open
= via_dig_playback_pcm_open
,
3009 .close
= via_dig_playback_pcm_close
,
3010 .prepare
= via_dig_playback_pcm_prepare
,
3011 .cleanup
= via_dig_playback_pcm_cleanup
3015 /* fill in the dac_nids table from the parsed pin configuration */
3016 static int vt1702_auto_fill_dac_nids(struct via_spec
*spec
,
3017 const struct auto_pin_cfg
*cfg
)
3019 spec
->multiout
.num_dacs
= 1;
3020 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3022 if (cfg
->line_out_pins
[0]) {
3023 /* config dac list */
3024 spec
->multiout
.dac_nids
[0] = 0x10;
3030 /* add playback controls from the parsed DAC table */
3031 static int vt1702_auto_create_line_out_ctls(struct via_spec
*spec
,
3032 const struct auto_pin_cfg
*cfg
)
3036 if (!cfg
->line_out_pins
[0])
3039 /* add control to mixer index 0 */
3040 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3041 "Master Front Playback Volume",
3042 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3045 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3046 "Master Front Playback Switch",
3047 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3052 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3053 "Front Playback Volume",
3054 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
));
3057 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3058 "Front Playback Switch",
3059 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT
));
3066 static int vt1702_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3073 spec
->multiout
.hp_nid
= 0x1D;
3075 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3076 "Headphone Playback Volume",
3077 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT
));
3081 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3082 "Headphone Playback Switch",
3083 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3087 create_hp_imux(spec
);
3092 /* create playback/capture controls for input pins */
3093 static int vt1702_auto_create_analog_input_ctls(struct via_spec
*spec
,
3094 const struct auto_pin_cfg
*cfg
)
3096 static char *labels
[] = {
3097 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3099 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3100 int i
, err
, idx
= 0;
3102 /* for internal loopback recording select */
3103 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3104 imux
->items
[imux
->num_items
].index
= 3;
3107 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3108 if (!cfg
->input_pins
[i
])
3111 switch (cfg
->input_pins
[i
]) {
3112 case 0x14: /* Mic */
3116 case 0x15: /* Line In */
3120 case 0x18: /* Front Mic */
3124 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
],
3125 labels
[i
], idx
, 0x1A);
3128 imux
->items
[imux
->num_items
].label
= labels
[i
];
3129 imux
->items
[imux
->num_items
].index
= idx
-1;
3135 static int vt1702_parse_auto_config(struct hda_codec
*codec
)
3137 struct via_spec
*spec
= codec
->spec
;
3140 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3143 err
= vt1702_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3146 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3147 return 0; /* can't find valid BIOS pin config */
3149 err
= vt1702_auto_create_line_out_ctls(spec
, &spec
->autocfg
);
3152 err
= vt1702_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3155 err
= vt1702_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3159 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3161 fill_dig_outs(codec
);
3163 if (spec
->kctls
.list
)
3164 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3166 spec
->input_mux
= &spec
->private_imux
[0];
3169 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3174 #ifdef CONFIG_SND_HDA_POWER_SAVE
3175 static struct hda_amp_list vt1702_loopbacks
[] = {
3176 { 0x1A, HDA_INPUT
, 1 },
3177 { 0x1A, HDA_INPUT
, 2 },
3178 { 0x1A, HDA_INPUT
, 3 },
3179 { 0x1A, HDA_INPUT
, 4 },
3184 static int patch_vt1702(struct hda_codec
*codec
)
3186 struct via_spec
*spec
;
3188 unsigned int response
;
3189 unsigned char control
;
3191 /* create a codec specific record */
3192 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3198 /* automatic parse from the BIOS config */
3199 err
= vt1702_parse_auto_config(codec
);
3204 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3205 "from BIOS. Using genenic mode...\n");
3208 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_volume_init_verbs
;
3209 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_uniwill_init_verbs
;
3211 spec
->stream_name_analog
= "VT1702 Analog";
3212 spec
->stream_analog_playback
= &vt1702_pcm_analog_playback
;
3213 spec
->stream_analog_capture
= &vt1702_pcm_analog_capture
;
3215 spec
->stream_name_digital
= "VT1702 Digital";
3216 spec
->stream_digital_playback
= &vt1702_pcm_digital_playback
;
3218 if (!spec
->adc_nids
&& spec
->input_mux
) {
3219 spec
->adc_nids
= vt1702_adc_nids
;
3220 spec
->num_adc_nids
= ARRAY_SIZE(vt1702_adc_nids
);
3221 get_mux_nids(codec
);
3222 spec
->mixers
[spec
->num_mixers
] = vt1702_capture_mixer
;
3226 codec
->patch_ops
= via_patch_ops
;
3228 codec
->patch_ops
.init
= via_auto_init
;
3229 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3230 #ifdef CONFIG_SND_HDA_POWER_SAVE
3231 spec
->loopback
.amplist
= vt1702_loopbacks
;
3235 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF8C, 0);
3236 control
= (unsigned char)(response
& 0xff);
3238 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF88, control
);
3240 /* Enable GPIO 0&1 for volume&mute control */
3241 /* Enable GPIO 2 for DMIC-DATA */
3242 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF84, 0);
3243 control
= (unsigned char)((response
>> 16) & 0x3f);
3244 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF82, control
);
3252 static struct hda_codec_preset snd_hda_preset_via
[] = {
3253 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
3254 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
3255 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
3256 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
3257 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
3258 .patch
= patch_vt1709_10ch
},
3259 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
3260 .patch
= patch_vt1709_10ch
},
3261 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
3262 .patch
= patch_vt1709_10ch
},
3263 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
3264 .patch
= patch_vt1709_10ch
},
3265 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
3266 .patch
= patch_vt1709_6ch
},
3267 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
3268 .patch
= patch_vt1709_6ch
},
3269 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
3270 .patch
= patch_vt1709_6ch
},
3271 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
3272 .patch
= patch_vt1709_6ch
},
3273 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
3274 .patch
= patch_vt1708B_8ch
},
3275 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
3276 .patch
= patch_vt1708B_8ch
},
3277 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
3278 .patch
= patch_vt1708B_8ch
},
3279 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
3280 .patch
= patch_vt1708B_8ch
},
3281 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
3282 .patch
= patch_vt1708B_4ch
},
3283 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
3284 .patch
= patch_vt1708B_4ch
},
3285 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
3286 .patch
= patch_vt1708B_4ch
},
3287 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
3288 .patch
= patch_vt1708B_4ch
},
3289 { .id
= 0x11060397, .name
= "VT1708S",
3290 .patch
= patch_vt1708S
},
3291 { .id
= 0x11061397, .name
= "VT1708S",
3292 .patch
= patch_vt1708S
},
3293 { .id
= 0x11062397, .name
= "VT1708S",
3294 .patch
= patch_vt1708S
},
3295 { .id
= 0x11063397, .name
= "VT1708S",
3296 .patch
= patch_vt1708S
},
3297 { .id
= 0x11064397, .name
= "VT1708S",
3298 .patch
= patch_vt1708S
},
3299 { .id
= 0x11065397, .name
= "VT1708S",
3300 .patch
= patch_vt1708S
},
3301 { .id
= 0x11066397, .name
= "VT1708S",
3302 .patch
= patch_vt1708S
},
3303 { .id
= 0x11067397, .name
= "VT1708S",
3304 .patch
= patch_vt1708S
},
3305 { .id
= 0x11060398, .name
= "VT1702",
3306 .patch
= patch_vt1702
},
3307 { .id
= 0x11061398, .name
= "VT1702",
3308 .patch
= patch_vt1702
},
3309 { .id
= 0x11062398, .name
= "VT1702",
3310 .patch
= patch_vt1702
},
3311 { .id
= 0x11063398, .name
= "VT1702",
3312 .patch
= patch_vt1702
},
3313 { .id
= 0x11064398, .name
= "VT1702",
3314 .patch
= patch_vt1702
},
3315 { .id
= 0x11065398, .name
= "VT1702",
3316 .patch
= patch_vt1702
},
3317 { .id
= 0x11066398, .name
= "VT1702",
3318 .patch
= patch_vt1702
},
3319 { .id
= 0x11067398, .name
= "VT1702",
3320 .patch
= patch_vt1702
},
3324 MODULE_ALIAS("snd-hda-codec-id:1106*");
3326 static struct hda_codec_preset_list via_list
= {
3327 .preset
= snd_hda_preset_via
,
3328 .owner
= THIS_MODULE
,
3331 MODULE_LICENSE("GPL");
3332 MODULE_DESCRIPTION("VIA HD-audio codec");
3334 static int __init
patch_via_init(void)
3336 return snd_hda_add_codec_preset(&via_list
);
3339 static void __exit
patch_via_exit(void)
3341 snd_hda_delete_codec_preset(&via_list
);
3344 module_init(patch_via_init
)
3345 module_exit(patch_via_exit
)