2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 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 */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
45 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
48 #include <linux/init.h>
49 #include <linux/delay.h>
50 #include <linux/slab.h>
51 #include <sound/core.h>
52 #include <sound/asoundef.h>
53 #include "hda_codec.h"
54 #include "hda_local.h"
57 #define AMP_VAL_IDX_SHIFT 19
58 #define AMP_VAL_IDX_MASK (0x0f<<19)
61 #define VT1708_HP_NID 0x13
62 #define VT1708_DIGOUT_NID 0x14
63 #define VT1708_DIGIN_NID 0x16
64 #define VT1708_DIGIN_PIN 0x26
65 #define VT1708_HP_PIN_NID 0x20
66 #define VT1708_CD_PIN_NID 0x24
68 #define VT1709_HP_DAC_NID 0x28
69 #define VT1709_DIGOUT_NID 0x13
70 #define VT1709_DIGIN_NID 0x17
71 #define VT1709_DIGIN_PIN 0x25
73 #define VT1708B_HP_NID 0x25
74 #define VT1708B_DIGOUT_NID 0x12
75 #define VT1708B_DIGIN_NID 0x15
76 #define VT1708B_DIGIN_PIN 0x21
78 #define VT1708S_HP_NID 0x25
79 #define VT1708S_DIGOUT_NID 0x12
81 #define VT1702_HP_NID 0x17
82 #define VT1702_DIGOUT_NID 0x11
102 /* codec parameterization */
103 struct snd_kcontrol_new
*mixers
[6];
104 unsigned int num_mixers
;
106 struct hda_verb
*init_verbs
[5];
107 unsigned int num_iverbs
;
109 char *stream_name_analog
;
110 struct hda_pcm_stream
*stream_analog_playback
;
111 struct hda_pcm_stream
*stream_analog_capture
;
113 char *stream_name_digital
;
114 struct hda_pcm_stream
*stream_digital_playback
;
115 struct hda_pcm_stream
*stream_digital_capture
;
118 struct hda_multi_out multiout
;
119 hda_nid_t slave_dig_outs
[2];
122 unsigned int num_adc_nids
;
124 hda_nid_t mux_nids
[3];
125 hda_nid_t dig_in_nid
;
126 hda_nid_t dig_in_pin
;
129 const struct hda_input_mux
*input_mux
;
130 unsigned int cur_mux
[3];
132 /* PCM information */
133 struct hda_pcm pcm_rec
[3];
135 /* dynamic controls, init_verbs and input_mux */
136 struct auto_pin_cfg autocfg
;
137 struct snd_array kctls
;
138 struct hda_input_mux private_imux
[2];
139 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
142 const struct hda_input_mux
*hp_mux
;
143 unsigned int hp_independent_mode
;
144 unsigned int hp_independent_mode_index
;
145 unsigned int smart51_enabled
;
146 unsigned int dmic_enabled
;
147 enum VIA_HDA_CODEC codec_type
;
149 /* work to check hp jack state */
150 struct hda_codec
*codec
;
151 struct delayed_work vt1708_hp_work
;
152 int vt1708_jack_detectect
;
153 int vt1708_hp_present
;
154 #ifdef CONFIG_SND_HDA_POWER_SAVE
155 struct hda_loopback_check loopback
;
159 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
)
161 u32 vendor_id
= codec
->vendor_id
;
162 u16 ven_id
= vendor_id
>> 16;
163 u16 dev_id
= vendor_id
& 0xffff;
164 enum VIA_HDA_CODEC codec_type
;
167 if (ven_id
!= 0x1106)
168 codec_type
= UNKNOWN
;
169 else if (dev_id
>= 0x1708 && dev_id
<= 0x170b)
171 else if (dev_id
>= 0xe710 && dev_id
<= 0xe713)
172 codec_type
= VT1709_10CH
;
173 else if (dev_id
>= 0xe714 && dev_id
<= 0xe717)
174 codec_type
= VT1709_6CH
;
175 else if (dev_id
>= 0xe720 && dev_id
<= 0xe723) {
176 codec_type
= VT1708B_8CH
;
177 if (snd_hda_param_read(codec
, 0x16, AC_PAR_CONNLIST_LEN
) == 0x7)
178 codec_type
= VT1708BCE
;
179 } else if (dev_id
>= 0xe724 && dev_id
<= 0xe727)
180 codec_type
= VT1708B_4CH
;
181 else if ((dev_id
& 0xfff) == 0x397
182 && (dev_id
>> 12) < 8)
183 codec_type
= VT1708S
;
184 else if ((dev_id
& 0xfff) == 0x398
185 && (dev_id
>> 12) < 8)
187 else if ((dev_id
& 0xfff) == 0x428
188 && (dev_id
>> 12) < 8)
189 codec_type
= VT1718S
;
190 else if (dev_id
== 0x0433 || dev_id
== 0xa721)
191 codec_type
= VT1716S
;
192 else if (dev_id
== 0x0441 || dev_id
== 0x4441)
193 codec_type
= VT1718S
;
194 else if (dev_id
== 0x0438 || dev_id
== 0x4438)
195 codec_type
= VT2002P
;
196 else if (dev_id
== 0x0448)
199 codec_type
= UNKNOWN
;
203 #define VIA_HP_EVENT 0x01
204 #define VIA_GPIO_EVENT 0x02
205 #define VIA_JACK_EVENT 0x04
206 #define VIA_MONO_EVENT 0x08
207 #define VIA_SPEAKER_EVENT 0x10
208 #define VIA_BIND_HP_EVENT 0x20
213 VIA_CTL_WIDGET_ANALOG_MUTE
,
214 VIA_CTL_WIDGET_BIND_PIN_MUTE
,
224 static void analog_low_current_mode(struct hda_codec
*codec
, int stream_idle
);
225 static void set_jack_power_state(struct hda_codec
*codec
);
226 static int is_aa_path_mute(struct hda_codec
*codec
);
228 static void vt1708_start_hp_work(struct via_spec
*spec
)
230 if (spec
->codec_type
!= VT1708
|| spec
->autocfg
.hp_pins
[0] == 0)
232 snd_hda_codec_write(spec
->codec
, 0x1, 0, 0xf81,
233 !spec
->vt1708_jack_detectect
);
234 if (!delayed_work_pending(&spec
->vt1708_hp_work
))
235 schedule_delayed_work(&spec
->vt1708_hp_work
,
236 msecs_to_jiffies(100));
239 static void vt1708_stop_hp_work(struct via_spec
*spec
)
241 if (spec
->codec_type
!= VT1708
|| spec
->autocfg
.hp_pins
[0] == 0)
243 if (snd_hda_get_bool_hint(spec
->codec
, "analog_loopback_hp_detect") == 1
244 && !is_aa_path_mute(spec
->codec
))
246 snd_hda_codec_write(spec
->codec
, 0x1, 0, 0xf81,
247 !spec
->vt1708_jack_detectect
);
248 cancel_delayed_work(&spec
->vt1708_hp_work
);
249 flush_scheduled_work();
253 static int analog_input_switch_put(struct snd_kcontrol
*kcontrol
,
254 struct snd_ctl_elem_value
*ucontrol
)
256 int change
= snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
257 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
259 set_jack_power_state(codec
);
260 analog_low_current_mode(snd_kcontrol_chip(kcontrol
), -1);
261 if (snd_hda_get_bool_hint(codec
, "analog_loopback_hp_detect") == 1) {
262 if (is_aa_path_mute(codec
))
263 vt1708_start_hp_work(codec
->spec
);
265 vt1708_stop_hp_work(codec
->spec
);
270 /* modify .put = snd_hda_mixer_amp_switch_put */
271 #define ANALOG_INPUT_MUTE \
272 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
275 .info = snd_hda_mixer_amp_switch_info, \
276 .get = snd_hda_mixer_amp_switch_get, \
277 .put = analog_input_switch_put, \
278 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
280 static void via_hp_bind_automute(struct hda_codec
*codec
);
282 static int bind_pin_switch_put(struct snd_kcontrol
*kcontrol
,
283 struct snd_ctl_elem_value
*ucontrol
)
285 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
286 struct via_spec
*spec
= codec
->spec
;
290 long *valp
= ucontrol
->value
.integer
.value
;
292 if (strstr(kcontrol
->id
.name
, "Switch") == NULL
) {
293 snd_printd("Invalid control!\n");
296 change
= snd_hda_mixer_amp_switch_put(kcontrol
,
299 lmute
= *valp
? 0 : HDA_AMP_MUTE
;
301 rmute
= *valp
? 0 : HDA_AMP_MUTE
;
304 if (!spec
->hp_independent_mode
) {
305 for (i
= 0; i
< spec
->autocfg
.hp_outs
; i
++) {
306 snd_hda_codec_amp_update(
307 codec
, spec
->autocfg
.hp_pins
[i
],
308 0, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
310 snd_hda_codec_amp_update(
311 codec
, spec
->autocfg
.hp_pins
[i
],
312 1, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
317 if (!lmute
&& !rmute
) {
319 for (i
= 0; i
< spec
->autocfg
.line_outs
; i
++)
320 snd_hda_codec_amp_stereo(
321 codec
, spec
->autocfg
.line_out_pins
[i
],
322 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
324 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++)
325 snd_hda_codec_amp_stereo(
326 codec
, spec
->autocfg
.speaker_pins
[i
],
327 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
329 via_hp_bind_automute(codec
);
333 /* Mute all left channels */
334 for (i
= 1; i
< spec
->autocfg
.line_outs
; i
++)
335 snd_hda_codec_amp_update(
337 spec
->autocfg
.line_out_pins
[i
],
338 0, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
340 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++)
341 snd_hda_codec_amp_update(
343 spec
->autocfg
.speaker_pins
[i
],
344 0, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
348 /* mute all right channels */
349 for (i
= 1; i
< spec
->autocfg
.line_outs
; i
++)
350 snd_hda_codec_amp_update(
352 spec
->autocfg
.line_out_pins
[i
],
353 1, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
355 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++)
356 snd_hda_codec_amp_update(
358 spec
->autocfg
.speaker_pins
[i
],
359 1, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
366 #define BIND_PIN_MUTE \
367 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
370 .info = snd_hda_mixer_amp_switch_info, \
371 .get = snd_hda_mixer_amp_switch_get, \
372 .put = bind_pin_switch_put, \
373 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
375 static struct snd_kcontrol_new via_control_templates
[] = {
376 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
377 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
382 static hda_nid_t vt1708_adc_nids
[2] = {
387 static hda_nid_t vt1709_adc_nids
[3] = {
392 static hda_nid_t vt1708B_adc_nids
[2] = {
397 static hda_nid_t vt1708S_adc_nids
[2] = {
402 static hda_nid_t vt1702_adc_nids
[3] = {
407 static hda_nid_t vt1718S_adc_nids
[2] = {
412 static hda_nid_t vt1716S_adc_nids
[2] = {
417 static hda_nid_t vt2002P_adc_nids
[2] = {
422 static hda_nid_t vt1812_adc_nids
[2] = {
428 /* add dynamic controls */
429 static int via_add_control(struct via_spec
*spec
, int type
, const char *name
,
432 struct snd_kcontrol_new
*knew
;
434 snd_array_init(&spec
->kctls
, sizeof(*knew
), 32);
435 knew
= snd_array_new(&spec
->kctls
);
438 *knew
= via_control_templates
[type
];
439 knew
->name
= kstrdup(name
, GFP_KERNEL
);
442 knew
->private_value
= val
;
446 static void via_free_kctls(struct hda_codec
*codec
)
448 struct via_spec
*spec
= codec
->spec
;
450 if (spec
->kctls
.list
) {
451 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
453 for (i
= 0; i
< spec
->kctls
.used
; i
++)
456 snd_array_free(&spec
->kctls
);
459 /* create input playback/capture controls for the given pin */
460 static int via_new_analog_input(struct via_spec
*spec
, const char *ctlname
,
461 int idx
, int mix_nid
)
466 sprintf(name
, "%s Playback Volume", ctlname
);
467 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
468 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
471 sprintf(name
, "%s Playback Switch", ctlname
);
472 err
= via_add_control(spec
, VIA_CTL_WIDGET_ANALOG_MUTE
, name
,
473 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
479 static void via_auto_set_output_and_unmute(struct hda_codec
*codec
,
480 hda_nid_t nid
, int pin_type
,
484 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
486 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
488 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
489 snd_hda_codec_write(codec
, nid
, 0,
490 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
494 static void via_auto_init_multi_out(struct hda_codec
*codec
)
496 struct via_spec
*spec
= codec
->spec
;
499 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
500 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
502 via_auto_set_output_and_unmute(codec
, nid
, PIN_OUT
, i
);
506 static void via_auto_init_hp_out(struct hda_codec
*codec
)
508 struct via_spec
*spec
= codec
->spec
;
512 for (i
= 0; i
< spec
->autocfg
.hp_outs
; i
++) {
513 pin
= spec
->autocfg
.hp_pins
[i
];
514 if (pin
) /* connect to front */
515 via_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, 0);
519 static void via_auto_init_analog_input(struct hda_codec
*codec
)
521 struct via_spec
*spec
= codec
->spec
;
524 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
525 hda_nid_t nid
= spec
->autocfg
.input_pins
[i
];
527 snd_hda_codec_write(codec
, nid
, 0,
528 AC_VERB_SET_PIN_WIDGET_CONTROL
,
529 (i
<= AUTO_PIN_FRONT_MIC
?
530 PIN_VREF50
: PIN_IN
));
535 static int is_smart51_pins(struct via_spec
*spec
, hda_nid_t pin
);
537 static void set_pin_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
538 unsigned int *affected_parm
)
541 unsigned def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
542 unsigned no_presence
= (def_conf
& AC_DEFCFG_MISC
)
543 >> AC_DEFCFG_MISC_SHIFT
544 & AC_DEFCFG_MISC_NO_PRESENCE
; /* do not support pin sense */
545 unsigned present
= snd_hda_codec_read(codec
, nid
, 0,
546 AC_VERB_GET_PIN_SENSE
, 0) >> 31;
547 struct via_spec
*spec
= codec
->spec
;
548 if ((spec
->smart51_enabled
&& is_smart51_pins(spec
, nid
))
549 || ((no_presence
|| present
)
550 && get_defcfg_connect(def_conf
) != AC_JACK_PORT_NONE
)) {
551 *affected_parm
= AC_PWRST_D0
; /* if it's connected */
556 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
559 static void set_jack_power_state(struct hda_codec
*codec
)
561 struct via_spec
*spec
= codec
->spec
;
565 if (spec
->codec_type
== VT1702
) {
566 imux_is_smixer
= snd_hda_codec_read(
567 codec
, 0x13, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
569 /* PW 1/2/5 (14h/15h/18h) */
571 set_pin_power_state(codec
, 0x14, &parm
);
572 set_pin_power_state(codec
, 0x15, &parm
);
573 set_pin_power_state(codec
, 0x18, &parm
);
575 parm
= AC_PWRST_D0
; /* SW0 = stereo mixer (idx 3) */
576 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
577 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
579 snd_hda_codec_write(codec
, 0x12, 0, AC_VERB_SET_POWER_STATE
,
581 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
,
583 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_POWER_STATE
,
587 /* PW 3/4 (16h/17h) */
589 set_pin_power_state(codec
, 0x16, &parm
);
590 set_pin_power_state(codec
, 0x17, &parm
);
591 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
592 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_POWER_STATE
,
593 imux_is_smixer
? AC_PWRST_D0
: parm
);
594 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
596 snd_hda_codec_write(codec
, 0x1d, 0, AC_VERB_SET_POWER_STATE
,
598 } else if (spec
->codec_type
== VT1708B_8CH
599 || spec
->codec_type
== VT1708B_4CH
600 || spec
->codec_type
== VT1708S
) {
601 /* SW0 (17h) = stereo mixer */
602 int is_8ch
= spec
->codec_type
!= VT1708B_4CH
;
603 imux_is_smixer
= snd_hda_codec_read(
604 codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00)
605 == ((spec
->codec_type
== VT1708S
) ? 5 : 0);
607 /* PW 1/2/5 (1ah/1bh/1eh) */
609 set_pin_power_state(codec
, 0x1a, &parm
);
610 set_pin_power_state(codec
, 0x1b, &parm
);
611 set_pin_power_state(codec
, 0x1e, &parm
);
614 /* SW0 (17h), AIW 0/1 (13h/14h) */
615 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_POWER_STATE
,
617 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
619 snd_hda_codec_write(codec
, 0x14, 0, AC_VERB_SET_POWER_STATE
,
623 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
625 set_pin_power_state(codec
, 0x19, &parm
);
626 snd_hda_codec_write(codec
, 0x18, 0, AC_VERB_SET_POWER_STATE
,
628 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
,
631 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
634 set_pin_power_state(codec
, 0x22, &parm
);
635 snd_hda_codec_write(codec
, 0x26, 0,
636 AC_VERB_SET_POWER_STATE
, parm
);
637 snd_hda_codec_write(codec
, 0x24, 0,
638 AC_VERB_SET_POWER_STATE
, parm
);
641 /* PW 3/4/7 (1ch/1dh/23h) */
643 /* force to D0 for internal Speaker */
644 set_pin_power_state(codec
, 0x1c, &parm
);
645 set_pin_power_state(codec
, 0x1d, &parm
);
647 set_pin_power_state(codec
, 0x23, &parm
);
648 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
649 snd_hda_codec_write(codec
, 0x16, 0, AC_VERB_SET_POWER_STATE
,
650 imux_is_smixer
? AC_PWRST_D0
: parm
);
651 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
654 snd_hda_codec_write(codec
, 0x25, 0,
655 AC_VERB_SET_POWER_STATE
, parm
);
656 snd_hda_codec_write(codec
, 0x27, 0,
657 AC_VERB_SET_POWER_STATE
, parm
);
659 } else if (spec
->codec_type
== VT1718S
) {
660 /* MUX6 (1eh) = stereo mixer */
661 imux_is_smixer
= snd_hda_codec_read(
662 codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
664 /* PW 5/6/7 (29h/2ah/2bh) */
666 set_pin_power_state(codec
, 0x29, &parm
);
667 set_pin_power_state(codec
, 0x2a, &parm
);
668 set_pin_power_state(codec
, 0x2b, &parm
);
671 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
672 snd_hda_codec_write(codec
, 0x1e, 0, AC_VERB_SET_POWER_STATE
,
674 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
,
676 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
678 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
,
682 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
684 set_pin_power_state(codec
, 0x27, &parm
);
685 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_POWER_STATE
,
687 snd_hda_codec_write(codec
, 0xb, 0, AC_VERB_SET_POWER_STATE
,
690 /* PW2 (26h), AOW2 (ah) */
692 set_pin_power_state(codec
, 0x26, &parm
);
693 snd_hda_codec_write(codec
, 0xa, 0, AC_VERB_SET_POWER_STATE
,
696 /* PW0/1 (24h/25h) */
698 set_pin_power_state(codec
, 0x24, &parm
);
699 set_pin_power_state(codec
, 0x25, &parm
);
700 if (!spec
->hp_independent_mode
) /* check for redirected HP */
701 set_pin_power_state(codec
, 0x28, &parm
);
702 snd_hda_codec_write(codec
, 0x8, 0, AC_VERB_SET_POWER_STATE
,
704 snd_hda_codec_write(codec
, 0x9, 0, AC_VERB_SET_POWER_STATE
,
706 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
707 snd_hda_codec_write(codec
, 0x21, 0, AC_VERB_SET_POWER_STATE
,
708 imux_is_smixer
? AC_PWRST_D0
: parm
);
709 if (spec
->hp_independent_mode
) {
710 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
712 set_pin_power_state(codec
, 0x28, &parm
);
713 snd_hda_codec_write(codec
, 0x1b, 0,
714 AC_VERB_SET_POWER_STATE
, parm
);
715 snd_hda_codec_write(codec
, 0x34, 0,
716 AC_VERB_SET_POWER_STATE
, parm
);
717 snd_hda_codec_write(codec
, 0xc, 0,
718 AC_VERB_SET_POWER_STATE
, parm
);
720 } else if (spec
->codec_type
== VT1716S
) {
721 unsigned int mono_out
, present
;
722 /* SW0 (17h) = stereo mixer */
723 imux_is_smixer
= snd_hda_codec_read(
724 codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
726 /* PW 1/2/5 (1ah/1bh/1eh) */
728 set_pin_power_state(codec
, 0x1a, &parm
);
729 set_pin_power_state(codec
, 0x1b, &parm
);
730 set_pin_power_state(codec
, 0x1e, &parm
);
733 /* SW0 (17h), AIW0(13h) */
734 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_POWER_STATE
,
736 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
740 set_pin_power_state(codec
, 0x1e, &parm
);
742 if (spec
->dmic_enabled
)
743 set_pin_power_state(codec
, 0x22, &parm
);
747 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
749 /* SW2(26h), AIW1(14h) */
750 snd_hda_codec_write(codec
, 0x26, 0, AC_VERB_SET_POWER_STATE
,
752 snd_hda_codec_write(codec
, 0x14, 0, AC_VERB_SET_POWER_STATE
,
756 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
758 set_pin_power_state(codec
, 0x19, &parm
);
759 /* Smart 5.1 PW2(1bh) */
760 if (spec
->smart51_enabled
)
761 set_pin_power_state(codec
, 0x1b, &parm
);
762 snd_hda_codec_write(codec
, 0x18, 0, AC_VERB_SET_POWER_STATE
,
764 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
,
767 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
769 set_pin_power_state(codec
, 0x23, &parm
);
770 /* Smart 5.1 PW1(1ah) */
771 if (spec
->smart51_enabled
)
772 set_pin_power_state(codec
, 0x1a, &parm
);
773 snd_hda_codec_write(codec
, 0x27, 0, AC_VERB_SET_POWER_STATE
,
776 /* Smart 5.1 PW5(1eh) */
777 if (spec
->smart51_enabled
)
778 set_pin_power_state(codec
, 0x1e, &parm
);
779 snd_hda_codec_write(codec
, 0x25, 0, AC_VERB_SET_POWER_STATE
,
783 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
784 present
= snd_hda_codec_read(
785 codec
, 0x1c, 0, AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
789 present
= snd_hda_codec_read(
790 codec
, 0x1d, 0, AC_VERB_GET_PIN_SENSE
, 0)
792 if (!spec
->hp_independent_mode
&& present
)
797 parm
= mono_out
? AC_PWRST_D0
: AC_PWRST_D3
;
798 snd_hda_codec_write(codec
, 0x28, 0, AC_VERB_SET_POWER_STATE
,
800 snd_hda_codec_write(codec
, 0x29, 0, AC_VERB_SET_POWER_STATE
,
802 snd_hda_codec_write(codec
, 0x2a, 0, AC_VERB_SET_POWER_STATE
,
805 /* PW 3/4 (1ch/1dh) */
807 set_pin_power_state(codec
, 0x1c, &parm
);
808 set_pin_power_state(codec
, 0x1d, &parm
);
809 /* HP Independent Mode, power on AOW3 */
810 if (spec
->hp_independent_mode
)
811 snd_hda_codec_write(codec
, 0x25, 0,
812 AC_VERB_SET_POWER_STATE
, parm
);
814 /* force to D0 for internal Speaker */
815 /* MW0 (16h), AOW0 (10h) */
816 snd_hda_codec_write(codec
, 0x16, 0, AC_VERB_SET_POWER_STATE
,
817 imux_is_smixer
? AC_PWRST_D0
: parm
);
818 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
819 mono_out
? AC_PWRST_D0
: parm
);
820 } else if (spec
->codec_type
== VT2002P
) {
821 unsigned int present
;
822 /* MUX9 (1eh) = stereo mixer */
823 imux_is_smixer
= snd_hda_codec_read(
824 codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
826 /* PW 5/6/7 (29h/2ah/2bh) */
828 set_pin_power_state(codec
, 0x29, &parm
);
829 set_pin_power_state(codec
, 0x2a, &parm
);
830 set_pin_power_state(codec
, 0x2b, &parm
);
833 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
834 snd_hda_codec_write(codec
, 0x1e, 0,
835 AC_VERB_SET_POWER_STATE
, parm
);
836 snd_hda_codec_write(codec
, 0x1f, 0,
837 AC_VERB_SET_POWER_STATE
, parm
);
838 snd_hda_codec_write(codec
, 0x10, 0,
839 AC_VERB_SET_POWER_STATE
, parm
);
840 snd_hda_codec_write(codec
, 0x11, 0,
841 AC_VERB_SET_POWER_STATE
, parm
);
845 snd_hda_codec_write(codec
, 0x8, 0,
846 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
848 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
850 set_pin_power_state(codec
, 0x26, &parm
);
851 snd_hda_codec_write(codec
, 0x1c, 0,
852 AC_VERB_SET_POWER_STATE
, parm
);
853 snd_hda_codec_write(codec
, 0x37,
854 0, AC_VERB_SET_POWER_STATE
, parm
);
856 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
858 set_pin_power_state(codec
, 0x25, &parm
);
859 snd_hda_codec_write(codec
, 0x19, 0,
860 AC_VERB_SET_POWER_STATE
, parm
);
861 snd_hda_codec_write(codec
, 0x35, 0,
862 AC_VERB_SET_POWER_STATE
, parm
);
863 if (spec
->hp_independent_mode
) {
864 snd_hda_codec_write(codec
, 0x9, 0,
865 AC_VERB_SET_POWER_STATE
, parm
);
869 /* PW0 (24h), MW0(18h), MUX0(34h) */
870 present
= snd_hda_codec_read(
871 codec
, 0x25, 0, AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
873 set_pin_power_state(codec
, 0x24, &parm
);
877 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
880 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
884 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
887 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
891 /* PW15 (31h), MW8(17h), MUX8(3bh) */
892 present
= snd_hda_codec_read(
893 codec
, 0x26, 0, AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
895 set_pin_power_state(codec
, 0x31, &parm
);
899 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
902 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
906 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
909 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
913 if (imux_is_smixer
|| !is_aa_path_mute(codec
))
916 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
920 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
921 } else if (spec
->codec_type
== VT1812
) {
922 unsigned int present
;
923 /* MUX10 (1eh) = stereo mixer */
924 imux_is_smixer
= snd_hda_codec_read(
925 codec
, 0x1e, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 5;
927 /* PW 5/6/7 (29h/2ah/2bh) */
929 set_pin_power_state(codec
, 0x29, &parm
);
930 set_pin_power_state(codec
, 0x2a, &parm
);
931 set_pin_power_state(codec
, 0x2b, &parm
);
934 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
935 snd_hda_codec_write(codec
, 0x1e, 0,
936 AC_VERB_SET_POWER_STATE
, parm
);
937 snd_hda_codec_write(codec
, 0x1f, 0,
938 AC_VERB_SET_POWER_STATE
, parm
);
939 snd_hda_codec_write(codec
, 0x10, 0,
940 AC_VERB_SET_POWER_STATE
, parm
);
941 snd_hda_codec_write(codec
, 0x11, 0,
942 AC_VERB_SET_POWER_STATE
, parm
);
946 snd_hda_codec_write(codec
, 0x8, 0,
947 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
949 /* PW4 (28h), MW4 (18h), MUX4(38h) */
951 set_pin_power_state(codec
, 0x28, &parm
);
952 snd_hda_codec_write(codec
, 0x18, 0,
953 AC_VERB_SET_POWER_STATE
, parm
);
954 snd_hda_codec_write(codec
, 0x38, 0,
955 AC_VERB_SET_POWER_STATE
, parm
);
957 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
959 set_pin_power_state(codec
, 0x25, &parm
);
960 snd_hda_codec_write(codec
, 0x15, 0,
961 AC_VERB_SET_POWER_STATE
, parm
);
962 snd_hda_codec_write(codec
, 0x35, 0,
963 AC_VERB_SET_POWER_STATE
, parm
);
964 if (spec
->hp_independent_mode
) {
965 snd_hda_codec_write(codec
, 0x9, 0,
966 AC_VERB_SET_POWER_STATE
, parm
);
969 /* Internal Speaker */
970 /* PW0 (24h), MW0(14h), MUX0(34h) */
971 present
= snd_hda_codec_read(
972 codec
, 0x25, 0, AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
974 set_pin_power_state(codec
, 0x24, &parm
);
976 snd_hda_codec_write(codec
, 0x14, 0,
977 AC_VERB_SET_POWER_STATE
,
979 snd_hda_codec_write(codec
, 0x34, 0,
980 AC_VERB_SET_POWER_STATE
,
983 snd_hda_codec_write(codec
, 0x14, 0,
984 AC_VERB_SET_POWER_STATE
,
986 snd_hda_codec_write(codec
, 0x34, 0,
987 AC_VERB_SET_POWER_STATE
,
991 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
992 present
= snd_hda_codec_read(
993 codec
, 0x28, 0, AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
995 set_pin_power_state(codec
, 0x31, &parm
);
997 snd_hda_codec_write(codec
, 0x1c, 0,
998 AC_VERB_SET_POWER_STATE
,
1000 snd_hda_codec_write(codec
, 0x3c, 0,
1001 AC_VERB_SET_POWER_STATE
,
1003 snd_hda_codec_write(codec
, 0x3e, 0,
1004 AC_VERB_SET_POWER_STATE
,
1007 snd_hda_codec_write(codec
, 0x1c, 0,
1008 AC_VERB_SET_POWER_STATE
,
1010 snd_hda_codec_write(codec
, 0x3c, 0,
1011 AC_VERB_SET_POWER_STATE
,
1013 snd_hda_codec_write(codec
, 0x3e, 0,
1014 AC_VERB_SET_POWER_STATE
,
1018 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1020 set_pin_power_state(codec
, 0x33, &parm
);
1021 snd_hda_codec_write(codec
, 0x1d, 0,
1022 AC_VERB_SET_POWER_STATE
, parm
);
1023 snd_hda_codec_write(codec
, 0x3d, 0,
1024 AC_VERB_SET_POWER_STATE
, parm
);
1027 if (imux_is_smixer
|| !is_aa_path_mute(codec
))
1028 snd_hda_codec_write(
1030 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
1032 snd_hda_codec_write(
1034 AC_VERB_SET_POWER_STATE
, AC_PWRST_D3
);
1039 * input MUX handling
1041 static int via_mux_enum_info(struct snd_kcontrol
*kcontrol
,
1042 struct snd_ctl_elem_info
*uinfo
)
1044 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1045 struct via_spec
*spec
= codec
->spec
;
1046 return snd_hda_input_mux_info(spec
->input_mux
, uinfo
);
1049 static int via_mux_enum_get(struct snd_kcontrol
*kcontrol
,
1050 struct snd_ctl_elem_value
*ucontrol
)
1052 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1053 struct via_spec
*spec
= codec
->spec
;
1054 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1056 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
1060 static int via_mux_enum_put(struct snd_kcontrol
*kcontrol
,
1061 struct snd_ctl_elem_value
*ucontrol
)
1063 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1064 struct via_spec
*spec
= codec
->spec
;
1065 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
1067 if (!spec
->mux_nids
[adc_idx
])
1069 /* switch to D0 beofre change index */
1070 if (snd_hda_codec_read(codec
, spec
->mux_nids
[adc_idx
], 0,
1071 AC_VERB_GET_POWER_STATE
, 0x00) != AC_PWRST_D0
)
1072 snd_hda_codec_write(codec
, spec
->mux_nids
[adc_idx
], 0,
1073 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
1074 /* update jack power state */
1075 set_jack_power_state(codec
);
1077 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
1078 spec
->mux_nids
[adc_idx
],
1079 &spec
->cur_mux
[adc_idx
]);
1082 static int via_independent_hp_info(struct snd_kcontrol
*kcontrol
,
1083 struct snd_ctl_elem_info
*uinfo
)
1085 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1086 struct via_spec
*spec
= codec
->spec
;
1087 return snd_hda_input_mux_info(spec
->hp_mux
, uinfo
);
1090 static int via_independent_hp_get(struct snd_kcontrol
*kcontrol
,
1091 struct snd_ctl_elem_value
*ucontrol
)
1093 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1094 struct via_spec
*spec
= codec
->spec
;
1096 unsigned int pinsel
;
1098 switch (spec
->codec_type
) {
1109 nid
= spec
->autocfg
.hp_pins
[0];
1112 /* use !! to translate conn sel 2 for VT1718S */
1113 pinsel
= !!snd_hda_codec_read(codec
, nid
, 0,
1114 AC_VERB_GET_CONNECT_SEL
,
1116 ucontrol
->value
.enumerated
.item
[0] = pinsel
;
1121 static void activate_ctl(struct hda_codec
*codec
, const char *name
, int active
)
1123 struct snd_kcontrol
*ctl
= snd_hda_find_mixer_ctl(codec
, name
);
1125 ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1126 ctl
->vd
[0].access
|= active
1127 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1128 snd_ctl_notify(codec
->bus
->card
,
1129 SNDRV_CTL_EVENT_MASK_VALUE
, &ctl
->id
);
1133 static int update_side_mute_status(struct hda_codec
*codec
)
1135 /* mute side channel */
1136 struct via_spec
*spec
= codec
->spec
;
1137 unsigned int parm
= spec
->hp_independent_mode
1138 ? AMP_OUT_MUTE
: AMP_OUT_UNMUTE
;
1141 switch (spec
->codec_type
) {
1158 snd_hda_codec_write(codec
, sw3
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
1163 static int via_independent_hp_put(struct snd_kcontrol
*kcontrol
,
1164 struct snd_ctl_elem_value
*ucontrol
)
1166 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1167 struct via_spec
*spec
= codec
->spec
;
1168 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
1169 unsigned int pinsel
= ucontrol
->value
.enumerated
.item
[0];
1170 /* Get Independent Mode index of headphone pin widget */
1171 spec
->hp_independent_mode
= spec
->hp_independent_mode_index
== pinsel
1174 switch (spec
->codec_type
) {
1177 pinsel
= pinsel
? 2 : 0; /* indep HP use AOW4 (index 2) */
1178 spec
->multiout
.num_dacs
= 4;
1187 nid
= spec
->autocfg
.hp_pins
[0];
1190 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, pinsel
);
1192 if (spec
->multiout
.hp_nid
&& spec
->multiout
.hp_nid
1193 != spec
->multiout
.dac_nids
[HDA_FRONT
])
1194 snd_hda_codec_setup_stream(codec
, spec
->multiout
.hp_nid
,
1197 update_side_mute_status(codec
);
1198 /* update HP volume/swtich active state */
1199 if (spec
->codec_type
== VT1708S
1200 || spec
->codec_type
== VT1702
1201 || spec
->codec_type
== VT1718S
1202 || spec
->codec_type
== VT1716S
1203 || spec
->codec_type
== VT2002P
1204 || spec
->codec_type
== VT1812
) {
1205 activate_ctl(codec
, "Headphone Playback Volume",
1206 spec
->hp_independent_mode
);
1207 activate_ctl(codec
, "Headphone Playback Switch",
1208 spec
->hp_independent_mode
);
1213 static struct snd_kcontrol_new via_hp_mixer
[] = {
1215 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1216 .name
= "Independent HP",
1218 .info
= via_independent_hp_info
,
1219 .get
= via_independent_hp_get
,
1220 .put
= via_independent_hp_put
,
1225 static void notify_aa_path_ctls(struct hda_codec
*codec
)
1228 struct snd_ctl_elem_id id
;
1229 const char *labels
[] = {"Mic", "Front Mic", "Line"};
1231 memset(&id
, 0, sizeof(id
));
1232 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
1233 for (i
= 0; i
< ARRAY_SIZE(labels
); i
++) {
1234 sprintf(id
.name
, "%s Playback Volume", labels
[i
]);
1235 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
1240 static void mute_aa_path(struct hda_codec
*codec
, int mute
)
1242 struct via_spec
*spec
= codec
->spec
;
1243 hda_nid_t nid_mixer
;
1247 /* get nid of MW0 and start & end index */
1248 switch (spec
->codec_type
) {
1271 /* check AA path's mute status */
1272 for (i
= start_idx
; i
<= end_idx
; i
++) {
1273 int val
= mute
? HDA_AMP_MUTE
: HDA_AMP_UNMUTE
;
1274 snd_hda_codec_amp_stereo(codec
, nid_mixer
, HDA_INPUT
, i
,
1278 static int is_smart51_pins(struct via_spec
*spec
, hda_nid_t pin
)
1282 for (index
= AUTO_PIN_MIC
; index
< AUTO_PIN_FRONT_LINE
; index
++) {
1283 if (pin
== spec
->autocfg
.input_pins
[index
]) {
1291 static int via_smart51_info(struct snd_kcontrol
*kcontrol
,
1292 struct snd_ctl_elem_info
*uinfo
)
1294 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1296 uinfo
->value
.integer
.min
= 0;
1297 uinfo
->value
.integer
.max
= 1;
1301 static int via_smart51_get(struct snd_kcontrol
*kcontrol
,
1302 struct snd_ctl_elem_value
*ucontrol
)
1304 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1305 struct via_spec
*spec
= codec
->spec
;
1306 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
1310 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
1311 hda_nid_t nid
= spec
->autocfg
.input_pins
[index
[i
]];
1314 snd_hda_codec_read(codec
, nid
, 0,
1315 AC_VERB_GET_PIN_WIDGET_CONTROL
,
1317 if (i
== AUTO_PIN_FRONT_MIC
1318 && spec
->hp_independent_mode
1319 && spec
->codec_type
!= VT1718S
)
1320 continue; /* ignore FMic for independent HP */
1321 if (ctl
& AC_PINCTL_IN_EN
1322 && !(ctl
& AC_PINCTL_OUT_EN
))
1326 *ucontrol
->value
.integer
.value
= on
;
1330 static int via_smart51_put(struct snd_kcontrol
*kcontrol
,
1331 struct snd_ctl_elem_value
*ucontrol
)
1333 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1334 struct via_spec
*spec
= codec
->spec
;
1335 int out_in
= *ucontrol
->value
.integer
.value
1336 ? AC_PINCTL_OUT_EN
: AC_PINCTL_IN_EN
;
1337 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
1340 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
1341 hda_nid_t nid
= spec
->autocfg
.input_pins
[index
[i
]];
1342 if (i
== AUTO_PIN_FRONT_MIC
1343 && spec
->hp_independent_mode
1344 && spec
->codec_type
!= VT1718S
)
1345 continue; /* don't retask FMic for independent HP */
1347 unsigned int parm
= snd_hda_codec_read(
1349 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
1350 parm
&= ~(AC_PINCTL_IN_EN
| AC_PINCTL_OUT_EN
);
1352 snd_hda_codec_write(codec
, nid
, 0,
1353 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1355 if (out_in
== AC_PINCTL_OUT_EN
) {
1356 mute_aa_path(codec
, 1);
1357 notify_aa_path_ctls(codec
);
1359 if (spec
->codec_type
== VT1718S
)
1360 snd_hda_codec_amp_stereo(
1361 codec
, nid
, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
1364 if (i
== AUTO_PIN_FRONT_MIC
) {
1365 if (spec
->codec_type
== VT1708S
1366 || spec
->codec_type
== VT1716S
) {
1367 /* input = index 1 (AOW3) */
1368 snd_hda_codec_write(
1370 AC_VERB_SET_CONNECT_SEL
, 1);
1371 snd_hda_codec_amp_stereo(
1372 codec
, nid
, HDA_OUTPUT
,
1373 0, HDA_AMP_MUTE
, HDA_AMP_UNMUTE
);
1377 spec
->smart51_enabled
= *ucontrol
->value
.integer
.value
;
1378 set_jack_power_state(codec
);
1382 static struct snd_kcontrol_new via_smart51_mixer
[] = {
1384 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1385 .name
= "Smart 5.1",
1387 .info
= via_smart51_info
,
1388 .get
= via_smart51_get
,
1389 .put
= via_smart51_put
,
1394 /* capture mixer elements */
1395 static struct snd_kcontrol_new vt1708_capture_mixer
[] = {
1396 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT
),
1397 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT
),
1398 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT
),
1399 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT
),
1401 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1402 /* The multiple "Capture Source" controls confuse alsamixer
1403 * So call somewhat different..
1405 /* .name = "Capture Source", */
1406 .name
= "Input Source",
1408 .info
= via_mux_enum_info
,
1409 .get
= via_mux_enum_get
,
1410 .put
= via_mux_enum_put
,
1415 /* check AA path's mute statue */
1416 static int is_aa_path_mute(struct hda_codec
*codec
)
1419 hda_nid_t nid_mixer
;
1423 struct via_spec
*spec
= codec
->spec
;
1424 /* get nid of MW0 and start & end index */
1425 switch (spec
->codec_type
) {
1453 /* check AA path's mute status */
1454 for (i
= start_idx
; i
<= end_idx
; i
++) {
1455 unsigned int con_list
= snd_hda_codec_read(
1456 codec
, nid_mixer
, 0, AC_VERB_GET_CONNECT_LIST
, i
/4*4);
1457 int shift
= 8 * (i
% 4);
1458 hda_nid_t nid_pin
= (con_list
& (0xff << shift
)) >> shift
;
1459 unsigned int defconf
= snd_hda_codec_get_pincfg(codec
, nid_pin
);
1460 if (get_defcfg_connect(defconf
) == AC_JACK_PORT_COMPLEX
) {
1461 /* check mute status while the pin is connected */
1462 int mute_l
= snd_hda_codec_amp_read(codec
, nid_mixer
, 0,
1464 int mute_r
= snd_hda_codec_amp_read(codec
, nid_mixer
, 1,
1466 if (!mute_l
|| !mute_r
) {
1475 /* enter/exit analog low-current mode */
1476 static void analog_low_current_mode(struct hda_codec
*codec
, int stream_idle
)
1478 struct via_spec
*spec
= codec
->spec
;
1479 static int saved_stream_idle
= 1; /* saved stream idle status */
1480 int enable
= is_aa_path_mute(codec
);
1481 unsigned int verb
= 0;
1482 unsigned int parm
= 0;
1484 if (stream_idle
== -1) /* stream status did not change */
1485 enable
= enable
&& saved_stream_idle
;
1487 enable
= enable
&& stream_idle
;
1488 saved_stream_idle
= stream_idle
;
1491 /* decide low current mode's verb & parameter */
1492 switch (spec
->codec_type
) {
1496 parm
= enable
? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1502 parm
= enable
? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1506 parm
= enable
? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1511 parm
= enable
? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1514 return; /* other codecs are not supported */
1517 snd_hda_codec_write(codec
, codec
->afg
, 0, verb
, parm
);
1521 * generic initialization of ADC, input mixers and output mixers
1523 static struct hda_verb vt1708_volume_init_verbs
[] = {
1525 * Unmute ADC0-1 and set the default input to mic-in
1527 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1528 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1531 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1534 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1535 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1536 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1537 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1538 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1539 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1542 * Set up output mixers (0x19 - 0x1b)
1544 /* set vol=0 to output mixers */
1545 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1546 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1547 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1549 /* Setup default input MW0 to PW4 */
1550 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
1551 /* PW9 Output enable */
1552 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1556 static int via_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1557 struct hda_codec
*codec
,
1558 struct snd_pcm_substream
*substream
)
1560 struct via_spec
*spec
= codec
->spec
;
1561 int idle
= substream
->pstr
->substream_opened
== 1
1562 && substream
->ref_count
== 0;
1563 analog_low_current_mode(codec
, idle
);
1564 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
1568 static void playback_multi_pcm_prep_0(struct hda_codec
*codec
,
1569 unsigned int stream_tag
,
1570 unsigned int format
,
1571 struct snd_pcm_substream
*substream
)
1573 struct via_spec
*spec
= codec
->spec
;
1574 struct hda_multi_out
*mout
= &spec
->multiout
;
1575 hda_nid_t
*nids
= mout
->dac_nids
;
1576 int chs
= substream
->runtime
->channels
;
1579 mutex_lock(&codec
->spdif_mutex
);
1580 if (mout
->dig_out_nid
&& mout
->dig_out_used
!= HDA_DIG_EXCLUSIVE
) {
1582 snd_hda_is_supported_format(codec
, mout
->dig_out_nid
,
1584 !(codec
->spdif_status
& IEC958_AES0_NONAUDIO
)) {
1585 mout
->dig_out_used
= HDA_DIG_ANALOG_DUP
;
1586 /* turn off SPDIF once; otherwise the IEC958 bits won't
1588 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1589 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1590 AC_VERB_SET_DIGI_CONVERT_1
,
1592 ~AC_DIG1_ENABLE
& 0xff);
1593 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1594 stream_tag
, 0, format
);
1595 /* turn on again (if needed) */
1596 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1597 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1598 AC_VERB_SET_DIGI_CONVERT_1
,
1599 codec
->spdif_ctls
& 0xff);
1601 mout
->dig_out_used
= 0;
1602 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1606 mutex_unlock(&codec
->spdif_mutex
);
1609 snd_hda_codec_setup_stream(codec
, nids
[HDA_FRONT
], stream_tag
,
1612 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
]
1613 && !spec
->hp_independent_mode
)
1614 /* headphone out will just decode front left/right (stereo) */
1615 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
, stream_tag
,
1618 /* extra outputs copied from front */
1619 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1620 if (mout
->extra_out_nid
[i
])
1621 snd_hda_codec_setup_stream(codec
,
1622 mout
->extra_out_nid
[i
],
1623 stream_tag
, 0, format
);
1626 for (i
= 1; i
< mout
->num_dacs
; i
++) {
1627 if (chs
>= (i
+ 1) * 2) /* independent out */
1628 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1630 else /* copy front */
1631 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1636 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1637 struct hda_codec
*codec
,
1638 unsigned int stream_tag
,
1639 unsigned int format
,
1640 struct snd_pcm_substream
*substream
)
1642 struct via_spec
*spec
= codec
->spec
;
1643 struct hda_multi_out
*mout
= &spec
->multiout
;
1644 hda_nid_t
*nids
= mout
->dac_nids
;
1646 if (substream
->number
== 0)
1647 playback_multi_pcm_prep_0(codec
, stream_tag
, format
,
1650 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1651 spec
->hp_independent_mode
)
1652 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1653 stream_tag
, 0, format
);
1655 vt1708_start_hp_work(spec
);
1659 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1660 struct hda_codec
*codec
,
1661 struct snd_pcm_substream
*substream
)
1663 struct via_spec
*spec
= codec
->spec
;
1664 struct hda_multi_out
*mout
= &spec
->multiout
;
1665 hda_nid_t
*nids
= mout
->dac_nids
;
1668 if (substream
->number
== 0) {
1669 for (i
= 0; i
< mout
->num_dacs
; i
++)
1670 snd_hda_codec_setup_stream(codec
, nids
[i
], 0, 0, 0);
1672 if (mout
->hp_nid
&& !spec
->hp_independent_mode
)
1673 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1676 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1677 if (mout
->extra_out_nid
[i
])
1678 snd_hda_codec_setup_stream(codec
,
1679 mout
->extra_out_nid
[i
],
1681 mutex_lock(&codec
->spdif_mutex
);
1682 if (mout
->dig_out_nid
&&
1683 mout
->dig_out_used
== HDA_DIG_ANALOG_DUP
) {
1684 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1686 mout
->dig_out_used
= 0;
1688 mutex_unlock(&codec
->spdif_mutex
);
1690 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1691 spec
->hp_independent_mode
)
1692 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1695 vt1708_stop_hp_work(spec
);
1702 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1703 struct hda_codec
*codec
,
1704 struct snd_pcm_substream
*substream
)
1706 struct via_spec
*spec
= codec
->spec
;
1707 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
1710 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
1711 struct hda_codec
*codec
,
1712 struct snd_pcm_substream
*substream
)
1714 struct via_spec
*spec
= codec
->spec
;
1715 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
1718 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1719 struct hda_codec
*codec
,
1720 unsigned int stream_tag
,
1721 unsigned int format
,
1722 struct snd_pcm_substream
*substream
)
1724 struct via_spec
*spec
= codec
->spec
;
1725 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
1726 stream_tag
, format
, substream
);
1729 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1730 struct hda_codec
*codec
,
1731 struct snd_pcm_substream
*substream
)
1733 struct via_spec
*spec
= codec
->spec
;
1734 snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
1741 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1742 struct hda_codec
*codec
,
1743 unsigned int stream_tag
,
1744 unsigned int format
,
1745 struct snd_pcm_substream
*substream
)
1747 struct via_spec
*spec
= codec
->spec
;
1749 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
1750 stream_tag
, 0, format
);
1754 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1755 struct hda_codec
*codec
,
1756 struct snd_pcm_substream
*substream
)
1758 struct via_spec
*spec
= codec
->spec
;
1759 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
1763 static struct hda_pcm_stream vt1708_pcm_analog_playback
= {
1767 .nid
= 0x10, /* NID to query formats and rates */
1769 .open
= via_playback_pcm_open
,
1770 .prepare
= via_playback_multi_pcm_prepare
,
1771 .cleanup
= via_playback_multi_pcm_cleanup
1775 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
1779 .nid
= 0x10, /* NID to query formats and rates */
1780 /* We got noisy outputs on the right channel on VT1708 when
1781 * 24bit samples are used. Until any workaround is found,
1782 * disable the 24bit format, so far.
1784 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1786 .open
= via_playback_pcm_open
,
1787 .prepare
= via_playback_multi_pcm_prepare
,
1788 .cleanup
= via_playback_multi_pcm_cleanup
1792 static struct hda_pcm_stream vt1708_pcm_analog_capture
= {
1796 .nid
= 0x15, /* NID to query formats and rates */
1798 .prepare
= via_capture_pcm_prepare
,
1799 .cleanup
= via_capture_pcm_cleanup
1803 static struct hda_pcm_stream vt1708_pcm_digital_playback
= {
1807 /* NID is set in via_build_pcms */
1809 .open
= via_dig_playback_pcm_open
,
1810 .close
= via_dig_playback_pcm_close
,
1811 .prepare
= via_dig_playback_pcm_prepare
,
1812 .cleanup
= via_dig_playback_pcm_cleanup
1816 static struct hda_pcm_stream vt1708_pcm_digital_capture
= {
1822 static int via_build_controls(struct hda_codec
*codec
)
1824 struct via_spec
*spec
= codec
->spec
;
1828 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1829 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1834 if (spec
->multiout
.dig_out_nid
) {
1835 err
= snd_hda_create_spdif_out_ctls(codec
,
1836 spec
->multiout
.dig_out_nid
);
1839 err
= snd_hda_create_spdif_share_sw(codec
,
1843 spec
->multiout
.share_spdif
= 1;
1845 if (spec
->dig_in_nid
) {
1846 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1851 /* init power states */
1852 set_jack_power_state(codec
);
1853 analog_low_current_mode(codec
, 1);
1855 via_free_kctls(codec
); /* no longer needed */
1859 static int via_build_pcms(struct hda_codec
*codec
)
1861 struct via_spec
*spec
= codec
->spec
;
1862 struct hda_pcm
*info
= spec
->pcm_rec
;
1864 codec
->num_pcms
= 1;
1865 codec
->pcm_info
= info
;
1867 info
->name
= spec
->stream_name_analog
;
1868 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1869 *(spec
->stream_analog_playback
);
1870 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1871 spec
->multiout
.dac_nids
[0];
1872 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *(spec
->stream_analog_capture
);
1873 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
1875 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
1876 spec
->multiout
.max_channels
;
1878 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
1881 info
->name
= spec
->stream_name_digital
;
1882 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
1883 if (spec
->multiout
.dig_out_nid
) {
1884 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1885 *(spec
->stream_digital_playback
);
1886 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1887 spec
->multiout
.dig_out_nid
;
1889 if (spec
->dig_in_nid
) {
1890 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
1891 *(spec
->stream_digital_capture
);
1892 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
1900 static void via_free(struct hda_codec
*codec
)
1902 struct via_spec
*spec
= codec
->spec
;
1907 via_free_kctls(codec
);
1908 vt1708_stop_hp_work(spec
);
1912 /* mute internal speaker if HP is plugged */
1913 static void via_hp_automute(struct hda_codec
*codec
)
1915 unsigned int present
= 0;
1916 struct via_spec
*spec
= codec
->spec
;
1918 present
= snd_hda_codec_read(codec
, spec
->autocfg
.hp_pins
[0], 0,
1919 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
1921 if (!spec
->hp_independent_mode
) {
1922 struct snd_ctl_elem_id id
;
1924 snd_hda_codec_amp_stereo(
1925 codec
, spec
->autocfg
.line_out_pins
[0], HDA_OUTPUT
, 0,
1926 HDA_AMP_MUTE
, present
? HDA_AMP_MUTE
: 0);
1928 memset(&id
, 0, sizeof(id
));
1929 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
1930 strcpy(id
.name
, "Front Playback Switch");
1931 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
1936 /* mute mono out if HP or Line out is plugged */
1937 static void via_mono_automute(struct hda_codec
*codec
)
1939 unsigned int hp_present
, lineout_present
;
1940 struct via_spec
*spec
= codec
->spec
;
1942 if (spec
->codec_type
!= VT1716S
)
1945 lineout_present
= snd_hda_codec_read(
1946 codec
, spec
->autocfg
.line_out_pins
[0], 0,
1947 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
1949 /* Mute Mono Out if Line Out is plugged */
1950 if (lineout_present
) {
1951 snd_hda_codec_amp_stereo(
1952 codec
, 0x2A, HDA_OUTPUT
, 0, HDA_AMP_MUTE
, HDA_AMP_MUTE
);
1956 hp_present
= snd_hda_codec_read(
1957 codec
, spec
->autocfg
.hp_pins
[0], 0,
1958 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
1960 if (!spec
->hp_independent_mode
)
1961 snd_hda_codec_amp_stereo(
1962 codec
, 0x2A, HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
1963 hp_present
? HDA_AMP_MUTE
: 0);
1966 static void via_gpio_control(struct hda_codec
*codec
)
1968 unsigned int gpio_data
;
1969 unsigned int vol_counter
;
1971 unsigned int master_vol
;
1973 struct via_spec
*spec
= codec
->spec
;
1975 gpio_data
= snd_hda_codec_read(codec
, codec
->afg
, 0,
1976 AC_VERB_GET_GPIO_DATA
, 0) & 0x03;
1978 vol_counter
= (snd_hda_codec_read(codec
, codec
->afg
, 0,
1979 0xF84, 0) & 0x3F0000) >> 16;
1981 vol
= vol_counter
& 0x1F;
1982 master_vol
= snd_hda_codec_read(codec
, 0x1A, 0,
1983 AC_VERB_GET_AMP_GAIN_MUTE
,
1986 if (gpio_data
== 0x02) {
1987 /* unmute line out */
1988 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
1989 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
1991 if (vol_counter
& 0x20) {
1992 /* decrease volume */
1993 if (vol
> master_vol
)
1995 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
,
1999 /* increase volume */
2000 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
, 0,
2002 ((master_vol
+vol
) > 0x2A) ? 0x2A :
2005 } else if (!(gpio_data
& 0x02)) {
2007 snd_hda_codec_amp_stereo(codec
,
2008 spec
->autocfg
.line_out_pins
[0],
2009 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
2014 /* mute Internal-Speaker if HP is plugged */
2015 static void via_speaker_automute(struct hda_codec
*codec
)
2017 unsigned int hp_present
;
2018 struct via_spec
*spec
= codec
->spec
;
2020 if (spec
->codec_type
!= VT2002P
&& spec
->codec_type
!= VT1812
)
2023 hp_present
= snd_hda_codec_read(codec
, spec
->autocfg
.hp_pins
[0], 0,
2024 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
2026 if (!spec
->hp_independent_mode
) {
2027 struct snd_ctl_elem_id id
;
2028 snd_hda_codec_amp_stereo(
2029 codec
, spec
->autocfg
.speaker_pins
[0], HDA_OUTPUT
, 0,
2030 HDA_AMP_MUTE
, hp_present
? HDA_AMP_MUTE
: 0);
2032 memset(&id
, 0, sizeof(id
));
2033 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
2034 strcpy(id
.name
, "Speaker Playback Switch");
2035 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
2040 /* mute line-out and internal speaker if HP is plugged */
2041 static void via_hp_bind_automute(struct hda_codec
*codec
)
2043 unsigned int hp_present
, present
= 0;
2044 struct via_spec
*spec
= codec
->spec
;
2047 if (!spec
->autocfg
.hp_pins
[0] || !spec
->autocfg
.line_out_pins
[0])
2050 hp_present
= snd_hda_codec_read(codec
, spec
->autocfg
.hp_pins
[0], 0,
2051 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
2053 present
= snd_hda_codec_read(codec
, spec
->autocfg
.line_out_pins
[0], 0,
2054 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
2056 if (!spec
->hp_independent_mode
) {
2057 /* Mute Line-Outs */
2058 for (i
= 0; i
< spec
->autocfg
.line_outs
; i
++)
2059 snd_hda_codec_amp_stereo(
2060 codec
, spec
->autocfg
.line_out_pins
[i
],
2062 HDA_AMP_MUTE
, hp_present
? HDA_AMP_MUTE
: 0);
2064 present
= hp_present
;
2067 for (i
= 0; i
< spec
->autocfg
.speaker_outs
; i
++)
2068 snd_hda_codec_amp_stereo(
2069 codec
, spec
->autocfg
.speaker_pins
[i
], HDA_OUTPUT
, 0,
2070 HDA_AMP_MUTE
, present
? HDA_AMP_MUTE
: 0);
2074 /* unsolicited event for jack sensing */
2075 static void via_unsol_event(struct hda_codec
*codec
,
2079 if (res
& VIA_HP_EVENT
)
2080 via_hp_automute(codec
);
2081 if (res
& VIA_GPIO_EVENT
)
2082 via_gpio_control(codec
);
2083 if (res
& VIA_JACK_EVENT
)
2084 set_jack_power_state(codec
);
2085 if (res
& VIA_MONO_EVENT
)
2086 via_mono_automute(codec
);
2087 if (res
& VIA_SPEAKER_EVENT
)
2088 via_speaker_automute(codec
);
2089 if (res
& VIA_BIND_HP_EVENT
)
2090 via_hp_bind_automute(codec
);
2093 static int via_init(struct hda_codec
*codec
)
2095 struct via_spec
*spec
= codec
->spec
;
2097 for (i
= 0; i
< spec
->num_iverbs
; i
++)
2098 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
2100 spec
->codec_type
= get_codec_type(codec
);
2101 if (spec
->codec_type
== VT1708BCE
)
2102 spec
->codec_type
= VT1708S
; /* VT1708BCE & VT1708S are almost
2104 /* Lydia Add for EAPD enable */
2105 if (!spec
->dig_in_nid
) { /* No Digital In connection */
2106 if (spec
->dig_in_pin
) {
2107 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
2108 AC_VERB_SET_PIN_WIDGET_CONTROL
,
2110 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
2111 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
2113 } else /* enable SPDIF-input pin */
2114 snd_hda_codec_write(codec
, spec
->autocfg
.dig_in_pin
, 0,
2115 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
2117 /* assign slave outs */
2118 if (spec
->slave_dig_outs
[0])
2119 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
2124 #ifdef SND_HDA_NEEDS_RESUME
2125 static int via_suspend(struct hda_codec
*codec
, pm_message_t state
)
2127 struct via_spec
*spec
= codec
->spec
;
2128 vt1708_stop_hp_work(spec
);
2133 #ifdef CONFIG_SND_HDA_POWER_SAVE
2134 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
2136 struct via_spec
*spec
= codec
->spec
;
2137 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
2143 static struct hda_codec_ops via_patch_ops
= {
2144 .build_controls
= via_build_controls
,
2145 .build_pcms
= via_build_pcms
,
2148 #ifdef SND_HDA_NEEDS_RESUME
2149 .suspend
= via_suspend
,
2151 #ifdef CONFIG_SND_HDA_POWER_SAVE
2152 .check_power_status
= via_check_power_status
,
2156 /* fill in the dac_nids table from the parsed pin configuration */
2157 static int vt1708_auto_fill_dac_nids(struct via_spec
*spec
,
2158 const struct auto_pin_cfg
*cfg
)
2163 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2165 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2167 for (i
= 0; i
< 4; i
++) {
2168 nid
= cfg
->line_out_pins
[i
];
2170 /* config dac list */
2172 case AUTO_SEQ_FRONT
:
2173 spec
->multiout
.dac_nids
[i
] = 0x10;
2175 case AUTO_SEQ_CENLFE
:
2176 spec
->multiout
.dac_nids
[i
] = 0x12;
2178 case AUTO_SEQ_SURROUND
:
2179 spec
->multiout
.dac_nids
[i
] = 0x11;
2182 spec
->multiout
.dac_nids
[i
] = 0x13;
2191 /* add playback controls from the parsed DAC table */
2192 static int vt1708_auto_create_multi_out_ctls(struct via_spec
*spec
,
2193 const struct auto_pin_cfg
*cfg
)
2196 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2197 hda_nid_t nid
, nid_vol
, nid_vols
[] = {0x17, 0x19, 0x1a, 0x1b};
2200 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2201 nid
= cfg
->line_out_pins
[i
];
2206 nid_vol
= nid_vols
[i
];
2208 if (i
== AUTO_SEQ_CENLFE
) {
2210 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2211 "Center Playback Volume",
2212 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2216 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2217 "LFE Playback Volume",
2218 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2222 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2223 "Center Playback Switch",
2224 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2228 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2229 "LFE Playback Switch",
2230 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2234 } else if (i
== AUTO_SEQ_FRONT
) {
2235 /* add control to mixer index 0 */
2236 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2237 "Master Front Playback Volume",
2238 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2242 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2243 "Master Front Playback Switch",
2244 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2249 /* add control to PW3 */
2250 sprintf(name
, "%s Playback Volume", chname
[i
]);
2251 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2252 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2256 sprintf(name
, "%s Playback Switch", chname
[i
]);
2257 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2258 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2263 sprintf(name
, "%s Playback Volume", chname
[i
]);
2264 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2265 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2269 sprintf(name
, "%s Playback Switch", chname
[i
]);
2270 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2271 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2281 static void create_hp_imux(struct via_spec
*spec
)
2284 struct hda_input_mux
*imux
= &spec
->private_imux
[1];
2285 static const char *texts
[] = { "OFF", "ON", NULL
};
2287 /* for hp mode select */
2289 while (texts
[i
] != NULL
) {
2290 imux
->items
[imux
->num_items
].label
= texts
[i
];
2291 imux
->items
[imux
->num_items
].index
= i
;
2296 spec
->hp_mux
= &spec
->private_imux
[1];
2299 static int vt1708_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2306 spec
->multiout
.hp_nid
= VT1708_HP_NID
; /* AOW3 */
2307 spec
->hp_independent_mode_index
= 1;
2309 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2310 "Headphone Playback Volume",
2311 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2314 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2315 "Headphone Playback Switch",
2316 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2320 create_hp_imux(spec
);
2325 /* create playback/capture controls for input pins */
2326 static int vt1708_auto_create_analog_input_ctls(struct via_spec
*spec
,
2327 const struct auto_pin_cfg
*cfg
)
2329 static char *labels
[] = {
2330 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2332 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2333 int i
, err
, idx
= 0;
2335 /* for internal loopback recording select */
2336 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2337 imux
->items
[imux
->num_items
].index
= idx
;
2340 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2341 if (!cfg
->input_pins
[i
])
2344 switch (cfg
->input_pins
[i
]) {
2345 case 0x1d: /* Mic */
2349 case 0x1e: /* Line In */
2353 case 0x21: /* Front Mic */
2361 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x17);
2364 imux
->items
[imux
->num_items
].label
= labels
[i
];
2365 imux
->items
[imux
->num_items
].index
= idx
;
2371 #ifdef CONFIG_SND_HDA_POWER_SAVE
2372 static struct hda_amp_list vt1708_loopbacks
[] = {
2373 { 0x17, HDA_INPUT
, 1 },
2374 { 0x17, HDA_INPUT
, 2 },
2375 { 0x17, HDA_INPUT
, 3 },
2376 { 0x17, HDA_INPUT
, 4 },
2381 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
2383 unsigned int def_conf
;
2384 unsigned char seqassoc
;
2386 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
2387 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
2388 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
2389 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
2390 && (seqassoc
== 0xf0 || seqassoc
== 0xff)) {
2391 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
2392 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
2398 static int vt1708_jack_detectect_get(struct snd_kcontrol
*kcontrol
,
2399 struct snd_ctl_elem_value
*ucontrol
)
2401 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2402 struct via_spec
*spec
= codec
->spec
;
2404 if (spec
->codec_type
!= VT1708
)
2406 spec
->vt1708_jack_detectect
=
2407 !((snd_hda_codec_read(codec
, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2408 ucontrol
->value
.integer
.value
[0] = spec
->vt1708_jack_detectect
;
2412 static int vt1708_jack_detectect_put(struct snd_kcontrol
*kcontrol
,
2413 struct snd_ctl_elem_value
*ucontrol
)
2415 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2416 struct via_spec
*spec
= codec
->spec
;
2419 if (spec
->codec_type
!= VT1708
)
2421 spec
->vt1708_jack_detectect
= ucontrol
->value
.integer
.value
[0];
2422 change
= (0x1 & (snd_hda_codec_read(codec
, 0x1, 0, 0xf84, 0) >> 8))
2423 == !spec
->vt1708_jack_detectect
;
2424 if (spec
->vt1708_jack_detectect
) {
2425 mute_aa_path(codec
, 1);
2426 notify_aa_path_ctls(codec
);
2431 static struct snd_kcontrol_new vt1708_jack_detectect
[] = {
2433 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2434 .name
= "Jack Detect",
2436 .info
= snd_ctl_boolean_mono_info
,
2437 .get
= vt1708_jack_detectect_get
,
2438 .put
= vt1708_jack_detectect_put
,
2443 static int vt1708_parse_auto_config(struct hda_codec
*codec
)
2445 struct via_spec
*spec
= codec
->spec
;
2448 /* Add HP and CD pin config connect bit re-config action */
2449 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
2450 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
2452 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2455 err
= vt1708_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2458 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2459 return 0; /* can't find valid BIOS pin config */
2461 err
= vt1708_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2464 err
= vt1708_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2467 err
= vt1708_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2470 /* add jack detect on/off control */
2471 err
= snd_hda_add_new_ctls(codec
, vt1708_jack_detectect
);
2475 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2477 if (spec
->autocfg
.dig_outs
)
2478 spec
->multiout
.dig_out_nid
= VT1708_DIGOUT_NID
;
2479 spec
->dig_in_pin
= VT1708_DIGIN_PIN
;
2480 if (spec
->autocfg
.dig_in_pin
)
2481 spec
->dig_in_nid
= VT1708_DIGIN_NID
;
2483 if (spec
->kctls
.list
)
2484 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2486 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_volume_init_verbs
;
2488 spec
->input_mux
= &spec
->private_imux
[0];
2491 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2493 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
2497 /* init callback for auto-configuration model -- overriding the default init */
2498 static int via_auto_init(struct hda_codec
*codec
)
2500 struct via_spec
*spec
= codec
->spec
;
2503 via_auto_init_multi_out(codec
);
2504 via_auto_init_hp_out(codec
);
2505 via_auto_init_analog_input(codec
);
2506 if (spec
->codec_type
== VT2002P
|| spec
->codec_type
== VT1812
) {
2507 via_hp_bind_automute(codec
);
2509 via_hp_automute(codec
);
2510 via_speaker_automute(codec
);
2516 static void vt1708_update_hp_jack_state(struct work_struct
*work
)
2518 struct via_spec
*spec
= container_of(work
, struct via_spec
,
2519 vt1708_hp_work
.work
);
2520 if (spec
->codec_type
!= VT1708
)
2522 /* if jack state toggled */
2523 if (spec
->vt1708_hp_present
2524 != (snd_hda_codec_read(spec
->codec
, spec
->autocfg
.hp_pins
[0], 0,
2525 AC_VERB_GET_PIN_SENSE
, 0) >> 31)) {
2526 spec
->vt1708_hp_present
^= 1;
2527 via_hp_automute(spec
->codec
);
2529 vt1708_start_hp_work(spec
);
2532 static int get_mux_nids(struct hda_codec
*codec
)
2534 struct via_spec
*spec
= codec
->spec
;
2535 hda_nid_t nid
, conn
[8];
2539 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
2540 nid
= spec
->adc_nids
[i
];
2542 type
= get_wcaps_type(get_wcaps(codec
, nid
));
2543 if (type
== AC_WID_PIN
)
2545 n
= snd_hda_get_connections(codec
, nid
, conn
,
2550 spec
->mux_nids
[i
] = nid
;
2559 static int patch_vt1708(struct hda_codec
*codec
)
2561 struct via_spec
*spec
;
2564 /* create a codec specific record */
2565 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2571 /* automatic parse from the BIOS config */
2572 err
= vt1708_parse_auto_config(codec
);
2577 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2578 "from BIOS. Using genenic mode...\n");
2582 spec
->stream_name_analog
= "VT1708 Analog";
2583 spec
->stream_analog_playback
= &vt1708_pcm_analog_playback
;
2584 /* disable 32bit format on VT1708 */
2585 if (codec
->vendor_id
== 0x11061708)
2586 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
2587 spec
->stream_analog_capture
= &vt1708_pcm_analog_capture
;
2589 spec
->stream_name_digital
= "VT1708 Digital";
2590 spec
->stream_digital_playback
= &vt1708_pcm_digital_playback
;
2591 spec
->stream_digital_capture
= &vt1708_pcm_digital_capture
;
2594 if (!spec
->adc_nids
&& spec
->input_mux
) {
2595 spec
->adc_nids
= vt1708_adc_nids
;
2596 spec
->num_adc_nids
= ARRAY_SIZE(vt1708_adc_nids
);
2597 get_mux_nids(codec
);
2598 spec
->mixers
[spec
->num_mixers
] = vt1708_capture_mixer
;
2602 codec
->patch_ops
= via_patch_ops
;
2604 codec
->patch_ops
.init
= via_auto_init
;
2605 #ifdef CONFIG_SND_HDA_POWER_SAVE
2606 spec
->loopback
.amplist
= vt1708_loopbacks
;
2608 spec
->codec
= codec
;
2609 INIT_DELAYED_WORK(&spec
->vt1708_hp_work
, vt1708_update_hp_jack_state
);
2613 /* capture mixer elements */
2614 static struct snd_kcontrol_new vt1709_capture_mixer
[] = {
2615 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT
),
2616 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT
),
2617 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT
),
2618 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT
),
2619 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT
),
2620 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT
),
2622 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2623 /* The multiple "Capture Source" controls confuse alsamixer
2624 * So call somewhat different..
2626 /* .name = "Capture Source", */
2627 .name
= "Input Source",
2629 .info
= via_mux_enum_info
,
2630 .get
= via_mux_enum_get
,
2631 .put
= via_mux_enum_put
,
2636 static struct hda_verb vt1709_uniwill_init_verbs
[] = {
2637 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
,
2638 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
2643 * generic initialization of ADC, input mixers and output mixers
2645 static struct hda_verb vt1709_10ch_volume_init_verbs
[] = {
2647 * Unmute ADC0-2 and set the default input to mic-in
2649 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2650 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2651 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2654 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2657 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2658 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2659 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2660 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2661 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2662 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2665 * Set up output selector (0x1a, 0x1b, 0x29)
2667 /* set vol=0 to output mixers */
2668 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2669 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2670 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2673 * Unmute PW3 and PW4
2675 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2676 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2678 /* Set input of PW4 as MW0 */
2679 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
2680 /* PW9 Output enable */
2681 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2685 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback
= {
2689 .nid
= 0x10, /* NID to query formats and rates */
2691 .open
= via_playback_pcm_open
,
2692 .prepare
= via_playback_multi_pcm_prepare
,
2693 .cleanup
= via_playback_multi_pcm_cleanup
,
2697 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback
= {
2701 .nid
= 0x10, /* NID to query formats and rates */
2703 .open
= via_playback_pcm_open
,
2704 .prepare
= via_playback_multi_pcm_prepare
,
2705 .cleanup
= via_playback_multi_pcm_cleanup
,
2709 static struct hda_pcm_stream vt1709_pcm_analog_capture
= {
2713 .nid
= 0x14, /* NID to query formats and rates */
2715 .prepare
= via_capture_pcm_prepare
,
2716 .cleanup
= via_capture_pcm_cleanup
2720 static struct hda_pcm_stream vt1709_pcm_digital_playback
= {
2724 /* NID is set in via_build_pcms */
2726 .open
= via_dig_playback_pcm_open
,
2727 .close
= via_dig_playback_pcm_close
2731 static struct hda_pcm_stream vt1709_pcm_digital_capture
= {
2737 static int vt1709_auto_fill_dac_nids(struct via_spec
*spec
,
2738 const struct auto_pin_cfg
*cfg
)
2743 if (cfg
->line_outs
== 4) /* 10 channels */
2744 spec
->multiout
.num_dacs
= cfg
->line_outs
+1; /* AOW0~AOW4 */
2745 else if (cfg
->line_outs
== 3) /* 6 channels */
2746 spec
->multiout
.num_dacs
= cfg
->line_outs
; /* AOW0~AOW2 */
2748 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2750 if (cfg
->line_outs
== 4) { /* 10 channels */
2751 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2752 nid
= cfg
->line_out_pins
[i
];
2754 /* config dac list */
2756 case AUTO_SEQ_FRONT
:
2758 spec
->multiout
.dac_nids
[i
] = 0x10;
2760 case AUTO_SEQ_CENLFE
:
2762 spec
->multiout
.dac_nids
[i
] = 0x12;
2764 case AUTO_SEQ_SURROUND
:
2766 spec
->multiout
.dac_nids
[i
] = 0x11;
2770 spec
->multiout
.dac_nids
[i
] = 0x27;
2777 spec
->multiout
.dac_nids
[cfg
->line_outs
] = 0x28; /* AOW4 */
2779 } else if (cfg
->line_outs
== 3) { /* 6 channels */
2780 for (i
= 0; i
< cfg
->line_outs
; i
++) {
2781 nid
= cfg
->line_out_pins
[i
];
2783 /* config dac list */
2785 case AUTO_SEQ_FRONT
:
2787 spec
->multiout
.dac_nids
[i
] = 0x10;
2789 case AUTO_SEQ_CENLFE
:
2791 spec
->multiout
.dac_nids
[i
] = 0x12;
2793 case AUTO_SEQ_SURROUND
:
2795 spec
->multiout
.dac_nids
[i
] = 0x11;
2807 /* add playback controls from the parsed DAC table */
2808 static int vt1709_auto_create_multi_out_ctls(struct via_spec
*spec
,
2809 const struct auto_pin_cfg
*cfg
)
2812 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2813 hda_nid_t nid
, nid_vol
, nid_vols
[] = {0x18, 0x1a, 0x1b, 0x29};
2816 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2817 nid
= cfg
->line_out_pins
[i
];
2822 nid_vol
= nid_vols
[i
];
2824 if (i
== AUTO_SEQ_CENLFE
) {
2826 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2827 "Center Playback Volume",
2828 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2832 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2833 "LFE Playback Volume",
2834 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2838 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2839 "Center Playback Switch",
2840 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2844 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2845 "LFE Playback Switch",
2846 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2850 } else if (i
== AUTO_SEQ_FRONT
) {
2851 /* ADD control to mixer index 0 */
2852 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2853 "Master Front Playback Volume",
2854 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2858 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2859 "Master Front Playback Switch",
2860 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2865 /* add control to PW3 */
2866 sprintf(name
, "%s Playback Volume", chname
[i
]);
2867 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2868 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2872 sprintf(name
, "%s Playback Switch", chname
[i
]);
2873 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2874 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2878 } else if (i
== AUTO_SEQ_SURROUND
) {
2879 sprintf(name
, "%s Playback Volume", chname
[i
]);
2880 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2881 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2885 sprintf(name
, "%s Playback Switch", chname
[i
]);
2886 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2887 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2891 } else if (i
== AUTO_SEQ_SIDE
) {
2892 sprintf(name
, "%s Playback Volume", chname
[i
]);
2893 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2894 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2898 sprintf(name
, "%s Playback Switch", chname
[i
]);
2899 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2900 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2910 static int vt1709_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2917 if (spec
->multiout
.num_dacs
== 5) /* 10 channels */
2918 spec
->multiout
.hp_nid
= VT1709_HP_DAC_NID
;
2919 else if (spec
->multiout
.num_dacs
== 3) /* 6 channels */
2920 spec
->multiout
.hp_nid
= 0;
2921 spec
->hp_independent_mode_index
= 1;
2923 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2924 "Headphone Playback Volume",
2925 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2928 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2929 "Headphone Playback Switch",
2930 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2937 /* create playback/capture controls for input pins */
2938 static int vt1709_auto_create_analog_input_ctls(struct via_spec
*spec
,
2939 const struct auto_pin_cfg
*cfg
)
2941 static char *labels
[] = {
2942 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2944 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2945 int i
, err
, idx
= 0;
2947 /* for internal loopback recording select */
2948 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2949 imux
->items
[imux
->num_items
].index
= idx
;
2952 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2953 if (!cfg
->input_pins
[i
])
2956 switch (cfg
->input_pins
[i
]) {
2957 case 0x1d: /* Mic */
2961 case 0x1e: /* Line In */
2965 case 0x21: /* Front Mic */
2973 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x18);
2976 imux
->items
[imux
->num_items
].label
= labels
[i
];
2977 imux
->items
[imux
->num_items
].index
= idx
;
2983 static int vt1709_parse_auto_config(struct hda_codec
*codec
)
2985 struct via_spec
*spec
= codec
->spec
;
2988 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2991 err
= vt1709_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2994 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2995 return 0; /* can't find valid BIOS pin config */
2997 err
= vt1709_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
3000 err
= vt1709_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3003 err
= vt1709_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3007 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3009 if (spec
->autocfg
.dig_outs
)
3010 spec
->multiout
.dig_out_nid
= VT1709_DIGOUT_NID
;
3011 spec
->dig_in_pin
= VT1709_DIGIN_PIN
;
3012 if (spec
->autocfg
.dig_in_pin
)
3013 spec
->dig_in_nid
= VT1709_DIGIN_NID
;
3015 if (spec
->kctls
.list
)
3016 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3018 spec
->input_mux
= &spec
->private_imux
[0];
3021 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3023 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
3027 #ifdef CONFIG_SND_HDA_POWER_SAVE
3028 static struct hda_amp_list vt1709_loopbacks
[] = {
3029 { 0x18, HDA_INPUT
, 1 },
3030 { 0x18, HDA_INPUT
, 2 },
3031 { 0x18, HDA_INPUT
, 3 },
3032 { 0x18, HDA_INPUT
, 4 },
3037 static int patch_vt1709_10ch(struct hda_codec
*codec
)
3039 struct via_spec
*spec
;
3042 /* create a codec specific record */
3043 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3049 err
= vt1709_parse_auto_config(codec
);
3054 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
3055 "Using genenic mode...\n");
3058 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_10ch_volume_init_verbs
;
3059 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
3061 spec
->stream_name_analog
= "VT1709 Analog";
3062 spec
->stream_analog_playback
= &vt1709_10ch_pcm_analog_playback
;
3063 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
3065 spec
->stream_name_digital
= "VT1709 Digital";
3066 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
3067 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
3070 if (!spec
->adc_nids
&& spec
->input_mux
) {
3071 spec
->adc_nids
= vt1709_adc_nids
;
3072 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
3073 get_mux_nids(codec
);
3074 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
3078 codec
->patch_ops
= via_patch_ops
;
3080 codec
->patch_ops
.init
= via_auto_init
;
3081 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3082 #ifdef CONFIG_SND_HDA_POWER_SAVE
3083 spec
->loopback
.amplist
= vt1709_loopbacks
;
3089 * generic initialization of ADC, input mixers and output mixers
3091 static struct hda_verb vt1709_6ch_volume_init_verbs
[] = {
3093 * Unmute ADC0-2 and set the default input to mic-in
3095 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3096 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3097 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3100 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3103 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3104 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3105 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3106 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3107 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3108 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3111 * Set up output selector (0x1a, 0x1b, 0x29)
3113 /* set vol=0 to output mixers */
3114 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3115 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3116 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3119 * Unmute PW3 and PW4
3121 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3122 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3124 /* Set input of PW4 as MW0 */
3125 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
3126 /* PW9 Output enable */
3127 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3131 static int patch_vt1709_6ch(struct hda_codec
*codec
)
3133 struct via_spec
*spec
;
3136 /* create a codec specific record */
3137 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3143 err
= vt1709_parse_auto_config(codec
);
3148 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
3149 "Using genenic mode...\n");
3152 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_6ch_volume_init_verbs
;
3153 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
3155 spec
->stream_name_analog
= "VT1709 Analog";
3156 spec
->stream_analog_playback
= &vt1709_6ch_pcm_analog_playback
;
3157 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
3159 spec
->stream_name_digital
= "VT1709 Digital";
3160 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
3161 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
3164 if (!spec
->adc_nids
&& spec
->input_mux
) {
3165 spec
->adc_nids
= vt1709_adc_nids
;
3166 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
3167 get_mux_nids(codec
);
3168 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
3172 codec
->patch_ops
= via_patch_ops
;
3174 codec
->patch_ops
.init
= via_auto_init
;
3175 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3176 #ifdef CONFIG_SND_HDA_POWER_SAVE
3177 spec
->loopback
.amplist
= vt1709_loopbacks
;
3182 /* capture mixer elements */
3183 static struct snd_kcontrol_new vt1708B_capture_mixer
[] = {
3184 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
3185 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
3186 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
3187 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
3189 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3190 /* The multiple "Capture Source" controls confuse alsamixer
3191 * So call somewhat different..
3193 /* .name = "Capture Source", */
3194 .name
= "Input Source",
3196 .info
= via_mux_enum_info
,
3197 .get
= via_mux_enum_get
,
3198 .put
= via_mux_enum_put
,
3203 * generic initialization of ADC, input mixers and output mixers
3205 static struct hda_verb vt1708B_8ch_volume_init_verbs
[] = {
3207 * Unmute ADC0-1 and set the default input to mic-in
3209 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3210 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3213 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3216 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3217 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3218 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3219 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3220 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3221 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3224 * Set up output mixers
3226 /* set vol=0 to output mixers */
3227 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3228 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3229 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3231 /* Setup default input to PW4 */
3232 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0},
3233 /* PW9 Output enable */
3234 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3235 /* PW10 Input enable */
3236 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
3240 static struct hda_verb vt1708B_4ch_volume_init_verbs
[] = {
3242 * Unmute ADC0-1 and set the default input to mic-in
3244 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3245 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3248 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3251 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3252 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3253 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3254 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3255 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3256 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3259 * Set up output mixers
3261 /* set vol=0 to output mixers */
3262 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3263 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3264 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
3266 /* Setup default input of PW4 to MW0 */
3267 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
3268 /* PW9 Output enable */
3269 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3270 /* PW10 Input enable */
3271 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
3275 static struct hda_verb vt1708B_uniwill_init_verbs
[] = {
3276 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
3277 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
3278 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3279 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3280 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3281 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3282 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3283 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3284 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3288 static int via_pcm_open_close(struct hda_pcm_stream
*hinfo
,
3289 struct hda_codec
*codec
,
3290 struct snd_pcm_substream
*substream
)
3292 int idle
= substream
->pstr
->substream_opened
== 1
3293 && substream
->ref_count
== 0;
3295 analog_low_current_mode(codec
, idle
);
3299 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback
= {
3303 .nid
= 0x10, /* NID to query formats and rates */
3305 .open
= via_playback_pcm_open
,
3306 .prepare
= via_playback_multi_pcm_prepare
,
3307 .cleanup
= via_playback_multi_pcm_cleanup
,
3308 .close
= via_pcm_open_close
3312 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback
= {
3316 .nid
= 0x10, /* NID to query formats and rates */
3318 .open
= via_playback_pcm_open
,
3319 .prepare
= via_playback_multi_pcm_prepare
,
3320 .cleanup
= via_playback_multi_pcm_cleanup
3324 static struct hda_pcm_stream vt1708B_pcm_analog_capture
= {
3328 .nid
= 0x13, /* NID to query formats and rates */
3330 .open
= via_pcm_open_close
,
3331 .prepare
= via_capture_pcm_prepare
,
3332 .cleanup
= via_capture_pcm_cleanup
,
3333 .close
= via_pcm_open_close
3337 static struct hda_pcm_stream vt1708B_pcm_digital_playback
= {
3341 /* NID is set in via_build_pcms */
3343 .open
= via_dig_playback_pcm_open
,
3344 .close
= via_dig_playback_pcm_close
,
3345 .prepare
= via_dig_playback_pcm_prepare
,
3346 .cleanup
= via_dig_playback_pcm_cleanup
3350 static struct hda_pcm_stream vt1708B_pcm_digital_capture
= {
3356 /* fill in the dac_nids table from the parsed pin configuration */
3357 static int vt1708B_auto_fill_dac_nids(struct via_spec
*spec
,
3358 const struct auto_pin_cfg
*cfg
)
3363 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3365 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3367 for (i
= 0; i
< 4; i
++) {
3368 nid
= cfg
->line_out_pins
[i
];
3370 /* config dac list */
3372 case AUTO_SEQ_FRONT
:
3373 spec
->multiout
.dac_nids
[i
] = 0x10;
3375 case AUTO_SEQ_CENLFE
:
3376 spec
->multiout
.dac_nids
[i
] = 0x24;
3378 case AUTO_SEQ_SURROUND
:
3379 spec
->multiout
.dac_nids
[i
] = 0x11;
3382 spec
->multiout
.dac_nids
[i
] = 0x25;
3391 /* add playback controls from the parsed DAC table */
3392 static int vt1708B_auto_create_multi_out_ctls(struct via_spec
*spec
,
3393 const struct auto_pin_cfg
*cfg
)
3396 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
3397 hda_nid_t nid_vols
[] = {0x16, 0x18, 0x26, 0x27};
3398 hda_nid_t nid
, nid_vol
= 0;
3401 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
3402 nid
= cfg
->line_out_pins
[i
];
3407 nid_vol
= nid_vols
[i
];
3409 if (i
== AUTO_SEQ_CENLFE
) {
3411 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3412 "Center Playback Volume",
3413 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3417 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3418 "LFE Playback Volume",
3419 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3423 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3424 "Center Playback Switch",
3425 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3429 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3430 "LFE Playback Switch",
3431 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3435 } else if (i
== AUTO_SEQ_FRONT
) {
3436 /* add control to mixer index 0 */
3437 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3438 "Master Front Playback Volume",
3439 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3443 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3444 "Master Front Playback Switch",
3445 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3450 /* add control to PW3 */
3451 sprintf(name
, "%s Playback Volume", chname
[i
]);
3452 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3453 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
3457 sprintf(name
, "%s Playback Switch", chname
[i
]);
3458 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3459 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
3464 sprintf(name
, "%s Playback Volume", chname
[i
]);
3465 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3466 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3470 sprintf(name
, "%s Playback Switch", chname
[i
]);
3471 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3472 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3482 static int vt1708B_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3489 spec
->multiout
.hp_nid
= VT1708B_HP_NID
; /* AOW3 */
3490 spec
->hp_independent_mode_index
= 1;
3492 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3493 "Headphone Playback Volume",
3494 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3497 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3498 "Headphone Playback Switch",
3499 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3503 create_hp_imux(spec
);
3508 /* create playback/capture controls for input pins */
3509 static int vt1708B_auto_create_analog_input_ctls(struct via_spec
*spec
,
3510 const struct auto_pin_cfg
*cfg
)
3512 static char *labels
[] = {
3513 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3515 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3516 int i
, err
, idx
= 0;
3518 /* for internal loopback recording select */
3519 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3520 imux
->items
[imux
->num_items
].index
= idx
;
3523 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3524 if (!cfg
->input_pins
[i
])
3527 switch (cfg
->input_pins
[i
]) {
3528 case 0x1a: /* Mic */
3532 case 0x1b: /* Line In */
3536 case 0x1e: /* Front Mic */
3544 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
3547 imux
->items
[imux
->num_items
].label
= labels
[i
];
3548 imux
->items
[imux
->num_items
].index
= idx
;
3554 static int vt1708B_parse_auto_config(struct hda_codec
*codec
)
3556 struct via_spec
*spec
= codec
->spec
;
3559 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3562 err
= vt1708B_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3565 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3566 return 0; /* can't find valid BIOS pin config */
3568 err
= vt1708B_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
3571 err
= vt1708B_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3574 err
= vt1708B_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3578 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3580 if (spec
->autocfg
.dig_outs
)
3581 spec
->multiout
.dig_out_nid
= VT1708B_DIGOUT_NID
;
3582 spec
->dig_in_pin
= VT1708B_DIGIN_PIN
;
3583 if (spec
->autocfg
.dig_in_pin
)
3584 spec
->dig_in_nid
= VT1708B_DIGIN_NID
;
3586 if (spec
->kctls
.list
)
3587 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3589 spec
->input_mux
= &spec
->private_imux
[0];
3592 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3594 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
3598 #ifdef CONFIG_SND_HDA_POWER_SAVE
3599 static struct hda_amp_list vt1708B_loopbacks
[] = {
3600 { 0x16, HDA_INPUT
, 1 },
3601 { 0x16, HDA_INPUT
, 2 },
3602 { 0x16, HDA_INPUT
, 3 },
3603 { 0x16, HDA_INPUT
, 4 },
3607 static int patch_vt1708S(struct hda_codec
*codec
);
3608 static int patch_vt1708B_8ch(struct hda_codec
*codec
)
3610 struct via_spec
*spec
;
3613 if (get_codec_type(codec
) == VT1708BCE
)
3614 return patch_vt1708S(codec
);
3615 /* create a codec specific record */
3616 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3622 /* automatic parse from the BIOS config */
3623 err
= vt1708B_parse_auto_config(codec
);
3628 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3629 "from BIOS. Using genenic mode...\n");
3632 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_8ch_volume_init_verbs
;
3633 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
3635 spec
->stream_name_analog
= "VT1708B Analog";
3636 spec
->stream_analog_playback
= &vt1708B_8ch_pcm_analog_playback
;
3637 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
3639 spec
->stream_name_digital
= "VT1708B Digital";
3640 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
3641 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
3643 if (!spec
->adc_nids
&& spec
->input_mux
) {
3644 spec
->adc_nids
= vt1708B_adc_nids
;
3645 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
3646 get_mux_nids(codec
);
3647 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
3651 codec
->patch_ops
= via_patch_ops
;
3653 codec
->patch_ops
.init
= via_auto_init
;
3654 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3655 #ifdef CONFIG_SND_HDA_POWER_SAVE
3656 spec
->loopback
.amplist
= vt1708B_loopbacks
;
3662 static int patch_vt1708B_4ch(struct hda_codec
*codec
)
3664 struct via_spec
*spec
;
3667 /* create a codec specific record */
3668 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3674 /* automatic parse from the BIOS config */
3675 err
= vt1708B_parse_auto_config(codec
);
3680 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3681 "from BIOS. Using genenic mode...\n");
3684 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_4ch_volume_init_verbs
;
3685 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
3687 spec
->stream_name_analog
= "VT1708B Analog";
3688 spec
->stream_analog_playback
= &vt1708B_4ch_pcm_analog_playback
;
3689 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
3691 spec
->stream_name_digital
= "VT1708B Digital";
3692 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
3693 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
3695 if (!spec
->adc_nids
&& spec
->input_mux
) {
3696 spec
->adc_nids
= vt1708B_adc_nids
;
3697 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
3698 get_mux_nids(codec
);
3699 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
3703 codec
->patch_ops
= via_patch_ops
;
3705 codec
->patch_ops
.init
= via_auto_init
;
3706 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3707 #ifdef CONFIG_SND_HDA_POWER_SAVE
3708 spec
->loopback
.amplist
= vt1708B_loopbacks
;
3714 /* Patch for VT1708S */
3716 /* capture mixer elements */
3717 static struct snd_kcontrol_new vt1708S_capture_mixer
[] = {
3718 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
3719 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
3720 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
3721 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
3722 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT
),
3723 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3726 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3727 /* The multiple "Capture Source" controls confuse alsamixer
3728 * So call somewhat different..
3730 /* .name = "Capture Source", */
3731 .name
= "Input Source",
3733 .info
= via_mux_enum_info
,
3734 .get
= via_mux_enum_get
,
3735 .put
= via_mux_enum_put
,
3740 static struct hda_verb vt1708S_volume_init_verbs
[] = {
3741 /* Unmute ADC0-1 and set the default input to mic-in */
3742 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3743 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3745 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3746 * analog-loopback mixer widget */
3747 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3748 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3749 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3750 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3751 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3752 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3754 /* Setup default input of PW4 to MW0 */
3755 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
3756 /* PW9, PW10 Output enable */
3757 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3758 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3759 /* Enable Mic Boost Volume backdoor */
3761 /* don't bybass mixer */
3766 static struct hda_verb vt1708S_uniwill_init_verbs
[] = {
3767 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
3768 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
3769 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3770 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3771 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3772 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3773 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3774 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3775 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3779 static struct hda_pcm_stream vt1708S_pcm_analog_playback
= {
3783 .nid
= 0x10, /* NID to query formats and rates */
3785 .open
= via_playback_pcm_open
,
3786 .prepare
= via_playback_multi_pcm_prepare
,
3787 .cleanup
= via_playback_multi_pcm_cleanup
,
3788 .close
= via_pcm_open_close
3792 static struct hda_pcm_stream vt1708S_pcm_analog_capture
= {
3796 .nid
= 0x13, /* NID to query formats and rates */
3798 .open
= via_pcm_open_close
,
3799 .prepare
= via_capture_pcm_prepare
,
3800 .cleanup
= via_capture_pcm_cleanup
,
3801 .close
= via_pcm_open_close
3805 static struct hda_pcm_stream vt1708S_pcm_digital_playback
= {
3809 /* NID is set in via_build_pcms */
3811 .open
= via_dig_playback_pcm_open
,
3812 .close
= via_dig_playback_pcm_close
,
3813 .prepare
= via_dig_playback_pcm_prepare
,
3814 .cleanup
= via_dig_playback_pcm_cleanup
3818 /* fill in the dac_nids table from the parsed pin configuration */
3819 static int vt1708S_auto_fill_dac_nids(struct via_spec
*spec
,
3820 const struct auto_pin_cfg
*cfg
)
3825 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3827 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3829 for (i
= 0; i
< 4; i
++) {
3830 nid
= cfg
->line_out_pins
[i
];
3832 /* config dac list */
3834 case AUTO_SEQ_FRONT
:
3835 spec
->multiout
.dac_nids
[i
] = 0x10;
3837 case AUTO_SEQ_CENLFE
:
3838 spec
->multiout
.dac_nids
[i
] = 0x24;
3840 case AUTO_SEQ_SURROUND
:
3841 spec
->multiout
.dac_nids
[i
] = 0x11;
3844 spec
->multiout
.dac_nids
[i
] = 0x25;
3853 /* add playback controls from the parsed DAC table */
3854 static int vt1708S_auto_create_multi_out_ctls(struct via_spec
*spec
,
3855 const struct auto_pin_cfg
*cfg
)
3858 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
3859 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x24, 0x25};
3860 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x26, 0x27};
3861 hda_nid_t nid
, nid_vol
, nid_mute
;
3864 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
3865 nid
= cfg
->line_out_pins
[i
];
3870 nid_vol
= nid_vols
[i
];
3871 nid_mute
= nid_mutes
[i
];
3873 if (i
== AUTO_SEQ_CENLFE
) {
3875 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3876 "Center Playback Volume",
3877 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3881 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3882 "LFE Playback Volume",
3883 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3887 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3888 "Center Playback Switch",
3889 HDA_COMPOSE_AMP_VAL(nid_mute
,
3894 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3895 "LFE Playback Switch",
3896 HDA_COMPOSE_AMP_VAL(nid_mute
,
3901 } else if (i
== AUTO_SEQ_FRONT
) {
3902 /* add control to mixer index 0 */
3903 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3904 "Master Front Playback Volume",
3905 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3909 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3910 "Master Front Playback Switch",
3911 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3917 sprintf(name
, "%s Playback Volume", chname
[i
]);
3918 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3919 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3923 sprintf(name
, "%s Playback Switch", chname
[i
]);
3924 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3925 HDA_COMPOSE_AMP_VAL(nid_mute
,
3931 sprintf(name
, "%s Playback Volume", chname
[i
]);
3932 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3933 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3937 sprintf(name
, "%s Playback Switch", chname
[i
]);
3938 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3939 HDA_COMPOSE_AMP_VAL(nid_mute
,
3950 static int vt1708S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3957 spec
->multiout
.hp_nid
= VT1708S_HP_NID
; /* AOW3 */
3958 spec
->hp_independent_mode_index
= 1;
3960 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3961 "Headphone Playback Volume",
3962 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
3966 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3967 "Headphone Playback Switch",
3968 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3972 create_hp_imux(spec
);
3977 /* create playback/capture controls for input pins */
3978 static int vt1708S_auto_create_analog_input_ctls(struct via_spec
*spec
,
3979 const struct auto_pin_cfg
*cfg
)
3981 static char *labels
[] = {
3982 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3984 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3985 int i
, err
, idx
= 0;
3987 /* for internal loopback recording select */
3988 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3989 imux
->items
[imux
->num_items
].index
= 5;
3992 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3993 if (!cfg
->input_pins
[i
])
3996 switch (cfg
->input_pins
[i
]) {
3997 case 0x1a: /* Mic */
4001 case 0x1b: /* Line In */
4005 case 0x1e: /* Front Mic */
4013 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
4016 imux
->items
[imux
->num_items
].label
= labels
[i
];
4017 imux
->items
[imux
->num_items
].index
= idx
-1;
4023 /* fill out digital output widgets; one for master and one for slave outputs */
4024 static void fill_dig_outs(struct hda_codec
*codec
)
4026 struct via_spec
*spec
= codec
->spec
;
4029 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
4033 nid
= spec
->autocfg
.dig_out_pins
[i
];
4036 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
4039 if (!spec
->multiout
.dig_out_nid
)
4040 spec
->multiout
.dig_out_nid
= nid
;
4042 spec
->slave_dig_outs
[0] = nid
;
4043 break; /* at most two dig outs */
4048 static int vt1708S_parse_auto_config(struct hda_codec
*codec
)
4050 struct via_spec
*spec
= codec
->spec
;
4053 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
4056 err
= vt1708S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
4059 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
4060 return 0; /* can't find valid BIOS pin config */
4062 err
= vt1708S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
4065 err
= vt1708S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
4068 err
= vt1708S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
4072 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4074 fill_dig_outs(codec
);
4076 if (spec
->kctls
.list
)
4077 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
4079 spec
->input_mux
= &spec
->private_imux
[0];
4082 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
4084 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
4088 #ifdef CONFIG_SND_HDA_POWER_SAVE
4089 static struct hda_amp_list vt1708S_loopbacks
[] = {
4090 { 0x16, HDA_INPUT
, 1 },
4091 { 0x16, HDA_INPUT
, 2 },
4092 { 0x16, HDA_INPUT
, 3 },
4093 { 0x16, HDA_INPUT
, 4 },
4098 static void override_mic_boost(struct hda_codec
*codec
, hda_nid_t pin
,
4099 int offset
, int num_steps
, int step_size
)
4101 snd_hda_override_amp_caps(codec
, pin
, HDA_INPUT
,
4102 (offset
<< AC_AMPCAP_OFFSET_SHIFT
) |
4103 (num_steps
<< AC_AMPCAP_NUM_STEPS_SHIFT
) |
4104 (step_size
<< AC_AMPCAP_STEP_SIZE_SHIFT
) |
4105 (0 << AC_AMPCAP_MUTE_SHIFT
));
4108 static int patch_vt1708S(struct hda_codec
*codec
)
4110 struct via_spec
*spec
;
4113 /* create a codec specific record */
4114 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4120 /* automatic parse from the BIOS config */
4121 err
= vt1708S_parse_auto_config(codec
);
4126 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
4127 "from BIOS. Using genenic mode...\n");
4130 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_volume_init_verbs
;
4131 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_uniwill_init_verbs
;
4133 spec
->stream_name_analog
= "VT1708S Analog";
4134 spec
->stream_analog_playback
= &vt1708S_pcm_analog_playback
;
4135 spec
->stream_analog_capture
= &vt1708S_pcm_analog_capture
;
4137 spec
->stream_name_digital
= "VT1708S Digital";
4138 spec
->stream_digital_playback
= &vt1708S_pcm_digital_playback
;
4140 if (!spec
->adc_nids
&& spec
->input_mux
) {
4141 spec
->adc_nids
= vt1708S_adc_nids
;
4142 spec
->num_adc_nids
= ARRAY_SIZE(vt1708S_adc_nids
);
4143 get_mux_nids(codec
);
4144 override_mic_boost(codec
, 0x1a, 0, 3, 40);
4145 override_mic_boost(codec
, 0x1e, 0, 3, 40);
4146 spec
->mixers
[spec
->num_mixers
] = vt1708S_capture_mixer
;
4150 codec
->patch_ops
= via_patch_ops
;
4152 codec
->patch_ops
.init
= via_auto_init
;
4153 codec
->patch_ops
.unsol_event
= via_unsol_event
;
4154 #ifdef CONFIG_SND_HDA_POWER_SAVE
4155 spec
->loopback
.amplist
= vt1708S_loopbacks
;
4158 /* correct names for VT1708BCE */
4159 if (get_codec_type(codec
) == VT1708BCE
) {
4160 kfree(codec
->chip_name
);
4161 codec
->chip_name
= kstrdup("VT1708BCE", GFP_KERNEL
);
4162 snprintf(codec
->bus
->card
->mixername
,
4163 sizeof(codec
->bus
->card
->mixername
),
4164 "%s %s", codec
->vendor_name
, codec
->chip_name
);
4165 spec
->stream_name_analog
= "VT1708BCE Analog";
4166 spec
->stream_name_digital
= "VT1708BCE Digital";
4171 /* Patch for VT1702 */
4173 /* capture mixer elements */
4174 static struct snd_kcontrol_new vt1702_capture_mixer
[] = {
4175 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT
),
4176 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT
),
4177 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT
),
4178 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT
),
4179 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT
),
4180 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT
),
4181 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4184 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
4185 /* The multiple "Capture Source" controls confuse alsamixer
4186 * So call somewhat different..
4188 /* .name = "Capture Source", */
4189 .name
= "Input Source",
4191 .info
= via_mux_enum_info
,
4192 .get
= via_mux_enum_get
,
4193 .put
= via_mux_enum_put
,
4198 static struct hda_verb vt1702_volume_init_verbs
[] = {
4200 * Unmute ADC0-1 and set the default input to mic-in
4202 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4203 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4204 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4207 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4210 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4211 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4212 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
4213 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
4214 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
4215 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
4217 /* Setup default input of PW4 to MW0 */
4218 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x1},
4219 /* PW6 PW7 Output enable */
4220 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
4221 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
4229 static struct hda_verb vt1702_uniwill_init_verbs
[] = {
4230 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE
,
4231 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
4232 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4233 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4234 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4235 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4239 static struct hda_pcm_stream vt1702_pcm_analog_playback
= {
4243 .nid
= 0x10, /* NID to query formats and rates */
4245 .open
= via_playback_pcm_open
,
4246 .prepare
= via_playback_multi_pcm_prepare
,
4247 .cleanup
= via_playback_multi_pcm_cleanup
,
4248 .close
= via_pcm_open_close
4252 static struct hda_pcm_stream vt1702_pcm_analog_capture
= {
4256 .nid
= 0x12, /* NID to query formats and rates */
4258 .open
= via_pcm_open_close
,
4259 .prepare
= via_capture_pcm_prepare
,
4260 .cleanup
= via_capture_pcm_cleanup
,
4261 .close
= via_pcm_open_close
4265 static struct hda_pcm_stream vt1702_pcm_digital_playback
= {
4269 /* NID is set in via_build_pcms */
4271 .open
= via_dig_playback_pcm_open
,
4272 .close
= via_dig_playback_pcm_close
,
4273 .prepare
= via_dig_playback_pcm_prepare
,
4274 .cleanup
= via_dig_playback_pcm_cleanup
4278 /* fill in the dac_nids table from the parsed pin configuration */
4279 static int vt1702_auto_fill_dac_nids(struct via_spec
*spec
,
4280 const struct auto_pin_cfg
*cfg
)
4282 spec
->multiout
.num_dacs
= 1;
4283 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
4285 if (cfg
->line_out_pins
[0]) {
4286 /* config dac list */
4287 spec
->multiout
.dac_nids
[0] = 0x10;
4293 /* add playback controls from the parsed DAC table */
4294 static int vt1702_auto_create_line_out_ctls(struct via_spec
*spec
,
4295 const struct auto_pin_cfg
*cfg
)
4299 if (!cfg
->line_out_pins
[0])
4302 /* add control to mixer index 0 */
4303 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4304 "Master Front Playback Volume",
4305 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
4308 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4309 "Master Front Playback Switch",
4310 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
4315 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4316 "Front Playback Volume",
4317 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
));
4320 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4321 "Front Playback Switch",
4322 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT
));
4329 static int vt1702_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
4332 struct hda_input_mux
*imux
;
4333 static const char *texts
[] = { "ON", "OFF", NULL
};
4336 spec
->multiout
.hp_nid
= 0x1D;
4337 spec
->hp_independent_mode_index
= 0;
4339 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4340 "Headphone Playback Volume",
4341 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT
));
4345 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4346 "Headphone Playback Switch",
4347 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
4351 imux
= &spec
->private_imux
[1];
4353 /* for hp mode select */
4355 while (texts
[i
] != NULL
) {
4356 imux
->items
[imux
->num_items
].label
= texts
[i
];
4357 imux
->items
[imux
->num_items
].index
= i
;
4362 spec
->hp_mux
= &spec
->private_imux
[1];
4366 /* create playback/capture controls for input pins */
4367 static int vt1702_auto_create_analog_input_ctls(struct via_spec
*spec
,
4368 const struct auto_pin_cfg
*cfg
)
4370 static char *labels
[] = {
4371 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4373 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
4374 int i
, err
, idx
= 0;
4376 /* for internal loopback recording select */
4377 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
4378 imux
->items
[imux
->num_items
].index
= 3;
4381 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
4382 if (!cfg
->input_pins
[i
])
4385 switch (cfg
->input_pins
[i
]) {
4386 case 0x14: /* Mic */
4390 case 0x15: /* Line In */
4394 case 0x18: /* Front Mic */
4398 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x1A);
4401 imux
->items
[imux
->num_items
].label
= labels
[i
];
4402 imux
->items
[imux
->num_items
].index
= idx
-1;
4408 static int vt1702_parse_auto_config(struct hda_codec
*codec
)
4410 struct via_spec
*spec
= codec
->spec
;
4413 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
4416 err
= vt1702_auto_fill_dac_nids(spec
, &spec
->autocfg
);
4419 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
4420 return 0; /* can't find valid BIOS pin config */
4422 err
= vt1702_auto_create_line_out_ctls(spec
, &spec
->autocfg
);
4425 err
= vt1702_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
4428 /* limit AA path volume to 0 dB */
4429 snd_hda_override_amp_caps(codec
, 0x1A, HDA_INPUT
,
4430 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
4431 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
4432 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
4433 (1 << AC_AMPCAP_MUTE_SHIFT
));
4434 err
= vt1702_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
4438 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4440 fill_dig_outs(codec
);
4442 if (spec
->kctls
.list
)
4443 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
4445 spec
->input_mux
= &spec
->private_imux
[0];
4448 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
4453 #ifdef CONFIG_SND_HDA_POWER_SAVE
4454 static struct hda_amp_list vt1702_loopbacks
[] = {
4455 { 0x1A, HDA_INPUT
, 1 },
4456 { 0x1A, HDA_INPUT
, 2 },
4457 { 0x1A, HDA_INPUT
, 3 },
4458 { 0x1A, HDA_INPUT
, 4 },
4463 static int patch_vt1702(struct hda_codec
*codec
)
4465 struct via_spec
*spec
;
4468 /* create a codec specific record */
4469 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4475 /* automatic parse from the BIOS config */
4476 err
= vt1702_parse_auto_config(codec
);
4481 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
4482 "from BIOS. Using genenic mode...\n");
4485 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_volume_init_verbs
;
4486 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_uniwill_init_verbs
;
4488 spec
->stream_name_analog
= "VT1702 Analog";
4489 spec
->stream_analog_playback
= &vt1702_pcm_analog_playback
;
4490 spec
->stream_analog_capture
= &vt1702_pcm_analog_capture
;
4492 spec
->stream_name_digital
= "VT1702 Digital";
4493 spec
->stream_digital_playback
= &vt1702_pcm_digital_playback
;
4495 if (!spec
->adc_nids
&& spec
->input_mux
) {
4496 spec
->adc_nids
= vt1702_adc_nids
;
4497 spec
->num_adc_nids
= ARRAY_SIZE(vt1702_adc_nids
);
4498 get_mux_nids(codec
);
4499 spec
->mixers
[spec
->num_mixers
] = vt1702_capture_mixer
;
4503 codec
->patch_ops
= via_patch_ops
;
4505 codec
->patch_ops
.init
= via_auto_init
;
4506 codec
->patch_ops
.unsol_event
= via_unsol_event
;
4507 #ifdef CONFIG_SND_HDA_POWER_SAVE
4508 spec
->loopback
.amplist
= vt1702_loopbacks
;
4514 /* Patch for VT1718S */
4516 /* capture mixer elements */
4517 static struct snd_kcontrol_new vt1718S_capture_mixer
[] = {
4518 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT
),
4519 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT
),
4520 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT
),
4521 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT
),
4522 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT
),
4523 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4526 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
4527 /* The multiple "Capture Source" controls confuse alsamixer
4528 * So call somewhat different..
4530 .name
= "Input Source",
4532 .info
= via_mux_enum_info
,
4533 .get
= via_mux_enum_get
,
4534 .put
= via_mux_enum_put
,
4539 static struct hda_verb vt1718S_volume_init_verbs
[] = {
4541 * Unmute ADC0-1 and set the default input to mic-in
4543 {0x10, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4544 {0x11, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4547 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4550 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4551 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
4552 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4553 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
4554 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
4555 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(5)},
4557 /* Setup default input of Front HP to MW9 */
4558 {0x28, AC_VERB_SET_CONNECT_SEL
, 0x1},
4559 /* PW9 PW10 Output enable */
4560 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_OUT_EN
},
4561 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_OUT_EN
},
4562 /* PW11 Input enable */
4563 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_IN_EN
},
4564 /* Enable Boost Volume backdoor */
4566 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4567 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4568 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4569 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4570 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4571 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4572 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
4573 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4574 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4575 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
4576 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
4577 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4578 {0x34, AC_VERB_SET_CONNECT_SEL
, 0x2},
4579 {0x35, AC_VERB_SET_CONNECT_SEL
, 0x1},
4580 /* Unmute MW4's index 0 */
4581 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
4586 static struct hda_verb vt1718S_uniwill_init_verbs
[] = {
4587 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE
,
4588 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
4589 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4590 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4591 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4592 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4593 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4594 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4595 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
4599 static struct hda_pcm_stream vt1718S_pcm_analog_playback
= {
4603 .nid
= 0x8, /* NID to query formats and rates */
4605 .open
= via_playback_pcm_open
,
4606 .prepare
= via_playback_multi_pcm_prepare
,
4607 .cleanup
= via_playback_multi_pcm_cleanup
,
4608 .close
= via_pcm_open_close
,
4612 static struct hda_pcm_stream vt1718S_pcm_analog_capture
= {
4616 .nid
= 0x10, /* NID to query formats and rates */
4618 .open
= via_pcm_open_close
,
4619 .prepare
= via_capture_pcm_prepare
,
4620 .cleanup
= via_capture_pcm_cleanup
,
4621 .close
= via_pcm_open_close
,
4625 static struct hda_pcm_stream vt1718S_pcm_digital_playback
= {
4629 .rates
= SNDRV_PCM_RATE_48000
,
4630 /* NID is set in via_build_pcms */
4632 .open
= via_dig_playback_pcm_open
,
4633 .close
= via_dig_playback_pcm_close
,
4634 .prepare
= via_dig_playback_pcm_prepare
,
4635 .cleanup
= via_dig_playback_pcm_cleanup
4639 static struct hda_pcm_stream vt1718S_pcm_digital_capture
= {
4645 /* fill in the dac_nids table from the parsed pin configuration */
4646 static int vt1718S_auto_fill_dac_nids(struct via_spec
*spec
,
4647 const struct auto_pin_cfg
*cfg
)
4652 spec
->multiout
.num_dacs
= cfg
->line_outs
;
4654 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
4656 for (i
= 0; i
< 4; i
++) {
4657 nid
= cfg
->line_out_pins
[i
];
4659 /* config dac list */
4661 case AUTO_SEQ_FRONT
:
4662 spec
->multiout
.dac_nids
[i
] = 0x8;
4664 case AUTO_SEQ_CENLFE
:
4665 spec
->multiout
.dac_nids
[i
] = 0xa;
4667 case AUTO_SEQ_SURROUND
:
4668 spec
->multiout
.dac_nids
[i
] = 0x9;
4671 spec
->multiout
.dac_nids
[i
] = 0xb;
4680 /* add playback controls from the parsed DAC table */
4681 static int vt1718S_auto_create_multi_out_ctls(struct via_spec
*spec
,
4682 const struct auto_pin_cfg
*cfg
)
4685 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
4686 hda_nid_t nid_vols
[] = {0x8, 0x9, 0xa, 0xb};
4687 hda_nid_t nid_mutes
[] = {0x24, 0x25, 0x26, 0x27};
4688 hda_nid_t nid
, nid_vol
, nid_mute
= 0;
4691 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
4692 nid
= cfg
->line_out_pins
[i
];
4696 nid_vol
= nid_vols
[i
];
4697 nid_mute
= nid_mutes
[i
];
4699 if (i
== AUTO_SEQ_CENLFE
) {
4701 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4702 "Center Playback Volume",
4703 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
4707 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4708 "LFE Playback Volume",
4709 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
4713 err
= via_add_control(
4714 spec
, VIA_CTL_WIDGET_MUTE
,
4715 "Center Playback Switch",
4716 HDA_COMPOSE_AMP_VAL(nid_mute
, 1, 0,
4720 err
= via_add_control(
4721 spec
, VIA_CTL_WIDGET_MUTE
,
4722 "LFE Playback Switch",
4723 HDA_COMPOSE_AMP_VAL(nid_mute
, 2, 0,
4727 } else if (i
== AUTO_SEQ_FRONT
) {
4729 sprintf(name
, "%s Playback Volume", chname
[i
]);
4730 err
= via_add_control(
4731 spec
, VIA_CTL_WIDGET_VOL
, name
,
4732 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0, HDA_OUTPUT
));
4735 sprintf(name
, "%s Playback Switch", chname
[i
]);
4736 err
= via_add_control(
4737 spec
, VIA_CTL_WIDGET_MUTE
, name
,
4738 HDA_COMPOSE_AMP_VAL(nid_mute
, 3, 0,
4743 sprintf(name
, "%s Playback Volume", chname
[i
]);
4744 err
= via_add_control(
4745 spec
, VIA_CTL_WIDGET_VOL
, name
,
4746 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0, HDA_OUTPUT
));
4749 sprintf(name
, "%s Playback Switch", chname
[i
]);
4750 err
= via_add_control(
4751 spec
, VIA_CTL_WIDGET_MUTE
, name
,
4752 HDA_COMPOSE_AMP_VAL(nid_mute
, 3, 0,
4761 static int vt1718S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
4768 spec
->multiout
.hp_nid
= 0xc; /* AOW4 */
4769 spec
->hp_independent_mode_index
= 1;
4771 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
4772 "Headphone Playback Volume",
4773 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT
));
4777 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
4778 "Headphone Playback Switch",
4779 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
4783 create_hp_imux(spec
);
4787 /* create playback/capture controls for input pins */
4788 static int vt1718S_auto_create_analog_input_ctls(struct via_spec
*spec
,
4789 const struct auto_pin_cfg
*cfg
)
4791 static char *labels
[] = {
4792 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4794 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
4795 int i
, err
, idx
= 0;
4797 /* for internal loopback recording select */
4798 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
4799 imux
->items
[imux
->num_items
].index
= 5;
4802 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
4803 if (!cfg
->input_pins
[i
])
4806 switch (cfg
->input_pins
[i
]) {
4807 case 0x2b: /* Mic */
4811 case 0x2a: /* Line In */
4815 case 0x29: /* Front Mic */
4823 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x21);
4826 imux
->items
[imux
->num_items
].label
= labels
[i
];
4827 imux
->items
[imux
->num_items
].index
= idx
;
4833 static int vt1718S_parse_auto_config(struct hda_codec
*codec
)
4835 struct via_spec
*spec
= codec
->spec
;
4838 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
4842 err
= vt1718S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
4845 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
4846 return 0; /* can't find valid BIOS pin config */
4848 err
= vt1718S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
4851 err
= vt1718S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
4854 err
= vt1718S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
4858 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
4860 fill_dig_outs(codec
);
4862 if (spec
->autocfg
.dig_in_pin
&& codec
->vendor_id
== 0x11060428)
4863 spec
->dig_in_nid
= 0x13;
4865 if (spec
->kctls
.list
)
4866 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
4868 spec
->input_mux
= &spec
->private_imux
[0];
4871 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
4873 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
4878 #ifdef CONFIG_SND_HDA_POWER_SAVE
4879 static struct hda_amp_list vt1718S_loopbacks
[] = {
4880 { 0x21, HDA_INPUT
, 1 },
4881 { 0x21, HDA_INPUT
, 2 },
4882 { 0x21, HDA_INPUT
, 3 },
4883 { 0x21, HDA_INPUT
, 4 },
4888 static int patch_vt1718S(struct hda_codec
*codec
)
4890 struct via_spec
*spec
;
4893 /* create a codec specific record */
4894 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4900 /* automatic parse from the BIOS config */
4901 err
= vt1718S_parse_auto_config(codec
);
4906 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
4907 "from BIOS. Using genenic mode...\n");
4910 spec
->init_verbs
[spec
->num_iverbs
++] = vt1718S_volume_init_verbs
;
4911 spec
->init_verbs
[spec
->num_iverbs
++] = vt1718S_uniwill_init_verbs
;
4913 if (codec
->vendor_id
== 0x11060441)
4914 spec
->stream_name_analog
= "VT2020 Analog";
4915 else if (codec
->vendor_id
== 0x11064441)
4916 spec
->stream_name_analog
= "VT1828S Analog";
4918 spec
->stream_name_analog
= "VT1718S Analog";
4919 spec
->stream_analog_playback
= &vt1718S_pcm_analog_playback
;
4920 spec
->stream_analog_capture
= &vt1718S_pcm_analog_capture
;
4922 if (codec
->vendor_id
== 0x11060441)
4923 spec
->stream_name_digital
= "VT2020 Digital";
4924 else if (codec
->vendor_id
== 0x11064441)
4925 spec
->stream_name_digital
= "VT1828S Digital";
4927 spec
->stream_name_digital
= "VT1718S Digital";
4928 spec
->stream_digital_playback
= &vt1718S_pcm_digital_playback
;
4929 if (codec
->vendor_id
== 0x11060428 || codec
->vendor_id
== 0x11060441)
4930 spec
->stream_digital_capture
= &vt1718S_pcm_digital_capture
;
4932 if (!spec
->adc_nids
&& spec
->input_mux
) {
4933 spec
->adc_nids
= vt1718S_adc_nids
;
4934 spec
->num_adc_nids
= ARRAY_SIZE(vt1718S_adc_nids
);
4935 get_mux_nids(codec
);
4936 override_mic_boost(codec
, 0x2b, 0, 3, 40);
4937 override_mic_boost(codec
, 0x29, 0, 3, 40);
4938 spec
->mixers
[spec
->num_mixers
] = vt1718S_capture_mixer
;
4942 codec
->patch_ops
= via_patch_ops
;
4944 codec
->patch_ops
.init
= via_auto_init
;
4945 codec
->patch_ops
.unsol_event
= via_unsol_event
;
4947 #ifdef CONFIG_SND_HDA_POWER_SAVE
4948 spec
->loopback
.amplist
= vt1718S_loopbacks
;
4954 /* Patch for VT1716S */
4956 static int vt1716s_dmic_info(struct snd_kcontrol
*kcontrol
,
4957 struct snd_ctl_elem_info
*uinfo
)
4959 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
4961 uinfo
->value
.integer
.min
= 0;
4962 uinfo
->value
.integer
.max
= 1;
4966 static int vt1716s_dmic_get(struct snd_kcontrol
*kcontrol
,
4967 struct snd_ctl_elem_value
*ucontrol
)
4969 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4972 index
= snd_hda_codec_read(codec
, 0x26, 0,
4973 AC_VERB_GET_CONNECT_SEL
, 0);
4975 *ucontrol
->value
.integer
.value
= index
;
4980 static int vt1716s_dmic_put(struct snd_kcontrol
*kcontrol
,
4981 struct snd_ctl_elem_value
*ucontrol
)
4983 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4984 struct via_spec
*spec
= codec
->spec
;
4985 int index
= *ucontrol
->value
.integer
.value
;
4987 snd_hda_codec_write(codec
, 0x26, 0,
4988 AC_VERB_SET_CONNECT_SEL
, index
);
4989 spec
->dmic_enabled
= index
;
4990 set_jack_power_state(codec
);
4995 /* capture mixer elements */
4996 static struct snd_kcontrol_new vt1716S_capture_mixer
[] = {
4997 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
4998 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
4999 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
5000 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
5001 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT
),
5002 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5005 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
5006 .name
= "Input Source",
5008 .info
= via_mux_enum_info
,
5009 .get
= via_mux_enum_get
,
5010 .put
= via_mux_enum_put
,
5015 static struct snd_kcontrol_new vt1716s_dmic_mixer
[] = {
5016 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT
),
5018 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
5019 .name
= "Digital Mic Capture Switch",
5021 .info
= vt1716s_dmic_info
,
5022 .get
= vt1716s_dmic_get
,
5023 .put
= vt1716s_dmic_put
,
5029 /* mono-out mixer elements */
5030 static struct snd_kcontrol_new vt1716S_mono_out_mixer
[] = {
5031 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT
),
5035 static struct hda_verb vt1716S_volume_init_verbs
[] = {
5037 * Unmute ADC0-1 and set the default input to mic-in
5039 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5040 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5043 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5046 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5047 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
5048 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5049 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
5050 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
5051 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
5053 /* MUX Indices: Stereo Mixer = 5 */
5054 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x5},
5056 /* Setup default input of PW4 to MW0 */
5057 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
5059 /* Setup default input of SW1 as MW0 */
5060 {0x18, AC_VERB_SET_CONNECT_SEL
, 0x1},
5062 /* Setup default input of SW4 as AOW0 */
5063 {0x28, AC_VERB_SET_CONNECT_SEL
, 0x1},
5065 /* PW9 PW10 Output enable */
5066 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
5067 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
5069 /* Unmute SW1, PW12 */
5070 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5071 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_UNMUTE
},
5072 /* PW12 Output enable */
5073 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
5074 /* Enable Boost Volume backdoor */
5076 /* don't bybass mixer */
5078 /* Enable mono output */
5084 static struct hda_verb vt1716S_uniwill_init_verbs
[] = {
5085 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
5086 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
5087 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5088 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5089 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5090 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
,
5091 AC_USRSP_EN
| VIA_MONO_EVENT
| VIA_JACK_EVENT
},
5092 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5093 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5097 static struct hda_pcm_stream vt1716S_pcm_analog_playback
= {
5101 .nid
= 0x10, /* NID to query formats and rates */
5103 .open
= via_playback_pcm_open
,
5104 .prepare
= via_playback_multi_pcm_prepare
,
5105 .cleanup
= via_playback_multi_pcm_cleanup
,
5106 .close
= via_pcm_open_close
,
5110 static struct hda_pcm_stream vt1716S_pcm_analog_capture
= {
5114 .nid
= 0x13, /* NID to query formats and rates */
5116 .open
= via_pcm_open_close
,
5117 .prepare
= via_capture_pcm_prepare
,
5118 .cleanup
= via_capture_pcm_cleanup
,
5119 .close
= via_pcm_open_close
,
5123 static struct hda_pcm_stream vt1716S_pcm_digital_playback
= {
5127 .rates
= SNDRV_PCM_RATE_48000
,
5128 /* NID is set in via_build_pcms */
5130 .open
= via_dig_playback_pcm_open
,
5131 .close
= via_dig_playback_pcm_close
,
5132 .prepare
= via_dig_playback_pcm_prepare
,
5133 .cleanup
= via_dig_playback_pcm_cleanup
5137 /* fill in the dac_nids table from the parsed pin configuration */
5138 static int vt1716S_auto_fill_dac_nids(struct via_spec
*spec
,
5139 const struct auto_pin_cfg
*cfg
)
5143 spec
->multiout
.num_dacs
= cfg
->line_outs
;
5145 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
5147 for (i
= 0; i
< 3; i
++) {
5148 nid
= cfg
->line_out_pins
[i
];
5150 /* config dac list */
5152 case AUTO_SEQ_FRONT
:
5153 spec
->multiout
.dac_nids
[i
] = 0x10;
5155 case AUTO_SEQ_CENLFE
:
5156 spec
->multiout
.dac_nids
[i
] = 0x25;
5158 case AUTO_SEQ_SURROUND
:
5159 spec
->multiout
.dac_nids
[i
] = 0x11;
5168 /* add playback controls from the parsed DAC table */
5169 static int vt1716S_auto_create_multi_out_ctls(struct via_spec
*spec
,
5170 const struct auto_pin_cfg
*cfg
)
5173 static const char *chname
[3] = { "Front", "Surround", "C/LFE" };
5174 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x25};
5175 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x27};
5176 hda_nid_t nid
, nid_vol
, nid_mute
;
5179 for (i
= 0; i
<= AUTO_SEQ_CENLFE
; i
++) {
5180 nid
= cfg
->line_out_pins
[i
];
5185 nid_vol
= nid_vols
[i
];
5186 nid_mute
= nid_mutes
[i
];
5188 if (i
== AUTO_SEQ_CENLFE
) {
5189 err
= via_add_control(
5190 spec
, VIA_CTL_WIDGET_VOL
,
5191 "Center Playback Volume",
5192 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0, HDA_OUTPUT
));
5195 err
= via_add_control(
5196 spec
, VIA_CTL_WIDGET_VOL
,
5197 "LFE Playback Volume",
5198 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0, HDA_OUTPUT
));
5201 err
= via_add_control(
5202 spec
, VIA_CTL_WIDGET_MUTE
,
5203 "Center Playback Switch",
5204 HDA_COMPOSE_AMP_VAL(nid_mute
, 1, 0,
5208 err
= via_add_control(
5209 spec
, VIA_CTL_WIDGET_MUTE
,
5210 "LFE Playback Switch",
5211 HDA_COMPOSE_AMP_VAL(nid_mute
, 2, 0,
5215 } else if (i
== AUTO_SEQ_FRONT
) {
5217 err
= via_add_control(
5218 spec
, VIA_CTL_WIDGET_VOL
,
5219 "Master Front Playback Volume",
5220 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT
));
5223 err
= via_add_control(
5224 spec
, VIA_CTL_WIDGET_MUTE
,
5225 "Master Front Playback Switch",
5226 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT
));
5230 sprintf(name
, "%s Playback Volume", chname
[i
]);
5231 err
= via_add_control(
5232 spec
, VIA_CTL_WIDGET_VOL
, name
,
5233 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0, HDA_OUTPUT
));
5236 sprintf(name
, "%s Playback Switch", chname
[i
]);
5237 err
= via_add_control(
5238 spec
, VIA_CTL_WIDGET_MUTE
, name
,
5239 HDA_COMPOSE_AMP_VAL(nid_mute
, 3, 0,
5244 sprintf(name
, "%s Playback Volume", chname
[i
]);
5245 err
= via_add_control(
5246 spec
, VIA_CTL_WIDGET_VOL
, name
,
5247 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0, HDA_OUTPUT
));
5250 sprintf(name
, "%s Playback Switch", chname
[i
]);
5251 err
= via_add_control(
5252 spec
, VIA_CTL_WIDGET_MUTE
, name
,
5253 HDA_COMPOSE_AMP_VAL(nid_mute
, 3, 0,
5262 static int vt1716S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
5269 spec
->multiout
.hp_nid
= 0x25; /* AOW3 */
5270 spec
->hp_independent_mode_index
= 1;
5272 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
5273 "Headphone Playback Volume",
5274 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
5278 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
5279 "Headphone Playback Switch",
5280 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
5284 create_hp_imux(spec
);
5288 /* create playback/capture controls for input pins */
5289 static int vt1716S_auto_create_analog_input_ctls(struct via_spec
*spec
,
5290 const struct auto_pin_cfg
*cfg
)
5292 static char *labels
[] = {
5293 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5295 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
5296 int i
, err
, idx
= 0;
5298 /* for internal loopback recording select */
5299 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
5300 imux
->items
[imux
->num_items
].index
= 5;
5303 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
5304 if (!cfg
->input_pins
[i
])
5307 switch (cfg
->input_pins
[i
]) {
5308 case 0x1a: /* Mic */
5312 case 0x1b: /* Line In */
5316 case 0x1e: /* Front Mic */
5324 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
5327 imux
->items
[imux
->num_items
].label
= labels
[i
];
5328 imux
->items
[imux
->num_items
].index
= idx
-1;
5334 static int vt1716S_parse_auto_config(struct hda_codec
*codec
)
5336 struct via_spec
*spec
= codec
->spec
;
5339 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
5342 err
= vt1716S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
5345 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
5346 return 0; /* can't find valid BIOS pin config */
5348 err
= vt1716S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
5351 err
= vt1716S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
5354 err
= vt1716S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
5358 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
5360 fill_dig_outs(codec
);
5362 if (spec
->kctls
.list
)
5363 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
5365 spec
->input_mux
= &spec
->private_imux
[0];
5368 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
5370 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
5375 #ifdef CONFIG_SND_HDA_POWER_SAVE
5376 static struct hda_amp_list vt1716S_loopbacks
[] = {
5377 { 0x16, HDA_INPUT
, 1 },
5378 { 0x16, HDA_INPUT
, 2 },
5379 { 0x16, HDA_INPUT
, 3 },
5380 { 0x16, HDA_INPUT
, 4 },
5385 static int patch_vt1716S(struct hda_codec
*codec
)
5387 struct via_spec
*spec
;
5390 /* create a codec specific record */
5391 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5397 /* automatic parse from the BIOS config */
5398 err
= vt1716S_parse_auto_config(codec
);
5403 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
5404 "from BIOS. Using genenic mode...\n");
5407 spec
->init_verbs
[spec
->num_iverbs
++] = vt1716S_volume_init_verbs
;
5408 spec
->init_verbs
[spec
->num_iverbs
++] = vt1716S_uniwill_init_verbs
;
5410 spec
->stream_name_analog
= "VT1716S Analog";
5411 spec
->stream_analog_playback
= &vt1716S_pcm_analog_playback
;
5412 spec
->stream_analog_capture
= &vt1716S_pcm_analog_capture
;
5414 spec
->stream_name_digital
= "VT1716S Digital";
5415 spec
->stream_digital_playback
= &vt1716S_pcm_digital_playback
;
5417 if (!spec
->adc_nids
&& spec
->input_mux
) {
5418 spec
->adc_nids
= vt1716S_adc_nids
;
5419 spec
->num_adc_nids
= ARRAY_SIZE(vt1716S_adc_nids
);
5420 get_mux_nids(codec
);
5421 override_mic_boost(codec
, 0x1a, 0, 3, 40);
5422 override_mic_boost(codec
, 0x1e, 0, 3, 40);
5423 spec
->mixers
[spec
->num_mixers
] = vt1716S_capture_mixer
;
5427 spec
->mixers
[spec
->num_mixers
] = vt1716s_dmic_mixer
;
5430 spec
->mixers
[spec
->num_mixers
++] = vt1716S_mono_out_mixer
;
5432 codec
->patch_ops
= via_patch_ops
;
5434 codec
->patch_ops
.init
= via_auto_init
;
5435 codec
->patch_ops
.unsol_event
= via_unsol_event
;
5437 #ifdef CONFIG_SND_HDA_POWER_SAVE
5438 spec
->loopback
.amplist
= vt1716S_loopbacks
;
5446 /* capture mixer elements */
5447 static struct snd_kcontrol_new vt2002P_capture_mixer
[] = {
5448 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT
),
5449 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT
),
5450 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT
),
5451 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT
),
5452 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT
),
5453 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5456 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
5457 /* The multiple "Capture Source" controls confuse alsamixer
5458 * So call somewhat different..
5460 /* .name = "Capture Source", */
5461 .name
= "Input Source",
5463 .info
= via_mux_enum_info
,
5464 .get
= via_mux_enum_get
,
5465 .put
= via_mux_enum_put
,
5470 static struct hda_verb vt2002P_volume_init_verbs
[] = {
5472 * Unmute ADC0-1 and set the default input to mic-in
5474 {0x8, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5475 {0x9, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5478 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5481 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5482 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
5483 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5484 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
5485 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
5486 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
5488 /* MUX Indices: Mic = 0 */
5489 {0x1e, AC_VERB_SET_CONNECT_SEL
, 0},
5490 {0x1f, AC_VERB_SET_CONNECT_SEL
, 0},
5492 /* PW9 Output enable */
5493 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_OUT_EN
},
5495 /* Enable Boost Volume backdoor */
5498 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5499 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5500 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5501 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5502 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5503 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5504 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5505 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5506 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5508 /* set MUX0/1/4/8 = 0 (AOW0) */
5509 {0x34, AC_VERB_SET_CONNECT_SEL
, 0},
5510 {0x35, AC_VERB_SET_CONNECT_SEL
, 0},
5511 {0x37, AC_VERB_SET_CONNECT_SEL
, 0},
5512 {0x3b, AC_VERB_SET_CONNECT_SEL
, 0},
5514 /* set PW0 index=0 (MW0) */
5515 {0x24, AC_VERB_SET_CONNECT_SEL
, 0},
5517 /* Enable AOW0 to MW9 */
5523 static struct hda_verb vt2002P_uniwill_init_verbs
[] = {
5524 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE
,
5525 AC_USRSP_EN
| VIA_JACK_EVENT
| VIA_BIND_HP_EVENT
},
5526 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE
,
5527 AC_USRSP_EN
| VIA_JACK_EVENT
| VIA_BIND_HP_EVENT
},
5528 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5529 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5530 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5534 static struct hda_pcm_stream vt2002P_pcm_analog_playback
= {
5538 .nid
= 0x8, /* NID to query formats and rates */
5540 .open
= via_playback_pcm_open
,
5541 .prepare
= via_playback_multi_pcm_prepare
,
5542 .cleanup
= via_playback_multi_pcm_cleanup
,
5543 .close
= via_pcm_open_close
,
5547 static struct hda_pcm_stream vt2002P_pcm_analog_capture
= {
5551 .nid
= 0x10, /* NID to query formats and rates */
5553 .open
= via_pcm_open_close
,
5554 .prepare
= via_capture_pcm_prepare
,
5555 .cleanup
= via_capture_pcm_cleanup
,
5556 .close
= via_pcm_open_close
,
5560 static struct hda_pcm_stream vt2002P_pcm_digital_playback
= {
5564 .rates
= SNDRV_PCM_RATE_48000
,
5565 /* NID is set in via_build_pcms */
5567 .open
= via_dig_playback_pcm_open
,
5568 .close
= via_dig_playback_pcm_close
,
5569 .prepare
= via_dig_playback_pcm_prepare
,
5570 .cleanup
= via_dig_playback_pcm_cleanup
5574 /* fill in the dac_nids table from the parsed pin configuration */
5575 static int vt2002P_auto_fill_dac_nids(struct via_spec
*spec
,
5576 const struct auto_pin_cfg
*cfg
)
5578 spec
->multiout
.num_dacs
= 1;
5579 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
5580 if (cfg
->line_out_pins
[0])
5581 spec
->multiout
.dac_nids
[0] = 0x8;
5585 /* add playback controls from the parsed DAC table */
5586 static int vt2002P_auto_create_multi_out_ctls(struct via_spec
*spec
,
5587 const struct auto_pin_cfg
*cfg
)
5591 if (!cfg
->line_out_pins
[0])
5595 /* Line-Out: PortE */
5596 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
5597 "Master Front Playback Volume",
5598 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT
));
5601 err
= via_add_control(spec
, VIA_CTL_WIDGET_BIND_PIN_MUTE
,
5602 "Master Front Playback Switch",
5603 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT
));
5610 static int vt2002P_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
5617 spec
->multiout
.hp_nid
= 0x9;
5618 spec
->hp_independent_mode_index
= 1;
5620 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
5621 "Headphone Playback Volume",
5622 HDA_COMPOSE_AMP_VAL(
5623 spec
->multiout
.hp_nid
, 3, 0, HDA_OUTPUT
));
5627 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
5628 "Headphone Playback Switch",
5629 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
5633 create_hp_imux(spec
);
5637 /* create playback/capture controls for input pins */
5638 static int vt2002P_auto_create_analog_input_ctls(struct via_spec
*spec
,
5639 const struct auto_pin_cfg
*cfg
)
5641 static char *labels
[] = {
5642 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5644 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
5645 int i
, err
, idx
= 0;
5647 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
5648 if (!cfg
->input_pins
[i
])
5651 switch (cfg
->input_pins
[i
]) {
5652 case 0x2b: /* Mic */
5656 case 0x2a: /* Line In */
5660 case 0x29: /* Front Mic */
5664 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x21);
5667 imux
->items
[imux
->num_items
].label
= labels
[i
];
5668 imux
->items
[imux
->num_items
].index
= idx
;
5672 /* build volume/mute control of loopback */
5673 err
= via_new_analog_input(spec
, "Stereo Mixer", 3, 0x21);
5677 /* for internal loopback recording select */
5678 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
5679 imux
->items
[imux
->num_items
].index
= 3;
5682 /* for digital mic select */
5683 imux
->items
[imux
->num_items
].label
= "Digital Mic";
5684 imux
->items
[imux
->num_items
].index
= 4;
5690 static int vt2002P_parse_auto_config(struct hda_codec
*codec
)
5692 struct via_spec
*spec
= codec
->spec
;
5696 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
5700 err
= vt2002P_auto_fill_dac_nids(spec
, &spec
->autocfg
);
5704 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
5705 return 0; /* can't find valid BIOS pin config */
5707 err
= vt2002P_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
5710 err
= vt2002P_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
5713 err
= vt2002P_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
5717 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
5719 fill_dig_outs(codec
);
5721 if (spec
->kctls
.list
)
5722 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
5724 spec
->input_mux
= &spec
->private_imux
[0];
5727 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
5732 #ifdef CONFIG_SND_HDA_POWER_SAVE
5733 static struct hda_amp_list vt2002P_loopbacks
[] = {
5734 { 0x21, HDA_INPUT
, 0 },
5735 { 0x21, HDA_INPUT
, 1 },
5736 { 0x21, HDA_INPUT
, 2 },
5742 /* patch for vt2002P */
5743 static int patch_vt2002P(struct hda_codec
*codec
)
5745 struct via_spec
*spec
;
5748 /* create a codec specific record */
5749 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5755 /* automatic parse from the BIOS config */
5756 err
= vt2002P_parse_auto_config(codec
);
5761 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
5762 "from BIOS. Using genenic mode...\n");
5765 spec
->init_verbs
[spec
->num_iverbs
++] = vt2002P_volume_init_verbs
;
5766 spec
->init_verbs
[spec
->num_iverbs
++] = vt2002P_uniwill_init_verbs
;
5768 spec
->stream_name_analog
= "VT2002P Analog";
5769 spec
->stream_analog_playback
= &vt2002P_pcm_analog_playback
;
5770 spec
->stream_analog_capture
= &vt2002P_pcm_analog_capture
;
5772 spec
->stream_name_digital
= "VT2002P Digital";
5773 spec
->stream_digital_playback
= &vt2002P_pcm_digital_playback
;
5775 if (!spec
->adc_nids
&& spec
->input_mux
) {
5776 spec
->adc_nids
= vt2002P_adc_nids
;
5777 spec
->num_adc_nids
= ARRAY_SIZE(vt2002P_adc_nids
);
5778 get_mux_nids(codec
);
5779 override_mic_boost(codec
, 0x2b, 0, 3, 40);
5780 override_mic_boost(codec
, 0x29, 0, 3, 40);
5781 spec
->mixers
[spec
->num_mixers
] = vt2002P_capture_mixer
;
5785 codec
->patch_ops
= via_patch_ops
;
5787 codec
->patch_ops
.init
= via_auto_init
;
5788 codec
->patch_ops
.unsol_event
= via_unsol_event
;
5790 #ifdef CONFIG_SND_HDA_POWER_SAVE
5791 spec
->loopback
.amplist
= vt2002P_loopbacks
;
5799 /* capture mixer elements */
5800 static struct snd_kcontrol_new vt1812_capture_mixer
[] = {
5801 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT
),
5802 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT
),
5803 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT
),
5804 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT
),
5805 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT
),
5806 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5809 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
5810 /* The multiple "Capture Source" controls confuse alsamixer
5811 * So call somewhat different..
5813 .name
= "Input Source",
5815 .info
= via_mux_enum_info
,
5816 .get
= via_mux_enum_get
,
5817 .put
= via_mux_enum_put
,
5822 static struct hda_verb vt1812_volume_init_verbs
[] = {
5824 * Unmute ADC0-1 and set the default input to mic-in
5826 {0x8, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5827 {0x9, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5830 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5833 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5834 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(0)},
5835 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(1)},
5836 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(2)},
5837 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(3)},
5838 {0x21, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
5840 /* MUX Indices: Mic = 0 */
5841 {0x1e, AC_VERB_SET_CONNECT_SEL
, 0},
5842 {0x1f, AC_VERB_SET_CONNECT_SEL
, 0},
5844 /* PW9 Output enable */
5845 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL
, AC_PINCTL_OUT_EN
},
5847 /* Enable Boost Volume backdoor */
5850 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5851 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5852 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5853 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5854 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5855 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
5856 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5857 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5858 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5859 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5860 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
5862 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5863 {0x34, AC_VERB_SET_CONNECT_SEL
, 0},
5864 {0x35, AC_VERB_SET_CONNECT_SEL
, 0},
5865 {0x38, AC_VERB_SET_CONNECT_SEL
, 0},
5866 {0x3c, AC_VERB_SET_CONNECT_SEL
, 0},
5867 {0x3d, AC_VERB_SET_CONNECT_SEL
, 0},
5869 /* Enable AOW0 to MW9 */
5875 static struct hda_verb vt1812_uniwill_init_verbs
[] = {
5876 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE
,
5877 AC_USRSP_EN
| VIA_JACK_EVENT
| VIA_BIND_HP_EVENT
},
5878 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5879 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE
,
5880 AC_USRSP_EN
| VIA_JACK_EVENT
| VIA_BIND_HP_EVENT
},
5881 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5882 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5883 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
5887 static struct hda_pcm_stream vt1812_pcm_analog_playback
= {
5891 .nid
= 0x8, /* NID to query formats and rates */
5893 .open
= via_playback_pcm_open
,
5894 .prepare
= via_playback_multi_pcm_prepare
,
5895 .cleanup
= via_playback_multi_pcm_cleanup
,
5896 .close
= via_pcm_open_close
,
5900 static struct hda_pcm_stream vt1812_pcm_analog_capture
= {
5904 .nid
= 0x10, /* NID to query formats and rates */
5906 .open
= via_pcm_open_close
,
5907 .prepare
= via_capture_pcm_prepare
,
5908 .cleanup
= via_capture_pcm_cleanup
,
5909 .close
= via_pcm_open_close
,
5913 static struct hda_pcm_stream vt1812_pcm_digital_playback
= {
5917 .rates
= SNDRV_PCM_RATE_48000
,
5918 /* NID is set in via_build_pcms */
5920 .open
= via_dig_playback_pcm_open
,
5921 .close
= via_dig_playback_pcm_close
,
5922 .prepare
= via_dig_playback_pcm_prepare
,
5923 .cleanup
= via_dig_playback_pcm_cleanup
5926 /* fill in the dac_nids table from the parsed pin configuration */
5927 static int vt1812_auto_fill_dac_nids(struct via_spec
*spec
,
5928 const struct auto_pin_cfg
*cfg
)
5930 spec
->multiout
.num_dacs
= 1;
5931 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
5932 if (cfg
->line_out_pins
[0])
5933 spec
->multiout
.dac_nids
[0] = 0x8;
5938 /* add playback controls from the parsed DAC table */
5939 static int vt1812_auto_create_multi_out_ctls(struct via_spec
*spec
,
5940 const struct auto_pin_cfg
*cfg
)
5944 if (!cfg
->line_out_pins
[0])
5947 /* Line-Out: PortE */
5948 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
5949 "Master Front Playback Volume",
5950 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT
));
5953 err
= via_add_control(spec
, VIA_CTL_WIDGET_BIND_PIN_MUTE
,
5954 "Master Front Playback Switch",
5955 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT
));
5962 static int vt1812_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
5969 spec
->multiout
.hp_nid
= 0x9;
5970 spec
->hp_independent_mode_index
= 1;
5973 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
5974 "Headphone Playback Volume",
5975 HDA_COMPOSE_AMP_VAL(
5976 spec
->multiout
.hp_nid
, 3, 0, HDA_OUTPUT
));
5980 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
5981 "Headphone Playback Switch",
5982 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
5986 create_hp_imux(spec
);
5990 /* create playback/capture controls for input pins */
5991 static int vt1812_auto_create_analog_input_ctls(struct via_spec
*spec
,
5992 const struct auto_pin_cfg
*cfg
)
5994 static char *labels
[] = {
5995 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5997 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
5998 int i
, err
, idx
= 0;
6000 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
6001 if (!cfg
->input_pins
[i
])
6004 switch (cfg
->input_pins
[i
]) {
6005 case 0x2b: /* Mic */
6009 case 0x2a: /* Line In */
6013 case 0x29: /* Front Mic */
6017 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x21);
6020 imux
->items
[imux
->num_items
].label
= labels
[i
];
6021 imux
->items
[imux
->num_items
].index
= idx
;
6024 /* build volume/mute control of loopback */
6025 err
= via_new_analog_input(spec
, "Stereo Mixer", 5, 0x21);
6029 /* for internal loopback recording select */
6030 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
6031 imux
->items
[imux
->num_items
].index
= 5;
6034 /* for digital mic select */
6035 imux
->items
[imux
->num_items
].label
= "Digital Mic";
6036 imux
->items
[imux
->num_items
].index
= 6;
6042 static int vt1812_parse_auto_config(struct hda_codec
*codec
)
6044 struct via_spec
*spec
= codec
->spec
;
6048 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
6051 fill_dig_outs(codec
);
6052 err
= vt1812_auto_fill_dac_nids(spec
, &spec
->autocfg
);
6056 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_outs
)
6057 return 0; /* can't find valid BIOS pin config */
6059 err
= vt1812_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
6062 err
= vt1812_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
6065 err
= vt1812_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
6069 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
6071 fill_dig_outs(codec
);
6073 if (spec
->kctls
.list
)
6074 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
6076 spec
->input_mux
= &spec
->private_imux
[0];
6079 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
6084 #ifdef CONFIG_SND_HDA_POWER_SAVE
6085 static struct hda_amp_list vt1812_loopbacks
[] = {
6086 { 0x21, HDA_INPUT
, 0 },
6087 { 0x21, HDA_INPUT
, 1 },
6088 { 0x21, HDA_INPUT
, 2 },
6094 /* patch for vt1812 */
6095 static int patch_vt1812(struct hda_codec
*codec
)
6097 struct via_spec
*spec
;
6100 /* create a codec specific record */
6101 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
6107 /* automatic parse from the BIOS config */
6108 err
= vt1812_parse_auto_config(codec
);
6113 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
6114 "from BIOS. Using genenic mode...\n");
6118 spec
->init_verbs
[spec
->num_iverbs
++] = vt1812_volume_init_verbs
;
6119 spec
->init_verbs
[spec
->num_iverbs
++] = vt1812_uniwill_init_verbs
;
6121 spec
->stream_name_analog
= "VT1812 Analog";
6122 spec
->stream_analog_playback
= &vt1812_pcm_analog_playback
;
6123 spec
->stream_analog_capture
= &vt1812_pcm_analog_capture
;
6125 spec
->stream_name_digital
= "VT1812 Digital";
6126 spec
->stream_digital_playback
= &vt1812_pcm_digital_playback
;
6129 if (!spec
->adc_nids
&& spec
->input_mux
) {
6130 spec
->adc_nids
= vt1812_adc_nids
;
6131 spec
->num_adc_nids
= ARRAY_SIZE(vt1812_adc_nids
);
6132 get_mux_nids(codec
);
6133 override_mic_boost(codec
, 0x2b, 0, 3, 40);
6134 override_mic_boost(codec
, 0x29, 0, 3, 40);
6135 spec
->mixers
[spec
->num_mixers
] = vt1812_capture_mixer
;
6139 codec
->patch_ops
= via_patch_ops
;
6141 codec
->patch_ops
.init
= via_auto_init
;
6142 codec
->patch_ops
.unsol_event
= via_unsol_event
;
6144 #ifdef CONFIG_SND_HDA_POWER_SAVE
6145 spec
->loopback
.amplist
= vt1812_loopbacks
;
6154 static struct hda_codec_preset snd_hda_preset_via
[] = {
6155 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
6156 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
6157 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
6158 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
6159 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
6160 .patch
= patch_vt1709_10ch
},
6161 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
6162 .patch
= patch_vt1709_10ch
},
6163 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
6164 .patch
= patch_vt1709_10ch
},
6165 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
6166 .patch
= patch_vt1709_10ch
},
6167 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
6168 .patch
= patch_vt1709_6ch
},
6169 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
6170 .patch
= patch_vt1709_6ch
},
6171 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
6172 .patch
= patch_vt1709_6ch
},
6173 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
6174 .patch
= patch_vt1709_6ch
},
6175 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
6176 .patch
= patch_vt1708B_8ch
},
6177 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
6178 .patch
= patch_vt1708B_8ch
},
6179 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
6180 .patch
= patch_vt1708B_8ch
},
6181 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
6182 .patch
= patch_vt1708B_8ch
},
6183 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
6184 .patch
= patch_vt1708B_4ch
},
6185 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
6186 .patch
= patch_vt1708B_4ch
},
6187 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
6188 .patch
= patch_vt1708B_4ch
},
6189 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
6190 .patch
= patch_vt1708B_4ch
},
6191 { .id
= 0x11060397, .name
= "VT1708S",
6192 .patch
= patch_vt1708S
},
6193 { .id
= 0x11061397, .name
= "VT1708S",
6194 .patch
= patch_vt1708S
},
6195 { .id
= 0x11062397, .name
= "VT1708S",
6196 .patch
= patch_vt1708S
},
6197 { .id
= 0x11063397, .name
= "VT1708S",
6198 .patch
= patch_vt1708S
},
6199 { .id
= 0x11064397, .name
= "VT1708S",
6200 .patch
= patch_vt1708S
},
6201 { .id
= 0x11065397, .name
= "VT1708S",
6202 .patch
= patch_vt1708S
},
6203 { .id
= 0x11066397, .name
= "VT1708S",
6204 .patch
= patch_vt1708S
},
6205 { .id
= 0x11067397, .name
= "VT1708S",
6206 .patch
= patch_vt1708S
},
6207 { .id
= 0x11060398, .name
= "VT1702",
6208 .patch
= patch_vt1702
},
6209 { .id
= 0x11061398, .name
= "VT1702",
6210 .patch
= patch_vt1702
},
6211 { .id
= 0x11062398, .name
= "VT1702",
6212 .patch
= patch_vt1702
},
6213 { .id
= 0x11063398, .name
= "VT1702",
6214 .patch
= patch_vt1702
},
6215 { .id
= 0x11064398, .name
= "VT1702",
6216 .patch
= patch_vt1702
},
6217 { .id
= 0x11065398, .name
= "VT1702",
6218 .patch
= patch_vt1702
},
6219 { .id
= 0x11066398, .name
= "VT1702",
6220 .patch
= patch_vt1702
},
6221 { .id
= 0x11067398, .name
= "VT1702",
6222 .patch
= patch_vt1702
},
6223 { .id
= 0x11060428, .name
= "VT1718S",
6224 .patch
= patch_vt1718S
},
6225 { .id
= 0x11064428, .name
= "VT1718S",
6226 .patch
= patch_vt1718S
},
6227 { .id
= 0x11060441, .name
= "VT2020",
6228 .patch
= patch_vt1718S
},
6229 { .id
= 0x11064441, .name
= "VT1828S",
6230 .patch
= patch_vt1718S
},
6231 { .id
= 0x11060433, .name
= "VT1716S",
6232 .patch
= patch_vt1716S
},
6233 { .id
= 0x1106a721, .name
= "VT1716S",
6234 .patch
= patch_vt1716S
},
6235 { .id
= 0x11060438, .name
= "VT2002P", .patch
= patch_vt2002P
},
6236 { .id
= 0x11064438, .name
= "VT2002P", .patch
= patch_vt2002P
},
6237 { .id
= 0x11060448, .name
= "VT1812", .patch
= patch_vt1812
},
6241 MODULE_ALIAS("snd-hda-codec-id:1106*");
6243 static struct hda_codec_preset_list via_list
= {
6244 .preset
= snd_hda_preset_via
,
6245 .owner
= THIS_MODULE
,
6248 MODULE_LICENSE("GPL");
6249 MODULE_DESCRIPTION("VIA HD-audio codec");
6251 static int __init
patch_via_init(void)
6253 return snd_hda_add_codec_preset(&via_list
);
6256 static void __exit
patch_via_exit(void)
6258 snd_hda_delete_codec_preset(&via_list
);
6261 module_init(patch_via_init
)
6262 module_exit(patch_via_exit
)