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"
50 #include "hda_patch.h"
53 #define AMP_VAL_IDX_SHIFT 19
54 #define AMP_VAL_IDX_MASK (0x0f<<19)
56 #define NUM_CONTROL_ALLOC 32
57 #define NUM_VERB_ALLOC 32
60 #define VT1708_HP_NID 0x13
61 #define VT1708_DIGOUT_NID 0x14
62 #define VT1708_DIGIN_NID 0x16
63 #define VT1708_DIGIN_PIN 0x26
64 #define VT1708_HP_PIN_NID 0x20
65 #define VT1708_CD_PIN_NID 0x24
67 #define VT1709_HP_DAC_NID 0x28
68 #define VT1709_DIGOUT_NID 0x13
69 #define VT1709_DIGIN_NID 0x17
70 #define VT1709_DIGIN_PIN 0x25
72 #define VT1708B_HP_NID 0x25
73 #define VT1708B_DIGOUT_NID 0x12
74 #define VT1708B_DIGIN_NID 0x15
75 #define VT1708B_DIGIN_PIN 0x21
77 #define VT1708S_HP_NID 0x25
78 #define VT1708S_DIGOUT_NID 0x12
80 #define VT1702_HP_NID 0x17
81 #define VT1702_DIGOUT_NID 0x11
83 #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
84 #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
85 #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
86 #define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
87 #define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
88 #define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
89 #define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
103 static enum VIA_HDA_CODEC
get_codec_type(u32 vendor_id
)
105 u16 ven_id
= vendor_id
>> 16;
106 u16 dev_id
= vendor_id
& 0xffff;
107 enum VIA_HDA_CODEC codec_type
;
110 if (ven_id
!= 0x1106)
111 codec_type
= UNKNOWN
;
112 else if (dev_id
>= 0x1708 && dev_id
<= 0x170b)
114 else if (dev_id
>= 0xe710 && dev_id
<= 0xe713)
115 codec_type
= VT1709_10CH
;
116 else if (dev_id
>= 0xe714 && dev_id
<= 0xe717)
117 codec_type
= VT1709_6CH
;
118 else if (dev_id
>= 0xe720 && dev_id
<= 0xe723)
119 codec_type
= VT1708B_8CH
;
120 else if (dev_id
>= 0xe724 && dev_id
<= 0xe727)
121 codec_type
= VT1708B_4CH
;
122 else if ((dev_id
& 0xfff) == 0x397
123 && (dev_id
>> 12) < 8)
124 codec_type
= VT1708S
;
125 else if ((dev_id
& 0xfff) == 0x398
126 && (dev_id
>> 12) < 8)
129 codec_type
= UNKNOWN
;
133 #define VIA_HP_EVENT 0x01
134 #define VIA_GPIO_EVENT 0x02
148 #define get_amp_nid(kc) ((kc)->private_value & 0xffff)
150 /* Some VT1708S based boards gets the micboost setting wrong, so we have
151 * to apply some brute-force and re-write the TLV's by software. */
152 static int mic_boost_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
153 unsigned int size
, unsigned int __user
*_tlv
)
155 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
156 hda_nid_t nid
= get_amp_nid(kcontrol
);
158 if (get_codec_type(codec
->vendor_id
) == VT1708S
159 && (nid
== 0x1a || nid
== 0x1e)) {
160 if (size
< 4 * sizeof(unsigned int))
162 if (put_user(1, _tlv
)) /* SNDRV_CTL_TLVT_DB_SCALE */
164 if (put_user(2 * sizeof(unsigned int), _tlv
+ 1))
166 if (put_user(0, _tlv
+ 2)) /* offset = 0 */
168 if (put_user(1000, _tlv
+ 3)) /* step size = 10 dB */
174 static int mic_boost_volume_info(struct snd_kcontrol
*kcontrol
,
175 struct snd_ctl_elem_info
*uinfo
)
177 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
178 hda_nid_t nid
= get_amp_nid(kcontrol
);
180 if (get_codec_type(codec
->vendor_id
) == VT1708S
181 && (nid
== 0x1a || nid
== 0x1e)) {
182 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
184 uinfo
->value
.integer
.min
= 0;
185 uinfo
->value
.integer
.max
= 3;
190 static struct snd_kcontrol_new vt1708_control_templates
[] = {
191 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
192 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
197 /* codec parameterization */
198 struct snd_kcontrol_new
*mixers
[3];
199 unsigned int num_mixers
;
201 struct hda_verb
*init_verbs
[5];
202 unsigned int num_iverbs
;
204 char *stream_name_analog
;
205 struct hda_pcm_stream
*stream_analog_playback
;
206 struct hda_pcm_stream
*stream_analog_capture
;
208 char *stream_name_digital
;
209 struct hda_pcm_stream
*stream_digital_playback
;
210 struct hda_pcm_stream
*stream_digital_capture
;
213 struct hda_multi_out multiout
;
214 hda_nid_t extra_dig_out_nid
;
217 unsigned int num_adc_nids
;
219 hda_nid_t dig_in_nid
;
222 const struct hda_input_mux
*input_mux
;
223 unsigned int cur_mux
[3];
225 /* PCM information */
226 struct hda_pcm pcm_rec
[3];
228 /* dynamic controls, init_verbs and input_mux */
229 struct auto_pin_cfg autocfg
;
230 unsigned int num_kctl_alloc
, num_kctl_used
;
231 struct snd_kcontrol_new
*kctl_alloc
;
232 struct hda_input_mux private_imux
[2];
233 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
236 const struct hda_input_mux
*hp_mux
;
237 unsigned int hp_independent_mode
;
239 #ifdef CONFIG_SND_HDA_POWER_SAVE
240 struct hda_loopback_check loopback
;
244 static hda_nid_t vt1708_adc_nids
[2] = {
249 static hda_nid_t vt1709_adc_nids
[3] = {
254 static hda_nid_t vt1708B_adc_nids
[2] = {
259 static hda_nid_t vt1708S_adc_nids
[2] = {
264 static hda_nid_t vt1702_adc_nids
[3] = {
269 /* add dynamic controls */
270 static int via_add_control(struct via_spec
*spec
, int type
, const char *name
,
273 struct snd_kcontrol_new
*knew
;
275 if (spec
->num_kctl_used
>= spec
->num_kctl_alloc
) {
276 int num
= spec
->num_kctl_alloc
+ NUM_CONTROL_ALLOC
;
278 /* array + terminator */
279 knew
= kcalloc(num
+ 1, sizeof(*knew
), GFP_KERNEL
);
282 if (spec
->kctl_alloc
) {
283 memcpy(knew
, spec
->kctl_alloc
,
284 sizeof(*knew
) * spec
->num_kctl_alloc
);
285 kfree(spec
->kctl_alloc
);
287 spec
->kctl_alloc
= knew
;
288 spec
->num_kctl_alloc
= num
;
291 knew
= &spec
->kctl_alloc
[spec
->num_kctl_used
];
292 *knew
= vt1708_control_templates
[type
];
293 knew
->name
= kstrdup(name
, GFP_KERNEL
);
297 knew
->private_value
= val
;
298 spec
->num_kctl_used
++;
302 /* create input playback/capture controls for the given pin */
303 static int via_new_analog_input(struct via_spec
*spec
, hda_nid_t pin
,
304 const char *ctlname
, int idx
, int mix_nid
)
309 sprintf(name
, "%s Playback Volume", ctlname
);
310 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
311 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
314 sprintf(name
, "%s Playback Switch", ctlname
);
315 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
316 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
322 static void via_auto_set_output_and_unmute(struct hda_codec
*codec
,
323 hda_nid_t nid
, int pin_type
,
327 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
329 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
334 static void via_auto_init_multi_out(struct hda_codec
*codec
)
336 struct via_spec
*spec
= codec
->spec
;
339 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
340 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
342 via_auto_set_output_and_unmute(codec
, nid
, PIN_OUT
, i
);
346 static void via_auto_init_hp_out(struct hda_codec
*codec
)
348 struct via_spec
*spec
= codec
->spec
;
351 pin
= spec
->autocfg
.hp_pins
[0];
352 if (pin
) /* connect to front */
353 via_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, 0);
356 static void via_auto_init_analog_input(struct hda_codec
*codec
)
358 struct via_spec
*spec
= codec
->spec
;
361 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
362 hda_nid_t nid
= spec
->autocfg
.input_pins
[i
];
364 snd_hda_codec_write(codec
, nid
, 0,
365 AC_VERB_SET_PIN_WIDGET_CONTROL
,
366 (i
<= AUTO_PIN_FRONT_MIC
?
367 PIN_VREF50
: PIN_IN
));
374 static int via_mux_enum_info(struct snd_kcontrol
*kcontrol
,
375 struct snd_ctl_elem_info
*uinfo
)
377 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
378 struct via_spec
*spec
= codec
->spec
;
379 return snd_hda_input_mux_info(spec
->input_mux
, uinfo
);
382 static int via_mux_enum_get(struct snd_kcontrol
*kcontrol
,
383 struct snd_ctl_elem_value
*ucontrol
)
385 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
386 struct via_spec
*spec
= codec
->spec
;
387 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
389 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
393 static int via_mux_enum_put(struct snd_kcontrol
*kcontrol
,
394 struct snd_ctl_elem_value
*ucontrol
)
396 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
397 struct via_spec
*spec
= codec
->spec
;
398 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
399 unsigned int vendor_id
= codec
->vendor_id
;
401 /* AIW0 lydia 060801 add for correct sw0 input select */
402 if (IS_VT1708_VENDORID(vendor_id
) && (adc_idx
== 0))
403 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
404 0x18, &spec
->cur_mux
[adc_idx
]);
405 else if ((IS_VT1709_10CH_VENDORID(vendor_id
) ||
406 IS_VT1709_6CH_VENDORID(vendor_id
)) && (adc_idx
== 0))
407 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
408 0x19, &spec
->cur_mux
[adc_idx
]);
409 else if ((IS_VT1708B_8CH_VENDORID(vendor_id
) ||
410 IS_VT1708B_4CH_VENDORID(vendor_id
)) && (adc_idx
== 0))
411 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
412 0x17, &spec
->cur_mux
[adc_idx
]);
413 else if (IS_VT1702_VENDORID(vendor_id
) && (adc_idx
== 0))
414 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
415 0x13, &spec
->cur_mux
[adc_idx
]);
417 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
418 spec
->adc_nids
[adc_idx
],
419 &spec
->cur_mux
[adc_idx
]);
422 static int via_independent_hp_info(struct snd_kcontrol
*kcontrol
,
423 struct snd_ctl_elem_info
*uinfo
)
425 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
426 struct via_spec
*spec
= codec
->spec
;
427 return snd_hda_input_mux_info(spec
->hp_mux
, uinfo
);
430 static int via_independent_hp_get(struct snd_kcontrol
*kcontrol
,
431 struct snd_ctl_elem_value
*ucontrol
)
433 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
434 struct via_spec
*spec
= codec
->spec
;
435 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
436 unsigned int pinsel
= snd_hda_codec_read(codec
, nid
, 0,
437 AC_VERB_GET_CONNECT_SEL
,
440 ucontrol
->value
.enumerated
.item
[0] = pinsel
;
445 static int via_independent_hp_put(struct snd_kcontrol
*kcontrol
,
446 struct snd_ctl_elem_value
*ucontrol
)
448 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
449 struct via_spec
*spec
= codec
->spec
;
450 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
451 unsigned int pinsel
= ucontrol
->value
.enumerated
.item
[0];
452 unsigned int con_nid
= snd_hda_codec_read(codec
, nid
, 0,
453 AC_VERB_GET_CONNECT_LIST
, 0) & 0xff;
455 if (con_nid
== spec
->multiout
.hp_nid
) {
457 if (!spec
->hp_independent_mode
) {
458 if (spec
->multiout
.num_dacs
> 1)
459 spec
->multiout
.num_dacs
-= 1;
460 spec
->hp_independent_mode
= 1;
462 } else if (pinsel
== 1) {
463 if (spec
->hp_independent_mode
) {
464 if (spec
->multiout
.num_dacs
> 1)
465 spec
->multiout
.num_dacs
+= 1;
466 spec
->hp_independent_mode
= 0;
471 if (spec
->hp_independent_mode
) {
472 if (spec
->multiout
.num_dacs
> 1)
473 spec
->multiout
.num_dacs
+= 1;
474 spec
->hp_independent_mode
= 0;
476 } else if (pinsel
== 1) {
477 if (!spec
->hp_independent_mode
) {
478 if (spec
->multiout
.num_dacs
> 1)
479 spec
->multiout
.num_dacs
-= 1;
480 spec
->hp_independent_mode
= 1;
484 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
,
487 if (spec
->multiout
.hp_nid
&&
488 spec
->multiout
.hp_nid
!= spec
->multiout
.dac_nids
[HDA_FRONT
])
489 snd_hda_codec_setup_stream(codec
,
490 spec
->multiout
.hp_nid
,
496 static struct snd_kcontrol_new via_hp_mixer
[] = {
498 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
499 .name
= "Independent HP",
501 .info
= via_independent_hp_info
,
502 .get
= via_independent_hp_get
,
503 .put
= via_independent_hp_put
,
508 /* capture mixer elements */
509 static struct snd_kcontrol_new vt1708_capture_mixer
[] = {
510 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT
),
511 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT
),
512 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT
),
513 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT
),
515 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
516 /* The multiple "Capture Source" controls confuse alsamixer
517 * So call somewhat different..
519 /* .name = "Capture Source", */
520 .name
= "Input Source",
522 .info
= via_mux_enum_info
,
523 .get
= via_mux_enum_get
,
524 .put
= via_mux_enum_put
,
529 * generic initialization of ADC, input mixers and output mixers
531 static struct hda_verb vt1708_volume_init_verbs
[] = {
533 * Unmute ADC0-1 and set the default input to mic-in
535 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
536 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
539 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
542 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
543 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
544 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
545 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
546 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
547 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
550 * Set up output mixers (0x19 - 0x1b)
552 /* set vol=0 to output mixers */
553 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
554 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
555 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
557 /* Setup default input to PW4 */
558 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
559 /* PW9 Output enable */
560 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
564 static int via_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
565 struct hda_codec
*codec
,
566 struct snd_pcm_substream
*substream
)
568 struct via_spec
*spec
= codec
->spec
;
569 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
573 static int via_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
574 struct hda_codec
*codec
,
575 unsigned int stream_tag
,
577 struct snd_pcm_substream
*substream
)
579 struct via_spec
*spec
= codec
->spec
;
580 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
581 stream_tag
, format
, substream
);
584 static int via_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
585 struct hda_codec
*codec
,
586 struct snd_pcm_substream
*substream
)
588 struct via_spec
*spec
= codec
->spec
;
589 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
593 static void playback_multi_pcm_prep_0(struct hda_codec
*codec
,
594 unsigned int stream_tag
,
596 struct snd_pcm_substream
*substream
)
598 struct via_spec
*spec
= codec
->spec
;
599 struct hda_multi_out
*mout
= &spec
->multiout
;
600 hda_nid_t
*nids
= mout
->dac_nids
;
601 int chs
= substream
->runtime
->channels
;
604 mutex_lock(&codec
->spdif_mutex
);
605 if (mout
->dig_out_nid
&& mout
->dig_out_used
!= HDA_DIG_EXCLUSIVE
) {
607 snd_hda_is_supported_format(codec
, mout
->dig_out_nid
,
609 !(codec
->spdif_status
& IEC958_AES0_NONAUDIO
)) {
610 mout
->dig_out_used
= HDA_DIG_ANALOG_DUP
;
611 /* turn off SPDIF once; otherwise the IEC958 bits won't
613 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
614 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
615 AC_VERB_SET_DIGI_CONVERT_1
,
617 ~AC_DIG1_ENABLE
& 0xff);
618 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
619 stream_tag
, 0, format
);
620 /* turn on again (if needed) */
621 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
622 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
623 AC_VERB_SET_DIGI_CONVERT_1
,
624 codec
->spdif_ctls
& 0xff);
626 mout
->dig_out_used
= 0;
627 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
631 mutex_unlock(&codec
->spdif_mutex
);
634 snd_hda_codec_setup_stream(codec
, nids
[HDA_FRONT
], stream_tag
,
637 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
638 !spec
->hp_independent_mode
)
639 /* headphone out will just decode front left/right (stereo) */
640 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
, stream_tag
,
643 /* extra outputs copied from front */
644 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
645 if (mout
->extra_out_nid
[i
])
646 snd_hda_codec_setup_stream(codec
,
647 mout
->extra_out_nid
[i
],
648 stream_tag
, 0, format
);
651 for (i
= 1; i
< mout
->num_dacs
; i
++) {
652 if (chs
>= (i
+ 1) * 2) /* independent out */
653 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
655 else /* copy front */
656 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
661 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
662 struct hda_codec
*codec
,
663 unsigned int stream_tag
,
665 struct snd_pcm_substream
*substream
)
667 struct via_spec
*spec
= codec
->spec
;
668 struct hda_multi_out
*mout
= &spec
->multiout
;
669 hda_nid_t
*nids
= mout
->dac_nids
;
671 if (substream
->number
== 0)
672 playback_multi_pcm_prep_0(codec
, stream_tag
, format
,
675 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
676 spec
->hp_independent_mode
)
677 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
678 stream_tag
, 0, format
);
684 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
685 struct hda_codec
*codec
,
686 struct snd_pcm_substream
*substream
)
688 struct via_spec
*spec
= codec
->spec
;
689 struct hda_multi_out
*mout
= &spec
->multiout
;
690 hda_nid_t
*nids
= mout
->dac_nids
;
693 if (substream
->number
== 0) {
694 for (i
= 0; i
< mout
->num_dacs
; i
++)
695 snd_hda_codec_setup_stream(codec
, nids
[i
], 0, 0, 0);
697 if (mout
->hp_nid
&& !spec
->hp_independent_mode
)
698 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
701 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
702 if (mout
->extra_out_nid
[i
])
703 snd_hda_codec_setup_stream(codec
,
704 mout
->extra_out_nid
[i
],
706 mutex_lock(&codec
->spdif_mutex
);
707 if (mout
->dig_out_nid
&&
708 mout
->dig_out_used
== HDA_DIG_ANALOG_DUP
) {
709 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
711 mout
->dig_out_used
= 0;
713 mutex_unlock(&codec
->spdif_mutex
);
715 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
716 spec
->hp_independent_mode
)
717 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
727 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
728 struct hda_codec
*codec
,
729 struct snd_pcm_substream
*substream
)
731 struct via_spec
*spec
= codec
->spec
;
732 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
735 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
736 struct hda_codec
*codec
,
737 struct snd_pcm_substream
*substream
)
739 struct via_spec
*spec
= codec
->spec
;
740 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
743 /* setup SPDIF output stream */
744 static void setup_dig_playback_stream(struct hda_codec
*codec
, hda_nid_t nid
,
745 unsigned int stream_tag
, unsigned int format
)
747 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
748 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
749 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_DIGI_CONVERT_1
,
750 codec
->spdif_ctls
& ~AC_DIG1_ENABLE
& 0xff);
751 snd_hda_codec_setup_stream(codec
, nid
, stream_tag
, 0, format
);
752 /* turn on again (if needed) */
753 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
754 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_DIGI_CONVERT_1
,
755 codec
->spdif_ctls
& 0xff);
758 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
759 struct hda_codec
*codec
,
760 unsigned int stream_tag
,
762 struct snd_pcm_substream
*substream
)
764 struct via_spec
*spec
= codec
->spec
;
767 /* 1st or 2nd S/PDIF */
768 if (substream
->number
== 0)
769 nid
= spec
->multiout
.dig_out_nid
;
770 else if (substream
->number
== 1)
771 nid
= spec
->extra_dig_out_nid
;
775 mutex_lock(&codec
->spdif_mutex
);
776 setup_dig_playback_stream(codec
, nid
, stream_tag
, format
);
777 mutex_unlock(&codec
->spdif_mutex
);
784 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
785 struct hda_codec
*codec
,
786 unsigned int stream_tag
,
788 struct snd_pcm_substream
*substream
)
790 struct via_spec
*spec
= codec
->spec
;
792 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
793 stream_tag
, 0, format
);
797 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
798 struct hda_codec
*codec
,
799 struct snd_pcm_substream
*substream
)
801 struct via_spec
*spec
= codec
->spec
;
802 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
806 static struct hda_pcm_stream vt1708_pcm_analog_playback
= {
810 .nid
= 0x10, /* NID to query formats and rates */
812 .open
= via_playback_pcm_open
,
813 .prepare
= via_playback_multi_pcm_prepare
,
814 .cleanup
= via_playback_multi_pcm_cleanup
818 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
822 .nid
= 0x10, /* NID to query formats and rates */
823 /* We got noisy outputs on the right channel on VT1708 when
824 * 24bit samples are used. Until any workaround is found,
825 * disable the 24bit format, so far.
827 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
829 .open
= via_playback_pcm_open
,
830 .prepare
= via_playback_pcm_prepare
,
831 .cleanup
= via_playback_pcm_cleanup
835 static struct hda_pcm_stream vt1708_pcm_analog_capture
= {
839 .nid
= 0x15, /* NID to query formats and rates */
841 .prepare
= via_capture_pcm_prepare
,
842 .cleanup
= via_capture_pcm_cleanup
846 static struct hda_pcm_stream vt1708_pcm_digital_playback
= {
850 /* NID is set in via_build_pcms */
852 .open
= via_dig_playback_pcm_open
,
853 .close
= via_dig_playback_pcm_close
,
854 .prepare
= via_dig_playback_pcm_prepare
858 static struct hda_pcm_stream vt1708_pcm_digital_capture
= {
864 static int via_build_controls(struct hda_codec
*codec
)
866 struct via_spec
*spec
= codec
->spec
;
870 for (i
= 0; i
< spec
->num_mixers
; i
++) {
871 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
876 if (spec
->multiout
.dig_out_nid
) {
877 err
= snd_hda_create_spdif_out_ctls(codec
,
878 spec
->multiout
.dig_out_nid
);
881 err
= snd_hda_create_spdif_share_sw(codec
,
885 spec
->multiout
.share_spdif
= 1;
887 if (spec
->extra_dig_out_nid
) {
888 err
= snd_hda_create_spdif_out_ctls(codec
,
889 spec
->extra_dig_out_nid
);
894 if (spec
->dig_in_nid
) {
895 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
902 static int via_build_pcms(struct hda_codec
*codec
)
904 struct via_spec
*spec
= codec
->spec
;
905 struct hda_pcm
*info
= spec
->pcm_rec
;
908 codec
->pcm_info
= info
;
910 info
->name
= spec
->stream_name_analog
;
911 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *(spec
->stream_analog_playback
);
912 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
913 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *(spec
->stream_analog_capture
);
914 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
916 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
917 spec
->multiout
.max_channels
;
919 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
922 info
->name
= spec
->stream_name_digital
;
923 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
924 if (spec
->multiout
.dig_out_nid
) {
925 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
926 *(spec
->stream_digital_playback
);
927 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
928 spec
->multiout
.dig_out_nid
;
930 if (spec
->dig_in_nid
) {
931 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
932 *(spec
->stream_digital_capture
);
933 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
941 static void via_free(struct hda_codec
*codec
)
943 struct via_spec
*spec
= codec
->spec
;
949 if (spec
->kctl_alloc
) {
950 for (i
= 0; i
< spec
->num_kctl_used
; i
++)
951 kfree(spec
->kctl_alloc
[i
].name
);
952 kfree(spec
->kctl_alloc
);
958 /* mute internal speaker if HP is plugged */
959 static void via_hp_automute(struct hda_codec
*codec
)
961 unsigned int present
;
962 struct via_spec
*spec
= codec
->spec
;
964 present
= snd_hda_codec_read(codec
, spec
->autocfg
.hp_pins
[0], 0,
965 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
966 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
967 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
968 present
? HDA_AMP_MUTE
: 0);
971 static void via_gpio_control(struct hda_codec
*codec
)
973 unsigned int gpio_data
;
974 unsigned int vol_counter
;
976 unsigned int master_vol
;
978 struct via_spec
*spec
= codec
->spec
;
980 gpio_data
= snd_hda_codec_read(codec
, codec
->afg
, 0,
981 AC_VERB_GET_GPIO_DATA
, 0) & 0x03;
983 vol_counter
= (snd_hda_codec_read(codec
, codec
->afg
, 0,
984 0xF84, 0) & 0x3F0000) >> 16;
986 vol
= vol_counter
& 0x1F;
987 master_vol
= snd_hda_codec_read(codec
, 0x1A, 0,
988 AC_VERB_GET_AMP_GAIN_MUTE
,
991 if (gpio_data
== 0x02) {
992 /* unmute line out */
993 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
994 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
996 if (vol_counter
& 0x20) {
997 /* decrease volume */
998 if (vol
> master_vol
)
1000 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
,
1004 /* increase volume */
1005 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
, 0,
1007 ((master_vol
+vol
) > 0x2A) ? 0x2A :
1010 } else if (!(gpio_data
& 0x02)) {
1012 snd_hda_codec_amp_stereo(codec
,
1013 spec
->autocfg
.line_out_pins
[0],
1014 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
1019 /* unsolicited event for jack sensing */
1020 static void via_unsol_event(struct hda_codec
*codec
,
1024 if (res
== VIA_HP_EVENT
)
1025 via_hp_automute(codec
);
1026 else if (res
== VIA_GPIO_EVENT
)
1027 via_gpio_control(codec
);
1030 static hda_nid_t slave_dig_outs
[] = {
1034 static int via_init(struct hda_codec
*codec
)
1036 struct via_spec
*spec
= codec
->spec
;
1038 for (i
= 0; i
< spec
->num_iverbs
; i
++)
1039 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
1041 /* Lydia Add for EAPD enable */
1042 if (!spec
->dig_in_nid
) { /* No Digital In connection */
1043 if (IS_VT1708_VENDORID(codec
->vendor_id
)) {
1044 snd_hda_codec_write(codec
, VT1708_DIGIN_PIN
, 0,
1045 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1047 snd_hda_codec_write(codec
, VT1708_DIGIN_PIN
, 0,
1048 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
1049 } else if (IS_VT1709_10CH_VENDORID(codec
->vendor_id
) ||
1050 IS_VT1709_6CH_VENDORID(codec
->vendor_id
)) {
1051 snd_hda_codec_write(codec
, VT1709_DIGIN_PIN
, 0,
1052 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1054 snd_hda_codec_write(codec
, VT1709_DIGIN_PIN
, 0,
1055 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
1056 } else if (IS_VT1708B_8CH_VENDORID(codec
->vendor_id
) ||
1057 IS_VT1708B_4CH_VENDORID(codec
->vendor_id
)) {
1058 snd_hda_codec_write(codec
, VT1708B_DIGIN_PIN
, 0,
1059 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1061 snd_hda_codec_write(codec
, VT1708B_DIGIN_PIN
, 0,
1062 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
1064 } else /* enable SPDIF-input pin */
1065 snd_hda_codec_write(codec
, spec
->autocfg
.dig_in_pin
, 0,
1066 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
1069 codec
->slave_dig_outs
= slave_dig_outs
;
1074 #ifdef CONFIG_SND_HDA_POWER_SAVE
1075 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
1077 struct via_spec
*spec
= codec
->spec
;
1078 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
1084 static struct hda_codec_ops via_patch_ops
= {
1085 .build_controls
= via_build_controls
,
1086 .build_pcms
= via_build_pcms
,
1089 #ifdef CONFIG_SND_HDA_POWER_SAVE
1090 .check_power_status
= via_check_power_status
,
1094 /* fill in the dac_nids table from the parsed pin configuration */
1095 static int vt1708_auto_fill_dac_nids(struct via_spec
*spec
,
1096 const struct auto_pin_cfg
*cfg
)
1101 spec
->multiout
.num_dacs
= cfg
->line_outs
;
1103 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1105 for(i
= 0; i
< 4; i
++) {
1106 nid
= cfg
->line_out_pins
[i
];
1108 /* config dac list */
1110 case AUTO_SEQ_FRONT
:
1111 spec
->multiout
.dac_nids
[i
] = 0x10;
1113 case AUTO_SEQ_CENLFE
:
1114 spec
->multiout
.dac_nids
[i
] = 0x12;
1116 case AUTO_SEQ_SURROUND
:
1117 spec
->multiout
.dac_nids
[i
] = 0x11;
1120 spec
->multiout
.dac_nids
[i
] = 0x13;
1129 /* add playback controls from the parsed DAC table */
1130 static int vt1708_auto_create_multi_out_ctls(struct via_spec
*spec
,
1131 const struct auto_pin_cfg
*cfg
)
1134 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1135 hda_nid_t nid
, nid_vol
= 0;
1138 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1139 nid
= cfg
->line_out_pins
[i
];
1144 if (i
!= AUTO_SEQ_FRONT
)
1147 if (i
== AUTO_SEQ_CENLFE
) {
1149 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1150 "Center Playback Volume",
1151 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1155 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1156 "LFE Playback Volume",
1157 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1161 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1162 "Center Playback Switch",
1163 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1167 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1168 "LFE Playback Switch",
1169 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1173 } else if (i
== AUTO_SEQ_FRONT
){
1174 /* add control to mixer index 0 */
1175 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1176 "Master Front Playback Volume",
1177 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1181 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1182 "Master Front Playback Switch",
1183 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1188 /* add control to PW3 */
1189 sprintf(name
, "%s Playback Volume", chname
[i
]);
1190 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1191 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1195 sprintf(name
, "%s Playback Switch", chname
[i
]);
1196 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1197 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1202 sprintf(name
, "%s Playback Volume", chname
[i
]);
1203 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1204 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1208 sprintf(name
, "%s Playback Switch", chname
[i
]);
1209 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1210 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1220 static void create_hp_imux(struct via_spec
*spec
)
1223 struct hda_input_mux
*imux
= &spec
->private_imux
[1];
1224 static const char *texts
[] = { "OFF", "ON", NULL
};
1226 /* for hp mode select */
1228 while (texts
[i
] != NULL
) {
1229 imux
->items
[imux
->num_items
].label
= texts
[i
];
1230 imux
->items
[imux
->num_items
].index
= i
;
1235 spec
->hp_mux
= &spec
->private_imux
[1];
1238 static int vt1708_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1245 spec
->multiout
.hp_nid
= VT1708_HP_NID
; /* AOW3 */
1247 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1248 "Headphone Playback Volume",
1249 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1252 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1253 "Headphone Playback Switch",
1254 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1258 create_hp_imux(spec
);
1263 /* create playback/capture controls for input pins */
1264 static int vt1708_auto_create_analog_input_ctls(struct via_spec
*spec
,
1265 const struct auto_pin_cfg
*cfg
)
1267 static char *labels
[] = {
1268 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1270 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1271 int i
, err
, idx
= 0;
1273 /* for internal loopback recording select */
1274 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1275 imux
->items
[imux
->num_items
].index
= idx
;
1278 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1279 if (!cfg
->input_pins
[i
])
1282 switch (cfg
->input_pins
[i
]) {
1283 case 0x1d: /* Mic */
1287 case 0x1e: /* Line In */
1291 case 0x21: /* Front Mic */
1299 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
1303 imux
->items
[imux
->num_items
].label
= labels
[i
];
1304 imux
->items
[imux
->num_items
].index
= idx
;
1310 #ifdef CONFIG_SND_HDA_POWER_SAVE
1311 static struct hda_amp_list vt1708_loopbacks
[] = {
1312 { 0x17, HDA_INPUT
, 1 },
1313 { 0x17, HDA_INPUT
, 2 },
1314 { 0x17, HDA_INPUT
, 3 },
1315 { 0x17, HDA_INPUT
, 4 },
1320 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
1322 unsigned int def_conf
;
1323 unsigned char seqassoc
;
1325 def_conf
= snd_hda_codec_read(codec
, nid
, 0,
1326 AC_VERB_GET_CONFIG_DEFAULT
, 0);
1327 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
1328 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
1329 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
) {
1330 if (seqassoc
== 0xff) {
1331 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
1332 snd_hda_codec_write(codec
, nid
, 0,
1333 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3
,
1341 static int vt1708_parse_auto_config(struct hda_codec
*codec
)
1343 struct via_spec
*spec
= codec
->spec
;
1346 /* Add HP and CD pin config connect bit re-config action */
1347 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
1348 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
1350 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1353 err
= vt1708_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1356 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1357 return 0; /* can't find valid BIOS pin config */
1359 err
= vt1708_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1362 err
= vt1708_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1365 err
= vt1708_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1369 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1371 if (spec
->autocfg
.dig_out_pin
)
1372 spec
->multiout
.dig_out_nid
= VT1708_DIGOUT_NID
;
1373 if (spec
->autocfg
.dig_in_pin
)
1374 spec
->dig_in_nid
= VT1708_DIGIN_NID
;
1376 if (spec
->kctl_alloc
)
1377 spec
->mixers
[spec
->num_mixers
++] = spec
->kctl_alloc
;
1379 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_volume_init_verbs
;
1381 spec
->input_mux
= &spec
->private_imux
[0];
1384 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1389 /* init callback for auto-configuration model -- overriding the default init */
1390 static int via_auto_init(struct hda_codec
*codec
)
1393 via_auto_init_multi_out(codec
);
1394 via_auto_init_hp_out(codec
);
1395 via_auto_init_analog_input(codec
);
1399 static int patch_vt1708(struct hda_codec
*codec
)
1401 struct via_spec
*spec
;
1404 /* create a codec specific record */
1405 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1411 /* automatic parse from the BIOS config */
1412 err
= vt1708_parse_auto_config(codec
);
1417 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
1418 "from BIOS. Using genenic mode...\n");
1422 spec
->stream_name_analog
= "VT1708 Analog";
1423 spec
->stream_analog_playback
= &vt1708_pcm_analog_playback
;
1424 /* disable 32bit format on VT1708 */
1425 if (codec
->vendor_id
== 0x11061708)
1426 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
1427 spec
->stream_analog_capture
= &vt1708_pcm_analog_capture
;
1429 spec
->stream_name_digital
= "VT1708 Digital";
1430 spec
->stream_digital_playback
= &vt1708_pcm_digital_playback
;
1431 spec
->stream_digital_capture
= &vt1708_pcm_digital_capture
;
1434 if (!spec
->adc_nids
&& spec
->input_mux
) {
1435 spec
->adc_nids
= vt1708_adc_nids
;
1436 spec
->num_adc_nids
= ARRAY_SIZE(vt1708_adc_nids
);
1437 spec
->mixers
[spec
->num_mixers
] = vt1708_capture_mixer
;
1441 codec
->patch_ops
= via_patch_ops
;
1443 codec
->patch_ops
.init
= via_auto_init
;
1444 #ifdef CONFIG_SND_HDA_POWER_SAVE
1445 spec
->loopback
.amplist
= vt1708_loopbacks
;
1451 /* capture mixer elements */
1452 static struct snd_kcontrol_new vt1709_capture_mixer
[] = {
1453 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT
),
1454 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT
),
1455 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT
),
1456 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT
),
1457 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT
),
1458 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT
),
1460 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1461 /* The multiple "Capture Source" controls confuse alsamixer
1462 * So call somewhat different..
1464 /* .name = "Capture Source", */
1465 .name
= "Input Source",
1467 .info
= via_mux_enum_info
,
1468 .get
= via_mux_enum_get
,
1469 .put
= via_mux_enum_put
,
1474 static struct hda_verb vt1709_uniwill_init_verbs
[] = {
1475 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
1480 * generic initialization of ADC, input mixers and output mixers
1482 static struct hda_verb vt1709_10ch_volume_init_verbs
[] = {
1484 * Unmute ADC0-2 and set the default input to mic-in
1486 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1487 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1488 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1491 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1494 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1495 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1496 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1497 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1498 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1499 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1502 * Set up output selector (0x1a, 0x1b, 0x29)
1504 /* set vol=0 to output mixers */
1505 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1506 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1507 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1510 * Unmute PW3 and PW4
1512 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1513 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1515 /* Set input of PW4 as AOW4 */
1516 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
1517 /* PW9 Output enable */
1518 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1522 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback
= {
1526 .nid
= 0x10, /* NID to query formats and rates */
1528 .open
= via_playback_pcm_open
,
1529 .prepare
= via_playback_pcm_prepare
,
1530 .cleanup
= via_playback_pcm_cleanup
1534 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback
= {
1538 .nid
= 0x10, /* NID to query formats and rates */
1540 .open
= via_playback_pcm_open
,
1541 .prepare
= via_playback_pcm_prepare
,
1542 .cleanup
= via_playback_pcm_cleanup
1546 static struct hda_pcm_stream vt1709_pcm_analog_capture
= {
1550 .nid
= 0x14, /* NID to query formats and rates */
1552 .prepare
= via_capture_pcm_prepare
,
1553 .cleanup
= via_capture_pcm_cleanup
1557 static struct hda_pcm_stream vt1709_pcm_digital_playback
= {
1561 /* NID is set in via_build_pcms */
1563 .open
= via_dig_playback_pcm_open
,
1564 .close
= via_dig_playback_pcm_close
1568 static struct hda_pcm_stream vt1709_pcm_digital_capture
= {
1574 static int vt1709_auto_fill_dac_nids(struct via_spec
*spec
,
1575 const struct auto_pin_cfg
*cfg
)
1580 if (cfg
->line_outs
== 4) /* 10 channels */
1581 spec
->multiout
.num_dacs
= cfg
->line_outs
+1; /* AOW0~AOW4 */
1582 else if (cfg
->line_outs
== 3) /* 6 channels */
1583 spec
->multiout
.num_dacs
= cfg
->line_outs
; /* AOW0~AOW2 */
1585 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1587 if (cfg
->line_outs
== 4) { /* 10 channels */
1588 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1589 nid
= cfg
->line_out_pins
[i
];
1591 /* config dac list */
1593 case AUTO_SEQ_FRONT
:
1595 spec
->multiout
.dac_nids
[i
] = 0x10;
1597 case AUTO_SEQ_CENLFE
:
1599 spec
->multiout
.dac_nids
[i
] = 0x12;
1601 case AUTO_SEQ_SURROUND
:
1603 spec
->multiout
.dac_nids
[i
] = 0x11;
1607 spec
->multiout
.dac_nids
[i
] = 0x27;
1614 spec
->multiout
.dac_nids
[cfg
->line_outs
] = 0x28; /* AOW4 */
1616 } else if (cfg
->line_outs
== 3) { /* 6 channels */
1617 for(i
= 0; i
< cfg
->line_outs
; i
++) {
1618 nid
= cfg
->line_out_pins
[i
];
1620 /* config dac list */
1622 case AUTO_SEQ_FRONT
:
1624 spec
->multiout
.dac_nids
[i
] = 0x10;
1626 case AUTO_SEQ_CENLFE
:
1628 spec
->multiout
.dac_nids
[i
] = 0x12;
1630 case AUTO_SEQ_SURROUND
:
1632 spec
->multiout
.dac_nids
[i
] = 0x11;
1644 /* add playback controls from the parsed DAC table */
1645 static int vt1709_auto_create_multi_out_ctls(struct via_spec
*spec
,
1646 const struct auto_pin_cfg
*cfg
)
1649 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1653 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1654 nid
= cfg
->line_out_pins
[i
];
1659 if (i
== AUTO_SEQ_CENLFE
) {
1661 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1662 "Center Playback Volume",
1663 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1667 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1668 "LFE Playback Volume",
1669 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1673 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1674 "Center Playback Switch",
1675 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1679 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1680 "LFE Playback Switch",
1681 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1685 } else if (i
== AUTO_SEQ_FRONT
){
1686 /* add control to mixer index 0 */
1687 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1688 "Master Front Playback Volume",
1689 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1693 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1694 "Master Front Playback Switch",
1695 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1700 /* add control to PW3 */
1701 sprintf(name
, "%s Playback Volume", chname
[i
]);
1702 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1703 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1707 sprintf(name
, "%s Playback Switch", chname
[i
]);
1708 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1709 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1713 } else if (i
== AUTO_SEQ_SURROUND
) {
1714 sprintf(name
, "%s Playback Volume", chname
[i
]);
1715 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1716 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1720 sprintf(name
, "%s Playback Switch", chname
[i
]);
1721 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1722 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1726 } else if (i
== AUTO_SEQ_SIDE
) {
1727 sprintf(name
, "%s Playback Volume", chname
[i
]);
1728 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1729 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1733 sprintf(name
, "%s Playback Switch", chname
[i
]);
1734 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1735 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1745 static int vt1709_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1752 if (spec
->multiout
.num_dacs
== 5) /* 10 channels */
1753 spec
->multiout
.hp_nid
= VT1709_HP_DAC_NID
;
1754 else if (spec
->multiout
.num_dacs
== 3) /* 6 channels */
1755 spec
->multiout
.hp_nid
= 0;
1757 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1758 "Headphone Playback Volume",
1759 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1762 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1763 "Headphone Playback Switch",
1764 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1771 /* create playback/capture controls for input pins */
1772 static int vt1709_auto_create_analog_input_ctls(struct via_spec
*spec
,
1773 const struct auto_pin_cfg
*cfg
)
1775 static char *labels
[] = {
1776 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1778 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1779 int i
, err
, idx
= 0;
1781 /* for internal loopback recording select */
1782 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1783 imux
->items
[imux
->num_items
].index
= idx
;
1786 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1787 if (!cfg
->input_pins
[i
])
1790 switch (cfg
->input_pins
[i
]) {
1791 case 0x1d: /* Mic */
1795 case 0x1e: /* Line In */
1799 case 0x21: /* Front Mic */
1807 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
1811 imux
->items
[imux
->num_items
].label
= labels
[i
];
1812 imux
->items
[imux
->num_items
].index
= idx
;
1818 static int vt1709_parse_auto_config(struct hda_codec
*codec
)
1820 struct via_spec
*spec
= codec
->spec
;
1823 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1826 err
= vt1709_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1829 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1830 return 0; /* can't find valid BIOS pin config */
1832 err
= vt1709_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1835 err
= vt1709_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1838 err
= vt1709_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1842 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1844 if (spec
->autocfg
.dig_out_pin
)
1845 spec
->multiout
.dig_out_nid
= VT1709_DIGOUT_NID
;
1846 if (spec
->autocfg
.dig_in_pin
)
1847 spec
->dig_in_nid
= VT1709_DIGIN_NID
;
1849 if (spec
->kctl_alloc
)
1850 spec
->mixers
[spec
->num_mixers
++] = spec
->kctl_alloc
;
1852 spec
->input_mux
= &spec
->private_imux
[0];
1855 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1860 #ifdef CONFIG_SND_HDA_POWER_SAVE
1861 static struct hda_amp_list vt1709_loopbacks
[] = {
1862 { 0x18, HDA_INPUT
, 1 },
1863 { 0x18, HDA_INPUT
, 2 },
1864 { 0x18, HDA_INPUT
, 3 },
1865 { 0x18, HDA_INPUT
, 4 },
1870 static int patch_vt1709_10ch(struct hda_codec
*codec
)
1872 struct via_spec
*spec
;
1875 /* create a codec specific record */
1876 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1882 err
= vt1709_parse_auto_config(codec
);
1887 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
1888 "Using genenic mode...\n");
1891 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_10ch_volume_init_verbs
;
1892 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
1894 spec
->stream_name_analog
= "VT1709 Analog";
1895 spec
->stream_analog_playback
= &vt1709_10ch_pcm_analog_playback
;
1896 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
1898 spec
->stream_name_digital
= "VT1709 Digital";
1899 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
1900 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
1903 if (!spec
->adc_nids
&& spec
->input_mux
) {
1904 spec
->adc_nids
= vt1709_adc_nids
;
1905 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
1906 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
1910 codec
->patch_ops
= via_patch_ops
;
1912 codec
->patch_ops
.init
= via_auto_init
;
1913 codec
->patch_ops
.unsol_event
= via_unsol_event
;
1914 #ifdef CONFIG_SND_HDA_POWER_SAVE
1915 spec
->loopback
.amplist
= vt1709_loopbacks
;
1921 * generic initialization of ADC, input mixers and output mixers
1923 static struct hda_verb vt1709_6ch_volume_init_verbs
[] = {
1925 * Unmute ADC0-2 and set the default input to mic-in
1927 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1928 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1929 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1932 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1935 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1936 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1937 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1938 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1939 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1940 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1943 * Set up output selector (0x1a, 0x1b, 0x29)
1945 /* set vol=0 to output mixers */
1946 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1947 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1948 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1951 * Unmute PW3 and PW4
1953 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1954 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1956 /* Set input of PW4 as MW0 */
1957 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
1958 /* PW9 Output enable */
1959 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1963 static int patch_vt1709_6ch(struct hda_codec
*codec
)
1965 struct via_spec
*spec
;
1968 /* create a codec specific record */
1969 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1975 err
= vt1709_parse_auto_config(codec
);
1980 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
1981 "Using genenic mode...\n");
1984 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_6ch_volume_init_verbs
;
1985 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
1987 spec
->stream_name_analog
= "VT1709 Analog";
1988 spec
->stream_analog_playback
= &vt1709_6ch_pcm_analog_playback
;
1989 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
1991 spec
->stream_name_digital
= "VT1709 Digital";
1992 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
1993 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
1996 if (!spec
->adc_nids
&& spec
->input_mux
) {
1997 spec
->adc_nids
= vt1709_adc_nids
;
1998 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
1999 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
2003 codec
->patch_ops
= via_patch_ops
;
2005 codec
->patch_ops
.init
= via_auto_init
;
2006 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2007 #ifdef CONFIG_SND_HDA_POWER_SAVE
2008 spec
->loopback
.amplist
= vt1709_loopbacks
;
2013 /* capture mixer elements */
2014 static struct snd_kcontrol_new vt1708B_capture_mixer
[] = {
2015 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
2016 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
2017 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
2018 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
2020 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2021 /* The multiple "Capture Source" controls confuse alsamixer
2022 * So call somewhat different..
2024 /* .name = "Capture Source", */
2025 .name
= "Input Source",
2027 .info
= via_mux_enum_info
,
2028 .get
= via_mux_enum_get
,
2029 .put
= via_mux_enum_put
,
2034 * generic initialization of ADC, input mixers and output mixers
2036 static struct hda_verb vt1708B_8ch_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 to PW4 */
2063 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x1},
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_4ch_volume_init_verbs
[] = {
2073 * Unmute ADC0-1 and set the default input to mic-in
2075 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2076 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2079 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2082 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2083 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2084 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2085 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2086 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2087 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2090 * Set up output mixers
2092 /* set vol=0 to output mixers */
2093 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2094 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2095 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2097 /* Setup default input of PW4 to MW0 */
2098 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2099 /* PW9 Output enable */
2100 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2101 /* PW10 Input enable */
2102 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2106 static struct hda_verb vt1708B_uniwill_init_verbs
[] = {
2107 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2111 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback
= {
2115 .nid
= 0x10, /* NID to query formats and rates */
2117 .open
= via_playback_pcm_open
,
2118 .prepare
= via_playback_multi_pcm_prepare
,
2119 .cleanup
= via_playback_multi_pcm_cleanup
2123 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback
= {
2127 .nid
= 0x10, /* NID to query formats and rates */
2129 .open
= via_playback_pcm_open
,
2130 .prepare
= via_playback_multi_pcm_prepare
,
2131 .cleanup
= via_playback_multi_pcm_cleanup
2135 static struct hda_pcm_stream vt1708B_pcm_analog_capture
= {
2139 .nid
= 0x13, /* NID to query formats and rates */
2141 .prepare
= via_capture_pcm_prepare
,
2142 .cleanup
= via_capture_pcm_cleanup
2146 static struct hda_pcm_stream vt1708B_pcm_digital_playback
= {
2150 /* NID is set in via_build_pcms */
2152 .open
= via_dig_playback_pcm_open
,
2153 .close
= via_dig_playback_pcm_close
,
2154 .prepare
= via_dig_playback_pcm_prepare
2158 static struct hda_pcm_stream vt1708B_pcm_digital_capture
= {
2164 /* fill in the dac_nids table from the parsed pin configuration */
2165 static int vt1708B_auto_fill_dac_nids(struct via_spec
*spec
,
2166 const struct auto_pin_cfg
*cfg
)
2171 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2173 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2175 for (i
= 0; i
< 4; i
++) {
2176 nid
= cfg
->line_out_pins
[i
];
2178 /* config dac list */
2180 case AUTO_SEQ_FRONT
:
2181 spec
->multiout
.dac_nids
[i
] = 0x10;
2183 case AUTO_SEQ_CENLFE
:
2184 spec
->multiout
.dac_nids
[i
] = 0x24;
2186 case AUTO_SEQ_SURROUND
:
2187 spec
->multiout
.dac_nids
[i
] = 0x11;
2190 spec
->multiout
.dac_nids
[i
] = 0x25;
2199 /* add playback controls from the parsed DAC table */
2200 static int vt1708B_auto_create_multi_out_ctls(struct via_spec
*spec
,
2201 const struct auto_pin_cfg
*cfg
)
2204 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2205 hda_nid_t nid_vols
[] = {0x16, 0x18, 0x26, 0x27};
2206 hda_nid_t nid
, nid_vol
= 0;
2209 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2210 nid
= cfg
->line_out_pins
[i
];
2215 nid_vol
= nid_vols
[i
];
2217 if (i
== AUTO_SEQ_CENLFE
) {
2219 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2220 "Center Playback Volume",
2221 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2225 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2226 "LFE Playback Volume",
2227 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2231 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2232 "Center Playback Switch",
2233 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2237 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2238 "LFE Playback Switch",
2239 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2243 } else if (i
== AUTO_SEQ_FRONT
) {
2244 /* add control to mixer index 0 */
2245 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2246 "Master Front Playback Volume",
2247 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2251 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2252 "Master Front Playback Switch",
2253 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2258 /* add control to PW3 */
2259 sprintf(name
, "%s Playback Volume", chname
[i
]);
2260 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2261 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2265 sprintf(name
, "%s Playback Switch", chname
[i
]);
2266 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2267 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2272 sprintf(name
, "%s Playback Volume", chname
[i
]);
2273 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2274 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2278 sprintf(name
, "%s Playback Switch", chname
[i
]);
2279 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2280 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2290 static int vt1708B_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2297 spec
->multiout
.hp_nid
= VT1708B_HP_NID
; /* AOW3 */
2299 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2300 "Headphone Playback Volume",
2301 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2304 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2305 "Headphone Playback Switch",
2306 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2310 create_hp_imux(spec
);
2315 /* create playback/capture controls for input pins */
2316 static int vt1708B_auto_create_analog_input_ctls(struct via_spec
*spec
,
2317 const struct auto_pin_cfg
*cfg
)
2319 static char *labels
[] = {
2320 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2322 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2323 int i
, err
, idx
= 0;
2325 /* for internal loopback recording select */
2326 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2327 imux
->items
[imux
->num_items
].index
= idx
;
2330 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2331 if (!cfg
->input_pins
[i
])
2334 switch (cfg
->input_pins
[i
]) {
2335 case 0x1a: /* Mic */
2339 case 0x1b: /* Line In */
2343 case 0x1e: /* Front Mic */
2351 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
2355 imux
->items
[imux
->num_items
].label
= labels
[i
];
2356 imux
->items
[imux
->num_items
].index
= idx
;
2362 static int vt1708B_parse_auto_config(struct hda_codec
*codec
)
2364 struct via_spec
*spec
= codec
->spec
;
2367 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2370 err
= vt1708B_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2373 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2374 return 0; /* can't find valid BIOS pin config */
2376 err
= vt1708B_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2379 err
= vt1708B_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2382 err
= vt1708B_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2386 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2388 if (spec
->autocfg
.dig_out_pin
)
2389 spec
->multiout
.dig_out_nid
= VT1708B_DIGOUT_NID
;
2390 if (spec
->autocfg
.dig_in_pin
)
2391 spec
->dig_in_nid
= VT1708B_DIGIN_NID
;
2393 if (spec
->kctl_alloc
)
2394 spec
->mixers
[spec
->num_mixers
++] = spec
->kctl_alloc
;
2396 spec
->input_mux
= &spec
->private_imux
[0];
2399 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2404 #ifdef CONFIG_SND_HDA_POWER_SAVE
2405 static struct hda_amp_list vt1708B_loopbacks
[] = {
2406 { 0x16, HDA_INPUT
, 1 },
2407 { 0x16, HDA_INPUT
, 2 },
2408 { 0x16, HDA_INPUT
, 3 },
2409 { 0x16, HDA_INPUT
, 4 },
2414 static int patch_vt1708B_8ch(struct hda_codec
*codec
)
2416 struct via_spec
*spec
;
2419 /* create a codec specific record */
2420 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2426 /* automatic parse from the BIOS config */
2427 err
= vt1708B_parse_auto_config(codec
);
2432 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2433 "from BIOS. Using genenic mode...\n");
2436 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_8ch_volume_init_verbs
;
2437 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2439 spec
->stream_name_analog
= "VT1708B Analog";
2440 spec
->stream_analog_playback
= &vt1708B_8ch_pcm_analog_playback
;
2441 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2443 spec
->stream_name_digital
= "VT1708B Digital";
2444 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2445 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2447 if (!spec
->adc_nids
&& spec
->input_mux
) {
2448 spec
->adc_nids
= vt1708B_adc_nids
;
2449 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2450 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2454 codec
->patch_ops
= via_patch_ops
;
2456 codec
->patch_ops
.init
= via_auto_init
;
2457 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2458 #ifdef CONFIG_SND_HDA_POWER_SAVE
2459 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2465 static int patch_vt1708B_4ch(struct hda_codec
*codec
)
2467 struct via_spec
*spec
;
2470 /* create a codec specific record */
2471 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2477 /* automatic parse from the BIOS config */
2478 err
= vt1708B_parse_auto_config(codec
);
2483 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2484 "from BIOS. Using genenic mode...\n");
2487 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_4ch_volume_init_verbs
;
2488 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2490 spec
->stream_name_analog
= "VT1708B Analog";
2491 spec
->stream_analog_playback
= &vt1708B_4ch_pcm_analog_playback
;
2492 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2494 spec
->stream_name_digital
= "VT1708B Digital";
2495 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2496 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2498 if (!spec
->adc_nids
&& spec
->input_mux
) {
2499 spec
->adc_nids
= vt1708B_adc_nids
;
2500 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2501 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2505 codec
->patch_ops
= via_patch_ops
;
2507 codec
->patch_ops
.init
= via_auto_init
;
2508 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2509 #ifdef CONFIG_SND_HDA_POWER_SAVE
2510 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2516 /* Patch for VT1708S */
2518 /* VT1708S software backdoor based override for buggy hardware micboost
2520 #define MIC_BOOST_VOLUME(xname, nid) { \
2521 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2524 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2525 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2526 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2527 .info = mic_boost_volume_info, \
2528 .get = snd_hda_mixer_amp_volume_get, \
2529 .put = snd_hda_mixer_amp_volume_put, \
2530 .tlv = { .c = mic_boost_tlv }, \
2531 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2533 /* capture mixer elements */
2534 static struct snd_kcontrol_new vt1708S_capture_mixer
[] = {
2535 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
2536 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
2537 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
2538 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
2539 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2540 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2542 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2543 /* The multiple "Capture Source" controls confuse alsamixer
2544 * So call somewhat different..
2546 /* .name = "Capture Source", */
2547 .name
= "Input Source",
2549 .info
= via_mux_enum_info
,
2550 .get
= via_mux_enum_get
,
2551 .put
= via_mux_enum_put
,
2556 static struct hda_verb vt1708S_volume_init_verbs
[] = {
2557 /* Unmute ADC0-1 and set the default input to mic-in */
2558 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2559 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2561 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2562 * analog-loopback mixer widget */
2563 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2564 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2565 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2566 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2567 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2568 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2570 /* Setup default input of PW4 to MW0 */
2571 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2572 /* PW9, PW10 Output enable */
2573 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2574 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2575 /* Enable Mic Boost Volume backdoor */
2580 static struct hda_verb vt1708S_uniwill_init_verbs
[] = {
2581 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2585 static struct hda_pcm_stream vt1708S_pcm_analog_playback
= {
2589 .nid
= 0x10, /* NID to query formats and rates */
2591 .open
= via_playback_pcm_open
,
2592 .prepare
= via_playback_pcm_prepare
,
2593 .cleanup
= via_playback_pcm_cleanup
2597 static struct hda_pcm_stream vt1708S_pcm_analog_capture
= {
2601 .nid
= 0x13, /* NID to query formats and rates */
2603 .prepare
= via_capture_pcm_prepare
,
2604 .cleanup
= via_capture_pcm_cleanup
2608 static struct hda_pcm_stream vt1708S_pcm_digital_playback
= {
2612 /* NID is set in via_build_pcms */
2614 .open
= via_dig_playback_pcm_open
,
2615 .close
= via_dig_playback_pcm_close
,
2616 .prepare
= via_dig_playback_pcm_prepare
2620 /* fill in the dac_nids table from the parsed pin configuration */
2621 static int vt1708S_auto_fill_dac_nids(struct via_spec
*spec
,
2622 const struct auto_pin_cfg
*cfg
)
2627 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2629 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2631 for (i
= 0; i
< 4; i
++) {
2632 nid
= cfg
->line_out_pins
[i
];
2634 /* config dac list */
2636 case AUTO_SEQ_FRONT
:
2637 spec
->multiout
.dac_nids
[i
] = 0x10;
2639 case AUTO_SEQ_CENLFE
:
2640 spec
->multiout
.dac_nids
[i
] = 0x24;
2642 case AUTO_SEQ_SURROUND
:
2643 spec
->multiout
.dac_nids
[i
] = 0x11;
2646 spec
->multiout
.dac_nids
[i
] = 0x25;
2655 /* add playback controls from the parsed DAC table */
2656 static int vt1708S_auto_create_multi_out_ctls(struct via_spec
*spec
,
2657 const struct auto_pin_cfg
*cfg
)
2660 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2661 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x24, 0x25};
2662 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x26, 0x27};
2663 hda_nid_t nid
, nid_vol
, nid_mute
;
2666 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2667 nid
= cfg
->line_out_pins
[i
];
2672 nid_vol
= nid_vols
[i
];
2673 nid_mute
= nid_mutes
[i
];
2675 if (i
== AUTO_SEQ_CENLFE
) {
2677 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2678 "Center Playback Volume",
2679 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2683 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2684 "LFE Playback Volume",
2685 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2689 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2690 "Center Playback Switch",
2691 HDA_COMPOSE_AMP_VAL(nid_mute
,
2696 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2697 "LFE Playback Switch",
2698 HDA_COMPOSE_AMP_VAL(nid_mute
,
2703 } else if (i
== AUTO_SEQ_FRONT
) {
2704 /* add control to mixer index 0 */
2705 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2706 "Master Front Playback Volume",
2707 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2711 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2712 "Master Front Playback Switch",
2713 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2719 sprintf(name
, "%s Playback Volume", chname
[i
]);
2720 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2721 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2725 sprintf(name
, "%s Playback Switch", chname
[i
]);
2726 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2727 HDA_COMPOSE_AMP_VAL(nid_mute
,
2733 sprintf(name
, "%s Playback Volume", chname
[i
]);
2734 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2735 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2739 sprintf(name
, "%s Playback Switch", chname
[i
]);
2740 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2741 HDA_COMPOSE_AMP_VAL(nid_mute
,
2752 static int vt1708S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2759 spec
->multiout
.hp_nid
= VT1708S_HP_NID
; /* AOW3 */
2761 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2762 "Headphone Playback Volume",
2763 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
2767 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2768 "Headphone Playback Switch",
2769 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2773 create_hp_imux(spec
);
2778 /* create playback/capture controls for input pins */
2779 static int vt1708S_auto_create_analog_input_ctls(struct via_spec
*spec
,
2780 const struct auto_pin_cfg
*cfg
)
2782 static char *labels
[] = {
2783 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2785 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2786 int i
, err
, idx
= 0;
2788 /* for internal loopback recording select */
2789 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2790 imux
->items
[imux
->num_items
].index
= 5;
2793 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2794 if (!cfg
->input_pins
[i
])
2797 switch (cfg
->input_pins
[i
]) {
2798 case 0x1a: /* Mic */
2802 case 0x1b: /* Line In */
2806 case 0x1e: /* Front Mic */
2814 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
], labels
[i
],
2818 imux
->items
[imux
->num_items
].label
= labels
[i
];
2819 imux
->items
[imux
->num_items
].index
= idx
-1;
2825 static int vt1708S_parse_auto_config(struct hda_codec
*codec
)
2827 struct via_spec
*spec
= codec
->spec
;
2829 static hda_nid_t vt1708s_ignore
[] = {0x21, 0};
2831 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
,
2835 err
= vt1708S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2838 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2839 return 0; /* can't find valid BIOS pin config */
2841 err
= vt1708S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2844 err
= vt1708S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2847 err
= vt1708S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2851 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2853 if (spec
->autocfg
.dig_out_pin
)
2854 spec
->multiout
.dig_out_nid
= VT1708S_DIGOUT_NID
;
2856 spec
->extra_dig_out_nid
= 0x15;
2858 if (spec
->kctl_alloc
)
2859 spec
->mixers
[spec
->num_mixers
++] = spec
->kctl_alloc
;
2861 spec
->input_mux
= &spec
->private_imux
[0];
2864 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2869 #ifdef CONFIG_SND_HDA_POWER_SAVE
2870 static struct hda_amp_list vt1708S_loopbacks
[] = {
2871 { 0x16, HDA_INPUT
, 1 },
2872 { 0x16, HDA_INPUT
, 2 },
2873 { 0x16, HDA_INPUT
, 3 },
2874 { 0x16, HDA_INPUT
, 4 },
2879 static int patch_vt1708S(struct hda_codec
*codec
)
2881 struct via_spec
*spec
;
2884 /* create a codec specific record */
2885 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2891 /* automatic parse from the BIOS config */
2892 err
= vt1708S_parse_auto_config(codec
);
2897 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2898 "from BIOS. Using genenic mode...\n");
2901 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_volume_init_verbs
;
2902 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_uniwill_init_verbs
;
2904 spec
->stream_name_analog
= "VT1708S Analog";
2905 spec
->stream_analog_playback
= &vt1708S_pcm_analog_playback
;
2906 spec
->stream_analog_capture
= &vt1708S_pcm_analog_capture
;
2908 spec
->stream_name_digital
= "VT1708S Digital";
2909 spec
->stream_digital_playback
= &vt1708S_pcm_digital_playback
;
2911 if (!spec
->adc_nids
&& spec
->input_mux
) {
2912 spec
->adc_nids
= vt1708S_adc_nids
;
2913 spec
->num_adc_nids
= ARRAY_SIZE(vt1708S_adc_nids
);
2914 spec
->mixers
[spec
->num_mixers
] = vt1708S_capture_mixer
;
2918 codec
->patch_ops
= via_patch_ops
;
2920 codec
->patch_ops
.init
= via_auto_init
;
2921 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2922 #ifdef CONFIG_SND_HDA_POWER_SAVE
2923 spec
->loopback
.amplist
= vt1708S_loopbacks
;
2929 /* Patch for VT1702 */
2931 /* capture mixer elements */
2932 static struct snd_kcontrol_new vt1702_capture_mixer
[] = {
2933 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT
),
2934 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT
),
2935 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT
),
2936 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT
),
2937 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT
),
2938 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT
),
2939 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2942 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2943 /* The multiple "Capture Source" controls confuse alsamixer
2944 * So call somewhat different..
2946 /* .name = "Capture Source", */
2947 .name
= "Input Source",
2949 .info
= via_mux_enum_info
,
2950 .get
= via_mux_enum_get
,
2951 .put
= via_mux_enum_put
,
2956 static struct hda_verb vt1702_volume_init_verbs
[] = {
2958 * Unmute ADC0-1 and set the default input to mic-in
2960 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2961 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2962 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2965 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2968 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2969 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2970 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2971 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2972 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2973 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
2975 /* Setup default input of PW4 to MW0 */
2976 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x1},
2977 /* PW6 PW7 Output enable */
2978 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2979 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2983 static struct hda_verb vt1702_uniwill_init_verbs
[] = {
2984 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_GPIO_EVENT
},
2985 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2989 static struct hda_pcm_stream vt1702_pcm_analog_playback
= {
2993 .nid
= 0x10, /* NID to query formats and rates */
2995 .open
= via_playback_pcm_open
,
2996 .prepare
= via_playback_multi_pcm_prepare
,
2997 .cleanup
= via_playback_multi_pcm_cleanup
3001 static struct hda_pcm_stream vt1702_pcm_analog_capture
= {
3005 .nid
= 0x12, /* NID to query formats and rates */
3007 .prepare
= via_capture_pcm_prepare
,
3008 .cleanup
= via_capture_pcm_cleanup
3012 static struct hda_pcm_stream vt1702_pcm_digital_playback
= {
3016 /* NID is set in via_build_pcms */
3018 .open
= via_dig_playback_pcm_open
,
3019 .close
= via_dig_playback_pcm_close
,
3020 .prepare
= via_dig_playback_pcm_prepare
3024 /* fill in the dac_nids table from the parsed pin configuration */
3025 static int vt1702_auto_fill_dac_nids(struct via_spec
*spec
,
3026 const struct auto_pin_cfg
*cfg
)
3028 spec
->multiout
.num_dacs
= 1;
3029 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3031 if (cfg
->line_out_pins
[0]) {
3032 /* config dac list */
3033 spec
->multiout
.dac_nids
[0] = 0x10;
3039 /* add playback controls from the parsed DAC table */
3040 static int vt1702_auto_create_line_out_ctls(struct via_spec
*spec
,
3041 const struct auto_pin_cfg
*cfg
)
3045 if (!cfg
->line_out_pins
[0])
3048 /* add control to mixer index 0 */
3049 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3050 "Master Front Playback Volume",
3051 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3054 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3055 "Master Front Playback Switch",
3056 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3061 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3062 "Front Playback Volume",
3063 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
));
3066 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3067 "Front Playback Switch",
3068 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT
));
3075 static int vt1702_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3082 spec
->multiout
.hp_nid
= 0x1D;
3084 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3085 "Headphone Playback Volume",
3086 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT
));
3090 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3091 "Headphone Playback Switch",
3092 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3096 create_hp_imux(spec
);
3101 /* create playback/capture controls for input pins */
3102 static int vt1702_auto_create_analog_input_ctls(struct via_spec
*spec
,
3103 const struct auto_pin_cfg
*cfg
)
3105 static char *labels
[] = {
3106 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3108 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3109 int i
, err
, idx
= 0;
3111 /* for internal loopback recording select */
3112 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3113 imux
->items
[imux
->num_items
].index
= 3;
3116 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3117 if (!cfg
->input_pins
[i
])
3120 switch (cfg
->input_pins
[i
]) {
3121 case 0x14: /* Mic */
3125 case 0x15: /* Line In */
3129 case 0x18: /* Front Mic */
3133 err
= via_new_analog_input(spec
, cfg
->input_pins
[i
],
3134 labels
[i
], idx
, 0x1A);
3137 imux
->items
[imux
->num_items
].label
= labels
[i
];
3138 imux
->items
[imux
->num_items
].index
= idx
-1;
3144 static int vt1702_parse_auto_config(struct hda_codec
*codec
)
3146 struct via_spec
*spec
= codec
->spec
;
3148 static hda_nid_t vt1702_ignore
[] = {0x1C, 0};
3150 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
,
3154 err
= vt1702_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3157 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3158 return 0; /* can't find valid BIOS pin config */
3160 err
= vt1702_auto_create_line_out_ctls(spec
, &spec
->autocfg
);
3163 err
= vt1702_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3166 err
= vt1702_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3170 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3172 if (spec
->autocfg
.dig_out_pin
)
3173 spec
->multiout
.dig_out_nid
= VT1702_DIGOUT_NID
;
3175 spec
->extra_dig_out_nid
= 0x1B;
3177 if (spec
->kctl_alloc
)
3178 spec
->mixers
[spec
->num_mixers
++] = spec
->kctl_alloc
;
3180 spec
->input_mux
= &spec
->private_imux
[0];
3183 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3188 #ifdef CONFIG_SND_HDA_POWER_SAVE
3189 static struct hda_amp_list vt1702_loopbacks
[] = {
3190 { 0x1A, HDA_INPUT
, 1 },
3191 { 0x1A, HDA_INPUT
, 2 },
3192 { 0x1A, HDA_INPUT
, 3 },
3193 { 0x1A, HDA_INPUT
, 4 },
3198 static int patch_vt1702(struct hda_codec
*codec
)
3200 struct via_spec
*spec
;
3202 unsigned int response
;
3203 unsigned char control
;
3205 /* create a codec specific record */
3206 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3212 /* automatic parse from the BIOS config */
3213 err
= vt1702_parse_auto_config(codec
);
3218 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3219 "from BIOS. Using genenic mode...\n");
3222 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_volume_init_verbs
;
3223 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_uniwill_init_verbs
;
3225 spec
->stream_name_analog
= "VT1702 Analog";
3226 spec
->stream_analog_playback
= &vt1702_pcm_analog_playback
;
3227 spec
->stream_analog_capture
= &vt1702_pcm_analog_capture
;
3229 spec
->stream_name_digital
= "VT1702 Digital";
3230 spec
->stream_digital_playback
= &vt1702_pcm_digital_playback
;
3232 if (!spec
->adc_nids
&& spec
->input_mux
) {
3233 spec
->adc_nids
= vt1702_adc_nids
;
3234 spec
->num_adc_nids
= ARRAY_SIZE(vt1702_adc_nids
);
3235 spec
->mixers
[spec
->num_mixers
] = vt1702_capture_mixer
;
3239 codec
->patch_ops
= via_patch_ops
;
3241 codec
->patch_ops
.init
= via_auto_init
;
3242 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3243 #ifdef CONFIG_SND_HDA_POWER_SAVE
3244 spec
->loopback
.amplist
= vt1702_loopbacks
;
3248 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF8C, 0);
3249 control
= (unsigned char)(response
& 0xff);
3251 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF88, control
);
3253 /* Enable GPIO 0&1 for volume&mute control */
3254 /* Enable GPIO 2 for DMIC-DATA */
3255 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF84, 0);
3256 control
= (unsigned char)((response
>> 16) & 0x3f);
3257 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF82, control
);
3265 struct hda_codec_preset snd_hda_preset_via
[] = {
3266 { .id
= 0x11061708, .name
= "VIA VT1708", .patch
= patch_vt1708
},
3267 { .id
= 0x11061709, .name
= "VIA VT1708", .patch
= patch_vt1708
},
3268 { .id
= 0x1106170A, .name
= "VIA VT1708", .patch
= patch_vt1708
},
3269 { .id
= 0x1106170B, .name
= "VIA VT1708", .patch
= patch_vt1708
},
3270 { .id
= 0x1106E710, .name
= "VIA VT1709 10-Ch",
3271 .patch
= patch_vt1709_10ch
},
3272 { .id
= 0x1106E711, .name
= "VIA VT1709 10-Ch",
3273 .patch
= patch_vt1709_10ch
},
3274 { .id
= 0x1106E712, .name
= "VIA VT1709 10-Ch",
3275 .patch
= patch_vt1709_10ch
},
3276 { .id
= 0x1106E713, .name
= "VIA VT1709 10-Ch",
3277 .patch
= patch_vt1709_10ch
},
3278 { .id
= 0x1106E714, .name
= "VIA VT1709 6-Ch",
3279 .patch
= patch_vt1709_6ch
},
3280 { .id
= 0x1106E715, .name
= "VIA VT1709 6-Ch",
3281 .patch
= patch_vt1709_6ch
},
3282 { .id
= 0x1106E716, .name
= "VIA VT1709 6-Ch",
3283 .patch
= patch_vt1709_6ch
},
3284 { .id
= 0x1106E717, .name
= "VIA VT1709 6-Ch",
3285 .patch
= patch_vt1709_6ch
},
3286 { .id
= 0x1106E720, .name
= "VIA VT1708B 8-Ch",
3287 .patch
= patch_vt1708B_8ch
},
3288 { .id
= 0x1106E721, .name
= "VIA VT1708B 8-Ch",
3289 .patch
= patch_vt1708B_8ch
},
3290 { .id
= 0x1106E722, .name
= "VIA VT1708B 8-Ch",
3291 .patch
= patch_vt1708B_8ch
},
3292 { .id
= 0x1106E723, .name
= "VIA VT1708B 8-Ch",
3293 .patch
= patch_vt1708B_8ch
},
3294 { .id
= 0x1106E724, .name
= "VIA VT1708B 4-Ch",
3295 .patch
= patch_vt1708B_4ch
},
3296 { .id
= 0x1106E725, .name
= "VIA VT1708B 4-Ch",
3297 .patch
= patch_vt1708B_4ch
},
3298 { .id
= 0x1106E726, .name
= "VIA VT1708B 4-Ch",
3299 .patch
= patch_vt1708B_4ch
},
3300 { .id
= 0x1106E727, .name
= "VIA VT1708B 4-Ch",
3301 .patch
= patch_vt1708B_4ch
},
3302 { .id
= 0x11060397, .name
= "VIA VT1708S",
3303 .patch
= patch_vt1708S
},
3304 { .id
= 0x11061397, .name
= "VIA VT1708S",
3305 .patch
= patch_vt1708S
},
3306 { .id
= 0x11062397, .name
= "VIA VT1708S",
3307 .patch
= patch_vt1708S
},
3308 { .id
= 0x11063397, .name
= "VIA VT1708S",
3309 .patch
= patch_vt1708S
},
3310 { .id
= 0x11064397, .name
= "VIA VT1708S",
3311 .patch
= patch_vt1708S
},
3312 { .id
= 0x11065397, .name
= "VIA VT1708S",
3313 .patch
= patch_vt1708S
},
3314 { .id
= 0x11066397, .name
= "VIA VT1708S",
3315 .patch
= patch_vt1708S
},
3316 { .id
= 0x11067397, .name
= "VIA VT1708S",
3317 .patch
= patch_vt1708S
},
3318 { .id
= 0x11060398, .name
= "VIA VT1702",
3319 .patch
= patch_vt1702
},
3320 { .id
= 0x11061398, .name
= "VIA VT1702",
3321 .patch
= patch_vt1702
},
3322 { .id
= 0x11062398, .name
= "VIA VT1702",
3323 .patch
= patch_vt1702
},
3324 { .id
= 0x11063398, .name
= "VIA VT1702",
3325 .patch
= patch_vt1702
},
3326 { .id
= 0x11064398, .name
= "VIA VT1702",
3327 .patch
= patch_vt1702
},
3328 { .id
= 0x11065398, .name
= "VIA VT1702",
3329 .patch
= patch_vt1702
},
3330 { .id
= 0x11066398, .name
= "VIA VT1702",
3331 .patch
= patch_vt1702
},
3332 { .id
= 0x11067398, .name
= "VIA VT1702",
3333 .patch
= patch_vt1702
},