2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec
6 * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com>
7 * Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
40 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 #include <linux/init.h>
44 #include <linux/delay.h>
45 #include <linux/slab.h>
46 #include <sound/core.h>
47 #include <sound/asoundef.h>
48 #include "hda_codec.h"
49 #include "hda_local.h"
52 #define AMP_VAL_IDX_SHIFT 19
53 #define AMP_VAL_IDX_MASK (0x0f<<19)
56 #define VT1708_HP_NID 0x13
57 #define VT1708_DIGOUT_NID 0x14
58 #define VT1708_DIGIN_NID 0x16
59 #define VT1708_DIGIN_PIN 0x26
60 #define VT1708_HP_PIN_NID 0x20
61 #define VT1708_CD_PIN_NID 0x24
63 #define VT1709_HP_DAC_NID 0x28
64 #define VT1709_DIGOUT_NID 0x13
65 #define VT1709_DIGIN_NID 0x17
66 #define VT1709_DIGIN_PIN 0x25
68 #define VT1708B_HP_NID 0x25
69 #define VT1708B_DIGOUT_NID 0x12
70 #define VT1708B_DIGIN_NID 0x15
71 #define VT1708B_DIGIN_PIN 0x21
73 #define VT1708S_HP_NID 0x25
74 #define VT1708S_DIGOUT_NID 0x12
76 #define VT1702_HP_NID 0x17
77 #define VT1702_DIGOUT_NID 0x11
92 static enum VIA_HDA_CODEC
get_codec_type(struct hda_codec
*codec
)
94 u32 vendor_id
= codec
->vendor_id
;
95 u16 ven_id
= vendor_id
>> 16;
96 u16 dev_id
= vendor_id
& 0xffff;
97 enum VIA_HDA_CODEC codec_type
;
100 if (ven_id
!= 0x1106)
101 codec_type
= UNKNOWN
;
102 else if (dev_id
>= 0x1708 && dev_id
<= 0x170b)
104 else if (dev_id
>= 0xe710 && dev_id
<= 0xe713)
105 codec_type
= VT1709_10CH
;
106 else if (dev_id
>= 0xe714 && dev_id
<= 0xe717)
107 codec_type
= VT1709_6CH
;
108 else if (dev_id
>= 0xe720 && dev_id
<= 0xe723) {
109 codec_type
= VT1708B_8CH
;
110 if (snd_hda_param_read(codec
, 0x16, AC_PAR_CONNLIST_LEN
) == 0x7)
111 codec_type
= VT1708BCE
;
112 } else if (dev_id
>= 0xe724 && dev_id
<= 0xe727)
113 codec_type
= VT1708B_4CH
;
114 else if ((dev_id
& 0xfff) == 0x397
115 && (dev_id
>> 12) < 8)
116 codec_type
= VT1708S
;
117 else if ((dev_id
& 0xfff) == 0x398
118 && (dev_id
>> 12) < 8)
121 codec_type
= UNKNOWN
;
125 #define VIA_HP_EVENT 0x01
126 #define VIA_GPIO_EVENT 0x02
127 #define VIA_JACK_EVENT 0x04
132 VIA_CTL_WIDGET_ANALOG_MUTE
,
142 /* Some VT1708S based boards gets the micboost setting wrong, so we have
143 * to apply some brute-force and re-write the TLV's by software. */
144 static int mic_boost_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
145 unsigned int size
, unsigned int __user
*_tlv
)
147 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
148 hda_nid_t nid
= get_amp_nid(kcontrol
);
150 if (get_codec_type(codec
) == VT1708S
151 && (nid
== 0x1a || nid
== 0x1e)) {
152 if (size
< 4 * sizeof(unsigned int))
154 if (put_user(1, _tlv
)) /* SNDRV_CTL_TLVT_DB_SCALE */
156 if (put_user(2 * sizeof(unsigned int), _tlv
+ 1))
158 if (put_user(0, _tlv
+ 2)) /* offset = 0 */
160 if (put_user(1000, _tlv
+ 3)) /* step size = 10 dB */
166 static int mic_boost_volume_info(struct snd_kcontrol
*kcontrol
,
167 struct snd_ctl_elem_info
*uinfo
)
169 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
170 hda_nid_t nid
= get_amp_nid(kcontrol
);
172 if (get_codec_type(codec
) == VT1708S
173 && (nid
== 0x1a || nid
== 0x1e)) {
174 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
176 uinfo
->value
.integer
.min
= 0;
177 uinfo
->value
.integer
.max
= 3;
182 static void analog_low_current_mode(struct hda_codec
*codec
, int stream_idle
);
183 static void set_jack_power_state(struct hda_codec
*codec
);
185 static int analog_input_switch_put(struct snd_kcontrol
*kcontrol
,
186 struct snd_ctl_elem_value
*ucontrol
)
188 int change
= snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
189 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
191 set_jack_power_state(codec
);
192 analog_low_current_mode(snd_kcontrol_chip(kcontrol
), -1);
196 /* modify .put = snd_hda_mixer_amp_switch_put */
197 #define ANALOG_INPUT_MUTE \
198 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
201 .info = snd_hda_mixer_amp_switch_info, \
202 .get = snd_hda_mixer_amp_switch_get, \
203 .put = analog_input_switch_put, \
204 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
206 static struct snd_kcontrol_new vt1708_control_templates
[] = {
207 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
208 HDA_CODEC_MUTE(NULL
, 0, 0, 0),
214 /* codec parameterization */
215 struct snd_kcontrol_new
*mixers
[4];
216 unsigned int num_mixers
;
218 struct hda_verb
*init_verbs
[5];
219 unsigned int num_iverbs
;
221 char *stream_name_analog
;
222 struct hda_pcm_stream
*stream_analog_playback
;
223 struct hda_pcm_stream
*stream_analog_capture
;
225 char *stream_name_digital
;
226 struct hda_pcm_stream
*stream_digital_playback
;
227 struct hda_pcm_stream
*stream_digital_capture
;
230 struct hda_multi_out multiout
;
231 hda_nid_t slave_dig_outs
[2];
234 unsigned int num_adc_nids
;
236 hda_nid_t mux_nids
[3];
237 hda_nid_t dig_in_nid
;
238 hda_nid_t dig_in_pin
;
241 const struct hda_input_mux
*input_mux
;
242 unsigned int cur_mux
[3];
244 /* PCM information */
245 struct hda_pcm pcm_rec
[3];
247 /* dynamic controls, init_verbs and input_mux */
248 struct auto_pin_cfg autocfg
;
249 struct snd_array kctls
;
250 struct hda_input_mux private_imux
[2];
251 hda_nid_t private_dac_nids
[AUTO_CFG_MAX_OUTS
];
254 const struct hda_input_mux
*hp_mux
;
255 unsigned int hp_independent_mode
;
256 unsigned int hp_independent_mode_index
;
257 unsigned int smart51_enabled
;
259 enum VIA_HDA_CODEC codec_type
;
261 #ifdef CONFIG_SND_HDA_POWER_SAVE
262 struct hda_loopback_check loopback
;
266 static hda_nid_t vt1708_adc_nids
[2] = {
271 static hda_nid_t vt1709_adc_nids
[3] = {
276 static hda_nid_t vt1708B_adc_nids
[2] = {
281 static hda_nid_t vt1708S_adc_nids
[2] = {
286 static hda_nid_t vt1702_adc_nids
[3] = {
291 /* add dynamic controls */
292 static int via_add_control(struct via_spec
*spec
, int type
, const char *name
,
295 struct snd_kcontrol_new
*knew
;
297 snd_array_init(&spec
->kctls
, sizeof(*knew
), 32);
298 knew
= snd_array_new(&spec
->kctls
);
301 *knew
= vt1708_control_templates
[type
];
302 knew
->name
= kstrdup(name
, GFP_KERNEL
);
305 knew
->private_value
= val
;
309 static void via_free_kctls(struct hda_codec
*codec
)
311 struct via_spec
*spec
= codec
->spec
;
313 if (spec
->kctls
.list
) {
314 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
316 for (i
= 0; i
< spec
->kctls
.used
; i
++)
319 snd_array_free(&spec
->kctls
);
322 /* create input playback/capture controls for the given pin */
323 static int via_new_analog_input(struct via_spec
*spec
, const char *ctlname
,
324 int idx
, int mix_nid
)
329 sprintf(name
, "%s Playback Volume", ctlname
);
330 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
331 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
334 sprintf(name
, "%s Playback Switch", ctlname
);
335 err
= via_add_control(spec
, VIA_CTL_WIDGET_ANALOG_MUTE
, name
,
336 HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
));
342 static void via_auto_set_output_and_unmute(struct hda_codec
*codec
,
343 hda_nid_t nid
, int pin_type
,
347 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_PIN_WIDGET_CONTROL
,
349 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
351 if (snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_EAPD
)
352 snd_hda_codec_write(codec
, nid
, 0,
353 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
357 static void via_auto_init_multi_out(struct hda_codec
*codec
)
359 struct via_spec
*spec
= codec
->spec
;
362 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
363 hda_nid_t nid
= spec
->autocfg
.line_out_pins
[i
];
365 via_auto_set_output_and_unmute(codec
, nid
, PIN_OUT
, i
);
369 static void via_auto_init_hp_out(struct hda_codec
*codec
)
371 struct via_spec
*spec
= codec
->spec
;
374 pin
= spec
->autocfg
.hp_pins
[0];
375 if (pin
) /* connect to front */
376 via_auto_set_output_and_unmute(codec
, pin
, PIN_HP
, 0);
379 static void via_auto_init_analog_input(struct hda_codec
*codec
)
381 struct via_spec
*spec
= codec
->spec
;
384 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
385 hda_nid_t nid
= spec
->autocfg
.input_pins
[i
];
387 snd_hda_codec_write(codec
, nid
, 0,
388 AC_VERB_SET_PIN_WIDGET_CONTROL
,
389 (i
<= AUTO_PIN_FRONT_MIC
?
390 PIN_VREF50
: PIN_IN
));
395 static int is_smart51_pins(struct via_spec
*spec
, hda_nid_t pin
);
397 static void set_pin_power_state(struct hda_codec
*codec
, hda_nid_t nid
,
398 unsigned int *affected_parm
)
401 unsigned def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
402 unsigned no_presence
= (def_conf
& AC_DEFCFG_MISC
)
403 >> AC_DEFCFG_MISC_SHIFT
404 & AC_DEFCFG_MISC_NO_PRESENCE
; /* do not support pin sense */
405 unsigned present
= snd_hda_codec_read(codec
, nid
, 0,
406 AC_VERB_GET_PIN_SENSE
, 0) >> 31;
407 struct via_spec
*spec
= codec
->spec
;
408 if ((spec
->smart51_enabled
&& is_smart51_pins(spec
, nid
))
409 || ((no_presence
|| present
)
410 && get_defcfg_connect(def_conf
) != AC_JACK_PORT_NONE
)) {
411 *affected_parm
= AC_PWRST_D0
; /* if it's connected */
416 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_POWER_STATE
, parm
);
419 static void set_jack_power_state(struct hda_codec
*codec
)
421 struct via_spec
*spec
= codec
->spec
;
425 if (spec
->codec_type
== VT1702
) {
426 imux_is_smixer
= snd_hda_codec_read(
427 codec
, 0x13, 0, AC_VERB_GET_CONNECT_SEL
, 0x00) == 3;
429 /* PW 1/2/5 (14h/15h/18h) */
431 set_pin_power_state(codec
, 0x14, &parm
);
432 set_pin_power_state(codec
, 0x15, &parm
);
433 set_pin_power_state(codec
, 0x18, &parm
);
435 parm
= AC_PWRST_D0
; /* SW0 = stereo mixer (idx 3) */
436 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
437 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
439 snd_hda_codec_write(codec
, 0x12, 0, AC_VERB_SET_POWER_STATE
,
441 snd_hda_codec_write(codec
, 0x1f, 0, AC_VERB_SET_POWER_STATE
,
443 snd_hda_codec_write(codec
, 0x20, 0, AC_VERB_SET_POWER_STATE
,
447 /* PW 3/4 (16h/17h) */
449 set_pin_power_state(codec
, 0x16, &parm
);
450 set_pin_power_state(codec
, 0x17, &parm
);
451 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
452 snd_hda_codec_write(codec
, 0x1a, 0, AC_VERB_SET_POWER_STATE
,
453 imux_is_smixer
? AC_PWRST_D0
: parm
);
454 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
456 snd_hda_codec_write(codec
, 0x1d, 0, AC_VERB_SET_POWER_STATE
,
458 } else if (spec
->codec_type
== VT1708B_8CH
459 || spec
->codec_type
== VT1708B_4CH
460 || spec
->codec_type
== VT1708S
) {
461 /* SW0 (17h) = stereo mixer */
462 int is_8ch
= spec
->codec_type
!= VT1708B_4CH
;
463 imux_is_smixer
= snd_hda_codec_read(
464 codec
, 0x17, 0, AC_VERB_GET_CONNECT_SEL
, 0x00)
465 == ((spec
->codec_type
== VT1708S
) ? 5 : 0);
467 /* PW 1/2/5 (1ah/1bh/1eh) */
469 set_pin_power_state(codec
, 0x1a, &parm
);
470 set_pin_power_state(codec
, 0x1b, &parm
);
471 set_pin_power_state(codec
, 0x1e, &parm
);
474 /* SW0 (17h), AIW 0/1 (13h/14h) */
475 snd_hda_codec_write(codec
, 0x17, 0, AC_VERB_SET_POWER_STATE
,
477 snd_hda_codec_write(codec
, 0x13, 0, AC_VERB_SET_POWER_STATE
,
479 snd_hda_codec_write(codec
, 0x14, 0, AC_VERB_SET_POWER_STATE
,
483 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
485 set_pin_power_state(codec
, 0x19, &parm
);
486 snd_hda_codec_write(codec
, 0x18, 0, AC_VERB_SET_POWER_STATE
,
488 snd_hda_codec_write(codec
, 0x11, 0, AC_VERB_SET_POWER_STATE
,
491 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
494 set_pin_power_state(codec
, 0x22, &parm
);
495 snd_hda_codec_write(codec
, 0x26, 0,
496 AC_VERB_SET_POWER_STATE
, parm
);
497 snd_hda_codec_write(codec
, 0x24, 0,
498 AC_VERB_SET_POWER_STATE
, parm
);
501 /* PW 3/4/7 (1ch/1dh/23h) */
503 /* force to D0 for internal Speaker */
504 set_pin_power_state(codec
, 0x1c, &parm
);
505 set_pin_power_state(codec
, 0x1d, &parm
);
507 set_pin_power_state(codec
, 0x23, &parm
);
508 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
509 snd_hda_codec_write(codec
, 0x16, 0, AC_VERB_SET_POWER_STATE
,
510 imux_is_smixer
? AC_PWRST_D0
: parm
);
511 snd_hda_codec_write(codec
, 0x10, 0, AC_VERB_SET_POWER_STATE
,
514 snd_hda_codec_write(codec
, 0x25, 0,
515 AC_VERB_SET_POWER_STATE
, parm
);
516 snd_hda_codec_write(codec
, 0x27, 0,
517 AC_VERB_SET_POWER_STATE
, parm
);
525 static int via_mux_enum_info(struct snd_kcontrol
*kcontrol
,
526 struct snd_ctl_elem_info
*uinfo
)
528 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
529 struct via_spec
*spec
= codec
->spec
;
530 return snd_hda_input_mux_info(spec
->input_mux
, uinfo
);
533 static int via_mux_enum_get(struct snd_kcontrol
*kcontrol
,
534 struct snd_ctl_elem_value
*ucontrol
)
536 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
537 struct via_spec
*spec
= codec
->spec
;
538 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
540 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
544 static int via_mux_enum_put(struct snd_kcontrol
*kcontrol
,
545 struct snd_ctl_elem_value
*ucontrol
)
547 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
548 struct via_spec
*spec
= codec
->spec
;
549 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
551 if (!spec
->mux_nids
[adc_idx
])
553 /* switch to D0 beofre change index */
554 if (snd_hda_codec_read(codec
, spec
->mux_nids
[adc_idx
], 0,
555 AC_VERB_GET_POWER_STATE
, 0x00) != AC_PWRST_D0
)
556 snd_hda_codec_write(codec
, spec
->mux_nids
[adc_idx
], 0,
557 AC_VERB_SET_POWER_STATE
, AC_PWRST_D0
);
558 /* update jack power state */
559 set_jack_power_state(codec
);
561 return snd_hda_input_mux_put(codec
, spec
->input_mux
, ucontrol
,
562 spec
->mux_nids
[adc_idx
],
563 &spec
->cur_mux
[adc_idx
]);
566 static int via_independent_hp_info(struct snd_kcontrol
*kcontrol
,
567 struct snd_ctl_elem_info
*uinfo
)
569 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
570 struct via_spec
*spec
= codec
->spec
;
571 return snd_hda_input_mux_info(spec
->hp_mux
, uinfo
);
574 static int via_independent_hp_get(struct snd_kcontrol
*kcontrol
,
575 struct snd_ctl_elem_value
*ucontrol
)
577 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
578 struct via_spec
*spec
= codec
->spec
;
579 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
580 unsigned int pinsel
= snd_hda_codec_read(codec
, nid
, 0,
581 AC_VERB_GET_CONNECT_SEL
,
584 ucontrol
->value
.enumerated
.item
[0] = pinsel
;
589 static void activate_ctl(struct hda_codec
*codec
, const char *name
, int active
)
591 struct snd_kcontrol
*ctl
= snd_hda_find_mixer_ctl(codec
, name
);
593 ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
594 ctl
->vd
[0].access
|= active
595 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
596 snd_ctl_notify(codec
->bus
->card
,
597 SNDRV_CTL_EVENT_MASK_VALUE
, &ctl
->id
);
601 static int update_side_mute_status(struct hda_codec
*codec
)
603 /* mute side channel */
604 struct via_spec
*spec
= codec
->spec
;
605 unsigned int parm
= spec
->hp_independent_mode
606 ? AMP_OUT_MUTE
: AMP_OUT_UNMUTE
;
609 switch (spec
->codec_type
) {
626 snd_hda_codec_write(codec
, sw3
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
631 static int via_independent_hp_put(struct snd_kcontrol
*kcontrol
,
632 struct snd_ctl_elem_value
*ucontrol
)
634 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
635 struct via_spec
*spec
= codec
->spec
;
636 hda_nid_t nid
= spec
->autocfg
.hp_pins
[0];
637 unsigned int pinsel
= ucontrol
->value
.enumerated
.item
[0];
638 /* Get Independent Mode index of headphone pin widget */
639 spec
->hp_independent_mode
= spec
->hp_independent_mode_index
== pinsel
642 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CONNECT_SEL
, pinsel
);
644 if (spec
->multiout
.hp_nid
&& spec
->multiout
.hp_nid
645 != spec
->multiout
.dac_nids
[HDA_FRONT
])
646 snd_hda_codec_setup_stream(codec
, spec
->multiout
.hp_nid
,
649 update_side_mute_status(codec
);
650 /* update HP volume/swtich active state */
651 if (spec
->codec_type
== VT1708S
652 || spec
->codec_type
== VT1702
) {
653 activate_ctl(codec
, "Headphone Playback Volume",
654 spec
->hp_independent_mode
);
655 activate_ctl(codec
, "Headphone Playback Switch",
656 spec
->hp_independent_mode
);
661 static struct snd_kcontrol_new via_hp_mixer
[] = {
663 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
664 .name
= "Independent HP",
666 .info
= via_independent_hp_info
,
667 .get
= via_independent_hp_get
,
668 .put
= via_independent_hp_put
,
673 static void notify_aa_path_ctls(struct hda_codec
*codec
)
676 struct snd_ctl_elem_id id
;
677 const char *labels
[] = {"Mic", "Front Mic", "Line"};
679 memset(&id
, 0, sizeof(id
));
680 id
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
681 for (i
= 0; i
< ARRAY_SIZE(labels
); i
++) {
682 sprintf(id
.name
, "%s Playback Volume", labels
[i
]);
683 snd_ctl_notify(codec
->bus
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
688 static void mute_aa_path(struct hda_codec
*codec
, int mute
)
690 struct via_spec
*spec
= codec
->spec
;
695 /* get nid of MW0 and start & end index */
696 switch (spec
->codec_type
) {
718 /* check AA path's mute status */
719 for (i
= start_idx
; i
<= end_idx
; i
++) {
720 int val
= mute
? HDA_AMP_MUTE
: HDA_AMP_UNMUTE
;
721 snd_hda_codec_amp_stereo(codec
, nid_mixer
, HDA_INPUT
, i
,
725 static int is_smart51_pins(struct via_spec
*spec
, hda_nid_t pin
)
729 for (index
= AUTO_PIN_MIC
; index
< AUTO_PIN_FRONT_LINE
; index
++) {
730 if (pin
== spec
->autocfg
.input_pins
[index
]) {
738 static int via_smart51_info(struct snd_kcontrol
*kcontrol
,
739 struct snd_ctl_elem_info
*uinfo
)
741 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
743 uinfo
->value
.integer
.min
= 0;
744 uinfo
->value
.integer
.max
= 1;
748 static int via_smart51_get(struct snd_kcontrol
*kcontrol
,
749 struct snd_ctl_elem_value
*ucontrol
)
751 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
752 struct via_spec
*spec
= codec
->spec
;
753 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
757 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
758 hda_nid_t nid
= spec
->autocfg
.input_pins
[index
[i
]];
761 snd_hda_codec_read(codec
, nid
, 0,
762 AC_VERB_GET_PIN_WIDGET_CONTROL
,
764 if (i
== AUTO_PIN_FRONT_MIC
765 && spec
->hp_independent_mode
)
766 continue; /* ignore FMic for independent HP */
767 if (ctl
& AC_PINCTL_IN_EN
768 && !(ctl
& AC_PINCTL_OUT_EN
))
772 *ucontrol
->value
.integer
.value
= on
;
776 static int via_smart51_put(struct snd_kcontrol
*kcontrol
,
777 struct snd_ctl_elem_value
*ucontrol
)
779 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
780 struct via_spec
*spec
= codec
->spec
;
781 int out_in
= *ucontrol
->value
.integer
.value
782 ? AC_PINCTL_OUT_EN
: AC_PINCTL_IN_EN
;
783 int index
[] = { AUTO_PIN_MIC
, AUTO_PIN_FRONT_MIC
, AUTO_PIN_LINE
};
786 for (i
= 0; i
< ARRAY_SIZE(index
); i
++) {
787 hda_nid_t nid
= spec
->autocfg
.input_pins
[index
[i
]];
788 if (i
== AUTO_PIN_FRONT_MIC
789 && spec
->hp_independent_mode
)
790 continue; /* don't retask FMic for independent HP */
792 unsigned int parm
= snd_hda_codec_read(
794 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
795 parm
&= ~(AC_PINCTL_IN_EN
| AC_PINCTL_OUT_EN
);
797 snd_hda_codec_write(codec
, nid
, 0,
798 AC_VERB_SET_PIN_WIDGET_CONTROL
,
800 if (out_in
== AC_PINCTL_OUT_EN
) {
801 mute_aa_path(codec
, 1);
802 notify_aa_path_ctls(codec
);
805 if (i
== AUTO_PIN_FRONT_MIC
) {
806 if (spec
->codec_type
== VT1708S
) {
807 /* input = index 1 (AOW3) */
810 AC_VERB_SET_CONNECT_SEL
, 1);
811 snd_hda_codec_amp_stereo(
812 codec
, nid
, HDA_OUTPUT
,
813 0, HDA_AMP_MUTE
, HDA_AMP_UNMUTE
);
817 spec
->smart51_enabled
= *ucontrol
->value
.integer
.value
;
818 set_jack_power_state(codec
);
822 static struct snd_kcontrol_new via_smart51_mixer
[] = {
824 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
827 .info
= via_smart51_info
,
828 .get
= via_smart51_get
,
829 .put
= via_smart51_put
,
834 /* capture mixer elements */
835 static struct snd_kcontrol_new vt1708_capture_mixer
[] = {
836 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT
),
837 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT
),
838 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT
),
839 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT
),
841 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
842 /* The multiple "Capture Source" controls confuse alsamixer
843 * So call somewhat different..
845 /* .name = "Capture Source", */
846 .name
= "Input Source",
848 .info
= via_mux_enum_info
,
849 .get
= via_mux_enum_get
,
850 .put
= via_mux_enum_put
,
855 /* check AA path's mute statue */
856 static int is_aa_path_mute(struct hda_codec
*codec
)
863 struct via_spec
*spec
= codec
->spec
;
864 /* get nid of MW0 and start & end index */
865 switch (spec
->codec_type
) {
881 /* check AA path's mute status */
882 for (i
= start_idx
; i
<= end_idx
; i
++) {
883 unsigned int con_list
= snd_hda_codec_read(
884 codec
, nid_mixer
, 0, AC_VERB_GET_CONNECT_LIST
, i
/4*4);
885 int shift
= 8 * (i
% 4);
886 hda_nid_t nid_pin
= (con_list
& (0xff << shift
)) >> shift
;
887 unsigned int defconf
= snd_hda_codec_get_pincfg(codec
, nid_pin
);
888 if (get_defcfg_connect(defconf
) == AC_JACK_PORT_COMPLEX
) {
889 /* check mute status while the pin is connected */
890 int mute_l
= snd_hda_codec_amp_read(codec
, nid_mixer
, 0,
892 int mute_r
= snd_hda_codec_amp_read(codec
, nid_mixer
, 1,
894 if (!mute_l
|| !mute_r
) {
903 /* enter/exit analog low-current mode */
904 static void analog_low_current_mode(struct hda_codec
*codec
, int stream_idle
)
906 struct via_spec
*spec
= codec
->spec
;
907 static int saved_stream_idle
= 1; /* saved stream idle status */
908 int enable
= is_aa_path_mute(codec
);
909 unsigned int verb
= 0;
910 unsigned int parm
= 0;
912 if (stream_idle
== -1) /* stream status did not change */
913 enable
= enable
&& saved_stream_idle
;
915 enable
= enable
&& stream_idle
;
916 saved_stream_idle
= stream_idle
;
919 /* decide low current mode's verb & parameter */
920 switch (spec
->codec_type
) {
924 parm
= enable
? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
928 parm
= enable
? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
932 parm
= enable
? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
935 return; /* other codecs are not supported */
938 snd_hda_codec_write(codec
, codec
->afg
, 0, verb
, parm
);
942 * generic initialization of ADC, input mixers and output mixers
944 static struct hda_verb vt1708_volume_init_verbs
[] = {
946 * Unmute ADC0-1 and set the default input to mic-in
948 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
949 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
952 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
955 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
956 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
957 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
958 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
959 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
960 {0x17, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
963 * Set up output mixers (0x19 - 0x1b)
965 /* set vol=0 to output mixers */
966 {0x19, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
967 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
968 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
970 /* Setup default input to PW4 */
971 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
972 /* PW9 Output enable */
973 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
977 static int via_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
978 struct hda_codec
*codec
,
979 struct snd_pcm_substream
*substream
)
981 struct via_spec
*spec
= codec
->spec
;
982 int idle
= substream
->pstr
->substream_opened
== 1
983 && substream
->ref_count
== 0;
985 analog_low_current_mode(codec
, idle
);
986 return snd_hda_multi_out_analog_open(codec
, &spec
->multiout
, substream
,
990 static int via_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
991 struct hda_codec
*codec
,
992 unsigned int stream_tag
,
994 struct snd_pcm_substream
*substream
)
996 struct via_spec
*spec
= codec
->spec
;
997 return snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
998 stream_tag
, format
, substream
);
1001 static int via_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1002 struct hda_codec
*codec
,
1003 struct snd_pcm_substream
*substream
)
1005 struct via_spec
*spec
= codec
->spec
;
1006 return snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
1010 static void playback_multi_pcm_prep_0(struct hda_codec
*codec
,
1011 unsigned int stream_tag
,
1012 unsigned int format
,
1013 struct snd_pcm_substream
*substream
)
1015 struct via_spec
*spec
= codec
->spec
;
1016 struct hda_multi_out
*mout
= &spec
->multiout
;
1017 hda_nid_t
*nids
= mout
->dac_nids
;
1018 int chs
= substream
->runtime
->channels
;
1021 mutex_lock(&codec
->spdif_mutex
);
1022 if (mout
->dig_out_nid
&& mout
->dig_out_used
!= HDA_DIG_EXCLUSIVE
) {
1024 snd_hda_is_supported_format(codec
, mout
->dig_out_nid
,
1026 !(codec
->spdif_status
& IEC958_AES0_NONAUDIO
)) {
1027 mout
->dig_out_used
= HDA_DIG_ANALOG_DUP
;
1028 /* turn off SPDIF once; otherwise the IEC958 bits won't
1030 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1031 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1032 AC_VERB_SET_DIGI_CONVERT_1
,
1034 ~AC_DIG1_ENABLE
& 0xff);
1035 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1036 stream_tag
, 0, format
);
1037 /* turn on again (if needed) */
1038 if (codec
->spdif_ctls
& AC_DIG1_ENABLE
)
1039 snd_hda_codec_write(codec
, mout
->dig_out_nid
, 0,
1040 AC_VERB_SET_DIGI_CONVERT_1
,
1041 codec
->spdif_ctls
& 0xff);
1043 mout
->dig_out_used
= 0;
1044 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1048 mutex_unlock(&codec
->spdif_mutex
);
1051 snd_hda_codec_setup_stream(codec
, nids
[HDA_FRONT
], stream_tag
,
1054 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1055 !spec
->hp_independent_mode
)
1056 /* headphone out will just decode front left/right (stereo) */
1057 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
, stream_tag
,
1060 /* extra outputs copied from front */
1061 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1062 if (mout
->extra_out_nid
[i
])
1063 snd_hda_codec_setup_stream(codec
,
1064 mout
->extra_out_nid
[i
],
1065 stream_tag
, 0, format
);
1068 for (i
= 1; i
< mout
->num_dacs
; i
++) {
1069 if (chs
>= (i
+ 1) * 2) /* independent out */
1070 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1072 else /* copy front */
1073 snd_hda_codec_setup_stream(codec
, nids
[i
], stream_tag
,
1078 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1079 struct hda_codec
*codec
,
1080 unsigned int stream_tag
,
1081 unsigned int format
,
1082 struct snd_pcm_substream
*substream
)
1084 struct via_spec
*spec
= codec
->spec
;
1085 struct hda_multi_out
*mout
= &spec
->multiout
;
1086 hda_nid_t
*nids
= mout
->dac_nids
;
1088 if (substream
->number
== 0)
1089 playback_multi_pcm_prep_0(codec
, stream_tag
, format
,
1092 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1093 spec
->hp_independent_mode
)
1094 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1095 stream_tag
, 0, format
);
1101 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1102 struct hda_codec
*codec
,
1103 struct snd_pcm_substream
*substream
)
1105 struct via_spec
*spec
= codec
->spec
;
1106 struct hda_multi_out
*mout
= &spec
->multiout
;
1107 hda_nid_t
*nids
= mout
->dac_nids
;
1110 if (substream
->number
== 0) {
1111 for (i
= 0; i
< mout
->num_dacs
; i
++)
1112 snd_hda_codec_setup_stream(codec
, nids
[i
], 0, 0, 0);
1114 if (mout
->hp_nid
&& !spec
->hp_independent_mode
)
1115 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1118 for (i
= 0; i
< ARRAY_SIZE(mout
->extra_out_nid
); i
++)
1119 if (mout
->extra_out_nid
[i
])
1120 snd_hda_codec_setup_stream(codec
,
1121 mout
->extra_out_nid
[i
],
1123 mutex_lock(&codec
->spdif_mutex
);
1124 if (mout
->dig_out_nid
&&
1125 mout
->dig_out_used
== HDA_DIG_ANALOG_DUP
) {
1126 snd_hda_codec_setup_stream(codec
, mout
->dig_out_nid
,
1128 mout
->dig_out_used
= 0;
1130 mutex_unlock(&codec
->spdif_mutex
);
1132 if (mout
->hp_nid
&& mout
->hp_nid
!= nids
[HDA_FRONT
] &&
1133 spec
->hp_independent_mode
)
1134 snd_hda_codec_setup_stream(codec
, mout
->hp_nid
,
1144 static int via_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
1145 struct hda_codec
*codec
,
1146 struct snd_pcm_substream
*substream
)
1148 struct via_spec
*spec
= codec
->spec
;
1149 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
1152 static int via_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
1153 struct hda_codec
*codec
,
1154 struct snd_pcm_substream
*substream
)
1156 struct via_spec
*spec
= codec
->spec
;
1157 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
1160 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1161 struct hda_codec
*codec
,
1162 unsigned int stream_tag
,
1163 unsigned int format
,
1164 struct snd_pcm_substream
*substream
)
1166 struct via_spec
*spec
= codec
->spec
;
1167 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
1168 stream_tag
, format
, substream
);
1171 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1172 struct hda_codec
*codec
,
1173 struct snd_pcm_substream
*substream
)
1175 struct via_spec
*spec
= codec
->spec
;
1176 snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
1183 static int via_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
1184 struct hda_codec
*codec
,
1185 unsigned int stream_tag
,
1186 unsigned int format
,
1187 struct snd_pcm_substream
*substream
)
1189 struct via_spec
*spec
= codec
->spec
;
1191 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
],
1192 stream_tag
, 0, format
);
1196 static int via_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
1197 struct hda_codec
*codec
,
1198 struct snd_pcm_substream
*substream
)
1200 struct via_spec
*spec
= codec
->spec
;
1201 snd_hda_codec_cleanup_stream(codec
, spec
->adc_nids
[substream
->number
]);
1205 static struct hda_pcm_stream vt1708_pcm_analog_playback
= {
1209 .nid
= 0x10, /* NID to query formats and rates */
1211 .open
= via_playback_pcm_open
,
1212 .prepare
= via_playback_multi_pcm_prepare
,
1213 .cleanup
= via_playback_multi_pcm_cleanup
1217 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback
= {
1221 .nid
= 0x10, /* NID to query formats and rates */
1222 /* We got noisy outputs on the right channel on VT1708 when
1223 * 24bit samples are used. Until any workaround is found,
1224 * disable the 24bit format, so far.
1226 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1228 .open
= via_playback_pcm_open
,
1229 .prepare
= via_playback_pcm_prepare
,
1230 .cleanup
= via_playback_pcm_cleanup
1234 static struct hda_pcm_stream vt1708_pcm_analog_capture
= {
1238 .nid
= 0x15, /* NID to query formats and rates */
1240 .prepare
= via_capture_pcm_prepare
,
1241 .cleanup
= via_capture_pcm_cleanup
1245 static struct hda_pcm_stream vt1708_pcm_digital_playback
= {
1249 /* NID is set in via_build_pcms */
1251 .open
= via_dig_playback_pcm_open
,
1252 .close
= via_dig_playback_pcm_close
,
1253 .prepare
= via_dig_playback_pcm_prepare
,
1254 .cleanup
= via_dig_playback_pcm_cleanup
1258 static struct hda_pcm_stream vt1708_pcm_digital_capture
= {
1264 static int via_build_controls(struct hda_codec
*codec
)
1266 struct via_spec
*spec
= codec
->spec
;
1270 for (i
= 0; i
< spec
->num_mixers
; i
++) {
1271 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
1276 if (spec
->multiout
.dig_out_nid
) {
1277 err
= snd_hda_create_spdif_out_ctls(codec
,
1278 spec
->multiout
.dig_out_nid
);
1281 err
= snd_hda_create_spdif_share_sw(codec
,
1285 spec
->multiout
.share_spdif
= 1;
1287 if (spec
->dig_in_nid
) {
1288 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
1293 /* init power states */
1294 set_jack_power_state(codec
);
1295 analog_low_current_mode(codec
, 1);
1297 via_free_kctls(codec
); /* no longer needed */
1301 static int via_build_pcms(struct hda_codec
*codec
)
1303 struct via_spec
*spec
= codec
->spec
;
1304 struct hda_pcm
*info
= spec
->pcm_rec
;
1306 codec
->num_pcms
= 1;
1307 codec
->pcm_info
= info
;
1309 info
->name
= spec
->stream_name_analog
;
1310 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *(spec
->stream_analog_playback
);
1311 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
1312 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *(spec
->stream_analog_capture
);
1313 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
1315 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
1316 spec
->multiout
.max_channels
;
1318 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
1321 info
->name
= spec
->stream_name_digital
;
1322 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
1323 if (spec
->multiout
.dig_out_nid
) {
1324 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
1325 *(spec
->stream_digital_playback
);
1326 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
1327 spec
->multiout
.dig_out_nid
;
1329 if (spec
->dig_in_nid
) {
1330 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
1331 *(spec
->stream_digital_capture
);
1332 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
1340 static void via_free(struct hda_codec
*codec
)
1342 struct via_spec
*spec
= codec
->spec
;
1347 via_free_kctls(codec
);
1351 /* mute internal speaker if HP is plugged */
1352 static void via_hp_automute(struct hda_codec
*codec
)
1354 unsigned int present
;
1355 struct via_spec
*spec
= codec
->spec
;
1357 present
= snd_hda_codec_read(codec
, spec
->autocfg
.hp_pins
[0], 0,
1358 AC_VERB_GET_PIN_SENSE
, 0) & 0x80000000;
1359 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
1360 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
1361 present
? HDA_AMP_MUTE
: 0);
1364 static void via_gpio_control(struct hda_codec
*codec
)
1366 unsigned int gpio_data
;
1367 unsigned int vol_counter
;
1369 unsigned int master_vol
;
1371 struct via_spec
*spec
= codec
->spec
;
1373 gpio_data
= snd_hda_codec_read(codec
, codec
->afg
, 0,
1374 AC_VERB_GET_GPIO_DATA
, 0) & 0x03;
1376 vol_counter
= (snd_hda_codec_read(codec
, codec
->afg
, 0,
1377 0xF84, 0) & 0x3F0000) >> 16;
1379 vol
= vol_counter
& 0x1F;
1380 master_vol
= snd_hda_codec_read(codec
, 0x1A, 0,
1381 AC_VERB_GET_AMP_GAIN_MUTE
,
1384 if (gpio_data
== 0x02) {
1385 /* unmute line out */
1386 snd_hda_codec_amp_stereo(codec
, spec
->autocfg
.line_out_pins
[0],
1387 HDA_OUTPUT
, 0, HDA_AMP_MUTE
, 0);
1389 if (vol_counter
& 0x20) {
1390 /* decrease volume */
1391 if (vol
> master_vol
)
1393 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
,
1397 /* increase volume */
1398 snd_hda_codec_amp_stereo(codec
, 0x1A, HDA_INPUT
, 0,
1400 ((master_vol
+vol
) > 0x2A) ? 0x2A :
1403 } else if (!(gpio_data
& 0x02)) {
1405 snd_hda_codec_amp_stereo(codec
,
1406 spec
->autocfg
.line_out_pins
[0],
1407 HDA_OUTPUT
, 0, HDA_AMP_MUTE
,
1412 /* unsolicited event for jack sensing */
1413 static void via_unsol_event(struct hda_codec
*codec
,
1417 if (res
& VIA_HP_EVENT
)
1418 via_hp_automute(codec
);
1419 if (res
& VIA_GPIO_EVENT
)
1420 via_gpio_control(codec
);
1421 if (res
& VIA_JACK_EVENT
)
1422 set_jack_power_state(codec
);
1425 static int via_init(struct hda_codec
*codec
)
1427 struct via_spec
*spec
= codec
->spec
;
1429 for (i
= 0; i
< spec
->num_iverbs
; i
++)
1430 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
1432 spec
->codec_type
= get_codec_type(codec
);
1433 if (spec
->codec_type
== VT1708BCE
)
1434 spec
->codec_type
= VT1708S
; /* VT1708BCE & VT1708S are almost
1436 /* Lydia Add for EAPD enable */
1437 if (!spec
->dig_in_nid
) { /* No Digital In connection */
1438 if (spec
->dig_in_pin
) {
1439 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
1440 AC_VERB_SET_PIN_WIDGET_CONTROL
,
1442 snd_hda_codec_write(codec
, spec
->dig_in_pin
, 0,
1443 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
1445 } else /* enable SPDIF-input pin */
1446 snd_hda_codec_write(codec
, spec
->autocfg
.dig_in_pin
, 0,
1447 AC_VERB_SET_PIN_WIDGET_CONTROL
, PIN_IN
);
1449 /* assign slave outs */
1450 if (spec
->slave_dig_outs
[0])
1451 codec
->slave_dig_outs
= spec
->slave_dig_outs
;
1456 #ifdef CONFIG_SND_HDA_POWER_SAVE
1457 static int via_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
1459 struct via_spec
*spec
= codec
->spec
;
1460 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
1466 static struct hda_codec_ops via_patch_ops
= {
1467 .build_controls
= via_build_controls
,
1468 .build_pcms
= via_build_pcms
,
1471 #ifdef CONFIG_SND_HDA_POWER_SAVE
1472 .check_power_status
= via_check_power_status
,
1476 /* fill in the dac_nids table from the parsed pin configuration */
1477 static int vt1708_auto_fill_dac_nids(struct via_spec
*spec
,
1478 const struct auto_pin_cfg
*cfg
)
1483 spec
->multiout
.num_dacs
= cfg
->line_outs
;
1485 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1487 for(i
= 0; i
< 4; i
++) {
1488 nid
= cfg
->line_out_pins
[i
];
1490 /* config dac list */
1492 case AUTO_SEQ_FRONT
:
1493 spec
->multiout
.dac_nids
[i
] = 0x10;
1495 case AUTO_SEQ_CENLFE
:
1496 spec
->multiout
.dac_nids
[i
] = 0x12;
1498 case AUTO_SEQ_SURROUND
:
1499 spec
->multiout
.dac_nids
[i
] = 0x11;
1502 spec
->multiout
.dac_nids
[i
] = 0x13;
1511 /* add playback controls from the parsed DAC table */
1512 static int vt1708_auto_create_multi_out_ctls(struct via_spec
*spec
,
1513 const struct auto_pin_cfg
*cfg
)
1516 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
1517 hda_nid_t nid
, nid_vol
= 0;
1520 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
1521 nid
= cfg
->line_out_pins
[i
];
1526 if (i
!= AUTO_SEQ_FRONT
)
1529 if (i
== AUTO_SEQ_CENLFE
) {
1531 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1532 "Center Playback Volume",
1533 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1537 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1538 "LFE Playback Volume",
1539 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1543 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1544 "Center Playback Switch",
1545 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
1549 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1550 "LFE Playback Switch",
1551 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
1555 } else if (i
== AUTO_SEQ_FRONT
){
1556 /* add control to mixer index 0 */
1557 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1558 "Master Front Playback Volume",
1559 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1563 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1564 "Master Front Playback Switch",
1565 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1570 /* add control to PW3 */
1571 sprintf(name
, "%s Playback Volume", chname
[i
]);
1572 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1573 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1577 sprintf(name
, "%s Playback Switch", chname
[i
]);
1578 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1579 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
1584 sprintf(name
, "%s Playback Volume", chname
[i
]);
1585 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
1586 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1590 sprintf(name
, "%s Playback Switch", chname
[i
]);
1591 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
1592 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
1602 static void create_hp_imux(struct via_spec
*spec
)
1605 struct hda_input_mux
*imux
= &spec
->private_imux
[1];
1606 static const char *texts
[] = { "OFF", "ON", NULL
};
1608 /* for hp mode select */
1610 while (texts
[i
] != NULL
) {
1611 imux
->items
[imux
->num_items
].label
= texts
[i
];
1612 imux
->items
[imux
->num_items
].index
= i
;
1617 spec
->hp_mux
= &spec
->private_imux
[1];
1620 static int vt1708_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
1627 spec
->multiout
.hp_nid
= VT1708_HP_NID
; /* AOW3 */
1628 spec
->hp_independent_mode_index
= 1;
1630 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
1631 "Headphone Playback Volume",
1632 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1635 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
1636 "Headphone Playback Switch",
1637 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
1641 create_hp_imux(spec
);
1646 /* create playback/capture controls for input pins */
1647 static int vt1708_auto_create_analog_input_ctls(struct via_spec
*spec
,
1648 const struct auto_pin_cfg
*cfg
)
1650 static char *labels
[] = {
1651 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1653 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
1654 int i
, err
, idx
= 0;
1656 /* for internal loopback recording select */
1657 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
1658 imux
->items
[imux
->num_items
].index
= idx
;
1661 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
1662 if (!cfg
->input_pins
[i
])
1665 switch (cfg
->input_pins
[i
]) {
1666 case 0x1d: /* Mic */
1670 case 0x1e: /* Line In */
1674 case 0x21: /* Front Mic */
1682 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x17);
1685 imux
->items
[imux
->num_items
].label
= labels
[i
];
1686 imux
->items
[imux
->num_items
].index
= idx
;
1692 #ifdef CONFIG_SND_HDA_POWER_SAVE
1693 static struct hda_amp_list vt1708_loopbacks
[] = {
1694 { 0x17, HDA_INPUT
, 1 },
1695 { 0x17, HDA_INPUT
, 2 },
1696 { 0x17, HDA_INPUT
, 3 },
1697 { 0x17, HDA_INPUT
, 4 },
1702 static void vt1708_set_pinconfig_connect(struct hda_codec
*codec
, hda_nid_t nid
)
1704 unsigned int def_conf
;
1705 unsigned char seqassoc
;
1707 def_conf
= snd_hda_codec_get_pincfg(codec
, nid
);
1708 seqassoc
= (unsigned char) get_defcfg_association(def_conf
);
1709 seqassoc
= (seqassoc
<< 4) | get_defcfg_sequence(def_conf
);
1710 if (get_defcfg_connect(def_conf
) == AC_JACK_PORT_NONE
) {
1711 if (seqassoc
== 0xff) {
1712 def_conf
= def_conf
& (~(AC_JACK_PORT_BOTH
<< 30));
1713 snd_hda_codec_set_pincfg(codec
, nid
, def_conf
);
1720 static int vt1708_parse_auto_config(struct hda_codec
*codec
)
1722 struct via_spec
*spec
= codec
->spec
;
1725 /* Add HP and CD pin config connect bit re-config action */
1726 vt1708_set_pinconfig_connect(codec
, VT1708_HP_PIN_NID
);
1727 vt1708_set_pinconfig_connect(codec
, VT1708_CD_PIN_NID
);
1729 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
1732 err
= vt1708_auto_fill_dac_nids(spec
, &spec
->autocfg
);
1735 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
1736 return 0; /* can't find valid BIOS pin config */
1738 err
= vt1708_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
1741 err
= vt1708_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
1744 err
= vt1708_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
1748 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
1750 if (spec
->autocfg
.dig_outs
)
1751 spec
->multiout
.dig_out_nid
= VT1708_DIGOUT_NID
;
1752 spec
->dig_in_pin
= VT1708_DIGIN_PIN
;
1753 if (spec
->autocfg
.dig_in_pin
)
1754 spec
->dig_in_nid
= VT1708_DIGIN_NID
;
1756 if (spec
->kctls
.list
)
1757 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
1759 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708_volume_init_verbs
;
1761 spec
->input_mux
= &spec
->private_imux
[0];
1764 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
1766 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
1770 /* init callback for auto-configuration model -- overriding the default init */
1771 static int via_auto_init(struct hda_codec
*codec
)
1774 via_auto_init_multi_out(codec
);
1775 via_auto_init_hp_out(codec
);
1776 via_auto_init_analog_input(codec
);
1780 static int get_mux_nids(struct hda_codec
*codec
)
1782 struct via_spec
*spec
= codec
->spec
;
1783 hda_nid_t nid
, conn
[8];
1787 for (i
= 0; i
< spec
->num_adc_nids
; i
++) {
1788 nid
= spec
->adc_nids
[i
];
1790 type
= get_wcaps_type(get_wcaps(codec
, nid
));
1791 if (type
== AC_WID_PIN
)
1793 n
= snd_hda_get_connections(codec
, nid
, conn
,
1798 spec
->mux_nids
[i
] = nid
;
1807 static int patch_vt1708(struct hda_codec
*codec
)
1809 struct via_spec
*spec
;
1812 /* create a codec specific record */
1813 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
1819 /* automatic parse from the BIOS config */
1820 err
= vt1708_parse_auto_config(codec
);
1825 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
1826 "from BIOS. Using genenic mode...\n");
1830 spec
->stream_name_analog
= "VT1708 Analog";
1831 spec
->stream_analog_playback
= &vt1708_pcm_analog_playback
;
1832 /* disable 32bit format on VT1708 */
1833 if (codec
->vendor_id
== 0x11061708)
1834 spec
->stream_analog_playback
= &vt1708_pcm_analog_s16_playback
;
1835 spec
->stream_analog_capture
= &vt1708_pcm_analog_capture
;
1837 spec
->stream_name_digital
= "VT1708 Digital";
1838 spec
->stream_digital_playback
= &vt1708_pcm_digital_playback
;
1839 spec
->stream_digital_capture
= &vt1708_pcm_digital_capture
;
1842 if (!spec
->adc_nids
&& spec
->input_mux
) {
1843 spec
->adc_nids
= vt1708_adc_nids
;
1844 spec
->num_adc_nids
= ARRAY_SIZE(vt1708_adc_nids
);
1845 get_mux_nids(codec
);
1846 spec
->mixers
[spec
->num_mixers
] = vt1708_capture_mixer
;
1850 codec
->patch_ops
= via_patch_ops
;
1852 codec
->patch_ops
.init
= via_auto_init
;
1853 #ifdef CONFIG_SND_HDA_POWER_SAVE
1854 spec
->loopback
.amplist
= vt1708_loopbacks
;
1860 /* capture mixer elements */
1861 static struct snd_kcontrol_new vt1709_capture_mixer
[] = {
1862 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT
),
1863 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT
),
1864 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT
),
1865 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT
),
1866 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT
),
1867 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT
),
1869 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1870 /* The multiple "Capture Source" controls confuse alsamixer
1871 * So call somewhat different..
1873 /* .name = "Capture Source", */
1874 .name
= "Input Source",
1876 .info
= via_mux_enum_info
,
1877 .get
= via_mux_enum_get
,
1878 .put
= via_mux_enum_put
,
1883 static struct hda_verb vt1709_uniwill_init_verbs
[] = {
1884 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE
,
1885 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
1890 * generic initialization of ADC, input mixers and output mixers
1892 static struct hda_verb vt1709_10ch_volume_init_verbs
[] = {
1894 * Unmute ADC0-2 and set the default input to mic-in
1896 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1897 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1898 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1901 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1904 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1905 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
1906 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
1907 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
1908 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
1909 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
1912 * Set up output selector (0x1a, 0x1b, 0x29)
1914 /* set vol=0 to output mixers */
1915 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1916 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1917 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1920 * Unmute PW3 and PW4
1922 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1923 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
1925 /* Set input of PW4 as AOW4 */
1926 {0x20, AC_VERB_SET_CONNECT_SEL
, 0x1},
1927 /* PW9 Output enable */
1928 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
1932 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback
= {
1936 .nid
= 0x10, /* NID to query formats and rates */
1938 .open
= via_playback_pcm_open
,
1939 .prepare
= via_playback_pcm_prepare
,
1940 .cleanup
= via_playback_pcm_cleanup
1944 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback
= {
1948 .nid
= 0x10, /* NID to query formats and rates */
1950 .open
= via_playback_pcm_open
,
1951 .prepare
= via_playback_pcm_prepare
,
1952 .cleanup
= via_playback_pcm_cleanup
1956 static struct hda_pcm_stream vt1709_pcm_analog_capture
= {
1960 .nid
= 0x14, /* NID to query formats and rates */
1962 .prepare
= via_capture_pcm_prepare
,
1963 .cleanup
= via_capture_pcm_cleanup
1967 static struct hda_pcm_stream vt1709_pcm_digital_playback
= {
1971 /* NID is set in via_build_pcms */
1973 .open
= via_dig_playback_pcm_open
,
1974 .close
= via_dig_playback_pcm_close
1978 static struct hda_pcm_stream vt1709_pcm_digital_capture
= {
1984 static int vt1709_auto_fill_dac_nids(struct via_spec
*spec
,
1985 const struct auto_pin_cfg
*cfg
)
1990 if (cfg
->line_outs
== 4) /* 10 channels */
1991 spec
->multiout
.num_dacs
= cfg
->line_outs
+1; /* AOW0~AOW4 */
1992 else if (cfg
->line_outs
== 3) /* 6 channels */
1993 spec
->multiout
.num_dacs
= cfg
->line_outs
; /* AOW0~AOW2 */
1995 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1997 if (cfg
->line_outs
== 4) { /* 10 channels */
1998 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1999 nid
= cfg
->line_out_pins
[i
];
2001 /* config dac list */
2003 case AUTO_SEQ_FRONT
:
2005 spec
->multiout
.dac_nids
[i
] = 0x10;
2007 case AUTO_SEQ_CENLFE
:
2009 spec
->multiout
.dac_nids
[i
] = 0x12;
2011 case AUTO_SEQ_SURROUND
:
2013 spec
->multiout
.dac_nids
[i
] = 0x11;
2017 spec
->multiout
.dac_nids
[i
] = 0x27;
2024 spec
->multiout
.dac_nids
[cfg
->line_outs
] = 0x28; /* AOW4 */
2026 } else if (cfg
->line_outs
== 3) { /* 6 channels */
2027 for(i
= 0; i
< cfg
->line_outs
; i
++) {
2028 nid
= cfg
->line_out_pins
[i
];
2030 /* config dac list */
2032 case AUTO_SEQ_FRONT
:
2034 spec
->multiout
.dac_nids
[i
] = 0x10;
2036 case AUTO_SEQ_CENLFE
:
2038 spec
->multiout
.dac_nids
[i
] = 0x12;
2040 case AUTO_SEQ_SURROUND
:
2042 spec
->multiout
.dac_nids
[i
] = 0x11;
2054 /* add playback controls from the parsed DAC table */
2055 static int vt1709_auto_create_multi_out_ctls(struct via_spec
*spec
,
2056 const struct auto_pin_cfg
*cfg
)
2059 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2063 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2064 nid
= cfg
->line_out_pins
[i
];
2069 if (i
== AUTO_SEQ_CENLFE
) {
2071 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2072 "Center Playback Volume",
2073 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
2077 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2078 "LFE Playback Volume",
2079 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
2083 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2084 "Center Playback Switch",
2085 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
2089 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2090 "LFE Playback Switch",
2091 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
2095 } else if (i
== AUTO_SEQ_FRONT
){
2096 /* add control to mixer index 0 */
2097 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2098 "Master Front Playback Volume",
2099 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
2103 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2104 "Master Front Playback Switch",
2105 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
2110 /* add control to PW3 */
2111 sprintf(name
, "%s Playback Volume", chname
[i
]);
2112 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2113 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2117 sprintf(name
, "%s Playback Switch", chname
[i
]);
2118 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2119 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2123 } else if (i
== AUTO_SEQ_SURROUND
) {
2124 sprintf(name
, "%s Playback Volume", chname
[i
]);
2125 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2126 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
2130 sprintf(name
, "%s Playback Switch", chname
[i
]);
2131 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2132 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
2136 } else if (i
== AUTO_SEQ_SIDE
) {
2137 sprintf(name
, "%s Playback Volume", chname
[i
]);
2138 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2139 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
2143 sprintf(name
, "%s Playback Switch", chname
[i
]);
2144 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2145 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
2155 static int vt1709_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2162 if (spec
->multiout
.num_dacs
== 5) /* 10 channels */
2163 spec
->multiout
.hp_nid
= VT1709_HP_DAC_NID
;
2164 else if (spec
->multiout
.num_dacs
== 3) /* 6 channels */
2165 spec
->multiout
.hp_nid
= 0;
2166 spec
->hp_independent_mode_index
= 1;
2168 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2169 "Headphone Playback Volume",
2170 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2173 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2174 "Headphone Playback Switch",
2175 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2182 /* create playback/capture controls for input pins */
2183 static int vt1709_auto_create_analog_input_ctls(struct via_spec
*spec
,
2184 const struct auto_pin_cfg
*cfg
)
2186 static char *labels
[] = {
2187 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2189 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2190 int i
, err
, idx
= 0;
2192 /* for internal loopback recording select */
2193 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2194 imux
->items
[imux
->num_items
].index
= idx
;
2197 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2198 if (!cfg
->input_pins
[i
])
2201 switch (cfg
->input_pins
[i
]) {
2202 case 0x1d: /* Mic */
2206 case 0x1e: /* Line In */
2210 case 0x21: /* Front Mic */
2218 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x18);
2221 imux
->items
[imux
->num_items
].label
= labels
[i
];
2222 imux
->items
[imux
->num_items
].index
= idx
;
2228 static int vt1709_parse_auto_config(struct hda_codec
*codec
)
2230 struct via_spec
*spec
= codec
->spec
;
2233 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2236 err
= vt1709_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2239 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2240 return 0; /* can't find valid BIOS pin config */
2242 err
= vt1709_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2245 err
= vt1709_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2248 err
= vt1709_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2252 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2254 if (spec
->autocfg
.dig_outs
)
2255 spec
->multiout
.dig_out_nid
= VT1709_DIGOUT_NID
;
2256 spec
->dig_in_pin
= VT1709_DIGIN_PIN
;
2257 if (spec
->autocfg
.dig_in_pin
)
2258 spec
->dig_in_nid
= VT1709_DIGIN_NID
;
2260 if (spec
->kctls
.list
)
2261 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2263 spec
->input_mux
= &spec
->private_imux
[0];
2266 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2268 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
2272 #ifdef CONFIG_SND_HDA_POWER_SAVE
2273 static struct hda_amp_list vt1709_loopbacks
[] = {
2274 { 0x18, HDA_INPUT
, 1 },
2275 { 0x18, HDA_INPUT
, 2 },
2276 { 0x18, HDA_INPUT
, 3 },
2277 { 0x18, HDA_INPUT
, 4 },
2282 static int patch_vt1709_10ch(struct hda_codec
*codec
)
2284 struct via_spec
*spec
;
2287 /* create a codec specific record */
2288 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2294 err
= vt1709_parse_auto_config(codec
);
2299 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
2300 "Using genenic mode...\n");
2303 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_10ch_volume_init_verbs
;
2304 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
2306 spec
->stream_name_analog
= "VT1709 Analog";
2307 spec
->stream_analog_playback
= &vt1709_10ch_pcm_analog_playback
;
2308 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
2310 spec
->stream_name_digital
= "VT1709 Digital";
2311 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
2312 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
2315 if (!spec
->adc_nids
&& spec
->input_mux
) {
2316 spec
->adc_nids
= vt1709_adc_nids
;
2317 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
2318 get_mux_nids(codec
);
2319 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
2323 codec
->patch_ops
= via_patch_ops
;
2325 codec
->patch_ops
.init
= via_auto_init
;
2326 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2327 #ifdef CONFIG_SND_HDA_POWER_SAVE
2328 spec
->loopback
.amplist
= vt1709_loopbacks
;
2334 * generic initialization of ADC, input mixers and output mixers
2336 static struct hda_verb vt1709_6ch_volume_init_verbs
[] = {
2338 * Unmute ADC0-2 and set the default input to mic-in
2340 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2341 {0x15, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2342 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2345 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2348 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2349 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2350 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2351 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2352 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2353 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2356 * Set up output selector (0x1a, 0x1b, 0x29)
2358 /* set vol=0 to output mixers */
2359 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2360 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2361 {0x29, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2364 * Unmute PW3 and PW4
2366 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2367 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2369 /* Set input of PW4 as MW0 */
2370 {0x20, AC_VERB_SET_CONNECT_SEL
, 0},
2371 /* PW9 Output enable */
2372 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2376 static int patch_vt1709_6ch(struct hda_codec
*codec
)
2378 struct via_spec
*spec
;
2381 /* create a codec specific record */
2382 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2388 err
= vt1709_parse_auto_config(codec
);
2393 printk(KERN_INFO
"hda_codec: Cannot set up configuration. "
2394 "Using genenic mode...\n");
2397 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_6ch_volume_init_verbs
;
2398 spec
->init_verbs
[spec
->num_iverbs
++] = vt1709_uniwill_init_verbs
;
2400 spec
->stream_name_analog
= "VT1709 Analog";
2401 spec
->stream_analog_playback
= &vt1709_6ch_pcm_analog_playback
;
2402 spec
->stream_analog_capture
= &vt1709_pcm_analog_capture
;
2404 spec
->stream_name_digital
= "VT1709 Digital";
2405 spec
->stream_digital_playback
= &vt1709_pcm_digital_playback
;
2406 spec
->stream_digital_capture
= &vt1709_pcm_digital_capture
;
2409 if (!spec
->adc_nids
&& spec
->input_mux
) {
2410 spec
->adc_nids
= vt1709_adc_nids
;
2411 spec
->num_adc_nids
= ARRAY_SIZE(vt1709_adc_nids
);
2412 get_mux_nids(codec
);
2413 spec
->mixers
[spec
->num_mixers
] = vt1709_capture_mixer
;
2417 codec
->patch_ops
= via_patch_ops
;
2419 codec
->patch_ops
.init
= via_auto_init
;
2420 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2421 #ifdef CONFIG_SND_HDA_POWER_SAVE
2422 spec
->loopback
.amplist
= vt1709_loopbacks
;
2427 /* capture mixer elements */
2428 static struct snd_kcontrol_new vt1708B_capture_mixer
[] = {
2429 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
2430 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
2431 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
2432 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
2434 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2435 /* The multiple "Capture Source" controls confuse alsamixer
2436 * So call somewhat different..
2438 /* .name = "Capture Source", */
2439 .name
= "Input Source",
2441 .info
= via_mux_enum_info
,
2442 .get
= via_mux_enum_get
,
2443 .put
= via_mux_enum_put
,
2448 * generic initialization of ADC, input mixers and output mixers
2450 static struct hda_verb vt1708B_8ch_volume_init_verbs
[] = {
2452 * Unmute ADC0-1 and set the default input to mic-in
2454 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2455 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2458 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2461 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2462 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2463 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2464 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2465 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2466 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2469 * Set up output mixers
2471 /* set vol=0 to output mixers */
2472 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2473 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2474 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2476 /* Setup default input to PW4 */
2477 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x1},
2478 /* PW9 Output enable */
2479 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2480 /* PW10 Input enable */
2481 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2485 static struct hda_verb vt1708B_4ch_volume_init_verbs
[] = {
2487 * Unmute ADC0-1 and set the default input to mic-in
2489 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2490 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2493 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2496 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2497 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
2498 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
2499 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
2500 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
2501 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
2504 * Set up output mixers
2506 /* set vol=0 to output mixers */
2507 {0x18, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2508 {0x26, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2509 {0x27, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
},
2511 /* Setup default input of PW4 to MW0 */
2512 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
2513 /* PW9 Output enable */
2514 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
2515 /* PW10 Input enable */
2516 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x20},
2520 static struct hda_verb vt1708B_uniwill_init_verbs
[] = {
2521 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
2522 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
2523 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2524 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2525 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2526 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2527 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2528 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2529 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
2533 static int via_pcm_open_close(struct hda_pcm_stream
*hinfo
,
2534 struct hda_codec
*codec
,
2535 struct snd_pcm_substream
*substream
)
2537 int idle
= substream
->pstr
->substream_opened
== 1
2538 && substream
->ref_count
== 0;
2540 analog_low_current_mode(codec
, idle
);
2544 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback
= {
2548 .nid
= 0x10, /* NID to query formats and rates */
2550 .open
= via_playback_pcm_open
,
2551 .prepare
= via_playback_multi_pcm_prepare
,
2552 .cleanup
= via_playback_multi_pcm_cleanup
,
2553 .close
= via_pcm_open_close
2557 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback
= {
2561 .nid
= 0x10, /* NID to query formats and rates */
2563 .open
= via_playback_pcm_open
,
2564 .prepare
= via_playback_multi_pcm_prepare
,
2565 .cleanup
= via_playback_multi_pcm_cleanup
2569 static struct hda_pcm_stream vt1708B_pcm_analog_capture
= {
2573 .nid
= 0x13, /* NID to query formats and rates */
2575 .open
= via_pcm_open_close
,
2576 .prepare
= via_capture_pcm_prepare
,
2577 .cleanup
= via_capture_pcm_cleanup
,
2578 .close
= via_pcm_open_close
2582 static struct hda_pcm_stream vt1708B_pcm_digital_playback
= {
2586 /* NID is set in via_build_pcms */
2588 .open
= via_dig_playback_pcm_open
,
2589 .close
= via_dig_playback_pcm_close
,
2590 .prepare
= via_dig_playback_pcm_prepare
,
2591 .cleanup
= via_dig_playback_pcm_cleanup
2595 static struct hda_pcm_stream vt1708B_pcm_digital_capture
= {
2601 /* fill in the dac_nids table from the parsed pin configuration */
2602 static int vt1708B_auto_fill_dac_nids(struct via_spec
*spec
,
2603 const struct auto_pin_cfg
*cfg
)
2608 spec
->multiout
.num_dacs
= cfg
->line_outs
;
2610 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
2612 for (i
= 0; i
< 4; i
++) {
2613 nid
= cfg
->line_out_pins
[i
];
2615 /* config dac list */
2617 case AUTO_SEQ_FRONT
:
2618 spec
->multiout
.dac_nids
[i
] = 0x10;
2620 case AUTO_SEQ_CENLFE
:
2621 spec
->multiout
.dac_nids
[i
] = 0x24;
2623 case AUTO_SEQ_SURROUND
:
2624 spec
->multiout
.dac_nids
[i
] = 0x11;
2627 spec
->multiout
.dac_nids
[i
] = 0x25;
2636 /* add playback controls from the parsed DAC table */
2637 static int vt1708B_auto_create_multi_out_ctls(struct via_spec
*spec
,
2638 const struct auto_pin_cfg
*cfg
)
2641 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
2642 hda_nid_t nid_vols
[] = {0x16, 0x18, 0x26, 0x27};
2643 hda_nid_t nid
, nid_vol
= 0;
2646 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
2647 nid
= cfg
->line_out_pins
[i
];
2652 nid_vol
= nid_vols
[i
];
2654 if (i
== AUTO_SEQ_CENLFE
) {
2656 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2657 "Center Playback Volume",
2658 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2662 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2663 "LFE Playback Volume",
2664 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2668 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2669 "Center Playback Switch",
2670 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
2674 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2675 "LFE Playback Switch",
2676 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
2680 } else if (i
== AUTO_SEQ_FRONT
) {
2681 /* add control to mixer index 0 */
2682 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2683 "Master Front Playback Volume",
2684 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2688 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2689 "Master Front Playback Switch",
2690 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2695 /* add control to PW3 */
2696 sprintf(name
, "%s Playback Volume", chname
[i
]);
2697 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2698 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2702 sprintf(name
, "%s Playback Switch", chname
[i
]);
2703 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2704 HDA_COMPOSE_AMP_VAL(nid
, 3, 0,
2709 sprintf(name
, "%s Playback Volume", chname
[i
]);
2710 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
2711 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2715 sprintf(name
, "%s Playback Switch", chname
[i
]);
2716 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
2717 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
2727 static int vt1708B_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
2734 spec
->multiout
.hp_nid
= VT1708B_HP_NID
; /* AOW3 */
2735 spec
->hp_independent_mode_index
= 1;
2737 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
2738 "Headphone Playback Volume",
2739 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2742 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
2743 "Headphone Playback Switch",
2744 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
2748 create_hp_imux(spec
);
2753 /* create playback/capture controls for input pins */
2754 static int vt1708B_auto_create_analog_input_ctls(struct via_spec
*spec
,
2755 const struct auto_pin_cfg
*cfg
)
2757 static char *labels
[] = {
2758 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2760 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
2761 int i
, err
, idx
= 0;
2763 /* for internal loopback recording select */
2764 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
2765 imux
->items
[imux
->num_items
].index
= idx
;
2768 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
2769 if (!cfg
->input_pins
[i
])
2772 switch (cfg
->input_pins
[i
]) {
2773 case 0x1a: /* Mic */
2777 case 0x1b: /* Line In */
2781 case 0x1e: /* Front Mic */
2789 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
2792 imux
->items
[imux
->num_items
].label
= labels
[i
];
2793 imux
->items
[imux
->num_items
].index
= idx
;
2799 static int vt1708B_parse_auto_config(struct hda_codec
*codec
)
2801 struct via_spec
*spec
= codec
->spec
;
2804 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
2807 err
= vt1708B_auto_fill_dac_nids(spec
, &spec
->autocfg
);
2810 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
2811 return 0; /* can't find valid BIOS pin config */
2813 err
= vt1708B_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
2816 err
= vt1708B_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
2819 err
= vt1708B_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
2823 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
2825 if (spec
->autocfg
.dig_outs
)
2826 spec
->multiout
.dig_out_nid
= VT1708B_DIGOUT_NID
;
2827 spec
->dig_in_pin
= VT1708B_DIGIN_PIN
;
2828 if (spec
->autocfg
.dig_in_pin
)
2829 spec
->dig_in_nid
= VT1708B_DIGIN_NID
;
2831 if (spec
->kctls
.list
)
2832 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
2834 spec
->input_mux
= &spec
->private_imux
[0];
2837 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
2839 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
2843 #ifdef CONFIG_SND_HDA_POWER_SAVE
2844 static struct hda_amp_list vt1708B_loopbacks
[] = {
2845 { 0x16, HDA_INPUT
, 1 },
2846 { 0x16, HDA_INPUT
, 2 },
2847 { 0x16, HDA_INPUT
, 3 },
2848 { 0x16, HDA_INPUT
, 4 },
2852 static int patch_vt1708S(struct hda_codec
*codec
);
2853 static int patch_vt1708B_8ch(struct hda_codec
*codec
)
2855 struct via_spec
*spec
;
2858 if (get_codec_type(codec
) == VT1708BCE
)
2859 return patch_vt1708S(codec
);
2860 /* create a codec specific record */
2861 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2867 /* automatic parse from the BIOS config */
2868 err
= vt1708B_parse_auto_config(codec
);
2873 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2874 "from BIOS. Using genenic mode...\n");
2877 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_8ch_volume_init_verbs
;
2878 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2880 spec
->stream_name_analog
= "VT1708B Analog";
2881 spec
->stream_analog_playback
= &vt1708B_8ch_pcm_analog_playback
;
2882 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2884 spec
->stream_name_digital
= "VT1708B Digital";
2885 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2886 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2888 if (!spec
->adc_nids
&& spec
->input_mux
) {
2889 spec
->adc_nids
= vt1708B_adc_nids
;
2890 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2891 get_mux_nids(codec
);
2892 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2896 codec
->patch_ops
= via_patch_ops
;
2898 codec
->patch_ops
.init
= via_auto_init
;
2899 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2900 #ifdef CONFIG_SND_HDA_POWER_SAVE
2901 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2907 static int patch_vt1708B_4ch(struct hda_codec
*codec
)
2909 struct via_spec
*spec
;
2912 /* create a codec specific record */
2913 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
2919 /* automatic parse from the BIOS config */
2920 err
= vt1708B_parse_auto_config(codec
);
2925 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
2926 "from BIOS. Using genenic mode...\n");
2929 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_4ch_volume_init_verbs
;
2930 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708B_uniwill_init_verbs
;
2932 spec
->stream_name_analog
= "VT1708B Analog";
2933 spec
->stream_analog_playback
= &vt1708B_4ch_pcm_analog_playback
;
2934 spec
->stream_analog_capture
= &vt1708B_pcm_analog_capture
;
2936 spec
->stream_name_digital
= "VT1708B Digital";
2937 spec
->stream_digital_playback
= &vt1708B_pcm_digital_playback
;
2938 spec
->stream_digital_capture
= &vt1708B_pcm_digital_capture
;
2940 if (!spec
->adc_nids
&& spec
->input_mux
) {
2941 spec
->adc_nids
= vt1708B_adc_nids
;
2942 spec
->num_adc_nids
= ARRAY_SIZE(vt1708B_adc_nids
);
2943 get_mux_nids(codec
);
2944 spec
->mixers
[spec
->num_mixers
] = vt1708B_capture_mixer
;
2948 codec
->patch_ops
= via_patch_ops
;
2950 codec
->patch_ops
.init
= via_auto_init
;
2951 codec
->patch_ops
.unsol_event
= via_unsol_event
;
2952 #ifdef CONFIG_SND_HDA_POWER_SAVE
2953 spec
->loopback
.amplist
= vt1708B_loopbacks
;
2959 /* Patch for VT1708S */
2961 /* VT1708S software backdoor based override for buggy hardware micboost
2963 #define MIC_BOOST_VOLUME(xname, nid) { \
2964 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2967 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2968 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2969 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2970 .info = mic_boost_volume_info, \
2971 .get = snd_hda_mixer_amp_volume_get, \
2972 .put = snd_hda_mixer_amp_volume_put, \
2973 .tlv = { .c = mic_boost_tlv }, \
2974 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2976 /* capture mixer elements */
2977 static struct snd_kcontrol_new vt1708S_capture_mixer
[] = {
2978 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT
),
2979 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT
),
2980 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT
),
2981 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT
),
2982 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2983 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2985 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2986 /* The multiple "Capture Source" controls confuse alsamixer
2987 * So call somewhat different..
2989 /* .name = "Capture Source", */
2990 .name
= "Input Source",
2992 .info
= via_mux_enum_info
,
2993 .get
= via_mux_enum_get
,
2994 .put
= via_mux_enum_put
,
2999 static struct hda_verb vt1708S_volume_init_verbs
[] = {
3000 /* Unmute ADC0-1 and set the default input to mic-in */
3001 {0x13, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3002 {0x14, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3004 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3005 * analog-loopback mixer widget */
3006 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3007 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3008 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3009 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3010 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3011 {0x16, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(4)},
3013 /* Setup default input of PW4 to MW0 */
3014 {0x1d, AC_VERB_SET_CONNECT_SEL
, 0x0},
3015 /* PW9, PW10 Output enable */
3016 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3017 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3018 /* Enable Mic Boost Volume backdoor */
3023 static struct hda_verb vt1708S_uniwill_init_verbs
[] = {
3024 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE
,
3025 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
3026 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3027 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3028 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3029 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3030 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3031 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3032 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3036 static struct hda_pcm_stream vt1708S_pcm_analog_playback
= {
3040 .nid
= 0x10, /* NID to query formats and rates */
3042 .open
= via_playback_pcm_open
,
3043 .prepare
= via_playback_pcm_prepare
,
3044 .cleanup
= via_playback_pcm_cleanup
,
3045 .close
= via_pcm_open_close
3049 static struct hda_pcm_stream vt1708S_pcm_analog_capture
= {
3053 .nid
= 0x13, /* NID to query formats and rates */
3055 .open
= via_pcm_open_close
,
3056 .prepare
= via_capture_pcm_prepare
,
3057 .cleanup
= via_capture_pcm_cleanup
,
3058 .close
= via_pcm_open_close
3062 static struct hda_pcm_stream vt1708S_pcm_digital_playback
= {
3066 /* NID is set in via_build_pcms */
3068 .open
= via_dig_playback_pcm_open
,
3069 .close
= via_dig_playback_pcm_close
,
3070 .prepare
= via_dig_playback_pcm_prepare
,
3071 .cleanup
= via_dig_playback_pcm_cleanup
3075 /* fill in the dac_nids table from the parsed pin configuration */
3076 static int vt1708S_auto_fill_dac_nids(struct via_spec
*spec
,
3077 const struct auto_pin_cfg
*cfg
)
3082 spec
->multiout
.num_dacs
= cfg
->line_outs
;
3084 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3086 for (i
= 0; i
< 4; i
++) {
3087 nid
= cfg
->line_out_pins
[i
];
3089 /* config dac list */
3091 case AUTO_SEQ_FRONT
:
3092 spec
->multiout
.dac_nids
[i
] = 0x10;
3094 case AUTO_SEQ_CENLFE
:
3095 spec
->multiout
.dac_nids
[i
] = 0x24;
3097 case AUTO_SEQ_SURROUND
:
3098 spec
->multiout
.dac_nids
[i
] = 0x11;
3101 spec
->multiout
.dac_nids
[i
] = 0x25;
3110 /* add playback controls from the parsed DAC table */
3111 static int vt1708S_auto_create_multi_out_ctls(struct via_spec
*spec
,
3112 const struct auto_pin_cfg
*cfg
)
3115 static const char *chname
[4] = { "Front", "Surround", "C/LFE", "Side" };
3116 hda_nid_t nid_vols
[] = {0x10, 0x11, 0x24, 0x25};
3117 hda_nid_t nid_mutes
[] = {0x1C, 0x18, 0x26, 0x27};
3118 hda_nid_t nid
, nid_vol
, nid_mute
;
3121 for (i
= 0; i
<= AUTO_SEQ_SIDE
; i
++) {
3122 nid
= cfg
->line_out_pins
[i
];
3127 nid_vol
= nid_vols
[i
];
3128 nid_mute
= nid_mutes
[i
];
3130 if (i
== AUTO_SEQ_CENLFE
) {
3132 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3133 "Center Playback Volume",
3134 HDA_COMPOSE_AMP_VAL(nid_vol
, 1, 0,
3138 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3139 "LFE Playback Volume",
3140 HDA_COMPOSE_AMP_VAL(nid_vol
, 2, 0,
3144 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3145 "Center Playback Switch",
3146 HDA_COMPOSE_AMP_VAL(nid_mute
,
3151 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3152 "LFE Playback Switch",
3153 HDA_COMPOSE_AMP_VAL(nid_mute
,
3158 } else if (i
== AUTO_SEQ_FRONT
) {
3159 /* add control to mixer index 0 */
3160 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3161 "Master Front Playback Volume",
3162 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3166 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3167 "Master Front Playback Switch",
3168 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3174 sprintf(name
, "%s Playback Volume", chname
[i
]);
3175 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3176 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3180 sprintf(name
, "%s Playback Switch", chname
[i
]);
3181 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3182 HDA_COMPOSE_AMP_VAL(nid_mute
,
3188 sprintf(name
, "%s Playback Volume", chname
[i
]);
3189 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
, name
,
3190 HDA_COMPOSE_AMP_VAL(nid_vol
, 3, 0,
3194 sprintf(name
, "%s Playback Switch", chname
[i
]);
3195 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
, name
,
3196 HDA_COMPOSE_AMP_VAL(nid_mute
,
3207 static int vt1708S_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3214 spec
->multiout
.hp_nid
= VT1708S_HP_NID
; /* AOW3 */
3215 spec
->hp_independent_mode_index
= 1;
3217 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3218 "Headphone Playback Volume",
3219 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT
));
3223 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3224 "Headphone Playback Switch",
3225 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3229 create_hp_imux(spec
);
3234 /* create playback/capture controls for input pins */
3235 static int vt1708S_auto_create_analog_input_ctls(struct via_spec
*spec
,
3236 const struct auto_pin_cfg
*cfg
)
3238 static char *labels
[] = {
3239 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3241 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3242 int i
, err
, idx
= 0;
3244 /* for internal loopback recording select */
3245 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3246 imux
->items
[imux
->num_items
].index
= 5;
3249 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3250 if (!cfg
->input_pins
[i
])
3253 switch (cfg
->input_pins
[i
]) {
3254 case 0x1a: /* Mic */
3258 case 0x1b: /* Line In */
3262 case 0x1e: /* Front Mic */
3270 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x16);
3273 imux
->items
[imux
->num_items
].label
= labels
[i
];
3274 imux
->items
[imux
->num_items
].index
= idx
-1;
3280 /* fill out digital output widgets; one for master and one for slave outputs */
3281 static void fill_dig_outs(struct hda_codec
*codec
)
3283 struct via_spec
*spec
= codec
->spec
;
3286 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
3290 nid
= spec
->autocfg
.dig_out_pins
[i
];
3293 conn
= snd_hda_get_connections(codec
, nid
, &nid
, 1);
3296 if (!spec
->multiout
.dig_out_nid
)
3297 spec
->multiout
.dig_out_nid
= nid
;
3299 spec
->slave_dig_outs
[0] = nid
;
3300 break; /* at most two dig outs */
3305 static int vt1708S_parse_auto_config(struct hda_codec
*codec
)
3307 struct via_spec
*spec
= codec
->spec
;
3310 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3313 err
= vt1708S_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3316 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3317 return 0; /* can't find valid BIOS pin config */
3319 err
= vt1708S_auto_create_multi_out_ctls(spec
, &spec
->autocfg
);
3322 err
= vt1708S_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3325 err
= vt1708S_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3329 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3331 fill_dig_outs(codec
);
3333 if (spec
->kctls
.list
)
3334 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3336 spec
->input_mux
= &spec
->private_imux
[0];
3339 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3341 spec
->mixers
[spec
->num_mixers
++] = via_smart51_mixer
;
3345 #ifdef CONFIG_SND_HDA_POWER_SAVE
3346 static struct hda_amp_list vt1708S_loopbacks
[] = {
3347 { 0x16, HDA_INPUT
, 1 },
3348 { 0x16, HDA_INPUT
, 2 },
3349 { 0x16, HDA_INPUT
, 3 },
3350 { 0x16, HDA_INPUT
, 4 },
3355 static int patch_vt1708S(struct hda_codec
*codec
)
3357 struct via_spec
*spec
;
3360 /* create a codec specific record */
3361 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3367 /* automatic parse from the BIOS config */
3368 err
= vt1708S_parse_auto_config(codec
);
3373 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3374 "from BIOS. Using genenic mode...\n");
3377 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_volume_init_verbs
;
3378 spec
->init_verbs
[spec
->num_iverbs
++] = vt1708S_uniwill_init_verbs
;
3380 spec
->stream_name_analog
= "VT1708S Analog";
3381 spec
->stream_analog_playback
= &vt1708S_pcm_analog_playback
;
3382 spec
->stream_analog_capture
= &vt1708S_pcm_analog_capture
;
3384 spec
->stream_name_digital
= "VT1708S Digital";
3385 spec
->stream_digital_playback
= &vt1708S_pcm_digital_playback
;
3387 if (!spec
->adc_nids
&& spec
->input_mux
) {
3388 spec
->adc_nids
= vt1708S_adc_nids
;
3389 spec
->num_adc_nids
= ARRAY_SIZE(vt1708S_adc_nids
);
3390 get_mux_nids(codec
);
3391 spec
->mixers
[spec
->num_mixers
] = vt1708S_capture_mixer
;
3395 codec
->patch_ops
= via_patch_ops
;
3397 codec
->patch_ops
.init
= via_auto_init
;
3398 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3399 #ifdef CONFIG_SND_HDA_POWER_SAVE
3400 spec
->loopback
.amplist
= vt1708S_loopbacks
;
3403 /* correct names for VT1708BCE */
3404 if (get_codec_type(codec
) == VT1708BCE
) {
3405 kfree(codec
->chip_name
);
3406 codec
->chip_name
= kstrdup("VT1708BCE", GFP_KERNEL
);
3407 snprintf(codec
->bus
->card
->mixername
,
3408 sizeof(codec
->bus
->card
->mixername
),
3409 "%s %s", codec
->vendor_name
, codec
->chip_name
);
3410 spec
->stream_name_analog
= "VT1708BCE Analog";
3411 spec
->stream_name_digital
= "VT1708BCE Digital";
3416 /* Patch for VT1702 */
3418 /* capture mixer elements */
3419 static struct snd_kcontrol_new vt1702_capture_mixer
[] = {
3420 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT
),
3421 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT
),
3422 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT
),
3423 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT
),
3424 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT
),
3425 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT
),
3426 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3429 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3430 /* The multiple "Capture Source" controls confuse alsamixer
3431 * So call somewhat different..
3433 /* .name = "Capture Source", */
3434 .name
= "Input Source",
3436 .info
= via_mux_enum_info
,
3437 .get
= via_mux_enum_get
,
3438 .put
= via_mux_enum_put
,
3443 static struct hda_verb vt1702_volume_init_verbs
[] = {
3445 * Unmute ADC0-1 and set the default input to mic-in
3447 {0x12, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3448 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3449 {0x20, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3452 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3455 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3456 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(0)},
3457 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(1)},
3458 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(2)},
3459 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_UNMUTE(3)},
3460 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE
, AMP_IN_MUTE(4)},
3462 /* Setup default input of PW4 to MW0 */
3463 {0x17, AC_VERB_SET_CONNECT_SEL
, 0x1},
3464 /* PW6 PW7 Output enable */
3465 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3466 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL
, 0x40},
3470 static struct hda_verb vt1702_uniwill_init_verbs
[] = {
3471 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE
,
3472 AC_USRSP_EN
| VIA_HP_EVENT
| VIA_JACK_EVENT
},
3473 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3474 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3475 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3476 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| VIA_JACK_EVENT
},
3480 static struct hda_pcm_stream vt1702_pcm_analog_playback
= {
3484 .nid
= 0x10, /* NID to query formats and rates */
3486 .open
= via_playback_pcm_open
,
3487 .prepare
= via_playback_multi_pcm_prepare
,
3488 .cleanup
= via_playback_multi_pcm_cleanup
,
3489 .close
= via_pcm_open_close
3493 static struct hda_pcm_stream vt1702_pcm_analog_capture
= {
3497 .nid
= 0x12, /* NID to query formats and rates */
3499 .open
= via_pcm_open_close
,
3500 .prepare
= via_capture_pcm_prepare
,
3501 .cleanup
= via_capture_pcm_cleanup
,
3502 .close
= via_pcm_open_close
3506 static struct hda_pcm_stream vt1702_pcm_digital_playback
= {
3510 /* NID is set in via_build_pcms */
3512 .open
= via_dig_playback_pcm_open
,
3513 .close
= via_dig_playback_pcm_close
,
3514 .prepare
= via_dig_playback_pcm_prepare
,
3515 .cleanup
= via_dig_playback_pcm_cleanup
3519 /* fill in the dac_nids table from the parsed pin configuration */
3520 static int vt1702_auto_fill_dac_nids(struct via_spec
*spec
,
3521 const struct auto_pin_cfg
*cfg
)
3523 spec
->multiout
.num_dacs
= 1;
3524 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
3526 if (cfg
->line_out_pins
[0]) {
3527 /* config dac list */
3528 spec
->multiout
.dac_nids
[0] = 0x10;
3534 /* add playback controls from the parsed DAC table */
3535 static int vt1702_auto_create_line_out_ctls(struct via_spec
*spec
,
3536 const struct auto_pin_cfg
*cfg
)
3540 if (!cfg
->line_out_pins
[0])
3543 /* add control to mixer index 0 */
3544 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3545 "Master Front Playback Volume",
3546 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3549 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3550 "Master Front Playback Switch",
3551 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT
));
3556 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3557 "Front Playback Volume",
3558 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT
));
3561 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3562 "Front Playback Switch",
3563 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT
));
3570 static int vt1702_auto_create_hp_ctls(struct via_spec
*spec
, hda_nid_t pin
)
3573 struct hda_input_mux
*imux
;
3574 static const char *texts
[] = { "ON", "OFF", NULL
};
3577 spec
->multiout
.hp_nid
= 0x1D;
3578 spec
->hp_independent_mode_index
= 0;
3580 err
= via_add_control(spec
, VIA_CTL_WIDGET_VOL
,
3581 "Headphone Playback Volume",
3582 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT
));
3586 err
= via_add_control(spec
, VIA_CTL_WIDGET_MUTE
,
3587 "Headphone Playback Switch",
3588 HDA_COMPOSE_AMP_VAL(pin
, 3, 0, HDA_OUTPUT
));
3592 imux
= &spec
->private_imux
[1];
3594 /* for hp mode select */
3596 while (texts
[i
] != NULL
) {
3597 imux
->items
[imux
->num_items
].label
= texts
[i
];
3598 imux
->items
[imux
->num_items
].index
= i
;
3603 spec
->hp_mux
= &spec
->private_imux
[1];
3607 /* create playback/capture controls for input pins */
3608 static int vt1702_auto_create_analog_input_ctls(struct via_spec
*spec
,
3609 const struct auto_pin_cfg
*cfg
)
3611 static char *labels
[] = {
3612 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3614 struct hda_input_mux
*imux
= &spec
->private_imux
[0];
3615 int i
, err
, idx
= 0;
3617 /* for internal loopback recording select */
3618 imux
->items
[imux
->num_items
].label
= "Stereo Mixer";
3619 imux
->items
[imux
->num_items
].index
= 3;
3622 for (i
= 0; i
< AUTO_PIN_LAST
; i
++) {
3623 if (!cfg
->input_pins
[i
])
3626 switch (cfg
->input_pins
[i
]) {
3627 case 0x14: /* Mic */
3631 case 0x15: /* Line In */
3635 case 0x18: /* Front Mic */
3639 err
= via_new_analog_input(spec
, labels
[i
], idx
, 0x1A);
3642 imux
->items
[imux
->num_items
].label
= labels
[i
];
3643 imux
->items
[imux
->num_items
].index
= idx
-1;
3649 static int vt1702_parse_auto_config(struct hda_codec
*codec
)
3651 struct via_spec
*spec
= codec
->spec
;
3654 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
3657 err
= vt1702_auto_fill_dac_nids(spec
, &spec
->autocfg
);
3660 if (!spec
->autocfg
.line_outs
&& !spec
->autocfg
.hp_pins
[0])
3661 return 0; /* can't find valid BIOS pin config */
3663 err
= vt1702_auto_create_line_out_ctls(spec
, &spec
->autocfg
);
3666 err
= vt1702_auto_create_hp_ctls(spec
, spec
->autocfg
.hp_pins
[0]);
3669 /* limit AA path volume to 0 dB */
3670 snd_hda_override_amp_caps(codec
, 0x1A, HDA_INPUT
,
3671 (0x17 << AC_AMPCAP_OFFSET_SHIFT
) |
3672 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT
) |
3673 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT
) |
3674 (1 << AC_AMPCAP_MUTE_SHIFT
));
3675 err
= vt1702_auto_create_analog_input_ctls(spec
, &spec
->autocfg
);
3679 spec
->multiout
.max_channels
= spec
->multiout
.num_dacs
* 2;
3681 fill_dig_outs(codec
);
3683 if (spec
->kctls
.list
)
3684 spec
->mixers
[spec
->num_mixers
++] = spec
->kctls
.list
;
3686 spec
->input_mux
= &spec
->private_imux
[0];
3689 spec
->mixers
[spec
->num_mixers
++] = via_hp_mixer
;
3694 #ifdef CONFIG_SND_HDA_POWER_SAVE
3695 static struct hda_amp_list vt1702_loopbacks
[] = {
3696 { 0x1A, HDA_INPUT
, 1 },
3697 { 0x1A, HDA_INPUT
, 2 },
3698 { 0x1A, HDA_INPUT
, 3 },
3699 { 0x1A, HDA_INPUT
, 4 },
3704 static int patch_vt1702(struct hda_codec
*codec
)
3706 struct via_spec
*spec
;
3708 unsigned int response
;
3709 unsigned char control
;
3711 /* create a codec specific record */
3712 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
3718 /* automatic parse from the BIOS config */
3719 err
= vt1702_parse_auto_config(codec
);
3724 printk(KERN_INFO
"hda_codec: Cannot set up configuration "
3725 "from BIOS. Using genenic mode...\n");
3728 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_volume_init_verbs
;
3729 spec
->init_verbs
[spec
->num_iverbs
++] = vt1702_uniwill_init_verbs
;
3731 spec
->stream_name_analog
= "VT1702 Analog";
3732 spec
->stream_analog_playback
= &vt1702_pcm_analog_playback
;
3733 spec
->stream_analog_capture
= &vt1702_pcm_analog_capture
;
3735 spec
->stream_name_digital
= "VT1702 Digital";
3736 spec
->stream_digital_playback
= &vt1702_pcm_digital_playback
;
3738 if (!spec
->adc_nids
&& spec
->input_mux
) {
3739 spec
->adc_nids
= vt1702_adc_nids
;
3740 spec
->num_adc_nids
= ARRAY_SIZE(vt1702_adc_nids
);
3741 get_mux_nids(codec
);
3742 spec
->mixers
[spec
->num_mixers
] = vt1702_capture_mixer
;
3746 codec
->patch_ops
= via_patch_ops
;
3748 codec
->patch_ops
.init
= via_auto_init
;
3749 codec
->patch_ops
.unsol_event
= via_unsol_event
;
3750 #ifdef CONFIG_SND_HDA_POWER_SAVE
3751 spec
->loopback
.amplist
= vt1702_loopbacks
;
3755 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF8C, 0);
3756 control
= (unsigned char)(response
& 0xff);
3758 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF88, control
);
3760 /* Enable GPIO 0&1 for volume&mute control */
3761 /* Enable GPIO 2 for DMIC-DATA */
3762 response
= snd_hda_codec_read(codec
, codec
->afg
, 0, 0xF84, 0);
3763 control
= (unsigned char)((response
>> 16) & 0x3f);
3764 snd_hda_codec_write(codec
, codec
->afg
, 0, 0xF82, control
);
3772 static struct hda_codec_preset snd_hda_preset_via
[] = {
3773 { .id
= 0x11061708, .name
= "VT1708", .patch
= patch_vt1708
},
3774 { .id
= 0x11061709, .name
= "VT1708", .patch
= patch_vt1708
},
3775 { .id
= 0x1106170a, .name
= "VT1708", .patch
= patch_vt1708
},
3776 { .id
= 0x1106170b, .name
= "VT1708", .patch
= patch_vt1708
},
3777 { .id
= 0x1106e710, .name
= "VT1709 10-Ch",
3778 .patch
= patch_vt1709_10ch
},
3779 { .id
= 0x1106e711, .name
= "VT1709 10-Ch",
3780 .patch
= patch_vt1709_10ch
},
3781 { .id
= 0x1106e712, .name
= "VT1709 10-Ch",
3782 .patch
= patch_vt1709_10ch
},
3783 { .id
= 0x1106e713, .name
= "VT1709 10-Ch",
3784 .patch
= patch_vt1709_10ch
},
3785 { .id
= 0x1106e714, .name
= "VT1709 6-Ch",
3786 .patch
= patch_vt1709_6ch
},
3787 { .id
= 0x1106e715, .name
= "VT1709 6-Ch",
3788 .patch
= patch_vt1709_6ch
},
3789 { .id
= 0x1106e716, .name
= "VT1709 6-Ch",
3790 .patch
= patch_vt1709_6ch
},
3791 { .id
= 0x1106e717, .name
= "VT1709 6-Ch",
3792 .patch
= patch_vt1709_6ch
},
3793 { .id
= 0x1106e720, .name
= "VT1708B 8-Ch",
3794 .patch
= patch_vt1708B_8ch
},
3795 { .id
= 0x1106e721, .name
= "VT1708B 8-Ch",
3796 .patch
= patch_vt1708B_8ch
},
3797 { .id
= 0x1106e722, .name
= "VT1708B 8-Ch",
3798 .patch
= patch_vt1708B_8ch
},
3799 { .id
= 0x1106e723, .name
= "VT1708B 8-Ch",
3800 .patch
= patch_vt1708B_8ch
},
3801 { .id
= 0x1106e724, .name
= "VT1708B 4-Ch",
3802 .patch
= patch_vt1708B_4ch
},
3803 { .id
= 0x1106e725, .name
= "VT1708B 4-Ch",
3804 .patch
= patch_vt1708B_4ch
},
3805 { .id
= 0x1106e726, .name
= "VT1708B 4-Ch",
3806 .patch
= patch_vt1708B_4ch
},
3807 { .id
= 0x1106e727, .name
= "VT1708B 4-Ch",
3808 .patch
= patch_vt1708B_4ch
},
3809 { .id
= 0x11060397, .name
= "VT1708S",
3810 .patch
= patch_vt1708S
},
3811 { .id
= 0x11061397, .name
= "VT1708S",
3812 .patch
= patch_vt1708S
},
3813 { .id
= 0x11062397, .name
= "VT1708S",
3814 .patch
= patch_vt1708S
},
3815 { .id
= 0x11063397, .name
= "VT1708S",
3816 .patch
= patch_vt1708S
},
3817 { .id
= 0x11064397, .name
= "VT1708S",
3818 .patch
= patch_vt1708S
},
3819 { .id
= 0x11065397, .name
= "VT1708S",
3820 .patch
= patch_vt1708S
},
3821 { .id
= 0x11066397, .name
= "VT1708S",
3822 .patch
= patch_vt1708S
},
3823 { .id
= 0x11067397, .name
= "VT1708S",
3824 .patch
= patch_vt1708S
},
3825 { .id
= 0x11060398, .name
= "VT1702",
3826 .patch
= patch_vt1702
},
3827 { .id
= 0x11061398, .name
= "VT1702",
3828 .patch
= patch_vt1702
},
3829 { .id
= 0x11062398, .name
= "VT1702",
3830 .patch
= patch_vt1702
},
3831 { .id
= 0x11063398, .name
= "VT1702",
3832 .patch
= patch_vt1702
},
3833 { .id
= 0x11064398, .name
= "VT1702",
3834 .patch
= patch_vt1702
},
3835 { .id
= 0x11065398, .name
= "VT1702",
3836 .patch
= patch_vt1702
},
3837 { .id
= 0x11066398, .name
= "VT1702",
3838 .patch
= patch_vt1702
},
3839 { .id
= 0x11067398, .name
= "VT1702",
3840 .patch
= patch_vt1702
},
3844 MODULE_ALIAS("snd-hda-codec-id:1106*");
3846 static struct hda_codec_preset_list via_list
= {
3847 .preset
= snd_hda_preset_via
,
3848 .owner
= THIS_MODULE
,
3851 MODULE_LICENSE("GPL");
3852 MODULE_DESCRIPTION("VIA HD-audio codec");
3854 static int __init
patch_via_init(void)
3856 return snd_hda_add_codec_preset(&via_list
);
3859 static void __exit
patch_via_exit(void)
3861 snd_hda_delete_codec_preset(&via_list
);
3864 module_init(patch_via_init
)
3865 module_exit(patch_via_exit
)