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 get_mux_nids(codec
);
1399 spec
->mixers
[spec
->num_mixers
] = vt1708_capture_mixer
;
1403 codec
->patch_ops
= via_patch_ops
;
1405 codec
->patch_ops
.init
= via_auto_init
;
1406 #ifdef CONFIG_SND_HDA_POWER_SAVE
1407 spec
->loopback
.amplist
= vt1708_loopbacks
;
1413 /* capture mixer elements */
1414 static struct snd_kcontrol_new vt1709_capture_mixer
[] = {
1415 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT
),
1416 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT
),
1417 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT
),
1418 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT
),
1419 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT
),
1420 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT
),
1422 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1423 /* The multiple "Capture Source" controls confuse alsamixer
1424 * So call somewhat different..
1426 /* .name = "Capture Source", */
1427 .name
= "Input Source",
1429 .info
= via_mux_enum_info
,
1430 .get
= via_mux_enum_get
,
1431 .put
= via_mux_enum_put
,
1436 static struct hda_verb vt1709_uniwill_init_verbs
[] = {
1437 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
1442 * generic initialization of ADC, input mixers and output mixers
1444 static struct hda_verb vt1709_10ch_volume_init_verbs
[] = {
1446 * Unmute ADC0-2 and set the default input to mic-in
1448 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1449 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1450 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1453 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1456 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1457 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1458 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1459 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1460 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1461 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1464 * Set up output selector (0x1a, 0x1b, 0x29)
1466 /* set vol=0 to output mixers */
1467 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1468 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1469 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1472 * Unmute PW3 and PW4
1474 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1475 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1477 /* Set input of PW4 as AOW4 */
1478 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
1479 /* PW9 Output enable */
1480 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1484 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback
= {
1488 .nid
= 0x10, /* NID to query formats and rates */
1490 .open
= via_playback_pcm_open
,
1491 .prepare
= via_playback_pcm_prepare
,
1492 .cleanup
= via_playback_pcm_cleanup
1496 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback
= {
1500 .nid
= 0x10, /* NID to query formats and rates */
1502 .open
= via_playback_pcm_open
,
1503 .prepare
= via_playback_pcm_prepare
,
1504 .cleanup
= via_playback_pcm_cleanup
1508 static struct hda_pcm_stream vt1709_pcm_analog_capture
= {
1512 .nid
= 0x14, /* NID to query formats and rates */
1514 .prepare
= via_capture_pcm_prepare
,
1515 .cleanup
= via_capture_pcm_cleanup
1519 static struct hda_pcm_stream vt1709_pcm_digital_playback
= {
1523 /* NID is set in via_build_pcms */
1525 .open
= via_dig_playback_pcm_open
,
1526 .close
= via_dig_playback_pcm_close
1530 static struct hda_pcm_stream vt1709_pcm_digital_capture
= {
1536 static int vt1709_auto_fill_dac_nids(struct via_spec
*spec
,
1537 const struct auto_pin_cfg
*cfg
)
1542 if (cfg
->line_outs
== 4) /* 10 channels */
1543 spec
->multiout
.num_dacs
= cfg
->line_outs
+1; /* AOW0~AOW4 */
1544 else if (cfg
->line_outs
== 3) /* 6 channels */
1545 spec
->multiout
.num_dacs
= cfg
->line_outs
; /* AOW0~AOW2 */
1547 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1549 if (cfg
->line_outs
== 4) { /* 10 channels */
1550 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1551 nid
= cfg
->line_out_pins
[i
];
1553 /* config dac list */
1555 case AUTO_SEQ_FRONT
:
1557 spec
->multiout
.dac_nids
[i
] = 0x10;
1559 case AUTO_SEQ_CENLFE
:
1561 spec
->multiout
.dac_nids
[i
] = 0x12;
1563 case AUTO_SEQ_SURROUND
:
1565 spec
->multiout
.dac_nids
[i
] = 0x11;
1569 spec
->multiout
.dac_nids
[i
] = 0x27;
1576 spec
->multiout
.dac_nids
[cfg
->line_outs
] = 0x28; /* AOW4 */
1578 } else if (cfg
->line_outs
== 3) { /* 6 channels */
1579 for(i
= 0; i
< cfg
->line_outs
; i
++) {
1580 nid
= cfg
->line_out_pins
[i
];
1582 /* config dac list */
1584 case AUTO_SEQ_FRONT
:
1586 spec
->multiout
.dac_nids
[i
] = 0x10;
1588 case AUTO_SEQ_CENLFE
:
1590 spec
->multiout
.dac_nids
[i
] = 0x12;
1592 case AUTO_SEQ_SURROUND
:
1594 spec
->multiout
.dac_nids
[i
] = 0x11;
1606 /* add playback controls from the parsed DAC table */
1607 static int vt1709_auto_create_multi_out_ctls(struct via_spec
*spec
,
1608 const struct auto_pin_cfg
*cfg
)
1611 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1615 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1616 nid
= cfg
->line_out_pins
[i
];
1621 if (i
== AUTO_SEQ_CENLFE
) {
1623 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1624 "Center Playback Volume",
1625 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1629 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1630 "LFE Playback Volume",
1631 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1635 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1636 "Center Playback Switch",
1637 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1641 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1642 "LFE Playback Switch",
1643 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1647 } else if (i
== AUTO_SEQ_FRONT
){
1648 /* add control to mixer index 0 */
1649 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1650 "Master Front Playback Volume",
1651 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1655 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1656 "Master Front Playback Switch",
1657 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1662 /* add control to PW3 */
1663 sprintf(name
, "%s Playback Volume", chname
[i
]);
1664 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1665 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1669 sprintf(name
, "%s Playback Switch", chname
[i
]);
1670 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1671 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1675 } else if (i
== AUTO_SEQ_SURROUND
) {
1676 sprintf(name
, "%s Playback Volume", chname
[i
]);
1677 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1678 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1682 sprintf(name
, "%s Playback Switch", chname
[i
]);
1683 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1684 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1688 } else if (i
== AUTO_SEQ_SIDE
) {
1689 sprintf(name
, "%s Playback Volume", chname
[i
]);
1690 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1691 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1695 sprintf(name
, "%s Playback Switch", chname
[i
]);
1696 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1697 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1707 static int vt1709_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1714 if (spec
->multiout
.num_dacs
== 5) /* 10 channels */
1715 spec
->multiout
.hp_nid
= VT1709_HP_DAC_NID
;
1716 else if (spec
->multiout
.num_dacs
== 3) /* 6 channels */
1717 spec
->multiout
.hp_nid
= 0;
1719 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1720 "Headphone Playback Volume",
1721 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1724 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1725 "Headphone Playback Switch",
1726 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1733 /* create playback/capture controls for input pins */
1734 static int vt1709_auto_create_analog_input_ctls(struct via_spec
*spec
,
1735 const struct auto_pin_cfg
*cfg
)
1737 static char *labels
[] = {
1738 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1740 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1741 int i
, err
, idx
= 0;
1743 /* for internal loopback recording select */
1744 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1745 imux
->items
[imux
->num_items
].index
= idx
;
1748 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1749 if (!cfg
->input_pins
[i
])
1752 switch (cfg
->input_pins
[i
]) {
1753 case 0x1d: /* Mic */
1757 case 0x1e: /* Line In */
1761 case 0x21: /* Front Mic */
1769 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
1773 imux
->items
[imux
->num_items
].label
= labels
[i
];
1774 imux
->items
[imux
->num_items
].index
= idx
;
1780 static int vt1709_parse_auto_config(struct hda_codec
*codec
)
1782 struct via_spec
*spec
= codec
->spec
;
1785 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1788 err
= vt1709_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1791 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1792 return 0; /* can't find valid BIOS pin config */
1794 err
= vt1709_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1797 err
= vt1709_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1800 err
= vt1709_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1804 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1806 if (spec
->autocfg
.dig_outs
)
1807 spec
->multiout
.dig_out_nid
= VT1709_DIGOUT_NID
;
1808 spec
->dig_in_pin
= VT1709_DIGIN_PIN
;
1809 if (spec
->autocfg
.dig_in_pin
)
1810 spec
->dig_in_nid
= VT1709_DIGIN_NID
;
1812 if (spec
->kctls
.list
)
1813 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
1815 spec
->input_mux
= &spec
->private_imux
[0];
1818 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1823 #ifdef CONFIG_SND_HDA_POWER_SAVE
1824 static struct hda_amp_list vt1709_loopbacks
[] = {
1825 { 0x18, HDA_INPUT
, 1 },
1826 { 0x18, HDA_INPUT
, 2 },
1827 { 0x18, HDA_INPUT
, 3 },
1828 { 0x18, HDA_INPUT
, 4 },
1833 static int patch_vt1709_10ch(struct hda_codec
*codec
)
1835 struct via_spec
*spec
;
1838 /* create a codec specific record */
1839 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1845 err
= vt1709_parse_auto_config(codec
);
1850 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
1851 "Using genenic mode...\n");
1854 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_10ch_volume_init_verbs
;
1855 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
1857 spec
->stream_name_analog
= "VT1709 Analog";
1858 spec
->stream_analog_playback
= &vt1709_10ch_pcm_analog_playback
;
1859 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
1861 spec
->stream_name_digital
= "VT1709 Digital";
1862 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
1863 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
1866 if (!spec
->adc_nids
&& spec
->input_mux
) {
1867 spec
->adc_nids
= vt1709_adc_nids
;
1868 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
1869 get_mux_nids(codec
);
1870 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
1874 codec
->patch_ops
= via_patch_ops
;
1876 codec
->patch_ops
.init
= via_auto_init
;
1877 codec
->patch_ops
.unsol_event
= via_unsol_event
;
1878 #ifdef CONFIG_SND_HDA_POWER_SAVE
1879 spec
->loopback
.amplist
= vt1709_loopbacks
;
1885 * generic initialization of ADC, input mixers and output mixers
1887 static struct hda_verb vt1709_6ch_volume_init_verbs
[] = {
1889 * Unmute ADC0-2 and set the default input to mic-in
1891 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1892 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1893 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1896 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1899 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1900 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1901 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1902 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1903 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1904 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1907 * Set up output selector (0x1a, 0x1b, 0x29)
1909 /* set vol=0 to output mixers */
1910 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1911 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1912 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1915 * Unmute PW3 and PW4
1917 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1918 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1920 /* Set input of PW4 as MW0 */
1921 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
1922 /* PW9 Output enable */
1923 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1927 static int patch_vt1709_6ch(struct hda_codec
*codec
)
1929 struct via_spec
*spec
;
1932 /* create a codec specific record */
1933 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1939 err
= vt1709_parse_auto_config(codec
);
1944 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
1945 "Using genenic mode...\n");
1948 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_6ch_volume_init_verbs
;
1949 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
1951 spec
->stream_name_analog
= "VT1709 Analog";
1952 spec
->stream_analog_playback
= &vt1709_6ch_pcm_analog_playback
;
1953 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
1955 spec
->stream_name_digital
= "VT1709 Digital";
1956 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
1957 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
1960 if (!spec
->adc_nids
&& spec
->input_mux
) {
1961 spec
->adc_nids
= vt1709_adc_nids
;
1962 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
1963 get_mux_nids(codec
);
1964 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
1968 codec
->patch_ops
= via_patch_ops
;
1970 codec
->patch_ops
.init
= via_auto_init
;
1971 codec
->patch_ops
.unsol_event
= via_unsol_event
;
1972 #ifdef CONFIG_SND_HDA_POWER_SAVE
1973 spec
->loopback
.amplist
= vt1709_loopbacks
;
1978 /* capture mixer elements */
1979 static struct snd_kcontrol_new vt1708B_capture_mixer
[] = {
1980 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
1981 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
1982 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
1983 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
1985 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1986 /* The multiple "Capture Source" controls confuse alsamixer
1987 * So call somewhat different..
1989 /* .name = "Capture Source", */
1990 .name
= "Input Source",
1992 .info
= via_mux_enum_info
,
1993 .get
= via_mux_enum_get
,
1994 .put
= via_mux_enum_put
,
1999 * generic initialization of ADC, input mixers and output mixers
2001 static struct hda_verb vt1708B_8ch_volume_init_verbs
[] = {
2003 * Unmute ADC0-1 and set the default input to mic-in
2005 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2006 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2009 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2012 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2013 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2014 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2015 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2016 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2017 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2020 * Set up output mixers
2022 /* set vol=0 to output mixers */
2023 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2024 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2025 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2027 /* Setup default input to PW4 */
2028 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x1},
2029 /* PW9 Output enable */
2030 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2031 /* PW10 Input enable */
2032 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2036 static struct hda_verb vt1708B_4ch_volume_init_verbs
[] = {
2038 * Unmute ADC0-1 and set the default input to mic-in
2040 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2041 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2044 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2047 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2048 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2049 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2050 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2051 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2052 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2055 * Set up output mixers
2057 /* set vol=0 to output mixers */
2058 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2059 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2060 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2062 /* Setup default input of PW4 to MW0 */
2063 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2064 /* PW9 Output enable */
2065 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2066 /* PW10 Input enable */
2067 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2071 static struct hda_verb vt1708B_uniwill_init_verbs
[] = {
2072 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2076 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback
= {
2080 .nid
= 0x10, /* NID to query formats and rates */
2082 .open
= via_playback_pcm_open
,
2083 .prepare
= via_playback_multi_pcm_prepare
,
2084 .cleanup
= via_playback_multi_pcm_cleanup
2088 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback
= {
2092 .nid
= 0x10, /* NID to query formats and rates */
2094 .open
= via_playback_pcm_open
,
2095 .prepare
= via_playback_multi_pcm_prepare
,
2096 .cleanup
= via_playback_multi_pcm_cleanup
2100 static struct hda_pcm_stream vt1708B_pcm_analog_capture
= {
2104 .nid
= 0x13, /* NID to query formats and rates */
2106 .prepare
= via_capture_pcm_prepare
,
2107 .cleanup
= via_capture_pcm_cleanup
2111 static struct hda_pcm_stream vt1708B_pcm_digital_playback
= {
2115 /* NID is set in via_build_pcms */
2117 .open
= via_dig_playback_pcm_open
,
2118 .close
= via_dig_playback_pcm_close
,
2119 .prepare
= via_dig_playback_pcm_prepare
,
2120 .cleanup
= via_dig_playback_pcm_cleanup
2124 static struct hda_pcm_stream vt1708B_pcm_digital_capture
= {
2130 /* fill in the dac_nids table from the parsed pin configuration */
2131 static int vt1708B_auto_fill_dac_nids(struct via_spec
*spec
,
2132 const struct auto_pin_cfg
*cfg
)
2137 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2139 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2141 for (i
= 0; i
< 4; i
++) {
2142 nid
= cfg
->line_out_pins
[i
];
2144 /* config dac list */
2146 case AUTO_SEQ_FRONT
:
2147 spec
->multiout
.dac_nids
[i
] = 0x10;
2149 case AUTO_SEQ_CENLFE
:
2150 spec
->multiout
.dac_nids
[i
] = 0x24;
2152 case AUTO_SEQ_SURROUND
:
2153 spec
->multiout
.dac_nids
[i
] = 0x11;
2156 spec
->multiout
.dac_nids
[i
] = 0x25;
2165 /* add playback controls from the parsed DAC table */
2166 static int vt1708B_auto_create_multi_out_ctls(struct via_spec
*spec
,
2167 const struct auto_pin_cfg
*cfg
)
2170 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2171 hda_nid_t nid_vols
[] = {0x16, 0x18, 0x26, 0x27};
2172 hda_nid_t nid
, nid_vol
= 0;
2175 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2176 nid
= cfg
->line_out_pins
[i
];
2181 nid_vol
= nid_vols
[i
];
2183 if (i
== AUTO_SEQ_CENLFE
) {
2185 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2186 "Center Playback Volume",
2187 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2191 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2192 "LFE Playback Volume",
2193 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2197 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2198 "Center Playback Switch",
2199 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2203 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2204 "LFE Playback Switch",
2205 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2209 } else if (i
== AUTO_SEQ_FRONT
) {
2210 /* add control to mixer index 0 */
2211 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2212 "Master Front Playback Volume",
2213 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2217 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2218 "Master Front Playback Switch",
2219 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2224 /* add control to PW3 */
2225 sprintf(name
, "%s Playback Volume", chname
[i
]);
2226 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2227 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2231 sprintf(name
, "%s Playback Switch", chname
[i
]);
2232 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2233 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2238 sprintf(name
, "%s Playback Volume", chname
[i
]);
2239 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2240 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2244 sprintf(name
, "%s Playback Switch", chname
[i
]);
2245 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2246 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2256 static int vt1708B_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2263 spec
->multiout
.hp_nid
= VT1708B_HP_NID
; /* AOW3 */
2265 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2266 "Headphone Playback Volume",
2267 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2270 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2271 "Headphone Playback Switch",
2272 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2276 create_hp_imux(spec
);
2281 /* create playback/capture controls for input pins */
2282 static int vt1708B_auto_create_analog_input_ctls(struct via_spec
*spec
,
2283 const struct auto_pin_cfg
*cfg
)
2285 static char *labels
[] = {
2286 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2288 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2289 int i
, err
, idx
= 0;
2291 /* for internal loopback recording select */
2292 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2293 imux
->items
[imux
->num_items
].index
= idx
;
2296 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2297 if (!cfg
->input_pins
[i
])
2300 switch (cfg
->input_pins
[i
]) {
2301 case 0x1a: /* Mic */
2305 case 0x1b: /* Line In */
2309 case 0x1e: /* Front Mic */
2317 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
2321 imux
->items
[imux
->num_items
].label
= labels
[i
];
2322 imux
->items
[imux
->num_items
].index
= idx
;
2328 static int vt1708B_parse_auto_config(struct hda_codec
*codec
)
2330 struct via_spec
*spec
= codec
->spec
;
2333 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2336 err
= vt1708B_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2339 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2340 return 0; /* can't find valid BIOS pin config */
2342 err
= vt1708B_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2345 err
= vt1708B_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2348 err
= vt1708B_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2352 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2354 if (spec
->autocfg
.dig_outs
)
2355 spec
->multiout
.dig_out_nid
= VT1708B_DIGOUT_NID
;
2356 spec
->dig_in_pin
= VT1708B_DIGIN_PIN
;
2357 if (spec
->autocfg
.dig_in_pin
)
2358 spec
->dig_in_nid
= VT1708B_DIGIN_NID
;
2360 if (spec
->kctls
.list
)
2361 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2363 spec
->input_mux
= &spec
->private_imux
[0];
2366 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2371 #ifdef CONFIG_SND_HDA_POWER_SAVE
2372 static struct hda_amp_list vt1708B_loopbacks
[] = {
2373 { 0x16, HDA_INPUT
, 1 },
2374 { 0x16, HDA_INPUT
, 2 },
2375 { 0x16, HDA_INPUT
, 3 },
2376 { 0x16, HDA_INPUT
, 4 },
2381 static int patch_vt1708B_8ch(struct hda_codec
*codec
)
2383 struct via_spec
*spec
;
2386 /* create a codec specific record */
2387 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2393 /* automatic parse from the BIOS config */
2394 err
= vt1708B_parse_auto_config(codec
);
2399 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2400 "from BIOS. Using genenic mode...\n");
2403 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_8ch_volume_init_verbs
;
2404 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2406 spec
->stream_name_analog
= "VT1708B Analog";
2407 spec
->stream_analog_playback
= &vt1708B_8ch_pcm_analog_playback
;
2408 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2410 spec
->stream_name_digital
= "VT1708B Digital";
2411 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2412 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2414 if (!spec
->adc_nids
&& spec
->input_mux
) {
2415 spec
->adc_nids
= vt1708B_adc_nids
;
2416 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2417 get_mux_nids(codec
);
2418 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2422 codec
->patch_ops
= via_patch_ops
;
2424 codec
->patch_ops
.init
= via_auto_init
;
2425 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2426 #ifdef CONFIG_SND_HDA_POWER_SAVE
2427 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2433 static int patch_vt1708B_4ch(struct hda_codec
*codec
)
2435 struct via_spec
*spec
;
2438 /* create a codec specific record */
2439 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2445 /* automatic parse from the BIOS config */
2446 err
= vt1708B_parse_auto_config(codec
);
2451 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2452 "from BIOS. Using genenic mode...\n");
2455 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_4ch_volume_init_verbs
;
2456 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2458 spec
->stream_name_analog
= "VT1708B Analog";
2459 spec
->stream_analog_playback
= &vt1708B_4ch_pcm_analog_playback
;
2460 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2462 spec
->stream_name_digital
= "VT1708B Digital";
2463 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2464 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2466 if (!spec
->adc_nids
&& spec
->input_mux
) {
2467 spec
->adc_nids
= vt1708B_adc_nids
;
2468 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2469 get_mux_nids(codec
);
2470 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2474 codec
->patch_ops
= via_patch_ops
;
2476 codec
->patch_ops
.init
= via_auto_init
;
2477 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2478 #ifdef CONFIG_SND_HDA_POWER_SAVE
2479 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2485 /* Patch for VT1708S */
2487 /* VT1708S software backdoor based override for buggy hardware micboost
2489 #define MIC_BOOST_VOLUME(xname, nid) { \
2490 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2493 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2494 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2495 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2496 .info = mic_boost_volume_info, \
2497 .get = snd_hda_mixer_amp_volume_get, \
2498 .put = snd_hda_mixer_amp_volume_put, \
2499 .tlv = { .c = mic_boost_tlv }, \
2500 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2502 /* capture mixer elements */
2503 static struct snd_kcontrol_new vt1708S_capture_mixer
[] = {
2504 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
2505 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
2506 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
2507 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
2508 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2509 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2511 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2512 /* The multiple "Capture Source" controls confuse alsamixer
2513 * So call somewhat different..
2515 /* .name = "Capture Source", */
2516 .name
= "Input Source",
2518 .info
= via_mux_enum_info
,
2519 .get
= via_mux_enum_get
,
2520 .put
= via_mux_enum_put
,
2525 static struct hda_verb vt1708S_volume_init_verbs
[] = {
2526 /* Unmute ADC0-1 and set the default input to mic-in */
2527 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2528 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2530 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2531 * analog-loopback mixer widget */
2532 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2533 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2534 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2535 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2536 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2537 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2539 /* Setup default input of PW4 to MW0 */
2540 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2541 /* PW9, PW10 Output enable */
2542 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2543 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2544 /* Enable Mic Boost Volume backdoor */
2549 static struct hda_verb vt1708S_uniwill_init_verbs
[] = {
2550 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2554 static struct hda_pcm_stream vt1708S_pcm_analog_playback
= {
2558 .nid
= 0x10, /* NID to query formats and rates */
2560 .open
= via_playback_pcm_open
,
2561 .prepare
= via_playback_pcm_prepare
,
2562 .cleanup
= via_playback_pcm_cleanup
2566 static struct hda_pcm_stream vt1708S_pcm_analog_capture
= {
2570 .nid
= 0x13, /* NID to query formats and rates */
2572 .prepare
= via_capture_pcm_prepare
,
2573 .cleanup
= via_capture_pcm_cleanup
2577 static struct hda_pcm_stream vt1708S_pcm_digital_playback
= {
2581 /* NID is set in via_build_pcms */
2583 .open
= via_dig_playback_pcm_open
,
2584 .close
= via_dig_playback_pcm_close
,
2585 .prepare
= via_dig_playback_pcm_prepare
,
2586 .cleanup
= via_dig_playback_pcm_cleanup
2590 /* fill in the dac_nids table from the parsed pin configuration */
2591 static int vt1708S_auto_fill_dac_nids(struct via_spec
*spec
,
2592 const struct auto_pin_cfg
*cfg
)
2597 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2599 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2601 for (i
= 0; i
< 4; i
++) {
2602 nid
= cfg
->line_out_pins
[i
];
2604 /* config dac list */
2606 case AUTO_SEQ_FRONT
:
2607 spec
->multiout
.dac_nids
[i
] = 0x10;
2609 case AUTO_SEQ_CENLFE
:
2610 spec
->multiout
.dac_nids
[i
] = 0x24;
2612 case AUTO_SEQ_SURROUND
:
2613 spec
->multiout
.dac_nids
[i
] = 0x11;
2616 spec
->multiout
.dac_nids
[i
] = 0x25;
2625 /* add playback controls from the parsed DAC table */
2626 static int vt1708S_auto_create_multi_out_ctls(struct via_spec
*spec
,
2627 const struct auto_pin_cfg
*cfg
)
2630 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2631 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x24, 0x25};
2632 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x26, 0x27};
2633 hda_nid_t nid
, nid_vol
, nid_mute
;
2636 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2637 nid
= cfg
->line_out_pins
[i
];
2642 nid_vol
= nid_vols
[i
];
2643 nid_mute
= nid_mutes
[i
];
2645 if (i
== AUTO_SEQ_CENLFE
) {
2647 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2648 "Center Playback Volume",
2649 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2653 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2654 "LFE Playback Volume",
2655 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2659 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2660 "Center Playback Switch",
2661 HDA_COMPOSE_AMP_VAL(nid_mute
,
2666 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2667 "LFE Playback Switch",
2668 HDA_COMPOSE_AMP_VAL(nid_mute
,
2673 } else if (i
== AUTO_SEQ_FRONT
) {
2674 /* add control to mixer index 0 */
2675 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2676 "Master Front Playback Volume",
2677 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2681 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2682 "Master Front Playback Switch",
2683 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2689 sprintf(name
, "%s Playback Volume", chname
[i
]);
2690 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2691 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2695 sprintf(name
, "%s Playback Switch", chname
[i
]);
2696 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2697 HDA_COMPOSE_AMP_VAL(nid_mute
,
2703 sprintf(name
, "%s Playback Volume", chname
[i
]);
2704 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2705 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2709 sprintf(name
, "%s Playback Switch", chname
[i
]);
2710 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2711 HDA_COMPOSE_AMP_VAL(nid_mute
,
2722 static int vt1708S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2729 spec
->multiout
.hp_nid
= VT1708S_HP_NID
; /* AOW3 */
2731 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2732 "Headphone Playback Volume",
2733 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
2737 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2738 "Headphone Playback Switch",
2739 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2743 create_hp_imux(spec
);
2748 /* create playback/capture controls for input pins */
2749 static int vt1708S_auto_create_analog_input_ctls(struct via_spec
*spec
,
2750 const struct auto_pin_cfg
*cfg
)
2752 static char *labels
[] = {
2753 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2755 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2756 int i
, err
, idx
= 0;
2758 /* for internal loopback recording select */
2759 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2760 imux
->items
[imux
->num_items
].index
= 5;
2763 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2764 if (!cfg
->input_pins
[i
])
2767 switch (cfg
->input_pins
[i
]) {
2768 case 0x1a: /* Mic */
2772 case 0x1b: /* Line In */
2776 case 0x1e: /* Front Mic */
2784 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
2788 imux
->items
[imux
->num_items
].label
= labels
[i
];
2789 imux
->items
[imux
->num_items
].index
= idx
-1;
2795 /* fill out digital output widgets; one for master and one for slave outputs */
2796 static void fill_dig_outs(struct hda_codec
*codec
)
2798 struct via_spec
*spec
= codec
->spec
;
2801 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
2805 nid
= spec
->autocfg
.dig_out_pins
[i
];
2808 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
2811 if (!spec
->multiout
.dig_out_nid
)
2812 spec
->multiout
.dig_out_nid
= nid
;
2814 spec
->slave_dig_outs
[0] = nid
;
2815 break; /* at most two dig outs */
2820 static int vt1708S_parse_auto_config(struct hda_codec
*codec
)
2822 struct via_spec
*spec
= codec
->spec
;
2825 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2828 err
= vt1708S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2831 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2832 return 0; /* can't find valid BIOS pin config */
2834 err
= vt1708S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2837 err
= vt1708S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2840 err
= vt1708S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2844 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2846 fill_dig_outs(codec
);
2848 if (spec
->kctls
.list
)
2849 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2851 spec
->input_mux
= &spec
->private_imux
[0];
2854 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2859 #ifdef CONFIG_SND_HDA_POWER_SAVE
2860 static struct hda_amp_list vt1708S_loopbacks
[] = {
2861 { 0x16, HDA_INPUT
, 1 },
2862 { 0x16, HDA_INPUT
, 2 },
2863 { 0x16, HDA_INPUT
, 3 },
2864 { 0x16, HDA_INPUT
, 4 },
2869 static int patch_vt1708S(struct hda_codec
*codec
)
2871 struct via_spec
*spec
;
2874 /* create a codec specific record */
2875 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2881 /* automatic parse from the BIOS config */
2882 err
= vt1708S_parse_auto_config(codec
);
2887 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2888 "from BIOS. Using genenic mode...\n");
2891 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_volume_init_verbs
;
2892 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_uniwill_init_verbs
;
2894 spec
->stream_name_analog
= "VT1708S Analog";
2895 spec
->stream_analog_playback
= &vt1708S_pcm_analog_playback
;
2896 spec
->stream_analog_capture
= &vt1708S_pcm_analog_capture
;
2898 spec
->stream_name_digital
= "VT1708S Digital";
2899 spec
->stream_digital_playback
= &vt1708S_pcm_digital_playback
;
2901 if (!spec
->adc_nids
&& spec
->input_mux
) {
2902 spec
->adc_nids
= vt1708S_adc_nids
;
2903 spec
->num_adc_nids
= ARRAY_SIZE(vt1708S_adc_nids
);
2904 get_mux_nids(codec
);
2905 spec
->mixers
[spec
->num_mixers
] = vt1708S_capture_mixer
;
2909 codec
->patch_ops
= via_patch_ops
;
2911 codec
->patch_ops
.init
= via_auto_init
;
2912 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2913 #ifdef CONFIG_SND_HDA_POWER_SAVE
2914 spec
->loopback
.amplist
= vt1708S_loopbacks
;
2920 /* Patch for VT1702 */
2922 /* capture mixer elements */
2923 static struct snd_kcontrol_new vt1702_capture_mixer
[] = {
2924 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT
),
2925 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT
),
2926 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT
),
2927 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT
),
2928 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT
),
2929 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT
),
2930 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2933 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2934 /* The multiple "Capture Source" controls confuse alsamixer
2935 * So call somewhat different..
2937 /* .name = "Capture Source", */
2938 .name
= "Input Source",
2940 .info
= via_mux_enum_info
,
2941 .get
= via_mux_enum_get
,
2942 .put
= via_mux_enum_put
,
2947 static struct hda_verb vt1702_volume_init_verbs
[] = {
2949 * Unmute ADC0-1 and set the default input to mic-in
2951 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2952 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2953 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2956 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2959 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2960 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2961 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2962 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2963 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2964 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
2966 /* Setup default input of PW4 to MW0 */
2967 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x1},
2968 /* PW6 PW7 Output enable */
2969 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2970 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2974 static struct hda_verb vt1702_uniwill_init_verbs
[] = {
2975 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_GPIO_EVENT
},
2976 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2980 static struct hda_pcm_stream vt1702_pcm_analog_playback
= {
2984 .nid
= 0x10, /* NID to query formats and rates */
2986 .open
= via_playback_pcm_open
,
2987 .prepare
= via_playback_multi_pcm_prepare
,
2988 .cleanup
= via_playback_multi_pcm_cleanup
2992 static struct hda_pcm_stream vt1702_pcm_analog_capture
= {
2996 .nid
= 0x12, /* NID to query formats and rates */
2998 .prepare
= via_capture_pcm_prepare
,
2999 .cleanup
= via_capture_pcm_cleanup
3003 static struct hda_pcm_stream vt1702_pcm_digital_playback
= {
3007 /* NID is set in via_build_pcms */
3009 .open
= via_dig_playback_pcm_open
,
3010 .close
= via_dig_playback_pcm_close
,
3011 .prepare
= via_dig_playback_pcm_prepare
,
3012 .cleanup
= via_dig_playback_pcm_cleanup
3016 /* fill in the dac_nids table from the parsed pin configuration */
3017 static int vt1702_auto_fill_dac_nids(struct via_spec
*spec
,
3018 const struct auto_pin_cfg
*cfg
)
3020 spec
->multiout
.num_dacs
= 1;
3021 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3023 if (cfg
->line_out_pins
[0]) {
3024 /* config dac list */
3025 spec
->multiout
.dac_nids
[0] = 0x10;
3031 /* add playback controls from the parsed DAC table */
3032 static int vt1702_auto_create_line_out_ctls(struct via_spec
*spec
,
3033 const struct auto_pin_cfg
*cfg
)
3037 if (!cfg
->line_out_pins
[0])
3040 /* add control to mixer index 0 */
3041 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3042 "Master Front Playback Volume",
3043 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3046 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3047 "Master Front Playback Switch",
3048 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3053 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3054 "Front Playback Volume",
3055 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
));
3058 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3059 "Front Playback Switch",
3060 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT
));
3067 static int vt1702_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3074 spec
->multiout
.hp_nid
= 0x1D;
3076 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3077 "Headphone Playback Volume",
3078 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT
));
3082 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3083 "Headphone Playback Switch",
3084 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3088 create_hp_imux(spec
);
3093 /* create playback/capture controls for input pins */
3094 static int vt1702_auto_create_analog_input_ctls(struct via_spec
*spec
,
3095 const struct auto_pin_cfg
*cfg
)
3097 static char *labels
[] = {
3098 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3100 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3101 int i
, err
, idx
= 0;
3103 /* for internal loopback recording select */
3104 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3105 imux
->items
[imux
->num_items
].index
= 3;
3108 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3109 if (!cfg
->input_pins
[i
])
3112 switch (cfg
->input_pins
[i
]) {
3113 case 0x14: /* Mic */
3117 case 0x15: /* Line In */
3121 case 0x18: /* Front Mic */
3125 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
],
3126 labels
[i
], idx
, 0x1A);
3129 imux
->items
[imux
->num_items
].label
= labels
[i
];
3130 imux
->items
[imux
->num_items
].index
= idx
-1;
3136 static int vt1702_parse_auto_config(struct hda_codec
*codec
)
3138 struct via_spec
*spec
= codec
->spec
;
3141 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3144 err
= vt1702_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3147 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3148 return 0; /* can't find valid BIOS pin config */
3150 err
= vt1702_auto_create_line_out_ctls(spec
, &spec
->autocfg
);
3153 err
= vt1702_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3156 err
= vt1702_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3160 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3162 fill_dig_outs(codec
);
3164 if (spec
->kctls
.list
)
3165 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3167 spec
->input_mux
= &spec
->private_imux
[0];
3170 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3175 #ifdef CONFIG_SND_HDA_POWER_SAVE
3176 static struct hda_amp_list vt1702_loopbacks
[] = {
3177 { 0x1A, HDA_INPUT
, 1 },
3178 { 0x1A, HDA_INPUT
, 2 },
3179 { 0x1A, HDA_INPUT
, 3 },
3180 { 0x1A, HDA_INPUT
, 4 },
3185 static int patch_vt1702(struct hda_codec
*codec
)
3187 struct via_spec
*spec
;
3189 unsigned int response
;
3190 unsigned char control
;
3192 /* create a codec specific record */
3193 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3199 /* automatic parse from the BIOS config */
3200 err
= vt1702_parse_auto_config(codec
);
3205 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3206 "from BIOS. Using genenic mode...\n");
3209 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_volume_init_verbs
;
3210 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_uniwill_init_verbs
;
3212 spec
->stream_name_analog
= "VT1702 Analog";
3213 spec
->stream_analog_playback
= &vt1702_pcm_analog_playback
;
3214 spec
->stream_analog_capture
= &vt1702_pcm_analog_capture
;
3216 spec
->stream_name_digital
= "VT1702 Digital";
3217 spec
->stream_digital_playback
= &vt1702_pcm_digital_playback
;
3219 if (!spec
->adc_nids
&& spec
->input_mux
) {
3220 spec
->adc_nids
= vt1702_adc_nids
;
3221 spec
->num_adc_nids
= ARRAY_SIZE(vt1702_adc_nids
);
3222 get_mux_nids(codec
);
3223 spec
->mixers
[spec
->num_mixers
] = vt1702_capture_mixer
;
3227 codec
->patch_ops
= via_patch_ops
;
3229 codec
->patch_ops
.init
= via_auto_init
;
3230 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3231 #ifdef CONFIG_SND_HDA_POWER_SAVE
3232 spec
->loopback
.amplist
= vt1702_loopbacks
;
3236 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF8C, 0);
3237 control
= (unsigned char)(response
& 0xff);
3239 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF88, control
);
3241 /* Enable GPIO 0&1 for volume&mute control */
3242 /* Enable GPIO 2 for DMIC-DATA */
3243 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF84, 0);
3244 control
= (unsigned char)((response
>> 16) & 0x3f);
3245 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF82, control
);
3253 static struct hda_codec_preset snd_hda_preset_via
[] = {
3254 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
3255 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
3256 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
3257 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
3258 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
3259 .patch
= patch_vt1709_10ch
},
3260 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
3261 .patch
= patch_vt1709_10ch
},
3262 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
3263 .patch
= patch_vt1709_10ch
},
3264 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
3265 .patch
= patch_vt1709_10ch
},
3266 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
3267 .patch
= patch_vt1709_6ch
},
3268 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
3269 .patch
= patch_vt1709_6ch
},
3270 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
3271 .patch
= patch_vt1709_6ch
},
3272 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
3273 .patch
= patch_vt1709_6ch
},
3274 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
3275 .patch
= patch_vt1708B_8ch
},
3276 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
3277 .patch
= patch_vt1708B_8ch
},
3278 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
3279 .patch
= patch_vt1708B_8ch
},
3280 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
3281 .patch
= patch_vt1708B_8ch
},
3282 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
3283 .patch
= patch_vt1708B_4ch
},
3284 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
3285 .patch
= patch_vt1708B_4ch
},
3286 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
3287 .patch
= patch_vt1708B_4ch
},
3288 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
3289 .patch
= patch_vt1708B_4ch
},
3290 { .id
= 0x11060397, .name
= "VT1708S",
3291 .patch
= patch_vt1708S
},
3292 { .id
= 0x11061397, .name
= "VT1708S",
3293 .patch
= patch_vt1708S
},
3294 { .id
= 0x11062397, .name
= "VT1708S",
3295 .patch
= patch_vt1708S
},
3296 { .id
= 0x11063397, .name
= "VT1708S",
3297 .patch
= patch_vt1708S
},
3298 { .id
= 0x11064397, .name
= "VT1708S",
3299 .patch
= patch_vt1708S
},
3300 { .id
= 0x11065397, .name
= "VT1708S",
3301 .patch
= patch_vt1708S
},
3302 { .id
= 0x11066397, .name
= "VT1708S",
3303 .patch
= patch_vt1708S
},
3304 { .id
= 0x11067397, .name
= "VT1708S",
3305 .patch
= patch_vt1708S
},
3306 { .id
= 0x11060398, .name
= "VT1702",
3307 .patch
= patch_vt1702
},
3308 { .id
= 0x11061398, .name
= "VT1702",
3309 .patch
= patch_vt1702
},
3310 { .id
= 0x11062398, .name
= "VT1702",
3311 .patch
= patch_vt1702
},
3312 { .id
= 0x11063398, .name
= "VT1702",
3313 .patch
= patch_vt1702
},
3314 { .id
= 0x11064398, .name
= "VT1702",
3315 .patch
= patch_vt1702
},
3316 { .id
= 0x11065398, .name
= "VT1702",
3317 .patch
= patch_vt1702
},
3318 { .id
= 0x11066398, .name
= "VT1702",
3319 .patch
= patch_vt1702
},
3320 { .id
= 0x11067398, .name
= "VT1702",
3321 .patch
= patch_vt1702
},
3325 MODULE_ALIAS("snd-hda-codec-id:1106*");
3327 static struct hda_codec_preset_list via_list
= {
3328 .preset
= snd_hda_preset_via
,
3329 .owner
= THIS_MODULE
,
3332 MODULE_LICENSE("GPL");
3333 MODULE_DESCRIPTION("VIA HD-audio codec");
3335 static int __init
patch_via_init(void)
3337 return snd_hda_add_codec_preset(&via_list
);
3340 static void __exit
patch_via_exit(void)
3342 snd_hda_delete_codec_preset(&via_list
);
3345 module_init(patch_via_init
)
3346 module_exit(patch_via_exit
)