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 void playback_multi_pcm_prep_0(struct hda_codec
*codec
,
1026 unsigned int stream_tag
,
1027 unsigned int format
,
1028 struct snd_pcm_substream
*substream
)
1030 struct via_spec
*spec
= codec
->spec
;
1031 struct hda_multi_out
*mout
= &spec
->multiout
;
1032 hda_nid_t
*nids
= mout
->dac_nids
;
1033 int chs
= substream
->runtime
->channels
;
1036 mutex_lock(&codec
->spdif_mutex
);
1037 if (mout
->dig_out_nid
&& mout
->dig_out_used
!= HDA_DIG_EXCLUSIVE
) {
1039 snd_hda_is_supported_format(codec
, mout
->dig_out_nid
,
1041 !(codec
->spdif_status
& IEC958_AES0_NONAUDIO
)) {
1042 mout
->dig_out_used
= HDA_DIG_ANALOG_DUP
;
1043 /* turn off SPDIF once; otherwise the IEC958 bits won't
1045 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1046 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1047 AC_VERB_SET_DIGI_CONVERT_1
,
1049 ~AC_DIG1_ENABLE
& 0xff);
1050 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1051 stream_tag
, 0, format
);
1052 /* turn on again (if needed) */
1053 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1054 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1055 AC_VERB_SET_DIGI_CONVERT_1
,
1056 codec
->spdif_ctls
& 0xff);
1058 mout
->dig_out_used
= 0;
1059 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1063 mutex_unlock(&codec
->spdif_mutex
);
1066 snd_hda_codec_setup_stream(codec
, nids
[HDA_FRONT
], stream_tag
,
1069 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1070 !spec
->hp_independent_mode
)
1071 /* headphone out will just decode front left/right (stereo) */
1072 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
, stream_tag
,
1075 /* extra outputs copied from front */
1076 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1077 if (mout
->extra_out_nid
[i
])
1078 snd_hda_codec_setup_stream(codec
,
1079 mout
->extra_out_nid
[i
],
1080 stream_tag
, 0, format
);
1083 for (i
= 1; i
< mout
->num_dacs
; i
++) {
1084 if (chs
>= (i
+ 1) * 2) /* independent out */
1085 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1087 else /* copy front */
1088 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1093 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1094 struct hda_codec
*codec
,
1095 unsigned int stream_tag
,
1096 unsigned int format
,
1097 struct snd_pcm_substream
*substream
)
1099 struct via_spec
*spec
= codec
->spec
;
1100 struct hda_multi_out
*mout
= &spec
->multiout
;
1101 hda_nid_t
*nids
= mout
->dac_nids
;
1103 if (substream
->number
== 0)
1104 playback_multi_pcm_prep_0(codec
, stream_tag
, format
,
1107 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1108 spec
->hp_independent_mode
)
1109 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1110 stream_tag
, 0, format
);
1112 vt1708_start_hp_work(spec
);
1116 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1117 struct hda_codec
*codec
,
1118 struct snd_pcm_substream
*substream
)
1120 struct via_spec
*spec
= codec
->spec
;
1121 struct hda_multi_out
*mout
= &spec
->multiout
;
1122 hda_nid_t
*nids
= mout
->dac_nids
;
1125 if (substream
->number
== 0) {
1126 for (i
= 0; i
< mout
->num_dacs
; i
++)
1127 snd_hda_codec_setup_stream(codec
, nids
[i
], 0, 0, 0);
1129 if (mout
->hp_nid
&& !spec
->hp_independent_mode
)
1130 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1133 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1134 if (mout
->extra_out_nid
[i
])
1135 snd_hda_codec_setup_stream(codec
,
1136 mout
->extra_out_nid
[i
],
1138 mutex_lock(&codec
->spdif_mutex
);
1139 if (mout
->dig_out_nid
&&
1140 mout
->dig_out_used
== HDA_DIG_ANALOG_DUP
) {
1141 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1143 mout
->dig_out_used
= 0;
1145 mutex_unlock(&codec
->spdif_mutex
);
1147 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1148 spec
->hp_independent_mode
)
1149 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1152 vt1708_stop_hp_work(spec
);
1159 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1160 struct hda_codec
*codec
,
1161 struct snd_pcm_substream
*substream
)
1163 struct via_spec
*spec
= codec
->spec
;
1164 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
1167 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
1168 struct hda_codec
*codec
,
1169 struct snd_pcm_substream
*substream
)
1171 struct via_spec
*spec
= codec
->spec
;
1172 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
1175 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1176 struct hda_codec
*codec
,
1177 unsigned int stream_tag
,
1178 unsigned int format
,
1179 struct snd_pcm_substream
*substream
)
1181 struct via_spec
*spec
= codec
->spec
;
1182 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
1183 stream_tag
, format
, substream
);
1186 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1187 struct hda_codec
*codec
,
1188 struct snd_pcm_substream
*substream
)
1190 struct via_spec
*spec
= codec
->spec
;
1191 snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
1198 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1199 struct hda_codec
*codec
,
1200 unsigned int stream_tag
,
1201 unsigned int format
,
1202 struct snd_pcm_substream
*substream
)
1204 struct via_spec
*spec
= codec
->spec
;
1206 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
1207 stream_tag
, 0, format
);
1211 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1212 struct hda_codec
*codec
,
1213 struct snd_pcm_substream
*substream
)
1215 struct via_spec
*spec
= codec
->spec
;
1216 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
1220 static struct hda_pcm_stream vt1708_pcm_analog_playback
= {
1224 .nid
= 0x10, /* NID to query formats and rates */
1226 .open
= via_playback_pcm_open
,
1227 .prepare
= via_playback_multi_pcm_prepare
,
1228 .cleanup
= via_playback_multi_pcm_cleanup
1232 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
1236 .nid
= 0x10, /* NID to query formats and rates */
1237 /* We got noisy outputs on the right channel on VT1708 when
1238 * 24bit samples are used. Until any workaround is found,
1239 * disable the 24bit format, so far.
1241 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1243 .open
= via_playback_pcm_open
,
1244 .prepare
= via_playback_multi_pcm_prepare
,
1245 .cleanup
= via_playback_multi_pcm_cleanup
1249 static struct hda_pcm_stream vt1708_pcm_analog_capture
= {
1253 .nid
= 0x15, /* NID to query formats and rates */
1255 .prepare
= via_capture_pcm_prepare
,
1256 .cleanup
= via_capture_pcm_cleanup
1260 static struct hda_pcm_stream vt1708_pcm_digital_playback
= {
1264 /* NID is set in via_build_pcms */
1266 .open
= via_dig_playback_pcm_open
,
1267 .close
= via_dig_playback_pcm_close
,
1268 .prepare
= via_dig_playback_pcm_prepare
,
1269 .cleanup
= via_dig_playback_pcm_cleanup
1273 static struct hda_pcm_stream vt1708_pcm_digital_capture
= {
1279 static int via_build_controls(struct hda_codec
*codec
)
1281 struct via_spec
*spec
= codec
->spec
;
1285 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1286 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1291 if (spec
->multiout
.dig_out_nid
) {
1292 err
= snd_hda_create_spdif_out_ctls(codec
,
1293 spec
->multiout
.dig_out_nid
);
1296 err
= snd_hda_create_spdif_share_sw(codec
,
1300 spec
->multiout
.share_spdif
= 1;
1302 if (spec
->dig_in_nid
) {
1303 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1308 /* init power states */
1309 set_jack_power_state(codec
);
1310 analog_low_current_mode(codec
, 1);
1312 via_free_kctls(codec
); /* no longer needed */
1316 static int via_build_pcms(struct hda_codec
*codec
)
1318 struct via_spec
*spec
= codec
->spec
;
1319 struct hda_pcm
*info
= spec
->pcm_rec
;
1321 codec
->num_pcms
= 1;
1322 codec
->pcm_info
= info
;
1324 info
->name
= spec
->stream_name_analog
;
1325 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *(spec
->stream_analog_playback
);
1326 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
1327 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *(spec
->stream_analog_capture
);
1328 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
1330 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
1331 spec
->multiout
.max_channels
;
1333 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
1336 info
->name
= spec
->stream_name_digital
;
1337 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
1338 if (spec
->multiout
.dig_out_nid
) {
1339 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1340 *(spec
->stream_digital_playback
);
1341 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1342 spec
->multiout
.dig_out_nid
;
1344 if (spec
->dig_in_nid
) {
1345 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
1346 *(spec
->stream_digital_capture
);
1347 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
1355 static void via_free(struct hda_codec
*codec
)
1357 struct via_spec
*spec
= codec
->spec
;
1362 via_free_kctls(codec
);
1363 vt1708_stop_hp_work(spec
);
1367 /* mute internal speaker if HP is plugged */
1368 static void via_hp_automute(struct hda_codec
*codec
)
1370 unsigned int present
= 0;
1371 struct via_spec
*spec
= codec
->spec
;
1373 present
= snd_hda_codec_read(codec
, spec
->autocfg
.hp_pins
[0], 0,
1374 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
1376 if (!spec
->hp_independent_mode
) {
1377 struct snd_ctl_elem_id id
;
1379 snd_hda_codec_amp_stereo(
1380 codec
, spec
->autocfg
.line_out_pins
[0], HDA_OUTPUT
, 0,
1381 HDA_AMP_MUTE
, present
? HDA_AMP_MUTE
: 0);
1383 memset(&id
, 0, sizeof(id
));
1384 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
1385 strcpy(id
.name
, "Front Playback Switch");
1386 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
1391 static void via_gpio_control(struct hda_codec
*codec
)
1393 unsigned int gpio_data
;
1394 unsigned int vol_counter
;
1396 unsigned int master_vol
;
1398 struct via_spec
*spec
= codec
->spec
;
1400 gpio_data
= snd_hda_codec_read(codec
, codec
->afg
, 0,
1401 AC_VERB_GET_GPIO_DATA
, 0) & 0x03;
1403 vol_counter
= (snd_hda_codec_read(codec
, codec
->afg
, 0,
1404 0xF84, 0) & 0x3F0000) >> 16;
1406 vol
= vol_counter
& 0x1F;
1407 master_vol
= snd_hda_codec_read(codec
, 0x1A, 0,
1408 AC_VERB_GET_AMP_GAIN_MUTE
,
1411 if (gpio_data
== 0x02) {
1412 /* unmute line out */
1413 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
1414 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
1416 if (vol_counter
& 0x20) {
1417 /* decrease volume */
1418 if (vol
> master_vol
)
1420 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
,
1424 /* increase volume */
1425 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
, 0,
1427 ((master_vol
+vol
) > 0x2A) ? 0x2A :
1430 } else if (!(gpio_data
& 0x02)) {
1432 snd_hda_codec_amp_stereo(codec
,
1433 spec
->autocfg
.line_out_pins
[0],
1434 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
1439 /* unsolicited event for jack sensing */
1440 static void via_unsol_event(struct hda_codec
*codec
,
1444 if (res
& VIA_HP_EVENT
)
1445 via_hp_automute(codec
);
1446 if (res
& VIA_GPIO_EVENT
)
1447 via_gpio_control(codec
);
1448 if (res
& VIA_JACK_EVENT
)
1449 set_jack_power_state(codec
);
1452 static int via_init(struct hda_codec
*codec
)
1454 struct via_spec
*spec
= codec
->spec
;
1456 for (i
= 0; i
< spec
->num_iverbs
; i
++)
1457 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
1459 spec
->codec_type
= get_codec_type(codec
);
1460 if (spec
->codec_type
== VT1708BCE
)
1461 spec
->codec_type
= VT1708S
; /* VT1708BCE & VT1708S are almost
1463 /* Lydia Add for EAPD enable */
1464 if (!spec
->dig_in_nid
) { /* No Digital In connection */
1465 if (spec
->dig_in_pin
) {
1466 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
1467 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1469 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
1470 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
1472 } else /* enable SPDIF-input pin */
1473 snd_hda_codec_write(codec
, spec
->autocfg
.dig_in_pin
, 0,
1474 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
1476 /* assign slave outs */
1477 if (spec
->slave_dig_outs
[0])
1478 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
1483 #ifdef SND_HDA_NEEDS_RESUME
1484 static int via_suspend(struct hda_codec
*codec
, pm_message_t state
)
1486 struct via_spec
*spec
= codec
->spec
;
1487 vt1708_stop_hp_work(spec
);
1492 #ifdef CONFIG_SND_HDA_POWER_SAVE
1493 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
1495 struct via_spec
*spec
= codec
->spec
;
1496 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
1502 static struct hda_codec_ops via_patch_ops
= {
1503 .build_controls
= via_build_controls
,
1504 .build_pcms
= via_build_pcms
,
1507 #ifdef SND_HDA_NEEDS_RESUME
1508 .suspend
= via_suspend
,
1510 #ifdef CONFIG_SND_HDA_POWER_SAVE
1511 .check_power_status
= via_check_power_status
,
1515 /* fill in the dac_nids table from the parsed pin configuration */
1516 static int vt1708_auto_fill_dac_nids(struct via_spec
*spec
,
1517 const struct auto_pin_cfg
*cfg
)
1522 spec
->multiout
.num_dacs
= cfg
->line_outs
;
1524 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1526 for(i
= 0; i
< 4; i
++) {
1527 nid
= cfg
->line_out_pins
[i
];
1529 /* config dac list */
1531 case AUTO_SEQ_FRONT
:
1532 spec
->multiout
.dac_nids
[i
] = 0x10;
1534 case AUTO_SEQ_CENLFE
:
1535 spec
->multiout
.dac_nids
[i
] = 0x12;
1537 case AUTO_SEQ_SURROUND
:
1538 spec
->multiout
.dac_nids
[i
] = 0x11;
1541 spec
->multiout
.dac_nids
[i
] = 0x13;
1550 /* add playback controls from the parsed DAC table */
1551 static int vt1708_auto_create_multi_out_ctls(struct via_spec
*spec
,
1552 const struct auto_pin_cfg
*cfg
)
1555 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1556 hda_nid_t nid
, nid_vol
, nid_vols
[] = {0x17, 0x19, 0x1a, 0x1b};
1559 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1560 nid
= cfg
->line_out_pins
[i
];
1565 nid_vol
= nid_vols
[i
];
1567 if (i
== AUTO_SEQ_CENLFE
) {
1569 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1570 "Center Playback Volume",
1571 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1575 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1576 "LFE Playback Volume",
1577 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1581 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1582 "Center Playback Switch",
1583 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1587 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1588 "LFE Playback Switch",
1589 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1593 } else if (i
== AUTO_SEQ_FRONT
){
1594 /* add control to mixer index 0 */
1595 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1596 "Master Front Playback Volume",
1597 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1601 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1602 "Master Front Playback Switch",
1603 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1608 /* add control to PW3 */
1609 sprintf(name
, "%s Playback Volume", chname
[i
]);
1610 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1611 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1615 sprintf(name
, "%s Playback Switch", chname
[i
]);
1616 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1617 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1622 sprintf(name
, "%s Playback Volume", chname
[i
]);
1623 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1624 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1628 sprintf(name
, "%s Playback Switch", chname
[i
]);
1629 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1630 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1640 static void create_hp_imux(struct via_spec
*spec
)
1643 struct hda_input_mux
*imux
= &spec
->private_imux
[1];
1644 static const char *texts
[] = { "OFF", "ON", NULL
};
1646 /* for hp mode select */
1648 while (texts
[i
] != NULL
) {
1649 imux
->items
[imux
->num_items
].label
= texts
[i
];
1650 imux
->items
[imux
->num_items
].index
= i
;
1655 spec
->hp_mux
= &spec
->private_imux
[1];
1658 static int vt1708_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1665 spec
->multiout
.hp_nid
= VT1708_HP_NID
; /* AOW3 */
1666 spec
->hp_independent_mode_index
= 1;
1668 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1669 "Headphone Playback Volume",
1670 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1673 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1674 "Headphone Playback Switch",
1675 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1679 create_hp_imux(spec
);
1684 /* create playback/capture controls for input pins */
1685 static int vt1708_auto_create_analog_input_ctls(struct via_spec
*spec
,
1686 const struct auto_pin_cfg
*cfg
)
1688 static char *labels
[] = {
1689 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1691 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1692 int i
, err
, idx
= 0;
1694 /* for internal loopback recording select */
1695 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1696 imux
->items
[imux
->num_items
].index
= idx
;
1699 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1700 if (!cfg
->input_pins
[i
])
1703 switch (cfg
->input_pins
[i
]) {
1704 case 0x1d: /* Mic */
1708 case 0x1e: /* Line In */
1712 case 0x21: /* Front Mic */
1720 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x17);
1723 imux
->items
[imux
->num_items
].label
= labels
[i
];
1724 imux
->items
[imux
->num_items
].index
= idx
;
1730 #ifdef CONFIG_SND_HDA_POWER_SAVE
1731 static struct hda_amp_list vt1708_loopbacks
[] = {
1732 { 0x17, HDA_INPUT
, 1 },
1733 { 0x17, HDA_INPUT
, 2 },
1734 { 0x17, HDA_INPUT
, 3 },
1735 { 0x17, HDA_INPUT
, 4 },
1740 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
1742 unsigned int def_conf
;
1743 unsigned char seqassoc
;
1745 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
1746 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
1747 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
1748 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
1749 && (seqassoc
== 0xf0 || seqassoc
== 0xff)) {
1750 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
1751 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
1757 static int vt1708_jack_detectect_get(struct snd_kcontrol
*kcontrol
,
1758 struct snd_ctl_elem_value
*ucontrol
)
1760 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1761 struct via_spec
*spec
= codec
->spec
;
1763 if (spec
->codec_type
!= VT1708
)
1765 spec
->vt1708_jack_detectect
=
1766 !((snd_hda_codec_read(codec
, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
1767 ucontrol
->value
.integer
.value
[0] = spec
->vt1708_jack_detectect
;
1771 static int vt1708_jack_detectect_put(struct snd_kcontrol
*kcontrol
,
1772 struct snd_ctl_elem_value
*ucontrol
)
1774 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1775 struct via_spec
*spec
= codec
->spec
;
1778 if (spec
->codec_type
!= VT1708
)
1780 spec
->vt1708_jack_detectect
= ucontrol
->value
.integer
.value
[0];
1781 change
= (0x1 & (snd_hda_codec_read(codec
, 0x1, 0, 0xf84, 0) >> 8))
1782 == !spec
->vt1708_jack_detectect
;
1783 if (spec
->vt1708_jack_detectect
) {
1784 mute_aa_path(codec
, 1);
1785 notify_aa_path_ctls(codec
);
1790 static struct snd_kcontrol_new vt1708_jack_detectect
[] = {
1792 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1793 .name
= "Jack Detect",
1795 .info
= snd_ctl_boolean_mono_info
,
1796 .get
= vt1708_jack_detectect_get
,
1797 .put
= vt1708_jack_detectect_put
,
1802 static int vt1708_parse_auto_config(struct hda_codec
*codec
)
1804 struct via_spec
*spec
= codec
->spec
;
1807 /* Add HP and CD pin config connect bit re-config action */
1808 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
1809 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
1811 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1814 err
= vt1708_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1817 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1818 return 0; /* can't find valid BIOS pin config */
1820 err
= vt1708_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1823 err
= vt1708_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1826 err
= vt1708_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1829 /* add jack detect on/off control */
1830 err
= snd_hda_add_new_ctls(codec
, vt1708_jack_detectect
);
1834 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1836 if (spec
->autocfg
.dig_outs
)
1837 spec
->multiout
.dig_out_nid
= VT1708_DIGOUT_NID
;
1838 spec
->dig_in_pin
= VT1708_DIGIN_PIN
;
1839 if (spec
->autocfg
.dig_in_pin
)
1840 spec
->dig_in_nid
= VT1708_DIGIN_NID
;
1842 if (spec
->kctls
.list
)
1843 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
1845 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_volume_init_verbs
;
1847 spec
->input_mux
= &spec
->private_imux
[0];
1850 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1852 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
1856 /* init callback for auto-configuration model -- overriding the default init */
1857 static int via_auto_init(struct hda_codec
*codec
)
1860 via_auto_init_multi_out(codec
);
1861 via_auto_init_hp_out(codec
);
1862 via_auto_init_analog_input(codec
);
1866 static void vt1708_update_hp_jack_state(struct work_struct
*work
)
1868 struct via_spec
*spec
= container_of(work
, struct via_spec
,
1869 vt1708_hp_work
.work
);
1870 if (spec
->codec_type
!= VT1708
)
1872 /* if jack state toggled */
1873 if (spec
->vt1708_hp_present
1874 != (snd_hda_codec_read(spec
->codec
, spec
->autocfg
.hp_pins
[0], 0,
1875 AC_VERB_GET_PIN_SENSE
, 0) >> 31)) {
1876 spec
->vt1708_hp_present
^= 1;
1877 via_hp_automute(spec
->codec
);
1879 vt1708_start_hp_work(spec
);
1882 static int get_mux_nids(struct hda_codec
*codec
)
1884 struct via_spec
*spec
= codec
->spec
;
1885 hda_nid_t nid
, conn
[8];
1889 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1890 nid
= spec
->adc_nids
[i
];
1892 type
= get_wcaps_type(get_wcaps(codec
, nid
));
1893 if (type
== AC_WID_PIN
)
1895 n
= snd_hda_get_connections(codec
, nid
, conn
,
1900 spec
->mux_nids
[i
] = nid
;
1909 static int patch_vt1708(struct hda_codec
*codec
)
1911 struct via_spec
*spec
;
1914 /* create a codec specific record */
1915 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1921 /* automatic parse from the BIOS config */
1922 err
= vt1708_parse_auto_config(codec
);
1927 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
1928 "from BIOS. Using genenic mode...\n");
1932 spec
->stream_name_analog
= "VT1708 Analog";
1933 spec
->stream_analog_playback
= &vt1708_pcm_analog_playback
;
1934 /* disable 32bit format on VT1708 */
1935 if (codec
->vendor_id
== 0x11061708)
1936 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
1937 spec
->stream_analog_capture
= &vt1708_pcm_analog_capture
;
1939 spec
->stream_name_digital
= "VT1708 Digital";
1940 spec
->stream_digital_playback
= &vt1708_pcm_digital_playback
;
1941 spec
->stream_digital_capture
= &vt1708_pcm_digital_capture
;
1944 if (!spec
->adc_nids
&& spec
->input_mux
) {
1945 spec
->adc_nids
= vt1708_adc_nids
;
1946 spec
->num_adc_nids
= ARRAY_SIZE(vt1708_adc_nids
);
1947 get_mux_nids(codec
);
1948 spec
->mixers
[spec
->num_mixers
] = vt1708_capture_mixer
;
1952 codec
->patch_ops
= via_patch_ops
;
1954 codec
->patch_ops
.init
= via_auto_init
;
1955 #ifdef CONFIG_SND_HDA_POWER_SAVE
1956 spec
->loopback
.amplist
= vt1708_loopbacks
;
1958 spec
->codec
= codec
;
1959 INIT_DELAYED_WORK(&spec
->vt1708_hp_work
, vt1708_update_hp_jack_state
);
1963 /* capture mixer elements */
1964 static struct snd_kcontrol_new vt1709_capture_mixer
[] = {
1965 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT
),
1966 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT
),
1967 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT
),
1968 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT
),
1969 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT
),
1970 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT
),
1972 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1973 /* The multiple "Capture Source" controls confuse alsamixer
1974 * So call somewhat different..
1976 /* .name = "Capture Source", */
1977 .name
= "Input Source",
1979 .info
= via_mux_enum_info
,
1980 .get
= via_mux_enum_get
,
1981 .put
= via_mux_enum_put
,
1986 static struct hda_verb vt1709_uniwill_init_verbs
[] = {
1987 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
,
1988 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
1993 * generic initialization of ADC, input mixers and output mixers
1995 static struct hda_verb vt1709_10ch_volume_init_verbs
[] = {
1997 * Unmute ADC0-2 and set the default input to mic-in
1999 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2000 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2001 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2004 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2007 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2008 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2009 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2010 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2011 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2012 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2015 * Set up output selector (0x1a, 0x1b, 0x29)
2017 /* set vol=0 to output mixers */
2018 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2019 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2020 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2023 * Unmute PW3 and PW4
2025 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2026 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2028 /* Set input of PW4 as AOW4 */
2029 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
2030 /* PW9 Output enable */
2031 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2035 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback
= {
2039 .nid
= 0x10, /* NID to query formats and rates */
2041 .open
= via_playback_pcm_open
,
2042 .prepare
= via_playback_multi_pcm_prepare
,
2043 .cleanup
= via_playback_multi_pcm_cleanup
,
2047 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback
= {
2051 .nid
= 0x10, /* NID to query formats and rates */
2053 .open
= via_playback_pcm_open
,
2054 .prepare
= via_playback_multi_pcm_prepare
,
2055 .cleanup
= via_playback_multi_pcm_cleanup
,
2059 static struct hda_pcm_stream vt1709_pcm_analog_capture
= {
2063 .nid
= 0x14, /* NID to query formats and rates */
2065 .prepare
= via_capture_pcm_prepare
,
2066 .cleanup
= via_capture_pcm_cleanup
2070 static struct hda_pcm_stream vt1709_pcm_digital_playback
= {
2074 /* NID is set in via_build_pcms */
2076 .open
= via_dig_playback_pcm_open
,
2077 .close
= via_dig_playback_pcm_close
2081 static struct hda_pcm_stream vt1709_pcm_digital_capture
= {
2087 static int vt1709_auto_fill_dac_nids(struct via_spec
*spec
,
2088 const struct auto_pin_cfg
*cfg
)
2093 if (cfg
->line_outs
== 4) /* 10 channels */
2094 spec
->multiout
.num_dacs
= cfg
->line_outs
+1; /* AOW0~AOW4 */
2095 else if (cfg
->line_outs
== 3) /* 6 channels */
2096 spec
->multiout
.num_dacs
= cfg
->line_outs
; /* AOW0~AOW2 */
2098 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2100 if (cfg
->line_outs
== 4) { /* 10 channels */
2101 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2102 nid
= cfg
->line_out_pins
[i
];
2104 /* config dac list */
2106 case AUTO_SEQ_FRONT
:
2108 spec
->multiout
.dac_nids
[i
] = 0x10;
2110 case AUTO_SEQ_CENLFE
:
2112 spec
->multiout
.dac_nids
[i
] = 0x12;
2114 case AUTO_SEQ_SURROUND
:
2116 spec
->multiout
.dac_nids
[i
] = 0x11;
2120 spec
->multiout
.dac_nids
[i
] = 0x27;
2127 spec
->multiout
.dac_nids
[cfg
->line_outs
] = 0x28; /* AOW4 */
2129 } else if (cfg
->line_outs
== 3) { /* 6 channels */
2130 for(i
= 0; i
< cfg
->line_outs
; i
++) {
2131 nid
= cfg
->line_out_pins
[i
];
2133 /* config dac list */
2135 case AUTO_SEQ_FRONT
:
2137 spec
->multiout
.dac_nids
[i
] = 0x10;
2139 case AUTO_SEQ_CENLFE
:
2141 spec
->multiout
.dac_nids
[i
] = 0x12;
2143 case AUTO_SEQ_SURROUND
:
2145 spec
->multiout
.dac_nids
[i
] = 0x11;
2157 /* add playback controls from the parsed DAC table */
2158 static int vt1709_auto_create_multi_out_ctls(struct via_spec
*spec
,
2159 const struct auto_pin_cfg
*cfg
)
2162 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2163 hda_nid_t nid
, nid_vol
, nid_vols
[] = {0x18, 0x1a, 0x1b, 0x29};
2166 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2167 nid
= cfg
->line_out_pins
[i
];
2172 nid_vol
= nid_vols
[i
];
2174 if (i
== AUTO_SEQ_CENLFE
) {
2176 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2177 "Center Playback Volume",
2178 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2182 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2183 "LFE Playback Volume",
2184 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2188 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2189 "Center Playback Switch",
2190 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2194 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2195 "LFE Playback Switch",
2196 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2200 } else if (i
== AUTO_SEQ_FRONT
){
2201 /* ADD control to mixer index 0 */
2202 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2203 "Master Front Playback Volume",
2204 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2208 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2209 "Master Front Playback Switch",
2210 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2215 /* add control to PW3 */
2216 sprintf(name
, "%s Playback Volume", chname
[i
]);
2217 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2218 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2222 sprintf(name
, "%s Playback Switch", chname
[i
]);
2223 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2224 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2228 } else if (i
== AUTO_SEQ_SURROUND
) {
2229 sprintf(name
, "%s Playback Volume", chname
[i
]);
2230 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2231 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2235 sprintf(name
, "%s Playback Switch", chname
[i
]);
2236 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2237 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2241 } else if (i
== AUTO_SEQ_SIDE
) {
2242 sprintf(name
, "%s Playback Volume", chname
[i
]);
2243 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2244 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2248 sprintf(name
, "%s Playback Switch", chname
[i
]);
2249 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2250 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2260 static int vt1709_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2267 if (spec
->multiout
.num_dacs
== 5) /* 10 channels */
2268 spec
->multiout
.hp_nid
= VT1709_HP_DAC_NID
;
2269 else if (spec
->multiout
.num_dacs
== 3) /* 6 channels */
2270 spec
->multiout
.hp_nid
= 0;
2271 spec
->hp_independent_mode_index
= 1;
2273 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2274 "Headphone Playback Volume",
2275 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2278 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2279 "Headphone Playback Switch",
2280 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2287 /* create playback/capture controls for input pins */
2288 static int vt1709_auto_create_analog_input_ctls(struct via_spec
*spec
,
2289 const struct auto_pin_cfg
*cfg
)
2291 static char *labels
[] = {
2292 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2294 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2295 int i
, err
, idx
= 0;
2297 /* for internal loopback recording select */
2298 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2299 imux
->items
[imux
->num_items
].index
= idx
;
2302 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2303 if (!cfg
->input_pins
[i
])
2306 switch (cfg
->input_pins
[i
]) {
2307 case 0x1d: /* Mic */
2311 case 0x1e: /* Line In */
2315 case 0x21: /* Front Mic */
2323 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x18);
2326 imux
->items
[imux
->num_items
].label
= labels
[i
];
2327 imux
->items
[imux
->num_items
].index
= idx
;
2333 static int vt1709_parse_auto_config(struct hda_codec
*codec
)
2335 struct via_spec
*spec
= codec
->spec
;
2338 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2341 err
= vt1709_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2344 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2345 return 0; /* can't find valid BIOS pin config */
2347 err
= vt1709_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2350 err
= vt1709_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2353 err
= vt1709_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2357 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2359 if (spec
->autocfg
.dig_outs
)
2360 spec
->multiout
.dig_out_nid
= VT1709_DIGOUT_NID
;
2361 spec
->dig_in_pin
= VT1709_DIGIN_PIN
;
2362 if (spec
->autocfg
.dig_in_pin
)
2363 spec
->dig_in_nid
= VT1709_DIGIN_NID
;
2365 if (spec
->kctls
.list
)
2366 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2368 spec
->input_mux
= &spec
->private_imux
[0];
2371 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2373 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
2377 #ifdef CONFIG_SND_HDA_POWER_SAVE
2378 static struct hda_amp_list vt1709_loopbacks
[] = {
2379 { 0x18, HDA_INPUT
, 1 },
2380 { 0x18, HDA_INPUT
, 2 },
2381 { 0x18, HDA_INPUT
, 3 },
2382 { 0x18, HDA_INPUT
, 4 },
2387 static int patch_vt1709_10ch(struct hda_codec
*codec
)
2389 struct via_spec
*spec
;
2392 /* create a codec specific record */
2393 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2399 err
= vt1709_parse_auto_config(codec
);
2404 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
2405 "Using genenic mode...\n");
2408 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_10ch_volume_init_verbs
;
2409 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
2411 spec
->stream_name_analog
= "VT1709 Analog";
2412 spec
->stream_analog_playback
= &vt1709_10ch_pcm_analog_playback
;
2413 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
2415 spec
->stream_name_digital
= "VT1709 Digital";
2416 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
2417 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
2420 if (!spec
->adc_nids
&& spec
->input_mux
) {
2421 spec
->adc_nids
= vt1709_adc_nids
;
2422 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
2423 get_mux_nids(codec
);
2424 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
2428 codec
->patch_ops
= via_patch_ops
;
2430 codec
->patch_ops
.init
= via_auto_init
;
2431 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2432 #ifdef CONFIG_SND_HDA_POWER_SAVE
2433 spec
->loopback
.amplist
= vt1709_loopbacks
;
2439 * generic initialization of ADC, input mixers and output mixers
2441 static struct hda_verb vt1709_6ch_volume_init_verbs
[] = {
2443 * Unmute ADC0-2 and set the default input to mic-in
2445 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2446 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2447 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2450 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2453 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2454 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2455 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2456 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2457 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2458 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2461 * Set up output selector (0x1a, 0x1b, 0x29)
2463 /* set vol=0 to output mixers */
2464 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2465 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2466 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2469 * Unmute PW3 and PW4
2471 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2472 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2474 /* Set input of PW4 as MW0 */
2475 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
2476 /* PW9 Output enable */
2477 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2481 static int patch_vt1709_6ch(struct hda_codec
*codec
)
2483 struct via_spec
*spec
;
2486 /* create a codec specific record */
2487 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2493 err
= vt1709_parse_auto_config(codec
);
2498 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
2499 "Using genenic mode...\n");
2502 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_6ch_volume_init_verbs
;
2503 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
2505 spec
->stream_name_analog
= "VT1709 Analog";
2506 spec
->stream_analog_playback
= &vt1709_6ch_pcm_analog_playback
;
2507 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
2509 spec
->stream_name_digital
= "VT1709 Digital";
2510 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
2511 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
2514 if (!spec
->adc_nids
&& spec
->input_mux
) {
2515 spec
->adc_nids
= vt1709_adc_nids
;
2516 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
2517 get_mux_nids(codec
);
2518 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
2522 codec
->patch_ops
= via_patch_ops
;
2524 codec
->patch_ops
.init
= via_auto_init
;
2525 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2526 #ifdef CONFIG_SND_HDA_POWER_SAVE
2527 spec
->loopback
.amplist
= vt1709_loopbacks
;
2532 /* capture mixer elements */
2533 static struct snd_kcontrol_new vt1708B_capture_mixer
[] = {
2534 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
2535 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
2536 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
2537 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
2539 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2540 /* The multiple "Capture Source" controls confuse alsamixer
2541 * So call somewhat different..
2543 /* .name = "Capture Source", */
2544 .name
= "Input Source",
2546 .info
= via_mux_enum_info
,
2547 .get
= via_mux_enum_get
,
2548 .put
= via_mux_enum_put
,
2553 * generic initialization of ADC, input mixers and output mixers
2555 static struct hda_verb vt1708B_8ch_volume_init_verbs
[] = {
2557 * Unmute ADC0-1 and set the default input to mic-in
2559 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2560 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2563 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2566 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2567 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2568 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2569 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2570 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2571 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2574 * Set up output mixers
2576 /* set vol=0 to output mixers */
2577 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2578 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2579 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2581 /* Setup default input to PW4 */
2582 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x1},
2583 /* PW9 Output enable */
2584 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2585 /* PW10 Input enable */
2586 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2590 static struct hda_verb vt1708B_4ch_volume_init_verbs
[] = {
2592 * Unmute ADC0-1 and set the default input to mic-in
2594 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2595 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2598 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2601 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2602 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2603 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2604 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2605 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2606 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2609 * Set up output mixers
2611 /* set vol=0 to output mixers */
2612 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2613 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2614 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2616 /* Setup default input of PW4 to MW0 */
2617 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2618 /* PW9 Output enable */
2619 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2620 /* PW10 Input enable */
2621 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2625 static struct hda_verb vt1708B_uniwill_init_verbs
[] = {
2626 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
2627 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
2628 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2629 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2630 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2631 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2632 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2633 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2634 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2638 static int via_pcm_open_close(struct hda_pcm_stream
*hinfo
,
2639 struct hda_codec
*codec
,
2640 struct snd_pcm_substream
*substream
)
2642 int idle
= substream
->pstr
->substream_opened
== 1
2643 && substream
->ref_count
== 0;
2645 analog_low_current_mode(codec
, idle
);
2649 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback
= {
2653 .nid
= 0x10, /* NID to query formats and rates */
2655 .open
= via_playback_pcm_open
,
2656 .prepare
= via_playback_multi_pcm_prepare
,
2657 .cleanup
= via_playback_multi_pcm_cleanup
,
2658 .close
= via_pcm_open_close
2662 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback
= {
2666 .nid
= 0x10, /* NID to query formats and rates */
2668 .open
= via_playback_pcm_open
,
2669 .prepare
= via_playback_multi_pcm_prepare
,
2670 .cleanup
= via_playback_multi_pcm_cleanup
2674 static struct hda_pcm_stream vt1708B_pcm_analog_capture
= {
2678 .nid
= 0x13, /* NID to query formats and rates */
2680 .open
= via_pcm_open_close
,
2681 .prepare
= via_capture_pcm_prepare
,
2682 .cleanup
= via_capture_pcm_cleanup
,
2683 .close
= via_pcm_open_close
2687 static struct hda_pcm_stream vt1708B_pcm_digital_playback
= {
2691 /* NID is set in via_build_pcms */
2693 .open
= via_dig_playback_pcm_open
,
2694 .close
= via_dig_playback_pcm_close
,
2695 .prepare
= via_dig_playback_pcm_prepare
,
2696 .cleanup
= via_dig_playback_pcm_cleanup
2700 static struct hda_pcm_stream vt1708B_pcm_digital_capture
= {
2706 /* fill in the dac_nids table from the parsed pin configuration */
2707 static int vt1708B_auto_fill_dac_nids(struct via_spec
*spec
,
2708 const struct auto_pin_cfg
*cfg
)
2713 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2715 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2717 for (i
= 0; i
< 4; i
++) {
2718 nid
= cfg
->line_out_pins
[i
];
2720 /* config dac list */
2722 case AUTO_SEQ_FRONT
:
2723 spec
->multiout
.dac_nids
[i
] = 0x10;
2725 case AUTO_SEQ_CENLFE
:
2726 spec
->multiout
.dac_nids
[i
] = 0x24;
2728 case AUTO_SEQ_SURROUND
:
2729 spec
->multiout
.dac_nids
[i
] = 0x11;
2732 spec
->multiout
.dac_nids
[i
] = 0x25;
2741 /* add playback controls from the parsed DAC table */
2742 static int vt1708B_auto_create_multi_out_ctls(struct via_spec
*spec
,
2743 const struct auto_pin_cfg
*cfg
)
2746 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2747 hda_nid_t nid_vols
[] = {0x16, 0x18, 0x26, 0x27};
2748 hda_nid_t nid
, nid_vol
= 0;
2751 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2752 nid
= cfg
->line_out_pins
[i
];
2757 nid_vol
= nid_vols
[i
];
2759 if (i
== AUTO_SEQ_CENLFE
) {
2761 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2762 "Center Playback Volume",
2763 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2767 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2768 "LFE Playback Volume",
2769 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2773 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2774 "Center Playback Switch",
2775 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2779 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2780 "LFE Playback Switch",
2781 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2785 } else if (i
== AUTO_SEQ_FRONT
) {
2786 /* add control to mixer index 0 */
2787 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2788 "Master Front Playback Volume",
2789 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2793 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2794 "Master Front Playback Switch",
2795 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2800 /* add control to PW3 */
2801 sprintf(name
, "%s Playback Volume", chname
[i
]);
2802 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2803 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2807 sprintf(name
, "%s Playback Switch", chname
[i
]);
2808 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2809 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2814 sprintf(name
, "%s Playback Volume", chname
[i
]);
2815 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2816 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2820 sprintf(name
, "%s Playback Switch", chname
[i
]);
2821 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2822 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2832 static int vt1708B_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2839 spec
->multiout
.hp_nid
= VT1708B_HP_NID
; /* AOW3 */
2840 spec
->hp_independent_mode_index
= 1;
2842 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2843 "Headphone Playback Volume",
2844 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2847 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2848 "Headphone Playback Switch",
2849 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2853 create_hp_imux(spec
);
2858 /* create playback/capture controls for input pins */
2859 static int vt1708B_auto_create_analog_input_ctls(struct via_spec
*spec
,
2860 const struct auto_pin_cfg
*cfg
)
2862 static char *labels
[] = {
2863 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2865 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2866 int i
, err
, idx
= 0;
2868 /* for internal loopback recording select */
2869 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2870 imux
->items
[imux
->num_items
].index
= idx
;
2873 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2874 if (!cfg
->input_pins
[i
])
2877 switch (cfg
->input_pins
[i
]) {
2878 case 0x1a: /* Mic */
2882 case 0x1b: /* Line In */
2886 case 0x1e: /* Front Mic */
2894 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
2897 imux
->items
[imux
->num_items
].label
= labels
[i
];
2898 imux
->items
[imux
->num_items
].index
= idx
;
2904 static int vt1708B_parse_auto_config(struct hda_codec
*codec
)
2906 struct via_spec
*spec
= codec
->spec
;
2909 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2912 err
= vt1708B_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2915 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2916 return 0; /* can't find valid BIOS pin config */
2918 err
= vt1708B_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2921 err
= vt1708B_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2924 err
= vt1708B_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2928 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2930 if (spec
->autocfg
.dig_outs
)
2931 spec
->multiout
.dig_out_nid
= VT1708B_DIGOUT_NID
;
2932 spec
->dig_in_pin
= VT1708B_DIGIN_PIN
;
2933 if (spec
->autocfg
.dig_in_pin
)
2934 spec
->dig_in_nid
= VT1708B_DIGIN_NID
;
2936 if (spec
->kctls
.list
)
2937 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2939 spec
->input_mux
= &spec
->private_imux
[0];
2942 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2944 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
2948 #ifdef CONFIG_SND_HDA_POWER_SAVE
2949 static struct hda_amp_list vt1708B_loopbacks
[] = {
2950 { 0x16, HDA_INPUT
, 1 },
2951 { 0x16, HDA_INPUT
, 2 },
2952 { 0x16, HDA_INPUT
, 3 },
2953 { 0x16, HDA_INPUT
, 4 },
2957 static int patch_vt1708S(struct hda_codec
*codec
);
2958 static int patch_vt1708B_8ch(struct hda_codec
*codec
)
2960 struct via_spec
*spec
;
2963 if (get_codec_type(codec
) == VT1708BCE
)
2964 return patch_vt1708S(codec
);
2965 /* create a codec specific record */
2966 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2972 /* automatic parse from the BIOS config */
2973 err
= vt1708B_parse_auto_config(codec
);
2978 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2979 "from BIOS. Using genenic mode...\n");
2982 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_8ch_volume_init_verbs
;
2983 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2985 spec
->stream_name_analog
= "VT1708B Analog";
2986 spec
->stream_analog_playback
= &vt1708B_8ch_pcm_analog_playback
;
2987 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2989 spec
->stream_name_digital
= "VT1708B Digital";
2990 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2991 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2993 if (!spec
->adc_nids
&& spec
->input_mux
) {
2994 spec
->adc_nids
= vt1708B_adc_nids
;
2995 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2996 get_mux_nids(codec
);
2997 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
3001 codec
->patch_ops
= via_patch_ops
;
3003 codec
->patch_ops
.init
= via_auto_init
;
3004 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3005 #ifdef CONFIG_SND_HDA_POWER_SAVE
3006 spec
->loopback
.amplist
= vt1708B_loopbacks
;
3012 static int patch_vt1708B_4ch(struct hda_codec
*codec
)
3014 struct via_spec
*spec
;
3017 /* create a codec specific record */
3018 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3024 /* automatic parse from the BIOS config */
3025 err
= vt1708B_parse_auto_config(codec
);
3030 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3031 "from BIOS. Using genenic mode...\n");
3034 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_4ch_volume_init_verbs
;
3035 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
3037 spec
->stream_name_analog
= "VT1708B Analog";
3038 spec
->stream_analog_playback
= &vt1708B_4ch_pcm_analog_playback
;
3039 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
3041 spec
->stream_name_digital
= "VT1708B Digital";
3042 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
3043 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
3045 if (!spec
->adc_nids
&& spec
->input_mux
) {
3046 spec
->adc_nids
= vt1708B_adc_nids
;
3047 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
3048 get_mux_nids(codec
);
3049 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
3053 codec
->patch_ops
= via_patch_ops
;
3055 codec
->patch_ops
.init
= via_auto_init
;
3056 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3057 #ifdef CONFIG_SND_HDA_POWER_SAVE
3058 spec
->loopback
.amplist
= vt1708B_loopbacks
;
3064 /* Patch for VT1708S */
3066 /* VT1708S software backdoor based override for buggy hardware micboost
3068 #define MIC_BOOST_VOLUME(xname, nid) { \
3069 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3072 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3073 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
3074 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
3075 .info = mic_boost_volume_info, \
3076 .get = snd_hda_mixer_amp_volume_get, \
3077 .put = snd_hda_mixer_amp_volume_put, \
3078 .tlv = { .c = mic_boost_tlv }, \
3079 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
3081 /* capture mixer elements */
3082 static struct snd_kcontrol_new vt1708S_capture_mixer
[] = {
3083 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
3084 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
3085 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
3086 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
3087 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
3088 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
3090 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3091 /* The multiple "Capture Source" controls confuse alsamixer
3092 * So call somewhat different..
3094 /* .name = "Capture Source", */
3095 .name
= "Input Source",
3097 .info
= via_mux_enum_info
,
3098 .get
= via_mux_enum_get
,
3099 .put
= via_mux_enum_put
,
3104 static struct hda_verb vt1708S_volume_init_verbs
[] = {
3105 /* Unmute ADC0-1 and set the default input to mic-in */
3106 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3107 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3109 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3110 * analog-loopback mixer widget */
3111 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3112 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3113 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3114 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3115 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3116 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3118 /* Setup default input of PW4 to MW0 */
3119 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
3120 /* PW9, PW10 Output enable */
3121 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3122 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3123 /* Enable Mic Boost Volume backdoor */
3128 static struct hda_verb vt1708S_uniwill_init_verbs
[] = {
3129 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
3130 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
3131 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3132 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3133 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3134 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3135 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3136 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3137 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3141 static struct hda_pcm_stream vt1708S_pcm_analog_playback
= {
3145 .nid
= 0x10, /* NID to query formats and rates */
3147 .open
= via_playback_pcm_open
,
3148 .prepare
= via_playback_multi_pcm_prepare
,
3149 .cleanup
= via_playback_multi_pcm_cleanup
,
3150 .close
= via_pcm_open_close
3154 static struct hda_pcm_stream vt1708S_pcm_analog_capture
= {
3158 .nid
= 0x13, /* NID to query formats and rates */
3160 .open
= via_pcm_open_close
,
3161 .prepare
= via_capture_pcm_prepare
,
3162 .cleanup
= via_capture_pcm_cleanup
,
3163 .close
= via_pcm_open_close
3167 static struct hda_pcm_stream vt1708S_pcm_digital_playback
= {
3171 /* NID is set in via_build_pcms */
3173 .open
= via_dig_playback_pcm_open
,
3174 .close
= via_dig_playback_pcm_close
,
3175 .prepare
= via_dig_playback_pcm_prepare
,
3176 .cleanup
= via_dig_playback_pcm_cleanup
3180 /* fill in the dac_nids table from the parsed pin configuration */
3181 static int vt1708S_auto_fill_dac_nids(struct via_spec
*spec
,
3182 const struct auto_pin_cfg
*cfg
)
3187 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3189 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3191 for (i
= 0; i
< 4; i
++) {
3192 nid
= cfg
->line_out_pins
[i
];
3194 /* config dac list */
3196 case AUTO_SEQ_FRONT
:
3197 spec
->multiout
.dac_nids
[i
] = 0x10;
3199 case AUTO_SEQ_CENLFE
:
3200 spec
->multiout
.dac_nids
[i
] = 0x24;
3202 case AUTO_SEQ_SURROUND
:
3203 spec
->multiout
.dac_nids
[i
] = 0x11;
3206 spec
->multiout
.dac_nids
[i
] = 0x25;
3215 /* add playback controls from the parsed DAC table */
3216 static int vt1708S_auto_create_multi_out_ctls(struct via_spec
*spec
,
3217 const struct auto_pin_cfg
*cfg
)
3220 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
3221 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x24, 0x25};
3222 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x26, 0x27};
3223 hda_nid_t nid
, nid_vol
, nid_mute
;
3226 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
3227 nid
= cfg
->line_out_pins
[i
];
3232 nid_vol
= nid_vols
[i
];
3233 nid_mute
= nid_mutes
[i
];
3235 if (i
== AUTO_SEQ_CENLFE
) {
3237 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3238 "Center Playback Volume",
3239 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3243 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3244 "LFE Playback Volume",
3245 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3249 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3250 "Center Playback Switch",
3251 HDA_COMPOSE_AMP_VAL(nid_mute
,
3256 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3257 "LFE Playback Switch",
3258 HDA_COMPOSE_AMP_VAL(nid_mute
,
3263 } else if (i
== AUTO_SEQ_FRONT
) {
3264 /* add control to mixer index 0 */
3265 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3266 "Master Front Playback Volume",
3267 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3271 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3272 "Master Front Playback Switch",
3273 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3279 sprintf(name
, "%s Playback Volume", chname
[i
]);
3280 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3281 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3285 sprintf(name
, "%s Playback Switch", chname
[i
]);
3286 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3287 HDA_COMPOSE_AMP_VAL(nid_mute
,
3293 sprintf(name
, "%s Playback Volume", chname
[i
]);
3294 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3295 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3299 sprintf(name
, "%s Playback Switch", chname
[i
]);
3300 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3301 HDA_COMPOSE_AMP_VAL(nid_mute
,
3312 static int vt1708S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3319 spec
->multiout
.hp_nid
= VT1708S_HP_NID
; /* AOW3 */
3320 spec
->hp_independent_mode_index
= 1;
3322 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3323 "Headphone Playback Volume",
3324 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
3328 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3329 "Headphone Playback Switch",
3330 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3334 create_hp_imux(spec
);
3339 /* create playback/capture controls for input pins */
3340 static int vt1708S_auto_create_analog_input_ctls(struct via_spec
*spec
,
3341 const struct auto_pin_cfg
*cfg
)
3343 static char *labels
[] = {
3344 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3346 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3347 int i
, err
, idx
= 0;
3349 /* for internal loopback recording select */
3350 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3351 imux
->items
[imux
->num_items
].index
= 5;
3354 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3355 if (!cfg
->input_pins
[i
])
3358 switch (cfg
->input_pins
[i
]) {
3359 case 0x1a: /* Mic */
3363 case 0x1b: /* Line In */
3367 case 0x1e: /* Front Mic */
3375 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
3378 imux
->items
[imux
->num_items
].label
= labels
[i
];
3379 imux
->items
[imux
->num_items
].index
= idx
-1;
3385 /* fill out digital output widgets; one for master and one for slave outputs */
3386 static void fill_dig_outs(struct hda_codec
*codec
)
3388 struct via_spec
*spec
= codec
->spec
;
3391 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
3395 nid
= spec
->autocfg
.dig_out_pins
[i
];
3398 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
3401 if (!spec
->multiout
.dig_out_nid
)
3402 spec
->multiout
.dig_out_nid
= nid
;
3404 spec
->slave_dig_outs
[0] = nid
;
3405 break; /* at most two dig outs */
3410 static int vt1708S_parse_auto_config(struct hda_codec
*codec
)
3412 struct via_spec
*spec
= codec
->spec
;
3415 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3418 err
= vt1708S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3421 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3422 return 0; /* can't find valid BIOS pin config */
3424 err
= vt1708S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
3427 err
= vt1708S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3430 err
= vt1708S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3434 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3436 fill_dig_outs(codec
);
3438 if (spec
->kctls
.list
)
3439 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3441 spec
->input_mux
= &spec
->private_imux
[0];
3444 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3446 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
3450 #ifdef CONFIG_SND_HDA_POWER_SAVE
3451 static struct hda_amp_list vt1708S_loopbacks
[] = {
3452 { 0x16, HDA_INPUT
, 1 },
3453 { 0x16, HDA_INPUT
, 2 },
3454 { 0x16, HDA_INPUT
, 3 },
3455 { 0x16, HDA_INPUT
, 4 },
3460 static int patch_vt1708S(struct hda_codec
*codec
)
3462 struct via_spec
*spec
;
3465 /* create a codec specific record */
3466 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3472 /* automatic parse from the BIOS config */
3473 err
= vt1708S_parse_auto_config(codec
);
3478 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3479 "from BIOS. Using genenic mode...\n");
3482 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_volume_init_verbs
;
3483 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_uniwill_init_verbs
;
3485 spec
->stream_name_analog
= "VT1708S Analog";
3486 spec
->stream_analog_playback
= &vt1708S_pcm_analog_playback
;
3487 spec
->stream_analog_capture
= &vt1708S_pcm_analog_capture
;
3489 spec
->stream_name_digital
= "VT1708S Digital";
3490 spec
->stream_digital_playback
= &vt1708S_pcm_digital_playback
;
3492 if (!spec
->adc_nids
&& spec
->input_mux
) {
3493 spec
->adc_nids
= vt1708S_adc_nids
;
3494 spec
->num_adc_nids
= ARRAY_SIZE(vt1708S_adc_nids
);
3495 get_mux_nids(codec
);
3496 spec
->mixers
[spec
->num_mixers
] = vt1708S_capture_mixer
;
3500 codec
->patch_ops
= via_patch_ops
;
3502 codec
->patch_ops
.init
= via_auto_init
;
3503 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3504 #ifdef CONFIG_SND_HDA_POWER_SAVE
3505 spec
->loopback
.amplist
= vt1708S_loopbacks
;
3508 /* correct names for VT1708BCE */
3509 if (get_codec_type(codec
) == VT1708BCE
) {
3510 kfree(codec
->chip_name
);
3511 codec
->chip_name
= kstrdup("VT1708BCE", GFP_KERNEL
);
3512 snprintf(codec
->bus
->card
->mixername
,
3513 sizeof(codec
->bus
->card
->mixername
),
3514 "%s %s", codec
->vendor_name
, codec
->chip_name
);
3515 spec
->stream_name_analog
= "VT1708BCE Analog";
3516 spec
->stream_name_digital
= "VT1708BCE Digital";
3521 /* Patch for VT1702 */
3523 /* capture mixer elements */
3524 static struct snd_kcontrol_new vt1702_capture_mixer
[] = {
3525 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT
),
3526 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT
),
3527 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT
),
3528 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT
),
3529 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT
),
3530 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT
),
3531 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3534 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3535 /* The multiple "Capture Source" controls confuse alsamixer
3536 * So call somewhat different..
3538 /* .name = "Capture Source", */
3539 .name
= "Input Source",
3541 .info
= via_mux_enum_info
,
3542 .get
= via_mux_enum_get
,
3543 .put
= via_mux_enum_put
,
3548 static struct hda_verb vt1702_volume_init_verbs
[] = {
3550 * Unmute ADC0-1 and set the default input to mic-in
3552 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3553 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3554 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3557 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3560 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3561 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3562 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3563 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3564 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3565 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
3567 /* Setup default input of PW4 to MW0 */
3568 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x1},
3569 /* PW6 PW7 Output enable */
3570 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3571 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3575 static struct hda_verb vt1702_uniwill_init_verbs
[] = {
3576 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE
,
3577 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
3578 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3579 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3580 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3581 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3585 static struct hda_pcm_stream vt1702_pcm_analog_playback
= {
3589 .nid
= 0x10, /* NID to query formats and rates */
3591 .open
= via_playback_pcm_open
,
3592 .prepare
= via_playback_multi_pcm_prepare
,
3593 .cleanup
= via_playback_multi_pcm_cleanup
,
3594 .close
= via_pcm_open_close
3598 static struct hda_pcm_stream vt1702_pcm_analog_capture
= {
3602 .nid
= 0x12, /* NID to query formats and rates */
3604 .open
= via_pcm_open_close
,
3605 .prepare
= via_capture_pcm_prepare
,
3606 .cleanup
= via_capture_pcm_cleanup
,
3607 .close
= via_pcm_open_close
3611 static struct hda_pcm_stream vt1702_pcm_digital_playback
= {
3615 /* NID is set in via_build_pcms */
3617 .open
= via_dig_playback_pcm_open
,
3618 .close
= via_dig_playback_pcm_close
,
3619 .prepare
= via_dig_playback_pcm_prepare
,
3620 .cleanup
= via_dig_playback_pcm_cleanup
3624 /* fill in the dac_nids table from the parsed pin configuration */
3625 static int vt1702_auto_fill_dac_nids(struct via_spec
*spec
,
3626 const struct auto_pin_cfg
*cfg
)
3628 spec
->multiout
.num_dacs
= 1;
3629 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3631 if (cfg
->line_out_pins
[0]) {
3632 /* config dac list */
3633 spec
->multiout
.dac_nids
[0] = 0x10;
3639 /* add playback controls from the parsed DAC table */
3640 static int vt1702_auto_create_line_out_ctls(struct via_spec
*spec
,
3641 const struct auto_pin_cfg
*cfg
)
3645 if (!cfg
->line_out_pins
[0])
3648 /* add control to mixer index 0 */
3649 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3650 "Master Front Playback Volume",
3651 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3654 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3655 "Master Front Playback Switch",
3656 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3661 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3662 "Front Playback Volume",
3663 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
));
3666 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3667 "Front Playback Switch",
3668 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT
));
3675 static int vt1702_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3678 struct hda_input_mux
*imux
;
3679 static const char *texts
[] = { "ON", "OFF", NULL
};
3682 spec
->multiout
.hp_nid
= 0x1D;
3683 spec
->hp_independent_mode_index
= 0;
3685 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3686 "Headphone Playback Volume",
3687 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT
));
3691 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3692 "Headphone Playback Switch",
3693 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3697 imux
= &spec
->private_imux
[1];
3699 /* for hp mode select */
3701 while (texts
[i
] != NULL
) {
3702 imux
->items
[imux
->num_items
].label
= texts
[i
];
3703 imux
->items
[imux
->num_items
].index
= i
;
3708 spec
->hp_mux
= &spec
->private_imux
[1];
3712 /* create playback/capture controls for input pins */
3713 static int vt1702_auto_create_analog_input_ctls(struct via_spec
*spec
,
3714 const struct auto_pin_cfg
*cfg
)
3716 static char *labels
[] = {
3717 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3719 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3720 int i
, err
, idx
= 0;
3722 /* for internal loopback recording select */
3723 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3724 imux
->items
[imux
->num_items
].index
= 3;
3727 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3728 if (!cfg
->input_pins
[i
])
3731 switch (cfg
->input_pins
[i
]) {
3732 case 0x14: /* Mic */
3736 case 0x15: /* Line In */
3740 case 0x18: /* Front Mic */
3744 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x1A);
3747 imux
->items
[imux
->num_items
].label
= labels
[i
];
3748 imux
->items
[imux
->num_items
].index
= idx
-1;
3754 static int vt1702_parse_auto_config(struct hda_codec
*codec
)
3756 struct via_spec
*spec
= codec
->spec
;
3759 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3762 err
= vt1702_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3765 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3766 return 0; /* can't find valid BIOS pin config */
3768 err
= vt1702_auto_create_line_out_ctls(spec
, &spec
->autocfg
);
3771 err
= vt1702_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3774 /* limit AA path volume to 0 dB */
3775 snd_hda_override_amp_caps(codec
, 0x1A, HDA_INPUT
,
3776 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
3777 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
3778 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
3779 (1 << AC_AMPCAP_MUTE_SHIFT
));
3780 err
= vt1702_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3784 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3786 fill_dig_outs(codec
);
3788 if (spec
->kctls
.list
)
3789 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3791 spec
->input_mux
= &spec
->private_imux
[0];
3794 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3799 #ifdef CONFIG_SND_HDA_POWER_SAVE
3800 static struct hda_amp_list vt1702_loopbacks
[] = {
3801 { 0x1A, HDA_INPUT
, 1 },
3802 { 0x1A, HDA_INPUT
, 2 },
3803 { 0x1A, HDA_INPUT
, 3 },
3804 { 0x1A, HDA_INPUT
, 4 },
3809 static int patch_vt1702(struct hda_codec
*codec
)
3811 struct via_spec
*spec
;
3813 unsigned int response
;
3814 unsigned char control
;
3816 /* create a codec specific record */
3817 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3823 /* automatic parse from the BIOS config */
3824 err
= vt1702_parse_auto_config(codec
);
3829 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3830 "from BIOS. Using genenic mode...\n");
3833 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_volume_init_verbs
;
3834 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_uniwill_init_verbs
;
3836 spec
->stream_name_analog
= "VT1702 Analog";
3837 spec
->stream_analog_playback
= &vt1702_pcm_analog_playback
;
3838 spec
->stream_analog_capture
= &vt1702_pcm_analog_capture
;
3840 spec
->stream_name_digital
= "VT1702 Digital";
3841 spec
->stream_digital_playback
= &vt1702_pcm_digital_playback
;
3843 if (!spec
->adc_nids
&& spec
->input_mux
) {
3844 spec
->adc_nids
= vt1702_adc_nids
;
3845 spec
->num_adc_nids
= ARRAY_SIZE(vt1702_adc_nids
);
3846 get_mux_nids(codec
);
3847 spec
->mixers
[spec
->num_mixers
] = vt1702_capture_mixer
;
3851 codec
->patch_ops
= via_patch_ops
;
3853 codec
->patch_ops
.init
= via_auto_init
;
3854 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3855 #ifdef CONFIG_SND_HDA_POWER_SAVE
3856 spec
->loopback
.amplist
= vt1702_loopbacks
;
3860 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF8C, 0);
3861 control
= (unsigned char)(response
& 0xff);
3863 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF88, control
);
3865 /* Enable GPIO 0&1 for volume&mute control */
3866 /* Enable GPIO 2 for DMIC-DATA */
3867 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF84, 0);
3868 control
= (unsigned char)((response
>> 16) & 0x3f);
3869 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF82, control
);
3877 static struct hda_codec_preset snd_hda_preset_via
[] = {
3878 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
3879 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
3880 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
3881 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
3882 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
3883 .patch
= patch_vt1709_10ch
},
3884 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
3885 .patch
= patch_vt1709_10ch
},
3886 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
3887 .patch
= patch_vt1709_10ch
},
3888 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
3889 .patch
= patch_vt1709_10ch
},
3890 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
3891 .patch
= patch_vt1709_6ch
},
3892 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
3893 .patch
= patch_vt1709_6ch
},
3894 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
3895 .patch
= patch_vt1709_6ch
},
3896 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
3897 .patch
= patch_vt1709_6ch
},
3898 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
3899 .patch
= patch_vt1708B_8ch
},
3900 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
3901 .patch
= patch_vt1708B_8ch
},
3902 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
3903 .patch
= patch_vt1708B_8ch
},
3904 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
3905 .patch
= patch_vt1708B_8ch
},
3906 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
3907 .patch
= patch_vt1708B_4ch
},
3908 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
3909 .patch
= patch_vt1708B_4ch
},
3910 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
3911 .patch
= patch_vt1708B_4ch
},
3912 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
3913 .patch
= patch_vt1708B_4ch
},
3914 { .id
= 0x11060397, .name
= "VT1708S",
3915 .patch
= patch_vt1708S
},
3916 { .id
= 0x11061397, .name
= "VT1708S",
3917 .patch
= patch_vt1708S
},
3918 { .id
= 0x11062397, .name
= "VT1708S",
3919 .patch
= patch_vt1708S
},
3920 { .id
= 0x11063397, .name
= "VT1708S",
3921 .patch
= patch_vt1708S
},
3922 { .id
= 0x11064397, .name
= "VT1708S",
3923 .patch
= patch_vt1708S
},
3924 { .id
= 0x11065397, .name
= "VT1708S",
3925 .patch
= patch_vt1708S
},
3926 { .id
= 0x11066397, .name
= "VT1708S",
3927 .patch
= patch_vt1708S
},
3928 { .id
= 0x11067397, .name
= "VT1708S",
3929 .patch
= patch_vt1708S
},
3930 { .id
= 0x11060398, .name
= "VT1702",
3931 .patch
= patch_vt1702
},
3932 { .id
= 0x11061398, .name
= "VT1702",
3933 .patch
= patch_vt1702
},
3934 { .id
= 0x11062398, .name
= "VT1702",
3935 .patch
= patch_vt1702
},
3936 { .id
= 0x11063398, .name
= "VT1702",
3937 .patch
= patch_vt1702
},
3938 { .id
= 0x11064398, .name
= "VT1702",
3939 .patch
= patch_vt1702
},
3940 { .id
= 0x11065398, .name
= "VT1702",
3941 .patch
= patch_vt1702
},
3942 { .id
= 0x11066398, .name
= "VT1702",
3943 .patch
= patch_vt1702
},
3944 { .id
= 0x11067398, .name
= "VT1702",
3945 .patch
= patch_vt1702
},
3949 MODULE_ALIAS("snd-hda-codec-id:1106*");
3951 static struct hda_codec_preset_list via_list
= {
3952 .preset
= snd_hda_preset_via
,
3953 .owner
= THIS_MODULE
,
3956 MODULE_LICENSE("GPL");
3957 MODULE_DESCRIPTION("VIA HD-audio codec");
3959 static int __init
patch_via_init(void)
3961 return snd_hda_add_codec_preset(&via_list
);
3964 static void __exit
patch_via_exit(void)
3966 snd_hda_delete_codec_preset(&via_list
);
3969 module_init(patch_via_init
)
3970 module_exit(patch_via_exit
)