ALSA: hda - Remove AUTO_PIN_FRONT_{MIC|LINE}
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / pci / hda / patch_via.c
blobde5f61d1b7257797a096b6202f77519f44c8b623
1 /*
2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
25 /* */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
45 /* */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <sound/core.h>
53 #include <sound/asoundef.h>
54 #include "hda_codec.h"
55 #include "hda_local.h"
57 #define NID_MAPPING (-1)
59 /* amp values */
60 #define AMP_VAL_IDX_SHIFT 19
61 #define AMP_VAL_IDX_MASK (0x0f<<19)
63 /* Pin Widget NID */
64 #define VT1708_HP_NID 0x13
65 #define VT1708_DIGOUT_NID 0x14
66 #define VT1708_DIGIN_NID 0x16
67 #define VT1708_DIGIN_PIN 0x26
68 #define VT1708_HP_PIN_NID 0x20
69 #define VT1708_CD_PIN_NID 0x24
71 #define VT1709_HP_DAC_NID 0x28
72 #define VT1709_DIGOUT_NID 0x13
73 #define VT1709_DIGIN_NID 0x17
74 #define VT1709_DIGIN_PIN 0x25
76 #define VT1708B_HP_NID 0x25
77 #define VT1708B_DIGOUT_NID 0x12
78 #define VT1708B_DIGIN_NID 0x15
79 #define VT1708B_DIGIN_PIN 0x21
81 #define VT1708S_HP_NID 0x25
82 #define VT1708S_DIGOUT_NID 0x12
84 #define VT1702_HP_NID 0x17
85 #define VT1702_DIGOUT_NID 0x11
87 enum VIA_HDA_CODEC {
88 UNKNOWN = -1,
89 VT1708,
90 VT1709_10CH,
91 VT1709_6CH,
92 VT1708B_8CH,
93 VT1708B_4CH,
94 VT1708S,
95 VT1708BCE,
96 VT1702,
97 VT1718S,
98 VT1716S,
99 VT2002P,
100 VT1812,
101 CODEC_TYPES,
104 struct via_spec {
105 /* codec parameterization */
106 struct snd_kcontrol_new *mixers[6];
107 unsigned int num_mixers;
109 struct hda_verb *init_verbs[5];
110 unsigned int num_iverbs;
112 char *stream_name_analog;
113 struct hda_pcm_stream *stream_analog_playback;
114 struct hda_pcm_stream *stream_analog_capture;
116 char *stream_name_digital;
117 struct hda_pcm_stream *stream_digital_playback;
118 struct hda_pcm_stream *stream_digital_capture;
120 /* playback */
121 struct hda_multi_out multiout;
122 hda_nid_t slave_dig_outs[2];
124 /* capture */
125 unsigned int num_adc_nids;
126 hda_nid_t *adc_nids;
127 hda_nid_t mux_nids[3];
128 hda_nid_t dig_in_nid;
129 hda_nid_t dig_in_pin;
131 /* capture source */
132 const struct hda_input_mux *input_mux;
133 unsigned int cur_mux[3];
135 /* PCM information */
136 struct hda_pcm pcm_rec[3];
138 /* dynamic controls, init_verbs and input_mux */
139 struct auto_pin_cfg autocfg;
140 struct snd_array kctls;
141 struct hda_input_mux private_imux[2];
142 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
144 /* HP mode source */
145 const struct hda_input_mux *hp_mux;
146 unsigned int hp_independent_mode;
147 unsigned int hp_independent_mode_index;
148 unsigned int smart51_enabled;
149 unsigned int dmic_enabled;
150 enum VIA_HDA_CODEC codec_type;
152 /* work to check hp jack state */
153 struct hda_codec *codec;
154 struct delayed_work vt1708_hp_work;
155 int vt1708_jack_detectect;
156 int vt1708_hp_present;
157 #ifdef CONFIG_SND_HDA_POWER_SAVE
158 struct hda_loopback_check loopback;
159 #endif
162 static struct via_spec * via_new_spec(struct hda_codec *codec)
164 struct via_spec *spec;
166 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
167 if (spec == NULL)
168 return NULL;
170 codec->spec = spec;
171 spec->codec = codec;
172 return spec;
175 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
177 u32 vendor_id = codec->vendor_id;
178 u16 ven_id = vendor_id >> 16;
179 u16 dev_id = vendor_id & 0xffff;
180 enum VIA_HDA_CODEC codec_type;
182 /* get codec type */
183 if (ven_id != 0x1106)
184 codec_type = UNKNOWN;
185 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
186 codec_type = VT1708;
187 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
188 codec_type = VT1709_10CH;
189 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
190 codec_type = VT1709_6CH;
191 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
192 codec_type = VT1708B_8CH;
193 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
194 codec_type = VT1708BCE;
195 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
196 codec_type = VT1708B_4CH;
197 else if ((dev_id & 0xfff) == 0x397
198 && (dev_id >> 12) < 8)
199 codec_type = VT1708S;
200 else if ((dev_id & 0xfff) == 0x398
201 && (dev_id >> 12) < 8)
202 codec_type = VT1702;
203 else if ((dev_id & 0xfff) == 0x428
204 && (dev_id >> 12) < 8)
205 codec_type = VT1718S;
206 else if (dev_id == 0x0433 || dev_id == 0xa721)
207 codec_type = VT1716S;
208 else if (dev_id == 0x0441 || dev_id == 0x4441)
209 codec_type = VT1718S;
210 else if (dev_id == 0x0438 || dev_id == 0x4438)
211 codec_type = VT2002P;
212 else if (dev_id == 0x0448)
213 codec_type = VT1812;
214 else if (dev_id == 0x0440)
215 codec_type = VT1708S;
216 else
217 codec_type = UNKNOWN;
218 return codec_type;
221 #define VIA_HP_EVENT 0x01
222 #define VIA_GPIO_EVENT 0x02
223 #define VIA_JACK_EVENT 0x04
224 #define VIA_MONO_EVENT 0x08
225 #define VIA_SPEAKER_EVENT 0x10
226 #define VIA_BIND_HP_EVENT 0x20
228 enum {
229 VIA_CTL_WIDGET_VOL,
230 VIA_CTL_WIDGET_MUTE,
231 VIA_CTL_WIDGET_ANALOG_MUTE,
232 VIA_CTL_WIDGET_BIND_PIN_MUTE,
235 enum {
236 AUTO_SEQ_FRONT = 0,
237 AUTO_SEQ_SURROUND,
238 AUTO_SEQ_CENLFE,
239 AUTO_SEQ_SIDE
242 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
243 static void set_jack_power_state(struct hda_codec *codec);
244 static int is_aa_path_mute(struct hda_codec *codec);
246 static void vt1708_start_hp_work(struct via_spec *spec)
248 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
249 return;
250 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
251 !spec->vt1708_jack_detectect);
252 if (!delayed_work_pending(&spec->vt1708_hp_work))
253 schedule_delayed_work(&spec->vt1708_hp_work,
254 msecs_to_jiffies(100));
257 static void vt1708_stop_hp_work(struct via_spec *spec)
259 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
260 return;
261 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
262 && !is_aa_path_mute(spec->codec))
263 return;
264 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
265 !spec->vt1708_jack_detectect);
266 cancel_delayed_work(&spec->vt1708_hp_work);
267 flush_scheduled_work();
271 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
272 struct snd_ctl_elem_value *ucontrol)
274 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
275 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
277 set_jack_power_state(codec);
278 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
279 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
280 if (is_aa_path_mute(codec))
281 vt1708_start_hp_work(codec->spec);
282 else
283 vt1708_stop_hp_work(codec->spec);
285 return change;
288 /* modify .put = snd_hda_mixer_amp_switch_put */
289 #define ANALOG_INPUT_MUTE \
290 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
291 .name = NULL, \
292 .index = 0, \
293 .info = snd_hda_mixer_amp_switch_info, \
294 .get = snd_hda_mixer_amp_switch_get, \
295 .put = analog_input_switch_put, \
296 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
298 static void via_hp_bind_automute(struct hda_codec *codec);
300 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
301 struct snd_ctl_elem_value *ucontrol)
303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
304 struct via_spec *spec = codec->spec;
305 int i;
306 int change = 0;
308 long *valp = ucontrol->value.integer.value;
309 int lmute, rmute;
310 if (strstr(kcontrol->id.name, "Switch") == NULL) {
311 snd_printd("Invalid control!\n");
312 return change;
314 change = snd_hda_mixer_amp_switch_put(kcontrol,
315 ucontrol);
316 /* Get mute value */
317 lmute = *valp ? 0 : HDA_AMP_MUTE;
318 valp++;
319 rmute = *valp ? 0 : HDA_AMP_MUTE;
321 /* Set hp pins */
322 if (!spec->hp_independent_mode) {
323 for (i = 0; i < spec->autocfg.hp_outs; i++) {
324 snd_hda_codec_amp_update(
325 codec, spec->autocfg.hp_pins[i],
326 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
327 lmute);
328 snd_hda_codec_amp_update(
329 codec, spec->autocfg.hp_pins[i],
330 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
331 rmute);
335 if (!lmute && !rmute) {
336 /* Line Outs */
337 for (i = 0; i < spec->autocfg.line_outs; i++)
338 snd_hda_codec_amp_stereo(
339 codec, spec->autocfg.line_out_pins[i],
340 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
341 /* Speakers */
342 for (i = 0; i < spec->autocfg.speaker_outs; i++)
343 snd_hda_codec_amp_stereo(
344 codec, spec->autocfg.speaker_pins[i],
345 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
346 /* unmute */
347 via_hp_bind_automute(codec);
349 } else {
350 if (lmute) {
351 /* Mute all left channels */
352 for (i = 1; i < spec->autocfg.line_outs; i++)
353 snd_hda_codec_amp_update(
354 codec,
355 spec->autocfg.line_out_pins[i],
356 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
357 lmute);
358 for (i = 0; i < spec->autocfg.speaker_outs; i++)
359 snd_hda_codec_amp_update(
360 codec,
361 spec->autocfg.speaker_pins[i],
362 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
363 lmute);
365 if (rmute) {
366 /* mute all right channels */
367 for (i = 1; i < spec->autocfg.line_outs; i++)
368 snd_hda_codec_amp_update(
369 codec,
370 spec->autocfg.line_out_pins[i],
371 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
372 rmute);
373 for (i = 0; i < spec->autocfg.speaker_outs; i++)
374 snd_hda_codec_amp_update(
375 codec,
376 spec->autocfg.speaker_pins[i],
377 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
378 rmute);
381 return change;
384 #define BIND_PIN_MUTE \
385 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
386 .name = NULL, \
387 .index = 0, \
388 .info = snd_hda_mixer_amp_switch_info, \
389 .get = snd_hda_mixer_amp_switch_get, \
390 .put = bind_pin_switch_put, \
391 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
393 static struct snd_kcontrol_new via_control_templates[] = {
394 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
395 HDA_CODEC_MUTE(NULL, 0, 0, 0),
396 ANALOG_INPUT_MUTE,
397 BIND_PIN_MUTE,
400 static hda_nid_t vt1708_adc_nids[2] = {
401 /* ADC1-2 */
402 0x15, 0x27
405 static hda_nid_t vt1709_adc_nids[3] = {
406 /* ADC1-2 */
407 0x14, 0x15, 0x16
410 static hda_nid_t vt1708B_adc_nids[2] = {
411 /* ADC1-2 */
412 0x13, 0x14
415 static hda_nid_t vt1708S_adc_nids[2] = {
416 /* ADC1-2 */
417 0x13, 0x14
420 static hda_nid_t vt1702_adc_nids[3] = {
421 /* ADC1-2 */
422 0x12, 0x20, 0x1F
425 static hda_nid_t vt1718S_adc_nids[2] = {
426 /* ADC1-2 */
427 0x10, 0x11
430 static hda_nid_t vt1716S_adc_nids[2] = {
431 /* ADC1-2 */
432 0x13, 0x14
435 static hda_nid_t vt2002P_adc_nids[2] = {
436 /* ADC1-2 */
437 0x10, 0x11
440 static hda_nid_t vt1812_adc_nids[2] = {
441 /* ADC1-2 */
442 0x10, 0x11
446 /* add dynamic controls */
447 static int __via_add_control(struct via_spec *spec, int type, const char *name,
448 int idx, unsigned long val)
450 struct snd_kcontrol_new *knew;
452 snd_array_init(&spec->kctls, sizeof(*knew), 32);
453 knew = snd_array_new(&spec->kctls);
454 if (!knew)
455 return -ENOMEM;
456 *knew = via_control_templates[type];
457 knew->name = kstrdup(name, GFP_KERNEL);
458 if (!knew->name)
459 return -ENOMEM;
460 if (get_amp_nid_(val))
461 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
462 knew->private_value = val;
463 return 0;
466 #define via_add_control(spec, type, name, val) \
467 __via_add_control(spec, type, name, 0, val)
469 static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
470 struct snd_kcontrol_new *tmpl)
472 struct snd_kcontrol_new *knew;
474 snd_array_init(&spec->kctls, sizeof(*knew), 32);
475 knew = snd_array_new(&spec->kctls);
476 if (!knew)
477 return NULL;
478 *knew = *tmpl;
479 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
480 if (!knew->name)
481 return NULL;
482 return knew;
485 static void via_free_kctls(struct hda_codec *codec)
487 struct via_spec *spec = codec->spec;
489 if (spec->kctls.list) {
490 struct snd_kcontrol_new *kctl = spec->kctls.list;
491 int i;
492 for (i = 0; i < spec->kctls.used; i++)
493 kfree(kctl[i].name);
495 snd_array_free(&spec->kctls);
498 /* create input playback/capture controls for the given pin */
499 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
500 int type_idx, int idx, int mix_nid)
502 char name[32];
503 int err;
505 sprintf(name, "%s Playback Volume", ctlname);
506 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
507 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
508 if (err < 0)
509 return err;
510 sprintf(name, "%s Playback Switch", ctlname);
511 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
512 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
513 if (err < 0)
514 return err;
515 return 0;
518 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
519 hda_nid_t nid, int pin_type,
520 int dac_idx)
522 /* set as output */
523 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
524 pin_type);
525 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
526 AMP_OUT_UNMUTE);
527 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
528 snd_hda_codec_write(codec, nid, 0,
529 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
533 static void via_auto_init_multi_out(struct hda_codec *codec)
535 struct via_spec *spec = codec->spec;
536 int i;
538 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
539 hda_nid_t nid = spec->autocfg.line_out_pins[i];
540 if (nid)
541 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
545 static void via_auto_init_hp_out(struct hda_codec *codec)
547 struct via_spec *spec = codec->spec;
548 hda_nid_t pin;
549 int i;
551 for (i = 0; i < spec->autocfg.hp_outs; i++) {
552 pin = spec->autocfg.hp_pins[i];
553 if (pin) /* connect to front */
554 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
558 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
560 static void via_auto_init_analog_input(struct hda_codec *codec)
562 struct via_spec *spec = codec->spec;
563 const struct auto_pin_cfg *cfg = &spec->autocfg;
564 unsigned int ctl;
565 int i;
567 for (i = 0; i < cfg->num_inputs; i++) {
568 hda_nid_t nid = cfg->inputs[i].pin;
569 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
570 ctl = PIN_OUT;
571 else if (i == AUTO_PIN_MIC)
572 ctl = PIN_VREF50;
573 else
574 ctl = PIN_IN;
575 snd_hda_codec_write(codec, nid, 0,
576 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
580 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
581 unsigned int *affected_parm)
583 unsigned parm;
584 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
585 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
586 >> AC_DEFCFG_MISC_SHIFT
587 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
588 unsigned present = snd_hda_jack_detect(codec, nid);
589 struct via_spec *spec = codec->spec;
590 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
591 || ((no_presence || present)
592 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
593 *affected_parm = AC_PWRST_D0; /* if it's connected */
594 parm = AC_PWRST_D0;
595 } else
596 parm = AC_PWRST_D3;
598 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
601 static void set_jack_power_state(struct hda_codec *codec)
603 struct via_spec *spec = codec->spec;
604 int imux_is_smixer;
605 unsigned int parm;
607 if (spec->codec_type == VT1702) {
608 imux_is_smixer = snd_hda_codec_read(
609 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
610 /* inputs */
611 /* PW 1/2/5 (14h/15h/18h) */
612 parm = AC_PWRST_D3;
613 set_pin_power_state(codec, 0x14, &parm);
614 set_pin_power_state(codec, 0x15, &parm);
615 set_pin_power_state(codec, 0x18, &parm);
616 if (imux_is_smixer)
617 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
618 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
619 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
620 parm);
621 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
622 parm);
623 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
624 parm);
625 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
626 parm);
628 /* outputs */
629 /* PW 3/4 (16h/17h) */
630 parm = AC_PWRST_D3;
631 set_pin_power_state(codec, 0x16, &parm);
632 set_pin_power_state(codec, 0x17, &parm);
633 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
634 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
635 imux_is_smixer ? AC_PWRST_D0 : parm);
636 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
637 parm);
638 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
639 parm);
640 } else if (spec->codec_type == VT1708B_8CH
641 || spec->codec_type == VT1708B_4CH
642 || spec->codec_type == VT1708S) {
643 /* SW0 (17h) = stereo mixer */
644 int is_8ch = spec->codec_type != VT1708B_4CH;
645 imux_is_smixer = snd_hda_codec_read(
646 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
647 == ((spec->codec_type == VT1708S) ? 5 : 0);
648 /* inputs */
649 /* PW 1/2/5 (1ah/1bh/1eh) */
650 parm = AC_PWRST_D3;
651 set_pin_power_state(codec, 0x1a, &parm);
652 set_pin_power_state(codec, 0x1b, &parm);
653 set_pin_power_state(codec, 0x1e, &parm);
654 if (imux_is_smixer)
655 parm = AC_PWRST_D0;
656 /* SW0 (17h), AIW 0/1 (13h/14h) */
657 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
658 parm);
659 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
660 parm);
661 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
662 parm);
664 /* outputs */
665 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
666 parm = AC_PWRST_D3;
667 set_pin_power_state(codec, 0x19, &parm);
668 if (spec->smart51_enabled)
669 parm = AC_PWRST_D0;
670 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
671 parm);
672 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
673 parm);
675 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
676 if (is_8ch) {
677 parm = AC_PWRST_D3;
678 set_pin_power_state(codec, 0x22, &parm);
679 if (spec->smart51_enabled)
680 parm = AC_PWRST_D0;
681 snd_hda_codec_write(codec, 0x26, 0,
682 AC_VERB_SET_POWER_STATE, parm);
683 snd_hda_codec_write(codec, 0x24, 0,
684 AC_VERB_SET_POWER_STATE, parm);
687 /* PW 3/4/7 (1ch/1dh/23h) */
688 parm = AC_PWRST_D3;
689 /* force to D0 for internal Speaker */
690 set_pin_power_state(codec, 0x1c, &parm);
691 set_pin_power_state(codec, 0x1d, &parm);
692 if (is_8ch)
693 set_pin_power_state(codec, 0x23, &parm);
694 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
695 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
696 imux_is_smixer ? AC_PWRST_D0 : parm);
697 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
698 parm);
699 if (is_8ch) {
700 snd_hda_codec_write(codec, 0x25, 0,
701 AC_VERB_SET_POWER_STATE, parm);
702 snd_hda_codec_write(codec, 0x27, 0,
703 AC_VERB_SET_POWER_STATE, parm);
705 } else if (spec->codec_type == VT1718S) {
706 /* MUX6 (1eh) = stereo mixer */
707 imux_is_smixer = snd_hda_codec_read(
708 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
709 /* inputs */
710 /* PW 5/6/7 (29h/2ah/2bh) */
711 parm = AC_PWRST_D3;
712 set_pin_power_state(codec, 0x29, &parm);
713 set_pin_power_state(codec, 0x2a, &parm);
714 set_pin_power_state(codec, 0x2b, &parm);
715 if (imux_is_smixer)
716 parm = AC_PWRST_D0;
717 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
718 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
719 parm);
720 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
721 parm);
722 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
723 parm);
724 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
725 parm);
727 /* outputs */
728 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
729 parm = AC_PWRST_D3;
730 set_pin_power_state(codec, 0x27, &parm);
731 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
732 parm);
733 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
734 parm);
736 /* PW2 (26h), AOW2 (ah) */
737 parm = AC_PWRST_D3;
738 set_pin_power_state(codec, 0x26, &parm);
739 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
740 parm);
742 /* PW0/1 (24h/25h) */
743 parm = AC_PWRST_D3;
744 set_pin_power_state(codec, 0x24, &parm);
745 set_pin_power_state(codec, 0x25, &parm);
746 if (!spec->hp_independent_mode) /* check for redirected HP */
747 set_pin_power_state(codec, 0x28, &parm);
748 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
749 parm);
750 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
751 parm);
752 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
753 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
754 imux_is_smixer ? AC_PWRST_D0 : parm);
755 if (spec->hp_independent_mode) {
756 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
757 parm = AC_PWRST_D3;
758 set_pin_power_state(codec, 0x28, &parm);
759 snd_hda_codec_write(codec, 0x1b, 0,
760 AC_VERB_SET_POWER_STATE, parm);
761 snd_hda_codec_write(codec, 0x34, 0,
762 AC_VERB_SET_POWER_STATE, parm);
763 snd_hda_codec_write(codec, 0xc, 0,
764 AC_VERB_SET_POWER_STATE, parm);
766 } else if (spec->codec_type == VT1716S) {
767 unsigned int mono_out, present;
768 /* SW0 (17h) = stereo mixer */
769 imux_is_smixer = snd_hda_codec_read(
770 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
771 /* inputs */
772 /* PW 1/2/5 (1ah/1bh/1eh) */
773 parm = AC_PWRST_D3;
774 set_pin_power_state(codec, 0x1a, &parm);
775 set_pin_power_state(codec, 0x1b, &parm);
776 set_pin_power_state(codec, 0x1e, &parm);
777 if (imux_is_smixer)
778 parm = AC_PWRST_D0;
779 /* SW0 (17h), AIW0(13h) */
780 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
781 parm);
782 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
783 parm);
785 parm = AC_PWRST_D3;
786 set_pin_power_state(codec, 0x1e, &parm);
787 /* PW11 (22h) */
788 if (spec->dmic_enabled)
789 set_pin_power_state(codec, 0x22, &parm);
790 else
791 snd_hda_codec_write(
792 codec, 0x22, 0,
793 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
795 /* SW2(26h), AIW1(14h) */
796 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
797 parm);
798 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
799 parm);
801 /* outputs */
802 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
803 parm = AC_PWRST_D3;
804 set_pin_power_state(codec, 0x19, &parm);
805 /* Smart 5.1 PW2(1bh) */
806 if (spec->smart51_enabled)
807 set_pin_power_state(codec, 0x1b, &parm);
808 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
809 parm);
810 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
811 parm);
813 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
814 parm = AC_PWRST_D3;
815 set_pin_power_state(codec, 0x23, &parm);
816 /* Smart 5.1 PW1(1ah) */
817 if (spec->smart51_enabled)
818 set_pin_power_state(codec, 0x1a, &parm);
819 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
820 parm);
822 /* Smart 5.1 PW5(1eh) */
823 if (spec->smart51_enabled)
824 set_pin_power_state(codec, 0x1e, &parm);
825 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
826 parm);
828 /* Mono out */
829 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
830 present = snd_hda_jack_detect(codec, 0x1c);
831 if (present)
832 mono_out = 0;
833 else {
834 present = snd_hda_jack_detect(codec, 0x1d);
835 if (!spec->hp_independent_mode && present)
836 mono_out = 0;
837 else
838 mono_out = 1;
840 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
841 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
842 parm);
843 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
844 parm);
845 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
846 parm);
848 /* PW 3/4 (1ch/1dh) */
849 parm = AC_PWRST_D3;
850 set_pin_power_state(codec, 0x1c, &parm);
851 set_pin_power_state(codec, 0x1d, &parm);
852 /* HP Independent Mode, power on AOW3 */
853 if (spec->hp_independent_mode)
854 snd_hda_codec_write(codec, 0x25, 0,
855 AC_VERB_SET_POWER_STATE, parm);
857 /* force to D0 for internal Speaker */
858 /* MW0 (16h), AOW0 (10h) */
859 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
860 imux_is_smixer ? AC_PWRST_D0 : parm);
861 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
862 mono_out ? AC_PWRST_D0 : parm);
863 } else if (spec->codec_type == VT2002P) {
864 unsigned int present;
865 /* MUX9 (1eh) = stereo mixer */
866 imux_is_smixer = snd_hda_codec_read(
867 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
868 /* inputs */
869 /* PW 5/6/7 (29h/2ah/2bh) */
870 parm = AC_PWRST_D3;
871 set_pin_power_state(codec, 0x29, &parm);
872 set_pin_power_state(codec, 0x2a, &parm);
873 set_pin_power_state(codec, 0x2b, &parm);
874 if (imux_is_smixer)
875 parm = AC_PWRST_D0;
876 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
877 snd_hda_codec_write(codec, 0x1e, 0,
878 AC_VERB_SET_POWER_STATE, parm);
879 snd_hda_codec_write(codec, 0x1f, 0,
880 AC_VERB_SET_POWER_STATE, parm);
881 snd_hda_codec_write(codec, 0x10, 0,
882 AC_VERB_SET_POWER_STATE, parm);
883 snd_hda_codec_write(codec, 0x11, 0,
884 AC_VERB_SET_POWER_STATE, parm);
886 /* outputs */
887 /* AOW0 (8h)*/
888 snd_hda_codec_write(codec, 0x8, 0,
889 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
891 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
892 parm = AC_PWRST_D3;
893 set_pin_power_state(codec, 0x26, &parm);
894 snd_hda_codec_write(codec, 0x1c, 0,
895 AC_VERB_SET_POWER_STATE, parm);
896 snd_hda_codec_write(codec, 0x37,
897 0, AC_VERB_SET_POWER_STATE, parm);
899 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
900 parm = AC_PWRST_D3;
901 set_pin_power_state(codec, 0x25, &parm);
902 snd_hda_codec_write(codec, 0x19, 0,
903 AC_VERB_SET_POWER_STATE, parm);
904 snd_hda_codec_write(codec, 0x35, 0,
905 AC_VERB_SET_POWER_STATE, parm);
906 if (spec->hp_independent_mode) {
907 snd_hda_codec_write(codec, 0x9, 0,
908 AC_VERB_SET_POWER_STATE, parm);
911 /* Class-D */
912 /* PW0 (24h), MW0(18h), MUX0(34h) */
913 present = snd_hda_jack_detect(codec, 0x25);
914 parm = AC_PWRST_D3;
915 set_pin_power_state(codec, 0x24, &parm);
916 if (present) {
917 snd_hda_codec_write(
918 codec, 0x18, 0,
919 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
920 snd_hda_codec_write(
921 codec, 0x34, 0,
922 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
923 } else {
924 snd_hda_codec_write(
925 codec, 0x18, 0,
926 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
927 snd_hda_codec_write(
928 codec, 0x34, 0,
929 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
932 /* Mono Out */
933 /* PW15 (31h), MW8(17h), MUX8(3bh) */
934 present = snd_hda_jack_detect(codec, 0x26);
935 parm = AC_PWRST_D3;
936 set_pin_power_state(codec, 0x31, &parm);
937 if (present) {
938 snd_hda_codec_write(
939 codec, 0x17, 0,
940 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
941 snd_hda_codec_write(
942 codec, 0x3b, 0,
943 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
944 } else {
945 snd_hda_codec_write(
946 codec, 0x17, 0,
947 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
948 snd_hda_codec_write(
949 codec, 0x3b, 0,
950 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
953 /* MW9 (21h) */
954 if (imux_is_smixer || !is_aa_path_mute(codec))
955 snd_hda_codec_write(
956 codec, 0x21, 0,
957 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
958 else
959 snd_hda_codec_write(
960 codec, 0x21, 0,
961 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
962 } else if (spec->codec_type == VT1812) {
963 unsigned int present;
964 /* MUX10 (1eh) = stereo mixer */
965 imux_is_smixer = snd_hda_codec_read(
966 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
967 /* inputs */
968 /* PW 5/6/7 (29h/2ah/2bh) */
969 parm = AC_PWRST_D3;
970 set_pin_power_state(codec, 0x29, &parm);
971 set_pin_power_state(codec, 0x2a, &parm);
972 set_pin_power_state(codec, 0x2b, &parm);
973 if (imux_is_smixer)
974 parm = AC_PWRST_D0;
975 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
976 snd_hda_codec_write(codec, 0x1e, 0,
977 AC_VERB_SET_POWER_STATE, parm);
978 snd_hda_codec_write(codec, 0x1f, 0,
979 AC_VERB_SET_POWER_STATE, parm);
980 snd_hda_codec_write(codec, 0x10, 0,
981 AC_VERB_SET_POWER_STATE, parm);
982 snd_hda_codec_write(codec, 0x11, 0,
983 AC_VERB_SET_POWER_STATE, parm);
985 /* outputs */
986 /* AOW0 (8h)*/
987 snd_hda_codec_write(codec, 0x8, 0,
988 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
990 /* PW4 (28h), MW4 (18h), MUX4(38h) */
991 parm = AC_PWRST_D3;
992 set_pin_power_state(codec, 0x28, &parm);
993 snd_hda_codec_write(codec, 0x18, 0,
994 AC_VERB_SET_POWER_STATE, parm);
995 snd_hda_codec_write(codec, 0x38, 0,
996 AC_VERB_SET_POWER_STATE, parm);
998 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
999 parm = AC_PWRST_D3;
1000 set_pin_power_state(codec, 0x25, &parm);
1001 snd_hda_codec_write(codec, 0x15, 0,
1002 AC_VERB_SET_POWER_STATE, parm);
1003 snd_hda_codec_write(codec, 0x35, 0,
1004 AC_VERB_SET_POWER_STATE, parm);
1005 if (spec->hp_independent_mode) {
1006 snd_hda_codec_write(codec, 0x9, 0,
1007 AC_VERB_SET_POWER_STATE, parm);
1010 /* Internal Speaker */
1011 /* PW0 (24h), MW0(14h), MUX0(34h) */
1012 present = snd_hda_jack_detect(codec, 0x25);
1013 parm = AC_PWRST_D3;
1014 set_pin_power_state(codec, 0x24, &parm);
1015 if (present) {
1016 snd_hda_codec_write(codec, 0x14, 0,
1017 AC_VERB_SET_POWER_STATE,
1018 AC_PWRST_D3);
1019 snd_hda_codec_write(codec, 0x34, 0,
1020 AC_VERB_SET_POWER_STATE,
1021 AC_PWRST_D3);
1022 } else {
1023 snd_hda_codec_write(codec, 0x14, 0,
1024 AC_VERB_SET_POWER_STATE,
1025 AC_PWRST_D0);
1026 snd_hda_codec_write(codec, 0x34, 0,
1027 AC_VERB_SET_POWER_STATE,
1028 AC_PWRST_D0);
1030 /* Mono Out */
1031 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1032 present = snd_hda_jack_detect(codec, 0x28);
1033 parm = AC_PWRST_D3;
1034 set_pin_power_state(codec, 0x31, &parm);
1035 if (present) {
1036 snd_hda_codec_write(codec, 0x1c, 0,
1037 AC_VERB_SET_POWER_STATE,
1038 AC_PWRST_D3);
1039 snd_hda_codec_write(codec, 0x3c, 0,
1040 AC_VERB_SET_POWER_STATE,
1041 AC_PWRST_D3);
1042 snd_hda_codec_write(codec, 0x3e, 0,
1043 AC_VERB_SET_POWER_STATE,
1044 AC_PWRST_D3);
1045 } else {
1046 snd_hda_codec_write(codec, 0x1c, 0,
1047 AC_VERB_SET_POWER_STATE,
1048 AC_PWRST_D0);
1049 snd_hda_codec_write(codec, 0x3c, 0,
1050 AC_VERB_SET_POWER_STATE,
1051 AC_PWRST_D0);
1052 snd_hda_codec_write(codec, 0x3e, 0,
1053 AC_VERB_SET_POWER_STATE,
1054 AC_PWRST_D0);
1057 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1058 parm = AC_PWRST_D3;
1059 set_pin_power_state(codec, 0x33, &parm);
1060 snd_hda_codec_write(codec, 0x1d, 0,
1061 AC_VERB_SET_POWER_STATE, parm);
1062 snd_hda_codec_write(codec, 0x3d, 0,
1063 AC_VERB_SET_POWER_STATE, parm);
1065 /* MW9 (21h) */
1066 if (imux_is_smixer || !is_aa_path_mute(codec))
1067 snd_hda_codec_write(
1068 codec, 0x21, 0,
1069 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1070 else
1071 snd_hda_codec_write(
1072 codec, 0x21, 0,
1073 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1078 * input MUX handling
1080 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1081 struct snd_ctl_elem_info *uinfo)
1083 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1084 struct via_spec *spec = codec->spec;
1085 return snd_hda_input_mux_info(spec->input_mux, uinfo);
1088 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1089 struct snd_ctl_elem_value *ucontrol)
1091 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1092 struct via_spec *spec = codec->spec;
1093 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1095 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
1096 return 0;
1099 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1100 struct snd_ctl_elem_value *ucontrol)
1102 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1103 struct via_spec *spec = codec->spec;
1104 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1106 if (!spec->mux_nids[adc_idx])
1107 return -EINVAL;
1108 /* switch to D0 beofre change index */
1109 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1110 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1111 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1112 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1113 /* update jack power state */
1114 set_jack_power_state(codec);
1116 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1117 spec->mux_nids[adc_idx],
1118 &spec->cur_mux[adc_idx]);
1121 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
1122 struct snd_ctl_elem_info *uinfo)
1124 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1125 struct via_spec *spec = codec->spec;
1126 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
1129 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
1130 struct snd_ctl_elem_value *ucontrol)
1132 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1133 hda_nid_t nid = kcontrol->private_value;
1134 unsigned int pinsel;
1136 /* use !! to translate conn sel 2 for VT1718S */
1137 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1138 AC_VERB_GET_CONNECT_SEL,
1139 0x00);
1140 ucontrol->value.enumerated.item[0] = pinsel;
1142 return 0;
1145 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1147 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1148 if (ctl) {
1149 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1150 ctl->vd[0].access |= active
1151 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1152 snd_ctl_notify(codec->bus->card,
1153 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1157 static hda_nid_t side_mute_channel(struct via_spec *spec)
1159 switch (spec->codec_type) {
1160 case VT1708: return 0x1b;
1161 case VT1709_10CH: return 0x29;
1162 case VT1708B_8CH: /* fall thru */
1163 case VT1708S: return 0x27;
1164 default: return 0;
1168 static int update_side_mute_status(struct hda_codec *codec)
1170 /* mute side channel */
1171 struct via_spec *spec = codec->spec;
1172 unsigned int parm = spec->hp_independent_mode
1173 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1174 hda_nid_t sw3 = side_mute_channel(spec);
1176 if (sw3)
1177 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1178 parm);
1179 return 0;
1182 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
1183 struct snd_ctl_elem_value *ucontrol)
1185 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1186 struct via_spec *spec = codec->spec;
1187 hda_nid_t nid = kcontrol->private_value;
1188 unsigned int pinsel = ucontrol->value.enumerated.item[0];
1189 /* Get Independent Mode index of headphone pin widget */
1190 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1191 ? 1 : 0;
1192 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
1194 if (spec->multiout.hp_nid && spec->multiout.hp_nid
1195 != spec->multiout.dac_nids[HDA_FRONT])
1196 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
1197 0, 0, 0);
1199 update_side_mute_status(codec);
1200 /* update HP volume/swtich active state */
1201 if (spec->codec_type == VT1708S
1202 || spec->codec_type == VT1702
1203 || spec->codec_type == VT1718S
1204 || spec->codec_type == VT1716S
1205 || spec->codec_type == VT2002P
1206 || spec->codec_type == VT1812) {
1207 activate_ctl(codec, "Headphone Playback Volume",
1208 spec->hp_independent_mode);
1209 activate_ctl(codec, "Headphone Playback Switch",
1210 spec->hp_independent_mode);
1212 return 0;
1215 static struct snd_kcontrol_new via_hp_mixer[2] = {
1217 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1218 .name = "Independent HP",
1219 .info = via_independent_hp_info,
1220 .get = via_independent_hp_get,
1221 .put = via_independent_hp_put,
1224 .iface = NID_MAPPING,
1225 .name = "Independent HP",
1229 static int via_hp_build(struct hda_codec *codec)
1231 struct via_spec *spec = codec->spec;
1232 struct snd_kcontrol_new *knew;
1233 hda_nid_t nid;
1234 int nums;
1235 hda_nid_t conn[HDA_MAX_CONNECTIONS];
1237 switch (spec->codec_type) {
1238 case VT1718S:
1239 nid = 0x34;
1240 break;
1241 case VT2002P:
1242 nid = 0x35;
1243 break;
1244 case VT1812:
1245 nid = 0x3d;
1246 break;
1247 default:
1248 nid = spec->autocfg.hp_pins[0];
1249 break;
1252 nums = snd_hda_get_connections(codec, nid, conn, HDA_MAX_CONNECTIONS);
1253 if (nums <= 1)
1254 return 0;
1256 knew = via_clone_control(spec, &via_hp_mixer[0]);
1257 if (knew == NULL)
1258 return -ENOMEM;
1260 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
1261 knew->private_value = nid;
1263 knew = via_clone_control(spec, &via_hp_mixer[1]);
1264 if (knew == NULL)
1265 return -ENOMEM;
1266 knew->subdevice = side_mute_channel(spec);
1268 return 0;
1271 static void notify_aa_path_ctls(struct hda_codec *codec)
1273 int i;
1274 struct snd_ctl_elem_id id;
1275 const char *labels[] = {"Mic", "Front Mic", "Line"};
1277 memset(&id, 0, sizeof(id));
1278 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1279 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1280 sprintf(id.name, "%s Playback Volume", labels[i]);
1281 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1282 &id);
1286 static void mute_aa_path(struct hda_codec *codec, int mute)
1288 struct via_spec *spec = codec->spec;
1289 hda_nid_t nid_mixer;
1290 int start_idx;
1291 int end_idx;
1292 int i;
1293 /* get nid of MW0 and start & end index */
1294 switch (spec->codec_type) {
1295 case VT1708:
1296 nid_mixer = 0x17;
1297 start_idx = 2;
1298 end_idx = 4;
1299 break;
1300 case VT1709_10CH:
1301 case VT1709_6CH:
1302 nid_mixer = 0x18;
1303 start_idx = 2;
1304 end_idx = 4;
1305 break;
1306 case VT1708B_8CH:
1307 case VT1708B_4CH:
1308 case VT1708S:
1309 case VT1716S:
1310 nid_mixer = 0x16;
1311 start_idx = 2;
1312 end_idx = 4;
1313 break;
1314 default:
1315 return;
1317 /* check AA path's mute status */
1318 for (i = start_idx; i <= end_idx; i++) {
1319 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1320 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1321 HDA_AMP_MUTE, val);
1324 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1326 const struct auto_pin_cfg *cfg = &spec->autocfg;
1327 int i;
1329 for (i = 0; i < cfg->num_inputs; i++) {
1330 if (pin == cfg->inputs[i].pin)
1331 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
1333 return 0;
1336 static int via_smart51_info(struct snd_kcontrol *kcontrol,
1337 struct snd_ctl_elem_info *uinfo)
1339 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1340 uinfo->count = 1;
1341 uinfo->value.integer.min = 0;
1342 uinfo->value.integer.max = 1;
1343 return 0;
1346 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1347 struct snd_ctl_elem_value *ucontrol)
1349 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1350 struct via_spec *spec = codec->spec;
1351 const struct auto_pin_cfg *cfg = &spec->autocfg;
1352 int on = 1;
1353 int i;
1355 for (i = 0; i < cfg->num_inputs; i++) {
1356 hda_nid_t nid = cfg->inputs[i].pin;
1357 int ctl = snd_hda_codec_read(codec, nid, 0,
1358 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1359 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1360 continue;
1361 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1362 spec->hp_independent_mode && spec->codec_type != VT1718S)
1363 continue; /* ignore FMic for independent HP */
1364 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
1365 on = 0;
1367 *ucontrol->value.integer.value = on;
1368 return 0;
1371 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1372 struct snd_ctl_elem_value *ucontrol)
1374 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1375 struct via_spec *spec = codec->spec;
1376 const struct auto_pin_cfg *cfg = &spec->autocfg;
1377 int out_in = *ucontrol->value.integer.value
1378 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1379 int i;
1381 for (i = 0; i < cfg->num_inputs; i++) {
1382 hda_nid_t nid = cfg->inputs[i].pin;
1383 unsigned int parm;
1385 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1386 continue;
1387 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1388 spec->hp_independent_mode && spec->codec_type != VT1718S)
1389 continue; /* don't retask FMic for independent HP */
1391 parm = snd_hda_codec_read(codec, nid, 0,
1392 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1393 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1394 parm |= out_in;
1395 snd_hda_codec_write(codec, nid, 0,
1396 AC_VERB_SET_PIN_WIDGET_CONTROL,
1397 parm);
1398 if (out_in == AC_PINCTL_OUT_EN) {
1399 mute_aa_path(codec, 1);
1400 notify_aa_path_ctls(codec);
1402 if (spec->codec_type == VT1718S) {
1403 snd_hda_codec_amp_stereo(
1404 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1405 HDA_AMP_UNMUTE);
1407 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
1408 if (spec->codec_type == VT1708S
1409 || spec->codec_type == VT1716S) {
1410 /* input = index 1 (AOW3) */
1411 snd_hda_codec_write(
1412 codec, nid, 0,
1413 AC_VERB_SET_CONNECT_SEL, 1);
1414 snd_hda_codec_amp_stereo(
1415 codec, nid, HDA_OUTPUT,
1416 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1420 spec->smart51_enabled = *ucontrol->value.integer.value;
1421 set_jack_power_state(codec);
1422 return 1;
1425 static struct snd_kcontrol_new via_smart51_mixer[2] = {
1427 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1428 .name = "Smart 5.1",
1429 .count = 1,
1430 .info = via_smart51_info,
1431 .get = via_smart51_get,
1432 .put = via_smart51_put,
1435 .iface = NID_MAPPING,
1436 .name = "Smart 5.1",
1440 static int via_smart51_build(struct via_spec *spec)
1442 struct snd_kcontrol_new *knew;
1443 const struct auto_pin_cfg *cfg = &spec->autocfg;
1444 hda_nid_t nid;
1445 int i;
1447 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1448 if (knew == NULL)
1449 return -ENOMEM;
1451 for (i = 0; i < cfg->num_inputs; i++) {
1452 nid = cfg->inputs[i].pin;
1453 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1454 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1455 if (knew == NULL)
1456 return -ENOMEM;
1457 knew->subdevice = nid;
1458 break;
1462 return 0;
1465 /* capture mixer elements */
1466 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1467 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1468 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1469 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1470 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1472 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1473 /* The multiple "Capture Source" controls confuse alsamixer
1474 * So call somewhat different..
1476 /* .name = "Capture Source", */
1477 .name = "Input Source",
1478 .count = 1,
1479 .info = via_mux_enum_info,
1480 .get = via_mux_enum_get,
1481 .put = via_mux_enum_put,
1483 { } /* end */
1486 /* check AA path's mute statue */
1487 static int is_aa_path_mute(struct hda_codec *codec)
1489 int mute = 1;
1490 hda_nid_t nid_mixer;
1491 int start_idx;
1492 int end_idx;
1493 int i;
1494 struct via_spec *spec = codec->spec;
1495 /* get nid of MW0 and start & end index */
1496 switch (spec->codec_type) {
1497 case VT1708B_8CH:
1498 case VT1708B_4CH:
1499 case VT1708S:
1500 case VT1716S:
1501 nid_mixer = 0x16;
1502 start_idx = 2;
1503 end_idx = 4;
1504 break;
1505 case VT1702:
1506 nid_mixer = 0x1a;
1507 start_idx = 1;
1508 end_idx = 3;
1509 break;
1510 case VT1718S:
1511 nid_mixer = 0x21;
1512 start_idx = 1;
1513 end_idx = 3;
1514 break;
1515 case VT2002P:
1516 case VT1812:
1517 nid_mixer = 0x21;
1518 start_idx = 0;
1519 end_idx = 2;
1520 break;
1521 default:
1522 return 0;
1524 /* check AA path's mute status */
1525 for (i = start_idx; i <= end_idx; i++) {
1526 unsigned int con_list = snd_hda_codec_read(
1527 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1528 int shift = 8 * (i % 4);
1529 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1530 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1531 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1532 /* check mute status while the pin is connected */
1533 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1534 HDA_INPUT, i) >> 7;
1535 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1536 HDA_INPUT, i) >> 7;
1537 if (!mute_l || !mute_r) {
1538 mute = 0;
1539 break;
1543 return mute;
1546 /* enter/exit analog low-current mode */
1547 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1549 struct via_spec *spec = codec->spec;
1550 static int saved_stream_idle = 1; /* saved stream idle status */
1551 int enable = is_aa_path_mute(codec);
1552 unsigned int verb = 0;
1553 unsigned int parm = 0;
1555 if (stream_idle == -1) /* stream status did not change */
1556 enable = enable && saved_stream_idle;
1557 else {
1558 enable = enable && stream_idle;
1559 saved_stream_idle = stream_idle;
1562 /* decide low current mode's verb & parameter */
1563 switch (spec->codec_type) {
1564 case VT1708B_8CH:
1565 case VT1708B_4CH:
1566 verb = 0xf70;
1567 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1568 break;
1569 case VT1708S:
1570 case VT1718S:
1571 case VT1716S:
1572 verb = 0xf73;
1573 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1574 break;
1575 case VT1702:
1576 verb = 0xf73;
1577 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1578 break;
1579 case VT2002P:
1580 case VT1812:
1581 verb = 0xf93;
1582 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1583 break;
1584 default:
1585 return; /* other codecs are not supported */
1587 /* send verb */
1588 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1592 * generic initialization of ADC, input mixers and output mixers
1594 static struct hda_verb vt1708_volume_init_verbs[] = {
1596 * Unmute ADC0-1 and set the default input to mic-in
1598 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1599 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1602 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1603 * mixer widget
1605 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1606 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1607 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1608 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1609 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1610 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1613 * Set up output mixers (0x19 - 0x1b)
1615 /* set vol=0 to output mixers */
1616 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1617 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1618 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1620 /* Setup default input MW0 to PW4 */
1621 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1622 /* PW9 Output enable */
1623 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1627 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1628 struct hda_codec *codec,
1629 struct snd_pcm_substream *substream)
1631 struct via_spec *spec = codec->spec;
1632 int idle = substream->pstr->substream_opened == 1
1633 && substream->ref_count == 0;
1634 analog_low_current_mode(codec, idle);
1635 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1636 hinfo);
1639 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1640 unsigned int stream_tag,
1641 unsigned int format,
1642 struct snd_pcm_substream *substream)
1644 struct via_spec *spec = codec->spec;
1645 struct hda_multi_out *mout = &spec->multiout;
1646 hda_nid_t *nids = mout->dac_nids;
1647 int chs = substream->runtime->channels;
1648 int i;
1650 mutex_lock(&codec->spdif_mutex);
1651 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1652 if (chs == 2 &&
1653 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1654 format) &&
1655 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1656 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1657 /* turn off SPDIF once; otherwise the IEC958 bits won't
1658 * be updated */
1659 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1660 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1661 AC_VERB_SET_DIGI_CONVERT_1,
1662 codec->spdif_ctls &
1663 ~AC_DIG1_ENABLE & 0xff);
1664 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1665 stream_tag, 0, format);
1666 /* turn on again (if needed) */
1667 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1668 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1669 AC_VERB_SET_DIGI_CONVERT_1,
1670 codec->spdif_ctls & 0xff);
1671 } else {
1672 mout->dig_out_used = 0;
1673 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1674 0, 0, 0);
1677 mutex_unlock(&codec->spdif_mutex);
1679 /* front */
1680 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1681 0, format);
1683 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1684 && !spec->hp_independent_mode)
1685 /* headphone out will just decode front left/right (stereo) */
1686 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1687 0, format);
1689 /* extra outputs copied from front */
1690 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1691 if (mout->extra_out_nid[i])
1692 snd_hda_codec_setup_stream(codec,
1693 mout->extra_out_nid[i],
1694 stream_tag, 0, format);
1696 /* surrounds */
1697 for (i = 1; i < mout->num_dacs; i++) {
1698 if (chs >= (i + 1) * 2) /* independent out */
1699 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1700 i * 2, format);
1701 else /* copy front */
1702 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1703 0, format);
1707 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1708 struct hda_codec *codec,
1709 unsigned int stream_tag,
1710 unsigned int format,
1711 struct snd_pcm_substream *substream)
1713 struct via_spec *spec = codec->spec;
1714 struct hda_multi_out *mout = &spec->multiout;
1715 hda_nid_t *nids = mout->dac_nids;
1717 if (substream->number == 0)
1718 playback_multi_pcm_prep_0(codec, stream_tag, format,
1719 substream);
1720 else {
1721 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1722 spec->hp_independent_mode)
1723 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1724 stream_tag, 0, format);
1726 vt1708_start_hp_work(spec);
1727 return 0;
1730 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1731 struct hda_codec *codec,
1732 struct snd_pcm_substream *substream)
1734 struct via_spec *spec = codec->spec;
1735 struct hda_multi_out *mout = &spec->multiout;
1736 hda_nid_t *nids = mout->dac_nids;
1737 int i;
1739 if (substream->number == 0) {
1740 for (i = 0; i < mout->num_dacs; i++)
1741 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1743 if (mout->hp_nid && !spec->hp_independent_mode)
1744 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1745 0, 0, 0);
1747 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1748 if (mout->extra_out_nid[i])
1749 snd_hda_codec_setup_stream(codec,
1750 mout->extra_out_nid[i],
1751 0, 0, 0);
1752 mutex_lock(&codec->spdif_mutex);
1753 if (mout->dig_out_nid &&
1754 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1755 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1756 0, 0, 0);
1757 mout->dig_out_used = 0;
1759 mutex_unlock(&codec->spdif_mutex);
1760 } else {
1761 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1762 spec->hp_independent_mode)
1763 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1764 0, 0, 0);
1766 vt1708_stop_hp_work(spec);
1767 return 0;
1771 * Digital out
1773 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1774 struct hda_codec *codec,
1775 struct snd_pcm_substream *substream)
1777 struct via_spec *spec = codec->spec;
1778 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1781 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1782 struct hda_codec *codec,
1783 struct snd_pcm_substream *substream)
1785 struct via_spec *spec = codec->spec;
1786 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1789 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1790 struct hda_codec *codec,
1791 unsigned int stream_tag,
1792 unsigned int format,
1793 struct snd_pcm_substream *substream)
1795 struct via_spec *spec = codec->spec;
1796 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1797 stream_tag, format, substream);
1800 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1801 struct hda_codec *codec,
1802 struct snd_pcm_substream *substream)
1804 struct via_spec *spec = codec->spec;
1805 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1806 return 0;
1810 * Analog capture
1812 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1813 struct hda_codec *codec,
1814 unsigned int stream_tag,
1815 unsigned int format,
1816 struct snd_pcm_substream *substream)
1818 struct via_spec *spec = codec->spec;
1820 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1821 stream_tag, 0, format);
1822 return 0;
1825 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1826 struct hda_codec *codec,
1827 struct snd_pcm_substream *substream)
1829 struct via_spec *spec = codec->spec;
1830 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1831 return 0;
1834 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1835 .substreams = 2,
1836 .channels_min = 2,
1837 .channels_max = 8,
1838 .nid = 0x10, /* NID to query formats and rates */
1839 .ops = {
1840 .open = via_playback_pcm_open,
1841 .prepare = via_playback_multi_pcm_prepare,
1842 .cleanup = via_playback_multi_pcm_cleanup
1846 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1847 .substreams = 2,
1848 .channels_min = 2,
1849 .channels_max = 8,
1850 .nid = 0x10, /* NID to query formats and rates */
1851 /* We got noisy outputs on the right channel on VT1708 when
1852 * 24bit samples are used. Until any workaround is found,
1853 * disable the 24bit format, so far.
1855 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1856 .ops = {
1857 .open = via_playback_pcm_open,
1858 .prepare = via_playback_multi_pcm_prepare,
1859 .cleanup = via_playback_multi_pcm_cleanup
1863 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1864 .substreams = 2,
1865 .channels_min = 2,
1866 .channels_max = 2,
1867 .nid = 0x15, /* NID to query formats and rates */
1868 .ops = {
1869 .prepare = via_capture_pcm_prepare,
1870 .cleanup = via_capture_pcm_cleanup
1874 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1875 .substreams = 1,
1876 .channels_min = 2,
1877 .channels_max = 2,
1878 /* NID is set in via_build_pcms */
1879 .ops = {
1880 .open = via_dig_playback_pcm_open,
1881 .close = via_dig_playback_pcm_close,
1882 .prepare = via_dig_playback_pcm_prepare,
1883 .cleanup = via_dig_playback_pcm_cleanup
1887 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1888 .substreams = 1,
1889 .channels_min = 2,
1890 .channels_max = 2,
1893 static int via_build_controls(struct hda_codec *codec)
1895 struct via_spec *spec = codec->spec;
1896 struct snd_kcontrol *kctl;
1897 struct snd_kcontrol_new *knew;
1898 int err, i;
1900 for (i = 0; i < spec->num_mixers; i++) {
1901 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1902 if (err < 0)
1903 return err;
1906 if (spec->multiout.dig_out_nid) {
1907 err = snd_hda_create_spdif_out_ctls(codec,
1908 spec->multiout.dig_out_nid);
1909 if (err < 0)
1910 return err;
1911 err = snd_hda_create_spdif_share_sw(codec,
1912 &spec->multiout);
1913 if (err < 0)
1914 return err;
1915 spec->multiout.share_spdif = 1;
1917 if (spec->dig_in_nid) {
1918 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1919 if (err < 0)
1920 return err;
1923 /* assign Capture Source enums to NID */
1924 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1925 for (i = 0; kctl && i < kctl->count; i++) {
1926 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1927 if (err < 0)
1928 return err;
1931 /* other nid->control mapping */
1932 for (i = 0; i < spec->num_mixers; i++) {
1933 for (knew = spec->mixers[i]; knew->name; knew++) {
1934 if (knew->iface != NID_MAPPING)
1935 continue;
1936 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1937 if (kctl == NULL)
1938 continue;
1939 err = snd_hda_add_nid(codec, kctl, 0,
1940 knew->subdevice);
1944 /* init power states */
1945 set_jack_power_state(codec);
1946 analog_low_current_mode(codec, 1);
1948 via_free_kctls(codec); /* no longer needed */
1949 return 0;
1952 static int via_build_pcms(struct hda_codec *codec)
1954 struct via_spec *spec = codec->spec;
1955 struct hda_pcm *info = spec->pcm_rec;
1957 codec->num_pcms = 1;
1958 codec->pcm_info = info;
1960 info->name = spec->stream_name_analog;
1961 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1962 *(spec->stream_analog_playback);
1963 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1964 spec->multiout.dac_nids[0];
1965 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1966 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1968 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1969 spec->multiout.max_channels;
1971 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1972 codec->num_pcms++;
1973 info++;
1974 info->name = spec->stream_name_digital;
1975 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1976 if (spec->multiout.dig_out_nid) {
1977 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1978 *(spec->stream_digital_playback);
1979 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1980 spec->multiout.dig_out_nid;
1982 if (spec->dig_in_nid) {
1983 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1984 *(spec->stream_digital_capture);
1985 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1986 spec->dig_in_nid;
1990 return 0;
1993 static void via_free(struct hda_codec *codec)
1995 struct via_spec *spec = codec->spec;
1997 if (!spec)
1998 return;
2000 via_free_kctls(codec);
2001 vt1708_stop_hp_work(spec);
2002 kfree(codec->spec);
2005 /* mute internal speaker if HP is plugged */
2006 static void via_hp_automute(struct hda_codec *codec)
2008 unsigned int present = 0;
2009 struct via_spec *spec = codec->spec;
2011 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2013 if (!spec->hp_independent_mode) {
2014 struct snd_ctl_elem_id id;
2015 /* auto mute */
2016 snd_hda_codec_amp_stereo(
2017 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
2018 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2019 /* notify change */
2020 memset(&id, 0, sizeof(id));
2021 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2022 strcpy(id.name, "Front Playback Switch");
2023 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2024 &id);
2028 /* mute mono out if HP or Line out is plugged */
2029 static void via_mono_automute(struct hda_codec *codec)
2031 unsigned int hp_present, lineout_present;
2032 struct via_spec *spec = codec->spec;
2034 if (spec->codec_type != VT1716S)
2035 return;
2037 lineout_present = snd_hda_jack_detect(codec,
2038 spec->autocfg.line_out_pins[0]);
2040 /* Mute Mono Out if Line Out is plugged */
2041 if (lineout_present) {
2042 snd_hda_codec_amp_stereo(
2043 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
2044 return;
2047 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2049 if (!spec->hp_independent_mode)
2050 snd_hda_codec_amp_stereo(
2051 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
2052 hp_present ? HDA_AMP_MUTE : 0);
2055 static void via_gpio_control(struct hda_codec *codec)
2057 unsigned int gpio_data;
2058 unsigned int vol_counter;
2059 unsigned int vol;
2060 unsigned int master_vol;
2062 struct via_spec *spec = codec->spec;
2064 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
2065 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
2067 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
2068 0xF84, 0) & 0x3F0000) >> 16;
2070 vol = vol_counter & 0x1F;
2071 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
2072 AC_VERB_GET_AMP_GAIN_MUTE,
2073 AC_AMP_GET_INPUT);
2075 if (gpio_data == 0x02) {
2076 /* unmute line out */
2077 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
2078 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
2080 if (vol_counter & 0x20) {
2081 /* decrease volume */
2082 if (vol > master_vol)
2083 vol = master_vol;
2084 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
2085 0, HDA_AMP_VOLMASK,
2086 master_vol-vol);
2087 } else {
2088 /* increase volume */
2089 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
2090 HDA_AMP_VOLMASK,
2091 ((master_vol+vol) > 0x2A) ? 0x2A :
2092 (master_vol+vol));
2094 } else if (!(gpio_data & 0x02)) {
2095 /* mute line out */
2096 snd_hda_codec_amp_stereo(codec,
2097 spec->autocfg.line_out_pins[0],
2098 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2099 HDA_AMP_MUTE);
2103 /* mute Internal-Speaker if HP is plugged */
2104 static void via_speaker_automute(struct hda_codec *codec)
2106 unsigned int hp_present;
2107 struct via_spec *spec = codec->spec;
2109 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2110 return;
2112 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2114 if (!spec->hp_independent_mode) {
2115 struct snd_ctl_elem_id id;
2116 snd_hda_codec_amp_stereo(
2117 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2118 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2119 /* notify change */
2120 memset(&id, 0, sizeof(id));
2121 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2122 strcpy(id.name, "Speaker Playback Switch");
2123 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2124 &id);
2128 /* mute line-out and internal speaker if HP is plugged */
2129 static void via_hp_bind_automute(struct hda_codec *codec)
2131 /* use long instead of int below just to avoid an internal compiler
2132 * error with gcc 4.0.x
2134 unsigned long hp_present, present = 0;
2135 struct via_spec *spec = codec->spec;
2136 int i;
2138 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2139 return;
2141 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2143 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2145 if (!spec->hp_independent_mode) {
2146 /* Mute Line-Outs */
2147 for (i = 0; i < spec->autocfg.line_outs; i++)
2148 snd_hda_codec_amp_stereo(
2149 codec, spec->autocfg.line_out_pins[i],
2150 HDA_OUTPUT, 0,
2151 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2152 if (hp_present)
2153 present = hp_present;
2155 /* Speakers */
2156 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2157 snd_hda_codec_amp_stereo(
2158 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2159 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2163 /* unsolicited event for jack sensing */
2164 static void via_unsol_event(struct hda_codec *codec,
2165 unsigned int res)
2167 res >>= 26;
2168 if (res & VIA_HP_EVENT)
2169 via_hp_automute(codec);
2170 if (res & VIA_GPIO_EVENT)
2171 via_gpio_control(codec);
2172 if (res & VIA_JACK_EVENT)
2173 set_jack_power_state(codec);
2174 if (res & VIA_MONO_EVENT)
2175 via_mono_automute(codec);
2176 if (res & VIA_SPEAKER_EVENT)
2177 via_speaker_automute(codec);
2178 if (res & VIA_BIND_HP_EVENT)
2179 via_hp_bind_automute(codec);
2182 static int via_init(struct hda_codec *codec)
2184 struct via_spec *spec = codec->spec;
2185 int i;
2186 for (i = 0; i < spec->num_iverbs; i++)
2187 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2189 spec->codec_type = get_codec_type(codec);
2190 if (spec->codec_type == VT1708BCE)
2191 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2192 same */
2193 /* Lydia Add for EAPD enable */
2194 if (!spec->dig_in_nid) { /* No Digital In connection */
2195 if (spec->dig_in_pin) {
2196 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2197 AC_VERB_SET_PIN_WIDGET_CONTROL,
2198 PIN_OUT);
2199 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2200 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2202 } else /* enable SPDIF-input pin */
2203 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2204 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2206 /* assign slave outs */
2207 if (spec->slave_dig_outs[0])
2208 codec->slave_dig_outs = spec->slave_dig_outs;
2210 return 0;
2213 #ifdef SND_HDA_NEEDS_RESUME
2214 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2216 struct via_spec *spec = codec->spec;
2217 vt1708_stop_hp_work(spec);
2218 return 0;
2220 #endif
2222 #ifdef CONFIG_SND_HDA_POWER_SAVE
2223 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2225 struct via_spec *spec = codec->spec;
2226 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2228 #endif
2232 static struct hda_codec_ops via_patch_ops = {
2233 .build_controls = via_build_controls,
2234 .build_pcms = via_build_pcms,
2235 .init = via_init,
2236 .free = via_free,
2237 #ifdef SND_HDA_NEEDS_RESUME
2238 .suspend = via_suspend,
2239 #endif
2240 #ifdef CONFIG_SND_HDA_POWER_SAVE
2241 .check_power_status = via_check_power_status,
2242 #endif
2245 /* fill in the dac_nids table from the parsed pin configuration */
2246 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2247 const struct auto_pin_cfg *cfg)
2249 int i;
2250 hda_nid_t nid;
2252 spec->multiout.num_dacs = cfg->line_outs;
2254 spec->multiout.dac_nids = spec->private_dac_nids;
2256 for (i = 0; i < 4; i++) {
2257 nid = cfg->line_out_pins[i];
2258 if (nid) {
2259 /* config dac list */
2260 switch (i) {
2261 case AUTO_SEQ_FRONT:
2262 spec->multiout.dac_nids[i] = 0x10;
2263 break;
2264 case AUTO_SEQ_CENLFE:
2265 spec->multiout.dac_nids[i] = 0x12;
2266 break;
2267 case AUTO_SEQ_SURROUND:
2268 spec->multiout.dac_nids[i] = 0x11;
2269 break;
2270 case AUTO_SEQ_SIDE:
2271 spec->multiout.dac_nids[i] = 0x13;
2272 break;
2277 return 0;
2280 /* add playback controls from the parsed DAC table */
2281 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2282 const struct auto_pin_cfg *cfg)
2284 char name[32];
2285 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2286 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2287 int i, err;
2289 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2290 nid = cfg->line_out_pins[i];
2292 if (!nid)
2293 continue;
2295 nid_vol = nid_vols[i];
2297 if (i == AUTO_SEQ_CENLFE) {
2298 /* Center/LFE */
2299 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2300 "Center Playback Volume",
2301 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2302 HDA_OUTPUT));
2303 if (err < 0)
2304 return err;
2305 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2306 "LFE Playback Volume",
2307 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2308 HDA_OUTPUT));
2309 if (err < 0)
2310 return err;
2311 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2312 "Center Playback Switch",
2313 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2314 HDA_OUTPUT));
2315 if (err < 0)
2316 return err;
2317 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2318 "LFE Playback Switch",
2319 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2320 HDA_OUTPUT));
2321 if (err < 0)
2322 return err;
2323 } else if (i == AUTO_SEQ_FRONT) {
2324 /* add control to mixer index 0 */
2325 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2326 "Master Front Playback Volume",
2327 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2328 HDA_INPUT));
2329 if (err < 0)
2330 return err;
2331 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2332 "Master Front Playback Switch",
2333 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2334 HDA_INPUT));
2335 if (err < 0)
2336 return err;
2338 /* add control to PW3 */
2339 sprintf(name, "%s Playback Volume", chname[i]);
2340 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2341 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2342 HDA_OUTPUT));
2343 if (err < 0)
2344 return err;
2345 sprintf(name, "%s Playback Switch", chname[i]);
2346 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2347 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2348 HDA_OUTPUT));
2349 if (err < 0)
2350 return err;
2351 } else {
2352 sprintf(name, "%s Playback Volume", chname[i]);
2353 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2354 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2355 HDA_OUTPUT));
2356 if (err < 0)
2357 return err;
2358 sprintf(name, "%s Playback Switch", chname[i]);
2359 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2360 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2361 HDA_OUTPUT));
2362 if (err < 0)
2363 return err;
2367 return 0;
2370 static void create_hp_imux(struct via_spec *spec)
2372 int i;
2373 struct hda_input_mux *imux = &spec->private_imux[1];
2374 static const char *texts[] = { "OFF", "ON", NULL};
2376 /* for hp mode select */
2377 i = 0;
2378 while (texts[i] != NULL) {
2379 strcpy(imux->items[imux->num_items].label, texts[i]);
2380 imux->items[imux->num_items].index = i;
2381 imux->num_items++;
2382 i++;
2385 spec->hp_mux = &spec->private_imux[1];
2388 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2390 int err;
2392 if (!pin)
2393 return 0;
2395 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2396 spec->hp_independent_mode_index = 1;
2398 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2399 "Headphone Playback Volume",
2400 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2401 if (err < 0)
2402 return err;
2403 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2404 "Headphone Playback Switch",
2405 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2406 if (err < 0)
2407 return err;
2409 create_hp_imux(spec);
2411 return 0;
2414 /* create playback/capture controls for input pins */
2415 static int vt_auto_create_analog_input_ctls(struct via_spec *spec,
2416 const struct auto_pin_cfg *cfg,
2417 hda_nid_t cap_nid,
2418 hda_nid_t pin_idxs[], int num_idxs)
2420 struct hda_input_mux *imux = &spec->private_imux[0];
2421 int i, err, idx, type, type_idx = 0;
2423 /* for internal loopback recording select */
2424 for (idx = 0; idx < num_idxs; idx++) {
2425 if (pin_idxs[idx] == 0xff) {
2426 strcpy(imux->items[imux->num_items].label,
2427 "Stereo Mixer");
2428 imux->items[imux->num_items].index = idx;
2429 imux->num_items++;
2430 break;
2434 for (i = 0; i < cfg->num_inputs; i++) {
2435 type = cfg->inputs[i].type;
2436 for (idx = 0; idx < num_idxs; idx++)
2437 if (pin_idxs[idx] == cfg->inputs[i].pin)
2438 break;
2439 if (idx >= num_idxs)
2440 continue;
2441 if (i > 0 && type == cfg->inputs[i - 1].type)
2442 type_idx++;
2443 else
2444 type_idx = 0;
2445 err = via_new_analog_input(spec, auto_pin_cfg_labels[type],
2446 type_idx, idx, cap_nid);
2447 if (err < 0)
2448 return err;
2449 snd_hda_get_input_pin_label(cfg, i,
2450 imux->items[imux->num_items].label);
2451 imux->items[imux->num_items].index = idx;
2452 imux->num_items++;
2454 return 0;
2457 /* create playback/capture controls for input pins */
2458 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
2459 const struct auto_pin_cfg *cfg)
2461 static hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2462 return vt_auto_create_analog_input_ctls(spec, cfg, 0x17, pin_idxs,
2463 ARRAY_SIZE(pin_idxs));
2466 #ifdef CONFIG_SND_HDA_POWER_SAVE
2467 static struct hda_amp_list vt1708_loopbacks[] = {
2468 { 0x17, HDA_INPUT, 1 },
2469 { 0x17, HDA_INPUT, 2 },
2470 { 0x17, HDA_INPUT, 3 },
2471 { 0x17, HDA_INPUT, 4 },
2472 { } /* end */
2474 #endif
2476 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2478 unsigned int def_conf;
2479 unsigned char seqassoc;
2481 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2482 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2483 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2484 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2485 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2486 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2487 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2490 return;
2493 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2494 struct snd_ctl_elem_value *ucontrol)
2496 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2497 struct via_spec *spec = codec->spec;
2499 if (spec->codec_type != VT1708)
2500 return 0;
2501 spec->vt1708_jack_detectect =
2502 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2503 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2504 return 0;
2507 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2508 struct snd_ctl_elem_value *ucontrol)
2510 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2511 struct via_spec *spec = codec->spec;
2512 int change;
2514 if (spec->codec_type != VT1708)
2515 return 0;
2516 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2517 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2518 == !spec->vt1708_jack_detectect;
2519 if (spec->vt1708_jack_detectect) {
2520 mute_aa_path(codec, 1);
2521 notify_aa_path_ctls(codec);
2523 return change;
2526 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2528 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2529 .name = "Jack Detect",
2530 .count = 1,
2531 .info = snd_ctl_boolean_mono_info,
2532 .get = vt1708_jack_detectect_get,
2533 .put = vt1708_jack_detectect_put,
2535 {} /* end */
2538 static int vt1708_parse_auto_config(struct hda_codec *codec)
2540 struct via_spec *spec = codec->spec;
2541 int err;
2543 /* Add HP and CD pin config connect bit re-config action */
2544 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2545 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2547 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2548 if (err < 0)
2549 return err;
2550 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2551 if (err < 0)
2552 return err;
2553 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2554 return 0; /* can't find valid BIOS pin config */
2556 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2557 if (err < 0)
2558 return err;
2559 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2560 if (err < 0)
2561 return err;
2562 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
2563 if (err < 0)
2564 return err;
2565 /* add jack detect on/off control */
2566 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2567 if (err < 0)
2568 return err;
2570 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2572 if (spec->autocfg.dig_outs)
2573 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2574 spec->dig_in_pin = VT1708_DIGIN_PIN;
2575 if (spec->autocfg.dig_in_pin)
2576 spec->dig_in_nid = VT1708_DIGIN_NID;
2578 if (spec->kctls.list)
2579 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2581 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2583 spec->input_mux = &spec->private_imux[0];
2585 if (spec->hp_mux)
2586 via_hp_build(codec);
2588 via_smart51_build(spec);
2589 return 1;
2592 /* init callback for auto-configuration model -- overriding the default init */
2593 static int via_auto_init(struct hda_codec *codec)
2595 struct via_spec *spec = codec->spec;
2597 via_init(codec);
2598 via_auto_init_multi_out(codec);
2599 via_auto_init_hp_out(codec);
2600 via_auto_init_analog_input(codec);
2601 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2602 via_hp_bind_automute(codec);
2603 } else {
2604 via_hp_automute(codec);
2605 via_speaker_automute(codec);
2608 return 0;
2611 static void vt1708_update_hp_jack_state(struct work_struct *work)
2613 struct via_spec *spec = container_of(work, struct via_spec,
2614 vt1708_hp_work.work);
2615 if (spec->codec_type != VT1708)
2616 return;
2617 /* if jack state toggled */
2618 if (spec->vt1708_hp_present
2619 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2620 spec->vt1708_hp_present ^= 1;
2621 via_hp_automute(spec->codec);
2623 vt1708_start_hp_work(spec);
2626 static int get_mux_nids(struct hda_codec *codec)
2628 struct via_spec *spec = codec->spec;
2629 hda_nid_t nid, conn[8];
2630 unsigned int type;
2631 int i, n;
2633 for (i = 0; i < spec->num_adc_nids; i++) {
2634 nid = spec->adc_nids[i];
2635 while (nid) {
2636 type = get_wcaps_type(get_wcaps(codec, nid));
2637 if (type == AC_WID_PIN)
2638 break;
2639 n = snd_hda_get_connections(codec, nid, conn,
2640 ARRAY_SIZE(conn));
2641 if (n <= 0)
2642 break;
2643 if (n > 1) {
2644 spec->mux_nids[i] = nid;
2645 break;
2647 nid = conn[0];
2650 return 0;
2653 static int patch_vt1708(struct hda_codec *codec)
2655 struct via_spec *spec;
2656 int err;
2658 /* create a codec specific record */
2659 spec = via_new_spec(codec);
2660 if (spec == NULL)
2661 return -ENOMEM;
2663 /* automatic parse from the BIOS config */
2664 err = vt1708_parse_auto_config(codec);
2665 if (err < 0) {
2666 via_free(codec);
2667 return err;
2668 } else if (!err) {
2669 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2670 "from BIOS. Using genenic mode...\n");
2674 spec->stream_name_analog = "VT1708 Analog";
2675 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2676 /* disable 32bit format on VT1708 */
2677 if (codec->vendor_id == 0x11061708)
2678 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2679 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2681 spec->stream_name_digital = "VT1708 Digital";
2682 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2683 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2686 if (!spec->adc_nids && spec->input_mux) {
2687 spec->adc_nids = vt1708_adc_nids;
2688 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2689 get_mux_nids(codec);
2690 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2691 spec->num_mixers++;
2694 codec->patch_ops = via_patch_ops;
2696 codec->patch_ops.init = via_auto_init;
2697 #ifdef CONFIG_SND_HDA_POWER_SAVE
2698 spec->loopback.amplist = vt1708_loopbacks;
2699 #endif
2700 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2701 return 0;
2704 /* capture mixer elements */
2705 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2706 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2707 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2708 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2709 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2710 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2711 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2713 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2714 /* The multiple "Capture Source" controls confuse alsamixer
2715 * So call somewhat different..
2717 /* .name = "Capture Source", */
2718 .name = "Input Source",
2719 .count = 1,
2720 .info = via_mux_enum_info,
2721 .get = via_mux_enum_get,
2722 .put = via_mux_enum_put,
2724 { } /* end */
2727 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2728 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2729 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2734 * generic initialization of ADC, input mixers and output mixers
2736 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2738 * Unmute ADC0-2 and set the default input to mic-in
2740 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2741 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2742 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2745 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2746 * mixer widget
2748 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2749 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2750 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2751 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2752 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2753 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2756 * Set up output selector (0x1a, 0x1b, 0x29)
2758 /* set vol=0 to output mixers */
2759 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2760 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2761 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2764 * Unmute PW3 and PW4
2766 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2767 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2769 /* Set input of PW4 as MW0 */
2770 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2771 /* PW9 Output enable */
2772 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2776 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2777 .substreams = 1,
2778 .channels_min = 2,
2779 .channels_max = 10,
2780 .nid = 0x10, /* NID to query formats and rates */
2781 .ops = {
2782 .open = via_playback_pcm_open,
2783 .prepare = via_playback_multi_pcm_prepare,
2784 .cleanup = via_playback_multi_pcm_cleanup,
2788 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2789 .substreams = 1,
2790 .channels_min = 2,
2791 .channels_max = 6,
2792 .nid = 0x10, /* NID to query formats and rates */
2793 .ops = {
2794 .open = via_playback_pcm_open,
2795 .prepare = via_playback_multi_pcm_prepare,
2796 .cleanup = via_playback_multi_pcm_cleanup,
2800 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2801 .substreams = 2,
2802 .channels_min = 2,
2803 .channels_max = 2,
2804 .nid = 0x14, /* NID to query formats and rates */
2805 .ops = {
2806 .prepare = via_capture_pcm_prepare,
2807 .cleanup = via_capture_pcm_cleanup
2811 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2812 .substreams = 1,
2813 .channels_min = 2,
2814 .channels_max = 2,
2815 /* NID is set in via_build_pcms */
2816 .ops = {
2817 .open = via_dig_playback_pcm_open,
2818 .close = via_dig_playback_pcm_close
2822 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2823 .substreams = 1,
2824 .channels_min = 2,
2825 .channels_max = 2,
2828 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2829 const struct auto_pin_cfg *cfg)
2831 int i;
2832 hda_nid_t nid;
2834 if (cfg->line_outs == 4) /* 10 channels */
2835 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2836 else if (cfg->line_outs == 3) /* 6 channels */
2837 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2839 spec->multiout.dac_nids = spec->private_dac_nids;
2841 if (cfg->line_outs == 4) { /* 10 channels */
2842 for (i = 0; i < cfg->line_outs; i++) {
2843 nid = cfg->line_out_pins[i];
2844 if (nid) {
2845 /* config dac list */
2846 switch (i) {
2847 case AUTO_SEQ_FRONT:
2848 /* AOW0 */
2849 spec->multiout.dac_nids[i] = 0x10;
2850 break;
2851 case AUTO_SEQ_CENLFE:
2852 /* AOW2 */
2853 spec->multiout.dac_nids[i] = 0x12;
2854 break;
2855 case AUTO_SEQ_SURROUND:
2856 /* AOW3 */
2857 spec->multiout.dac_nids[i] = 0x11;
2858 break;
2859 case AUTO_SEQ_SIDE:
2860 /* AOW1 */
2861 spec->multiout.dac_nids[i] = 0x27;
2862 break;
2863 default:
2864 break;
2868 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2870 } else if (cfg->line_outs == 3) { /* 6 channels */
2871 for (i = 0; i < cfg->line_outs; i++) {
2872 nid = cfg->line_out_pins[i];
2873 if (nid) {
2874 /* config dac list */
2875 switch (i) {
2876 case AUTO_SEQ_FRONT:
2877 /* AOW0 */
2878 spec->multiout.dac_nids[i] = 0x10;
2879 break;
2880 case AUTO_SEQ_CENLFE:
2881 /* AOW2 */
2882 spec->multiout.dac_nids[i] = 0x12;
2883 break;
2884 case AUTO_SEQ_SURROUND:
2885 /* AOW1 */
2886 spec->multiout.dac_nids[i] = 0x11;
2887 break;
2888 default:
2889 break;
2895 return 0;
2898 /* add playback controls from the parsed DAC table */
2899 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2900 const struct auto_pin_cfg *cfg)
2902 char name[32];
2903 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2904 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2905 int i, err;
2907 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2908 nid = cfg->line_out_pins[i];
2910 if (!nid)
2911 continue;
2913 nid_vol = nid_vols[i];
2915 if (i == AUTO_SEQ_CENLFE) {
2916 /* Center/LFE */
2917 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2918 "Center Playback Volume",
2919 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2920 HDA_OUTPUT));
2921 if (err < 0)
2922 return err;
2923 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2924 "LFE Playback Volume",
2925 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2926 HDA_OUTPUT));
2927 if (err < 0)
2928 return err;
2929 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2930 "Center Playback Switch",
2931 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2932 HDA_OUTPUT));
2933 if (err < 0)
2934 return err;
2935 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2936 "LFE Playback Switch",
2937 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2938 HDA_OUTPUT));
2939 if (err < 0)
2940 return err;
2941 } else if (i == AUTO_SEQ_FRONT) {
2942 /* ADD control to mixer index 0 */
2943 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2944 "Master Front Playback Volume",
2945 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2946 HDA_INPUT));
2947 if (err < 0)
2948 return err;
2949 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2950 "Master Front Playback Switch",
2951 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2952 HDA_INPUT));
2953 if (err < 0)
2954 return err;
2956 /* add control to PW3 */
2957 sprintf(name, "%s Playback Volume", chname[i]);
2958 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2959 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2960 HDA_OUTPUT));
2961 if (err < 0)
2962 return err;
2963 sprintf(name, "%s Playback Switch", chname[i]);
2964 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2965 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2966 HDA_OUTPUT));
2967 if (err < 0)
2968 return err;
2969 } else if (i == AUTO_SEQ_SURROUND) {
2970 sprintf(name, "%s Playback Volume", chname[i]);
2971 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2972 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2973 HDA_OUTPUT));
2974 if (err < 0)
2975 return err;
2976 sprintf(name, "%s Playback Switch", chname[i]);
2977 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2978 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2979 HDA_OUTPUT));
2980 if (err < 0)
2981 return err;
2982 } else if (i == AUTO_SEQ_SIDE) {
2983 sprintf(name, "%s Playback Volume", chname[i]);
2984 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2985 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2986 HDA_OUTPUT));
2987 if (err < 0)
2988 return err;
2989 sprintf(name, "%s Playback Switch", chname[i]);
2990 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2991 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2992 HDA_OUTPUT));
2993 if (err < 0)
2994 return err;
2998 return 0;
3001 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3003 int err;
3005 if (!pin)
3006 return 0;
3008 if (spec->multiout.num_dacs == 5) /* 10 channels */
3009 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
3010 else if (spec->multiout.num_dacs == 3) /* 6 channels */
3011 spec->multiout.hp_nid = 0;
3012 spec->hp_independent_mode_index = 1;
3014 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3015 "Headphone Playback Volume",
3016 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3017 if (err < 0)
3018 return err;
3019 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3020 "Headphone Playback Switch",
3021 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3022 if (err < 0)
3023 return err;
3025 return 0;
3028 /* create playback/capture controls for input pins */
3029 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
3030 const struct auto_pin_cfg *cfg)
3032 static hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
3033 return vt_auto_create_analog_input_ctls(spec, cfg, 0x18, pin_idxs,
3034 ARRAY_SIZE(pin_idxs));
3037 static int vt1709_parse_auto_config(struct hda_codec *codec)
3039 struct via_spec *spec = codec->spec;
3040 int err;
3042 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3043 if (err < 0)
3044 return err;
3045 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
3046 if (err < 0)
3047 return err;
3048 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3049 return 0; /* can't find valid BIOS pin config */
3051 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
3052 if (err < 0)
3053 return err;
3054 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3055 if (err < 0)
3056 return err;
3057 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
3058 if (err < 0)
3059 return err;
3061 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3063 if (spec->autocfg.dig_outs)
3064 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3065 spec->dig_in_pin = VT1709_DIGIN_PIN;
3066 if (spec->autocfg.dig_in_pin)
3067 spec->dig_in_nid = VT1709_DIGIN_NID;
3069 if (spec->kctls.list)
3070 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3072 spec->input_mux = &spec->private_imux[0];
3074 if (spec->hp_mux)
3075 via_hp_build(codec);
3077 via_smart51_build(spec);
3078 return 1;
3081 #ifdef CONFIG_SND_HDA_POWER_SAVE
3082 static struct hda_amp_list vt1709_loopbacks[] = {
3083 { 0x18, HDA_INPUT, 1 },
3084 { 0x18, HDA_INPUT, 2 },
3085 { 0x18, HDA_INPUT, 3 },
3086 { 0x18, HDA_INPUT, 4 },
3087 { } /* end */
3089 #endif
3091 static int patch_vt1709_10ch(struct hda_codec *codec)
3093 struct via_spec *spec;
3094 int err;
3096 /* create a codec specific record */
3097 spec = via_new_spec(codec);
3098 if (spec == NULL)
3099 return -ENOMEM;
3101 err = vt1709_parse_auto_config(codec);
3102 if (err < 0) {
3103 via_free(codec);
3104 return err;
3105 } else if (!err) {
3106 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3107 "Using genenic mode...\n");
3110 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3111 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3113 spec->stream_name_analog = "VT1709 Analog";
3114 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3115 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3117 spec->stream_name_digital = "VT1709 Digital";
3118 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3119 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3122 if (!spec->adc_nids && spec->input_mux) {
3123 spec->adc_nids = vt1709_adc_nids;
3124 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3125 get_mux_nids(codec);
3126 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3127 spec->num_mixers++;
3130 codec->patch_ops = via_patch_ops;
3132 codec->patch_ops.init = via_auto_init;
3133 codec->patch_ops.unsol_event = via_unsol_event;
3134 #ifdef CONFIG_SND_HDA_POWER_SAVE
3135 spec->loopback.amplist = vt1709_loopbacks;
3136 #endif
3138 return 0;
3141 * generic initialization of ADC, input mixers and output mixers
3143 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3145 * Unmute ADC0-2 and set the default input to mic-in
3147 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3148 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3149 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3152 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3153 * mixer widget
3155 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3156 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3157 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3158 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3159 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3160 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3163 * Set up output selector (0x1a, 0x1b, 0x29)
3165 /* set vol=0 to output mixers */
3166 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3167 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3168 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3171 * Unmute PW3 and PW4
3173 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3174 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3176 /* Set input of PW4 as MW0 */
3177 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3178 /* PW9 Output enable */
3179 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3183 static int patch_vt1709_6ch(struct hda_codec *codec)
3185 struct via_spec *spec;
3186 int err;
3188 /* create a codec specific record */
3189 spec = via_new_spec(codec);
3190 if (spec == NULL)
3191 return -ENOMEM;
3193 err = vt1709_parse_auto_config(codec);
3194 if (err < 0) {
3195 via_free(codec);
3196 return err;
3197 } else if (!err) {
3198 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3199 "Using genenic mode...\n");
3202 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3203 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3205 spec->stream_name_analog = "VT1709 Analog";
3206 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3207 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3209 spec->stream_name_digital = "VT1709 Digital";
3210 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3211 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3214 if (!spec->adc_nids && spec->input_mux) {
3215 spec->adc_nids = vt1709_adc_nids;
3216 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3217 get_mux_nids(codec);
3218 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3219 spec->num_mixers++;
3222 codec->patch_ops = via_patch_ops;
3224 codec->patch_ops.init = via_auto_init;
3225 codec->patch_ops.unsol_event = via_unsol_event;
3226 #ifdef CONFIG_SND_HDA_POWER_SAVE
3227 spec->loopback.amplist = vt1709_loopbacks;
3228 #endif
3229 return 0;
3232 /* capture mixer elements */
3233 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3234 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3235 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3236 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3237 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3239 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3240 /* The multiple "Capture Source" controls confuse alsamixer
3241 * So call somewhat different..
3243 /* .name = "Capture Source", */
3244 .name = "Input Source",
3245 .count = 1,
3246 .info = via_mux_enum_info,
3247 .get = via_mux_enum_get,
3248 .put = via_mux_enum_put,
3250 { } /* end */
3253 * generic initialization of ADC, input mixers and output mixers
3255 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3257 * Unmute ADC0-1 and set the default input to mic-in
3259 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3260 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3263 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3264 * mixer widget
3266 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3267 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3268 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3269 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3270 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3271 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3274 * Set up output mixers
3276 /* set vol=0 to output mixers */
3277 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3278 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3279 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3281 /* Setup default input to PW4 */
3282 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3283 /* PW9 Output enable */
3284 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3285 /* PW10 Input enable */
3286 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3290 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3292 * Unmute ADC0-1 and set the default input to mic-in
3294 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3295 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3298 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3299 * mixer widget
3301 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3302 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3303 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3304 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3305 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3306 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3309 * Set up output mixers
3311 /* set vol=0 to output mixers */
3312 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3313 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3314 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3316 /* Setup default input of PW4 to MW0 */
3317 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3318 /* PW9 Output enable */
3319 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3320 /* PW10 Input enable */
3321 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3325 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3326 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3327 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3328 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3329 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3330 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3331 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3332 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3333 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3334 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3338 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3339 struct hda_codec *codec,
3340 struct snd_pcm_substream *substream)
3342 int idle = substream->pstr->substream_opened == 1
3343 && substream->ref_count == 0;
3345 analog_low_current_mode(codec, idle);
3346 return 0;
3349 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3350 .substreams = 2,
3351 .channels_min = 2,
3352 .channels_max = 8,
3353 .nid = 0x10, /* NID to query formats and rates */
3354 .ops = {
3355 .open = via_playback_pcm_open,
3356 .prepare = via_playback_multi_pcm_prepare,
3357 .cleanup = via_playback_multi_pcm_cleanup,
3358 .close = via_pcm_open_close
3362 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3363 .substreams = 2,
3364 .channels_min = 2,
3365 .channels_max = 4,
3366 .nid = 0x10, /* NID to query formats and rates */
3367 .ops = {
3368 .open = via_playback_pcm_open,
3369 .prepare = via_playback_multi_pcm_prepare,
3370 .cleanup = via_playback_multi_pcm_cleanup
3374 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3375 .substreams = 2,
3376 .channels_min = 2,
3377 .channels_max = 2,
3378 .nid = 0x13, /* NID to query formats and rates */
3379 .ops = {
3380 .open = via_pcm_open_close,
3381 .prepare = via_capture_pcm_prepare,
3382 .cleanup = via_capture_pcm_cleanup,
3383 .close = via_pcm_open_close
3387 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3388 .substreams = 1,
3389 .channels_min = 2,
3390 .channels_max = 2,
3391 /* NID is set in via_build_pcms */
3392 .ops = {
3393 .open = via_dig_playback_pcm_open,
3394 .close = via_dig_playback_pcm_close,
3395 .prepare = via_dig_playback_pcm_prepare,
3396 .cleanup = via_dig_playback_pcm_cleanup
3400 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3401 .substreams = 1,
3402 .channels_min = 2,
3403 .channels_max = 2,
3406 /* fill in the dac_nids table from the parsed pin configuration */
3407 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3408 const struct auto_pin_cfg *cfg)
3410 int i;
3411 hda_nid_t nid;
3413 spec->multiout.num_dacs = cfg->line_outs;
3415 spec->multiout.dac_nids = spec->private_dac_nids;
3417 for (i = 0; i < 4; i++) {
3418 nid = cfg->line_out_pins[i];
3419 if (nid) {
3420 /* config dac list */
3421 switch (i) {
3422 case AUTO_SEQ_FRONT:
3423 spec->multiout.dac_nids[i] = 0x10;
3424 break;
3425 case AUTO_SEQ_CENLFE:
3426 spec->multiout.dac_nids[i] = 0x24;
3427 break;
3428 case AUTO_SEQ_SURROUND:
3429 spec->multiout.dac_nids[i] = 0x11;
3430 break;
3431 case AUTO_SEQ_SIDE:
3432 spec->multiout.dac_nids[i] = 0x25;
3433 break;
3438 return 0;
3441 /* add playback controls from the parsed DAC table */
3442 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3443 const struct auto_pin_cfg *cfg)
3445 char name[32];
3446 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3447 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3448 hda_nid_t nid, nid_vol = 0;
3449 int i, err;
3451 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3452 nid = cfg->line_out_pins[i];
3454 if (!nid)
3455 continue;
3457 nid_vol = nid_vols[i];
3459 if (i == AUTO_SEQ_CENLFE) {
3460 /* Center/LFE */
3461 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3462 "Center Playback Volume",
3463 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3464 HDA_OUTPUT));
3465 if (err < 0)
3466 return err;
3467 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3468 "LFE Playback Volume",
3469 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3470 HDA_OUTPUT));
3471 if (err < 0)
3472 return err;
3473 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3474 "Center Playback Switch",
3475 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3476 HDA_OUTPUT));
3477 if (err < 0)
3478 return err;
3479 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3480 "LFE Playback Switch",
3481 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3482 HDA_OUTPUT));
3483 if (err < 0)
3484 return err;
3485 } else if (i == AUTO_SEQ_FRONT) {
3486 /* add control to mixer index 0 */
3487 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3488 "Master Front Playback Volume",
3489 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3490 HDA_INPUT));
3491 if (err < 0)
3492 return err;
3493 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3494 "Master Front Playback Switch",
3495 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3496 HDA_INPUT));
3497 if (err < 0)
3498 return err;
3500 /* add control to PW3 */
3501 sprintf(name, "%s Playback Volume", chname[i]);
3502 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3503 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3504 HDA_OUTPUT));
3505 if (err < 0)
3506 return err;
3507 sprintf(name, "%s Playback Switch", chname[i]);
3508 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3509 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3510 HDA_OUTPUT));
3511 if (err < 0)
3512 return err;
3513 } else {
3514 sprintf(name, "%s Playback Volume", chname[i]);
3515 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3516 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3517 HDA_OUTPUT));
3518 if (err < 0)
3519 return err;
3520 sprintf(name, "%s Playback Switch", chname[i]);
3521 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3522 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3523 HDA_OUTPUT));
3524 if (err < 0)
3525 return err;
3529 return 0;
3532 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3534 int err;
3536 if (!pin)
3537 return 0;
3539 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3540 spec->hp_independent_mode_index = 1;
3542 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3543 "Headphone Playback Volume",
3544 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3545 if (err < 0)
3546 return err;
3547 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3548 "Headphone Playback Switch",
3549 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3550 if (err < 0)
3551 return err;
3553 create_hp_imux(spec);
3555 return 0;
3558 /* create playback/capture controls for input pins */
3559 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
3560 const struct auto_pin_cfg *cfg)
3562 static hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3563 return vt_auto_create_analog_input_ctls(spec, cfg, 0x16, pin_idxs,
3564 ARRAY_SIZE(pin_idxs));
3567 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3569 struct via_spec *spec = codec->spec;
3570 int err;
3572 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3573 if (err < 0)
3574 return err;
3575 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3576 if (err < 0)
3577 return err;
3578 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3579 return 0; /* can't find valid BIOS pin config */
3581 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3582 if (err < 0)
3583 return err;
3584 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3585 if (err < 0)
3586 return err;
3587 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
3588 if (err < 0)
3589 return err;
3591 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3593 if (spec->autocfg.dig_outs)
3594 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3595 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3596 if (spec->autocfg.dig_in_pin)
3597 spec->dig_in_nid = VT1708B_DIGIN_NID;
3599 if (spec->kctls.list)
3600 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3602 spec->input_mux = &spec->private_imux[0];
3604 if (spec->hp_mux)
3605 via_hp_build(codec);
3607 via_smart51_build(spec);
3608 return 1;
3611 #ifdef CONFIG_SND_HDA_POWER_SAVE
3612 static struct hda_amp_list vt1708B_loopbacks[] = {
3613 { 0x16, HDA_INPUT, 1 },
3614 { 0x16, HDA_INPUT, 2 },
3615 { 0x16, HDA_INPUT, 3 },
3616 { 0x16, HDA_INPUT, 4 },
3617 { } /* end */
3619 #endif
3620 static int patch_vt1708S(struct hda_codec *codec);
3621 static int patch_vt1708B_8ch(struct hda_codec *codec)
3623 struct via_spec *spec;
3624 int err;
3626 if (get_codec_type(codec) == VT1708BCE)
3627 return patch_vt1708S(codec);
3628 /* create a codec specific record */
3629 spec = via_new_spec(codec);
3630 if (spec == NULL)
3631 return -ENOMEM;
3633 /* automatic parse from the BIOS config */
3634 err = vt1708B_parse_auto_config(codec);
3635 if (err < 0) {
3636 via_free(codec);
3637 return err;
3638 } else if (!err) {
3639 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3640 "from BIOS. Using genenic mode...\n");
3643 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3644 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3646 spec->stream_name_analog = "VT1708B Analog";
3647 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3648 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3650 spec->stream_name_digital = "VT1708B Digital";
3651 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3652 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3654 if (!spec->adc_nids && spec->input_mux) {
3655 spec->adc_nids = vt1708B_adc_nids;
3656 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3657 get_mux_nids(codec);
3658 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3659 spec->num_mixers++;
3662 codec->patch_ops = via_patch_ops;
3664 codec->patch_ops.init = via_auto_init;
3665 codec->patch_ops.unsol_event = via_unsol_event;
3666 #ifdef CONFIG_SND_HDA_POWER_SAVE
3667 spec->loopback.amplist = vt1708B_loopbacks;
3668 #endif
3670 return 0;
3673 static int patch_vt1708B_4ch(struct hda_codec *codec)
3675 struct via_spec *spec;
3676 int err;
3678 /* create a codec specific record */
3679 spec = via_new_spec(codec);
3680 if (spec == NULL)
3681 return -ENOMEM;
3683 /* automatic parse from the BIOS config */
3684 err = vt1708B_parse_auto_config(codec);
3685 if (err < 0) {
3686 via_free(codec);
3687 return err;
3688 } else if (!err) {
3689 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3690 "from BIOS. Using genenic mode...\n");
3693 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3694 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3696 spec->stream_name_analog = "VT1708B Analog";
3697 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3698 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3700 spec->stream_name_digital = "VT1708B Digital";
3701 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3702 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3704 if (!spec->adc_nids && spec->input_mux) {
3705 spec->adc_nids = vt1708B_adc_nids;
3706 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3707 get_mux_nids(codec);
3708 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3709 spec->num_mixers++;
3712 codec->patch_ops = via_patch_ops;
3714 codec->patch_ops.init = via_auto_init;
3715 codec->patch_ops.unsol_event = via_unsol_event;
3716 #ifdef CONFIG_SND_HDA_POWER_SAVE
3717 spec->loopback.amplist = vt1708B_loopbacks;
3718 #endif
3720 return 0;
3723 /* Patch for VT1708S */
3725 /* capture mixer elements */
3726 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3727 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3728 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3729 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3730 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3731 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3732 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3733 HDA_INPUT),
3735 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3736 /* The multiple "Capture Source" controls confuse alsamixer
3737 * So call somewhat different..
3739 /* .name = "Capture Source", */
3740 .name = "Input Source",
3741 .count = 1,
3742 .info = via_mux_enum_info,
3743 .get = via_mux_enum_get,
3744 .put = via_mux_enum_put,
3746 { } /* end */
3749 static struct hda_verb vt1708S_volume_init_verbs[] = {
3750 /* Unmute ADC0-1 and set the default input to mic-in */
3751 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3752 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3754 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3755 * analog-loopback mixer widget */
3756 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3757 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3758 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3759 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3760 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3761 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3763 /* Setup default input of PW4 to MW0 */
3764 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3765 /* PW9, PW10 Output enable */
3766 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3767 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3768 /* Enable Mic Boost Volume backdoor */
3769 {0x1, 0xf98, 0x1},
3770 /* don't bybass mixer */
3771 {0x1, 0xf88, 0xc0},
3775 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3776 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3777 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3778 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3779 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3780 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3781 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3782 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3783 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3784 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3788 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3789 .substreams = 2,
3790 .channels_min = 2,
3791 .channels_max = 8,
3792 .nid = 0x10, /* NID to query formats and rates */
3793 .ops = {
3794 .open = via_playback_pcm_open,
3795 .prepare = via_playback_multi_pcm_prepare,
3796 .cleanup = via_playback_multi_pcm_cleanup,
3797 .close = via_pcm_open_close
3801 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3802 .substreams = 2,
3803 .channels_min = 2,
3804 .channels_max = 2,
3805 .nid = 0x13, /* NID to query formats and rates */
3806 .ops = {
3807 .open = via_pcm_open_close,
3808 .prepare = via_capture_pcm_prepare,
3809 .cleanup = via_capture_pcm_cleanup,
3810 .close = via_pcm_open_close
3814 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3815 .substreams = 1,
3816 .channels_min = 2,
3817 .channels_max = 2,
3818 /* NID is set in via_build_pcms */
3819 .ops = {
3820 .open = via_dig_playback_pcm_open,
3821 .close = via_dig_playback_pcm_close,
3822 .prepare = via_dig_playback_pcm_prepare,
3823 .cleanup = via_dig_playback_pcm_cleanup
3827 /* fill in the dac_nids table from the parsed pin configuration */
3828 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3829 const struct auto_pin_cfg *cfg)
3831 int i;
3832 hda_nid_t nid;
3834 spec->multiout.num_dacs = cfg->line_outs;
3836 spec->multiout.dac_nids = spec->private_dac_nids;
3838 for (i = 0; i < 4; i++) {
3839 nid = cfg->line_out_pins[i];
3840 if (nid) {
3841 /* config dac list */
3842 switch (i) {
3843 case AUTO_SEQ_FRONT:
3844 spec->multiout.dac_nids[i] = 0x10;
3845 break;
3846 case AUTO_SEQ_CENLFE:
3847 spec->multiout.dac_nids[i] = 0x24;
3848 break;
3849 case AUTO_SEQ_SURROUND:
3850 spec->multiout.dac_nids[i] = 0x11;
3851 break;
3852 case AUTO_SEQ_SIDE:
3853 spec->multiout.dac_nids[i] = 0x25;
3854 break;
3859 /* for Smart 5.1, line/mic inputs double as output pins */
3860 if (cfg->line_outs == 1) {
3861 spec->multiout.num_dacs = 3;
3862 spec->multiout.dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3863 spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3866 return 0;
3869 /* add playback controls from the parsed DAC table */
3870 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3871 const struct auto_pin_cfg *cfg)
3873 char name[32];
3874 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3875 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3876 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3877 hda_nid_t nid, nid_vol, nid_mute;
3878 int i, err;
3880 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3881 nid = cfg->line_out_pins[i];
3883 /* for Smart 5.1, there are always at least six channels */
3884 if (!nid && i > AUTO_SEQ_CENLFE)
3885 continue;
3887 nid_vol = nid_vols[i];
3888 nid_mute = nid_mutes[i];
3890 if (i == AUTO_SEQ_CENLFE) {
3891 /* Center/LFE */
3892 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3893 "Center Playback Volume",
3894 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3895 HDA_OUTPUT));
3896 if (err < 0)
3897 return err;
3898 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3899 "LFE Playback Volume",
3900 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3901 HDA_OUTPUT));
3902 if (err < 0)
3903 return err;
3904 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3905 "Center Playback Switch",
3906 HDA_COMPOSE_AMP_VAL(nid_mute,
3907 1, 0,
3908 HDA_OUTPUT));
3909 if (err < 0)
3910 return err;
3911 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3912 "LFE Playback Switch",
3913 HDA_COMPOSE_AMP_VAL(nid_mute,
3914 2, 0,
3915 HDA_OUTPUT));
3916 if (err < 0)
3917 return err;
3918 } else if (i == AUTO_SEQ_FRONT) {
3919 /* add control to mixer index 0 */
3920 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3921 "Master Front Playback Volume",
3922 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3923 HDA_INPUT));
3924 if (err < 0)
3925 return err;
3926 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3927 "Master Front Playback Switch",
3928 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3929 HDA_INPUT));
3930 if (err < 0)
3931 return err;
3933 /* Front */
3934 sprintf(name, "%s Playback Volume", chname[i]);
3935 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3936 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3937 HDA_OUTPUT));
3938 if (err < 0)
3939 return err;
3940 sprintf(name, "%s Playback Switch", chname[i]);
3941 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3942 HDA_COMPOSE_AMP_VAL(nid_mute,
3943 3, 0,
3944 HDA_OUTPUT));
3945 if (err < 0)
3946 return err;
3947 } else {
3948 sprintf(name, "%s Playback Volume", chname[i]);
3949 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3950 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3951 HDA_OUTPUT));
3952 if (err < 0)
3953 return err;
3954 sprintf(name, "%s Playback Switch", chname[i]);
3955 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3956 HDA_COMPOSE_AMP_VAL(nid_mute,
3957 3, 0,
3958 HDA_OUTPUT));
3959 if (err < 0)
3960 return err;
3964 return 0;
3967 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3969 int err;
3971 if (!pin)
3972 return 0;
3974 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3975 spec->hp_independent_mode_index = 1;
3977 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3978 "Headphone Playback Volume",
3979 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3980 if (err < 0)
3981 return err;
3983 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3984 "Headphone Playback Switch",
3985 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3986 if (err < 0)
3987 return err;
3989 create_hp_imux(spec);
3991 return 0;
3994 /* create playback/capture controls for input pins */
3995 static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
3996 const struct auto_pin_cfg *cfg)
3998 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
3999 return vt_auto_create_analog_input_ctls(spec, cfg, 0x16, pin_idxs,
4000 ARRAY_SIZE(pin_idxs));
4003 /* fill out digital output widgets; one for master and one for slave outputs */
4004 static void fill_dig_outs(struct hda_codec *codec)
4006 struct via_spec *spec = codec->spec;
4007 int i;
4009 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4010 hda_nid_t nid;
4011 int conn;
4013 nid = spec->autocfg.dig_out_pins[i];
4014 if (!nid)
4015 continue;
4016 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4017 if (conn < 1)
4018 continue;
4019 if (!spec->multiout.dig_out_nid)
4020 spec->multiout.dig_out_nid = nid;
4021 else {
4022 spec->slave_dig_outs[0] = nid;
4023 break; /* at most two dig outs */
4028 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4030 struct via_spec *spec = codec->spec;
4031 int err;
4033 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4034 if (err < 0)
4035 return err;
4036 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4037 if (err < 0)
4038 return err;
4039 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4040 return 0; /* can't find valid BIOS pin config */
4042 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4043 if (err < 0)
4044 return err;
4045 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4046 if (err < 0)
4047 return err;
4048 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4049 if (err < 0)
4050 return err;
4052 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4054 fill_dig_outs(codec);
4056 if (spec->kctls.list)
4057 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4059 spec->input_mux = &spec->private_imux[0];
4061 if (spec->hp_mux)
4062 via_hp_build(codec);
4064 via_smart51_build(spec);
4065 return 1;
4068 #ifdef CONFIG_SND_HDA_POWER_SAVE
4069 static struct hda_amp_list vt1708S_loopbacks[] = {
4070 { 0x16, HDA_INPUT, 1 },
4071 { 0x16, HDA_INPUT, 2 },
4072 { 0x16, HDA_INPUT, 3 },
4073 { 0x16, HDA_INPUT, 4 },
4074 { } /* end */
4076 #endif
4078 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4079 int offset, int num_steps, int step_size)
4081 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4082 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4083 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4084 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4085 (0 << AC_AMPCAP_MUTE_SHIFT));
4088 static int patch_vt1708S(struct hda_codec *codec)
4090 struct via_spec *spec;
4091 int err;
4093 /* create a codec specific record */
4094 spec = via_new_spec(codec);
4095 if (spec == NULL)
4096 return -ENOMEM;
4098 /* automatic parse from the BIOS config */
4099 err = vt1708S_parse_auto_config(codec);
4100 if (err < 0) {
4101 via_free(codec);
4102 return err;
4103 } else if (!err) {
4104 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4105 "from BIOS. Using genenic mode...\n");
4108 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4109 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4111 if (codec->vendor_id == 0x11060440)
4112 spec->stream_name_analog = "VT1818S Analog";
4113 else
4114 spec->stream_name_analog = "VT1708S Analog";
4115 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4116 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4118 if (codec->vendor_id == 0x11060440)
4119 spec->stream_name_digital = "VT1818S Digital";
4120 else
4121 spec->stream_name_digital = "VT1708S Digital";
4122 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4124 if (!spec->adc_nids && spec->input_mux) {
4125 spec->adc_nids = vt1708S_adc_nids;
4126 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4127 get_mux_nids(codec);
4128 override_mic_boost(codec, 0x1a, 0, 3, 40);
4129 override_mic_boost(codec, 0x1e, 0, 3, 40);
4130 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4131 spec->num_mixers++;
4134 codec->patch_ops = via_patch_ops;
4136 codec->patch_ops.init = via_auto_init;
4137 codec->patch_ops.unsol_event = via_unsol_event;
4138 #ifdef CONFIG_SND_HDA_POWER_SAVE
4139 spec->loopback.amplist = vt1708S_loopbacks;
4140 #endif
4142 /* correct names for VT1708BCE */
4143 if (get_codec_type(codec) == VT1708BCE) {
4144 kfree(codec->chip_name);
4145 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4146 snprintf(codec->bus->card->mixername,
4147 sizeof(codec->bus->card->mixername),
4148 "%s %s", codec->vendor_name, codec->chip_name);
4149 spec->stream_name_analog = "VT1708BCE Analog";
4150 spec->stream_name_digital = "VT1708BCE Digital";
4152 return 0;
4155 /* Patch for VT1702 */
4157 /* capture mixer elements */
4158 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4159 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4160 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4161 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4162 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4163 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4164 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4165 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4166 HDA_INPUT),
4168 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4169 /* The multiple "Capture Source" controls confuse alsamixer
4170 * So call somewhat different..
4172 /* .name = "Capture Source", */
4173 .name = "Input Source",
4174 .count = 1,
4175 .info = via_mux_enum_info,
4176 .get = via_mux_enum_get,
4177 .put = via_mux_enum_put,
4179 { } /* end */
4182 static struct hda_verb vt1702_volume_init_verbs[] = {
4184 * Unmute ADC0-1 and set the default input to mic-in
4186 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4187 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4188 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4191 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4192 * mixer widget
4194 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4195 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4196 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4197 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4198 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4199 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4201 /* Setup default input of PW4 to MW0 */
4202 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4203 /* PW6 PW7 Output enable */
4204 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4205 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4206 /* mixer enable */
4207 {0x1, 0xF88, 0x3},
4208 /* GPIO 0~2 */
4209 {0x1, 0xF82, 0x3F},
4213 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4214 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4215 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4216 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4217 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4218 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4219 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4223 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4224 .substreams = 2,
4225 .channels_min = 2,
4226 .channels_max = 2,
4227 .nid = 0x10, /* NID to query formats and rates */
4228 .ops = {
4229 .open = via_playback_pcm_open,
4230 .prepare = via_playback_multi_pcm_prepare,
4231 .cleanup = via_playback_multi_pcm_cleanup,
4232 .close = via_pcm_open_close
4236 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4237 .substreams = 3,
4238 .channels_min = 2,
4239 .channels_max = 2,
4240 .nid = 0x12, /* NID to query formats and rates */
4241 .ops = {
4242 .open = via_pcm_open_close,
4243 .prepare = via_capture_pcm_prepare,
4244 .cleanup = via_capture_pcm_cleanup,
4245 .close = via_pcm_open_close
4249 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4250 .substreams = 2,
4251 .channels_min = 2,
4252 .channels_max = 2,
4253 /* NID is set in via_build_pcms */
4254 .ops = {
4255 .open = via_dig_playback_pcm_open,
4256 .close = via_dig_playback_pcm_close,
4257 .prepare = via_dig_playback_pcm_prepare,
4258 .cleanup = via_dig_playback_pcm_cleanup
4262 /* fill in the dac_nids table from the parsed pin configuration */
4263 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4264 const struct auto_pin_cfg *cfg)
4266 spec->multiout.num_dacs = 1;
4267 spec->multiout.dac_nids = spec->private_dac_nids;
4269 if (cfg->line_out_pins[0]) {
4270 /* config dac list */
4271 spec->multiout.dac_nids[0] = 0x10;
4274 return 0;
4277 /* add playback controls from the parsed DAC table */
4278 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4279 const struct auto_pin_cfg *cfg)
4281 int err;
4283 if (!cfg->line_out_pins[0])
4284 return -1;
4286 /* add control to mixer index 0 */
4287 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4288 "Master Front Playback Volume",
4289 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4290 if (err < 0)
4291 return err;
4292 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4293 "Master Front Playback Switch",
4294 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4295 if (err < 0)
4296 return err;
4298 /* Front */
4299 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4300 "Front Playback Volume",
4301 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4302 if (err < 0)
4303 return err;
4304 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4305 "Front Playback Switch",
4306 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4307 if (err < 0)
4308 return err;
4310 return 0;
4313 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4315 int err, i;
4316 struct hda_input_mux *imux;
4317 static const char *texts[] = { "ON", "OFF", NULL};
4318 if (!pin)
4319 return 0;
4320 spec->multiout.hp_nid = 0x1D;
4321 spec->hp_independent_mode_index = 0;
4323 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4324 "Headphone Playback Volume",
4325 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4326 if (err < 0)
4327 return err;
4329 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4330 "Headphone Playback Switch",
4331 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4332 if (err < 0)
4333 return err;
4335 imux = &spec->private_imux[1];
4337 /* for hp mode select */
4338 i = 0;
4339 while (texts[i] != NULL) {
4340 strcpy(imux->items[imux->num_items].label, texts[i]);
4341 imux->items[imux->num_items].index = i;
4342 imux->num_items++;
4343 i++;
4346 spec->hp_mux = &spec->private_imux[1];
4347 return 0;
4350 /* create playback/capture controls for input pins */
4351 static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
4352 const struct auto_pin_cfg *cfg)
4354 static hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4355 return vt_auto_create_analog_input_ctls(spec, cfg, 0x1a, pin_idxs,
4356 ARRAY_SIZE(pin_idxs));
4359 static int vt1702_parse_auto_config(struct hda_codec *codec)
4361 struct via_spec *spec = codec->spec;
4362 int err;
4364 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4365 if (err < 0)
4366 return err;
4367 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4368 if (err < 0)
4369 return err;
4370 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4371 return 0; /* can't find valid BIOS pin config */
4373 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4374 if (err < 0)
4375 return err;
4376 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4377 if (err < 0)
4378 return err;
4379 /* limit AA path volume to 0 dB */
4380 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4381 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4382 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4383 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4384 (1 << AC_AMPCAP_MUTE_SHIFT));
4385 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
4386 if (err < 0)
4387 return err;
4389 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4391 fill_dig_outs(codec);
4393 if (spec->kctls.list)
4394 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4396 spec->input_mux = &spec->private_imux[0];
4398 if (spec->hp_mux)
4399 via_hp_build(codec);
4401 return 1;
4404 #ifdef CONFIG_SND_HDA_POWER_SAVE
4405 static struct hda_amp_list vt1702_loopbacks[] = {
4406 { 0x1A, HDA_INPUT, 1 },
4407 { 0x1A, HDA_INPUT, 2 },
4408 { 0x1A, HDA_INPUT, 3 },
4409 { 0x1A, HDA_INPUT, 4 },
4410 { } /* end */
4412 #endif
4414 static int patch_vt1702(struct hda_codec *codec)
4416 struct via_spec *spec;
4417 int err;
4419 /* create a codec specific record */
4420 spec = via_new_spec(codec);
4421 if (spec == NULL)
4422 return -ENOMEM;
4424 /* automatic parse from the BIOS config */
4425 err = vt1702_parse_auto_config(codec);
4426 if (err < 0) {
4427 via_free(codec);
4428 return err;
4429 } else if (!err) {
4430 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4431 "from BIOS. Using genenic mode...\n");
4434 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4435 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4437 spec->stream_name_analog = "VT1702 Analog";
4438 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4439 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4441 spec->stream_name_digital = "VT1702 Digital";
4442 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4444 if (!spec->adc_nids && spec->input_mux) {
4445 spec->adc_nids = vt1702_adc_nids;
4446 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4447 get_mux_nids(codec);
4448 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4449 spec->num_mixers++;
4452 codec->patch_ops = via_patch_ops;
4454 codec->patch_ops.init = via_auto_init;
4455 codec->patch_ops.unsol_event = via_unsol_event;
4456 #ifdef CONFIG_SND_HDA_POWER_SAVE
4457 spec->loopback.amplist = vt1702_loopbacks;
4458 #endif
4460 return 0;
4463 /* Patch for VT1718S */
4465 /* capture mixer elements */
4466 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4467 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4468 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4469 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4470 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4471 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4472 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4473 HDA_INPUT),
4475 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4476 /* The multiple "Capture Source" controls confuse alsamixer
4477 * So call somewhat different..
4479 .name = "Input Source",
4480 .count = 2,
4481 .info = via_mux_enum_info,
4482 .get = via_mux_enum_get,
4483 .put = via_mux_enum_put,
4485 { } /* end */
4488 static struct hda_verb vt1718S_volume_init_verbs[] = {
4490 * Unmute ADC0-1 and set the default input to mic-in
4492 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4493 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4496 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4497 * mixer widget
4499 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4500 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4501 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4502 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4503 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4504 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4506 /* Setup default input of Front HP to MW9 */
4507 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4508 /* PW9 PW10 Output enable */
4509 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4510 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4511 /* PW11 Input enable */
4512 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4513 /* Enable Boost Volume backdoor */
4514 {0x1, 0xf88, 0x8},
4515 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4516 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4517 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4518 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4519 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4520 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4521 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4522 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4523 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4524 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4525 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4526 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4527 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4528 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4529 /* Unmute MW4's index 0 */
4530 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4535 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4536 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4537 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4538 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4539 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4540 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4541 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4542 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4543 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4544 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4548 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4549 .substreams = 2,
4550 .channels_min = 2,
4551 .channels_max = 10,
4552 .nid = 0x8, /* NID to query formats and rates */
4553 .ops = {
4554 .open = via_playback_pcm_open,
4555 .prepare = via_playback_multi_pcm_prepare,
4556 .cleanup = via_playback_multi_pcm_cleanup,
4557 .close = via_pcm_open_close,
4561 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4562 .substreams = 2,
4563 .channels_min = 2,
4564 .channels_max = 2,
4565 .nid = 0x10, /* NID to query formats and rates */
4566 .ops = {
4567 .open = via_pcm_open_close,
4568 .prepare = via_capture_pcm_prepare,
4569 .cleanup = via_capture_pcm_cleanup,
4570 .close = via_pcm_open_close,
4574 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4575 .substreams = 2,
4576 .channels_min = 2,
4577 .channels_max = 2,
4578 /* NID is set in via_build_pcms */
4579 .ops = {
4580 .open = via_dig_playback_pcm_open,
4581 .close = via_dig_playback_pcm_close,
4582 .prepare = via_dig_playback_pcm_prepare,
4583 .cleanup = via_dig_playback_pcm_cleanup
4587 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4588 .substreams = 1,
4589 .channels_min = 2,
4590 .channels_max = 2,
4593 /* fill in the dac_nids table from the parsed pin configuration */
4594 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4595 const struct auto_pin_cfg *cfg)
4597 int i;
4598 hda_nid_t nid;
4600 spec->multiout.num_dacs = cfg->line_outs;
4602 spec->multiout.dac_nids = spec->private_dac_nids;
4604 for (i = 0; i < 4; i++) {
4605 nid = cfg->line_out_pins[i];
4606 if (nid) {
4607 /* config dac list */
4608 switch (i) {
4609 case AUTO_SEQ_FRONT:
4610 spec->multiout.dac_nids[i] = 0x8;
4611 break;
4612 case AUTO_SEQ_CENLFE:
4613 spec->multiout.dac_nids[i] = 0xa;
4614 break;
4615 case AUTO_SEQ_SURROUND:
4616 spec->multiout.dac_nids[i] = 0x9;
4617 break;
4618 case AUTO_SEQ_SIDE:
4619 spec->multiout.dac_nids[i] = 0xb;
4620 break;
4625 return 0;
4628 /* add playback controls from the parsed DAC table */
4629 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4630 const struct auto_pin_cfg *cfg)
4632 char name[32];
4633 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4634 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4635 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4636 hda_nid_t nid, nid_vol, nid_mute = 0;
4637 int i, err;
4639 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4640 nid = cfg->line_out_pins[i];
4642 if (!nid)
4643 continue;
4644 nid_vol = nid_vols[i];
4645 nid_mute = nid_mutes[i];
4647 if (i == AUTO_SEQ_CENLFE) {
4648 /* Center/LFE */
4649 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4650 "Center Playback Volume",
4651 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4652 HDA_OUTPUT));
4653 if (err < 0)
4654 return err;
4655 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4656 "LFE Playback Volume",
4657 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4658 HDA_OUTPUT));
4659 if (err < 0)
4660 return err;
4661 err = via_add_control(
4662 spec, VIA_CTL_WIDGET_MUTE,
4663 "Center Playback Switch",
4664 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4665 HDA_OUTPUT));
4666 if (err < 0)
4667 return err;
4668 err = via_add_control(
4669 spec, VIA_CTL_WIDGET_MUTE,
4670 "LFE Playback Switch",
4671 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4672 HDA_OUTPUT));
4673 if (err < 0)
4674 return err;
4675 } else if (i == AUTO_SEQ_FRONT) {
4676 /* Front */
4677 sprintf(name, "%s Playback Volume", chname[i]);
4678 err = via_add_control(
4679 spec, VIA_CTL_WIDGET_VOL, name,
4680 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4681 if (err < 0)
4682 return err;
4683 sprintf(name, "%s Playback Switch", chname[i]);
4684 err = via_add_control(
4685 spec, VIA_CTL_WIDGET_MUTE, name,
4686 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4687 HDA_OUTPUT));
4688 if (err < 0)
4689 return err;
4690 } else {
4691 sprintf(name, "%s Playback Volume", chname[i]);
4692 err = via_add_control(
4693 spec, VIA_CTL_WIDGET_VOL, name,
4694 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4695 if (err < 0)
4696 return err;
4697 sprintf(name, "%s Playback Switch", chname[i]);
4698 err = via_add_control(
4699 spec, VIA_CTL_WIDGET_MUTE, name,
4700 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4701 HDA_OUTPUT));
4702 if (err < 0)
4703 return err;
4706 return 0;
4709 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4711 int err;
4713 if (!pin)
4714 return 0;
4716 spec->multiout.hp_nid = 0xc; /* AOW4 */
4717 spec->hp_independent_mode_index = 1;
4719 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4720 "Headphone Playback Volume",
4721 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4722 if (err < 0)
4723 return err;
4725 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4726 "Headphone Playback Switch",
4727 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4728 if (err < 0)
4729 return err;
4731 create_hp_imux(spec);
4732 return 0;
4735 /* create playback/capture controls for input pins */
4736 static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4737 const struct auto_pin_cfg *cfg)
4739 static hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4740 return vt_auto_create_analog_input_ctls(spec, cfg, 0x21, pin_idxs,
4741 ARRAY_SIZE(pin_idxs));
4744 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4746 struct via_spec *spec = codec->spec;
4747 int err;
4749 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4751 if (err < 0)
4752 return err;
4753 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4754 if (err < 0)
4755 return err;
4756 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4757 return 0; /* can't find valid BIOS pin config */
4759 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4760 if (err < 0)
4761 return err;
4762 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4763 if (err < 0)
4764 return err;
4765 err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4766 if (err < 0)
4767 return err;
4769 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4771 fill_dig_outs(codec);
4773 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4774 spec->dig_in_nid = 0x13;
4776 if (spec->kctls.list)
4777 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4779 spec->input_mux = &spec->private_imux[0];
4781 if (spec->hp_mux)
4782 via_hp_build(codec);
4784 via_smart51_build(spec);
4786 return 1;
4789 #ifdef CONFIG_SND_HDA_POWER_SAVE
4790 static struct hda_amp_list vt1718S_loopbacks[] = {
4791 { 0x21, HDA_INPUT, 1 },
4792 { 0x21, HDA_INPUT, 2 },
4793 { 0x21, HDA_INPUT, 3 },
4794 { 0x21, HDA_INPUT, 4 },
4795 { } /* end */
4797 #endif
4799 static int patch_vt1718S(struct hda_codec *codec)
4801 struct via_spec *spec;
4802 int err;
4804 /* create a codec specific record */
4805 spec = via_new_spec(codec);
4806 if (spec == NULL)
4807 return -ENOMEM;
4809 /* automatic parse from the BIOS config */
4810 err = vt1718S_parse_auto_config(codec);
4811 if (err < 0) {
4812 via_free(codec);
4813 return err;
4814 } else if (!err) {
4815 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4816 "from BIOS. Using genenic mode...\n");
4819 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4820 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4822 if (codec->vendor_id == 0x11060441)
4823 spec->stream_name_analog = "VT2020 Analog";
4824 else if (codec->vendor_id == 0x11064441)
4825 spec->stream_name_analog = "VT1828S Analog";
4826 else
4827 spec->stream_name_analog = "VT1718S Analog";
4828 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4829 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4831 if (codec->vendor_id == 0x11060441)
4832 spec->stream_name_digital = "VT2020 Digital";
4833 else if (codec->vendor_id == 0x11064441)
4834 spec->stream_name_digital = "VT1828S Digital";
4835 else
4836 spec->stream_name_digital = "VT1718S Digital";
4837 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4838 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4839 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4841 if (!spec->adc_nids && spec->input_mux) {
4842 spec->adc_nids = vt1718S_adc_nids;
4843 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4844 get_mux_nids(codec);
4845 override_mic_boost(codec, 0x2b, 0, 3, 40);
4846 override_mic_boost(codec, 0x29, 0, 3, 40);
4847 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4848 spec->num_mixers++;
4851 codec->patch_ops = via_patch_ops;
4853 codec->patch_ops.init = via_auto_init;
4854 codec->patch_ops.unsol_event = via_unsol_event;
4856 #ifdef CONFIG_SND_HDA_POWER_SAVE
4857 spec->loopback.amplist = vt1718S_loopbacks;
4858 #endif
4860 return 0;
4863 /* Patch for VT1716S */
4865 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4866 struct snd_ctl_elem_info *uinfo)
4868 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4869 uinfo->count = 1;
4870 uinfo->value.integer.min = 0;
4871 uinfo->value.integer.max = 1;
4872 return 0;
4875 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4876 struct snd_ctl_elem_value *ucontrol)
4878 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4879 int index = 0;
4881 index = snd_hda_codec_read(codec, 0x26, 0,
4882 AC_VERB_GET_CONNECT_SEL, 0);
4883 if (index != -1)
4884 *ucontrol->value.integer.value = index;
4886 return 0;
4889 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4890 struct snd_ctl_elem_value *ucontrol)
4892 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4893 struct via_spec *spec = codec->spec;
4894 int index = *ucontrol->value.integer.value;
4896 snd_hda_codec_write(codec, 0x26, 0,
4897 AC_VERB_SET_CONNECT_SEL, index);
4898 spec->dmic_enabled = index;
4899 set_jack_power_state(codec);
4901 return 1;
4904 /* capture mixer elements */
4905 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4906 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4907 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4908 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4909 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4910 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4911 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4912 HDA_INPUT),
4914 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4915 .name = "Input Source",
4916 .count = 1,
4917 .info = via_mux_enum_info,
4918 .get = via_mux_enum_get,
4919 .put = via_mux_enum_put,
4921 { } /* end */
4924 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4925 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4927 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4928 .name = "Digital Mic Capture Switch",
4929 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4930 .count = 1,
4931 .info = vt1716s_dmic_info,
4932 .get = vt1716s_dmic_get,
4933 .put = vt1716s_dmic_put,
4935 {} /* end */
4939 /* mono-out mixer elements */
4940 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4941 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4942 { } /* end */
4945 static struct hda_verb vt1716S_volume_init_verbs[] = {
4947 * Unmute ADC0-1 and set the default input to mic-in
4949 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4950 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4953 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4954 * mixer widget
4956 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4957 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4958 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4959 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4960 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4961 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4963 /* MUX Indices: Stereo Mixer = 5 */
4964 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4966 /* Setup default input of PW4 to MW0 */
4967 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4969 /* Setup default input of SW1 as MW0 */
4970 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4972 /* Setup default input of SW4 as AOW0 */
4973 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4975 /* PW9 PW10 Output enable */
4976 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4977 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4979 /* Unmute SW1, PW12 */
4980 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4981 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4982 /* PW12 Output enable */
4983 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4984 /* Enable Boost Volume backdoor */
4985 {0x1, 0xf8a, 0x80},
4986 /* don't bybass mixer */
4987 {0x1, 0xf88, 0xc0},
4988 /* Enable mono output */
4989 {0x1, 0xf90, 0x08},
4994 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
4995 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4996 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4997 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4998 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4999 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5000 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5001 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5002 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5003 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5007 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5008 .substreams = 2,
5009 .channels_min = 2,
5010 .channels_max = 6,
5011 .nid = 0x10, /* NID to query formats and rates */
5012 .ops = {
5013 .open = via_playback_pcm_open,
5014 .prepare = via_playback_multi_pcm_prepare,
5015 .cleanup = via_playback_multi_pcm_cleanup,
5016 .close = via_pcm_open_close,
5020 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5021 .substreams = 2,
5022 .channels_min = 2,
5023 .channels_max = 2,
5024 .nid = 0x13, /* NID to query formats and rates */
5025 .ops = {
5026 .open = via_pcm_open_close,
5027 .prepare = via_capture_pcm_prepare,
5028 .cleanup = via_capture_pcm_cleanup,
5029 .close = via_pcm_open_close,
5033 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5034 .substreams = 2,
5035 .channels_min = 2,
5036 .channels_max = 2,
5037 /* NID is set in via_build_pcms */
5038 .ops = {
5039 .open = via_dig_playback_pcm_open,
5040 .close = via_dig_playback_pcm_close,
5041 .prepare = via_dig_playback_pcm_prepare,
5042 .cleanup = via_dig_playback_pcm_cleanup
5046 /* fill in the dac_nids table from the parsed pin configuration */
5047 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5048 const struct auto_pin_cfg *cfg)
5049 { int i;
5050 hda_nid_t nid;
5052 spec->multiout.num_dacs = cfg->line_outs;
5054 spec->multiout.dac_nids = spec->private_dac_nids;
5056 for (i = 0; i < 3; i++) {
5057 nid = cfg->line_out_pins[i];
5058 if (nid) {
5059 /* config dac list */
5060 switch (i) {
5061 case AUTO_SEQ_FRONT:
5062 spec->multiout.dac_nids[i] = 0x10;
5063 break;
5064 case AUTO_SEQ_CENLFE:
5065 spec->multiout.dac_nids[i] = 0x25;
5066 break;
5067 case AUTO_SEQ_SURROUND:
5068 spec->multiout.dac_nids[i] = 0x11;
5069 break;
5074 return 0;
5077 /* add playback controls from the parsed DAC table */
5078 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5079 const struct auto_pin_cfg *cfg)
5081 char name[32];
5082 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5083 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5084 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5085 hda_nid_t nid, nid_vol, nid_mute;
5086 int i, err;
5088 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5089 nid = cfg->line_out_pins[i];
5091 if (!nid)
5092 continue;
5094 nid_vol = nid_vols[i];
5095 nid_mute = nid_mutes[i];
5097 if (i == AUTO_SEQ_CENLFE) {
5098 err = via_add_control(
5099 spec, VIA_CTL_WIDGET_VOL,
5100 "Center Playback Volume",
5101 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5102 if (err < 0)
5103 return err;
5104 err = via_add_control(
5105 spec, VIA_CTL_WIDGET_VOL,
5106 "LFE Playback Volume",
5107 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5108 if (err < 0)
5109 return err;
5110 err = via_add_control(
5111 spec, VIA_CTL_WIDGET_MUTE,
5112 "Center Playback Switch",
5113 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5114 HDA_OUTPUT));
5115 if (err < 0)
5116 return err;
5117 err = via_add_control(
5118 spec, VIA_CTL_WIDGET_MUTE,
5119 "LFE Playback Switch",
5120 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5121 HDA_OUTPUT));
5122 if (err < 0)
5123 return err;
5124 } else if (i == AUTO_SEQ_FRONT) {
5126 err = via_add_control(
5127 spec, VIA_CTL_WIDGET_VOL,
5128 "Master Front Playback Volume",
5129 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5130 if (err < 0)
5131 return err;
5132 err = via_add_control(
5133 spec, VIA_CTL_WIDGET_MUTE,
5134 "Master Front Playback Switch",
5135 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5136 if (err < 0)
5137 return err;
5139 sprintf(name, "%s Playback Volume", chname[i]);
5140 err = via_add_control(
5141 spec, VIA_CTL_WIDGET_VOL, name,
5142 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5143 if (err < 0)
5144 return err;
5145 sprintf(name, "%s Playback Switch", chname[i]);
5146 err = via_add_control(
5147 spec, VIA_CTL_WIDGET_MUTE, name,
5148 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5149 HDA_OUTPUT));
5150 if (err < 0)
5151 return err;
5152 } else {
5153 sprintf(name, "%s Playback Volume", chname[i]);
5154 err = via_add_control(
5155 spec, VIA_CTL_WIDGET_VOL, name,
5156 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5157 if (err < 0)
5158 return err;
5159 sprintf(name, "%s Playback Switch", chname[i]);
5160 err = via_add_control(
5161 spec, VIA_CTL_WIDGET_MUTE, name,
5162 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5163 HDA_OUTPUT));
5164 if (err < 0)
5165 return err;
5168 return 0;
5171 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5173 int err;
5175 if (!pin)
5176 return 0;
5178 spec->multiout.hp_nid = 0x25; /* AOW3 */
5179 spec->hp_independent_mode_index = 1;
5181 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5182 "Headphone Playback Volume",
5183 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5184 if (err < 0)
5185 return err;
5187 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5188 "Headphone Playback Switch",
5189 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5190 if (err < 0)
5191 return err;
5193 create_hp_imux(spec);
5194 return 0;
5197 /* create playback/capture controls for input pins */
5198 static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5199 const struct auto_pin_cfg *cfg)
5201 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5202 return vt_auto_create_analog_input_ctls(spec, cfg, 0x16, pin_idxs,
5203 ARRAY_SIZE(pin_idxs));
5206 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5208 struct via_spec *spec = codec->spec;
5209 int err;
5211 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5212 if (err < 0)
5213 return err;
5214 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5215 if (err < 0)
5216 return err;
5217 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5218 return 0; /* can't find valid BIOS pin config */
5220 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5221 if (err < 0)
5222 return err;
5223 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5224 if (err < 0)
5225 return err;
5226 err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
5227 if (err < 0)
5228 return err;
5230 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5232 fill_dig_outs(codec);
5234 if (spec->kctls.list)
5235 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5237 spec->input_mux = &spec->private_imux[0];
5239 if (spec->hp_mux)
5240 via_hp_build(codec);
5242 via_smart51_build(spec);
5244 return 1;
5247 #ifdef CONFIG_SND_HDA_POWER_SAVE
5248 static struct hda_amp_list vt1716S_loopbacks[] = {
5249 { 0x16, HDA_INPUT, 1 },
5250 { 0x16, HDA_INPUT, 2 },
5251 { 0x16, HDA_INPUT, 3 },
5252 { 0x16, HDA_INPUT, 4 },
5253 { } /* end */
5255 #endif
5257 static int patch_vt1716S(struct hda_codec *codec)
5259 struct via_spec *spec;
5260 int err;
5262 /* create a codec specific record */
5263 spec = via_new_spec(codec);
5264 if (spec == NULL)
5265 return -ENOMEM;
5267 /* automatic parse from the BIOS config */
5268 err = vt1716S_parse_auto_config(codec);
5269 if (err < 0) {
5270 via_free(codec);
5271 return err;
5272 } else if (!err) {
5273 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5274 "from BIOS. Using genenic mode...\n");
5277 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5278 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5280 spec->stream_name_analog = "VT1716S Analog";
5281 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5282 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5284 spec->stream_name_digital = "VT1716S Digital";
5285 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5287 if (!spec->adc_nids && spec->input_mux) {
5288 spec->adc_nids = vt1716S_adc_nids;
5289 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5290 get_mux_nids(codec);
5291 override_mic_boost(codec, 0x1a, 0, 3, 40);
5292 override_mic_boost(codec, 0x1e, 0, 3, 40);
5293 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5294 spec->num_mixers++;
5297 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5298 spec->num_mixers++;
5300 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5302 codec->patch_ops = via_patch_ops;
5304 codec->patch_ops.init = via_auto_init;
5305 codec->patch_ops.unsol_event = via_unsol_event;
5307 #ifdef CONFIG_SND_HDA_POWER_SAVE
5308 spec->loopback.amplist = vt1716S_loopbacks;
5309 #endif
5311 return 0;
5314 /* for vt2002P */
5316 /* capture mixer elements */
5317 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5318 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5319 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5320 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5321 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5322 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5323 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5324 HDA_INPUT),
5326 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5327 /* The multiple "Capture Source" controls confuse alsamixer
5328 * So call somewhat different..
5330 /* .name = "Capture Source", */
5331 .name = "Input Source",
5332 .count = 2,
5333 .info = via_mux_enum_info,
5334 .get = via_mux_enum_get,
5335 .put = via_mux_enum_put,
5337 { } /* end */
5340 static struct hda_verb vt2002P_volume_init_verbs[] = {
5342 * Unmute ADC0-1 and set the default input to mic-in
5344 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5345 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5348 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5349 * mixer widget
5351 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5352 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5353 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5354 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5355 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5356 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5358 /* MUX Indices: Mic = 0 */
5359 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5360 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5362 /* PW9 Output enable */
5363 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5365 /* Enable Boost Volume backdoor */
5366 {0x1, 0xfb9, 0x24},
5368 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5369 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5370 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5371 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5372 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5373 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5374 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5375 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5376 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5378 /* set MUX0/1/4/8 = 0 (AOW0) */
5379 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5380 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5381 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5382 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5384 /* set PW0 index=0 (MW0) */
5385 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5387 /* Enable AOW0 to MW9 */
5388 {0x1, 0xfb8, 0x88},
5393 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5394 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5395 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5396 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5397 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5398 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5399 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5400 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5404 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5405 .substreams = 2,
5406 .channels_min = 2,
5407 .channels_max = 2,
5408 .nid = 0x8, /* NID to query formats and rates */
5409 .ops = {
5410 .open = via_playback_pcm_open,
5411 .prepare = via_playback_multi_pcm_prepare,
5412 .cleanup = via_playback_multi_pcm_cleanup,
5413 .close = via_pcm_open_close,
5417 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5418 .substreams = 2,
5419 .channels_min = 2,
5420 .channels_max = 2,
5421 .nid = 0x10, /* NID to query formats and rates */
5422 .ops = {
5423 .open = via_pcm_open_close,
5424 .prepare = via_capture_pcm_prepare,
5425 .cleanup = via_capture_pcm_cleanup,
5426 .close = via_pcm_open_close,
5430 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5431 .substreams = 1,
5432 .channels_min = 2,
5433 .channels_max = 2,
5434 /* NID is set in via_build_pcms */
5435 .ops = {
5436 .open = via_dig_playback_pcm_open,
5437 .close = via_dig_playback_pcm_close,
5438 .prepare = via_dig_playback_pcm_prepare,
5439 .cleanup = via_dig_playback_pcm_cleanup
5443 /* fill in the dac_nids table from the parsed pin configuration */
5444 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5445 const struct auto_pin_cfg *cfg)
5447 spec->multiout.num_dacs = 1;
5448 spec->multiout.dac_nids = spec->private_dac_nids;
5449 if (cfg->line_out_pins[0])
5450 spec->multiout.dac_nids[0] = 0x8;
5451 return 0;
5454 /* add playback controls from the parsed DAC table */
5455 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5456 const struct auto_pin_cfg *cfg)
5458 int err;
5460 if (!cfg->line_out_pins[0])
5461 return -1;
5464 /* Line-Out: PortE */
5465 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5466 "Master Front Playback Volume",
5467 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5468 if (err < 0)
5469 return err;
5470 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5471 "Master Front Playback Switch",
5472 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5473 if (err < 0)
5474 return err;
5476 return 0;
5479 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5481 int err;
5483 if (!pin)
5484 return 0;
5486 spec->multiout.hp_nid = 0x9;
5487 spec->hp_independent_mode_index = 1;
5489 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5490 "Headphone Playback Volume",
5491 HDA_COMPOSE_AMP_VAL(
5492 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5493 if (err < 0)
5494 return err;
5496 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5497 "Headphone Playback Switch",
5498 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5499 if (err < 0)
5500 return err;
5502 create_hp_imux(spec);
5503 return 0;
5506 /* create playback/capture controls for input pins */
5507 static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
5508 const struct auto_pin_cfg *cfg)
5510 struct hda_input_mux *imux = &spec->private_imux[0];
5511 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5512 int err;
5514 err = vt_auto_create_analog_input_ctls(spec, cfg, 0x21, pin_idxs,
5515 ARRAY_SIZE(pin_idxs));
5516 if (err < 0)
5517 return err;
5518 /* build volume/mute control of loopback */
5519 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
5520 if (err < 0)
5521 return err;
5523 /* for digital mic select */
5524 strcpy(imux->items[imux->num_items].label, "Digital Mic");
5525 imux->items[imux->num_items].index = 4;
5526 imux->num_items++;
5528 return 0;
5531 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5533 struct via_spec *spec = codec->spec;
5534 int err;
5537 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5538 if (err < 0)
5539 return err;
5541 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5542 if (err < 0)
5543 return err;
5545 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5546 return 0; /* can't find valid BIOS pin config */
5548 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5549 if (err < 0)
5550 return err;
5551 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5552 if (err < 0)
5553 return err;
5554 err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
5555 if (err < 0)
5556 return err;
5558 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5560 fill_dig_outs(codec);
5562 if (spec->kctls.list)
5563 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5565 spec->input_mux = &spec->private_imux[0];
5567 if (spec->hp_mux)
5568 via_hp_build(codec);
5570 return 1;
5573 #ifdef CONFIG_SND_HDA_POWER_SAVE
5574 static struct hda_amp_list vt2002P_loopbacks[] = {
5575 { 0x21, HDA_INPUT, 0 },
5576 { 0x21, HDA_INPUT, 1 },
5577 { 0x21, HDA_INPUT, 2 },
5578 { } /* end */
5580 #endif
5583 /* patch for vt2002P */
5584 static int patch_vt2002P(struct hda_codec *codec)
5586 struct via_spec *spec;
5587 int err;
5589 /* create a codec specific record */
5590 spec = via_new_spec(codec);
5591 if (spec == NULL)
5592 return -ENOMEM;
5594 /* automatic parse from the BIOS config */
5595 err = vt2002P_parse_auto_config(codec);
5596 if (err < 0) {
5597 via_free(codec);
5598 return err;
5599 } else if (!err) {
5600 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5601 "from BIOS. Using genenic mode...\n");
5604 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5605 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5607 spec->stream_name_analog = "VT2002P Analog";
5608 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5609 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5611 spec->stream_name_digital = "VT2002P Digital";
5612 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5614 if (!spec->adc_nids && spec->input_mux) {
5615 spec->adc_nids = vt2002P_adc_nids;
5616 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5617 get_mux_nids(codec);
5618 override_mic_boost(codec, 0x2b, 0, 3, 40);
5619 override_mic_boost(codec, 0x29, 0, 3, 40);
5620 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5621 spec->num_mixers++;
5624 codec->patch_ops = via_patch_ops;
5626 codec->patch_ops.init = via_auto_init;
5627 codec->patch_ops.unsol_event = via_unsol_event;
5629 #ifdef CONFIG_SND_HDA_POWER_SAVE
5630 spec->loopback.amplist = vt2002P_loopbacks;
5631 #endif
5633 return 0;
5636 /* for vt1812 */
5638 /* capture mixer elements */
5639 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5640 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5641 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5642 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5643 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5644 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5645 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5646 HDA_INPUT),
5648 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5649 /* The multiple "Capture Source" controls confuse alsamixer
5650 * So call somewhat different..
5652 .name = "Input Source",
5653 .count = 2,
5654 .info = via_mux_enum_info,
5655 .get = via_mux_enum_get,
5656 .put = via_mux_enum_put,
5658 { } /* end */
5661 static struct hda_verb vt1812_volume_init_verbs[] = {
5663 * Unmute ADC0-1 and set the default input to mic-in
5665 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5666 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5669 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5670 * mixer widget
5672 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5673 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5674 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5675 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5676 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5677 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5679 /* MUX Indices: Mic = 0 */
5680 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5681 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5683 /* PW9 Output enable */
5684 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5686 /* Enable Boost Volume backdoor */
5687 {0x1, 0xfb9, 0x24},
5689 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5690 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5691 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5692 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5693 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5694 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5695 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5696 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5697 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5698 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5699 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5701 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5702 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5703 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5704 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5705 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5706 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5708 /* Enable AOW0 to MW9 */
5709 {0x1, 0xfb8, 0xa8},
5714 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5715 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5716 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5717 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5718 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5719 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5720 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5721 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5722 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5726 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5727 .substreams = 2,
5728 .channels_min = 2,
5729 .channels_max = 2,
5730 .nid = 0x8, /* NID to query formats and rates */
5731 .ops = {
5732 .open = via_playback_pcm_open,
5733 .prepare = via_playback_multi_pcm_prepare,
5734 .cleanup = via_playback_multi_pcm_cleanup,
5735 .close = via_pcm_open_close,
5739 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5740 .substreams = 2,
5741 .channels_min = 2,
5742 .channels_max = 2,
5743 .nid = 0x10, /* NID to query formats and rates */
5744 .ops = {
5745 .open = via_pcm_open_close,
5746 .prepare = via_capture_pcm_prepare,
5747 .cleanup = via_capture_pcm_cleanup,
5748 .close = via_pcm_open_close,
5752 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5753 .substreams = 1,
5754 .channels_min = 2,
5755 .channels_max = 2,
5756 /* NID is set in via_build_pcms */
5757 .ops = {
5758 .open = via_dig_playback_pcm_open,
5759 .close = via_dig_playback_pcm_close,
5760 .prepare = via_dig_playback_pcm_prepare,
5761 .cleanup = via_dig_playback_pcm_cleanup
5764 /* fill in the dac_nids table from the parsed pin configuration */
5765 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5766 const struct auto_pin_cfg *cfg)
5768 spec->multiout.num_dacs = 1;
5769 spec->multiout.dac_nids = spec->private_dac_nids;
5770 if (cfg->line_out_pins[0])
5771 spec->multiout.dac_nids[0] = 0x8;
5772 return 0;
5776 /* add playback controls from the parsed DAC table */
5777 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5778 const struct auto_pin_cfg *cfg)
5780 int err;
5782 if (!cfg->line_out_pins[0])
5783 return -1;
5785 /* Line-Out: PortE */
5786 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5787 "Front Playback Volume",
5788 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5789 if (err < 0)
5790 return err;
5791 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5792 "Front Playback Switch",
5793 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5794 if (err < 0)
5795 return err;
5797 return 0;
5800 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5802 int err;
5804 if (!pin)
5805 return 0;
5807 spec->multiout.hp_nid = 0x9;
5808 spec->hp_independent_mode_index = 1;
5811 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5812 "Headphone Playback Volume",
5813 HDA_COMPOSE_AMP_VAL(
5814 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5815 if (err < 0)
5816 return err;
5818 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5819 "Headphone Playback Switch",
5820 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5821 if (err < 0)
5822 return err;
5824 create_hp_imux(spec);
5825 return 0;
5828 /* create playback/capture controls for input pins */
5829 static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
5830 const struct auto_pin_cfg *cfg)
5832 struct hda_input_mux *imux = &spec->private_imux[0];
5833 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5834 int err;
5836 err = vt_auto_create_analog_input_ctls(spec, cfg, 0x21, pin_idxs,
5837 ARRAY_SIZE(pin_idxs));
5838 if (err < 0)
5839 return err;
5841 /* build volume/mute control of loopback */
5842 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
5843 if (err < 0)
5844 return err;
5846 /* for digital mic select */
5847 strcpy(imux->items[imux->num_items].label, "Digital Mic");
5848 imux->items[imux->num_items].index = 6;
5849 imux->num_items++;
5851 return 0;
5854 static int vt1812_parse_auto_config(struct hda_codec *codec)
5856 struct via_spec *spec = codec->spec;
5857 int err;
5860 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5861 if (err < 0)
5862 return err;
5863 fill_dig_outs(codec);
5864 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5865 if (err < 0)
5866 return err;
5868 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5869 return 0; /* can't find valid BIOS pin config */
5871 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5872 if (err < 0)
5873 return err;
5874 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5875 if (err < 0)
5876 return err;
5877 err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
5878 if (err < 0)
5879 return err;
5881 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5883 fill_dig_outs(codec);
5885 if (spec->kctls.list)
5886 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5888 spec->input_mux = &spec->private_imux[0];
5890 if (spec->hp_mux)
5891 via_hp_build(codec);
5893 return 1;
5896 #ifdef CONFIG_SND_HDA_POWER_SAVE
5897 static struct hda_amp_list vt1812_loopbacks[] = {
5898 { 0x21, HDA_INPUT, 0 },
5899 { 0x21, HDA_INPUT, 1 },
5900 { 0x21, HDA_INPUT, 2 },
5901 { } /* end */
5903 #endif
5906 /* patch for vt1812 */
5907 static int patch_vt1812(struct hda_codec *codec)
5909 struct via_spec *spec;
5910 int err;
5912 /* create a codec specific record */
5913 spec = via_new_spec(codec);
5914 if (spec == NULL)
5915 return -ENOMEM;
5917 /* automatic parse from the BIOS config */
5918 err = vt1812_parse_auto_config(codec);
5919 if (err < 0) {
5920 via_free(codec);
5921 return err;
5922 } else if (!err) {
5923 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5924 "from BIOS. Using genenic mode...\n");
5928 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
5929 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
5931 spec->stream_name_analog = "VT1812 Analog";
5932 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
5933 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
5935 spec->stream_name_digital = "VT1812 Digital";
5936 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
5939 if (!spec->adc_nids && spec->input_mux) {
5940 spec->adc_nids = vt1812_adc_nids;
5941 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
5942 get_mux_nids(codec);
5943 override_mic_boost(codec, 0x2b, 0, 3, 40);
5944 override_mic_boost(codec, 0x29, 0, 3, 40);
5945 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
5946 spec->num_mixers++;
5949 codec->patch_ops = via_patch_ops;
5951 codec->patch_ops.init = via_auto_init;
5952 codec->patch_ops.unsol_event = via_unsol_event;
5954 #ifdef CONFIG_SND_HDA_POWER_SAVE
5955 spec->loopback.amplist = vt1812_loopbacks;
5956 #endif
5958 return 0;
5962 * patch entries
5964 static struct hda_codec_preset snd_hda_preset_via[] = {
5965 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
5966 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
5967 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
5968 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
5969 { .id = 0x1106e710, .name = "VT1709 10-Ch",
5970 .patch = patch_vt1709_10ch},
5971 { .id = 0x1106e711, .name = "VT1709 10-Ch",
5972 .patch = patch_vt1709_10ch},
5973 { .id = 0x1106e712, .name = "VT1709 10-Ch",
5974 .patch = patch_vt1709_10ch},
5975 { .id = 0x1106e713, .name = "VT1709 10-Ch",
5976 .patch = patch_vt1709_10ch},
5977 { .id = 0x1106e714, .name = "VT1709 6-Ch",
5978 .patch = patch_vt1709_6ch},
5979 { .id = 0x1106e715, .name = "VT1709 6-Ch",
5980 .patch = patch_vt1709_6ch},
5981 { .id = 0x1106e716, .name = "VT1709 6-Ch",
5982 .patch = patch_vt1709_6ch},
5983 { .id = 0x1106e717, .name = "VT1709 6-Ch",
5984 .patch = patch_vt1709_6ch},
5985 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
5986 .patch = patch_vt1708B_8ch},
5987 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
5988 .patch = patch_vt1708B_8ch},
5989 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
5990 .patch = patch_vt1708B_8ch},
5991 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
5992 .patch = patch_vt1708B_8ch},
5993 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
5994 .patch = patch_vt1708B_4ch},
5995 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
5996 .patch = patch_vt1708B_4ch},
5997 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
5998 .patch = patch_vt1708B_4ch},
5999 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6000 .patch = patch_vt1708B_4ch},
6001 { .id = 0x11060397, .name = "VT1708S",
6002 .patch = patch_vt1708S},
6003 { .id = 0x11061397, .name = "VT1708S",
6004 .patch = patch_vt1708S},
6005 { .id = 0x11062397, .name = "VT1708S",
6006 .patch = patch_vt1708S},
6007 { .id = 0x11063397, .name = "VT1708S",
6008 .patch = patch_vt1708S},
6009 { .id = 0x11064397, .name = "VT1708S",
6010 .patch = patch_vt1708S},
6011 { .id = 0x11065397, .name = "VT1708S",
6012 .patch = patch_vt1708S},
6013 { .id = 0x11066397, .name = "VT1708S",
6014 .patch = patch_vt1708S},
6015 { .id = 0x11067397, .name = "VT1708S",
6016 .patch = patch_vt1708S},
6017 { .id = 0x11060398, .name = "VT1702",
6018 .patch = patch_vt1702},
6019 { .id = 0x11061398, .name = "VT1702",
6020 .patch = patch_vt1702},
6021 { .id = 0x11062398, .name = "VT1702",
6022 .patch = patch_vt1702},
6023 { .id = 0x11063398, .name = "VT1702",
6024 .patch = patch_vt1702},
6025 { .id = 0x11064398, .name = "VT1702",
6026 .patch = patch_vt1702},
6027 { .id = 0x11065398, .name = "VT1702",
6028 .patch = patch_vt1702},
6029 { .id = 0x11066398, .name = "VT1702",
6030 .patch = patch_vt1702},
6031 { .id = 0x11067398, .name = "VT1702",
6032 .patch = patch_vt1702},
6033 { .id = 0x11060428, .name = "VT1718S",
6034 .patch = patch_vt1718S},
6035 { .id = 0x11064428, .name = "VT1718S",
6036 .patch = patch_vt1718S},
6037 { .id = 0x11060441, .name = "VT2020",
6038 .patch = patch_vt1718S},
6039 { .id = 0x11064441, .name = "VT1828S",
6040 .patch = patch_vt1718S},
6041 { .id = 0x11060433, .name = "VT1716S",
6042 .patch = patch_vt1716S},
6043 { .id = 0x1106a721, .name = "VT1716S",
6044 .patch = patch_vt1716S},
6045 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6046 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6047 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6048 { .id = 0x11060440, .name = "VT1818S",
6049 .patch = patch_vt1708S},
6050 {} /* terminator */
6053 MODULE_ALIAS("snd-hda-codec-id:1106*");
6055 static struct hda_codec_preset_list via_list = {
6056 .preset = snd_hda_preset_via,
6057 .owner = THIS_MODULE,
6060 MODULE_LICENSE("GPL");
6061 MODULE_DESCRIPTION("VIA HD-audio codec");
6063 static int __init patch_via_init(void)
6065 return snd_hda_add_codec_preset(&via_list);
6068 static void __exit patch_via_exit(void)
6070 snd_hda_delete_codec_preset(&via_list);
6073 module_init(patch_via_init)
6074 module_exit(patch_via_exit)