2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec
6 * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com>
7 * Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
40 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 #include <linux/init.h>
44 #include <linux/delay.h>
45 #include <linux/slab.h>
46 #include <sound/core.h>
47 #include <sound/asoundef.h>
48 #include "hda_codec.h"
49 #include "hda_local.h"
52 #define AMP_VAL_IDX_SHIFT 19
53 #define AMP_VAL_IDX_MASK (0x0f<<19)
56 #define VT1708_HP_NID 0x13
57 #define VT1708_DIGOUT_NID 0x14
58 #define VT1708_DIGIN_NID 0x16
59 #define VT1708_DIGIN_PIN 0x26
60 #define VT1708_HP_PIN_NID 0x20
61 #define VT1708_CD_PIN_NID 0x24
63 #define VT1709_HP_DAC_NID 0x28
64 #define VT1709_DIGOUT_NID 0x13
65 #define VT1709_DIGIN_NID 0x17
66 #define VT1709_DIGIN_PIN 0x25
68 #define VT1708B_HP_NID 0x25
69 #define VT1708B_DIGOUT_NID 0x12
70 #define VT1708B_DIGIN_NID 0x15
71 #define VT1708B_DIGIN_PIN 0x21
73 #define VT1708S_HP_NID 0x25
74 #define VT1708S_DIGOUT_NID 0x12
76 #define VT1702_HP_NID 0x17
77 #define VT1702_DIGOUT_NID 0x11
92 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
)
94 u32 vendor_id
= codec
->vendor_id
;
95 u16 ven_id
= vendor_id
>> 16;
96 u16 dev_id
= vendor_id
& 0xffff;
97 enum VIA_HDA_CODEC codec_type
;
100 if (ven_id
!= 0x1106)
101 codec_type
= UNKNOWN
;
102 else if (dev_id
>= 0x1708 && dev_id
<= 0x170b)
104 else if (dev_id
>= 0xe710 && dev_id
<= 0xe713)
105 codec_type
= VT1709_10CH
;
106 else if (dev_id
>= 0xe714 && dev_id
<= 0xe717)
107 codec_type
= VT1709_6CH
;
108 else if (dev_id
>= 0xe720 && dev_id
<= 0xe723) {
109 codec_type
= VT1708B_8CH
;
110 if (snd_hda_param_read(codec
, 0x16, AC_PAR_CONNLIST_LEN
) == 0x7)
111 codec_type
= VT1708BCE
;
112 } else if (dev_id
>= 0xe724 && dev_id
<= 0xe727)
113 codec_type
= VT1708B_4CH
;
114 else if ((dev_id
& 0xfff) == 0x397
115 && (dev_id
>> 12) < 8)
116 codec_type
= VT1708S
;
117 else if ((dev_id
& 0xfff) == 0x398
118 && (dev_id
>> 12) < 8)
121 codec_type
= UNKNOWN
;
125 #define VIA_HP_EVENT 0x01
126 #define VIA_GPIO_EVENT 0x02
131 VIA_CTL_WIDGET_ANALOG_MUTE
,
141 /* Some VT1708S based boards gets the micboost setting wrong, so we have
142 * to apply some brute-force and re-write the TLV's by software. */
143 static int mic_boost_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
144 unsigned int size
, unsigned int __user
*_tlv
)
146 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
147 hda_nid_t nid
= get_amp_nid(kcontrol
);
149 if (get_codec_type(codec
) == VT1708S
150 && (nid
== 0x1a || nid
== 0x1e)) {
151 if (size
< 4 * sizeof(unsigned int))
153 if (put_user(1, _tlv
)) /* SNDRV_CTL_TLVT_DB_SCALE */
155 if (put_user(2 * sizeof(unsigned int), _tlv
+ 1))
157 if (put_user(0, _tlv
+ 2)) /* offset = 0 */
159 if (put_user(1000, _tlv
+ 3)) /* step size = 10 dB */
165 static int mic_boost_volume_info(struct snd_kcontrol
*kcontrol
,
166 struct snd_ctl_elem_info
*uinfo
)
168 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
169 hda_nid_t nid
= get_amp_nid(kcontrol
);
171 if (get_codec_type(codec
) == VT1708S
172 && (nid
== 0x1a || nid
== 0x1e)) {
173 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
175 uinfo
->value
.integer
.min
= 0;
176 uinfo
->value
.integer
.max
= 3;
181 static void analog_low_current_mode(struct hda_codec
*codec
, int stream_idle
);
182 static void set_jack_power_state(struct hda_codec
*codec
);
184 static int analog_input_switch_put(struct snd_kcontrol
*kcontrol
,
185 struct snd_ctl_elem_value
*ucontrol
)
187 int change
= snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
188 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
190 set_jack_power_state(codec
);
191 analog_low_current_mode(snd_kcontrol_chip(kcontrol
), -1);
195 /* modify .put = snd_hda_mixer_amp_switch_put */
196 #define ANALOG_INPUT_MUTE \
197 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
200 .info = snd_hda_mixer_amp_switch_info, \
201 .get = snd_hda_mixer_amp_switch_get, \
202 .put = analog_input_switch_put, \
203 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
205 static struct snd_kcontrol_new vt1708_control_templates
[] = {
206 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
207 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
213 /* codec parameterization */
214 struct snd_kcontrol_new
*mixers
[4];
215 unsigned int num_mixers
;
217 struct hda_verb
*init_verbs
[5];
218 unsigned int num_iverbs
;
220 char *stream_name_analog
;
221 struct hda_pcm_stream
*stream_analog_playback
;
222 struct hda_pcm_stream
*stream_analog_capture
;
224 char *stream_name_digital
;
225 struct hda_pcm_stream
*stream_digital_playback
;
226 struct hda_pcm_stream
*stream_digital_capture
;
229 struct hda_multi_out multiout
;
230 hda_nid_t slave_dig_outs
[2];
233 unsigned int num_adc_nids
;
235 hda_nid_t mux_nids
[3];
236 hda_nid_t dig_in_nid
;
237 hda_nid_t dig_in_pin
;
240 const struct hda_input_mux
*input_mux
;
241 unsigned int cur_mux
[3];
243 /* PCM information */
244 struct hda_pcm pcm_rec
[3];
246 /* dynamic controls, init_verbs and input_mux */
247 struct auto_pin_cfg autocfg
;
248 struct snd_array kctls
;
249 struct hda_input_mux private_imux
[2];
250 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
253 const struct hda_input_mux
*hp_mux
;
254 unsigned int hp_independent_mode
;
255 unsigned int hp_independent_mode_index
;
256 unsigned int smart51_enabled
;
258 enum VIA_HDA_CODEC codec_type
;
260 #ifdef CONFIG_SND_HDA_POWER_SAVE
261 struct hda_loopback_check loopback
;
265 static hda_nid_t vt1708_adc_nids
[2] = {
270 static hda_nid_t vt1709_adc_nids
[3] = {
275 static hda_nid_t vt1708B_adc_nids
[2] = {
280 static hda_nid_t vt1708S_adc_nids
[2] = {
285 static hda_nid_t vt1702_adc_nids
[3] = {
290 /* add dynamic controls */
291 static int via_add_control(struct via_spec
*spec
, int type
, const char *name
,
294 struct snd_kcontrol_new
*knew
;
296 snd_array_init(&spec
->kctls
, sizeof(*knew
), 32);
297 knew
= snd_array_new(&spec
->kctls
);
300 *knew
= vt1708_control_templates
[type
];
301 knew
->name
= kstrdup(name
, GFP_KERNEL
);
304 knew
->private_value
= val
;
308 static void via_free_kctls(struct hda_codec
*codec
)
310 struct via_spec
*spec
= codec
->spec
;
312 if (spec
->kctls
.list
) {
313 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
315 for (i
= 0; i
< spec
->kctls
.used
; i
++)
318 snd_array_free(&spec
->kctls
);
321 /* create input playback/capture controls for the given pin */
322 static int via_new_analog_input(struct via_spec
*spec
, const char *ctlname
,
323 int idx
, int mix_nid
)
328 sprintf(name
, "%s Playback Volume", ctlname
);
329 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
330 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
333 sprintf(name
, "%s Playback Switch", ctlname
);
334 err
= via_add_control(spec
, VIA_CTL_WIDGET_ANALOG_MUTE
, name
,
335 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
341 static void via_auto_set_output_and_unmute(struct hda_codec
*codec
,
342 hda_nid_t nid
, int pin_type
,
346 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
348 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
350 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
351 snd_hda_codec_write(codec
, nid
, 0,
352 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
356 static void via_auto_init_multi_out(struct hda_codec
*codec
)
358 struct via_spec
*spec
= codec
->spec
;
361 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
362 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
364 via_auto_set_output_and_unmute(codec
, nid
, PIN_OUT
, i
);
368 static void via_auto_init_hp_out(struct hda_codec
*codec
)
370 struct via_spec
*spec
= codec
->spec
;
373 pin
= spec
->autocfg
.hp_pins
[0];
374 if (pin
) /* connect to front */
375 via_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, 0);
378 static void via_auto_init_analog_input(struct hda_codec
*codec
)
380 struct via_spec
*spec
= codec
->spec
;
383 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
384 hda_nid_t nid
= spec
->autocfg
.input_pins
[i
];
386 snd_hda_codec_write(codec
, nid
, 0,
387 AC_VERB_SET_PIN_WIDGET_CONTROL
,
388 (i
<= AUTO_PIN_FRONT_MIC
?
389 PIN_VREF50
: PIN_IN
));
394 static int is_smart51_pins(struct via_spec
*spec
, hda_nid_t pin
);
396 static void set_pin_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
397 unsigned int *affected_parm
)
400 unsigned def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
401 unsigned no_presence
= (def_conf
& AC_DEFCFG_MISC
)
402 >> AC_DEFCFG_MISC_SHIFT
403 & AC_DEFCFG_MISC_NO_PRESENCE
; /* do not support pin sense */
404 unsigned present
= snd_hda_codec_read(codec
, nid
, 0,
405 AC_VERB_GET_PIN_SENSE
, 0) >> 31;
406 struct via_spec
*spec
= codec
->spec
;
407 if ((spec
->smart51_enabled
&& is_smart51_pins(spec
, nid
))
408 || ((no_presence
|| present
)
409 && get_defcfg_connect(def_conf
) != AC_JACK_PORT_NONE
)) {
410 *affected_parm
= AC_PWRST_D0
; /* if it's connected */
415 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
418 static void set_jack_power_state(struct hda_codec
*codec
)
420 struct via_spec
*spec
= codec
->spec
;
424 if (spec
->codec_type
== VT1702
) {
425 imux_is_smixer
= snd_hda_codec_read(
426 codec
, 0x13, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
428 /* PW 1/2/5 (14h/15h/18h) */
430 set_pin_power_state(codec
, 0x14, &parm
);
431 set_pin_power_state(codec
, 0x15, &parm
);
432 set_pin_power_state(codec
, 0x18, &parm
);
434 parm
= AC_PWRST_D0
; /* SW0 = stereo mixer (idx 3) */
435 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
436 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
438 snd_hda_codec_write(codec
, 0x12, 0, AC_VERB_SET_POWER_STATE
,
440 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
,
442 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_POWER_STATE
,
446 /* PW 3/4 (16h/17h) */
448 set_pin_power_state(codec
, 0x16, &parm
);
449 set_pin_power_state(codec
, 0x17, &parm
);
450 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
451 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_POWER_STATE
,
452 imux_is_smixer
? AC_PWRST_D0
: parm
);
453 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
455 snd_hda_codec_write(codec
, 0x1d, 0, AC_VERB_SET_POWER_STATE
,
457 } else if (spec
->codec_type
== VT1708B_8CH
458 || spec
->codec_type
== VT1708B_4CH
459 || spec
->codec_type
== VT1708S
) {
460 /* SW0 (17h) = stereo mixer */
461 int is_8ch
= spec
->codec_type
!= VT1708B_4CH
;
462 imux_is_smixer
= snd_hda_codec_read(
463 codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00)
464 == ((spec
->codec_type
== VT1708S
) ? 5 : 0);
466 /* PW 1/2/5 (1ah/1bh/1eh) */
468 set_pin_power_state(codec
, 0x1a, &parm
);
469 set_pin_power_state(codec
, 0x1b, &parm
);
470 set_pin_power_state(codec
, 0x1e, &parm
);
473 /* SW0 (17h), AIW 0/1 (13h/14h) */
474 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_POWER_STATE
,
476 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
478 snd_hda_codec_write(codec
, 0x14, 0, AC_VERB_SET_POWER_STATE
,
482 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
484 set_pin_power_state(codec
, 0x19, &parm
);
485 snd_hda_codec_write(codec
, 0x18, 0, AC_VERB_SET_POWER_STATE
,
487 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
,
490 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
493 set_pin_power_state(codec
, 0x22, &parm
);
494 snd_hda_codec_write(codec
, 0x26, 0,
495 AC_VERB_SET_POWER_STATE
, parm
);
496 snd_hda_codec_write(codec
, 0x24, 0,
497 AC_VERB_SET_POWER_STATE
, parm
);
500 /* PW 3/4/7 (1ch/1dh/23h) */
502 /* force to D0 for internal Speaker */
503 set_pin_power_state(codec
, 0x1c, &parm
);
504 set_pin_power_state(codec
, 0x1d, &parm
);
506 set_pin_power_state(codec
, 0x23, &parm
);
507 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
508 snd_hda_codec_write(codec
, 0x16, 0, AC_VERB_SET_POWER_STATE
,
509 imux_is_smixer
? AC_PWRST_D0
: parm
);
510 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
513 snd_hda_codec_write(codec
, 0x25, 0,
514 AC_VERB_SET_POWER_STATE
, parm
);
515 snd_hda_codec_write(codec
, 0x27, 0,
516 AC_VERB_SET_POWER_STATE
, parm
);
524 static int via_mux_enum_info(struct snd_kcontrol
*kcontrol
,
525 struct snd_ctl_elem_info
*uinfo
)
527 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
528 struct via_spec
*spec
= codec
->spec
;
529 return snd_hda_input_mux_info(spec
->input_mux
, uinfo
);
532 static int via_mux_enum_get(struct snd_kcontrol
*kcontrol
,
533 struct snd_ctl_elem_value
*ucontrol
)
535 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
536 struct via_spec
*spec
= codec
->spec
;
537 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
539 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
543 static int via_mux_enum_put(struct snd_kcontrol
*kcontrol
,
544 struct snd_ctl_elem_value
*ucontrol
)
546 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
547 struct via_spec
*spec
= codec
->spec
;
548 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
550 if (!spec
->mux_nids
[adc_idx
])
552 /* switch to D0 beofre change index */
553 if (snd_hda_codec_read(codec
, spec
->mux_nids
[adc_idx
], 0,
554 AC_VERB_GET_POWER_STATE
, 0x00) != AC_PWRST_D0
)
555 snd_hda_codec_write(codec
, spec
->mux_nids
[adc_idx
], 0,
556 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
557 /* update jack power state */
558 set_jack_power_state(codec
);
560 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
561 spec
->mux_nids
[adc_idx
],
562 &spec
->cur_mux
[adc_idx
]);
565 static int via_independent_hp_info(struct snd_kcontrol
*kcontrol
,
566 struct snd_ctl_elem_info
*uinfo
)
568 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
569 struct via_spec
*spec
= codec
->spec
;
570 return snd_hda_input_mux_info(spec
->hp_mux
, uinfo
);
573 static int via_independent_hp_get(struct snd_kcontrol
*kcontrol
,
574 struct snd_ctl_elem_value
*ucontrol
)
576 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
577 struct via_spec
*spec
= codec
->spec
;
578 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
579 unsigned int pinsel
= snd_hda_codec_read(codec
, nid
, 0,
580 AC_VERB_GET_CONNECT_SEL
,
583 ucontrol
->value
.enumerated
.item
[0] = pinsel
;
588 static void activate_ctl(struct hda_codec
*codec
, const char *name
, int active
)
590 struct snd_kcontrol
*ctl
= snd_hda_find_mixer_ctl(codec
, name
);
592 ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
593 ctl
->vd
[0].access
|= active
594 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
595 snd_ctl_notify(codec
->bus
->card
,
596 SNDRV_CTL_EVENT_MASK_VALUE
, &ctl
->id
);
600 static int update_side_mute_status(struct hda_codec
*codec
)
602 /* mute side channel */
603 struct via_spec
*spec
= codec
->spec
;
604 unsigned int parm
= spec
->hp_independent_mode
605 ? AMP_OUT_MUTE
: AMP_OUT_UNMUTE
;
608 switch (spec
->codec_type
) {
625 snd_hda_codec_write(codec
, sw3
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
630 static int via_independent_hp_put(struct snd_kcontrol
*kcontrol
,
631 struct snd_ctl_elem_value
*ucontrol
)
633 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
634 struct via_spec
*spec
= codec
->spec
;
635 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
636 unsigned int pinsel
= ucontrol
->value
.enumerated
.item
[0];
637 /* Get Independent Mode index of headphone pin widget */
638 spec
->hp_independent_mode
= spec
->hp_independent_mode_index
== pinsel
641 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, pinsel
);
643 if (spec
->multiout
.hp_nid
&& spec
->multiout
.hp_nid
644 != spec
->multiout
.dac_nids
[HDA_FRONT
])
645 snd_hda_codec_setup_stream(codec
, spec
->multiout
.hp_nid
,
648 update_side_mute_status(codec
);
649 /* update HP volume/swtich active state */
650 if (spec
->codec_type
== VT1708S
651 || spec
->codec_type
== VT1702
) {
652 activate_ctl(codec
, "Headphone Playback Volume",
653 spec
->hp_independent_mode
);
654 activate_ctl(codec
, "Headphone Playback Switch",
655 spec
->hp_independent_mode
);
660 static struct snd_kcontrol_new via_hp_mixer
[] = {
662 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
663 .name
= "Independent HP",
665 .info
= via_independent_hp_info
,
666 .get
= via_independent_hp_get
,
667 .put
= via_independent_hp_put
,
672 static void notify_aa_path_ctls(struct hda_codec
*codec
)
675 struct snd_ctl_elem_id id
;
676 const char *labels
[] = {"Mic", "Front Mic", "Line"};
678 memset(&id
, 0, sizeof(id
));
679 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
680 for (i
= 0; i
< ARRAY_SIZE(labels
); i
++) {
681 sprintf(id
.name
, "%s Playback Volume", labels
[i
]);
682 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
687 static void mute_aa_path(struct hda_codec
*codec
, int mute
)
689 struct via_spec
*spec
= codec
->spec
;
694 /* get nid of MW0 and start & end index */
695 switch (spec
->codec_type
) {
717 /* check AA path's mute status */
718 for (i
= start_idx
; i
<= end_idx
; i
++) {
719 int val
= mute
? HDA_AMP_MUTE
: HDA_AMP_UNMUTE
;
720 snd_hda_codec_amp_stereo(codec
, nid_mixer
, HDA_INPUT
, i
,
724 static int is_smart51_pins(struct via_spec
*spec
, hda_nid_t pin
)
728 for (index
= AUTO_PIN_MIC
; index
< AUTO_PIN_FRONT_LINE
; index
++) {
729 if (pin
== spec
->autocfg
.input_pins
[index
]) {
737 static int via_smart51_info(struct snd_kcontrol
*kcontrol
,
738 struct snd_ctl_elem_info
*uinfo
)
740 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
742 uinfo
->value
.integer
.min
= 0;
743 uinfo
->value
.integer
.max
= 1;
747 static int via_smart51_get(struct snd_kcontrol
*kcontrol
,
748 struct snd_ctl_elem_value
*ucontrol
)
750 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
751 struct via_spec
*spec
= codec
->spec
;
752 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
756 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
757 hda_nid_t nid
= spec
->autocfg
.input_pins
[index
[i
]];
760 snd_hda_codec_read(codec
, nid
, 0,
761 AC_VERB_GET_PIN_WIDGET_CONTROL
,
763 if (i
== AUTO_PIN_FRONT_MIC
764 && spec
->hp_independent_mode
)
765 continue; /* ignore FMic for independent HP */
766 if (ctl
& AC_PINCTL_IN_EN
767 && !(ctl
& AC_PINCTL_OUT_EN
))
771 *ucontrol
->value
.integer
.value
= on
;
775 static int via_smart51_put(struct snd_kcontrol
*kcontrol
,
776 struct snd_ctl_elem_value
*ucontrol
)
778 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
779 struct via_spec
*spec
= codec
->spec
;
780 int out_in
= *ucontrol
->value
.integer
.value
781 ? AC_PINCTL_OUT_EN
: AC_PINCTL_IN_EN
;
782 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
785 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
786 hda_nid_t nid
= spec
->autocfg
.input_pins
[index
[i
]];
787 if (i
== AUTO_PIN_FRONT_MIC
788 && spec
->hp_independent_mode
)
789 continue; /* don't retask FMic for independent HP */
791 unsigned int parm
= snd_hda_codec_read(
793 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
794 parm
&= ~(AC_PINCTL_IN_EN
| AC_PINCTL_OUT_EN
);
796 snd_hda_codec_write(codec
, nid
, 0,
797 AC_VERB_SET_PIN_WIDGET_CONTROL
,
799 if (out_in
== AC_PINCTL_OUT_EN
) {
800 mute_aa_path(codec
, 1);
801 notify_aa_path_ctls(codec
);
804 if (i
== AUTO_PIN_FRONT_MIC
) {
805 if (spec
->codec_type
== VT1708S
) {
806 /* input = index 1 (AOW3) */
809 AC_VERB_SET_CONNECT_SEL
, 1);
810 snd_hda_codec_amp_stereo(
811 codec
, nid
, HDA_OUTPUT
,
812 0, HDA_AMP_MUTE
, HDA_AMP_UNMUTE
);
816 spec
->smart51_enabled
= *ucontrol
->value
.integer
.value
;
817 set_jack_power_state(codec
);
821 static struct snd_kcontrol_new via_smart51_mixer
[] = {
823 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
826 .info
= via_smart51_info
,
827 .get
= via_smart51_get
,
828 .put
= via_smart51_put
,
833 /* capture mixer elements */
834 static struct snd_kcontrol_new vt1708_capture_mixer
[] = {
835 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT
),
836 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT
),
837 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT
),
838 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT
),
840 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
841 /* The multiple "Capture Source" controls confuse alsamixer
842 * So call somewhat different..
844 /* .name = "Capture Source", */
845 .name
= "Input Source",
847 .info
= via_mux_enum_info
,
848 .get
= via_mux_enum_get
,
849 .put
= via_mux_enum_put
,
854 /* check AA path's mute statue */
855 static int is_aa_path_mute(struct hda_codec
*codec
)
862 struct via_spec
*spec
= codec
->spec
;
863 /* get nid of MW0 and start & end index */
864 switch (spec
->codec_type
) {
880 /* check AA path's mute status */
881 for (i
= start_idx
; i
<= end_idx
; i
++) {
882 unsigned int con_list
= snd_hda_codec_read(
883 codec
, nid_mixer
, 0, AC_VERB_GET_CONNECT_LIST
, i
/4*4);
884 int shift
= 8 * (i
% 4);
885 hda_nid_t nid_pin
= (con_list
& (0xff << shift
)) >> shift
;
886 unsigned int defconf
= snd_hda_codec_get_pincfg(codec
, nid_pin
);
887 if (get_defcfg_connect(defconf
) == AC_JACK_PORT_COMPLEX
) {
888 /* check mute status while the pin is connected */
889 int mute_l
= snd_hda_codec_amp_read(codec
, nid_mixer
, 0,
891 int mute_r
= snd_hda_codec_amp_read(codec
, nid_mixer
, 1,
893 if (!mute_l
|| !mute_r
) {
902 /* enter/exit analog low-current mode */
903 static void analog_low_current_mode(struct hda_codec
*codec
, int stream_idle
)
905 struct via_spec
*spec
= codec
->spec
;
906 static int saved_stream_idle
= 1; /* saved stream idle status */
907 int enable
= is_aa_path_mute(codec
);
908 unsigned int verb
= 0;
909 unsigned int parm
= 0;
911 if (stream_idle
== -1) /* stream status did not change */
912 enable
= enable
&& saved_stream_idle
;
914 enable
= enable
&& stream_idle
;
915 saved_stream_idle
= stream_idle
;
918 /* decide low current mode's verb & parameter */
919 switch (spec
->codec_type
) {
923 parm
= enable
? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
927 parm
= enable
? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
931 parm
= enable
? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
934 return; /* other codecs are not supported */
937 snd_hda_codec_write(codec
, codec
->afg
, 0, verb
, parm
);
941 * generic initialization of ADC, input mixers and output mixers
943 static struct hda_verb vt1708_volume_init_verbs
[] = {
945 * Unmute ADC0-1 and set the default input to mic-in
947 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
948 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
951 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
954 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
955 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
956 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
957 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
958 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
959 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
962 * Set up output mixers (0x19 - 0x1b)
964 /* set vol=0 to output mixers */
965 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
966 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
967 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
969 /* Setup default input to PW4 */
970 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
971 /* PW9 Output enable */
972 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
976 static int via_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
977 struct hda_codec
*codec
,
978 struct snd_pcm_substream
*substream
)
980 struct via_spec
*spec
= codec
->spec
;
981 int idle
= substream
->pstr
->substream_opened
== 1
982 && substream
->ref_count
== 0;
984 analog_low_current_mode(codec
, idle
);
985 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
989 static int via_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
990 struct hda_codec
*codec
,
991 unsigned int stream_tag
,
993 struct snd_pcm_substream
*substream
)
995 struct via_spec
*spec
= codec
->spec
;
996 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
997 stream_tag
, format
, substream
);
1000 static int via_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1001 struct hda_codec
*codec
,
1002 struct snd_pcm_substream
*substream
)
1004 struct via_spec
*spec
= codec
->spec
;
1005 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
1009 static void playback_multi_pcm_prep_0(struct hda_codec
*codec
,
1010 unsigned int stream_tag
,
1011 unsigned int format
,
1012 struct snd_pcm_substream
*substream
)
1014 struct via_spec
*spec
= codec
->spec
;
1015 struct hda_multi_out
*mout
= &spec
->multiout
;
1016 hda_nid_t
*nids
= mout
->dac_nids
;
1017 int chs
= substream
->runtime
->channels
;
1020 mutex_lock(&codec
->spdif_mutex
);
1021 if (mout
->dig_out_nid
&& mout
->dig_out_used
!= HDA_DIG_EXCLUSIVE
) {
1023 snd_hda_is_supported_format(codec
, mout
->dig_out_nid
,
1025 !(codec
->spdif_status
& IEC958_AES0_NONAUDIO
)) {
1026 mout
->dig_out_used
= HDA_DIG_ANALOG_DUP
;
1027 /* turn off SPDIF once; otherwise the IEC958 bits won't
1029 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1030 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1031 AC_VERB_SET_DIGI_CONVERT_1
,
1033 ~AC_DIG1_ENABLE
& 0xff);
1034 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1035 stream_tag
, 0, format
);
1036 /* turn on again (if needed) */
1037 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1038 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1039 AC_VERB_SET_DIGI_CONVERT_1
,
1040 codec
->spdif_ctls
& 0xff);
1042 mout
->dig_out_used
= 0;
1043 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1047 mutex_unlock(&codec
->spdif_mutex
);
1050 snd_hda_codec_setup_stream(codec
, nids
[HDA_FRONT
], stream_tag
,
1053 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1054 !spec
->hp_independent_mode
)
1055 /* headphone out will just decode front left/right (stereo) */
1056 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
, stream_tag
,
1059 /* extra outputs copied from front */
1060 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1061 if (mout
->extra_out_nid
[i
])
1062 snd_hda_codec_setup_stream(codec
,
1063 mout
->extra_out_nid
[i
],
1064 stream_tag
, 0, format
);
1067 for (i
= 1; i
< mout
->num_dacs
; i
++) {
1068 if (chs
>= (i
+ 1) * 2) /* independent out */
1069 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1071 else /* copy front */
1072 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1077 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1078 struct hda_codec
*codec
,
1079 unsigned int stream_tag
,
1080 unsigned int format
,
1081 struct snd_pcm_substream
*substream
)
1083 struct via_spec
*spec
= codec
->spec
;
1084 struct hda_multi_out
*mout
= &spec
->multiout
;
1085 hda_nid_t
*nids
= mout
->dac_nids
;
1087 if (substream
->number
== 0)
1088 playback_multi_pcm_prep_0(codec
, stream_tag
, format
,
1091 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1092 spec
->hp_independent_mode
)
1093 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1094 stream_tag
, 0, format
);
1100 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1101 struct hda_codec
*codec
,
1102 struct snd_pcm_substream
*substream
)
1104 struct via_spec
*spec
= codec
->spec
;
1105 struct hda_multi_out
*mout
= &spec
->multiout
;
1106 hda_nid_t
*nids
= mout
->dac_nids
;
1109 if (substream
->number
== 0) {
1110 for (i
= 0; i
< mout
->num_dacs
; i
++)
1111 snd_hda_codec_setup_stream(codec
, nids
[i
], 0, 0, 0);
1113 if (mout
->hp_nid
&& !spec
->hp_independent_mode
)
1114 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1117 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1118 if (mout
->extra_out_nid
[i
])
1119 snd_hda_codec_setup_stream(codec
,
1120 mout
->extra_out_nid
[i
],
1122 mutex_lock(&codec
->spdif_mutex
);
1123 if (mout
->dig_out_nid
&&
1124 mout
->dig_out_used
== HDA_DIG_ANALOG_DUP
) {
1125 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1127 mout
->dig_out_used
= 0;
1129 mutex_unlock(&codec
->spdif_mutex
);
1131 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1132 spec
->hp_independent_mode
)
1133 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1143 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1144 struct hda_codec
*codec
,
1145 struct snd_pcm_substream
*substream
)
1147 struct via_spec
*spec
= codec
->spec
;
1148 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
1151 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
1152 struct hda_codec
*codec
,
1153 struct snd_pcm_substream
*substream
)
1155 struct via_spec
*spec
= codec
->spec
;
1156 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
1159 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1160 struct hda_codec
*codec
,
1161 unsigned int stream_tag
,
1162 unsigned int format
,
1163 struct snd_pcm_substream
*substream
)
1165 struct via_spec
*spec
= codec
->spec
;
1166 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
1167 stream_tag
, format
, substream
);
1170 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1171 struct hda_codec
*codec
,
1172 struct snd_pcm_substream
*substream
)
1174 struct via_spec
*spec
= codec
->spec
;
1175 snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
1182 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1183 struct hda_codec
*codec
,
1184 unsigned int stream_tag
,
1185 unsigned int format
,
1186 struct snd_pcm_substream
*substream
)
1188 struct via_spec
*spec
= codec
->spec
;
1190 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
1191 stream_tag
, 0, format
);
1195 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1196 struct hda_codec
*codec
,
1197 struct snd_pcm_substream
*substream
)
1199 struct via_spec
*spec
= codec
->spec
;
1200 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
1204 static struct hda_pcm_stream vt1708_pcm_analog_playback
= {
1208 .nid
= 0x10, /* NID to query formats and rates */
1210 .open
= via_playback_pcm_open
,
1211 .prepare
= via_playback_multi_pcm_prepare
,
1212 .cleanup
= via_playback_multi_pcm_cleanup
1216 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
1220 .nid
= 0x10, /* NID to query formats and rates */
1221 /* We got noisy outputs on the right channel on VT1708 when
1222 * 24bit samples are used. Until any workaround is found,
1223 * disable the 24bit format, so far.
1225 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1227 .open
= via_playback_pcm_open
,
1228 .prepare
= via_playback_pcm_prepare
,
1229 .cleanup
= via_playback_pcm_cleanup
1233 static struct hda_pcm_stream vt1708_pcm_analog_capture
= {
1237 .nid
= 0x15, /* NID to query formats and rates */
1239 .prepare
= via_capture_pcm_prepare
,
1240 .cleanup
= via_capture_pcm_cleanup
1244 static struct hda_pcm_stream vt1708_pcm_digital_playback
= {
1248 /* NID is set in via_build_pcms */
1250 .open
= via_dig_playback_pcm_open
,
1251 .close
= via_dig_playback_pcm_close
,
1252 .prepare
= via_dig_playback_pcm_prepare
,
1253 .cleanup
= via_dig_playback_pcm_cleanup
1257 static struct hda_pcm_stream vt1708_pcm_digital_capture
= {
1263 static int via_build_controls(struct hda_codec
*codec
)
1265 struct via_spec
*spec
= codec
->spec
;
1269 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1270 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1275 if (spec
->multiout
.dig_out_nid
) {
1276 err
= snd_hda_create_spdif_out_ctls(codec
,
1277 spec
->multiout
.dig_out_nid
);
1280 err
= snd_hda_create_spdif_share_sw(codec
,
1284 spec
->multiout
.share_spdif
= 1;
1286 if (spec
->dig_in_nid
) {
1287 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1292 /* init power states */
1293 set_jack_power_state(codec
);
1294 analog_low_current_mode(codec
, 1);
1296 via_free_kctls(codec
); /* no longer needed */
1300 static int via_build_pcms(struct hda_codec
*codec
)
1302 struct via_spec
*spec
= codec
->spec
;
1303 struct hda_pcm
*info
= spec
->pcm_rec
;
1305 codec
->num_pcms
= 1;
1306 codec
->pcm_info
= info
;
1308 info
->name
= spec
->stream_name_analog
;
1309 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *(spec
->stream_analog_playback
);
1310 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
1311 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *(spec
->stream_analog_capture
);
1312 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
1314 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
1315 spec
->multiout
.max_channels
;
1317 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
1320 info
->name
= spec
->stream_name_digital
;
1321 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
1322 if (spec
->multiout
.dig_out_nid
) {
1323 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1324 *(spec
->stream_digital_playback
);
1325 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1326 spec
->multiout
.dig_out_nid
;
1328 if (spec
->dig_in_nid
) {
1329 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
1330 *(spec
->stream_digital_capture
);
1331 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
1339 static void via_free(struct hda_codec
*codec
)
1341 struct via_spec
*spec
= codec
->spec
;
1346 via_free_kctls(codec
);
1350 /* mute internal speaker if HP is plugged */
1351 static void via_hp_automute(struct hda_codec
*codec
)
1353 unsigned int present
;
1354 struct via_spec
*spec
= codec
->spec
;
1356 present
= snd_hda_codec_read(codec
, spec
->autocfg
.hp_pins
[0], 0,
1357 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
1358 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
1359 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
1360 present
? HDA_AMP_MUTE
: 0);
1363 static void via_gpio_control(struct hda_codec
*codec
)
1365 unsigned int gpio_data
;
1366 unsigned int vol_counter
;
1368 unsigned int master_vol
;
1370 struct via_spec
*spec
= codec
->spec
;
1372 gpio_data
= snd_hda_codec_read(codec
, codec
->afg
, 0,
1373 AC_VERB_GET_GPIO_DATA
, 0) & 0x03;
1375 vol_counter
= (snd_hda_codec_read(codec
, codec
->afg
, 0,
1376 0xF84, 0) & 0x3F0000) >> 16;
1378 vol
= vol_counter
& 0x1F;
1379 master_vol
= snd_hda_codec_read(codec
, 0x1A, 0,
1380 AC_VERB_GET_AMP_GAIN_MUTE
,
1383 if (gpio_data
== 0x02) {
1384 /* unmute line out */
1385 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
1386 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
1388 if (vol_counter
& 0x20) {
1389 /* decrease volume */
1390 if (vol
> master_vol
)
1392 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
,
1396 /* increase volume */
1397 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
, 0,
1399 ((master_vol
+vol
) > 0x2A) ? 0x2A :
1402 } else if (!(gpio_data
& 0x02)) {
1404 snd_hda_codec_amp_stereo(codec
,
1405 spec
->autocfg
.line_out_pins
[0],
1406 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
1411 /* unsolicited event for jack sensing */
1412 static void via_unsol_event(struct hda_codec
*codec
,
1416 if (res
== VIA_HP_EVENT
)
1417 via_hp_automute(codec
);
1418 else if (res
== VIA_GPIO_EVENT
)
1419 via_gpio_control(codec
);
1422 static int via_init(struct hda_codec
*codec
)
1424 struct via_spec
*spec
= codec
->spec
;
1426 for (i
= 0; i
< spec
->num_iverbs
; i
++)
1427 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
1429 spec
->codec_type
= get_codec_type(codec
);
1430 if (spec
->codec_type
== VT1708BCE
)
1431 spec
->codec_type
= VT1708S
; /* VT1708BCE & VT1708S are almost
1433 /* Lydia Add for EAPD enable */
1434 if (!spec
->dig_in_nid
) { /* No Digital In connection */
1435 if (spec
->dig_in_pin
) {
1436 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
1437 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1439 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
1440 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
1442 } else /* enable SPDIF-input pin */
1443 snd_hda_codec_write(codec
, spec
->autocfg
.dig_in_pin
, 0,
1444 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
1446 /* assign slave outs */
1447 if (spec
->slave_dig_outs
[0])
1448 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
1453 #ifdef CONFIG_SND_HDA_POWER_SAVE
1454 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
1456 struct via_spec
*spec
= codec
->spec
;
1457 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
1463 static struct hda_codec_ops via_patch_ops
= {
1464 .build_controls
= via_build_controls
,
1465 .build_pcms
= via_build_pcms
,
1468 #ifdef CONFIG_SND_HDA_POWER_SAVE
1469 .check_power_status
= via_check_power_status
,
1473 /* fill in the dac_nids table from the parsed pin configuration */
1474 static int vt1708_auto_fill_dac_nids(struct via_spec
*spec
,
1475 const struct auto_pin_cfg
*cfg
)
1480 spec
->multiout
.num_dacs
= cfg
->line_outs
;
1482 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1484 for(i
= 0; i
< 4; i
++) {
1485 nid
= cfg
->line_out_pins
[i
];
1487 /* config dac list */
1489 case AUTO_SEQ_FRONT
:
1490 spec
->multiout
.dac_nids
[i
] = 0x10;
1492 case AUTO_SEQ_CENLFE
:
1493 spec
->multiout
.dac_nids
[i
] = 0x12;
1495 case AUTO_SEQ_SURROUND
:
1496 spec
->multiout
.dac_nids
[i
] = 0x11;
1499 spec
->multiout
.dac_nids
[i
] = 0x13;
1508 /* add playback controls from the parsed DAC table */
1509 static int vt1708_auto_create_multi_out_ctls(struct via_spec
*spec
,
1510 const struct auto_pin_cfg
*cfg
)
1513 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1514 hda_nid_t nid
, nid_vol
= 0;
1517 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1518 nid
= cfg
->line_out_pins
[i
];
1523 if (i
!= AUTO_SEQ_FRONT
)
1526 if (i
== AUTO_SEQ_CENLFE
) {
1528 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1529 "Center Playback Volume",
1530 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1534 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1535 "LFE Playback Volume",
1536 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1540 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1541 "Center Playback Switch",
1542 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1546 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1547 "LFE Playback Switch",
1548 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1552 } else if (i
== AUTO_SEQ_FRONT
){
1553 /* add control to mixer index 0 */
1554 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1555 "Master Front Playback Volume",
1556 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1560 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1561 "Master Front Playback Switch",
1562 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1567 /* add control to PW3 */
1568 sprintf(name
, "%s Playback Volume", chname
[i
]);
1569 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1570 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1574 sprintf(name
, "%s Playback Switch", chname
[i
]);
1575 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1576 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1581 sprintf(name
, "%s Playback Volume", chname
[i
]);
1582 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1583 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1587 sprintf(name
, "%s Playback Switch", chname
[i
]);
1588 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1589 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1599 static void create_hp_imux(struct via_spec
*spec
)
1602 struct hda_input_mux
*imux
= &spec
->private_imux
[1];
1603 static const char *texts
[] = { "OFF", "ON", NULL
};
1605 /* for hp mode select */
1607 while (texts
[i
] != NULL
) {
1608 imux
->items
[imux
->num_items
].label
= texts
[i
];
1609 imux
->items
[imux
->num_items
].index
= i
;
1614 spec
->hp_mux
= &spec
->private_imux
[1];
1617 static int vt1708_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1624 spec
->multiout
.hp_nid
= VT1708_HP_NID
; /* AOW3 */
1625 spec
->hp_independent_mode_index
= 1;
1627 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1628 "Headphone Playback Volume",
1629 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1632 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1633 "Headphone Playback Switch",
1634 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1638 create_hp_imux(spec
);
1643 /* create playback/capture controls for input pins */
1644 static int vt1708_auto_create_analog_input_ctls(struct via_spec
*spec
,
1645 const struct auto_pin_cfg
*cfg
)
1647 static char *labels
[] = {
1648 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1650 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1651 int i
, err
, idx
= 0;
1653 /* for internal loopback recording select */
1654 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1655 imux
->items
[imux
->num_items
].index
= idx
;
1658 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1659 if (!cfg
->input_pins
[i
])
1662 switch (cfg
->input_pins
[i
]) {
1663 case 0x1d: /* Mic */
1667 case 0x1e: /* Line In */
1671 case 0x21: /* Front Mic */
1679 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x17);
1682 imux
->items
[imux
->num_items
].label
= labels
[i
];
1683 imux
->items
[imux
->num_items
].index
= idx
;
1689 #ifdef CONFIG_SND_HDA_POWER_SAVE
1690 static struct hda_amp_list vt1708_loopbacks
[] = {
1691 { 0x17, HDA_INPUT
, 1 },
1692 { 0x17, HDA_INPUT
, 2 },
1693 { 0x17, HDA_INPUT
, 3 },
1694 { 0x17, HDA_INPUT
, 4 },
1699 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
1701 unsigned int def_conf
;
1702 unsigned char seqassoc
;
1704 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
1705 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
1706 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
1707 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
) {
1708 if (seqassoc
== 0xff) {
1709 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
1710 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
1717 static int vt1708_parse_auto_config(struct hda_codec
*codec
)
1719 struct via_spec
*spec
= codec
->spec
;
1722 /* Add HP and CD pin config connect bit re-config action */
1723 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
1724 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
1726 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1729 err
= vt1708_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1732 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1733 return 0; /* can't find valid BIOS pin config */
1735 err
= vt1708_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1738 err
= vt1708_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1741 err
= vt1708_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1745 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1747 if (spec
->autocfg
.dig_outs
)
1748 spec
->multiout
.dig_out_nid
= VT1708_DIGOUT_NID
;
1749 spec
->dig_in_pin
= VT1708_DIGIN_PIN
;
1750 if (spec
->autocfg
.dig_in_pin
)
1751 spec
->dig_in_nid
= VT1708_DIGIN_NID
;
1753 if (spec
->kctls
.list
)
1754 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
1756 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_volume_init_verbs
;
1758 spec
->input_mux
= &spec
->private_imux
[0];
1761 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1763 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
1767 /* init callback for auto-configuration model -- overriding the default init */
1768 static int via_auto_init(struct hda_codec
*codec
)
1771 via_auto_init_multi_out(codec
);
1772 via_auto_init_hp_out(codec
);
1773 via_auto_init_analog_input(codec
);
1777 static int get_mux_nids(struct hda_codec
*codec
)
1779 struct via_spec
*spec
= codec
->spec
;
1780 hda_nid_t nid
, conn
[8];
1784 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1785 nid
= spec
->adc_nids
[i
];
1787 type
= get_wcaps_type(get_wcaps(codec
, nid
));
1788 if (type
== AC_WID_PIN
)
1790 n
= snd_hda_get_connections(codec
, nid
, conn
,
1795 spec
->mux_nids
[i
] = nid
;
1804 static int patch_vt1708(struct hda_codec
*codec
)
1806 struct via_spec
*spec
;
1809 /* create a codec specific record */
1810 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1816 /* automatic parse from the BIOS config */
1817 err
= vt1708_parse_auto_config(codec
);
1822 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
1823 "from BIOS. Using genenic mode...\n");
1827 spec
->stream_name_analog
= "VT1708 Analog";
1828 spec
->stream_analog_playback
= &vt1708_pcm_analog_playback
;
1829 /* disable 32bit format on VT1708 */
1830 if (codec
->vendor_id
== 0x11061708)
1831 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
1832 spec
->stream_analog_capture
= &vt1708_pcm_analog_capture
;
1834 spec
->stream_name_digital
= "VT1708 Digital";
1835 spec
->stream_digital_playback
= &vt1708_pcm_digital_playback
;
1836 spec
->stream_digital_capture
= &vt1708_pcm_digital_capture
;
1839 if (!spec
->adc_nids
&& spec
->input_mux
) {
1840 spec
->adc_nids
= vt1708_adc_nids
;
1841 spec
->num_adc_nids
= ARRAY_SIZE(vt1708_adc_nids
);
1842 get_mux_nids(codec
);
1843 spec
->mixers
[spec
->num_mixers
] = vt1708_capture_mixer
;
1847 codec
->patch_ops
= via_patch_ops
;
1849 codec
->patch_ops
.init
= via_auto_init
;
1850 #ifdef CONFIG_SND_HDA_POWER_SAVE
1851 spec
->loopback
.amplist
= vt1708_loopbacks
;
1857 /* capture mixer elements */
1858 static struct snd_kcontrol_new vt1709_capture_mixer
[] = {
1859 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT
),
1860 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT
),
1861 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT
),
1862 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT
),
1863 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT
),
1864 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT
),
1866 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1867 /* The multiple "Capture Source" controls confuse alsamixer
1868 * So call somewhat different..
1870 /* .name = "Capture Source", */
1871 .name
= "Input Source",
1873 .info
= via_mux_enum_info
,
1874 .get
= via_mux_enum_get
,
1875 .put
= via_mux_enum_put
,
1880 static struct hda_verb vt1709_uniwill_init_verbs
[] = {
1881 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
1886 * generic initialization of ADC, input mixers and output mixers
1888 static struct hda_verb vt1709_10ch_volume_init_verbs
[] = {
1890 * Unmute ADC0-2 and set the default input to mic-in
1892 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1893 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1894 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1897 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1900 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1901 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1902 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1903 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1904 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1905 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1908 * Set up output selector (0x1a, 0x1b, 0x29)
1910 /* set vol=0 to output mixers */
1911 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1912 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1913 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1916 * Unmute PW3 and PW4
1918 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1919 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1921 /* Set input of PW4 as AOW4 */
1922 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
1923 /* PW9 Output enable */
1924 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1928 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback
= {
1932 .nid
= 0x10, /* NID to query formats and rates */
1934 .open
= via_playback_pcm_open
,
1935 .prepare
= via_playback_pcm_prepare
,
1936 .cleanup
= via_playback_pcm_cleanup
1940 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback
= {
1944 .nid
= 0x10, /* NID to query formats and rates */
1946 .open
= via_playback_pcm_open
,
1947 .prepare
= via_playback_pcm_prepare
,
1948 .cleanup
= via_playback_pcm_cleanup
1952 static struct hda_pcm_stream vt1709_pcm_analog_capture
= {
1956 .nid
= 0x14, /* NID to query formats and rates */
1958 .prepare
= via_capture_pcm_prepare
,
1959 .cleanup
= via_capture_pcm_cleanup
1963 static struct hda_pcm_stream vt1709_pcm_digital_playback
= {
1967 /* NID is set in via_build_pcms */
1969 .open
= via_dig_playback_pcm_open
,
1970 .close
= via_dig_playback_pcm_close
1974 static struct hda_pcm_stream vt1709_pcm_digital_capture
= {
1980 static int vt1709_auto_fill_dac_nids(struct via_spec
*spec
,
1981 const struct auto_pin_cfg
*cfg
)
1986 if (cfg
->line_outs
== 4) /* 10 channels */
1987 spec
->multiout
.num_dacs
= cfg
->line_outs
+1; /* AOW0~AOW4 */
1988 else if (cfg
->line_outs
== 3) /* 6 channels */
1989 spec
->multiout
.num_dacs
= cfg
->line_outs
; /* AOW0~AOW2 */
1991 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1993 if (cfg
->line_outs
== 4) { /* 10 channels */
1994 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1995 nid
= cfg
->line_out_pins
[i
];
1997 /* config dac list */
1999 case AUTO_SEQ_FRONT
:
2001 spec
->multiout
.dac_nids
[i
] = 0x10;
2003 case AUTO_SEQ_CENLFE
:
2005 spec
->multiout
.dac_nids
[i
] = 0x12;
2007 case AUTO_SEQ_SURROUND
:
2009 spec
->multiout
.dac_nids
[i
] = 0x11;
2013 spec
->multiout
.dac_nids
[i
] = 0x27;
2020 spec
->multiout
.dac_nids
[cfg
->line_outs
] = 0x28; /* AOW4 */
2022 } else if (cfg
->line_outs
== 3) { /* 6 channels */
2023 for(i
= 0; i
< cfg
->line_outs
; i
++) {
2024 nid
= cfg
->line_out_pins
[i
];
2026 /* config dac list */
2028 case AUTO_SEQ_FRONT
:
2030 spec
->multiout
.dac_nids
[i
] = 0x10;
2032 case AUTO_SEQ_CENLFE
:
2034 spec
->multiout
.dac_nids
[i
] = 0x12;
2036 case AUTO_SEQ_SURROUND
:
2038 spec
->multiout
.dac_nids
[i
] = 0x11;
2050 /* add playback controls from the parsed DAC table */
2051 static int vt1709_auto_create_multi_out_ctls(struct via_spec
*spec
,
2052 const struct auto_pin_cfg
*cfg
)
2055 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2059 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2060 nid
= cfg
->line_out_pins
[i
];
2065 if (i
== AUTO_SEQ_CENLFE
) {
2067 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2068 "Center Playback Volume",
2069 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
2073 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2074 "LFE Playback Volume",
2075 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
2079 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2080 "Center Playback Switch",
2081 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
2085 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2086 "LFE Playback Switch",
2087 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
2091 } else if (i
== AUTO_SEQ_FRONT
){
2092 /* add control to mixer index 0 */
2093 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2094 "Master Front Playback Volume",
2095 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
2099 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2100 "Master Front Playback Switch",
2101 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
2106 /* add control to PW3 */
2107 sprintf(name
, "%s Playback Volume", chname
[i
]);
2108 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2109 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2113 sprintf(name
, "%s Playback Switch", chname
[i
]);
2114 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2115 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2119 } else if (i
== AUTO_SEQ_SURROUND
) {
2120 sprintf(name
, "%s Playback Volume", chname
[i
]);
2121 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2122 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
2126 sprintf(name
, "%s Playback Switch", chname
[i
]);
2127 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2128 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
2132 } else if (i
== AUTO_SEQ_SIDE
) {
2133 sprintf(name
, "%s Playback Volume", chname
[i
]);
2134 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2135 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
2139 sprintf(name
, "%s Playback Switch", chname
[i
]);
2140 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2141 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
2151 static int vt1709_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2158 if (spec
->multiout
.num_dacs
== 5) /* 10 channels */
2159 spec
->multiout
.hp_nid
= VT1709_HP_DAC_NID
;
2160 else if (spec
->multiout
.num_dacs
== 3) /* 6 channels */
2161 spec
->multiout
.hp_nid
= 0;
2162 spec
->hp_independent_mode_index
= 1;
2164 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2165 "Headphone Playback Volume",
2166 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2169 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2170 "Headphone Playback Switch",
2171 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2178 /* create playback/capture controls for input pins */
2179 static int vt1709_auto_create_analog_input_ctls(struct via_spec
*spec
,
2180 const struct auto_pin_cfg
*cfg
)
2182 static char *labels
[] = {
2183 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2185 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2186 int i
, err
, idx
= 0;
2188 /* for internal loopback recording select */
2189 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2190 imux
->items
[imux
->num_items
].index
= idx
;
2193 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2194 if (!cfg
->input_pins
[i
])
2197 switch (cfg
->input_pins
[i
]) {
2198 case 0x1d: /* Mic */
2202 case 0x1e: /* Line In */
2206 case 0x21: /* Front Mic */
2214 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x18);
2217 imux
->items
[imux
->num_items
].label
= labels
[i
];
2218 imux
->items
[imux
->num_items
].index
= idx
;
2224 static int vt1709_parse_auto_config(struct hda_codec
*codec
)
2226 struct via_spec
*spec
= codec
->spec
;
2229 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2232 err
= vt1709_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2235 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2236 return 0; /* can't find valid BIOS pin config */
2238 err
= vt1709_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2241 err
= vt1709_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2244 err
= vt1709_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2248 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2250 if (spec
->autocfg
.dig_outs
)
2251 spec
->multiout
.dig_out_nid
= VT1709_DIGOUT_NID
;
2252 spec
->dig_in_pin
= VT1709_DIGIN_PIN
;
2253 if (spec
->autocfg
.dig_in_pin
)
2254 spec
->dig_in_nid
= VT1709_DIGIN_NID
;
2256 if (spec
->kctls
.list
)
2257 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2259 spec
->input_mux
= &spec
->private_imux
[0];
2262 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2264 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
2268 #ifdef CONFIG_SND_HDA_POWER_SAVE
2269 static struct hda_amp_list vt1709_loopbacks
[] = {
2270 { 0x18, HDA_INPUT
, 1 },
2271 { 0x18, HDA_INPUT
, 2 },
2272 { 0x18, HDA_INPUT
, 3 },
2273 { 0x18, HDA_INPUT
, 4 },
2278 static int patch_vt1709_10ch(struct hda_codec
*codec
)
2280 struct via_spec
*spec
;
2283 /* create a codec specific record */
2284 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2290 err
= vt1709_parse_auto_config(codec
);
2295 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
2296 "Using genenic mode...\n");
2299 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_10ch_volume_init_verbs
;
2300 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
2302 spec
->stream_name_analog
= "VT1709 Analog";
2303 spec
->stream_analog_playback
= &vt1709_10ch_pcm_analog_playback
;
2304 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
2306 spec
->stream_name_digital
= "VT1709 Digital";
2307 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
2308 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
2311 if (!spec
->adc_nids
&& spec
->input_mux
) {
2312 spec
->adc_nids
= vt1709_adc_nids
;
2313 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
2314 get_mux_nids(codec
);
2315 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
2319 codec
->patch_ops
= via_patch_ops
;
2321 codec
->patch_ops
.init
= via_auto_init
;
2322 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2323 #ifdef CONFIG_SND_HDA_POWER_SAVE
2324 spec
->loopback
.amplist
= vt1709_loopbacks
;
2330 * generic initialization of ADC, input mixers and output mixers
2332 static struct hda_verb vt1709_6ch_volume_init_verbs
[] = {
2334 * Unmute ADC0-2 and set the default input to mic-in
2336 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2337 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2338 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2341 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2344 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2345 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2346 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2347 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2348 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2349 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2352 * Set up output selector (0x1a, 0x1b, 0x29)
2354 /* set vol=0 to output mixers */
2355 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2356 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2357 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2360 * Unmute PW3 and PW4
2362 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2363 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2365 /* Set input of PW4 as MW0 */
2366 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
2367 /* PW9 Output enable */
2368 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2372 static int patch_vt1709_6ch(struct hda_codec
*codec
)
2374 struct via_spec
*spec
;
2377 /* create a codec specific record */
2378 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2384 err
= vt1709_parse_auto_config(codec
);
2389 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
2390 "Using genenic mode...\n");
2393 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_6ch_volume_init_verbs
;
2394 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
2396 spec
->stream_name_analog
= "VT1709 Analog";
2397 spec
->stream_analog_playback
= &vt1709_6ch_pcm_analog_playback
;
2398 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
2400 spec
->stream_name_digital
= "VT1709 Digital";
2401 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
2402 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
2405 if (!spec
->adc_nids
&& spec
->input_mux
) {
2406 spec
->adc_nids
= vt1709_adc_nids
;
2407 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
2408 get_mux_nids(codec
);
2409 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
2413 codec
->patch_ops
= via_patch_ops
;
2415 codec
->patch_ops
.init
= via_auto_init
;
2416 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2417 #ifdef CONFIG_SND_HDA_POWER_SAVE
2418 spec
->loopback
.amplist
= vt1709_loopbacks
;
2423 /* capture mixer elements */
2424 static struct snd_kcontrol_new vt1708B_capture_mixer
[] = {
2425 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
2426 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
2427 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
2428 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
2430 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2431 /* The multiple "Capture Source" controls confuse alsamixer
2432 * So call somewhat different..
2434 /* .name = "Capture Source", */
2435 .name
= "Input Source",
2437 .info
= via_mux_enum_info
,
2438 .get
= via_mux_enum_get
,
2439 .put
= via_mux_enum_put
,
2444 * generic initialization of ADC, input mixers and output mixers
2446 static struct hda_verb vt1708B_8ch_volume_init_verbs
[] = {
2448 * Unmute ADC0-1 and set the default input to mic-in
2450 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2451 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2454 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2457 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2458 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2459 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2460 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2461 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2462 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2465 * Set up output mixers
2467 /* set vol=0 to output mixers */
2468 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2469 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2470 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2472 /* Setup default input to PW4 */
2473 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x1},
2474 /* PW9 Output enable */
2475 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2476 /* PW10 Input enable */
2477 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2481 static struct hda_verb vt1708B_4ch_volume_init_verbs
[] = {
2483 * Unmute ADC0-1 and set the default input to mic-in
2485 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2486 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2489 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2492 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2493 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2494 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2495 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2496 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2497 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2500 * Set up output mixers
2502 /* set vol=0 to output mixers */
2503 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2504 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2505 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2507 /* Setup default input of PW4 to MW0 */
2508 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2509 /* PW9 Output enable */
2510 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2511 /* PW10 Input enable */
2512 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2516 static struct hda_verb vt1708B_uniwill_init_verbs
[] = {
2517 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
2521 static int via_pcm_open_close(struct hda_pcm_stream
*hinfo
,
2522 struct hda_codec
*codec
,
2523 struct snd_pcm_substream
*substream
)
2525 int idle
= substream
->pstr
->substream_opened
== 1
2526 && substream
->ref_count
== 0;
2528 analog_low_current_mode(codec
, idle
);
2532 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback
= {
2536 .nid
= 0x10, /* NID to query formats and rates */
2538 .open
= via_playback_pcm_open
,
2539 .prepare
= via_playback_multi_pcm_prepare
,
2540 .cleanup
= via_playback_multi_pcm_cleanup
,
2541 .close
= via_pcm_open_close
2545 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback
= {
2549 .nid
= 0x10, /* NID to query formats and rates */
2551 .open
= via_playback_pcm_open
,
2552 .prepare
= via_playback_multi_pcm_prepare
,
2553 .cleanup
= via_playback_multi_pcm_cleanup
2557 static struct hda_pcm_stream vt1708B_pcm_analog_capture
= {
2561 .nid
= 0x13, /* NID to query formats and rates */
2563 .open
= via_pcm_open_close
,
2564 .prepare
= via_capture_pcm_prepare
,
2565 .cleanup
= via_capture_pcm_cleanup
,
2566 .close
= via_pcm_open_close
2570 static struct hda_pcm_stream vt1708B_pcm_digital_playback
= {
2574 /* NID is set in via_build_pcms */
2576 .open
= via_dig_playback_pcm_open
,
2577 .close
= via_dig_playback_pcm_close
,
2578 .prepare
= via_dig_playback_pcm_prepare
,
2579 .cleanup
= via_dig_playback_pcm_cleanup
2583 static struct hda_pcm_stream vt1708B_pcm_digital_capture
= {
2589 /* fill in the dac_nids table from the parsed pin configuration */
2590 static int vt1708B_auto_fill_dac_nids(struct via_spec
*spec
,
2591 const struct auto_pin_cfg
*cfg
)
2596 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2598 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2600 for (i
= 0; i
< 4; i
++) {
2601 nid
= cfg
->line_out_pins
[i
];
2603 /* config dac list */
2605 case AUTO_SEQ_FRONT
:
2606 spec
->multiout
.dac_nids
[i
] = 0x10;
2608 case AUTO_SEQ_CENLFE
:
2609 spec
->multiout
.dac_nids
[i
] = 0x24;
2611 case AUTO_SEQ_SURROUND
:
2612 spec
->multiout
.dac_nids
[i
] = 0x11;
2615 spec
->multiout
.dac_nids
[i
] = 0x25;
2624 /* add playback controls from the parsed DAC table */
2625 static int vt1708B_auto_create_multi_out_ctls(struct via_spec
*spec
,
2626 const struct auto_pin_cfg
*cfg
)
2629 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2630 hda_nid_t nid_vols
[] = {0x16, 0x18, 0x26, 0x27};
2631 hda_nid_t nid
, nid_vol
= 0;
2634 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2635 nid
= cfg
->line_out_pins
[i
];
2640 nid_vol
= nid_vols
[i
];
2642 if (i
== AUTO_SEQ_CENLFE
) {
2644 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2645 "Center Playback Volume",
2646 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2650 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2651 "LFE Playback Volume",
2652 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2656 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2657 "Center Playback Switch",
2658 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2662 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2663 "LFE Playback Switch",
2664 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2668 } else if (i
== AUTO_SEQ_FRONT
) {
2669 /* add control to mixer index 0 */
2670 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2671 "Master Front Playback Volume",
2672 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2676 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2677 "Master Front Playback Switch",
2678 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2683 /* add control to PW3 */
2684 sprintf(name
, "%s Playback Volume", chname
[i
]);
2685 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2686 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2690 sprintf(name
, "%s Playback Switch", chname
[i
]);
2691 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2692 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2697 sprintf(name
, "%s Playback Volume", chname
[i
]);
2698 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2699 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2703 sprintf(name
, "%s Playback Switch", chname
[i
]);
2704 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2705 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2715 static int vt1708B_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2722 spec
->multiout
.hp_nid
= VT1708B_HP_NID
; /* AOW3 */
2723 spec
->hp_independent_mode_index
= 1;
2725 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2726 "Headphone Playback Volume",
2727 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2730 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2731 "Headphone Playback Switch",
2732 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2736 create_hp_imux(spec
);
2741 /* create playback/capture controls for input pins */
2742 static int vt1708B_auto_create_analog_input_ctls(struct via_spec
*spec
,
2743 const struct auto_pin_cfg
*cfg
)
2745 static char *labels
[] = {
2746 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2748 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2749 int i
, err
, idx
= 0;
2751 /* for internal loopback recording select */
2752 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2753 imux
->items
[imux
->num_items
].index
= idx
;
2756 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2757 if (!cfg
->input_pins
[i
])
2760 switch (cfg
->input_pins
[i
]) {
2761 case 0x1a: /* Mic */
2765 case 0x1b: /* Line In */
2769 case 0x1e: /* Front Mic */
2777 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
2780 imux
->items
[imux
->num_items
].label
= labels
[i
];
2781 imux
->items
[imux
->num_items
].index
= idx
;
2787 static int vt1708B_parse_auto_config(struct hda_codec
*codec
)
2789 struct via_spec
*spec
= codec
->spec
;
2792 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2795 err
= vt1708B_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2798 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2799 return 0; /* can't find valid BIOS pin config */
2801 err
= vt1708B_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2804 err
= vt1708B_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2807 err
= vt1708B_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2811 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2813 if (spec
->autocfg
.dig_outs
)
2814 spec
->multiout
.dig_out_nid
= VT1708B_DIGOUT_NID
;
2815 spec
->dig_in_pin
= VT1708B_DIGIN_PIN
;
2816 if (spec
->autocfg
.dig_in_pin
)
2817 spec
->dig_in_nid
= VT1708B_DIGIN_NID
;
2819 if (spec
->kctls
.list
)
2820 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2822 spec
->input_mux
= &spec
->private_imux
[0];
2825 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2827 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
2831 #ifdef CONFIG_SND_HDA_POWER_SAVE
2832 static struct hda_amp_list vt1708B_loopbacks
[] = {
2833 { 0x16, HDA_INPUT
, 1 },
2834 { 0x16, HDA_INPUT
, 2 },
2835 { 0x16, HDA_INPUT
, 3 },
2836 { 0x16, HDA_INPUT
, 4 },
2840 static int patch_vt1708S(struct hda_codec
*codec
);
2841 static int patch_vt1708B_8ch(struct hda_codec
*codec
)
2843 struct via_spec
*spec
;
2846 if (get_codec_type(codec
) == VT1708BCE
)
2847 return patch_vt1708S(codec
);
2848 /* create a codec specific record */
2849 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2855 /* automatic parse from the BIOS config */
2856 err
= vt1708B_parse_auto_config(codec
);
2861 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2862 "from BIOS. Using genenic mode...\n");
2865 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_8ch_volume_init_verbs
;
2866 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2868 spec
->stream_name_analog
= "VT1708B Analog";
2869 spec
->stream_analog_playback
= &vt1708B_8ch_pcm_analog_playback
;
2870 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2872 spec
->stream_name_digital
= "VT1708B Digital";
2873 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2874 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2876 if (!spec
->adc_nids
&& spec
->input_mux
) {
2877 spec
->adc_nids
= vt1708B_adc_nids
;
2878 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2879 get_mux_nids(codec
);
2880 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2884 codec
->patch_ops
= via_patch_ops
;
2886 codec
->patch_ops
.init
= via_auto_init
;
2887 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2888 #ifdef CONFIG_SND_HDA_POWER_SAVE
2889 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2895 static int patch_vt1708B_4ch(struct hda_codec
*codec
)
2897 struct via_spec
*spec
;
2900 /* create a codec specific record */
2901 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2907 /* automatic parse from the BIOS config */
2908 err
= vt1708B_parse_auto_config(codec
);
2913 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2914 "from BIOS. Using genenic mode...\n");
2917 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_4ch_volume_init_verbs
;
2918 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2920 spec
->stream_name_analog
= "VT1708B Analog";
2921 spec
->stream_analog_playback
= &vt1708B_4ch_pcm_analog_playback
;
2922 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2924 spec
->stream_name_digital
= "VT1708B Digital";
2925 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2926 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2928 if (!spec
->adc_nids
&& spec
->input_mux
) {
2929 spec
->adc_nids
= vt1708B_adc_nids
;
2930 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2931 get_mux_nids(codec
);
2932 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2936 codec
->patch_ops
= via_patch_ops
;
2938 codec
->patch_ops
.init
= via_auto_init
;
2939 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2940 #ifdef CONFIG_SND_HDA_POWER_SAVE
2941 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2947 /* Patch for VT1708S */
2949 /* VT1708S software backdoor based override for buggy hardware micboost
2951 #define MIC_BOOST_VOLUME(xname, nid) { \
2952 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2955 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2956 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2957 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2958 .info = mic_boost_volume_info, \
2959 .get = snd_hda_mixer_amp_volume_get, \
2960 .put = snd_hda_mixer_amp_volume_put, \
2961 .tlv = { .c = mic_boost_tlv }, \
2962 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2964 /* capture mixer elements */
2965 static struct snd_kcontrol_new vt1708S_capture_mixer
[] = {
2966 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
2967 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
2968 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
2969 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
2970 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2971 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2973 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2974 /* The multiple "Capture Source" controls confuse alsamixer
2975 * So call somewhat different..
2977 /* .name = "Capture Source", */
2978 .name
= "Input Source",
2980 .info
= via_mux_enum_info
,
2981 .get
= via_mux_enum_get
,
2982 .put
= via_mux_enum_put
,
2987 static struct hda_verb vt1708S_volume_init_verbs
[] = {
2988 /* Unmute ADC0-1 and set the default input to mic-in */
2989 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2990 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2992 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2993 * analog-loopback mixer widget */
2994 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2995 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2996 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2997 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2998 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2999 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3001 /* Setup default input of PW4 to MW0 */
3002 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
3003 /* PW9, PW10 Output enable */
3004 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3005 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3006 /* Enable Mic Boost Volume backdoor */
3011 static struct hda_verb vt1708S_uniwill_init_verbs
[] = {
3012 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
3016 static struct hda_pcm_stream vt1708S_pcm_analog_playback
= {
3020 .nid
= 0x10, /* NID to query formats and rates */
3022 .open
= via_playback_pcm_open
,
3023 .prepare
= via_playback_pcm_prepare
,
3024 .cleanup
= via_playback_pcm_cleanup
,
3025 .close
= via_pcm_open_close
3029 static struct hda_pcm_stream vt1708S_pcm_analog_capture
= {
3033 .nid
= 0x13, /* NID to query formats and rates */
3035 .open
= via_pcm_open_close
,
3036 .prepare
= via_capture_pcm_prepare
,
3037 .cleanup
= via_capture_pcm_cleanup
,
3038 .close
= via_pcm_open_close
3042 static struct hda_pcm_stream vt1708S_pcm_digital_playback
= {
3046 /* NID is set in via_build_pcms */
3048 .open
= via_dig_playback_pcm_open
,
3049 .close
= via_dig_playback_pcm_close
,
3050 .prepare
= via_dig_playback_pcm_prepare
,
3051 .cleanup
= via_dig_playback_pcm_cleanup
3055 /* fill in the dac_nids table from the parsed pin configuration */
3056 static int vt1708S_auto_fill_dac_nids(struct via_spec
*spec
,
3057 const struct auto_pin_cfg
*cfg
)
3062 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3064 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3066 for (i
= 0; i
< 4; i
++) {
3067 nid
= cfg
->line_out_pins
[i
];
3069 /* config dac list */
3071 case AUTO_SEQ_FRONT
:
3072 spec
->multiout
.dac_nids
[i
] = 0x10;
3074 case AUTO_SEQ_CENLFE
:
3075 spec
->multiout
.dac_nids
[i
] = 0x24;
3077 case AUTO_SEQ_SURROUND
:
3078 spec
->multiout
.dac_nids
[i
] = 0x11;
3081 spec
->multiout
.dac_nids
[i
] = 0x25;
3090 /* add playback controls from the parsed DAC table */
3091 static int vt1708S_auto_create_multi_out_ctls(struct via_spec
*spec
,
3092 const struct auto_pin_cfg
*cfg
)
3095 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
3096 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x24, 0x25};
3097 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x26, 0x27};
3098 hda_nid_t nid
, nid_vol
, nid_mute
;
3101 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
3102 nid
= cfg
->line_out_pins
[i
];
3107 nid_vol
= nid_vols
[i
];
3108 nid_mute
= nid_mutes
[i
];
3110 if (i
== AUTO_SEQ_CENLFE
) {
3112 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3113 "Center Playback Volume",
3114 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3118 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3119 "LFE Playback Volume",
3120 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3124 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3125 "Center Playback Switch",
3126 HDA_COMPOSE_AMP_VAL(nid_mute
,
3131 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3132 "LFE Playback Switch",
3133 HDA_COMPOSE_AMP_VAL(nid_mute
,
3138 } else if (i
== AUTO_SEQ_FRONT
) {
3139 /* add control to mixer index 0 */
3140 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3141 "Master Front Playback Volume",
3142 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3146 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3147 "Master Front Playback Switch",
3148 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3154 sprintf(name
, "%s Playback Volume", chname
[i
]);
3155 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3156 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3160 sprintf(name
, "%s Playback Switch", chname
[i
]);
3161 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3162 HDA_COMPOSE_AMP_VAL(nid_mute
,
3168 sprintf(name
, "%s Playback Volume", chname
[i
]);
3169 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3170 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3174 sprintf(name
, "%s Playback Switch", chname
[i
]);
3175 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3176 HDA_COMPOSE_AMP_VAL(nid_mute
,
3187 static int vt1708S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3194 spec
->multiout
.hp_nid
= VT1708S_HP_NID
; /* AOW3 */
3195 spec
->hp_independent_mode_index
= 1;
3197 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3198 "Headphone Playback Volume",
3199 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
3203 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3204 "Headphone Playback Switch",
3205 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3209 create_hp_imux(spec
);
3214 /* create playback/capture controls for input pins */
3215 static int vt1708S_auto_create_analog_input_ctls(struct via_spec
*spec
,
3216 const struct auto_pin_cfg
*cfg
)
3218 static char *labels
[] = {
3219 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3221 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3222 int i
, err
, idx
= 0;
3224 /* for internal loopback recording select */
3225 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3226 imux
->items
[imux
->num_items
].index
= 5;
3229 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3230 if (!cfg
->input_pins
[i
])
3233 switch (cfg
->input_pins
[i
]) {
3234 case 0x1a: /* Mic */
3238 case 0x1b: /* Line In */
3242 case 0x1e: /* Front Mic */
3250 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
3253 imux
->items
[imux
->num_items
].label
= labels
[i
];
3254 imux
->items
[imux
->num_items
].index
= idx
-1;
3260 /* fill out digital output widgets; one for master and one for slave outputs */
3261 static void fill_dig_outs(struct hda_codec
*codec
)
3263 struct via_spec
*spec
= codec
->spec
;
3266 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
3270 nid
= spec
->autocfg
.dig_out_pins
[i
];
3273 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
3276 if (!spec
->multiout
.dig_out_nid
)
3277 spec
->multiout
.dig_out_nid
= nid
;
3279 spec
->slave_dig_outs
[0] = nid
;
3280 break; /* at most two dig outs */
3285 static int vt1708S_parse_auto_config(struct hda_codec
*codec
)
3287 struct via_spec
*spec
= codec
->spec
;
3290 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3293 err
= vt1708S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3296 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3297 return 0; /* can't find valid BIOS pin config */
3299 err
= vt1708S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
3302 err
= vt1708S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3305 err
= vt1708S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3309 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3311 fill_dig_outs(codec
);
3313 if (spec
->kctls
.list
)
3314 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3316 spec
->input_mux
= &spec
->private_imux
[0];
3319 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3321 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
3325 #ifdef CONFIG_SND_HDA_POWER_SAVE
3326 static struct hda_amp_list vt1708S_loopbacks
[] = {
3327 { 0x16, HDA_INPUT
, 1 },
3328 { 0x16, HDA_INPUT
, 2 },
3329 { 0x16, HDA_INPUT
, 3 },
3330 { 0x16, HDA_INPUT
, 4 },
3335 static int patch_vt1708S(struct hda_codec
*codec
)
3337 struct via_spec
*spec
;
3340 /* create a codec specific record */
3341 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3347 /* automatic parse from the BIOS config */
3348 err
= vt1708S_parse_auto_config(codec
);
3353 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3354 "from BIOS. Using genenic mode...\n");
3357 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_volume_init_verbs
;
3358 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_uniwill_init_verbs
;
3360 spec
->stream_name_analog
= "VT1708S Analog";
3361 spec
->stream_analog_playback
= &vt1708S_pcm_analog_playback
;
3362 spec
->stream_analog_capture
= &vt1708S_pcm_analog_capture
;
3364 spec
->stream_name_digital
= "VT1708S Digital";
3365 spec
->stream_digital_playback
= &vt1708S_pcm_digital_playback
;
3367 if (!spec
->adc_nids
&& spec
->input_mux
) {
3368 spec
->adc_nids
= vt1708S_adc_nids
;
3369 spec
->num_adc_nids
= ARRAY_SIZE(vt1708S_adc_nids
);
3370 get_mux_nids(codec
);
3371 spec
->mixers
[spec
->num_mixers
] = vt1708S_capture_mixer
;
3375 codec
->patch_ops
= via_patch_ops
;
3377 codec
->patch_ops
.init
= via_auto_init
;
3378 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3379 #ifdef CONFIG_SND_HDA_POWER_SAVE
3380 spec
->loopback
.amplist
= vt1708S_loopbacks
;
3383 /* correct names for VT1708BCE */
3384 if (get_codec_type(codec
) == VT1708BCE
) {
3385 kfree(codec
->chip_name
);
3386 codec
->chip_name
= kstrdup("VT1708BCE", GFP_KERNEL
);
3387 snprintf(codec
->bus
->card
->mixername
,
3388 sizeof(codec
->bus
->card
->mixername
),
3389 "%s %s", codec
->vendor_name
, codec
->chip_name
);
3390 spec
->stream_name_analog
= "VT1708BCE Analog";
3391 spec
->stream_name_digital
= "VT1708BCE Digital";
3396 /* Patch for VT1702 */
3398 /* capture mixer elements */
3399 static struct snd_kcontrol_new vt1702_capture_mixer
[] = {
3400 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT
),
3401 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT
),
3402 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT
),
3403 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT
),
3404 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT
),
3405 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT
),
3406 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3409 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3410 /* The multiple "Capture Source" controls confuse alsamixer
3411 * So call somewhat different..
3413 /* .name = "Capture Source", */
3414 .name
= "Input Source",
3416 .info
= via_mux_enum_info
,
3417 .get
= via_mux_enum_get
,
3418 .put
= via_mux_enum_put
,
3423 static struct hda_verb vt1702_volume_init_verbs
[] = {
3425 * Unmute ADC0-1 and set the default input to mic-in
3427 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3428 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3429 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3432 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3435 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3436 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3437 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3438 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3439 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3440 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
3442 /* Setup default input of PW4 to MW0 */
3443 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x1},
3444 /* PW6 PW7 Output enable */
3445 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3446 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3450 static struct hda_verb vt1702_uniwill_init_verbs
[] = {
3451 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_GPIO_EVENT
},
3452 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_HP_EVENT
},
3456 static struct hda_pcm_stream vt1702_pcm_analog_playback
= {
3460 .nid
= 0x10, /* NID to query formats and rates */
3462 .open
= via_playback_pcm_open
,
3463 .prepare
= via_playback_multi_pcm_prepare
,
3464 .cleanup
= via_playback_multi_pcm_cleanup
,
3465 .close
= via_pcm_open_close
3469 static struct hda_pcm_stream vt1702_pcm_analog_capture
= {
3473 .nid
= 0x12, /* NID to query formats and rates */
3475 .open
= via_pcm_open_close
,
3476 .prepare
= via_capture_pcm_prepare
,
3477 .cleanup
= via_capture_pcm_cleanup
,
3478 .close
= via_pcm_open_close
3482 static struct hda_pcm_stream vt1702_pcm_digital_playback
= {
3486 /* NID is set in via_build_pcms */
3488 .open
= via_dig_playback_pcm_open
,
3489 .close
= via_dig_playback_pcm_close
,
3490 .prepare
= via_dig_playback_pcm_prepare
,
3491 .cleanup
= via_dig_playback_pcm_cleanup
3495 /* fill in the dac_nids table from the parsed pin configuration */
3496 static int vt1702_auto_fill_dac_nids(struct via_spec
*spec
,
3497 const struct auto_pin_cfg
*cfg
)
3499 spec
->multiout
.num_dacs
= 1;
3500 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3502 if (cfg
->line_out_pins
[0]) {
3503 /* config dac list */
3504 spec
->multiout
.dac_nids
[0] = 0x10;
3510 /* add playback controls from the parsed DAC table */
3511 static int vt1702_auto_create_line_out_ctls(struct via_spec
*spec
,
3512 const struct auto_pin_cfg
*cfg
)
3516 if (!cfg
->line_out_pins
[0])
3519 /* add control to mixer index 0 */
3520 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3521 "Master Front Playback Volume",
3522 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3525 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3526 "Master Front Playback Switch",
3527 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3532 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3533 "Front Playback Volume",
3534 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
));
3537 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3538 "Front Playback Switch",
3539 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT
));
3546 static int vt1702_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3549 struct hda_input_mux
*imux
;
3550 static const char *texts
[] = { "ON", "OFF", NULL
};
3553 spec
->multiout
.hp_nid
= 0x1D;
3554 spec
->hp_independent_mode_index
= 0;
3556 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3557 "Headphone Playback Volume",
3558 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT
));
3562 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3563 "Headphone Playback Switch",
3564 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3568 imux
= &spec
->private_imux
[1];
3570 /* for hp mode select */
3572 while (texts
[i
] != NULL
) {
3573 imux
->items
[imux
->num_items
].label
= texts
[i
];
3574 imux
->items
[imux
->num_items
].index
= i
;
3579 spec
->hp_mux
= &spec
->private_imux
[1];
3583 /* create playback/capture controls for input pins */
3584 static int vt1702_auto_create_analog_input_ctls(struct via_spec
*spec
,
3585 const struct auto_pin_cfg
*cfg
)
3587 static char *labels
[] = {
3588 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3590 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3591 int i
, err
, idx
= 0;
3593 /* for internal loopback recording select */
3594 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3595 imux
->items
[imux
->num_items
].index
= 3;
3598 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3599 if (!cfg
->input_pins
[i
])
3602 switch (cfg
->input_pins
[i
]) {
3603 case 0x14: /* Mic */
3607 case 0x15: /* Line In */
3611 case 0x18: /* Front Mic */
3615 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x1A);
3618 imux
->items
[imux
->num_items
].label
= labels
[i
];
3619 imux
->items
[imux
->num_items
].index
= idx
-1;
3625 static int vt1702_parse_auto_config(struct hda_codec
*codec
)
3627 struct via_spec
*spec
= codec
->spec
;
3630 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3633 err
= vt1702_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3636 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3637 return 0; /* can't find valid BIOS pin config */
3639 err
= vt1702_auto_create_line_out_ctls(spec
, &spec
->autocfg
);
3642 err
= vt1702_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3645 /* limit AA path volume to 0 dB */
3646 snd_hda_override_amp_caps(codec
, 0x1A, HDA_INPUT
,
3647 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
3648 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
3649 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
3650 (1 << AC_AMPCAP_MUTE_SHIFT
));
3651 err
= vt1702_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3655 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3657 fill_dig_outs(codec
);
3659 if (spec
->kctls
.list
)
3660 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3662 spec
->input_mux
= &spec
->private_imux
[0];
3665 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3670 #ifdef CONFIG_SND_HDA_POWER_SAVE
3671 static struct hda_amp_list vt1702_loopbacks
[] = {
3672 { 0x1A, HDA_INPUT
, 1 },
3673 { 0x1A, HDA_INPUT
, 2 },
3674 { 0x1A, HDA_INPUT
, 3 },
3675 { 0x1A, HDA_INPUT
, 4 },
3680 static int patch_vt1702(struct hda_codec
*codec
)
3682 struct via_spec
*spec
;
3684 unsigned int response
;
3685 unsigned char control
;
3687 /* create a codec specific record */
3688 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3694 /* automatic parse from the BIOS config */
3695 err
= vt1702_parse_auto_config(codec
);
3700 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3701 "from BIOS. Using genenic mode...\n");
3704 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_volume_init_verbs
;
3705 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_uniwill_init_verbs
;
3707 spec
->stream_name_analog
= "VT1702 Analog";
3708 spec
->stream_analog_playback
= &vt1702_pcm_analog_playback
;
3709 spec
->stream_analog_capture
= &vt1702_pcm_analog_capture
;
3711 spec
->stream_name_digital
= "VT1702 Digital";
3712 spec
->stream_digital_playback
= &vt1702_pcm_digital_playback
;
3714 if (!spec
->adc_nids
&& spec
->input_mux
) {
3715 spec
->adc_nids
= vt1702_adc_nids
;
3716 spec
->num_adc_nids
= ARRAY_SIZE(vt1702_adc_nids
);
3717 get_mux_nids(codec
);
3718 spec
->mixers
[spec
->num_mixers
] = vt1702_capture_mixer
;
3722 codec
->patch_ops
= via_patch_ops
;
3724 codec
->patch_ops
.init
= via_auto_init
;
3725 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3726 #ifdef CONFIG_SND_HDA_POWER_SAVE
3727 spec
->loopback
.amplist
= vt1702_loopbacks
;
3731 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF8C, 0);
3732 control
= (unsigned char)(response
& 0xff);
3734 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF88, control
);
3736 /* Enable GPIO 0&1 for volume&mute control */
3737 /* Enable GPIO 2 for DMIC-DATA */
3738 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF84, 0);
3739 control
= (unsigned char)((response
>> 16) & 0x3f);
3740 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF82, control
);
3748 static struct hda_codec_preset snd_hda_preset_via
[] = {
3749 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
3750 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
3751 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
3752 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
3753 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
3754 .patch
= patch_vt1709_10ch
},
3755 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
3756 .patch
= patch_vt1709_10ch
},
3757 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
3758 .patch
= patch_vt1709_10ch
},
3759 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
3760 .patch
= patch_vt1709_10ch
},
3761 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
3762 .patch
= patch_vt1709_6ch
},
3763 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
3764 .patch
= patch_vt1709_6ch
},
3765 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
3766 .patch
= patch_vt1709_6ch
},
3767 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
3768 .patch
= patch_vt1709_6ch
},
3769 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
3770 .patch
= patch_vt1708B_8ch
},
3771 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
3772 .patch
= patch_vt1708B_8ch
},
3773 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
3774 .patch
= patch_vt1708B_8ch
},
3775 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
3776 .patch
= patch_vt1708B_8ch
},
3777 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
3778 .patch
= patch_vt1708B_4ch
},
3779 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
3780 .patch
= patch_vt1708B_4ch
},
3781 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
3782 .patch
= patch_vt1708B_4ch
},
3783 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
3784 .patch
= patch_vt1708B_4ch
},
3785 { .id
= 0x11060397, .name
= "VT1708S",
3786 .patch
= patch_vt1708S
},
3787 { .id
= 0x11061397, .name
= "VT1708S",
3788 .patch
= patch_vt1708S
},
3789 { .id
= 0x11062397, .name
= "VT1708S",
3790 .patch
= patch_vt1708S
},
3791 { .id
= 0x11063397, .name
= "VT1708S",
3792 .patch
= patch_vt1708S
},
3793 { .id
= 0x11064397, .name
= "VT1708S",
3794 .patch
= patch_vt1708S
},
3795 { .id
= 0x11065397, .name
= "VT1708S",
3796 .patch
= patch_vt1708S
},
3797 { .id
= 0x11066397, .name
= "VT1708S",
3798 .patch
= patch_vt1708S
},
3799 { .id
= 0x11067397, .name
= "VT1708S",
3800 .patch
= patch_vt1708S
},
3801 { .id
= 0x11060398, .name
= "VT1702",
3802 .patch
= patch_vt1702
},
3803 { .id
= 0x11061398, .name
= "VT1702",
3804 .patch
= patch_vt1702
},
3805 { .id
= 0x11062398, .name
= "VT1702",
3806 .patch
= patch_vt1702
},
3807 { .id
= 0x11063398, .name
= "VT1702",
3808 .patch
= patch_vt1702
},
3809 { .id
= 0x11064398, .name
= "VT1702",
3810 .patch
= patch_vt1702
},
3811 { .id
= 0x11065398, .name
= "VT1702",
3812 .patch
= patch_vt1702
},
3813 { .id
= 0x11066398, .name
= "VT1702",
3814 .patch
= patch_vt1702
},
3815 { .id
= 0x11067398, .name
= "VT1702",
3816 .patch
= patch_vt1702
},
3820 MODULE_ALIAS("snd-hda-codec-id:1106*");
3822 static struct hda_codec_preset_list via_list
= {
3823 .preset
= snd_hda_preset_via
,
3824 .owner
= THIS_MODULE
,
3827 MODULE_LICENSE("GPL");
3828 MODULE_DESCRIPTION("VIA HD-audio codec");
3830 static int __init
patch_via_init(void)
3832 return snd_hda_add_codec_preset(&via_list
);
3835 static void __exit
patch_via_exit(void)
3837 snd_hda_delete_codec_preset(&via_list
);
3840 module_init(patch_via_init
)
3841 module_exit(patch_via_exit
)