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
93 /* codec parameterization */
94 struct snd_kcontrol_new
*mixers
[4];
95 unsigned int num_mixers
;
97 struct hda_verb
*init_verbs
[5];
98 unsigned int num_iverbs
;
100 char *stream_name_analog
;
101 struct hda_pcm_stream
*stream_analog_playback
;
102 struct hda_pcm_stream
*stream_analog_capture
;
104 char *stream_name_digital
;
105 struct hda_pcm_stream
*stream_digital_playback
;
106 struct hda_pcm_stream
*stream_digital_capture
;
109 struct hda_multi_out multiout
;
110 hda_nid_t slave_dig_outs
[2];
113 unsigned int num_adc_nids
;
115 hda_nid_t mux_nids
[3];
116 hda_nid_t dig_in_nid
;
117 hda_nid_t dig_in_pin
;
120 const struct hda_input_mux
*input_mux
;
121 unsigned int cur_mux
[3];
123 /* PCM information */
124 struct hda_pcm pcm_rec
[3];
126 /* dynamic controls, init_verbs and input_mux */
127 struct auto_pin_cfg autocfg
;
128 struct snd_array kctls
;
129 struct hda_input_mux private_imux
[2];
130 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
133 const struct hda_input_mux
*hp_mux
;
134 unsigned int hp_independent_mode
;
135 unsigned int hp_independent_mode_index
;
136 unsigned int smart51_enabled
;
138 enum VIA_HDA_CODEC codec_type
;
140 /* work to check hp jack state */
141 struct hda_codec
*codec
;
142 struct delayed_work vt1708_hp_work
;
143 int vt1708_jack_detectect
;
144 int vt1708_hp_present
;
145 #ifdef CONFIG_SND_HDA_POWER_SAVE
146 struct hda_loopback_check loopback
;
150 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
)
152 u32 vendor_id
= codec
->vendor_id
;
153 u16 ven_id
= vendor_id
>> 16;
154 u16 dev_id
= vendor_id
& 0xffff;
155 enum VIA_HDA_CODEC codec_type
;
158 if (ven_id
!= 0x1106)
159 codec_type
= UNKNOWN
;
160 else if (dev_id
>= 0x1708 && dev_id
<= 0x170b)
162 else if (dev_id
>= 0xe710 && dev_id
<= 0xe713)
163 codec_type
= VT1709_10CH
;
164 else if (dev_id
>= 0xe714 && dev_id
<= 0xe717)
165 codec_type
= VT1709_6CH
;
166 else if (dev_id
>= 0xe720 && dev_id
<= 0xe723) {
167 codec_type
= VT1708B_8CH
;
168 if (snd_hda_param_read(codec
, 0x16, AC_PAR_CONNLIST_LEN
) == 0x7)
169 codec_type
= VT1708BCE
;
170 } else if (dev_id
>= 0xe724 && dev_id
<= 0xe727)
171 codec_type
= VT1708B_4CH
;
172 else if ((dev_id
& 0xfff) == 0x397
173 && (dev_id
>> 12) < 8)
174 codec_type
= VT1708S
;
175 else if ((dev_id
& 0xfff) == 0x398
176 && (dev_id
>> 12) < 8)
179 codec_type
= UNKNOWN
;
183 #define VIA_HP_EVENT 0x01
184 #define VIA_GPIO_EVENT 0x02
185 #define VIA_JACK_EVENT 0x04
190 VIA_CTL_WIDGET_ANALOG_MUTE
,
200 /* Some VT1708S based boards gets the micboost setting wrong, so we have
201 * to apply some brute-force and re-write the TLV's by software. */
202 static int mic_boost_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
203 unsigned int size
, unsigned int __user
*_tlv
)
205 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
206 hda_nid_t nid
= get_amp_nid(kcontrol
);
208 if (get_codec_type(codec
) == VT1708S
209 && (nid
== 0x1a || nid
== 0x1e)) {
210 if (size
< 4 * sizeof(unsigned int))
212 if (put_user(1, _tlv
)) /* SNDRV_CTL_TLVT_DB_SCALE */
214 if (put_user(2 * sizeof(unsigned int), _tlv
+ 1))
216 if (put_user(0, _tlv
+ 2)) /* offset = 0 */
218 if (put_user(1000, _tlv
+ 3)) /* step size = 10 dB */
224 static int mic_boost_volume_info(struct snd_kcontrol
*kcontrol
,
225 struct snd_ctl_elem_info
*uinfo
)
227 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
228 hda_nid_t nid
= get_amp_nid(kcontrol
);
230 if (get_codec_type(codec
) == VT1708S
231 && (nid
== 0x1a || nid
== 0x1e)) {
232 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
234 uinfo
->value
.integer
.min
= 0;
235 uinfo
->value
.integer
.max
= 3;
240 static void analog_low_current_mode(struct hda_codec
*codec
, int stream_idle
);
241 static void set_jack_power_state(struct hda_codec
*codec
);
242 static int is_aa_path_mute(struct hda_codec
*codec
);
244 static void vt1708_start_hp_work(struct via_spec
*spec
)
246 if (spec
->codec_type
!= VT1708
|| spec
->autocfg
.hp_pins
[0] == 0)
248 snd_hda_codec_write(spec
->codec
, 0x1, 0, 0xf81,
249 !spec
->vt1708_jack_detectect
);
250 if (!delayed_work_pending(&spec
->vt1708_hp_work
))
251 schedule_delayed_work(&spec
->vt1708_hp_work
,
252 msecs_to_jiffies(100));
255 static void vt1708_stop_hp_work(struct via_spec
*spec
)
257 if (spec
->codec_type
!= VT1708
|| spec
->autocfg
.hp_pins
[0] == 0)
259 if (snd_hda_get_bool_hint(spec
->codec
, "analog_loopback_hp_detect") == 1
260 && !is_aa_path_mute(spec
->codec
))
262 snd_hda_codec_write(spec
->codec
, 0x1, 0, 0xf81,
263 !spec
->vt1708_jack_detectect
);
264 cancel_delayed_work(&spec
->vt1708_hp_work
);
265 flush_scheduled_work();
268 static int analog_input_switch_put(struct snd_kcontrol
*kcontrol
,
269 struct snd_ctl_elem_value
*ucontrol
)
271 int change
= snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
272 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
274 set_jack_power_state(codec
);
275 analog_low_current_mode(snd_kcontrol_chip(kcontrol
), -1);
276 if (snd_hda_get_bool_hint(codec
, "analog_loopback_hp_detect") == 1) {
277 if (is_aa_path_mute(codec
))
278 vt1708_start_hp_work(codec
->spec
);
280 vt1708_stop_hp_work(codec
->spec
);
285 /* modify .put = snd_hda_mixer_amp_switch_put */
286 #define ANALOG_INPUT_MUTE \
287 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
290 .info = snd_hda_mixer_amp_switch_info, \
291 .get = snd_hda_mixer_amp_switch_get, \
292 .put = analog_input_switch_put, \
293 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
295 static struct snd_kcontrol_new vt1708_control_templates
[] = {
296 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
297 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
302 static hda_nid_t vt1708_adc_nids
[2] = {
307 static hda_nid_t vt1709_adc_nids
[3] = {
312 static hda_nid_t vt1708B_adc_nids
[2] = {
317 static hda_nid_t vt1708S_adc_nids
[2] = {
322 static hda_nid_t vt1702_adc_nids
[3] = {
327 /* add dynamic controls */
328 static int via_add_control(struct via_spec
*spec
, int type
, const char *name
,
331 struct snd_kcontrol_new
*knew
;
333 snd_array_init(&spec
->kctls
, sizeof(*knew
), 32);
334 knew
= snd_array_new(&spec
->kctls
);
337 *knew
= vt1708_control_templates
[type
];
338 knew
->name
= kstrdup(name
, GFP_KERNEL
);
341 knew
->private_value
= val
;
345 static void via_free_kctls(struct hda_codec
*codec
)
347 struct via_spec
*spec
= codec
->spec
;
349 if (spec
->kctls
.list
) {
350 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
352 for (i
= 0; i
< spec
->kctls
.used
; i
++)
355 snd_array_free(&spec
->kctls
);
358 /* create input playback/capture controls for the given pin */
359 static int via_new_analog_input(struct via_spec
*spec
, const char *ctlname
,
360 int idx
, int mix_nid
)
365 sprintf(name
, "%s Playback Volume", ctlname
);
366 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
367 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
370 sprintf(name
, "%s Playback Switch", ctlname
);
371 err
= via_add_control(spec
, VIA_CTL_WIDGET_ANALOG_MUTE
, name
,
372 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
378 static void via_auto_set_output_and_unmute(struct hda_codec
*codec
,
379 hda_nid_t nid
, int pin_type
,
383 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
385 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
387 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
388 snd_hda_codec_write(codec
, nid
, 0,
389 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
393 static void via_auto_init_multi_out(struct hda_codec
*codec
)
395 struct via_spec
*spec
= codec
->spec
;
398 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
399 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
401 via_auto_set_output_and_unmute(codec
, nid
, PIN_OUT
, i
);
405 static void via_auto_init_hp_out(struct hda_codec
*codec
)
407 struct via_spec
*spec
= codec
->spec
;
410 pin
= spec
->autocfg
.hp_pins
[0];
411 if (pin
) /* connect to front */
412 via_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, 0);
415 static void via_auto_init_analog_input(struct hda_codec
*codec
)
417 struct via_spec
*spec
= codec
->spec
;
420 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
421 hda_nid_t nid
= spec
->autocfg
.input_pins
[i
];
423 snd_hda_codec_write(codec
, nid
, 0,
424 AC_VERB_SET_PIN_WIDGET_CONTROL
,
425 (i
<= AUTO_PIN_FRONT_MIC
?
426 PIN_VREF50
: PIN_IN
));
431 static int is_smart51_pins(struct via_spec
*spec
, hda_nid_t pin
);
433 static void set_pin_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
434 unsigned int *affected_parm
)
437 unsigned def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
438 unsigned no_presence
= (def_conf
& AC_DEFCFG_MISC
)
439 >> AC_DEFCFG_MISC_SHIFT
440 & AC_DEFCFG_MISC_NO_PRESENCE
; /* do not support pin sense */
441 unsigned present
= snd_hda_codec_read(codec
, nid
, 0,
442 AC_VERB_GET_PIN_SENSE
, 0) >> 31;
443 struct via_spec
*spec
= codec
->spec
;
444 if ((spec
->smart51_enabled
&& is_smart51_pins(spec
, nid
))
445 || ((no_presence
|| present
)
446 && get_defcfg_connect(def_conf
) != AC_JACK_PORT_NONE
)) {
447 *affected_parm
= AC_PWRST_D0
; /* if it's connected */
452 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
455 static void set_jack_power_state(struct hda_codec
*codec
)
457 struct via_spec
*spec
= codec
->spec
;
461 if (spec
->codec_type
== VT1702
) {
462 imux_is_smixer
= snd_hda_codec_read(
463 codec
, 0x13, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
465 /* PW 1/2/5 (14h/15h/18h) */
467 set_pin_power_state(codec
, 0x14, &parm
);
468 set_pin_power_state(codec
, 0x15, &parm
);
469 set_pin_power_state(codec
, 0x18, &parm
);
471 parm
= AC_PWRST_D0
; /* SW0 = stereo mixer (idx 3) */
472 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
473 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
475 snd_hda_codec_write(codec
, 0x12, 0, AC_VERB_SET_POWER_STATE
,
477 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
,
479 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_POWER_STATE
,
483 /* PW 3/4 (16h/17h) */
485 set_pin_power_state(codec
, 0x16, &parm
);
486 set_pin_power_state(codec
, 0x17, &parm
);
487 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
488 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_POWER_STATE
,
489 imux_is_smixer
? AC_PWRST_D0
: parm
);
490 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
492 snd_hda_codec_write(codec
, 0x1d, 0, AC_VERB_SET_POWER_STATE
,
494 } else if (spec
->codec_type
== VT1708B_8CH
495 || spec
->codec_type
== VT1708B_4CH
496 || spec
->codec_type
== VT1708S
) {
497 /* SW0 (17h) = stereo mixer */
498 int is_8ch
= spec
->codec_type
!= VT1708B_4CH
;
499 imux_is_smixer
= snd_hda_codec_read(
500 codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00)
501 == ((spec
->codec_type
== VT1708S
) ? 5 : 0);
503 /* PW 1/2/5 (1ah/1bh/1eh) */
505 set_pin_power_state(codec
, 0x1a, &parm
);
506 set_pin_power_state(codec
, 0x1b, &parm
);
507 set_pin_power_state(codec
, 0x1e, &parm
);
510 /* SW0 (17h), AIW 0/1 (13h/14h) */
511 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_POWER_STATE
,
513 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
515 snd_hda_codec_write(codec
, 0x14, 0, AC_VERB_SET_POWER_STATE
,
519 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
521 set_pin_power_state(codec
, 0x19, &parm
);
522 snd_hda_codec_write(codec
, 0x18, 0, AC_VERB_SET_POWER_STATE
,
524 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
,
527 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
530 set_pin_power_state(codec
, 0x22, &parm
);
531 snd_hda_codec_write(codec
, 0x26, 0,
532 AC_VERB_SET_POWER_STATE
, parm
);
533 snd_hda_codec_write(codec
, 0x24, 0,
534 AC_VERB_SET_POWER_STATE
, parm
);
537 /* PW 3/4/7 (1ch/1dh/23h) */
539 /* force to D0 for internal Speaker */
540 set_pin_power_state(codec
, 0x1c, &parm
);
541 set_pin_power_state(codec
, 0x1d, &parm
);
543 set_pin_power_state(codec
, 0x23, &parm
);
544 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
545 snd_hda_codec_write(codec
, 0x16, 0, AC_VERB_SET_POWER_STATE
,
546 imux_is_smixer
? AC_PWRST_D0
: parm
);
547 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
550 snd_hda_codec_write(codec
, 0x25, 0,
551 AC_VERB_SET_POWER_STATE
, parm
);
552 snd_hda_codec_write(codec
, 0x27, 0,
553 AC_VERB_SET_POWER_STATE
, parm
);
561 static int via_mux_enum_info(struct snd_kcontrol
*kcontrol
,
562 struct snd_ctl_elem_info
*uinfo
)
564 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
565 struct via_spec
*spec
= codec
->spec
;
566 return snd_hda_input_mux_info(spec
->input_mux
, uinfo
);
569 static int via_mux_enum_get(struct snd_kcontrol
*kcontrol
,
570 struct snd_ctl_elem_value
*ucontrol
)
572 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
573 struct via_spec
*spec
= codec
->spec
;
574 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
576 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
580 static int via_mux_enum_put(struct snd_kcontrol
*kcontrol
,
581 struct snd_ctl_elem_value
*ucontrol
)
583 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
584 struct via_spec
*spec
= codec
->spec
;
585 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
587 if (!spec
->mux_nids
[adc_idx
])
589 /* switch to D0 beofre change index */
590 if (snd_hda_codec_read(codec
, spec
->mux_nids
[adc_idx
], 0,
591 AC_VERB_GET_POWER_STATE
, 0x00) != AC_PWRST_D0
)
592 snd_hda_codec_write(codec
, spec
->mux_nids
[adc_idx
], 0,
593 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
594 /* update jack power state */
595 set_jack_power_state(codec
);
597 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
598 spec
->mux_nids
[adc_idx
],
599 &spec
->cur_mux
[adc_idx
]);
602 static int via_independent_hp_info(struct snd_kcontrol
*kcontrol
,
603 struct snd_ctl_elem_info
*uinfo
)
605 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
606 struct via_spec
*spec
= codec
->spec
;
607 return snd_hda_input_mux_info(spec
->hp_mux
, uinfo
);
610 static int via_independent_hp_get(struct snd_kcontrol
*kcontrol
,
611 struct snd_ctl_elem_value
*ucontrol
)
613 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
614 struct via_spec
*spec
= codec
->spec
;
615 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
616 unsigned int pinsel
= snd_hda_codec_read(codec
, nid
, 0,
617 AC_VERB_GET_CONNECT_SEL
,
620 ucontrol
->value
.enumerated
.item
[0] = pinsel
;
625 static void activate_ctl(struct hda_codec
*codec
, const char *name
, int active
)
627 struct snd_kcontrol
*ctl
= snd_hda_find_mixer_ctl(codec
, name
);
629 ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
630 ctl
->vd
[0].access
|= active
631 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
632 snd_ctl_notify(codec
->bus
->card
,
633 SNDRV_CTL_EVENT_MASK_VALUE
, &ctl
->id
);
637 static int update_side_mute_status(struct hda_codec
*codec
)
639 /* mute side channel */
640 struct via_spec
*spec
= codec
->spec
;
641 unsigned int parm
= spec
->hp_independent_mode
642 ? AMP_OUT_MUTE
: AMP_OUT_UNMUTE
;
645 switch (spec
->codec_type
) {
662 snd_hda_codec_write(codec
, sw3
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
667 static int via_independent_hp_put(struct snd_kcontrol
*kcontrol
,
668 struct snd_ctl_elem_value
*ucontrol
)
670 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
671 struct via_spec
*spec
= codec
->spec
;
672 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
673 unsigned int pinsel
= ucontrol
->value
.enumerated
.item
[0];
674 /* Get Independent Mode index of headphone pin widget */
675 spec
->hp_independent_mode
= spec
->hp_independent_mode_index
== pinsel
678 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, pinsel
);
680 if (spec
->multiout
.hp_nid
&& spec
->multiout
.hp_nid
681 != spec
->multiout
.dac_nids
[HDA_FRONT
])
682 snd_hda_codec_setup_stream(codec
, spec
->multiout
.hp_nid
,
685 update_side_mute_status(codec
);
686 /* update HP volume/swtich active state */
687 if (spec
->codec_type
== VT1708S
688 || spec
->codec_type
== VT1702
) {
689 activate_ctl(codec
, "Headphone Playback Volume",
690 spec
->hp_independent_mode
);
691 activate_ctl(codec
, "Headphone Playback Switch",
692 spec
->hp_independent_mode
);
697 static struct snd_kcontrol_new via_hp_mixer
[] = {
699 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
700 .name
= "Independent HP",
702 .info
= via_independent_hp_info
,
703 .get
= via_independent_hp_get
,
704 .put
= via_independent_hp_put
,
709 static void notify_aa_path_ctls(struct hda_codec
*codec
)
712 struct snd_ctl_elem_id id
;
713 const char *labels
[] = {"Mic", "Front Mic", "Line"};
715 memset(&id
, 0, sizeof(id
));
716 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
717 for (i
= 0; i
< ARRAY_SIZE(labels
); i
++) {
718 sprintf(id
.name
, "%s Playback Volume", labels
[i
]);
719 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
724 static void mute_aa_path(struct hda_codec
*codec
, int mute
)
726 struct via_spec
*spec
= codec
->spec
;
731 /* get nid of MW0 and start & end index */
732 switch (spec
->codec_type
) {
754 /* check AA path's mute status */
755 for (i
= start_idx
; i
<= end_idx
; i
++) {
756 int val
= mute
? HDA_AMP_MUTE
: HDA_AMP_UNMUTE
;
757 snd_hda_codec_amp_stereo(codec
, nid_mixer
, HDA_INPUT
, i
,
761 static int is_smart51_pins(struct via_spec
*spec
, hda_nid_t pin
)
765 for (index
= AUTO_PIN_MIC
; index
< AUTO_PIN_FRONT_LINE
; index
++) {
766 if (pin
== spec
->autocfg
.input_pins
[index
]) {
774 static int via_smart51_info(struct snd_kcontrol
*kcontrol
,
775 struct snd_ctl_elem_info
*uinfo
)
777 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
779 uinfo
->value
.integer
.min
= 0;
780 uinfo
->value
.integer
.max
= 1;
784 static int via_smart51_get(struct snd_kcontrol
*kcontrol
,
785 struct snd_ctl_elem_value
*ucontrol
)
787 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
788 struct via_spec
*spec
= codec
->spec
;
789 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
793 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
794 hda_nid_t nid
= spec
->autocfg
.input_pins
[index
[i
]];
797 snd_hda_codec_read(codec
, nid
, 0,
798 AC_VERB_GET_PIN_WIDGET_CONTROL
,
800 if (i
== AUTO_PIN_FRONT_MIC
801 && spec
->hp_independent_mode
)
802 continue; /* ignore FMic for independent HP */
803 if (ctl
& AC_PINCTL_IN_EN
804 && !(ctl
& AC_PINCTL_OUT_EN
))
808 *ucontrol
->value
.integer
.value
= on
;
812 static int via_smart51_put(struct snd_kcontrol
*kcontrol
,
813 struct snd_ctl_elem_value
*ucontrol
)
815 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
816 struct via_spec
*spec
= codec
->spec
;
817 int out_in
= *ucontrol
->value
.integer
.value
818 ? AC_PINCTL_OUT_EN
: AC_PINCTL_IN_EN
;
819 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
822 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
823 hda_nid_t nid
= spec
->autocfg
.input_pins
[index
[i
]];
824 if (i
== AUTO_PIN_FRONT_MIC
825 && spec
->hp_independent_mode
)
826 continue; /* don't retask FMic for independent HP */
828 unsigned int parm
= snd_hda_codec_read(
830 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
831 parm
&= ~(AC_PINCTL_IN_EN
| AC_PINCTL_OUT_EN
);
833 snd_hda_codec_write(codec
, nid
, 0,
834 AC_VERB_SET_PIN_WIDGET_CONTROL
,
836 if (out_in
== AC_PINCTL_OUT_EN
) {
837 mute_aa_path(codec
, 1);
838 notify_aa_path_ctls(codec
);
841 if (i
== AUTO_PIN_FRONT_MIC
) {
842 if (spec
->codec_type
== VT1708S
) {
843 /* input = index 1 (AOW3) */
846 AC_VERB_SET_CONNECT_SEL
, 1);
847 snd_hda_codec_amp_stereo(
848 codec
, nid
, HDA_OUTPUT
,
849 0, HDA_AMP_MUTE
, HDA_AMP_UNMUTE
);
853 spec
->smart51_enabled
= *ucontrol
->value
.integer
.value
;
854 set_jack_power_state(codec
);
858 static struct snd_kcontrol_new via_smart51_mixer
[] = {
860 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
863 .info
= via_smart51_info
,
864 .get
= via_smart51_get
,
865 .put
= via_smart51_put
,
870 /* capture mixer elements */
871 static struct snd_kcontrol_new vt1708_capture_mixer
[] = {
872 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT
),
873 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT
),
874 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT
),
875 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT
),
877 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
878 /* The multiple "Capture Source" controls confuse alsamixer
879 * So call somewhat different..
881 /* .name = "Capture Source", */
882 .name
= "Input Source",
884 .info
= via_mux_enum_info
,
885 .get
= via_mux_enum_get
,
886 .put
= via_mux_enum_put
,
891 /* check AA path's mute statue */
892 static int is_aa_path_mute(struct hda_codec
*codec
)
899 struct via_spec
*spec
= codec
->spec
;
900 /* get nid of MW0 and start & end index */
901 switch (spec
->codec_type
) {
917 /* check AA path's mute status */
918 for (i
= start_idx
; i
<= end_idx
; i
++) {
919 unsigned int con_list
= snd_hda_codec_read(
920 codec
, nid_mixer
, 0, AC_VERB_GET_CONNECT_LIST
, i
/4*4);
921 int shift
= 8 * (i
% 4);
922 hda_nid_t nid_pin
= (con_list
& (0xff << shift
)) >> shift
;
923 unsigned int defconf
= snd_hda_codec_get_pincfg(codec
, nid_pin
);
924 if (get_defcfg_connect(defconf
) == AC_JACK_PORT_COMPLEX
) {
925 /* check mute status while the pin is connected */
926 int mute_l
= snd_hda_codec_amp_read(codec
, nid_mixer
, 0,
928 int mute_r
= snd_hda_codec_amp_read(codec
, nid_mixer
, 1,
930 if (!mute_l
|| !mute_r
) {
939 /* enter/exit analog low-current mode */
940 static void analog_low_current_mode(struct hda_codec
*codec
, int stream_idle
)
942 struct via_spec
*spec
= codec
->spec
;
943 static int saved_stream_idle
= 1; /* saved stream idle status */
944 int enable
= is_aa_path_mute(codec
);
945 unsigned int verb
= 0;
946 unsigned int parm
= 0;
948 if (stream_idle
== -1) /* stream status did not change */
949 enable
= enable
&& saved_stream_idle
;
951 enable
= enable
&& stream_idle
;
952 saved_stream_idle
= stream_idle
;
955 /* decide low current mode's verb & parameter */
956 switch (spec
->codec_type
) {
960 parm
= enable
? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
964 parm
= enable
? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
968 parm
= enable
? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
971 return; /* other codecs are not supported */
974 snd_hda_codec_write(codec
, codec
->afg
, 0, verb
, parm
);
978 * generic initialization of ADC, input mixers and output mixers
980 static struct hda_verb vt1708_volume_init_verbs
[] = {
982 * Unmute ADC0-1 and set the default input to mic-in
984 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
985 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
988 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
991 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
992 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
993 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
994 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
995 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
996 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
999 * Set up output mixers (0x19 - 0x1b)
1001 /* set vol=0 to output mixers */
1002 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1003 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1004 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1006 /* Setup default input to PW4 */
1007 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
1008 /* PW9 Output enable */
1009 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1013 static int via_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1014 struct hda_codec
*codec
,
1015 struct snd_pcm_substream
*substream
)
1017 struct via_spec
*spec
= codec
->spec
;
1018 int idle
= substream
->pstr
->substream_opened
== 1
1019 && substream
->ref_count
== 0;
1020 analog_low_current_mode(codec
, idle
);
1021 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
1025 static int via_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1026 struct hda_codec
*codec
,
1027 unsigned int stream_tag
,
1028 unsigned int format
,
1029 struct snd_pcm_substream
*substream
)
1031 struct via_spec
*spec
= codec
->spec
;
1032 vt1708_start_hp_work(spec
);
1033 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
1034 stream_tag
, format
, substream
);
1037 static int via_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1038 struct hda_codec
*codec
,
1039 struct snd_pcm_substream
*substream
)
1041 struct via_spec
*spec
= codec
->spec
;
1042 vt1708_stop_hp_work(spec
);
1043 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
1047 static void playback_multi_pcm_prep_0(struct hda_codec
*codec
,
1048 unsigned int stream_tag
,
1049 unsigned int format
,
1050 struct snd_pcm_substream
*substream
)
1052 struct via_spec
*spec
= codec
->spec
;
1053 struct hda_multi_out
*mout
= &spec
->multiout
;
1054 hda_nid_t
*nids
= mout
->dac_nids
;
1055 int chs
= substream
->runtime
->channels
;
1058 mutex_lock(&codec
->spdif_mutex
);
1059 if (mout
->dig_out_nid
&& mout
->dig_out_used
!= HDA_DIG_EXCLUSIVE
) {
1061 snd_hda_is_supported_format(codec
, mout
->dig_out_nid
,
1063 !(codec
->spdif_status
& IEC958_AES0_NONAUDIO
)) {
1064 mout
->dig_out_used
= HDA_DIG_ANALOG_DUP
;
1065 /* turn off SPDIF once; otherwise the IEC958 bits won't
1067 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1068 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1069 AC_VERB_SET_DIGI_CONVERT_1
,
1071 ~AC_DIG1_ENABLE
& 0xff);
1072 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1073 stream_tag
, 0, format
);
1074 /* turn on again (if needed) */
1075 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1076 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1077 AC_VERB_SET_DIGI_CONVERT_1
,
1078 codec
->spdif_ctls
& 0xff);
1080 mout
->dig_out_used
= 0;
1081 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1085 mutex_unlock(&codec
->spdif_mutex
);
1088 snd_hda_codec_setup_stream(codec
, nids
[HDA_FRONT
], stream_tag
,
1091 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1092 !spec
->hp_independent_mode
)
1093 /* headphone out will just decode front left/right (stereo) */
1094 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
, stream_tag
,
1097 /* extra outputs copied from front */
1098 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1099 if (mout
->extra_out_nid
[i
])
1100 snd_hda_codec_setup_stream(codec
,
1101 mout
->extra_out_nid
[i
],
1102 stream_tag
, 0, format
);
1105 for (i
= 1; i
< mout
->num_dacs
; i
++) {
1106 if (chs
>= (i
+ 1) * 2) /* independent out */
1107 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1109 else /* copy front */
1110 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1115 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1116 struct hda_codec
*codec
,
1117 unsigned int stream_tag
,
1118 unsigned int format
,
1119 struct snd_pcm_substream
*substream
)
1121 struct via_spec
*spec
= codec
->spec
;
1122 struct hda_multi_out
*mout
= &spec
->multiout
;
1123 hda_nid_t
*nids
= mout
->dac_nids
;
1125 if (substream
->number
== 0)
1126 playback_multi_pcm_prep_0(codec
, stream_tag
, format
,
1129 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1130 spec
->hp_independent_mode
)
1131 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1132 stream_tag
, 0, format
);
1134 vt1708_start_hp_work(spec
);
1138 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1139 struct hda_codec
*codec
,
1140 struct snd_pcm_substream
*substream
)
1142 struct via_spec
*spec
= codec
->spec
;
1143 struct hda_multi_out
*mout
= &spec
->multiout
;
1144 hda_nid_t
*nids
= mout
->dac_nids
;
1147 if (substream
->number
== 0) {
1148 for (i
= 0; i
< mout
->num_dacs
; i
++)
1149 snd_hda_codec_setup_stream(codec
, nids
[i
], 0, 0, 0);
1151 if (mout
->hp_nid
&& !spec
->hp_independent_mode
)
1152 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1155 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1156 if (mout
->extra_out_nid
[i
])
1157 snd_hda_codec_setup_stream(codec
,
1158 mout
->extra_out_nid
[i
],
1160 mutex_lock(&codec
->spdif_mutex
);
1161 if (mout
->dig_out_nid
&&
1162 mout
->dig_out_used
== HDA_DIG_ANALOG_DUP
) {
1163 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1165 mout
->dig_out_used
= 0;
1167 mutex_unlock(&codec
->spdif_mutex
);
1169 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1170 spec
->hp_independent_mode
)
1171 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1174 vt1708_stop_hp_work(spec
);
1181 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1182 struct hda_codec
*codec
,
1183 struct snd_pcm_substream
*substream
)
1185 struct via_spec
*spec
= codec
->spec
;
1186 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
1189 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
1190 struct hda_codec
*codec
,
1191 struct snd_pcm_substream
*substream
)
1193 struct via_spec
*spec
= codec
->spec
;
1194 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
1197 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1198 struct hda_codec
*codec
,
1199 unsigned int stream_tag
,
1200 unsigned int format
,
1201 struct snd_pcm_substream
*substream
)
1203 struct via_spec
*spec
= codec
->spec
;
1204 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
1205 stream_tag
, format
, substream
);
1208 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1209 struct hda_codec
*codec
,
1210 struct snd_pcm_substream
*substream
)
1212 struct via_spec
*spec
= codec
->spec
;
1213 snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
1220 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1221 struct hda_codec
*codec
,
1222 unsigned int stream_tag
,
1223 unsigned int format
,
1224 struct snd_pcm_substream
*substream
)
1226 struct via_spec
*spec
= codec
->spec
;
1228 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
1229 stream_tag
, 0, format
);
1233 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1234 struct hda_codec
*codec
,
1235 struct snd_pcm_substream
*substream
)
1237 struct via_spec
*spec
= codec
->spec
;
1238 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
1242 static struct hda_pcm_stream vt1708_pcm_analog_playback
= {
1246 .nid
= 0x10, /* NID to query formats and rates */
1248 .open
= via_playback_pcm_open
,
1249 .prepare
= via_playback_multi_pcm_prepare
,
1250 .cleanup
= via_playback_multi_pcm_cleanup
1254 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
1258 .nid
= 0x10, /* NID to query formats and rates */
1259 /* We got noisy outputs on the right channel on VT1708 when
1260 * 24bit samples are used. Until any workaround is found,
1261 * disable the 24bit format, so far.
1263 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1265 .open
= via_playback_pcm_open
,
1266 .prepare
= via_playback_pcm_prepare
,
1267 .cleanup
= via_playback_pcm_cleanup
1271 static struct hda_pcm_stream vt1708_pcm_analog_capture
= {
1275 .nid
= 0x15, /* NID to query formats and rates */
1277 .prepare
= via_capture_pcm_prepare
,
1278 .cleanup
= via_capture_pcm_cleanup
1282 static struct hda_pcm_stream vt1708_pcm_digital_playback
= {
1286 /* NID is set in via_build_pcms */
1288 .open
= via_dig_playback_pcm_open
,
1289 .close
= via_dig_playback_pcm_close
,
1290 .prepare
= via_dig_playback_pcm_prepare
,
1291 .cleanup
= via_dig_playback_pcm_cleanup
1295 static struct hda_pcm_stream vt1708_pcm_digital_capture
= {
1301 static int via_build_controls(struct hda_codec
*codec
)
1303 struct via_spec
*spec
= codec
->spec
;
1307 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1308 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1313 if (spec
->multiout
.dig_out_nid
) {
1314 err
= snd_hda_create_spdif_out_ctls(codec
,
1315 spec
->multiout
.dig_out_nid
);
1318 err
= snd_hda_create_spdif_share_sw(codec
,
1322 spec
->multiout
.share_spdif
= 1;
1324 if (spec
->dig_in_nid
) {
1325 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1330 /* init power states */
1331 set_jack_power_state(codec
);
1332 analog_low_current_mode(codec
, 1);
1334 via_free_kctls(codec
); /* no longer needed */
1338 static int via_build_pcms(struct hda_codec
*codec
)
1340 struct via_spec
*spec
= codec
->spec
;
1341 struct hda_pcm
*info
= spec
->pcm_rec
;
1343 codec
->num_pcms
= 1;
1344 codec
->pcm_info
= info
;
1346 info
->name
= spec
->stream_name_analog
;
1347 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *(spec
->stream_analog_playback
);
1348 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
1349 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *(spec
->stream_analog_capture
);
1350 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
1352 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
1353 spec
->multiout
.max_channels
;
1355 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
1358 info
->name
= spec
->stream_name_digital
;
1359 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
1360 if (spec
->multiout
.dig_out_nid
) {
1361 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1362 *(spec
->stream_digital_playback
);
1363 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1364 spec
->multiout
.dig_out_nid
;
1366 if (spec
->dig_in_nid
) {
1367 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
1368 *(spec
->stream_digital_capture
);
1369 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
1377 static void via_free(struct hda_codec
*codec
)
1379 struct via_spec
*spec
= codec
->spec
;
1384 via_free_kctls(codec
);
1385 vt1708_stop_hp_work(spec
);
1389 /* mute internal speaker if HP is plugged */
1390 static void via_hp_automute(struct hda_codec
*codec
)
1392 unsigned int present
= 0;
1393 struct via_spec
*spec
= codec
->spec
;
1395 present
= snd_hda_codec_read(codec
, spec
->autocfg
.hp_pins
[0], 0,
1396 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
1398 if (!spec
->hp_independent_mode
) {
1399 struct snd_ctl_elem_id id
;
1401 snd_hda_codec_amp_stereo(
1402 codec
, spec
->autocfg
.line_out_pins
[0], HDA_OUTPUT
, 0,
1403 HDA_AMP_MUTE
, present
? HDA_AMP_MUTE
: 0);
1405 memset(&id
, 0, sizeof(id
));
1406 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
1407 strcpy(id
.name
, "Front Playback Switch");
1408 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
1413 static void via_gpio_control(struct hda_codec
*codec
)
1415 unsigned int gpio_data
;
1416 unsigned int vol_counter
;
1418 unsigned int master_vol
;
1420 struct via_spec
*spec
= codec
->spec
;
1422 gpio_data
= snd_hda_codec_read(codec
, codec
->afg
, 0,
1423 AC_VERB_GET_GPIO_DATA
, 0) & 0x03;
1425 vol_counter
= (snd_hda_codec_read(codec
, codec
->afg
, 0,
1426 0xF84, 0) & 0x3F0000) >> 16;
1428 vol
= vol_counter
& 0x1F;
1429 master_vol
= snd_hda_codec_read(codec
, 0x1A, 0,
1430 AC_VERB_GET_AMP_GAIN_MUTE
,
1433 if (gpio_data
== 0x02) {
1434 /* unmute line out */
1435 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
1436 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
1438 if (vol_counter
& 0x20) {
1439 /* decrease volume */
1440 if (vol
> master_vol
)
1442 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
,
1446 /* increase volume */
1447 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
, 0,
1449 ((master_vol
+vol
) > 0x2A) ? 0x2A :
1452 } else if (!(gpio_data
& 0x02)) {
1454 snd_hda_codec_amp_stereo(codec
,
1455 spec
->autocfg
.line_out_pins
[0],
1456 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
1461 /* unsolicited event for jack sensing */
1462 static void via_unsol_event(struct hda_codec
*codec
,
1466 if (res
& VIA_HP_EVENT
)
1467 via_hp_automute(codec
);
1468 if (res
& VIA_GPIO_EVENT
)
1469 via_gpio_control(codec
);
1470 if (res
& VIA_JACK_EVENT
)
1471 set_jack_power_state(codec
);
1474 static int via_init(struct hda_codec
*codec
)
1476 struct via_spec
*spec
= codec
->spec
;
1478 for (i
= 0; i
< spec
->num_iverbs
; i
++)
1479 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
1481 spec
->codec_type
= get_codec_type(codec
);
1482 if (spec
->codec_type
== VT1708BCE
)
1483 spec
->codec_type
= VT1708S
; /* VT1708BCE & VT1708S are almost
1485 /* Lydia Add for EAPD enable */
1486 if (!spec
->dig_in_nid
) { /* No Digital In connection */
1487 if (spec
->dig_in_pin
) {
1488 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
1489 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1491 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
1492 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
1494 } else /* enable SPDIF-input pin */
1495 snd_hda_codec_write(codec
, spec
->autocfg
.dig_in_pin
, 0,
1496 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
1498 /* assign slave outs */
1499 if (spec
->slave_dig_outs
[0])
1500 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
1505 #ifdef SND_HDA_NEEDS_RESUME
1506 static int via_suspend(struct hda_codec
*codec
, pm_message_t state
)
1508 struct via_spec
*spec
= codec
->spec
;
1509 vt1708_stop_hp_work(spec
);
1514 #ifdef CONFIG_SND_HDA_POWER_SAVE
1515 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
1517 struct via_spec
*spec
= codec
->spec
;
1518 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
1524 static struct hda_codec_ops via_patch_ops
= {
1525 .build_controls
= via_build_controls
,
1526 .build_pcms
= via_build_pcms
,
1529 #ifdef SND_HDA_NEEDS_RESUME
1530 .suspend
= via_suspend
,
1532 #ifdef CONFIG_SND_HDA_POWER_SAVE
1533 .check_power_status
= via_check_power_status
,
1537 /* fill in the dac_nids table from the parsed pin configuration */
1538 static int vt1708_auto_fill_dac_nids(struct via_spec
*spec
,
1539 const struct auto_pin_cfg
*cfg
)
1544 spec
->multiout
.num_dacs
= cfg
->line_outs
;
1546 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1548 for(i
= 0; i
< 4; i
++) {
1549 nid
= cfg
->line_out_pins
[i
];
1551 /* config dac list */
1553 case AUTO_SEQ_FRONT
:
1554 spec
->multiout
.dac_nids
[i
] = 0x10;
1556 case AUTO_SEQ_CENLFE
:
1557 spec
->multiout
.dac_nids
[i
] = 0x12;
1559 case AUTO_SEQ_SURROUND
:
1560 spec
->multiout
.dac_nids
[i
] = 0x11;
1563 spec
->multiout
.dac_nids
[i
] = 0x13;
1572 /* add playback controls from the parsed DAC table */
1573 static int vt1708_auto_create_multi_out_ctls(struct via_spec
*spec
,
1574 const struct auto_pin_cfg
*cfg
)
1577 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1578 hda_nid_t nid
, nid_vol
= 0;
1581 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1582 nid
= cfg
->line_out_pins
[i
];
1587 if (i
!= AUTO_SEQ_FRONT
)
1590 if (i
== AUTO_SEQ_CENLFE
) {
1592 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1593 "Center Playback Volume",
1594 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1598 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1599 "LFE Playback Volume",
1600 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1604 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1605 "Center Playback Switch",
1606 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1610 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1611 "LFE Playback Switch",
1612 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1616 } else if (i
== AUTO_SEQ_FRONT
){
1617 /* add control to mixer index 0 */
1618 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1619 "Master Front Playback Volume",
1620 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1624 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1625 "Master Front Playback Switch",
1626 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1631 /* add control to PW3 */
1632 sprintf(name
, "%s Playback Volume", chname
[i
]);
1633 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1634 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1638 sprintf(name
, "%s Playback Switch", chname
[i
]);
1639 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1640 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1645 sprintf(name
, "%s Playback Volume", chname
[i
]);
1646 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1647 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1651 sprintf(name
, "%s Playback Switch", chname
[i
]);
1652 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1653 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1663 static void create_hp_imux(struct via_spec
*spec
)
1666 struct hda_input_mux
*imux
= &spec
->private_imux
[1];
1667 static const char *texts
[] = { "OFF", "ON", NULL
};
1669 /* for hp mode select */
1671 while (texts
[i
] != NULL
) {
1672 imux
->items
[imux
->num_items
].label
= texts
[i
];
1673 imux
->items
[imux
->num_items
].index
= i
;
1678 spec
->hp_mux
= &spec
->private_imux
[1];
1681 static int vt1708_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1688 spec
->multiout
.hp_nid
= VT1708_HP_NID
; /* AOW3 */
1689 spec
->hp_independent_mode_index
= 1;
1691 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1692 "Headphone Playback Volume",
1693 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1696 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1697 "Headphone Playback Switch",
1698 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1702 create_hp_imux(spec
);
1707 /* create playback/capture controls for input pins */
1708 static int vt1708_auto_create_analog_input_ctls(struct via_spec
*spec
,
1709 const struct auto_pin_cfg
*cfg
)
1711 static char *labels
[] = {
1712 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1714 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1715 int i
, err
, idx
= 0;
1717 /* for internal loopback recording select */
1718 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1719 imux
->items
[imux
->num_items
].index
= idx
;
1722 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1723 if (!cfg
->input_pins
[i
])
1726 switch (cfg
->input_pins
[i
]) {
1727 case 0x1d: /* Mic */
1731 case 0x1e: /* Line In */
1735 case 0x21: /* Front Mic */
1743 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x17);
1746 imux
->items
[imux
->num_items
].label
= labels
[i
];
1747 imux
->items
[imux
->num_items
].index
= idx
;
1753 #ifdef CONFIG_SND_HDA_POWER_SAVE
1754 static struct hda_amp_list vt1708_loopbacks
[] = {
1755 { 0x17, HDA_INPUT
, 1 },
1756 { 0x17, HDA_INPUT
, 2 },
1757 { 0x17, HDA_INPUT
, 3 },
1758 { 0x17, HDA_INPUT
, 4 },
1763 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
1765 unsigned int def_conf
;
1766 unsigned char seqassoc
;
1768 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
1769 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
1770 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
1771 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
1772 && (seqassoc
== 0xf0 || seqassoc
== 0xff)) {
1773 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
1774 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
1780 static int vt1708_jack_detectect_get(struct snd_kcontrol
*kcontrol
,
1781 struct snd_ctl_elem_value
*ucontrol
)
1783 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1784 struct via_spec
*spec
= codec
->spec
;
1786 if (spec
->codec_type
!= VT1708
)
1788 spec
->vt1708_jack_detectect
=
1789 !((snd_hda_codec_read(codec
, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
1790 ucontrol
->value
.integer
.value
[0] = spec
->vt1708_jack_detectect
;
1794 static int vt1708_jack_detectect_put(struct snd_kcontrol
*kcontrol
,
1795 struct snd_ctl_elem_value
*ucontrol
)
1797 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1798 struct via_spec
*spec
= codec
->spec
;
1801 if (spec
->codec_type
!= VT1708
)
1803 spec
->vt1708_jack_detectect
= ucontrol
->value
.integer
.value
[0];
1804 change
= (0x1 & (snd_hda_codec_read(codec
, 0x1, 0, 0xf84, 0) >> 8))
1805 == !spec
->vt1708_jack_detectect
;
1806 if (spec
->vt1708_jack_detectect
) {
1807 mute_aa_path(codec
, 1);
1808 notify_aa_path_ctls(codec
);
1813 static struct snd_kcontrol_new vt1708_jack_detectect
[] = {
1815 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1816 .name
= "Jack Detect",
1818 .info
= snd_ctl_boolean_mono_info
,
1819 .get
= vt1708_jack_detectect_get
,
1820 .put
= vt1708_jack_detectect_put
,
1825 static int vt1708_parse_auto_config(struct hda_codec
*codec
)
1827 struct via_spec
*spec
= codec
->spec
;
1830 /* Add HP and CD pin config connect bit re-config action */
1831 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
1832 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
1834 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1837 err
= vt1708_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1840 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1841 return 0; /* can't find valid BIOS pin config */
1843 err
= vt1708_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1846 err
= vt1708_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1849 err
= vt1708_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1852 /* add jack detect on/off control */
1853 err
= snd_hda_add_new_ctls(codec
, vt1708_jack_detectect
);
1857 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1859 if (spec
->autocfg
.dig_outs
)
1860 spec
->multiout
.dig_out_nid
= VT1708_DIGOUT_NID
;
1861 spec
->dig_in_pin
= VT1708_DIGIN_PIN
;
1862 if (spec
->autocfg
.dig_in_pin
)
1863 spec
->dig_in_nid
= VT1708_DIGIN_NID
;
1865 if (spec
->kctls
.list
)
1866 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
1868 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_volume_init_verbs
;
1870 spec
->input_mux
= &spec
->private_imux
[0];
1873 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1875 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
1879 /* init callback for auto-configuration model -- overriding the default init */
1880 static int via_auto_init(struct hda_codec
*codec
)
1883 via_auto_init_multi_out(codec
);
1884 via_auto_init_hp_out(codec
);
1885 via_auto_init_analog_input(codec
);
1889 static void vt1708_update_hp_jack_state(struct work_struct
*work
)
1891 struct via_spec
*spec
= container_of(work
, struct via_spec
,
1892 vt1708_hp_work
.work
);
1893 if (spec
->codec_type
!= VT1708
)
1895 /* if jack state toggled */
1896 if (spec
->vt1708_hp_present
1897 != (snd_hda_codec_read(spec
->codec
, spec
->autocfg
.hp_pins
[0], 0,
1898 AC_VERB_GET_PIN_SENSE
, 0) >> 31)) {
1899 spec
->vt1708_hp_present
^= 1;
1900 via_hp_automute(spec
->codec
);
1902 vt1708_start_hp_work(spec
);
1905 static int get_mux_nids(struct hda_codec
*codec
)
1907 struct via_spec
*spec
= codec
->spec
;
1908 hda_nid_t nid
, conn
[8];
1912 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1913 nid
= spec
->adc_nids
[i
];
1915 type
= get_wcaps_type(get_wcaps(codec
, nid
));
1916 if (type
== AC_WID_PIN
)
1918 n
= snd_hda_get_connections(codec
, nid
, conn
,
1923 spec
->mux_nids
[i
] = nid
;
1932 static int patch_vt1708(struct hda_codec
*codec
)
1934 struct via_spec
*spec
;
1937 /* create a codec specific record */
1938 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1944 /* automatic parse from the BIOS config */
1945 err
= vt1708_parse_auto_config(codec
);
1950 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
1951 "from BIOS. Using genenic mode...\n");
1955 spec
->stream_name_analog
= "VT1708 Analog";
1956 spec
->stream_analog_playback
= &vt1708_pcm_analog_playback
;
1957 /* disable 32bit format on VT1708 */
1958 if (codec
->vendor_id
== 0x11061708)
1959 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
1960 spec
->stream_analog_capture
= &vt1708_pcm_analog_capture
;
1962 spec
->stream_name_digital
= "VT1708 Digital";
1963 spec
->stream_digital_playback
= &vt1708_pcm_digital_playback
;
1964 spec
->stream_digital_capture
= &vt1708_pcm_digital_capture
;
1967 if (!spec
->adc_nids
&& spec
->input_mux
) {
1968 spec
->adc_nids
= vt1708_adc_nids
;
1969 spec
->num_adc_nids
= ARRAY_SIZE(vt1708_adc_nids
);
1970 get_mux_nids(codec
);
1971 spec
->mixers
[spec
->num_mixers
] = vt1708_capture_mixer
;
1975 codec
->patch_ops
= via_patch_ops
;
1977 codec
->patch_ops
.init
= via_auto_init
;
1978 #ifdef CONFIG_SND_HDA_POWER_SAVE
1979 spec
->loopback
.amplist
= vt1708_loopbacks
;
1981 spec
->codec
= codec
;
1982 INIT_DELAYED_WORK(&spec
->vt1708_hp_work
, vt1708_update_hp_jack_state
);
1986 /* capture mixer elements */
1987 static struct snd_kcontrol_new vt1709_capture_mixer
[] = {
1988 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT
),
1989 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT
),
1990 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT
),
1991 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT
),
1992 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT
),
1993 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT
),
1995 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1996 /* The multiple "Capture Source" controls confuse alsamixer
1997 * So call somewhat different..
1999 /* .name = "Capture Source", */
2000 .name
= "Input Source",
2002 .info
= via_mux_enum_info
,
2003 .get
= via_mux_enum_get
,
2004 .put
= via_mux_enum_put
,
2009 static struct hda_verb vt1709_uniwill_init_verbs
[] = {
2010 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
,
2011 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
2016 * generic initialization of ADC, input mixers and output mixers
2018 static struct hda_verb vt1709_10ch_volume_init_verbs
[] = {
2020 * Unmute ADC0-2 and set the default input to mic-in
2022 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2023 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2024 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2027 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2030 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2031 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2032 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2033 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2034 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2035 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2038 * Set up output selector (0x1a, 0x1b, 0x29)
2040 /* set vol=0 to output mixers */
2041 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2042 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2043 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2046 * Unmute PW3 and PW4
2048 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2049 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2051 /* Set input of PW4 as AOW4 */
2052 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
2053 /* PW9 Output enable */
2054 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2058 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback
= {
2062 .nid
= 0x10, /* NID to query formats and rates */
2064 .open
= via_playback_pcm_open
,
2065 .prepare
= via_playback_pcm_prepare
,
2066 .cleanup
= via_playback_pcm_cleanup
2070 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback
= {
2074 .nid
= 0x10, /* NID to query formats and rates */
2076 .open
= via_playback_pcm_open
,
2077 .prepare
= via_playback_pcm_prepare
,
2078 .cleanup
= via_playback_pcm_cleanup
2082 static struct hda_pcm_stream vt1709_pcm_analog_capture
= {
2086 .nid
= 0x14, /* NID to query formats and rates */
2088 .prepare
= via_capture_pcm_prepare
,
2089 .cleanup
= via_capture_pcm_cleanup
2093 static struct hda_pcm_stream vt1709_pcm_digital_playback
= {
2097 /* NID is set in via_build_pcms */
2099 .open
= via_dig_playback_pcm_open
,
2100 .close
= via_dig_playback_pcm_close
2104 static struct hda_pcm_stream vt1709_pcm_digital_capture
= {
2110 static int vt1709_auto_fill_dac_nids(struct via_spec
*spec
,
2111 const struct auto_pin_cfg
*cfg
)
2116 if (cfg
->line_outs
== 4) /* 10 channels */
2117 spec
->multiout
.num_dacs
= cfg
->line_outs
+1; /* AOW0~AOW4 */
2118 else if (cfg
->line_outs
== 3) /* 6 channels */
2119 spec
->multiout
.num_dacs
= cfg
->line_outs
; /* AOW0~AOW2 */
2121 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2123 if (cfg
->line_outs
== 4) { /* 10 channels */
2124 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2125 nid
= cfg
->line_out_pins
[i
];
2127 /* config dac list */
2129 case AUTO_SEQ_FRONT
:
2131 spec
->multiout
.dac_nids
[i
] = 0x10;
2133 case AUTO_SEQ_CENLFE
:
2135 spec
->multiout
.dac_nids
[i
] = 0x12;
2137 case AUTO_SEQ_SURROUND
:
2139 spec
->multiout
.dac_nids
[i
] = 0x11;
2143 spec
->multiout
.dac_nids
[i
] = 0x27;
2150 spec
->multiout
.dac_nids
[cfg
->line_outs
] = 0x28; /* AOW4 */
2152 } else if (cfg
->line_outs
== 3) { /* 6 channels */
2153 for(i
= 0; i
< cfg
->line_outs
; i
++) {
2154 nid
= cfg
->line_out_pins
[i
];
2156 /* config dac list */
2158 case AUTO_SEQ_FRONT
:
2160 spec
->multiout
.dac_nids
[i
] = 0x10;
2162 case AUTO_SEQ_CENLFE
:
2164 spec
->multiout
.dac_nids
[i
] = 0x12;
2166 case AUTO_SEQ_SURROUND
:
2168 spec
->multiout
.dac_nids
[i
] = 0x11;
2180 /* add playback controls from the parsed DAC table */
2181 static int vt1709_auto_create_multi_out_ctls(struct via_spec
*spec
,
2182 const struct auto_pin_cfg
*cfg
)
2185 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2189 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2190 nid
= cfg
->line_out_pins
[i
];
2195 if (i
== AUTO_SEQ_CENLFE
) {
2197 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2198 "Center Playback Volume",
2199 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
2203 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2204 "LFE Playback Volume",
2205 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
2209 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2210 "Center Playback Switch",
2211 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
2215 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2216 "LFE Playback Switch",
2217 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
2221 } else if (i
== AUTO_SEQ_FRONT
){
2222 /* add control to mixer index 0 */
2223 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2224 "Master Front Playback Volume",
2225 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
2229 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2230 "Master Front Playback Switch",
2231 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
2236 /* add control to PW3 */
2237 sprintf(name
, "%s Playback Volume", chname
[i
]);
2238 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2239 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2243 sprintf(name
, "%s Playback Switch", chname
[i
]);
2244 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2245 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2249 } else if (i
== AUTO_SEQ_SURROUND
) {
2250 sprintf(name
, "%s Playback Volume", chname
[i
]);
2251 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2252 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
2256 sprintf(name
, "%s Playback Switch", chname
[i
]);
2257 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2258 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
2262 } else if (i
== AUTO_SEQ_SIDE
) {
2263 sprintf(name
, "%s Playback Volume", chname
[i
]);
2264 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2265 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
2269 sprintf(name
, "%s Playback Switch", chname
[i
]);
2270 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2271 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
2281 static int vt1709_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2288 if (spec
->multiout
.num_dacs
== 5) /* 10 channels */
2289 spec
->multiout
.hp_nid
= VT1709_HP_DAC_NID
;
2290 else if (spec
->multiout
.num_dacs
== 3) /* 6 channels */
2291 spec
->multiout
.hp_nid
= 0;
2292 spec
->hp_independent_mode_index
= 1;
2294 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2295 "Headphone Playback Volume",
2296 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2299 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2300 "Headphone Playback Switch",
2301 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2308 /* create playback/capture controls for input pins */
2309 static int vt1709_auto_create_analog_input_ctls(struct via_spec
*spec
,
2310 const struct auto_pin_cfg
*cfg
)
2312 static char *labels
[] = {
2313 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2315 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2316 int i
, err
, idx
= 0;
2318 /* for internal loopback recording select */
2319 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2320 imux
->items
[imux
->num_items
].index
= idx
;
2323 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2324 if (!cfg
->input_pins
[i
])
2327 switch (cfg
->input_pins
[i
]) {
2328 case 0x1d: /* Mic */
2332 case 0x1e: /* Line In */
2336 case 0x21: /* Front Mic */
2344 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x18);
2347 imux
->items
[imux
->num_items
].label
= labels
[i
];
2348 imux
->items
[imux
->num_items
].index
= idx
;
2354 static int vt1709_parse_auto_config(struct hda_codec
*codec
)
2356 struct via_spec
*spec
= codec
->spec
;
2359 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2362 err
= vt1709_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2365 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2366 return 0; /* can't find valid BIOS pin config */
2368 err
= vt1709_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2371 err
= vt1709_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2374 err
= vt1709_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2378 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2380 if (spec
->autocfg
.dig_outs
)
2381 spec
->multiout
.dig_out_nid
= VT1709_DIGOUT_NID
;
2382 spec
->dig_in_pin
= VT1709_DIGIN_PIN
;
2383 if (spec
->autocfg
.dig_in_pin
)
2384 spec
->dig_in_nid
= VT1709_DIGIN_NID
;
2386 if (spec
->kctls
.list
)
2387 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2389 spec
->input_mux
= &spec
->private_imux
[0];
2392 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2394 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
2398 #ifdef CONFIG_SND_HDA_POWER_SAVE
2399 static struct hda_amp_list vt1709_loopbacks
[] = {
2400 { 0x18, HDA_INPUT
, 1 },
2401 { 0x18, HDA_INPUT
, 2 },
2402 { 0x18, HDA_INPUT
, 3 },
2403 { 0x18, HDA_INPUT
, 4 },
2408 static int patch_vt1709_10ch(struct hda_codec
*codec
)
2410 struct via_spec
*spec
;
2413 /* create a codec specific record */
2414 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2420 err
= vt1709_parse_auto_config(codec
);
2425 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
2426 "Using genenic mode...\n");
2429 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_10ch_volume_init_verbs
;
2430 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
2432 spec
->stream_name_analog
= "VT1709 Analog";
2433 spec
->stream_analog_playback
= &vt1709_10ch_pcm_analog_playback
;
2434 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
2436 spec
->stream_name_digital
= "VT1709 Digital";
2437 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
2438 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
2441 if (!spec
->adc_nids
&& spec
->input_mux
) {
2442 spec
->adc_nids
= vt1709_adc_nids
;
2443 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
2444 get_mux_nids(codec
);
2445 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
2449 codec
->patch_ops
= via_patch_ops
;
2451 codec
->patch_ops
.init
= via_auto_init
;
2452 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2453 #ifdef CONFIG_SND_HDA_POWER_SAVE
2454 spec
->loopback
.amplist
= vt1709_loopbacks
;
2460 * generic initialization of ADC, input mixers and output mixers
2462 static struct hda_verb vt1709_6ch_volume_init_verbs
[] = {
2464 * Unmute ADC0-2 and set the default input to mic-in
2466 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2467 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2468 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2471 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2474 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2475 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2476 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2477 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2478 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2479 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2482 * Set up output selector (0x1a, 0x1b, 0x29)
2484 /* set vol=0 to output mixers */
2485 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2486 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2487 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2490 * Unmute PW3 and PW4
2492 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2493 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2495 /* Set input of PW4 as MW0 */
2496 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
2497 /* PW9 Output enable */
2498 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2502 static int patch_vt1709_6ch(struct hda_codec
*codec
)
2504 struct via_spec
*spec
;
2507 /* create a codec specific record */
2508 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2514 err
= vt1709_parse_auto_config(codec
);
2519 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
2520 "Using genenic mode...\n");
2523 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_6ch_volume_init_verbs
;
2524 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
2526 spec
->stream_name_analog
= "VT1709 Analog";
2527 spec
->stream_analog_playback
= &vt1709_6ch_pcm_analog_playback
;
2528 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
2530 spec
->stream_name_digital
= "VT1709 Digital";
2531 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
2532 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
2535 if (!spec
->adc_nids
&& spec
->input_mux
) {
2536 spec
->adc_nids
= vt1709_adc_nids
;
2537 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
2538 get_mux_nids(codec
);
2539 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
2543 codec
->patch_ops
= via_patch_ops
;
2545 codec
->patch_ops
.init
= via_auto_init
;
2546 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2547 #ifdef CONFIG_SND_HDA_POWER_SAVE
2548 spec
->loopback
.amplist
= vt1709_loopbacks
;
2553 /* capture mixer elements */
2554 static struct snd_kcontrol_new vt1708B_capture_mixer
[] = {
2555 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
2556 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
2557 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
2558 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
2560 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2561 /* The multiple "Capture Source" controls confuse alsamixer
2562 * So call somewhat different..
2564 /* .name = "Capture Source", */
2565 .name
= "Input Source",
2567 .info
= via_mux_enum_info
,
2568 .get
= via_mux_enum_get
,
2569 .put
= via_mux_enum_put
,
2574 * generic initialization of ADC, input mixers and output mixers
2576 static struct hda_verb vt1708B_8ch_volume_init_verbs
[] = {
2578 * Unmute ADC0-1 and set the default input to mic-in
2580 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2581 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2584 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2587 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2588 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2589 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2590 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2591 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2592 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2595 * Set up output mixers
2597 /* set vol=0 to output mixers */
2598 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2599 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2600 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2602 /* Setup default input to PW4 */
2603 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x1},
2604 /* PW9 Output enable */
2605 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2606 /* PW10 Input enable */
2607 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2611 static struct hda_verb vt1708B_4ch_volume_init_verbs
[] = {
2613 * Unmute ADC0-1 and set the default input to mic-in
2615 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2616 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2619 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2622 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2623 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2624 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2625 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2626 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2627 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2630 * Set up output mixers
2632 /* set vol=0 to output mixers */
2633 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2634 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2635 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2637 /* Setup default input of PW4 to MW0 */
2638 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2639 /* PW9 Output enable */
2640 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2641 /* PW10 Input enable */
2642 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2646 static struct hda_verb vt1708B_uniwill_init_verbs
[] = {
2647 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
2648 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
2649 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2650 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2651 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2652 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2653 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2654 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2655 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2659 static int via_pcm_open_close(struct hda_pcm_stream
*hinfo
,
2660 struct hda_codec
*codec
,
2661 struct snd_pcm_substream
*substream
)
2663 int idle
= substream
->pstr
->substream_opened
== 1
2664 && substream
->ref_count
== 0;
2666 analog_low_current_mode(codec
, idle
);
2670 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback
= {
2674 .nid
= 0x10, /* NID to query formats and rates */
2676 .open
= via_playback_pcm_open
,
2677 .prepare
= via_playback_multi_pcm_prepare
,
2678 .cleanup
= via_playback_multi_pcm_cleanup
,
2679 .close
= via_pcm_open_close
2683 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback
= {
2687 .nid
= 0x10, /* NID to query formats and rates */
2689 .open
= via_playback_pcm_open
,
2690 .prepare
= via_playback_multi_pcm_prepare
,
2691 .cleanup
= via_playback_multi_pcm_cleanup
2695 static struct hda_pcm_stream vt1708B_pcm_analog_capture
= {
2699 .nid
= 0x13, /* NID to query formats and rates */
2701 .open
= via_pcm_open_close
,
2702 .prepare
= via_capture_pcm_prepare
,
2703 .cleanup
= via_capture_pcm_cleanup
,
2704 .close
= via_pcm_open_close
2708 static struct hda_pcm_stream vt1708B_pcm_digital_playback
= {
2712 /* NID is set in via_build_pcms */
2714 .open
= via_dig_playback_pcm_open
,
2715 .close
= via_dig_playback_pcm_close
,
2716 .prepare
= via_dig_playback_pcm_prepare
,
2717 .cleanup
= via_dig_playback_pcm_cleanup
2721 static struct hda_pcm_stream vt1708B_pcm_digital_capture
= {
2727 /* fill in the dac_nids table from the parsed pin configuration */
2728 static int vt1708B_auto_fill_dac_nids(struct via_spec
*spec
,
2729 const struct auto_pin_cfg
*cfg
)
2734 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2736 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2738 for (i
= 0; i
< 4; i
++) {
2739 nid
= cfg
->line_out_pins
[i
];
2741 /* config dac list */
2743 case AUTO_SEQ_FRONT
:
2744 spec
->multiout
.dac_nids
[i
] = 0x10;
2746 case AUTO_SEQ_CENLFE
:
2747 spec
->multiout
.dac_nids
[i
] = 0x24;
2749 case AUTO_SEQ_SURROUND
:
2750 spec
->multiout
.dac_nids
[i
] = 0x11;
2753 spec
->multiout
.dac_nids
[i
] = 0x25;
2762 /* add playback controls from the parsed DAC table */
2763 static int vt1708B_auto_create_multi_out_ctls(struct via_spec
*spec
,
2764 const struct auto_pin_cfg
*cfg
)
2767 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2768 hda_nid_t nid_vols
[] = {0x16, 0x18, 0x26, 0x27};
2769 hda_nid_t nid
, nid_vol
= 0;
2772 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2773 nid
= cfg
->line_out_pins
[i
];
2778 nid_vol
= nid_vols
[i
];
2780 if (i
== AUTO_SEQ_CENLFE
) {
2782 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2783 "Center Playback Volume",
2784 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2788 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2789 "LFE Playback Volume",
2790 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2794 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2795 "Center Playback Switch",
2796 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2800 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2801 "LFE Playback Switch",
2802 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2806 } else if (i
== AUTO_SEQ_FRONT
) {
2807 /* add control to mixer index 0 */
2808 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2809 "Master Front Playback Volume",
2810 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2814 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2815 "Master Front Playback Switch",
2816 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2821 /* add control to PW3 */
2822 sprintf(name
, "%s Playback Volume", chname
[i
]);
2823 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2824 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2828 sprintf(name
, "%s Playback Switch", chname
[i
]);
2829 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2830 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2835 sprintf(name
, "%s Playback Volume", chname
[i
]);
2836 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2837 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2841 sprintf(name
, "%s Playback Switch", chname
[i
]);
2842 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2843 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2853 static int vt1708B_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2860 spec
->multiout
.hp_nid
= VT1708B_HP_NID
; /* AOW3 */
2861 spec
->hp_independent_mode_index
= 1;
2863 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2864 "Headphone Playback Volume",
2865 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2868 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2869 "Headphone Playback Switch",
2870 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2874 create_hp_imux(spec
);
2879 /* create playback/capture controls for input pins */
2880 static int vt1708B_auto_create_analog_input_ctls(struct via_spec
*spec
,
2881 const struct auto_pin_cfg
*cfg
)
2883 static char *labels
[] = {
2884 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2886 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2887 int i
, err
, idx
= 0;
2889 /* for internal loopback recording select */
2890 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2891 imux
->items
[imux
->num_items
].index
= idx
;
2894 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2895 if (!cfg
->input_pins
[i
])
2898 switch (cfg
->input_pins
[i
]) {
2899 case 0x1a: /* Mic */
2903 case 0x1b: /* Line In */
2907 case 0x1e: /* Front Mic */
2915 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
2918 imux
->items
[imux
->num_items
].label
= labels
[i
];
2919 imux
->items
[imux
->num_items
].index
= idx
;
2925 static int vt1708B_parse_auto_config(struct hda_codec
*codec
)
2927 struct via_spec
*spec
= codec
->spec
;
2930 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2933 err
= vt1708B_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2936 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2937 return 0; /* can't find valid BIOS pin config */
2939 err
= vt1708B_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2942 err
= vt1708B_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2945 err
= vt1708B_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2949 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2951 if (spec
->autocfg
.dig_outs
)
2952 spec
->multiout
.dig_out_nid
= VT1708B_DIGOUT_NID
;
2953 spec
->dig_in_pin
= VT1708B_DIGIN_PIN
;
2954 if (spec
->autocfg
.dig_in_pin
)
2955 spec
->dig_in_nid
= VT1708B_DIGIN_NID
;
2957 if (spec
->kctls
.list
)
2958 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2960 spec
->input_mux
= &spec
->private_imux
[0];
2963 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2965 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
2969 #ifdef CONFIG_SND_HDA_POWER_SAVE
2970 static struct hda_amp_list vt1708B_loopbacks
[] = {
2971 { 0x16, HDA_INPUT
, 1 },
2972 { 0x16, HDA_INPUT
, 2 },
2973 { 0x16, HDA_INPUT
, 3 },
2974 { 0x16, HDA_INPUT
, 4 },
2978 static int patch_vt1708S(struct hda_codec
*codec
);
2979 static int patch_vt1708B_8ch(struct hda_codec
*codec
)
2981 struct via_spec
*spec
;
2984 if (get_codec_type(codec
) == VT1708BCE
)
2985 return patch_vt1708S(codec
);
2986 /* create a codec specific record */
2987 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2993 /* automatic parse from the BIOS config */
2994 err
= vt1708B_parse_auto_config(codec
);
2999 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3000 "from BIOS. Using genenic mode...\n");
3003 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_8ch_volume_init_verbs
;
3004 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
3006 spec
->stream_name_analog
= "VT1708B Analog";
3007 spec
->stream_analog_playback
= &vt1708B_8ch_pcm_analog_playback
;
3008 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
3010 spec
->stream_name_digital
= "VT1708B Digital";
3011 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
3012 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
3014 if (!spec
->adc_nids
&& spec
->input_mux
) {
3015 spec
->adc_nids
= vt1708B_adc_nids
;
3016 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
3017 get_mux_nids(codec
);
3018 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
3022 codec
->patch_ops
= via_patch_ops
;
3024 codec
->patch_ops
.init
= via_auto_init
;
3025 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3026 #ifdef CONFIG_SND_HDA_POWER_SAVE
3027 spec
->loopback
.amplist
= vt1708B_loopbacks
;
3033 static int patch_vt1708B_4ch(struct hda_codec
*codec
)
3035 struct via_spec
*spec
;
3038 /* create a codec specific record */
3039 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3045 /* automatic parse from the BIOS config */
3046 err
= vt1708B_parse_auto_config(codec
);
3051 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3052 "from BIOS. Using genenic mode...\n");
3055 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_4ch_volume_init_verbs
;
3056 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
3058 spec
->stream_name_analog
= "VT1708B Analog";
3059 spec
->stream_analog_playback
= &vt1708B_4ch_pcm_analog_playback
;
3060 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
3062 spec
->stream_name_digital
= "VT1708B Digital";
3063 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
3064 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
3066 if (!spec
->adc_nids
&& spec
->input_mux
) {
3067 spec
->adc_nids
= vt1708B_adc_nids
;
3068 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
3069 get_mux_nids(codec
);
3070 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
3074 codec
->patch_ops
= via_patch_ops
;
3076 codec
->patch_ops
.init
= via_auto_init
;
3077 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3078 #ifdef CONFIG_SND_HDA_POWER_SAVE
3079 spec
->loopback
.amplist
= vt1708B_loopbacks
;
3085 /* Patch for VT1708S */
3087 /* VT1708S software backdoor based override for buggy hardware micboost
3089 #define MIC_BOOST_VOLUME(xname, nid) { \
3090 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3093 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3094 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3095 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3096 .info = mic_boost_volume_info, \
3097 .get = snd_hda_mixer_amp_volume_get, \
3098 .put = snd_hda_mixer_amp_volume_put, \
3099 .tlv = { .c = mic_boost_tlv }, \
3100 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
3102 /* capture mixer elements */
3103 static struct snd_kcontrol_new vt1708S_capture_mixer
[] = {
3104 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
3105 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
3106 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
3107 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
3108 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
3109 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
3111 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3112 /* The multiple "Capture Source" controls confuse alsamixer
3113 * So call somewhat different..
3115 /* .name = "Capture Source", */
3116 .name
= "Input Source",
3118 .info
= via_mux_enum_info
,
3119 .get
= via_mux_enum_get
,
3120 .put
= via_mux_enum_put
,
3125 static struct hda_verb vt1708S_volume_init_verbs
[] = {
3126 /* Unmute ADC0-1 and set the default input to mic-in */
3127 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3128 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3130 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3131 * analog-loopback mixer widget */
3132 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3133 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3134 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3135 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3136 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3137 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3139 /* Setup default input of PW4 to MW0 */
3140 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
3141 /* PW9, PW10 Output enable */
3142 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3143 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3144 /* Enable Mic Boost Volume backdoor */
3149 static struct hda_verb vt1708S_uniwill_init_verbs
[] = {
3150 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
3151 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
3152 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3153 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3154 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3155 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3156 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3157 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3158 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3162 static struct hda_pcm_stream vt1708S_pcm_analog_playback
= {
3166 .nid
= 0x10, /* NID to query formats and rates */
3168 .open
= via_playback_pcm_open
,
3169 .prepare
= via_playback_pcm_prepare
,
3170 .cleanup
= via_playback_pcm_cleanup
,
3171 .close
= via_pcm_open_close
3175 static struct hda_pcm_stream vt1708S_pcm_analog_capture
= {
3179 .nid
= 0x13, /* NID to query formats and rates */
3181 .open
= via_pcm_open_close
,
3182 .prepare
= via_capture_pcm_prepare
,
3183 .cleanup
= via_capture_pcm_cleanup
,
3184 .close
= via_pcm_open_close
3188 static struct hda_pcm_stream vt1708S_pcm_digital_playback
= {
3192 /* NID is set in via_build_pcms */
3194 .open
= via_dig_playback_pcm_open
,
3195 .close
= via_dig_playback_pcm_close
,
3196 .prepare
= via_dig_playback_pcm_prepare
,
3197 .cleanup
= via_dig_playback_pcm_cleanup
3201 /* fill in the dac_nids table from the parsed pin configuration */
3202 static int vt1708S_auto_fill_dac_nids(struct via_spec
*spec
,
3203 const struct auto_pin_cfg
*cfg
)
3208 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3210 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3212 for (i
= 0; i
< 4; i
++) {
3213 nid
= cfg
->line_out_pins
[i
];
3215 /* config dac list */
3217 case AUTO_SEQ_FRONT
:
3218 spec
->multiout
.dac_nids
[i
] = 0x10;
3220 case AUTO_SEQ_CENLFE
:
3221 spec
->multiout
.dac_nids
[i
] = 0x24;
3223 case AUTO_SEQ_SURROUND
:
3224 spec
->multiout
.dac_nids
[i
] = 0x11;
3227 spec
->multiout
.dac_nids
[i
] = 0x25;
3236 /* add playback controls from the parsed DAC table */
3237 static int vt1708S_auto_create_multi_out_ctls(struct via_spec
*spec
,
3238 const struct auto_pin_cfg
*cfg
)
3241 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
3242 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x24, 0x25};
3243 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x26, 0x27};
3244 hda_nid_t nid
, nid_vol
, nid_mute
;
3247 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
3248 nid
= cfg
->line_out_pins
[i
];
3253 nid_vol
= nid_vols
[i
];
3254 nid_mute
= nid_mutes
[i
];
3256 if (i
== AUTO_SEQ_CENLFE
) {
3258 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3259 "Center Playback Volume",
3260 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3264 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3265 "LFE Playback Volume",
3266 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3270 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3271 "Center Playback Switch",
3272 HDA_COMPOSE_AMP_VAL(nid_mute
,
3277 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3278 "LFE Playback Switch",
3279 HDA_COMPOSE_AMP_VAL(nid_mute
,
3284 } else if (i
== AUTO_SEQ_FRONT
) {
3285 /* add control to mixer index 0 */
3286 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3287 "Master Front Playback Volume",
3288 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3292 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3293 "Master Front Playback Switch",
3294 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3300 sprintf(name
, "%s Playback Volume", chname
[i
]);
3301 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3302 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3306 sprintf(name
, "%s Playback Switch", chname
[i
]);
3307 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3308 HDA_COMPOSE_AMP_VAL(nid_mute
,
3314 sprintf(name
, "%s Playback Volume", chname
[i
]);
3315 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3316 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3320 sprintf(name
, "%s Playback Switch", chname
[i
]);
3321 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3322 HDA_COMPOSE_AMP_VAL(nid_mute
,
3333 static int vt1708S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3340 spec
->multiout
.hp_nid
= VT1708S_HP_NID
; /* AOW3 */
3341 spec
->hp_independent_mode_index
= 1;
3343 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3344 "Headphone Playback Volume",
3345 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
3349 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3350 "Headphone Playback Switch",
3351 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3355 create_hp_imux(spec
);
3360 /* create playback/capture controls for input pins */
3361 static int vt1708S_auto_create_analog_input_ctls(struct via_spec
*spec
,
3362 const struct auto_pin_cfg
*cfg
)
3364 static char *labels
[] = {
3365 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3367 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3368 int i
, err
, idx
= 0;
3370 /* for internal loopback recording select */
3371 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3372 imux
->items
[imux
->num_items
].index
= 5;
3375 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3376 if (!cfg
->input_pins
[i
])
3379 switch (cfg
->input_pins
[i
]) {
3380 case 0x1a: /* Mic */
3384 case 0x1b: /* Line In */
3388 case 0x1e: /* Front Mic */
3396 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
3399 imux
->items
[imux
->num_items
].label
= labels
[i
];
3400 imux
->items
[imux
->num_items
].index
= idx
-1;
3406 /* fill out digital output widgets; one for master and one for slave outputs */
3407 static void fill_dig_outs(struct hda_codec
*codec
)
3409 struct via_spec
*spec
= codec
->spec
;
3412 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
3416 nid
= spec
->autocfg
.dig_out_pins
[i
];
3419 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
3422 if (!spec
->multiout
.dig_out_nid
)
3423 spec
->multiout
.dig_out_nid
= nid
;
3425 spec
->slave_dig_outs
[0] = nid
;
3426 break; /* at most two dig outs */
3431 static int vt1708S_parse_auto_config(struct hda_codec
*codec
)
3433 struct via_spec
*spec
= codec
->spec
;
3436 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3439 err
= vt1708S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3442 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3443 return 0; /* can't find valid BIOS pin config */
3445 err
= vt1708S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
3448 err
= vt1708S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3451 err
= vt1708S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3455 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3457 fill_dig_outs(codec
);
3459 if (spec
->kctls
.list
)
3460 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3462 spec
->input_mux
= &spec
->private_imux
[0];
3465 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3467 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
3471 #ifdef CONFIG_SND_HDA_POWER_SAVE
3472 static struct hda_amp_list vt1708S_loopbacks
[] = {
3473 { 0x16, HDA_INPUT
, 1 },
3474 { 0x16, HDA_INPUT
, 2 },
3475 { 0x16, HDA_INPUT
, 3 },
3476 { 0x16, HDA_INPUT
, 4 },
3481 static int patch_vt1708S(struct hda_codec
*codec
)
3483 struct via_spec
*spec
;
3486 /* create a codec specific record */
3487 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3493 /* automatic parse from the BIOS config */
3494 err
= vt1708S_parse_auto_config(codec
);
3499 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3500 "from BIOS. Using genenic mode...\n");
3503 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_volume_init_verbs
;
3504 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_uniwill_init_verbs
;
3506 spec
->stream_name_analog
= "VT1708S Analog";
3507 spec
->stream_analog_playback
= &vt1708S_pcm_analog_playback
;
3508 spec
->stream_analog_capture
= &vt1708S_pcm_analog_capture
;
3510 spec
->stream_name_digital
= "VT1708S Digital";
3511 spec
->stream_digital_playback
= &vt1708S_pcm_digital_playback
;
3513 if (!spec
->adc_nids
&& spec
->input_mux
) {
3514 spec
->adc_nids
= vt1708S_adc_nids
;
3515 spec
->num_adc_nids
= ARRAY_SIZE(vt1708S_adc_nids
);
3516 get_mux_nids(codec
);
3517 spec
->mixers
[spec
->num_mixers
] = vt1708S_capture_mixer
;
3521 codec
->patch_ops
= via_patch_ops
;
3523 codec
->patch_ops
.init
= via_auto_init
;
3524 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3525 #ifdef CONFIG_SND_HDA_POWER_SAVE
3526 spec
->loopback
.amplist
= vt1708S_loopbacks
;
3529 /* correct names for VT1708BCE */
3530 if (get_codec_type(codec
) == VT1708BCE
) {
3531 kfree(codec
->chip_name
);
3532 codec
->chip_name
= kstrdup("VT1708BCE", GFP_KERNEL
);
3533 snprintf(codec
->bus
->card
->mixername
,
3534 sizeof(codec
->bus
->card
->mixername
),
3535 "%s %s", codec
->vendor_name
, codec
->chip_name
);
3536 spec
->stream_name_analog
= "VT1708BCE Analog";
3537 spec
->stream_name_digital
= "VT1708BCE Digital";
3542 /* Patch for VT1702 */
3544 /* capture mixer elements */
3545 static struct snd_kcontrol_new vt1702_capture_mixer
[] = {
3546 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT
),
3547 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT
),
3548 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT
),
3549 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT
),
3550 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT
),
3551 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT
),
3552 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3555 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3556 /* The multiple "Capture Source" controls confuse alsamixer
3557 * So call somewhat different..
3559 /* .name = "Capture Source", */
3560 .name
= "Input Source",
3562 .info
= via_mux_enum_info
,
3563 .get
= via_mux_enum_get
,
3564 .put
= via_mux_enum_put
,
3569 static struct hda_verb vt1702_volume_init_verbs
[] = {
3571 * Unmute ADC0-1 and set the default input to mic-in
3573 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3574 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3575 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3578 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3581 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3582 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3583 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3584 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3585 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3586 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
3588 /* Setup default input of PW4 to MW0 */
3589 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x1},
3590 /* PW6 PW7 Output enable */
3591 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3592 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3596 static struct hda_verb vt1702_uniwill_init_verbs
[] = {
3597 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE
,
3598 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
3599 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3600 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3601 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3602 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3606 static struct hda_pcm_stream vt1702_pcm_analog_playback
= {
3610 .nid
= 0x10, /* NID to query formats and rates */
3612 .open
= via_playback_pcm_open
,
3613 .prepare
= via_playback_multi_pcm_prepare
,
3614 .cleanup
= via_playback_multi_pcm_cleanup
,
3615 .close
= via_pcm_open_close
3619 static struct hda_pcm_stream vt1702_pcm_analog_capture
= {
3623 .nid
= 0x12, /* NID to query formats and rates */
3625 .open
= via_pcm_open_close
,
3626 .prepare
= via_capture_pcm_prepare
,
3627 .cleanup
= via_capture_pcm_cleanup
,
3628 .close
= via_pcm_open_close
3632 static struct hda_pcm_stream vt1702_pcm_digital_playback
= {
3636 /* NID is set in via_build_pcms */
3638 .open
= via_dig_playback_pcm_open
,
3639 .close
= via_dig_playback_pcm_close
,
3640 .prepare
= via_dig_playback_pcm_prepare
,
3641 .cleanup
= via_dig_playback_pcm_cleanup
3645 /* fill in the dac_nids table from the parsed pin configuration */
3646 static int vt1702_auto_fill_dac_nids(struct via_spec
*spec
,
3647 const struct auto_pin_cfg
*cfg
)
3649 spec
->multiout
.num_dacs
= 1;
3650 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3652 if (cfg
->line_out_pins
[0]) {
3653 /* config dac list */
3654 spec
->multiout
.dac_nids
[0] = 0x10;
3660 /* add playback controls from the parsed DAC table */
3661 static int vt1702_auto_create_line_out_ctls(struct via_spec
*spec
,
3662 const struct auto_pin_cfg
*cfg
)
3666 if (!cfg
->line_out_pins
[0])
3669 /* add control to mixer index 0 */
3670 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3671 "Master Front Playback Volume",
3672 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3675 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3676 "Master Front Playback Switch",
3677 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3682 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3683 "Front Playback Volume",
3684 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
));
3687 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3688 "Front Playback Switch",
3689 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT
));
3696 static int vt1702_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3699 struct hda_input_mux
*imux
;
3700 static const char *texts
[] = { "ON", "OFF", NULL
};
3703 spec
->multiout
.hp_nid
= 0x1D;
3704 spec
->hp_independent_mode_index
= 0;
3706 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3707 "Headphone Playback Volume",
3708 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT
));
3712 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3713 "Headphone Playback Switch",
3714 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3718 imux
= &spec
->private_imux
[1];
3720 /* for hp mode select */
3722 while (texts
[i
] != NULL
) {
3723 imux
->items
[imux
->num_items
].label
= texts
[i
];
3724 imux
->items
[imux
->num_items
].index
= i
;
3729 spec
->hp_mux
= &spec
->private_imux
[1];
3733 /* create playback/capture controls for input pins */
3734 static int vt1702_auto_create_analog_input_ctls(struct via_spec
*spec
,
3735 const struct auto_pin_cfg
*cfg
)
3737 static char *labels
[] = {
3738 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3740 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3741 int i
, err
, idx
= 0;
3743 /* for internal loopback recording select */
3744 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3745 imux
->items
[imux
->num_items
].index
= 3;
3748 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3749 if (!cfg
->input_pins
[i
])
3752 switch (cfg
->input_pins
[i
]) {
3753 case 0x14: /* Mic */
3757 case 0x15: /* Line In */
3761 case 0x18: /* Front Mic */
3765 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x1A);
3768 imux
->items
[imux
->num_items
].label
= labels
[i
];
3769 imux
->items
[imux
->num_items
].index
= idx
-1;
3775 static int vt1702_parse_auto_config(struct hda_codec
*codec
)
3777 struct via_spec
*spec
= codec
->spec
;
3780 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3783 err
= vt1702_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3786 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3787 return 0; /* can't find valid BIOS pin config */
3789 err
= vt1702_auto_create_line_out_ctls(spec
, &spec
->autocfg
);
3792 err
= vt1702_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3795 /* limit AA path volume to 0 dB */
3796 snd_hda_override_amp_caps(codec
, 0x1A, HDA_INPUT
,
3797 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
3798 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
3799 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
3800 (1 << AC_AMPCAP_MUTE_SHIFT
));
3801 err
= vt1702_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3805 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3807 fill_dig_outs(codec
);
3809 if (spec
->kctls
.list
)
3810 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3812 spec
->input_mux
= &spec
->private_imux
[0];
3815 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3820 #ifdef CONFIG_SND_HDA_POWER_SAVE
3821 static struct hda_amp_list vt1702_loopbacks
[] = {
3822 { 0x1A, HDA_INPUT
, 1 },
3823 { 0x1A, HDA_INPUT
, 2 },
3824 { 0x1A, HDA_INPUT
, 3 },
3825 { 0x1A, HDA_INPUT
, 4 },
3830 static int patch_vt1702(struct hda_codec
*codec
)
3832 struct via_spec
*spec
;
3834 unsigned int response
;
3835 unsigned char control
;
3837 /* create a codec specific record */
3838 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3844 /* automatic parse from the BIOS config */
3845 err
= vt1702_parse_auto_config(codec
);
3850 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3851 "from BIOS. Using genenic mode...\n");
3854 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_volume_init_verbs
;
3855 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_uniwill_init_verbs
;
3857 spec
->stream_name_analog
= "VT1702 Analog";
3858 spec
->stream_analog_playback
= &vt1702_pcm_analog_playback
;
3859 spec
->stream_analog_capture
= &vt1702_pcm_analog_capture
;
3861 spec
->stream_name_digital
= "VT1702 Digital";
3862 spec
->stream_digital_playback
= &vt1702_pcm_digital_playback
;
3864 if (!spec
->adc_nids
&& spec
->input_mux
) {
3865 spec
->adc_nids
= vt1702_adc_nids
;
3866 spec
->num_adc_nids
= ARRAY_SIZE(vt1702_adc_nids
);
3867 get_mux_nids(codec
);
3868 spec
->mixers
[spec
->num_mixers
] = vt1702_capture_mixer
;
3872 codec
->patch_ops
= via_patch_ops
;
3874 codec
->patch_ops
.init
= via_auto_init
;
3875 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3876 #ifdef CONFIG_SND_HDA_POWER_SAVE
3877 spec
->loopback
.amplist
= vt1702_loopbacks
;
3881 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF8C, 0);
3882 control
= (unsigned char)(response
& 0xff);
3884 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF88, control
);
3886 /* Enable GPIO 0&1 for volume&mute control */
3887 /* Enable GPIO 2 for DMIC-DATA */
3888 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF84, 0);
3889 control
= (unsigned char)((response
>> 16) & 0x3f);
3890 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF82, control
);
3898 static struct hda_codec_preset snd_hda_preset_via
[] = {
3899 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
3900 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
3901 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
3902 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
3903 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
3904 .patch
= patch_vt1709_10ch
},
3905 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
3906 .patch
= patch_vt1709_10ch
},
3907 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
3908 .patch
= patch_vt1709_10ch
},
3909 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
3910 .patch
= patch_vt1709_10ch
},
3911 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
3912 .patch
= patch_vt1709_6ch
},
3913 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
3914 .patch
= patch_vt1709_6ch
},
3915 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
3916 .patch
= patch_vt1709_6ch
},
3917 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
3918 .patch
= patch_vt1709_6ch
},
3919 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
3920 .patch
= patch_vt1708B_8ch
},
3921 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
3922 .patch
= patch_vt1708B_8ch
},
3923 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
3924 .patch
= patch_vt1708B_8ch
},
3925 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
3926 .patch
= patch_vt1708B_8ch
},
3927 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
3928 .patch
= patch_vt1708B_4ch
},
3929 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
3930 .patch
= patch_vt1708B_4ch
},
3931 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
3932 .patch
= patch_vt1708B_4ch
},
3933 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
3934 .patch
= patch_vt1708B_4ch
},
3935 { .id
= 0x11060397, .name
= "VT1708S",
3936 .patch
= patch_vt1708S
},
3937 { .id
= 0x11061397, .name
= "VT1708S",
3938 .patch
= patch_vt1708S
},
3939 { .id
= 0x11062397, .name
= "VT1708S",
3940 .patch
= patch_vt1708S
},
3941 { .id
= 0x11063397, .name
= "VT1708S",
3942 .patch
= patch_vt1708S
},
3943 { .id
= 0x11064397, .name
= "VT1708S",
3944 .patch
= patch_vt1708S
},
3945 { .id
= 0x11065397, .name
= "VT1708S",
3946 .patch
= patch_vt1708S
},
3947 { .id
= 0x11066397, .name
= "VT1708S",
3948 .patch
= patch_vt1708S
},
3949 { .id
= 0x11067397, .name
= "VT1708S",
3950 .patch
= patch_vt1708S
},
3951 { .id
= 0x11060398, .name
= "VT1702",
3952 .patch
= patch_vt1702
},
3953 { .id
= 0x11061398, .name
= "VT1702",
3954 .patch
= patch_vt1702
},
3955 { .id
= 0x11062398, .name
= "VT1702",
3956 .patch
= patch_vt1702
},
3957 { .id
= 0x11063398, .name
= "VT1702",
3958 .patch
= patch_vt1702
},
3959 { .id
= 0x11064398, .name
= "VT1702",
3960 .patch
= patch_vt1702
},
3961 { .id
= 0x11065398, .name
= "VT1702",
3962 .patch
= patch_vt1702
},
3963 { .id
= 0x11066398, .name
= "VT1702",
3964 .patch
= patch_vt1702
},
3965 { .id
= 0x11067398, .name
= "VT1702",
3966 .patch
= patch_vt1702
},
3970 MODULE_ALIAS("snd-hda-codec-id:1106*");
3972 static struct hda_codec_preset_list via_list
= {
3973 .preset
= snd_hda_preset_via
,
3974 .owner
= THIS_MODULE
,
3977 MODULE_LICENSE("GPL");
3978 MODULE_DESCRIPTION("VIA HD-audio codec");
3980 static int __init
patch_via_init(void)
3982 return snd_hda_add_codec_preset(&via_list
);
3985 static void __exit
patch_via_exit(void)
3987 snd_hda_delete_codec_preset(&via_list
);
3990 module_init(patch_via_init
)
3991 module_exit(patch_via_exit
)