Add linux-next specific files for 20110421
[linux-2.6/next.git] / sound / pci / hda / patch_via.c
blob15b57a101aa028303ca2b2dce11b1b851a196ee9
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 VT1802,
102 CODEC_TYPES,
105 #define VT2002P_COMPATIBLE(spec) \
106 ((spec)->codec_type == VT2002P ||\
107 (spec)->codec_type == VT1812 ||\
108 (spec)->codec_type == VT1802)
110 struct via_spec {
111 /* codec parameterization */
112 struct snd_kcontrol_new *mixers[6];
113 unsigned int num_mixers;
115 struct hda_verb *init_verbs[5];
116 unsigned int num_iverbs;
118 char *stream_name_analog;
119 struct hda_pcm_stream *stream_analog_playback;
120 struct hda_pcm_stream *stream_analog_capture;
122 char *stream_name_digital;
123 struct hda_pcm_stream *stream_digital_playback;
124 struct hda_pcm_stream *stream_digital_capture;
126 /* playback */
127 struct hda_multi_out multiout;
128 hda_nid_t slave_dig_outs[2];
130 /* capture */
131 unsigned int num_adc_nids;
132 hda_nid_t *adc_nids;
133 hda_nid_t mux_nids[3];
134 hda_nid_t dig_in_nid;
135 hda_nid_t dig_in_pin;
137 /* capture source */
138 const struct hda_input_mux *input_mux;
139 unsigned int cur_mux[3];
141 /* PCM information */
142 struct hda_pcm pcm_rec[3];
144 /* dynamic controls, init_verbs and input_mux */
145 struct auto_pin_cfg autocfg;
146 struct snd_array kctls;
147 struct hda_input_mux private_imux[2];
148 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
150 /* HP mode source */
151 const struct hda_input_mux *hp_mux;
152 unsigned int hp_independent_mode;
153 unsigned int hp_independent_mode_index;
154 unsigned int smart51_enabled;
155 unsigned int dmic_enabled;
156 enum VIA_HDA_CODEC codec_type;
158 /* work to check hp jack state */
159 struct hda_codec *codec;
160 struct delayed_work vt1708_hp_work;
161 int vt1708_jack_detectect;
162 int vt1708_hp_present;
164 void (*set_widgets_power_state)(struct hda_codec *codec);
166 #ifdef CONFIG_SND_HDA_POWER_SAVE
167 struct hda_loopback_check loopback;
168 #endif
171 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
172 static struct via_spec * via_new_spec(struct hda_codec *codec)
174 struct via_spec *spec;
176 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
177 if (spec == NULL)
178 return NULL;
180 codec->spec = spec;
181 spec->codec = codec;
182 spec->codec_type = get_codec_type(codec);
183 /* VT1708BCE & VT1708S are almost same */
184 if (spec->codec_type == VT1708BCE)
185 spec->codec_type = VT1708S;
186 return spec;
189 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
191 u32 vendor_id = codec->vendor_id;
192 u16 ven_id = vendor_id >> 16;
193 u16 dev_id = vendor_id & 0xffff;
194 enum VIA_HDA_CODEC codec_type;
196 /* get codec type */
197 if (ven_id != 0x1106)
198 codec_type = UNKNOWN;
199 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
200 codec_type = VT1708;
201 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
202 codec_type = VT1709_10CH;
203 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
204 codec_type = VT1709_6CH;
205 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
206 codec_type = VT1708B_8CH;
207 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
208 codec_type = VT1708BCE;
209 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
210 codec_type = VT1708B_4CH;
211 else if ((dev_id & 0xfff) == 0x397
212 && (dev_id >> 12) < 8)
213 codec_type = VT1708S;
214 else if ((dev_id & 0xfff) == 0x398
215 && (dev_id >> 12) < 8)
216 codec_type = VT1702;
217 else if ((dev_id & 0xfff) == 0x428
218 && (dev_id >> 12) < 8)
219 codec_type = VT1718S;
220 else if (dev_id == 0x0433 || dev_id == 0xa721)
221 codec_type = VT1716S;
222 else if (dev_id == 0x0441 || dev_id == 0x4441)
223 codec_type = VT1718S;
224 else if (dev_id == 0x0438 || dev_id == 0x4438)
225 codec_type = VT2002P;
226 else if (dev_id == 0x0448)
227 codec_type = VT1812;
228 else if (dev_id == 0x0440)
229 codec_type = VT1708S;
230 else if ((dev_id & 0xfff) == 0x446)
231 codec_type = VT1802;
232 else
233 codec_type = UNKNOWN;
234 return codec_type;
237 #define VIA_JACK_EVENT 0x20
238 #define VIA_HP_EVENT 0x01
239 #define VIA_GPIO_EVENT 0x02
240 #define VIA_MONO_EVENT 0x03
241 #define VIA_SPEAKER_EVENT 0x04
242 #define VIA_BIND_HP_EVENT 0x05
244 enum {
245 VIA_CTL_WIDGET_VOL,
246 VIA_CTL_WIDGET_MUTE,
247 VIA_CTL_WIDGET_ANALOG_MUTE,
248 VIA_CTL_WIDGET_BIND_PIN_MUTE,
251 enum {
252 AUTO_SEQ_FRONT = 0,
253 AUTO_SEQ_SURROUND,
254 AUTO_SEQ_CENLFE,
255 AUTO_SEQ_SIDE
258 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
259 static int is_aa_path_mute(struct hda_codec *codec);
261 static void vt1708_start_hp_work(struct via_spec *spec)
263 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
264 return;
265 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
266 !spec->vt1708_jack_detectect);
267 if (!delayed_work_pending(&spec->vt1708_hp_work))
268 schedule_delayed_work(&spec->vt1708_hp_work,
269 msecs_to_jiffies(100));
272 static void vt1708_stop_hp_work(struct via_spec *spec)
274 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
275 return;
276 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
277 && !is_aa_path_mute(spec->codec))
278 return;
279 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
280 !spec->vt1708_jack_detectect);
281 cancel_delayed_work_sync(&spec->vt1708_hp_work);
284 static void set_widgets_power_state(struct hda_codec *codec)
286 struct via_spec *spec = codec->spec;
287 if (spec->set_widgets_power_state)
288 spec->set_widgets_power_state(codec);
291 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
292 struct snd_ctl_elem_value *ucontrol)
294 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
295 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
297 set_widgets_power_state(codec);
298 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
299 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
300 if (is_aa_path_mute(codec))
301 vt1708_start_hp_work(codec->spec);
302 else
303 vt1708_stop_hp_work(codec->spec);
305 return change;
308 /* modify .put = snd_hda_mixer_amp_switch_put */
309 #define ANALOG_INPUT_MUTE \
310 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
311 .name = NULL, \
312 .index = 0, \
313 .info = snd_hda_mixer_amp_switch_info, \
314 .get = snd_hda_mixer_amp_switch_get, \
315 .put = analog_input_switch_put, \
316 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
318 static void via_hp_bind_automute(struct hda_codec *codec);
320 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
321 struct snd_ctl_elem_value *ucontrol)
323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
324 struct via_spec *spec = codec->spec;
325 int i;
326 int change = 0;
328 long *valp = ucontrol->value.integer.value;
329 int lmute, rmute;
330 if (strstr(kcontrol->id.name, "Switch") == NULL) {
331 snd_printd("Invalid control!\n");
332 return change;
334 change = snd_hda_mixer_amp_switch_put(kcontrol,
335 ucontrol);
336 /* Get mute value */
337 lmute = *valp ? 0 : HDA_AMP_MUTE;
338 valp++;
339 rmute = *valp ? 0 : HDA_AMP_MUTE;
341 /* Set hp pins */
342 if (!spec->hp_independent_mode) {
343 for (i = 0; i < spec->autocfg.hp_outs; i++) {
344 snd_hda_codec_amp_update(
345 codec, spec->autocfg.hp_pins[i],
346 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
347 lmute);
348 snd_hda_codec_amp_update(
349 codec, spec->autocfg.hp_pins[i],
350 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
351 rmute);
355 if (!lmute && !rmute) {
356 /* Line Outs */
357 for (i = 0; i < spec->autocfg.line_outs; i++)
358 snd_hda_codec_amp_stereo(
359 codec, spec->autocfg.line_out_pins[i],
360 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
361 /* Speakers */
362 for (i = 0; i < spec->autocfg.speaker_outs; i++)
363 snd_hda_codec_amp_stereo(
364 codec, spec->autocfg.speaker_pins[i],
365 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
366 /* unmute */
367 via_hp_bind_automute(codec);
369 } else {
370 if (lmute) {
371 /* Mute all left channels */
372 for (i = 1; i < spec->autocfg.line_outs; i++)
373 snd_hda_codec_amp_update(
374 codec,
375 spec->autocfg.line_out_pins[i],
376 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
377 lmute);
378 for (i = 0; i < spec->autocfg.speaker_outs; i++)
379 snd_hda_codec_amp_update(
380 codec,
381 spec->autocfg.speaker_pins[i],
382 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
383 lmute);
385 if (rmute) {
386 /* mute all right channels */
387 for (i = 1; i < spec->autocfg.line_outs; i++)
388 snd_hda_codec_amp_update(
389 codec,
390 spec->autocfg.line_out_pins[i],
391 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
392 rmute);
393 for (i = 0; i < spec->autocfg.speaker_outs; i++)
394 snd_hda_codec_amp_update(
395 codec,
396 spec->autocfg.speaker_pins[i],
397 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
398 rmute);
401 return change;
404 #define BIND_PIN_MUTE \
405 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
406 .name = NULL, \
407 .index = 0, \
408 .info = snd_hda_mixer_amp_switch_info, \
409 .get = snd_hda_mixer_amp_switch_get, \
410 .put = bind_pin_switch_put, \
411 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
413 static struct snd_kcontrol_new via_control_templates[] = {
414 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
415 HDA_CODEC_MUTE(NULL, 0, 0, 0),
416 ANALOG_INPUT_MUTE,
417 BIND_PIN_MUTE,
420 static hda_nid_t vt1708_adc_nids[2] = {
421 /* ADC1-2 */
422 0x15, 0x27
425 static hda_nid_t vt1709_adc_nids[3] = {
426 /* ADC1-2 */
427 0x14, 0x15, 0x16
430 static hda_nid_t vt1708B_adc_nids[2] = {
431 /* ADC1-2 */
432 0x13, 0x14
435 static hda_nid_t vt1708S_adc_nids[2] = {
436 /* ADC1-2 */
437 0x13, 0x14
440 static hda_nid_t vt1702_adc_nids[3] = {
441 /* ADC1-2 */
442 0x12, 0x20, 0x1F
445 static hda_nid_t vt1718S_adc_nids[2] = {
446 /* ADC1-2 */
447 0x10, 0x11
450 static hda_nid_t vt1716S_adc_nids[2] = {
451 /* ADC1-2 */
452 0x13, 0x14
455 static hda_nid_t vt2002P_adc_nids[2] = {
456 /* ADC1-2 */
457 0x10, 0x11
460 static hda_nid_t vt1812_adc_nids[2] = {
461 /* ADC1-2 */
462 0x10, 0x11
466 /* add dynamic controls */
467 static int __via_add_control(struct via_spec *spec, int type, const char *name,
468 int idx, unsigned long val)
470 struct snd_kcontrol_new *knew;
472 snd_array_init(&spec->kctls, sizeof(*knew), 32);
473 knew = snd_array_new(&spec->kctls);
474 if (!knew)
475 return -ENOMEM;
476 *knew = via_control_templates[type];
477 knew->name = kstrdup(name, GFP_KERNEL);
478 if (!knew->name)
479 return -ENOMEM;
480 if (get_amp_nid_(val))
481 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
482 knew->private_value = val;
483 return 0;
486 #define via_add_control(spec, type, name, val) \
487 __via_add_control(spec, type, name, 0, val)
489 static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
490 struct snd_kcontrol_new *tmpl)
492 struct snd_kcontrol_new *knew;
494 snd_array_init(&spec->kctls, sizeof(*knew), 32);
495 knew = snd_array_new(&spec->kctls);
496 if (!knew)
497 return NULL;
498 *knew = *tmpl;
499 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
500 if (!knew->name)
501 return NULL;
502 return knew;
505 static void via_free_kctls(struct hda_codec *codec)
507 struct via_spec *spec = codec->spec;
509 if (spec->kctls.list) {
510 struct snd_kcontrol_new *kctl = spec->kctls.list;
511 int i;
512 for (i = 0; i < spec->kctls.used; i++)
513 kfree(kctl[i].name);
515 snd_array_free(&spec->kctls);
518 /* create input playback/capture controls for the given pin */
519 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
520 int type_idx, int idx, int mix_nid)
522 char name[32];
523 int err;
525 sprintf(name, "%s Playback Volume", ctlname);
526 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
527 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
528 if (err < 0)
529 return err;
530 sprintf(name, "%s Playback Switch", ctlname);
531 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
532 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
533 if (err < 0)
534 return err;
535 return 0;
538 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
539 hda_nid_t nid, int pin_type,
540 int dac_idx)
542 /* set as output */
543 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
544 pin_type);
545 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
546 AMP_OUT_UNMUTE);
547 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
548 snd_hda_codec_write(codec, nid, 0,
549 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
553 static void via_auto_init_multi_out(struct hda_codec *codec)
555 struct via_spec *spec = codec->spec;
556 int i;
558 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
559 hda_nid_t nid = spec->autocfg.line_out_pins[i];
560 if (nid)
561 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
565 static void via_auto_init_hp_out(struct hda_codec *codec)
567 struct via_spec *spec = codec->spec;
568 hda_nid_t pin;
569 int i;
571 for (i = 0; i < spec->autocfg.hp_outs; i++) {
572 pin = spec->autocfg.hp_pins[i];
573 if (pin) /* connect to front */
574 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
578 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
580 static void via_auto_init_analog_input(struct hda_codec *codec)
582 struct via_spec *spec = codec->spec;
583 const struct auto_pin_cfg *cfg = &spec->autocfg;
584 unsigned int ctl;
585 int i;
587 for (i = 0; i < cfg->num_inputs; i++) {
588 hda_nid_t nid = cfg->inputs[i].pin;
589 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
590 ctl = PIN_OUT;
591 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
592 ctl = PIN_VREF50;
593 else
594 ctl = PIN_IN;
595 snd_hda_codec_write(codec, nid, 0,
596 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
600 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
601 unsigned int *affected_parm)
603 unsigned parm;
604 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
605 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
606 >> AC_DEFCFG_MISC_SHIFT
607 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
608 unsigned present = snd_hda_jack_detect(codec, nid);
609 struct via_spec *spec = codec->spec;
610 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
611 || ((no_presence || present)
612 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
613 *affected_parm = AC_PWRST_D0; /* if it's connected */
614 parm = AC_PWRST_D0;
615 } else
616 parm = AC_PWRST_D3;
618 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
622 * input MUX handling
624 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
625 struct snd_ctl_elem_info *uinfo)
627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
628 struct via_spec *spec = codec->spec;
629 return snd_hda_input_mux_info(spec->input_mux, uinfo);
632 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_value *ucontrol)
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct via_spec *spec = codec->spec;
637 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
639 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
640 return 0;
643 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_value *ucontrol)
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct via_spec *spec = codec->spec;
648 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
649 int ret;
651 if (!spec->mux_nids[adc_idx])
652 return -EINVAL;
653 /* switch to D0 beofre change index */
654 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
655 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
656 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
657 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
659 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
660 spec->mux_nids[adc_idx],
661 &spec->cur_mux[adc_idx]);
662 /* update jack power state */
663 set_widgets_power_state(codec);
665 return ret;
668 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
669 struct snd_ctl_elem_info *uinfo)
671 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
672 struct via_spec *spec = codec->spec;
673 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
676 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
677 struct snd_ctl_elem_value *ucontrol)
679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
680 hda_nid_t nid = kcontrol->private_value;
681 unsigned int pinsel;
683 /* use !! to translate conn sel 2 for VT1718S */
684 pinsel = !!snd_hda_codec_read(codec, nid, 0,
685 AC_VERB_GET_CONNECT_SEL,
686 0x00);
687 ucontrol->value.enumerated.item[0] = pinsel;
689 return 0;
692 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
694 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
695 if (ctl) {
696 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
697 ctl->vd[0].access |= active
698 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
699 snd_ctl_notify(codec->bus->card,
700 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
704 static hda_nid_t side_mute_channel(struct via_spec *spec)
706 switch (spec->codec_type) {
707 case VT1708: return 0x1b;
708 case VT1709_10CH: return 0x29;
709 case VT1708B_8CH: /* fall thru */
710 case VT1708S: return 0x27;
711 case VT2002P: return 0x19;
712 case VT1802: return 0x15;
713 case VT1812: return 0x15;
714 default: return 0;
718 static int update_side_mute_status(struct hda_codec *codec)
720 /* mute side channel */
721 struct via_spec *spec = codec->spec;
722 unsigned int parm;
723 hda_nid_t sw3 = side_mute_channel(spec);
725 if (sw3) {
726 if (VT2002P_COMPATIBLE(spec))
727 parm = spec->hp_independent_mode ?
728 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
729 else
730 parm = spec->hp_independent_mode ?
731 AMP_OUT_MUTE : AMP_OUT_UNMUTE;
732 snd_hda_codec_write(codec, sw3, 0,
733 AC_VERB_SET_AMP_GAIN_MUTE, parm);
734 if (spec->codec_type == VT1812)
735 snd_hda_codec_write(codec, 0x1d, 0,
736 AC_VERB_SET_AMP_GAIN_MUTE, parm);
738 return 0;
741 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
742 struct snd_ctl_elem_value *ucontrol)
744 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
745 struct via_spec *spec = codec->spec;
746 hda_nid_t nid = kcontrol->private_value;
747 unsigned int pinsel = ucontrol->value.enumerated.item[0];
748 /* Get Independent Mode index of headphone pin widget */
749 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
750 ? 1 : 0;
751 if (spec->codec_type == VT1718S)
752 snd_hda_codec_write(codec, nid, 0,
753 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
754 else
755 snd_hda_codec_write(codec, nid, 0,
756 AC_VERB_SET_CONNECT_SEL, pinsel);
758 if (spec->codec_type == VT1812)
759 snd_hda_codec_write(codec, 0x35, 0,
760 AC_VERB_SET_CONNECT_SEL, pinsel);
761 if (spec->multiout.hp_nid && spec->multiout.hp_nid
762 != spec->multiout.dac_nids[HDA_FRONT])
763 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
764 0, 0, 0);
766 update_side_mute_status(codec);
767 /* update HP volume/swtich active state */
768 if (spec->codec_type == VT1708S
769 || spec->codec_type == VT1702
770 || spec->codec_type == VT1718S
771 || spec->codec_type == VT1716S
772 || VT2002P_COMPATIBLE(spec)) {
773 activate_ctl(codec, "Headphone Playback Volume",
774 spec->hp_independent_mode);
775 activate_ctl(codec, "Headphone Playback Switch",
776 spec->hp_independent_mode);
778 /* update jack power state */
779 set_widgets_power_state(codec);
780 return 0;
783 static struct snd_kcontrol_new via_hp_mixer[2] = {
785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
786 .name = "Independent HP",
787 .info = via_independent_hp_info,
788 .get = via_independent_hp_get,
789 .put = via_independent_hp_put,
792 .iface = NID_MAPPING,
793 .name = "Independent HP",
797 static int via_hp_build(struct hda_codec *codec)
799 struct via_spec *spec = codec->spec;
800 struct snd_kcontrol_new *knew;
801 hda_nid_t nid;
802 int nums;
803 hda_nid_t conn[HDA_MAX_CONNECTIONS];
805 switch (spec->codec_type) {
806 case VT1718S:
807 nid = 0x34;
808 break;
809 case VT2002P:
810 case VT1802:
811 nid = 0x35;
812 break;
813 case VT1812:
814 nid = 0x3d;
815 break;
816 default:
817 nid = spec->autocfg.hp_pins[0];
818 break;
821 if (spec->codec_type != VT1708) {
822 nums = snd_hda_get_connections(codec, nid,
823 conn, HDA_MAX_CONNECTIONS);
824 if (nums <= 1)
825 return 0;
828 knew = via_clone_control(spec, &via_hp_mixer[0]);
829 if (knew == NULL)
830 return -ENOMEM;
832 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
833 knew->private_value = nid;
835 knew = via_clone_control(spec, &via_hp_mixer[1]);
836 if (knew == NULL)
837 return -ENOMEM;
838 knew->subdevice = side_mute_channel(spec);
840 return 0;
843 static void notify_aa_path_ctls(struct hda_codec *codec)
845 int i;
846 struct snd_ctl_elem_id id;
847 const char *labels[] = {"Mic", "Front Mic", "Line"};
849 memset(&id, 0, sizeof(id));
850 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
851 for (i = 0; i < ARRAY_SIZE(labels); i++) {
852 sprintf(id.name, "%s Playback Volume", labels[i]);
853 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
854 &id);
858 static void mute_aa_path(struct hda_codec *codec, int mute)
860 struct via_spec *spec = codec->spec;
861 hda_nid_t nid_mixer;
862 int start_idx;
863 int end_idx;
864 int i;
865 /* get nid of MW0 and start & end index */
866 switch (spec->codec_type) {
867 case VT1708:
868 nid_mixer = 0x17;
869 start_idx = 2;
870 end_idx = 4;
871 break;
872 case VT1709_10CH:
873 case VT1709_6CH:
874 nid_mixer = 0x18;
875 start_idx = 2;
876 end_idx = 4;
877 break;
878 case VT1708B_8CH:
879 case VT1708B_4CH:
880 case VT1708S:
881 case VT1716S:
882 nid_mixer = 0x16;
883 start_idx = 2;
884 end_idx = 4;
885 break;
886 case VT1718S:
887 nid_mixer = 0x21;
888 start_idx = 1;
889 end_idx = 3;
890 break;
891 default:
892 return;
894 /* check AA path's mute status */
895 for (i = start_idx; i <= end_idx; i++) {
896 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
897 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
898 HDA_AMP_MUTE, val);
901 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
903 const struct auto_pin_cfg *cfg = &spec->autocfg;
904 int i;
906 for (i = 0; i < cfg->num_inputs; i++) {
907 if (pin == cfg->inputs[i].pin)
908 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
910 return 0;
913 static int via_smart51_info(struct snd_kcontrol *kcontrol,
914 struct snd_ctl_elem_info *uinfo)
916 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
917 uinfo->count = 1;
918 uinfo->value.integer.min = 0;
919 uinfo->value.integer.max = 1;
920 return 0;
923 static int via_smart51_get(struct snd_kcontrol *kcontrol,
924 struct snd_ctl_elem_value *ucontrol)
926 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
927 struct via_spec *spec = codec->spec;
928 const struct auto_pin_cfg *cfg = &spec->autocfg;
929 int on = 1;
930 int i;
932 for (i = 0; i < cfg->num_inputs; i++) {
933 hda_nid_t nid = cfg->inputs[i].pin;
934 int ctl = snd_hda_codec_read(codec, nid, 0,
935 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
936 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
937 continue;
938 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
939 spec->hp_independent_mode && spec->codec_type != VT1718S)
940 continue; /* ignore FMic for independent HP */
941 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
942 on = 0;
944 *ucontrol->value.integer.value = on;
945 return 0;
948 static int via_smart51_put(struct snd_kcontrol *kcontrol,
949 struct snd_ctl_elem_value *ucontrol)
951 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
952 struct via_spec *spec = codec->spec;
953 const struct auto_pin_cfg *cfg = &spec->autocfg;
954 int out_in = *ucontrol->value.integer.value
955 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
956 int i;
958 for (i = 0; i < cfg->num_inputs; i++) {
959 hda_nid_t nid = cfg->inputs[i].pin;
960 unsigned int parm;
962 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
963 continue;
964 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
965 spec->hp_independent_mode && spec->codec_type != VT1718S)
966 continue; /* don't retask FMic for independent HP */
968 parm = snd_hda_codec_read(codec, nid, 0,
969 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
970 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
971 parm |= out_in;
972 snd_hda_codec_write(codec, nid, 0,
973 AC_VERB_SET_PIN_WIDGET_CONTROL,
974 parm);
975 if (out_in == AC_PINCTL_OUT_EN) {
976 mute_aa_path(codec, 1);
977 notify_aa_path_ctls(codec);
979 if (spec->codec_type == VT1718S) {
980 snd_hda_codec_amp_stereo(
981 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
982 HDA_AMP_UNMUTE);
984 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
985 if (spec->codec_type == VT1708S
986 || spec->codec_type == VT1716S) {
987 /* input = index 1 (AOW3) */
988 snd_hda_codec_write(
989 codec, nid, 0,
990 AC_VERB_SET_CONNECT_SEL, 1);
991 snd_hda_codec_amp_stereo(
992 codec, nid, HDA_OUTPUT,
993 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
997 spec->smart51_enabled = *ucontrol->value.integer.value;
998 set_widgets_power_state(codec);
999 return 1;
1002 static struct snd_kcontrol_new via_smart51_mixer[2] = {
1004 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1005 .name = "Smart 5.1",
1006 .count = 1,
1007 .info = via_smart51_info,
1008 .get = via_smart51_get,
1009 .put = via_smart51_put,
1012 .iface = NID_MAPPING,
1013 .name = "Smart 5.1",
1017 static int via_smart51_build(struct via_spec *spec)
1019 struct snd_kcontrol_new *knew;
1020 const struct auto_pin_cfg *cfg = &spec->autocfg;
1021 hda_nid_t nid;
1022 int i;
1024 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1025 if (knew == NULL)
1026 return -ENOMEM;
1028 for (i = 0; i < cfg->num_inputs; i++) {
1029 nid = cfg->inputs[i].pin;
1030 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1031 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1032 if (knew == NULL)
1033 return -ENOMEM;
1034 knew->subdevice = nid;
1035 break;
1039 return 0;
1042 /* capture mixer elements */
1043 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1044 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1045 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1046 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1047 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1049 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1050 /* The multiple "Capture Source" controls confuse alsamixer
1051 * So call somewhat different..
1053 /* .name = "Capture Source", */
1054 .name = "Input Source",
1055 .count = 1,
1056 .info = via_mux_enum_info,
1057 .get = via_mux_enum_get,
1058 .put = via_mux_enum_put,
1060 { } /* end */
1063 /* check AA path's mute statue */
1064 static int is_aa_path_mute(struct hda_codec *codec)
1066 int mute = 1;
1067 hda_nid_t nid_mixer;
1068 int start_idx;
1069 int end_idx;
1070 int i;
1071 struct via_spec *spec = codec->spec;
1072 /* get nid of MW0 and start & end index */
1073 switch (spec->codec_type) {
1074 case VT1708B_8CH:
1075 case VT1708B_4CH:
1076 case VT1708S:
1077 case VT1716S:
1078 nid_mixer = 0x16;
1079 start_idx = 2;
1080 end_idx = 4;
1081 break;
1082 case VT1702:
1083 nid_mixer = 0x1a;
1084 start_idx = 1;
1085 end_idx = 3;
1086 break;
1087 case VT1718S:
1088 nid_mixer = 0x21;
1089 start_idx = 1;
1090 end_idx = 3;
1091 break;
1092 case VT2002P:
1093 case VT1812:
1094 case VT1802:
1095 nid_mixer = 0x21;
1096 start_idx = 0;
1097 end_idx = 2;
1098 break;
1099 default:
1100 return 0;
1102 /* check AA path's mute status */
1103 for (i = start_idx; i <= end_idx; i++) {
1104 unsigned int con_list = snd_hda_codec_read(
1105 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1106 int shift = 8 * (i % 4);
1107 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1108 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1109 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1110 /* check mute status while the pin is connected */
1111 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1112 HDA_INPUT, i) >> 7;
1113 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1114 HDA_INPUT, i) >> 7;
1115 if (!mute_l || !mute_r) {
1116 mute = 0;
1117 break;
1121 return mute;
1124 /* enter/exit analog low-current mode */
1125 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1127 struct via_spec *spec = codec->spec;
1128 static int saved_stream_idle = 1; /* saved stream idle status */
1129 int enable = is_aa_path_mute(codec);
1130 unsigned int verb = 0;
1131 unsigned int parm = 0;
1133 if (stream_idle == -1) /* stream status did not change */
1134 enable = enable && saved_stream_idle;
1135 else {
1136 enable = enable && stream_idle;
1137 saved_stream_idle = stream_idle;
1140 /* decide low current mode's verb & parameter */
1141 switch (spec->codec_type) {
1142 case VT1708B_8CH:
1143 case VT1708B_4CH:
1144 verb = 0xf70;
1145 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1146 break;
1147 case VT1708S:
1148 case VT1718S:
1149 case VT1716S:
1150 verb = 0xf73;
1151 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1152 break;
1153 case VT1702:
1154 verb = 0xf73;
1155 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1156 break;
1157 case VT2002P:
1158 case VT1812:
1159 case VT1802:
1160 verb = 0xf93;
1161 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1162 break;
1163 default:
1164 return; /* other codecs are not supported */
1166 /* send verb */
1167 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1171 * generic initialization of ADC, input mixers and output mixers
1173 static struct hda_verb vt1708_volume_init_verbs[] = {
1175 * Unmute ADC0-1 and set the default input to mic-in
1177 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1178 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1181 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1182 * mixer widget
1184 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1185 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1186 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1187 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1188 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1189 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1192 * Set up output mixers (0x19 - 0x1b)
1194 /* set vol=0 to output mixers */
1195 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1196 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1197 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1199 /* Setup default input MW0 to PW4 */
1200 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1201 /* PW9 Output enable */
1202 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1203 /* power down jack detect function */
1204 {0x1, 0xf81, 0x1},
1208 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1209 struct hda_codec *codec,
1210 struct snd_pcm_substream *substream)
1212 struct via_spec *spec = codec->spec;
1213 int idle = substream->pstr->substream_opened == 1
1214 && substream->ref_count == 0;
1215 analog_low_current_mode(codec, idle);
1216 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1217 hinfo);
1220 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1221 unsigned int stream_tag,
1222 unsigned int format,
1223 struct snd_pcm_substream *substream)
1225 struct via_spec *spec = codec->spec;
1226 struct hda_multi_out *mout = &spec->multiout;
1227 hda_nid_t *nids = mout->dac_nids;
1228 int chs = substream->runtime->channels;
1229 int i;
1231 mutex_lock(&codec->spdif_mutex);
1232 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1233 if (chs == 2 &&
1234 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1235 format) &&
1236 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1237 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1238 /* turn off SPDIF once; otherwise the IEC958 bits won't
1239 * be updated */
1240 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1241 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1242 AC_VERB_SET_DIGI_CONVERT_1,
1243 codec->spdif_ctls &
1244 ~AC_DIG1_ENABLE & 0xff);
1245 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1246 stream_tag, 0, format);
1247 /* turn on again (if needed) */
1248 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1249 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1250 AC_VERB_SET_DIGI_CONVERT_1,
1251 codec->spdif_ctls & 0xff);
1252 } else {
1253 mout->dig_out_used = 0;
1254 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1255 0, 0, 0);
1258 mutex_unlock(&codec->spdif_mutex);
1260 /* front */
1261 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1262 0, format);
1264 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1265 && !spec->hp_independent_mode)
1266 /* headphone out will just decode front left/right (stereo) */
1267 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1268 0, format);
1270 /* extra outputs copied from front */
1271 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1272 if (mout->extra_out_nid[i])
1273 snd_hda_codec_setup_stream(codec,
1274 mout->extra_out_nid[i],
1275 stream_tag, 0, format);
1277 /* surrounds */
1278 for (i = 1; i < mout->num_dacs; i++) {
1279 if (chs >= (i + 1) * 2) /* independent out */
1280 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1281 i * 2, format);
1282 else /* copy front */
1283 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1284 0, format);
1288 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1289 struct hda_codec *codec,
1290 unsigned int stream_tag,
1291 unsigned int format,
1292 struct snd_pcm_substream *substream)
1294 struct via_spec *spec = codec->spec;
1295 struct hda_multi_out *mout = &spec->multiout;
1296 hda_nid_t *nids = mout->dac_nids;
1298 if (substream->number == 0)
1299 playback_multi_pcm_prep_0(codec, stream_tag, format,
1300 substream);
1301 else {
1302 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1303 spec->hp_independent_mode)
1304 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1305 stream_tag, 0, format);
1307 vt1708_start_hp_work(spec);
1308 return 0;
1311 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1312 struct hda_codec *codec,
1313 struct snd_pcm_substream *substream)
1315 struct via_spec *spec = codec->spec;
1316 struct hda_multi_out *mout = &spec->multiout;
1317 hda_nid_t *nids = mout->dac_nids;
1318 int i;
1320 if (substream->number == 0) {
1321 for (i = 0; i < mout->num_dacs; i++)
1322 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1324 if (mout->hp_nid && !spec->hp_independent_mode)
1325 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1326 0, 0, 0);
1328 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1329 if (mout->extra_out_nid[i])
1330 snd_hda_codec_setup_stream(codec,
1331 mout->extra_out_nid[i],
1332 0, 0, 0);
1333 mutex_lock(&codec->spdif_mutex);
1334 if (mout->dig_out_nid &&
1335 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1336 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1337 0, 0, 0);
1338 mout->dig_out_used = 0;
1340 mutex_unlock(&codec->spdif_mutex);
1341 } else {
1342 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1343 spec->hp_independent_mode)
1344 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1345 0, 0, 0);
1347 vt1708_stop_hp_work(spec);
1348 return 0;
1352 * Digital out
1354 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1355 struct hda_codec *codec,
1356 struct snd_pcm_substream *substream)
1358 struct via_spec *spec = codec->spec;
1359 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1362 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1363 struct hda_codec *codec,
1364 struct snd_pcm_substream *substream)
1366 struct via_spec *spec = codec->spec;
1367 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1370 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1371 struct hda_codec *codec,
1372 unsigned int stream_tag,
1373 unsigned int format,
1374 struct snd_pcm_substream *substream)
1376 struct via_spec *spec = codec->spec;
1377 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1378 stream_tag, format, substream);
1381 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1382 struct hda_codec *codec,
1383 struct snd_pcm_substream *substream)
1385 struct via_spec *spec = codec->spec;
1386 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1387 return 0;
1391 * Analog capture
1393 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1394 struct hda_codec *codec,
1395 unsigned int stream_tag,
1396 unsigned int format,
1397 struct snd_pcm_substream *substream)
1399 struct via_spec *spec = codec->spec;
1401 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1402 stream_tag, 0, format);
1403 return 0;
1406 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1407 struct hda_codec *codec,
1408 struct snd_pcm_substream *substream)
1410 struct via_spec *spec = codec->spec;
1411 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1412 return 0;
1415 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1416 .substreams = 2,
1417 .channels_min = 2,
1418 .channels_max = 8,
1419 .nid = 0x10, /* NID to query formats and rates */
1420 .ops = {
1421 .open = via_playback_pcm_open,
1422 .prepare = via_playback_multi_pcm_prepare,
1423 .cleanup = via_playback_multi_pcm_cleanup
1427 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1428 .substreams = 2,
1429 .channels_min = 2,
1430 .channels_max = 8,
1431 .nid = 0x10, /* NID to query formats and rates */
1432 /* We got noisy outputs on the right channel on VT1708 when
1433 * 24bit samples are used. Until any workaround is found,
1434 * disable the 24bit format, so far.
1436 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1437 .ops = {
1438 .open = via_playback_pcm_open,
1439 .prepare = via_playback_multi_pcm_prepare,
1440 .cleanup = via_playback_multi_pcm_cleanup
1444 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1445 .substreams = 2,
1446 .channels_min = 2,
1447 .channels_max = 2,
1448 .nid = 0x15, /* NID to query formats and rates */
1449 .ops = {
1450 .prepare = via_capture_pcm_prepare,
1451 .cleanup = via_capture_pcm_cleanup
1455 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1456 .substreams = 1,
1457 .channels_min = 2,
1458 .channels_max = 2,
1459 /* NID is set in via_build_pcms */
1460 .ops = {
1461 .open = via_dig_playback_pcm_open,
1462 .close = via_dig_playback_pcm_close,
1463 .prepare = via_dig_playback_pcm_prepare,
1464 .cleanup = via_dig_playback_pcm_cleanup
1468 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1469 .substreams = 1,
1470 .channels_min = 2,
1471 .channels_max = 2,
1474 static int via_build_controls(struct hda_codec *codec)
1476 struct via_spec *spec = codec->spec;
1477 struct snd_kcontrol *kctl;
1478 struct snd_kcontrol_new *knew;
1479 int err, i;
1481 for (i = 0; i < spec->num_mixers; i++) {
1482 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1483 if (err < 0)
1484 return err;
1487 if (spec->multiout.dig_out_nid) {
1488 err = snd_hda_create_spdif_out_ctls(codec,
1489 spec->multiout.dig_out_nid);
1490 if (err < 0)
1491 return err;
1492 err = snd_hda_create_spdif_share_sw(codec,
1493 &spec->multiout);
1494 if (err < 0)
1495 return err;
1496 spec->multiout.share_spdif = 1;
1498 if (spec->dig_in_nid) {
1499 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1500 if (err < 0)
1501 return err;
1504 /* assign Capture Source enums to NID */
1505 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1506 for (i = 0; kctl && i < kctl->count; i++) {
1507 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1508 if (err < 0)
1509 return err;
1512 /* other nid->control mapping */
1513 for (i = 0; i < spec->num_mixers; i++) {
1514 for (knew = spec->mixers[i]; knew->name; knew++) {
1515 if (knew->iface != NID_MAPPING)
1516 continue;
1517 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1518 if (kctl == NULL)
1519 continue;
1520 err = snd_hda_add_nid(codec, kctl, 0,
1521 knew->subdevice);
1525 /* init power states */
1526 set_widgets_power_state(codec);
1527 analog_low_current_mode(codec, 1);
1529 via_free_kctls(codec); /* no longer needed */
1530 return 0;
1533 static int via_build_pcms(struct hda_codec *codec)
1535 struct via_spec *spec = codec->spec;
1536 struct hda_pcm *info = spec->pcm_rec;
1538 codec->num_pcms = 1;
1539 codec->pcm_info = info;
1541 info->name = spec->stream_name_analog;
1542 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1543 *(spec->stream_analog_playback);
1544 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1545 spec->multiout.dac_nids[0];
1546 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1547 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1549 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1550 spec->multiout.max_channels;
1552 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1553 codec->num_pcms++;
1554 info++;
1555 info->name = spec->stream_name_digital;
1556 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1557 if (spec->multiout.dig_out_nid) {
1558 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1559 *(spec->stream_digital_playback);
1560 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1561 spec->multiout.dig_out_nid;
1563 if (spec->dig_in_nid) {
1564 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1565 *(spec->stream_digital_capture);
1566 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1567 spec->dig_in_nid;
1571 return 0;
1574 static void via_free(struct hda_codec *codec)
1576 struct via_spec *spec = codec->spec;
1578 if (!spec)
1579 return;
1581 via_free_kctls(codec);
1582 vt1708_stop_hp_work(spec);
1583 kfree(codec->spec);
1586 /* mute internal speaker if HP is plugged */
1587 static void via_hp_automute(struct hda_codec *codec)
1589 unsigned int present = 0;
1590 struct via_spec *spec = codec->spec;
1592 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1594 if (!spec->hp_independent_mode) {
1595 struct snd_ctl_elem_id id;
1596 /* auto mute */
1597 snd_hda_codec_amp_stereo(
1598 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1599 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1600 /* notify change */
1601 memset(&id, 0, sizeof(id));
1602 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1603 strcpy(id.name, "Front Playback Switch");
1604 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1605 &id);
1609 /* mute mono out if HP or Line out is plugged */
1610 static void via_mono_automute(struct hda_codec *codec)
1612 unsigned int hp_present, lineout_present;
1613 struct via_spec *spec = codec->spec;
1615 if (spec->codec_type != VT1716S)
1616 return;
1618 lineout_present = snd_hda_jack_detect(codec,
1619 spec->autocfg.line_out_pins[0]);
1621 /* Mute Mono Out if Line Out is plugged */
1622 if (lineout_present) {
1623 snd_hda_codec_amp_stereo(
1624 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1625 return;
1628 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1630 if (!spec->hp_independent_mode)
1631 snd_hda_codec_amp_stereo(
1632 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1633 hp_present ? HDA_AMP_MUTE : 0);
1636 static void via_gpio_control(struct hda_codec *codec)
1638 unsigned int gpio_data;
1639 unsigned int vol_counter;
1640 unsigned int vol;
1641 unsigned int master_vol;
1643 struct via_spec *spec = codec->spec;
1645 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1646 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1648 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1649 0xF84, 0) & 0x3F0000) >> 16;
1651 vol = vol_counter & 0x1F;
1652 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1653 AC_VERB_GET_AMP_GAIN_MUTE,
1654 AC_AMP_GET_INPUT);
1656 if (gpio_data == 0x02) {
1657 /* unmute line out */
1658 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1659 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1661 if (vol_counter & 0x20) {
1662 /* decrease volume */
1663 if (vol > master_vol)
1664 vol = master_vol;
1665 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1666 0, HDA_AMP_VOLMASK,
1667 master_vol-vol);
1668 } else {
1669 /* increase volume */
1670 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1671 HDA_AMP_VOLMASK,
1672 ((master_vol+vol) > 0x2A) ? 0x2A :
1673 (master_vol+vol));
1675 } else if (!(gpio_data & 0x02)) {
1676 /* mute line out */
1677 snd_hda_codec_amp_stereo(codec,
1678 spec->autocfg.line_out_pins[0],
1679 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1680 HDA_AMP_MUTE);
1684 /* mute Internal-Speaker if HP is plugged */
1685 static void via_speaker_automute(struct hda_codec *codec)
1687 unsigned int hp_present;
1688 struct via_spec *spec = codec->spec;
1690 if (!VT2002P_COMPATIBLE(spec))
1691 return;
1693 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1695 if (!spec->hp_independent_mode) {
1696 struct snd_ctl_elem_id id;
1697 snd_hda_codec_amp_stereo(
1698 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
1699 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1700 /* notify change */
1701 memset(&id, 0, sizeof(id));
1702 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1703 strcpy(id.name, "Speaker Playback Switch");
1704 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1705 &id);
1709 /* mute line-out and internal speaker if HP is plugged */
1710 static void via_hp_bind_automute(struct hda_codec *codec)
1712 /* use long instead of int below just to avoid an internal compiler
1713 * error with gcc 4.0.x
1715 unsigned long hp_present, present = 0;
1716 struct via_spec *spec = codec->spec;
1717 int i;
1719 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1720 return;
1722 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1724 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
1726 if (!spec->hp_independent_mode) {
1727 /* Mute Line-Outs */
1728 for (i = 0; i < spec->autocfg.line_outs; i++)
1729 snd_hda_codec_amp_stereo(
1730 codec, spec->autocfg.line_out_pins[i],
1731 HDA_OUTPUT, 0,
1732 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1733 if (hp_present)
1734 present = hp_present;
1736 /* Speakers */
1737 for (i = 0; i < spec->autocfg.speaker_outs; i++)
1738 snd_hda_codec_amp_stereo(
1739 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
1740 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1744 /* unsolicited event for jack sensing */
1745 static void via_unsol_event(struct hda_codec *codec,
1746 unsigned int res)
1748 res >>= 26;
1750 if (res & VIA_JACK_EVENT)
1751 set_widgets_power_state(codec);
1753 res &= ~VIA_JACK_EVENT;
1755 if (res == VIA_HP_EVENT)
1756 via_hp_automute(codec);
1757 else if (res == VIA_GPIO_EVENT)
1758 via_gpio_control(codec);
1759 else if (res == VIA_MONO_EVENT)
1760 via_mono_automute(codec);
1761 else if (res == VIA_SPEAKER_EVENT)
1762 via_speaker_automute(codec);
1763 else if (res == VIA_BIND_HP_EVENT)
1764 via_hp_bind_automute(codec);
1767 static int via_init(struct hda_codec *codec)
1769 struct via_spec *spec = codec->spec;
1770 int i;
1771 for (i = 0; i < spec->num_iverbs; i++)
1772 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1774 /* Lydia Add for EAPD enable */
1775 if (!spec->dig_in_nid) { /* No Digital In connection */
1776 if (spec->dig_in_pin) {
1777 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1778 AC_VERB_SET_PIN_WIDGET_CONTROL,
1779 PIN_OUT);
1780 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1781 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1783 } else /* enable SPDIF-input pin */
1784 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1785 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1787 /* assign slave outs */
1788 if (spec->slave_dig_outs[0])
1789 codec->slave_dig_outs = spec->slave_dig_outs;
1791 return 0;
1794 #ifdef SND_HDA_NEEDS_RESUME
1795 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1797 struct via_spec *spec = codec->spec;
1798 vt1708_stop_hp_work(spec);
1799 return 0;
1801 #endif
1803 #ifdef CONFIG_SND_HDA_POWER_SAVE
1804 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1806 struct via_spec *spec = codec->spec;
1807 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1809 #endif
1813 static struct hda_codec_ops via_patch_ops = {
1814 .build_controls = via_build_controls,
1815 .build_pcms = via_build_pcms,
1816 .init = via_init,
1817 .free = via_free,
1818 #ifdef SND_HDA_NEEDS_RESUME
1819 .suspend = via_suspend,
1820 #endif
1821 #ifdef CONFIG_SND_HDA_POWER_SAVE
1822 .check_power_status = via_check_power_status,
1823 #endif
1826 /* fill in the dac_nids table from the parsed pin configuration */
1827 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1828 const struct auto_pin_cfg *cfg)
1830 int i;
1831 hda_nid_t nid;
1833 spec->multiout.num_dacs = cfg->line_outs;
1835 spec->multiout.dac_nids = spec->private_dac_nids;
1837 for (i = 0; i < 4; i++) {
1838 nid = cfg->line_out_pins[i];
1839 if (nid) {
1840 /* config dac list */
1841 switch (i) {
1842 case AUTO_SEQ_FRONT:
1843 spec->multiout.dac_nids[i] = 0x10;
1844 break;
1845 case AUTO_SEQ_CENLFE:
1846 spec->multiout.dac_nids[i] = 0x12;
1847 break;
1848 case AUTO_SEQ_SURROUND:
1849 spec->multiout.dac_nids[i] = 0x11;
1850 break;
1851 case AUTO_SEQ_SIDE:
1852 spec->multiout.dac_nids[i] = 0x13;
1853 break;
1858 return 0;
1861 /* add playback controls from the parsed DAC table */
1862 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1863 const struct auto_pin_cfg *cfg)
1865 char name[32];
1866 static const char * const chname[4] = {
1867 "Front", "Surround", "C/LFE", "Side"
1869 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
1870 int i, err;
1872 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1873 nid = cfg->line_out_pins[i];
1875 if (!nid)
1876 continue;
1878 nid_vol = nid_vols[i];
1880 if (i == AUTO_SEQ_CENLFE) {
1881 /* Center/LFE */
1882 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1883 "Center Playback Volume",
1884 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1885 HDA_OUTPUT));
1886 if (err < 0)
1887 return err;
1888 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1889 "LFE Playback Volume",
1890 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1891 HDA_OUTPUT));
1892 if (err < 0)
1893 return err;
1894 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1895 "Center Playback Switch",
1896 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1897 HDA_OUTPUT));
1898 if (err < 0)
1899 return err;
1900 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1901 "LFE Playback Switch",
1902 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1903 HDA_OUTPUT));
1904 if (err < 0)
1905 return err;
1906 } else if (i == AUTO_SEQ_FRONT) {
1907 /* add control to mixer index 0 */
1908 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1909 "Master Front Playback Volume",
1910 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1911 HDA_INPUT));
1912 if (err < 0)
1913 return err;
1914 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1915 "Master Front Playback Switch",
1916 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1917 HDA_INPUT));
1918 if (err < 0)
1919 return err;
1921 /* add control to PW3 */
1922 sprintf(name, "%s Playback Volume", chname[i]);
1923 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1924 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1925 HDA_OUTPUT));
1926 if (err < 0)
1927 return err;
1928 sprintf(name, "%s Playback Switch", chname[i]);
1929 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1930 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1931 HDA_OUTPUT));
1932 if (err < 0)
1933 return err;
1934 } else {
1935 sprintf(name, "%s Playback Volume", chname[i]);
1936 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1937 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1938 HDA_OUTPUT));
1939 if (err < 0)
1940 return err;
1941 sprintf(name, "%s Playback Switch", chname[i]);
1942 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1943 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1944 HDA_OUTPUT));
1945 if (err < 0)
1946 return err;
1950 return 0;
1953 static void create_hp_imux(struct via_spec *spec)
1955 int i;
1956 struct hda_input_mux *imux = &spec->private_imux[1];
1957 static const char * const texts[] = { "OFF", "ON", NULL};
1959 /* for hp mode select */
1960 for (i = 0; texts[i]; i++)
1961 snd_hda_add_imux_item(imux, texts[i], i, NULL);
1963 spec->hp_mux = &spec->private_imux[1];
1966 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1968 int err;
1970 if (!pin)
1971 return 0;
1973 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1974 spec->hp_independent_mode_index = 1;
1976 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1977 "Headphone Playback Volume",
1978 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1979 if (err < 0)
1980 return err;
1981 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1982 "Headphone Playback Switch",
1983 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1984 if (err < 0)
1985 return err;
1987 create_hp_imux(spec);
1989 return 0;
1992 /* create playback/capture controls for input pins */
1993 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
1994 const struct auto_pin_cfg *cfg,
1995 hda_nid_t cap_nid,
1996 hda_nid_t pin_idxs[], int num_idxs)
1998 struct via_spec *spec = codec->spec;
1999 struct hda_input_mux *imux = &spec->private_imux[0];
2000 int i, err, idx, type, type_idx = 0;
2002 /* for internal loopback recording select */
2003 for (idx = 0; idx < num_idxs; idx++) {
2004 if (pin_idxs[idx] == 0xff) {
2005 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2006 break;
2010 for (i = 0; i < cfg->num_inputs; i++) {
2011 const char *label;
2012 type = cfg->inputs[i].type;
2013 for (idx = 0; idx < num_idxs; idx++)
2014 if (pin_idxs[idx] == cfg->inputs[i].pin)
2015 break;
2016 if (idx >= num_idxs)
2017 continue;
2018 if (i > 0 && type == cfg->inputs[i - 1].type)
2019 type_idx++;
2020 else
2021 type_idx = 0;
2022 label = hda_get_autocfg_input_label(codec, cfg, i);
2023 if (spec->codec_type == VT1708S ||
2024 spec->codec_type == VT1702 ||
2025 spec->codec_type == VT1716S)
2026 err = via_new_analog_input(spec, label, type_idx,
2027 idx+1, cap_nid);
2028 else
2029 err = via_new_analog_input(spec, label, type_idx,
2030 idx, cap_nid);
2031 if (err < 0)
2032 return err;
2033 snd_hda_add_imux_item(imux, label, idx, NULL);
2035 return 0;
2038 /* create playback/capture controls for input pins */
2039 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2040 const struct auto_pin_cfg *cfg)
2042 static hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2043 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
2044 ARRAY_SIZE(pin_idxs));
2047 #ifdef CONFIG_SND_HDA_POWER_SAVE
2048 static struct hda_amp_list vt1708_loopbacks[] = {
2049 { 0x17, HDA_INPUT, 1 },
2050 { 0x17, HDA_INPUT, 2 },
2051 { 0x17, HDA_INPUT, 3 },
2052 { 0x17, HDA_INPUT, 4 },
2053 { } /* end */
2055 #endif
2057 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2059 unsigned int def_conf;
2060 unsigned char seqassoc;
2062 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2063 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2064 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2065 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2066 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2067 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2068 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2071 return;
2074 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2075 struct snd_ctl_elem_value *ucontrol)
2077 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2078 struct via_spec *spec = codec->spec;
2080 if (spec->codec_type != VT1708)
2081 return 0;
2082 spec->vt1708_jack_detectect =
2083 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2084 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2085 return 0;
2088 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2089 struct snd_ctl_elem_value *ucontrol)
2091 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2092 struct via_spec *spec = codec->spec;
2093 int change;
2095 if (spec->codec_type != VT1708)
2096 return 0;
2097 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2098 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2099 == !spec->vt1708_jack_detectect;
2100 if (spec->vt1708_jack_detectect) {
2101 mute_aa_path(codec, 1);
2102 notify_aa_path_ctls(codec);
2104 return change;
2107 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2109 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2110 .name = "Jack Detect",
2111 .count = 1,
2112 .info = snd_ctl_boolean_mono_info,
2113 .get = vt1708_jack_detectect_get,
2114 .put = vt1708_jack_detectect_put,
2116 {} /* end */
2119 static int vt1708_parse_auto_config(struct hda_codec *codec)
2121 struct via_spec *spec = codec->spec;
2122 int err;
2124 /* Add HP and CD pin config connect bit re-config action */
2125 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2126 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2128 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2129 if (err < 0)
2130 return err;
2131 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2132 if (err < 0)
2133 return err;
2134 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2135 return 0; /* can't find valid BIOS pin config */
2137 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2138 if (err < 0)
2139 return err;
2140 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2141 if (err < 0)
2142 return err;
2143 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2144 if (err < 0)
2145 return err;
2146 /* add jack detect on/off control */
2147 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2148 if (err < 0)
2149 return err;
2151 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2153 if (spec->autocfg.dig_outs)
2154 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2155 spec->dig_in_pin = VT1708_DIGIN_PIN;
2156 if (spec->autocfg.dig_in_pin)
2157 spec->dig_in_nid = VT1708_DIGIN_NID;
2159 if (spec->kctls.list)
2160 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2162 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2164 spec->input_mux = &spec->private_imux[0];
2166 if (spec->hp_mux)
2167 via_hp_build(codec);
2169 via_smart51_build(spec);
2170 return 1;
2173 /* init callback for auto-configuration model -- overriding the default init */
2174 static int via_auto_init(struct hda_codec *codec)
2176 struct via_spec *spec = codec->spec;
2178 via_init(codec);
2179 via_auto_init_multi_out(codec);
2180 via_auto_init_hp_out(codec);
2181 via_auto_init_analog_input(codec);
2183 if (VT2002P_COMPATIBLE(spec)) {
2184 via_hp_bind_automute(codec);
2185 } else {
2186 via_hp_automute(codec);
2187 via_speaker_automute(codec);
2190 return 0;
2193 static void vt1708_update_hp_jack_state(struct work_struct *work)
2195 struct via_spec *spec = container_of(work, struct via_spec,
2196 vt1708_hp_work.work);
2197 if (spec->codec_type != VT1708)
2198 return;
2199 /* if jack state toggled */
2200 if (spec->vt1708_hp_present
2201 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2202 spec->vt1708_hp_present ^= 1;
2203 via_hp_automute(spec->codec);
2205 vt1708_start_hp_work(spec);
2208 static int get_mux_nids(struct hda_codec *codec)
2210 struct via_spec *spec = codec->spec;
2211 hda_nid_t nid, conn[8];
2212 unsigned int type;
2213 int i, n;
2215 for (i = 0; i < spec->num_adc_nids; i++) {
2216 nid = spec->adc_nids[i];
2217 while (nid) {
2218 type = get_wcaps_type(get_wcaps(codec, nid));
2219 if (type == AC_WID_PIN)
2220 break;
2221 n = snd_hda_get_connections(codec, nid, conn,
2222 ARRAY_SIZE(conn));
2223 if (n <= 0)
2224 break;
2225 if (n > 1) {
2226 spec->mux_nids[i] = nid;
2227 break;
2229 nid = conn[0];
2232 return 0;
2235 static int patch_vt1708(struct hda_codec *codec)
2237 struct via_spec *spec;
2238 int err;
2240 /* create a codec specific record */
2241 spec = via_new_spec(codec);
2242 if (spec == NULL)
2243 return -ENOMEM;
2245 /* automatic parse from the BIOS config */
2246 err = vt1708_parse_auto_config(codec);
2247 if (err < 0) {
2248 via_free(codec);
2249 return err;
2250 } else if (!err) {
2251 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2252 "from BIOS. Using genenic mode...\n");
2256 spec->stream_name_analog = "VT1708 Analog";
2257 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2258 /* disable 32bit format on VT1708 */
2259 if (codec->vendor_id == 0x11061708)
2260 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2261 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2263 spec->stream_name_digital = "VT1708 Digital";
2264 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2265 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2268 if (!spec->adc_nids && spec->input_mux) {
2269 spec->adc_nids = vt1708_adc_nids;
2270 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2271 get_mux_nids(codec);
2272 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2273 spec->num_mixers++;
2276 codec->patch_ops = via_patch_ops;
2278 codec->patch_ops.init = via_auto_init;
2279 #ifdef CONFIG_SND_HDA_POWER_SAVE
2280 spec->loopback.amplist = vt1708_loopbacks;
2281 #endif
2282 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2283 return 0;
2286 /* capture mixer elements */
2287 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2288 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2289 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2290 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2291 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2292 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2293 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2295 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2296 /* The multiple "Capture Source" controls confuse alsamixer
2297 * So call somewhat different..
2299 /* .name = "Capture Source", */
2300 .name = "Input Source",
2301 .count = 1,
2302 .info = via_mux_enum_info,
2303 .get = via_mux_enum_get,
2304 .put = via_mux_enum_put,
2306 { } /* end */
2309 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2310 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2311 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2316 * generic initialization of ADC, input mixers and output mixers
2318 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2320 * Unmute ADC0-2 and set the default input to mic-in
2322 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2323 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2324 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2327 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2328 * mixer widget
2330 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2331 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2332 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2333 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2334 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2335 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2338 * Set up output selector (0x1a, 0x1b, 0x29)
2340 /* set vol=0 to output mixers */
2341 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2342 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2343 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2346 * Unmute PW3 and PW4
2348 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2349 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2351 /* Set input of PW4 as MW0 */
2352 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2353 /* PW9 Output enable */
2354 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2358 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2359 .substreams = 1,
2360 .channels_min = 2,
2361 .channels_max = 10,
2362 .nid = 0x10, /* NID to query formats and rates */
2363 .ops = {
2364 .open = via_playback_pcm_open,
2365 .prepare = via_playback_multi_pcm_prepare,
2366 .cleanup = via_playback_multi_pcm_cleanup,
2370 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2371 .substreams = 1,
2372 .channels_min = 2,
2373 .channels_max = 6,
2374 .nid = 0x10, /* NID to query formats and rates */
2375 .ops = {
2376 .open = via_playback_pcm_open,
2377 .prepare = via_playback_multi_pcm_prepare,
2378 .cleanup = via_playback_multi_pcm_cleanup,
2382 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2383 .substreams = 2,
2384 .channels_min = 2,
2385 .channels_max = 2,
2386 .nid = 0x14, /* NID to query formats and rates */
2387 .ops = {
2388 .prepare = via_capture_pcm_prepare,
2389 .cleanup = via_capture_pcm_cleanup
2393 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2394 .substreams = 1,
2395 .channels_min = 2,
2396 .channels_max = 2,
2397 /* NID is set in via_build_pcms */
2398 .ops = {
2399 .open = via_dig_playback_pcm_open,
2400 .close = via_dig_playback_pcm_close
2404 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2405 .substreams = 1,
2406 .channels_min = 2,
2407 .channels_max = 2,
2410 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2411 const struct auto_pin_cfg *cfg)
2413 int i;
2414 hda_nid_t nid;
2416 if (cfg->line_outs == 4) /* 10 channels */
2417 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2418 else if (cfg->line_outs == 3) /* 6 channels */
2419 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2421 spec->multiout.dac_nids = spec->private_dac_nids;
2423 if (cfg->line_outs == 4) { /* 10 channels */
2424 for (i = 0; i < cfg->line_outs; i++) {
2425 nid = cfg->line_out_pins[i];
2426 if (nid) {
2427 /* config dac list */
2428 switch (i) {
2429 case AUTO_SEQ_FRONT:
2430 /* AOW0 */
2431 spec->multiout.dac_nids[i] = 0x10;
2432 break;
2433 case AUTO_SEQ_CENLFE:
2434 /* AOW2 */
2435 spec->multiout.dac_nids[i] = 0x12;
2436 break;
2437 case AUTO_SEQ_SURROUND:
2438 /* AOW3 */
2439 spec->multiout.dac_nids[i] = 0x11;
2440 break;
2441 case AUTO_SEQ_SIDE:
2442 /* AOW1 */
2443 spec->multiout.dac_nids[i] = 0x27;
2444 break;
2445 default:
2446 break;
2450 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2452 } else if (cfg->line_outs == 3) { /* 6 channels */
2453 for (i = 0; i < cfg->line_outs; i++) {
2454 nid = cfg->line_out_pins[i];
2455 if (nid) {
2456 /* config dac list */
2457 switch (i) {
2458 case AUTO_SEQ_FRONT:
2459 /* AOW0 */
2460 spec->multiout.dac_nids[i] = 0x10;
2461 break;
2462 case AUTO_SEQ_CENLFE:
2463 /* AOW2 */
2464 spec->multiout.dac_nids[i] = 0x12;
2465 break;
2466 case AUTO_SEQ_SURROUND:
2467 /* AOW1 */
2468 spec->multiout.dac_nids[i] = 0x11;
2469 break;
2470 default:
2471 break;
2477 return 0;
2480 /* add playback controls from the parsed DAC table */
2481 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2482 const struct auto_pin_cfg *cfg)
2484 char name[32];
2485 static const char * const chname[4] = {
2486 "Front", "Surround", "C/LFE", "Side"
2488 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2489 int i, err;
2491 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2492 nid = cfg->line_out_pins[i];
2494 if (!nid)
2495 continue;
2497 nid_vol = nid_vols[i];
2499 if (i == AUTO_SEQ_CENLFE) {
2500 /* Center/LFE */
2501 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2502 "Center Playback Volume",
2503 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2504 HDA_OUTPUT));
2505 if (err < 0)
2506 return err;
2507 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2508 "LFE Playback Volume",
2509 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2510 HDA_OUTPUT));
2511 if (err < 0)
2512 return err;
2513 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2514 "Center Playback Switch",
2515 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2516 HDA_OUTPUT));
2517 if (err < 0)
2518 return err;
2519 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2520 "LFE Playback Switch",
2521 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2522 HDA_OUTPUT));
2523 if (err < 0)
2524 return err;
2525 } else if (i == AUTO_SEQ_FRONT) {
2526 /* ADD control to mixer index 0 */
2527 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2528 "Master Front Playback Volume",
2529 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2530 HDA_INPUT));
2531 if (err < 0)
2532 return err;
2533 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2534 "Master Front Playback Switch",
2535 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2536 HDA_INPUT));
2537 if (err < 0)
2538 return err;
2540 /* add control to PW3 */
2541 sprintf(name, "%s Playback Volume", chname[i]);
2542 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2543 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2544 HDA_OUTPUT));
2545 if (err < 0)
2546 return err;
2547 sprintf(name, "%s Playback Switch", chname[i]);
2548 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2549 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2550 HDA_OUTPUT));
2551 if (err < 0)
2552 return err;
2553 } else if (i == AUTO_SEQ_SURROUND) {
2554 sprintf(name, "%s Playback Volume", chname[i]);
2555 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2556 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2557 HDA_OUTPUT));
2558 if (err < 0)
2559 return err;
2560 sprintf(name, "%s Playback Switch", chname[i]);
2561 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2562 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2563 HDA_OUTPUT));
2564 if (err < 0)
2565 return err;
2566 } else if (i == AUTO_SEQ_SIDE) {
2567 sprintf(name, "%s Playback Volume", chname[i]);
2568 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2569 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2570 HDA_OUTPUT));
2571 if (err < 0)
2572 return err;
2573 sprintf(name, "%s Playback Switch", chname[i]);
2574 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2575 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2576 HDA_OUTPUT));
2577 if (err < 0)
2578 return err;
2582 return 0;
2585 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2587 int err;
2589 if (!pin)
2590 return 0;
2592 if (spec->multiout.num_dacs == 5) /* 10 channels */
2593 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2594 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2595 spec->multiout.hp_nid = 0;
2596 spec->hp_independent_mode_index = 1;
2598 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2599 "Headphone Playback Volume",
2600 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2601 if (err < 0)
2602 return err;
2603 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2604 "Headphone Playback Switch",
2605 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2606 if (err < 0)
2607 return err;
2609 return 0;
2612 /* create playback/capture controls for input pins */
2613 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
2614 const struct auto_pin_cfg *cfg)
2616 static hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
2617 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
2618 ARRAY_SIZE(pin_idxs));
2621 static int vt1709_parse_auto_config(struct hda_codec *codec)
2623 struct via_spec *spec = codec->spec;
2624 int err;
2626 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2627 if (err < 0)
2628 return err;
2629 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2630 if (err < 0)
2631 return err;
2632 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2633 return 0; /* can't find valid BIOS pin config */
2635 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2636 if (err < 0)
2637 return err;
2638 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2639 if (err < 0)
2640 return err;
2641 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
2642 if (err < 0)
2643 return err;
2645 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2647 if (spec->autocfg.dig_outs)
2648 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
2649 spec->dig_in_pin = VT1709_DIGIN_PIN;
2650 if (spec->autocfg.dig_in_pin)
2651 spec->dig_in_nid = VT1709_DIGIN_NID;
2653 if (spec->kctls.list)
2654 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2656 spec->input_mux = &spec->private_imux[0];
2658 if (spec->hp_mux)
2659 via_hp_build(codec);
2661 via_smart51_build(spec);
2662 return 1;
2665 #ifdef CONFIG_SND_HDA_POWER_SAVE
2666 static struct hda_amp_list vt1709_loopbacks[] = {
2667 { 0x18, HDA_INPUT, 1 },
2668 { 0x18, HDA_INPUT, 2 },
2669 { 0x18, HDA_INPUT, 3 },
2670 { 0x18, HDA_INPUT, 4 },
2671 { } /* end */
2673 #endif
2675 static int patch_vt1709_10ch(struct hda_codec *codec)
2677 struct via_spec *spec;
2678 int err;
2680 /* create a codec specific record */
2681 spec = via_new_spec(codec);
2682 if (spec == NULL)
2683 return -ENOMEM;
2685 err = vt1709_parse_auto_config(codec);
2686 if (err < 0) {
2687 via_free(codec);
2688 return err;
2689 } else if (!err) {
2690 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2691 "Using genenic mode...\n");
2694 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2695 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2697 spec->stream_name_analog = "VT1709 Analog";
2698 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2699 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2701 spec->stream_name_digital = "VT1709 Digital";
2702 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2703 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2706 if (!spec->adc_nids && spec->input_mux) {
2707 spec->adc_nids = vt1709_adc_nids;
2708 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
2709 get_mux_nids(codec);
2710 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2711 spec->num_mixers++;
2714 codec->patch_ops = via_patch_ops;
2716 codec->patch_ops.init = via_auto_init;
2717 codec->patch_ops.unsol_event = via_unsol_event;
2718 #ifdef CONFIG_SND_HDA_POWER_SAVE
2719 spec->loopback.amplist = vt1709_loopbacks;
2720 #endif
2722 return 0;
2725 * generic initialization of ADC, input mixers and output mixers
2727 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
2729 * Unmute ADC0-2 and set the default input to mic-in
2731 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2732 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2733 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2736 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2737 * mixer widget
2739 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2740 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2741 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2742 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2743 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2744 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2747 * Set up output selector (0x1a, 0x1b, 0x29)
2749 /* set vol=0 to output mixers */
2750 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2751 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2752 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2755 * Unmute PW3 and PW4
2757 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2758 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2760 /* Set input of PW4 as MW0 */
2761 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2762 /* PW9 Output enable */
2763 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2767 static int patch_vt1709_6ch(struct hda_codec *codec)
2769 struct via_spec *spec;
2770 int err;
2772 /* create a codec specific record */
2773 spec = via_new_spec(codec);
2774 if (spec == NULL)
2775 return -ENOMEM;
2777 err = vt1709_parse_auto_config(codec);
2778 if (err < 0) {
2779 via_free(codec);
2780 return err;
2781 } else if (!err) {
2782 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2783 "Using genenic mode...\n");
2786 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2787 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2789 spec->stream_name_analog = "VT1709 Analog";
2790 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2791 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2793 spec->stream_name_digital = "VT1709 Digital";
2794 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2795 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2798 if (!spec->adc_nids && spec->input_mux) {
2799 spec->adc_nids = vt1709_adc_nids;
2800 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
2801 get_mux_nids(codec);
2802 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2803 spec->num_mixers++;
2806 codec->patch_ops = via_patch_ops;
2808 codec->patch_ops.init = via_auto_init;
2809 codec->patch_ops.unsol_event = via_unsol_event;
2810 #ifdef CONFIG_SND_HDA_POWER_SAVE
2811 spec->loopback.amplist = vt1709_loopbacks;
2812 #endif
2813 return 0;
2816 /* capture mixer elements */
2817 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
2818 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2819 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2820 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2821 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2823 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2824 /* The multiple "Capture Source" controls confuse alsamixer
2825 * So call somewhat different..
2827 /* .name = "Capture Source", */
2828 .name = "Input Source",
2829 .count = 1,
2830 .info = via_mux_enum_info,
2831 .get = via_mux_enum_get,
2832 .put = via_mux_enum_put,
2834 { } /* end */
2837 * generic initialization of ADC, input mixers and output mixers
2839 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2841 * Unmute ADC0-1 and set the default input to mic-in
2843 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2844 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2847 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2848 * mixer widget
2850 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2851 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2852 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2853 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2854 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2855 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2858 * Set up output mixers
2860 /* set vol=0 to output mixers */
2861 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2862 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2863 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2865 /* Setup default input to PW4 */
2866 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2867 /* PW9 Output enable */
2868 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2869 /* PW10 Input enable */
2870 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2874 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2876 * Unmute ADC0-1 and set the default input to mic-in
2878 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2879 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2882 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2883 * mixer widget
2885 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2886 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2887 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2888 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2889 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2890 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2893 * Set up output mixers
2895 /* set vol=0 to output mixers */
2896 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2897 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2898 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2900 /* Setup default input of PW4 to MW0 */
2901 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2902 /* PW9 Output enable */
2903 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2904 /* PW10 Input enable */
2905 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2909 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2910 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2911 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2912 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2913 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2914 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2915 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2916 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2917 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2918 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2922 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2923 struct hda_codec *codec,
2924 struct snd_pcm_substream *substream)
2926 int idle = substream->pstr->substream_opened == 1
2927 && substream->ref_count == 0;
2929 analog_low_current_mode(codec, idle);
2930 return 0;
2933 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2934 .substreams = 2,
2935 .channels_min = 2,
2936 .channels_max = 8,
2937 .nid = 0x10, /* NID to query formats and rates */
2938 .ops = {
2939 .open = via_playback_pcm_open,
2940 .prepare = via_playback_multi_pcm_prepare,
2941 .cleanup = via_playback_multi_pcm_cleanup,
2942 .close = via_pcm_open_close
2946 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
2947 .substreams = 2,
2948 .channels_min = 2,
2949 .channels_max = 4,
2950 .nid = 0x10, /* NID to query formats and rates */
2951 .ops = {
2952 .open = via_playback_pcm_open,
2953 .prepare = via_playback_multi_pcm_prepare,
2954 .cleanup = via_playback_multi_pcm_cleanup
2958 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2959 .substreams = 2,
2960 .channels_min = 2,
2961 .channels_max = 2,
2962 .nid = 0x13, /* NID to query formats and rates */
2963 .ops = {
2964 .open = via_pcm_open_close,
2965 .prepare = via_capture_pcm_prepare,
2966 .cleanup = via_capture_pcm_cleanup,
2967 .close = via_pcm_open_close
2971 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2972 .substreams = 1,
2973 .channels_min = 2,
2974 .channels_max = 2,
2975 /* NID is set in via_build_pcms */
2976 .ops = {
2977 .open = via_dig_playback_pcm_open,
2978 .close = via_dig_playback_pcm_close,
2979 .prepare = via_dig_playback_pcm_prepare,
2980 .cleanup = via_dig_playback_pcm_cleanup
2984 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
2985 .substreams = 1,
2986 .channels_min = 2,
2987 .channels_max = 2,
2990 /* fill in the dac_nids table from the parsed pin configuration */
2991 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
2992 const struct auto_pin_cfg *cfg)
2994 int i;
2995 hda_nid_t nid;
2997 spec->multiout.num_dacs = cfg->line_outs;
2999 spec->multiout.dac_nids = spec->private_dac_nids;
3001 for (i = 0; i < 4; i++) {
3002 nid = cfg->line_out_pins[i];
3003 if (nid) {
3004 /* config dac list */
3005 switch (i) {
3006 case AUTO_SEQ_FRONT:
3007 spec->multiout.dac_nids[i] = 0x10;
3008 break;
3009 case AUTO_SEQ_CENLFE:
3010 spec->multiout.dac_nids[i] = 0x24;
3011 break;
3012 case AUTO_SEQ_SURROUND:
3013 spec->multiout.dac_nids[i] = 0x11;
3014 break;
3015 case AUTO_SEQ_SIDE:
3016 spec->multiout.dac_nids[i] = 0x25;
3017 break;
3022 return 0;
3025 /* add playback controls from the parsed DAC table */
3026 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3027 const struct auto_pin_cfg *cfg)
3029 char name[32];
3030 static const char * const chname[4] = {
3031 "Front", "Surround", "C/LFE", "Side"
3033 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3034 hda_nid_t nid, nid_vol = 0;
3035 int i, err;
3037 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3038 nid = cfg->line_out_pins[i];
3040 if (!nid)
3041 continue;
3043 nid_vol = nid_vols[i];
3045 if (i == AUTO_SEQ_CENLFE) {
3046 /* Center/LFE */
3047 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3048 "Center Playback Volume",
3049 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3050 HDA_OUTPUT));
3051 if (err < 0)
3052 return err;
3053 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3054 "LFE Playback Volume",
3055 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3056 HDA_OUTPUT));
3057 if (err < 0)
3058 return err;
3059 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3060 "Center Playback Switch",
3061 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3062 HDA_OUTPUT));
3063 if (err < 0)
3064 return err;
3065 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3066 "LFE Playback Switch",
3067 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3068 HDA_OUTPUT));
3069 if (err < 0)
3070 return err;
3071 } else if (i == AUTO_SEQ_FRONT) {
3072 /* add control to mixer index 0 */
3073 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3074 "Master Front Playback Volume",
3075 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3076 HDA_INPUT));
3077 if (err < 0)
3078 return err;
3079 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3080 "Master Front Playback Switch",
3081 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3082 HDA_INPUT));
3083 if (err < 0)
3084 return err;
3086 /* add control to PW3 */
3087 sprintf(name, "%s Playback Volume", chname[i]);
3088 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3089 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3090 HDA_OUTPUT));
3091 if (err < 0)
3092 return err;
3093 sprintf(name, "%s Playback Switch", chname[i]);
3094 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3095 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3096 HDA_OUTPUT));
3097 if (err < 0)
3098 return err;
3099 } else {
3100 sprintf(name, "%s Playback Volume", chname[i]);
3101 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3102 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3103 HDA_OUTPUT));
3104 if (err < 0)
3105 return err;
3106 sprintf(name, "%s Playback Switch", chname[i]);
3107 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3108 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3109 HDA_OUTPUT));
3110 if (err < 0)
3111 return err;
3115 return 0;
3118 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3120 int err;
3122 if (!pin)
3123 return 0;
3125 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3126 spec->hp_independent_mode_index = 1;
3128 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3129 "Headphone Playback Volume",
3130 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3131 if (err < 0)
3132 return err;
3133 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3134 "Headphone Playback Switch",
3135 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3136 if (err < 0)
3137 return err;
3139 create_hp_imux(spec);
3141 return 0;
3144 /* create playback/capture controls for input pins */
3145 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3146 const struct auto_pin_cfg *cfg)
3148 static hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3149 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3150 ARRAY_SIZE(pin_idxs));
3153 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3155 struct via_spec *spec = codec->spec;
3156 int err;
3158 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3159 if (err < 0)
3160 return err;
3161 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3162 if (err < 0)
3163 return err;
3164 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3165 return 0; /* can't find valid BIOS pin config */
3167 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3168 if (err < 0)
3169 return err;
3170 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3171 if (err < 0)
3172 return err;
3173 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3174 if (err < 0)
3175 return err;
3177 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3179 if (spec->autocfg.dig_outs)
3180 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3181 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3182 if (spec->autocfg.dig_in_pin)
3183 spec->dig_in_nid = VT1708B_DIGIN_NID;
3185 if (spec->kctls.list)
3186 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3188 spec->input_mux = &spec->private_imux[0];
3190 if (spec->hp_mux)
3191 via_hp_build(codec);
3193 via_smart51_build(spec);
3194 return 1;
3197 #ifdef CONFIG_SND_HDA_POWER_SAVE
3198 static struct hda_amp_list vt1708B_loopbacks[] = {
3199 { 0x16, HDA_INPUT, 1 },
3200 { 0x16, HDA_INPUT, 2 },
3201 { 0x16, HDA_INPUT, 3 },
3202 { 0x16, HDA_INPUT, 4 },
3203 { } /* end */
3205 #endif
3207 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3209 struct via_spec *spec = codec->spec;
3210 int imux_is_smixer;
3211 unsigned int parm;
3212 int is_8ch = 0;
3213 if ((spec->codec_type != VT1708B_4CH) &&
3214 (codec->vendor_id != 0x11064397))
3215 is_8ch = 1;
3217 /* SW0 (17h) = stereo mixer */
3218 imux_is_smixer =
3219 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3220 == ((spec->codec_type == VT1708S) ? 5 : 0));
3221 /* inputs */
3222 /* PW 1/2/5 (1ah/1bh/1eh) */
3223 parm = AC_PWRST_D3;
3224 set_pin_power_state(codec, 0x1a, &parm);
3225 set_pin_power_state(codec, 0x1b, &parm);
3226 set_pin_power_state(codec, 0x1e, &parm);
3227 if (imux_is_smixer)
3228 parm = AC_PWRST_D0;
3229 /* SW0 (17h), AIW 0/1 (13h/14h) */
3230 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3231 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3232 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3234 /* outputs */
3235 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3236 parm = AC_PWRST_D3;
3237 set_pin_power_state(codec, 0x19, &parm);
3238 if (spec->smart51_enabled)
3239 set_pin_power_state(codec, 0x1b, &parm);
3240 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3241 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3243 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3244 if (is_8ch) {
3245 parm = AC_PWRST_D3;
3246 set_pin_power_state(codec, 0x22, &parm);
3247 if (spec->smart51_enabled)
3248 set_pin_power_state(codec, 0x1a, &parm);
3249 snd_hda_codec_write(codec, 0x26, 0,
3250 AC_VERB_SET_POWER_STATE, parm);
3251 snd_hda_codec_write(codec, 0x24, 0,
3252 AC_VERB_SET_POWER_STATE, parm);
3253 } else if (codec->vendor_id == 0x11064397) {
3254 /* PW7(23h), SW2(27h), AOW2(25h) */
3255 parm = AC_PWRST_D3;
3256 set_pin_power_state(codec, 0x23, &parm);
3257 if (spec->smart51_enabled)
3258 set_pin_power_state(codec, 0x1a, &parm);
3259 snd_hda_codec_write(codec, 0x27, 0,
3260 AC_VERB_SET_POWER_STATE, parm);
3261 snd_hda_codec_write(codec, 0x25, 0,
3262 AC_VERB_SET_POWER_STATE, parm);
3265 /* PW 3/4/7 (1ch/1dh/23h) */
3266 parm = AC_PWRST_D3;
3267 /* force to D0 for internal Speaker */
3268 set_pin_power_state(codec, 0x1c, &parm);
3269 set_pin_power_state(codec, 0x1d, &parm);
3270 if (is_8ch)
3271 set_pin_power_state(codec, 0x23, &parm);
3273 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3274 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3275 imux_is_smixer ? AC_PWRST_D0 : parm);
3276 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3277 if (is_8ch) {
3278 snd_hda_codec_write(codec, 0x25, 0,
3279 AC_VERB_SET_POWER_STATE, parm);
3280 snd_hda_codec_write(codec, 0x27, 0,
3281 AC_VERB_SET_POWER_STATE, parm);
3282 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3283 snd_hda_codec_write(codec, 0x25, 0,
3284 AC_VERB_SET_POWER_STATE, parm);
3287 static int patch_vt1708S(struct hda_codec *codec);
3288 static int patch_vt1708B_8ch(struct hda_codec *codec)
3290 struct via_spec *spec;
3291 int err;
3293 if (get_codec_type(codec) == VT1708BCE)
3294 return patch_vt1708S(codec);
3295 /* create a codec specific record */
3296 spec = via_new_spec(codec);
3297 if (spec == NULL)
3298 return -ENOMEM;
3300 /* automatic parse from the BIOS config */
3301 err = vt1708B_parse_auto_config(codec);
3302 if (err < 0) {
3303 via_free(codec);
3304 return err;
3305 } else if (!err) {
3306 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3307 "from BIOS. Using genenic mode...\n");
3310 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3311 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3313 spec->stream_name_analog = "VT1708B Analog";
3314 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3315 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3317 spec->stream_name_digital = "VT1708B Digital";
3318 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3319 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3321 if (!spec->adc_nids && spec->input_mux) {
3322 spec->adc_nids = vt1708B_adc_nids;
3323 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3324 get_mux_nids(codec);
3325 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3326 spec->num_mixers++;
3329 codec->patch_ops = via_patch_ops;
3331 codec->patch_ops.init = via_auto_init;
3332 codec->patch_ops.unsol_event = via_unsol_event;
3333 #ifdef CONFIG_SND_HDA_POWER_SAVE
3334 spec->loopback.amplist = vt1708B_loopbacks;
3335 #endif
3337 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3339 return 0;
3342 static int patch_vt1708B_4ch(struct hda_codec *codec)
3344 struct via_spec *spec;
3345 int err;
3347 /* create a codec specific record */
3348 spec = via_new_spec(codec);
3349 if (spec == NULL)
3350 return -ENOMEM;
3352 /* automatic parse from the BIOS config */
3353 err = vt1708B_parse_auto_config(codec);
3354 if (err < 0) {
3355 via_free(codec);
3356 return err;
3357 } else if (!err) {
3358 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3359 "from BIOS. Using genenic mode...\n");
3362 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3363 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3365 spec->stream_name_analog = "VT1708B Analog";
3366 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3367 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3369 spec->stream_name_digital = "VT1708B Digital";
3370 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3371 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3373 if (!spec->adc_nids && spec->input_mux) {
3374 spec->adc_nids = vt1708B_adc_nids;
3375 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3376 get_mux_nids(codec);
3377 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3378 spec->num_mixers++;
3381 codec->patch_ops = via_patch_ops;
3383 codec->patch_ops.init = via_auto_init;
3384 codec->patch_ops.unsol_event = via_unsol_event;
3385 #ifdef CONFIG_SND_HDA_POWER_SAVE
3386 spec->loopback.amplist = vt1708B_loopbacks;
3387 #endif
3389 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3391 return 0;
3394 /* Patch for VT1708S */
3396 /* capture mixer elements */
3397 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3398 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3399 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3400 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3401 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3402 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3403 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3404 HDA_INPUT),
3406 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3407 /* The multiple "Capture Source" controls confuse alsamixer
3408 * So call somewhat different..
3410 /* .name = "Capture Source", */
3411 .name = "Input Source",
3412 .count = 1,
3413 .info = via_mux_enum_info,
3414 .get = via_mux_enum_get,
3415 .put = via_mux_enum_put,
3417 { } /* end */
3420 static struct hda_verb vt1708S_volume_init_verbs[] = {
3421 /* Unmute ADC0-1 and set the default input to mic-in */
3422 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3423 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3425 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3426 * analog-loopback mixer widget */
3427 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3428 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3429 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3430 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3431 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3432 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3434 /* Setup default input of PW4 to MW0 */
3435 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3436 /* PW9, PW10 Output enable */
3437 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3438 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3439 /* Enable Mic Boost Volume backdoor */
3440 {0x1, 0xf98, 0x1},
3441 /* don't bybass mixer */
3442 {0x1, 0xf88, 0xc0},
3446 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3447 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3448 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3449 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3450 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3451 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3452 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3453 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3454 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3455 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3459 static struct hda_verb vt1705_uniwill_init_verbs[] = {
3460 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3461 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3462 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3463 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3464 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3465 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3466 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3467 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3471 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3472 .substreams = 2,
3473 .channels_min = 2,
3474 .channels_max = 8,
3475 .nid = 0x10, /* NID to query formats and rates */
3476 .ops = {
3477 .open = via_playback_pcm_open,
3478 .prepare = via_playback_multi_pcm_prepare,
3479 .cleanup = via_playback_multi_pcm_cleanup,
3480 .close = via_pcm_open_close
3484 static struct hda_pcm_stream vt1705_pcm_analog_playback = {
3485 .substreams = 2,
3486 .channels_min = 2,
3487 .channels_max = 6,
3488 .nid = 0x10, /* NID to query formats and rates */
3489 .ops = {
3490 .open = via_playback_pcm_open,
3491 .prepare = via_playback_multi_pcm_prepare,
3492 .cleanup = via_playback_multi_pcm_cleanup,
3493 .close = via_pcm_open_close
3497 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3498 .substreams = 2,
3499 .channels_min = 2,
3500 .channels_max = 2,
3501 .nid = 0x13, /* NID to query formats and rates */
3502 .ops = {
3503 .open = via_pcm_open_close,
3504 .prepare = via_capture_pcm_prepare,
3505 .cleanup = via_capture_pcm_cleanup,
3506 .close = via_pcm_open_close
3510 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3511 .substreams = 1,
3512 .channels_min = 2,
3513 .channels_max = 2,
3514 /* NID is set in via_build_pcms */
3515 .ops = {
3516 .open = via_dig_playback_pcm_open,
3517 .close = via_dig_playback_pcm_close,
3518 .prepare = via_dig_playback_pcm_prepare,
3519 .cleanup = via_dig_playback_pcm_cleanup
3523 /* fill in the dac_nids table from the parsed pin configuration */
3524 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3525 const struct auto_pin_cfg *cfg)
3527 int i;
3528 hda_nid_t nid;
3530 spec->multiout.num_dacs = cfg->line_outs;
3532 spec->multiout.dac_nids = spec->private_dac_nids;
3534 for (i = 0; i < 4; i++) {
3535 nid = cfg->line_out_pins[i];
3536 if (nid) {
3537 /* config dac list */
3538 switch (i) {
3539 case AUTO_SEQ_FRONT:
3540 spec->multiout.dac_nids[i] = 0x10;
3541 break;
3542 case AUTO_SEQ_CENLFE:
3543 if (spec->codec->vendor_id == 0x11064397)
3544 spec->multiout.dac_nids[i] = 0x25;
3545 else
3546 spec->multiout.dac_nids[i] = 0x24;
3547 break;
3548 case AUTO_SEQ_SURROUND:
3549 spec->multiout.dac_nids[i] = 0x11;
3550 break;
3551 case AUTO_SEQ_SIDE:
3552 spec->multiout.dac_nids[i] = 0x25;
3553 break;
3558 /* for Smart 5.1, line/mic inputs double as output pins */
3559 if (cfg->line_outs == 1) {
3560 spec->multiout.num_dacs = 3;
3561 spec->multiout.dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3562 if (spec->codec->vendor_id == 0x11064397)
3563 spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x25;
3564 else
3565 spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3568 return 0;
3571 /* add playback controls from the parsed DAC table */
3572 static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
3573 const struct auto_pin_cfg *cfg)
3575 struct via_spec *spec = codec->spec;
3576 char name[32];
3577 static const char * const chname[4] = {
3578 "Front", "Surround", "C/LFE", "Side"
3580 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3581 {0x10, 0x11, 0x25, 0} };
3582 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3583 {0x1C, 0x18, 0x27, 0} };
3584 hda_nid_t nid, nid_vol, nid_mute;
3585 int i, err;
3587 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3588 nid = cfg->line_out_pins[i];
3590 /* for Smart 5.1, there are always at least six channels */
3591 if (!nid && i > AUTO_SEQ_CENLFE)
3592 continue;
3594 if (codec->vendor_id == 0x11064397) {
3595 nid_vol = nid_vols[1][i];
3596 nid_mute = nid_mutes[1][i];
3597 } else {
3598 nid_vol = nid_vols[0][i];
3599 nid_mute = nid_mutes[0][i];
3601 if (!nid_vol && !nid_mute)
3602 continue;
3604 if (i == AUTO_SEQ_CENLFE) {
3605 /* Center/LFE */
3606 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3607 "Center Playback Volume",
3608 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3609 HDA_OUTPUT));
3610 if (err < 0)
3611 return err;
3612 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3613 "LFE Playback Volume",
3614 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3615 HDA_OUTPUT));
3616 if (err < 0)
3617 return err;
3618 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3619 "Center Playback Switch",
3620 HDA_COMPOSE_AMP_VAL(nid_mute,
3621 1, 0,
3622 HDA_OUTPUT));
3623 if (err < 0)
3624 return err;
3625 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3626 "LFE Playback Switch",
3627 HDA_COMPOSE_AMP_VAL(nid_mute,
3628 2, 0,
3629 HDA_OUTPUT));
3630 if (err < 0)
3631 return err;
3632 } else if (i == AUTO_SEQ_FRONT) {
3633 /* add control to mixer index 0 */
3634 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3635 "Master Front Playback Volume",
3636 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3637 HDA_INPUT));
3638 if (err < 0)
3639 return err;
3640 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3641 "Master Front Playback Switch",
3642 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3643 HDA_INPUT));
3644 if (err < 0)
3645 return err;
3647 /* Front */
3648 sprintf(name, "%s Playback Volume", chname[i]);
3649 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3650 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3651 HDA_OUTPUT));
3652 if (err < 0)
3653 return err;
3654 sprintf(name, "%s Playback Switch", chname[i]);
3655 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3656 HDA_COMPOSE_AMP_VAL(nid_mute,
3657 3, 0,
3658 HDA_OUTPUT));
3659 if (err < 0)
3660 return err;
3661 } else {
3662 sprintf(name, "%s Playback Volume", chname[i]);
3663 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3664 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3665 HDA_OUTPUT));
3666 if (err < 0)
3667 return err;
3668 sprintf(name, "%s Playback Switch", chname[i]);
3669 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3670 HDA_COMPOSE_AMP_VAL(nid_mute,
3671 3, 0,
3672 HDA_OUTPUT));
3673 if (err < 0)
3674 return err;
3678 return 0;
3681 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3683 int err;
3685 if (!pin)
3686 return 0;
3688 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3689 spec->hp_independent_mode_index = 1;
3691 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3692 "Headphone Playback Volume",
3693 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3694 if (err < 0)
3695 return err;
3697 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3698 "Headphone Playback Switch",
3699 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3700 if (err < 0)
3701 return err;
3703 create_hp_imux(spec);
3705 return 0;
3708 /* create playback/capture controls for input pins */
3709 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
3710 const struct auto_pin_cfg *cfg)
3712 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
3713 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3714 ARRAY_SIZE(pin_idxs));
3717 /* fill out digital output widgets; one for master and one for slave outputs */
3718 static void fill_dig_outs(struct hda_codec *codec)
3720 struct via_spec *spec = codec->spec;
3721 int i;
3723 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3724 hda_nid_t nid;
3725 int conn;
3727 nid = spec->autocfg.dig_out_pins[i];
3728 if (!nid)
3729 continue;
3730 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3731 if (conn < 1)
3732 continue;
3733 if (!spec->multiout.dig_out_nid)
3734 spec->multiout.dig_out_nid = nid;
3735 else {
3736 spec->slave_dig_outs[0] = nid;
3737 break; /* at most two dig outs */
3742 static int vt1708S_parse_auto_config(struct hda_codec *codec)
3744 struct via_spec *spec = codec->spec;
3745 int err;
3747 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3748 if (err < 0)
3749 return err;
3750 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3751 if (err < 0)
3752 return err;
3753 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3754 return 0; /* can't find valid BIOS pin config */
3756 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
3757 if (err < 0)
3758 return err;
3759 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3760 if (err < 0)
3761 return err;
3762 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
3763 if (err < 0)
3764 return err;
3766 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3768 fill_dig_outs(codec);
3770 if (spec->kctls.list)
3771 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3773 spec->input_mux = &spec->private_imux[0];
3775 if (spec->hp_mux)
3776 via_hp_build(codec);
3778 via_smart51_build(spec);
3779 return 1;
3782 #ifdef CONFIG_SND_HDA_POWER_SAVE
3783 static struct hda_amp_list vt1708S_loopbacks[] = {
3784 { 0x16, HDA_INPUT, 1 },
3785 { 0x16, HDA_INPUT, 2 },
3786 { 0x16, HDA_INPUT, 3 },
3787 { 0x16, HDA_INPUT, 4 },
3788 { } /* end */
3790 #endif
3792 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3793 int offset, int num_steps, int step_size)
3795 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3796 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3797 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3798 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3799 (0 << AC_AMPCAP_MUTE_SHIFT));
3802 static int patch_vt1708S(struct hda_codec *codec)
3804 struct via_spec *spec;
3805 int err;
3807 /* create a codec specific record */
3808 spec = via_new_spec(codec);
3809 if (spec == NULL)
3810 return -ENOMEM;
3812 /* automatic parse from the BIOS config */
3813 err = vt1708S_parse_auto_config(codec);
3814 if (err < 0) {
3815 via_free(codec);
3816 return err;
3817 } else if (!err) {
3818 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3819 "from BIOS. Using genenic mode...\n");
3822 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
3823 if (codec->vendor_id == 0x11064397)
3824 spec->init_verbs[spec->num_iverbs++] =
3825 vt1705_uniwill_init_verbs;
3826 else
3827 spec->init_verbs[spec->num_iverbs++] =
3828 vt1708S_uniwill_init_verbs;
3830 if (codec->vendor_id == 0x11060440)
3831 spec->stream_name_analog = "VT1818S Analog";
3832 else if (codec->vendor_id == 0x11064397)
3833 spec->stream_name_analog = "VT1705 Analog";
3834 else
3835 spec->stream_name_analog = "VT1708S Analog";
3836 if (codec->vendor_id == 0x11064397)
3837 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3838 else
3839 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
3840 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3842 if (codec->vendor_id == 0x11060440)
3843 spec->stream_name_digital = "VT1818S Digital";
3844 else if (codec->vendor_id == 0x11064397)
3845 spec->stream_name_digital = "VT1705 Digital";
3846 else
3847 spec->stream_name_digital = "VT1708S Digital";
3848 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3850 if (!spec->adc_nids && spec->input_mux) {
3851 spec->adc_nids = vt1708S_adc_nids;
3852 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
3853 get_mux_nids(codec);
3854 override_mic_boost(codec, 0x1a, 0, 3, 40);
3855 override_mic_boost(codec, 0x1e, 0, 3, 40);
3856 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3857 spec->num_mixers++;
3860 codec->patch_ops = via_patch_ops;
3862 codec->patch_ops.init = via_auto_init;
3863 codec->patch_ops.unsol_event = via_unsol_event;
3864 #ifdef CONFIG_SND_HDA_POWER_SAVE
3865 spec->loopback.amplist = vt1708S_loopbacks;
3866 #endif
3868 /* correct names for VT1708BCE */
3869 if (get_codec_type(codec) == VT1708BCE) {
3870 kfree(codec->chip_name);
3871 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3872 snprintf(codec->bus->card->mixername,
3873 sizeof(codec->bus->card->mixername),
3874 "%s %s", codec->vendor_name, codec->chip_name);
3875 spec->stream_name_analog = "VT1708BCE Analog";
3876 spec->stream_name_digital = "VT1708BCE Digital";
3878 /* correct names for VT1818S */
3879 if (codec->vendor_id == 0x11060440) {
3880 spec->stream_name_analog = "VT1818S Analog";
3881 spec->stream_name_digital = "VT1818S Digital";
3883 /* correct names for VT1705 */
3884 if (codec->vendor_id == 0x11064397) {
3885 kfree(codec->chip_name);
3886 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3887 snprintf(codec->bus->card->mixername,
3888 sizeof(codec->bus->card->mixername),
3889 "%s %s", codec->vendor_name, codec->chip_name);
3891 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3892 return 0;
3895 /* Patch for VT1702 */
3897 /* capture mixer elements */
3898 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
3899 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3900 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3901 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3902 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3903 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3904 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3905 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3906 HDA_INPUT),
3908 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3909 /* The multiple "Capture Source" controls confuse alsamixer
3910 * So call somewhat different..
3912 /* .name = "Capture Source", */
3913 .name = "Input Source",
3914 .count = 1,
3915 .info = via_mux_enum_info,
3916 .get = via_mux_enum_get,
3917 .put = via_mux_enum_put,
3919 { } /* end */
3922 static struct hda_verb vt1702_volume_init_verbs[] = {
3924 * Unmute ADC0-1 and set the default input to mic-in
3926 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3927 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3928 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3931 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3932 * mixer widget
3934 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3935 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3936 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3937 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3938 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3939 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3941 /* Setup default input of PW4 to MW0 */
3942 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3943 /* PW6 PW7 Output enable */
3944 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3945 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3946 /* mixer enable */
3947 {0x1, 0xF88, 0x3},
3948 /* GPIO 0~2 */
3949 {0x1, 0xF82, 0x3F},
3953 static struct hda_verb vt1702_uniwill_init_verbs[] = {
3954 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3955 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3956 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3957 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3958 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3959 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3963 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
3964 .substreams = 2,
3965 .channels_min = 2,
3966 .channels_max = 2,
3967 .nid = 0x10, /* NID to query formats and rates */
3968 .ops = {
3969 .open = via_playback_pcm_open,
3970 .prepare = via_playback_multi_pcm_prepare,
3971 .cleanup = via_playback_multi_pcm_cleanup,
3972 .close = via_pcm_open_close
3976 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
3977 .substreams = 3,
3978 .channels_min = 2,
3979 .channels_max = 2,
3980 .nid = 0x12, /* NID to query formats and rates */
3981 .ops = {
3982 .open = via_pcm_open_close,
3983 .prepare = via_capture_pcm_prepare,
3984 .cleanup = via_capture_pcm_cleanup,
3985 .close = via_pcm_open_close
3989 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
3990 .substreams = 2,
3991 .channels_min = 2,
3992 .channels_max = 2,
3993 /* NID is set in via_build_pcms */
3994 .ops = {
3995 .open = via_dig_playback_pcm_open,
3996 .close = via_dig_playback_pcm_close,
3997 .prepare = via_dig_playback_pcm_prepare,
3998 .cleanup = via_dig_playback_pcm_cleanup
4002 /* fill in the dac_nids table from the parsed pin configuration */
4003 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4004 const struct auto_pin_cfg *cfg)
4006 spec->multiout.num_dacs = 1;
4007 spec->multiout.dac_nids = spec->private_dac_nids;
4009 if (cfg->line_out_pins[0]) {
4010 /* config dac list */
4011 spec->multiout.dac_nids[0] = 0x10;
4014 return 0;
4017 /* add playback controls from the parsed DAC table */
4018 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4019 const struct auto_pin_cfg *cfg)
4021 int err;
4023 if (!cfg->line_out_pins[0])
4024 return -1;
4026 /* add control to mixer index 0 */
4027 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4028 "Master Front Playback Volume",
4029 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4030 if (err < 0)
4031 return err;
4032 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4033 "Master Front Playback Switch",
4034 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4035 if (err < 0)
4036 return err;
4038 /* Front */
4039 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4040 "Front Playback Volume",
4041 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4042 if (err < 0)
4043 return err;
4044 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4045 "Front Playback Switch",
4046 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4047 if (err < 0)
4048 return err;
4050 return 0;
4053 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4055 int err, i;
4056 struct hda_input_mux *imux;
4057 static const char * const texts[] = { "ON", "OFF", NULL};
4058 if (!pin)
4059 return 0;
4060 spec->multiout.hp_nid = 0x1D;
4061 spec->hp_independent_mode_index = 0;
4063 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4064 "Headphone Playback Volume",
4065 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4066 if (err < 0)
4067 return err;
4069 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4070 "Headphone Playback Switch",
4071 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4072 if (err < 0)
4073 return err;
4075 imux = &spec->private_imux[1];
4077 /* for hp mode select */
4078 for (i = 0; texts[i]; i++)
4079 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4081 spec->hp_mux = &spec->private_imux[1];
4082 return 0;
4085 /* create playback/capture controls for input pins */
4086 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4087 const struct auto_pin_cfg *cfg)
4089 static hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4090 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
4091 ARRAY_SIZE(pin_idxs));
4094 static int vt1702_parse_auto_config(struct hda_codec *codec)
4096 struct via_spec *spec = codec->spec;
4097 int err;
4099 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4100 if (err < 0)
4101 return err;
4102 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4103 if (err < 0)
4104 return err;
4105 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4106 return 0; /* can't find valid BIOS pin config */
4108 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4109 if (err < 0)
4110 return err;
4111 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4112 if (err < 0)
4113 return err;
4114 /* limit AA path volume to 0 dB */
4115 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4116 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4117 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4118 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4119 (1 << AC_AMPCAP_MUTE_SHIFT));
4120 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4121 if (err < 0)
4122 return err;
4124 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4126 fill_dig_outs(codec);
4128 if (spec->kctls.list)
4129 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4131 spec->input_mux = &spec->private_imux[0];
4133 if (spec->hp_mux)
4134 via_hp_build(codec);
4136 return 1;
4139 #ifdef CONFIG_SND_HDA_POWER_SAVE
4140 static struct hda_amp_list vt1702_loopbacks[] = {
4141 { 0x1A, HDA_INPUT, 1 },
4142 { 0x1A, HDA_INPUT, 2 },
4143 { 0x1A, HDA_INPUT, 3 },
4144 { 0x1A, HDA_INPUT, 4 },
4145 { } /* end */
4147 #endif
4149 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4151 int imux_is_smixer =
4152 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4153 unsigned int parm;
4154 /* inputs */
4155 /* PW 1/2/5 (14h/15h/18h) */
4156 parm = AC_PWRST_D3;
4157 set_pin_power_state(codec, 0x14, &parm);
4158 set_pin_power_state(codec, 0x15, &parm);
4159 set_pin_power_state(codec, 0x18, &parm);
4160 if (imux_is_smixer)
4161 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4162 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4163 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4164 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4165 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4166 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4168 /* outputs */
4169 /* PW 3/4 (16h/17h) */
4170 parm = AC_PWRST_D3;
4171 set_pin_power_state(codec, 0x17, &parm);
4172 set_pin_power_state(codec, 0x16, &parm);
4173 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4174 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4175 imux_is_smixer ? AC_PWRST_D0 : parm);
4176 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4177 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4180 static int patch_vt1702(struct hda_codec *codec)
4182 struct via_spec *spec;
4183 int err;
4185 /* create a codec specific record */
4186 spec = via_new_spec(codec);
4187 if (spec == NULL)
4188 return -ENOMEM;
4190 /* automatic parse from the BIOS config */
4191 err = vt1702_parse_auto_config(codec);
4192 if (err < 0) {
4193 via_free(codec);
4194 return err;
4195 } else if (!err) {
4196 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4197 "from BIOS. Using genenic mode...\n");
4200 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4201 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4203 spec->stream_name_analog = "VT1702 Analog";
4204 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4205 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4207 spec->stream_name_digital = "VT1702 Digital";
4208 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4210 if (!spec->adc_nids && spec->input_mux) {
4211 spec->adc_nids = vt1702_adc_nids;
4212 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4213 get_mux_nids(codec);
4214 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4215 spec->num_mixers++;
4218 codec->patch_ops = via_patch_ops;
4220 codec->patch_ops.init = via_auto_init;
4221 codec->patch_ops.unsol_event = via_unsol_event;
4222 #ifdef CONFIG_SND_HDA_POWER_SAVE
4223 spec->loopback.amplist = vt1702_loopbacks;
4224 #endif
4226 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
4227 return 0;
4230 /* Patch for VT1718S */
4232 /* capture mixer elements */
4233 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4234 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4235 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4236 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4237 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4238 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4239 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4240 HDA_INPUT),
4242 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4243 /* The multiple "Capture Source" controls confuse alsamixer
4244 * So call somewhat different..
4246 .name = "Input Source",
4247 .count = 2,
4248 .info = via_mux_enum_info,
4249 .get = via_mux_enum_get,
4250 .put = via_mux_enum_put,
4252 { } /* end */
4255 static struct hda_verb vt1718S_volume_init_verbs[] = {
4257 * Unmute ADC0-1 and set the default input to mic-in
4259 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4260 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4262 /* Enable MW0 adjust Gain 5 */
4263 {0x1, 0xfb2, 0x10},
4264 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4265 * mixer widget
4267 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4268 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4269 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4270 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4271 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4272 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
4274 /* Setup default input of Front HP to MW9 */
4275 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4276 /* PW9 PW10 Output enable */
4277 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4278 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4279 /* PW11 Input enable */
4280 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4281 /* Enable Boost Volume backdoor */
4282 {0x1, 0xf88, 0x8},
4283 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4284 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4285 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4286 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4287 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4288 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4289 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4290 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4291 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4292 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4293 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4294 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4295 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4296 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4297 /* Unmute MW4's index 0 */
4298 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4303 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4304 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4305 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4306 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4307 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4308 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4309 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4310 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4311 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4312 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4316 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4317 .substreams = 2,
4318 .channels_min = 2,
4319 .channels_max = 10,
4320 .nid = 0x8, /* NID to query formats and rates */
4321 .ops = {
4322 .open = via_playback_pcm_open,
4323 .prepare = via_playback_multi_pcm_prepare,
4324 .cleanup = via_playback_multi_pcm_cleanup,
4325 .close = via_pcm_open_close,
4329 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4330 .substreams = 2,
4331 .channels_min = 2,
4332 .channels_max = 2,
4333 .nid = 0x10, /* NID to query formats and rates */
4334 .ops = {
4335 .open = via_pcm_open_close,
4336 .prepare = via_capture_pcm_prepare,
4337 .cleanup = via_capture_pcm_cleanup,
4338 .close = via_pcm_open_close,
4342 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4343 .substreams = 2,
4344 .channels_min = 2,
4345 .channels_max = 2,
4346 /* NID is set in via_build_pcms */
4347 .ops = {
4348 .open = via_dig_playback_pcm_open,
4349 .close = via_dig_playback_pcm_close,
4350 .prepare = via_dig_playback_pcm_prepare,
4351 .cleanup = via_dig_playback_pcm_cleanup
4355 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4356 .substreams = 1,
4357 .channels_min = 2,
4358 .channels_max = 2,
4361 /* fill in the dac_nids table from the parsed pin configuration */
4362 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4363 const struct auto_pin_cfg *cfg)
4365 int i;
4366 hda_nid_t nid;
4368 spec->multiout.num_dacs = cfg->line_outs;
4370 spec->multiout.dac_nids = spec->private_dac_nids;
4372 for (i = 0; i < 4; i++) {
4373 nid = cfg->line_out_pins[i];
4374 if (nid) {
4375 /* config dac list */
4376 switch (i) {
4377 case AUTO_SEQ_FRONT:
4378 spec->multiout.dac_nids[i] = 0x8;
4379 break;
4380 case AUTO_SEQ_CENLFE:
4381 spec->multiout.dac_nids[i] = 0xa;
4382 break;
4383 case AUTO_SEQ_SURROUND:
4384 spec->multiout.dac_nids[i] = 0x9;
4385 break;
4386 case AUTO_SEQ_SIDE:
4387 spec->multiout.dac_nids[i] = 0xb;
4388 break;
4393 return 0;
4396 /* add playback controls from the parsed DAC table */
4397 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4398 const struct auto_pin_cfg *cfg)
4400 char name[32];
4401 static const char * const chname[4] = {
4402 "Front", "Surround", "C/LFE", "Side"
4404 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4405 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4406 hda_nid_t nid, nid_vol, nid_mute = 0;
4407 int i, err;
4409 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4410 nid = cfg->line_out_pins[i];
4412 if (!nid)
4413 continue;
4414 nid_vol = nid_vols[i];
4415 nid_mute = nid_mutes[i];
4417 if (i == AUTO_SEQ_CENLFE) {
4418 /* Center/LFE */
4419 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4420 "Center Playback Volume",
4421 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4422 HDA_OUTPUT));
4423 if (err < 0)
4424 return err;
4425 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4426 "LFE Playback Volume",
4427 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4428 HDA_OUTPUT));
4429 if (err < 0)
4430 return err;
4431 err = via_add_control(
4432 spec, VIA_CTL_WIDGET_MUTE,
4433 "Center Playback Switch",
4434 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4435 HDA_OUTPUT));
4436 if (err < 0)
4437 return err;
4438 err = via_add_control(
4439 spec, VIA_CTL_WIDGET_MUTE,
4440 "LFE Playback Switch",
4441 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4442 HDA_OUTPUT));
4443 if (err < 0)
4444 return err;
4445 } else if (i == AUTO_SEQ_FRONT) {
4446 /* Front */
4447 sprintf(name, "%s Playback Volume", chname[i]);
4448 err = via_add_control(
4449 spec, VIA_CTL_WIDGET_VOL, name,
4450 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4451 if (err < 0)
4452 return err;
4453 sprintf(name, "%s Playback Switch", chname[i]);
4454 err = via_add_control(
4455 spec, VIA_CTL_WIDGET_MUTE, name,
4456 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4457 HDA_OUTPUT));
4458 if (err < 0)
4459 return err;
4460 } else {
4461 sprintf(name, "%s Playback Volume", chname[i]);
4462 err = via_add_control(
4463 spec, VIA_CTL_WIDGET_VOL, name,
4464 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4465 if (err < 0)
4466 return err;
4467 sprintf(name, "%s Playback Switch", chname[i]);
4468 err = via_add_control(
4469 spec, VIA_CTL_WIDGET_MUTE, name,
4470 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4471 HDA_OUTPUT));
4472 if (err < 0)
4473 return err;
4476 return 0;
4479 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4481 int err;
4483 if (!pin)
4484 return 0;
4486 spec->multiout.hp_nid = 0xc; /* AOW4 */
4487 spec->hp_independent_mode_index = 1;
4489 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4490 "Headphone Playback Volume",
4491 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4492 if (err < 0)
4493 return err;
4495 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4496 "Headphone Playback Switch",
4497 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4498 if (err < 0)
4499 return err;
4501 create_hp_imux(spec);
4502 return 0;
4505 /* create playback/capture controls for input pins */
4506 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4507 const struct auto_pin_cfg *cfg)
4509 static hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4510 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
4511 ARRAY_SIZE(pin_idxs));
4514 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4516 struct via_spec *spec = codec->spec;
4517 int err;
4519 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4521 if (err < 0)
4522 return err;
4523 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4524 if (err < 0)
4525 return err;
4526 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4527 return 0; /* can't find valid BIOS pin config */
4529 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4530 if (err < 0)
4531 return err;
4532 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4533 if (err < 0)
4534 return err;
4535 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4536 if (err < 0)
4537 return err;
4539 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4541 fill_dig_outs(codec);
4543 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4544 spec->dig_in_nid = 0x13;
4546 if (spec->kctls.list)
4547 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4549 spec->input_mux = &spec->private_imux[0];
4551 if (spec->hp_mux)
4552 via_hp_build(codec);
4554 via_smart51_build(spec);
4556 return 1;
4559 #ifdef CONFIG_SND_HDA_POWER_SAVE
4560 static struct hda_amp_list vt1718S_loopbacks[] = {
4561 { 0x21, HDA_INPUT, 1 },
4562 { 0x21, HDA_INPUT, 2 },
4563 { 0x21, HDA_INPUT, 3 },
4564 { 0x21, HDA_INPUT, 4 },
4565 { } /* end */
4567 #endif
4569 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4571 struct via_spec *spec = codec->spec;
4572 int imux_is_smixer;
4573 unsigned int parm;
4574 /* MUX6 (1eh) = stereo mixer */
4575 imux_is_smixer =
4576 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4577 /* inputs */
4578 /* PW 5/6/7 (29h/2ah/2bh) */
4579 parm = AC_PWRST_D3;
4580 set_pin_power_state(codec, 0x29, &parm);
4581 set_pin_power_state(codec, 0x2a, &parm);
4582 set_pin_power_state(codec, 0x2b, &parm);
4583 if (imux_is_smixer)
4584 parm = AC_PWRST_D0;
4585 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4586 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4587 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4588 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4589 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4591 /* outputs */
4592 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4593 parm = AC_PWRST_D3;
4594 set_pin_power_state(codec, 0x27, &parm);
4595 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4596 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4598 /* PW2 (26h), AOW2 (ah) */
4599 parm = AC_PWRST_D3;
4600 set_pin_power_state(codec, 0x26, &parm);
4601 if (spec->smart51_enabled)
4602 set_pin_power_state(codec, 0x2b, &parm);
4603 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4605 /* PW0 (24h), AOW0 (8h) */
4606 parm = AC_PWRST_D3;
4607 set_pin_power_state(codec, 0x24, &parm);
4608 if (!spec->hp_independent_mode) /* check for redirected HP */
4609 set_pin_power_state(codec, 0x28, &parm);
4610 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4611 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4612 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4613 imux_is_smixer ? AC_PWRST_D0 : parm);
4615 /* PW1 (25h), AOW1 (9h) */
4616 parm = AC_PWRST_D3;
4617 set_pin_power_state(codec, 0x25, &parm);
4618 if (spec->smart51_enabled)
4619 set_pin_power_state(codec, 0x2a, &parm);
4620 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4622 if (spec->hp_independent_mode) {
4623 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4624 parm = AC_PWRST_D3;
4625 set_pin_power_state(codec, 0x28, &parm);
4626 snd_hda_codec_write(codec, 0x1b, 0,
4627 AC_VERB_SET_POWER_STATE, parm);
4628 snd_hda_codec_write(codec, 0x34, 0,
4629 AC_VERB_SET_POWER_STATE, parm);
4630 snd_hda_codec_write(codec, 0xc, 0,
4631 AC_VERB_SET_POWER_STATE, parm);
4635 static int patch_vt1718S(struct hda_codec *codec)
4637 struct via_spec *spec;
4638 int err;
4640 /* create a codec specific record */
4641 spec = via_new_spec(codec);
4642 if (spec == NULL)
4643 return -ENOMEM;
4645 /* automatic parse from the BIOS config */
4646 err = vt1718S_parse_auto_config(codec);
4647 if (err < 0) {
4648 via_free(codec);
4649 return err;
4650 } else if (!err) {
4651 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4652 "from BIOS. Using genenic mode...\n");
4655 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4656 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4658 if (codec->vendor_id == 0x11060441)
4659 spec->stream_name_analog = "VT2020 Analog";
4660 else if (codec->vendor_id == 0x11064441)
4661 spec->stream_name_analog = "VT1828S Analog";
4662 else
4663 spec->stream_name_analog = "VT1718S Analog";
4664 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4665 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4667 if (codec->vendor_id == 0x11060441)
4668 spec->stream_name_digital = "VT2020 Digital";
4669 else if (codec->vendor_id == 0x11064441)
4670 spec->stream_name_digital = "VT1828S Digital";
4671 else
4672 spec->stream_name_digital = "VT1718S Digital";
4673 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4674 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4675 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4677 if (!spec->adc_nids && spec->input_mux) {
4678 spec->adc_nids = vt1718S_adc_nids;
4679 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4680 get_mux_nids(codec);
4681 override_mic_boost(codec, 0x2b, 0, 3, 40);
4682 override_mic_boost(codec, 0x29, 0, 3, 40);
4683 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4684 spec->num_mixers++;
4687 codec->patch_ops = via_patch_ops;
4689 codec->patch_ops.init = via_auto_init;
4690 codec->patch_ops.unsol_event = via_unsol_event;
4692 #ifdef CONFIG_SND_HDA_POWER_SAVE
4693 spec->loopback.amplist = vt1718S_loopbacks;
4694 #endif
4696 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4698 return 0;
4701 /* Patch for VT1716S */
4703 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4704 struct snd_ctl_elem_info *uinfo)
4706 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4707 uinfo->count = 1;
4708 uinfo->value.integer.min = 0;
4709 uinfo->value.integer.max = 1;
4710 return 0;
4713 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4714 struct snd_ctl_elem_value *ucontrol)
4716 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4717 int index = 0;
4719 index = snd_hda_codec_read(codec, 0x26, 0,
4720 AC_VERB_GET_CONNECT_SEL, 0);
4721 if (index != -1)
4722 *ucontrol->value.integer.value = index;
4724 return 0;
4727 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4728 struct snd_ctl_elem_value *ucontrol)
4730 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4731 struct via_spec *spec = codec->spec;
4732 int index = *ucontrol->value.integer.value;
4734 snd_hda_codec_write(codec, 0x26, 0,
4735 AC_VERB_SET_CONNECT_SEL, index);
4736 spec->dmic_enabled = index;
4737 set_widgets_power_state(codec);
4738 return 1;
4741 /* capture mixer elements */
4742 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4743 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4744 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4745 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4746 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4747 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4748 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4749 HDA_INPUT),
4751 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4752 .name = "Input Source",
4753 .count = 1,
4754 .info = via_mux_enum_info,
4755 .get = via_mux_enum_get,
4756 .put = via_mux_enum_put,
4758 { } /* end */
4761 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4762 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4764 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4765 .name = "Digital Mic Capture Switch",
4766 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4767 .count = 1,
4768 .info = vt1716s_dmic_info,
4769 .get = vt1716s_dmic_get,
4770 .put = vt1716s_dmic_put,
4772 {} /* end */
4776 /* mono-out mixer elements */
4777 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4778 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4779 { } /* end */
4782 static struct hda_verb vt1716S_volume_init_verbs[] = {
4784 * Unmute ADC0-1 and set the default input to mic-in
4786 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4787 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4790 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4791 * mixer widget
4793 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4794 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4795 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4796 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4797 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4798 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4800 /* MUX Indices: Stereo Mixer = 5 */
4801 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4803 /* Setup default input of PW4 to MW0 */
4804 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4806 /* Setup default input of SW1 as MW0 */
4807 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4809 /* Setup default input of SW4 as AOW0 */
4810 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4812 /* PW9 PW10 Output enable */
4813 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4814 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4816 /* Unmute SW1, PW12 */
4817 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4818 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4819 /* PW12 Output enable */
4820 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4821 /* Enable Boost Volume backdoor */
4822 {0x1, 0xf8a, 0x80},
4823 /* don't bybass mixer */
4824 {0x1, 0xf88, 0xc0},
4825 /* Enable mono output */
4826 {0x1, 0xf90, 0x08},
4831 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
4832 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4833 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4834 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4835 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4836 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4837 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4838 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4839 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4840 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4844 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
4845 .substreams = 2,
4846 .channels_min = 2,
4847 .channels_max = 6,
4848 .nid = 0x10, /* NID to query formats and rates */
4849 .ops = {
4850 .open = via_playback_pcm_open,
4851 .prepare = via_playback_multi_pcm_prepare,
4852 .cleanup = via_playback_multi_pcm_cleanup,
4853 .close = via_pcm_open_close,
4857 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
4858 .substreams = 2,
4859 .channels_min = 2,
4860 .channels_max = 2,
4861 .nid = 0x13, /* NID to query formats and rates */
4862 .ops = {
4863 .open = via_pcm_open_close,
4864 .prepare = via_capture_pcm_prepare,
4865 .cleanup = via_capture_pcm_cleanup,
4866 .close = via_pcm_open_close,
4870 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
4871 .substreams = 2,
4872 .channels_min = 2,
4873 .channels_max = 2,
4874 /* NID is set in via_build_pcms */
4875 .ops = {
4876 .open = via_dig_playback_pcm_open,
4877 .close = via_dig_playback_pcm_close,
4878 .prepare = via_dig_playback_pcm_prepare,
4879 .cleanup = via_dig_playback_pcm_cleanup
4883 /* fill in the dac_nids table from the parsed pin configuration */
4884 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4885 const struct auto_pin_cfg *cfg)
4886 { int i;
4887 hda_nid_t nid;
4889 spec->multiout.num_dacs = cfg->line_outs;
4891 spec->multiout.dac_nids = spec->private_dac_nids;
4893 for (i = 0; i < 3; i++) {
4894 nid = cfg->line_out_pins[i];
4895 if (nid) {
4896 /* config dac list */
4897 switch (i) {
4898 case AUTO_SEQ_FRONT:
4899 spec->multiout.dac_nids[i] = 0x10;
4900 break;
4901 case AUTO_SEQ_CENLFE:
4902 spec->multiout.dac_nids[i] = 0x25;
4903 break;
4904 case AUTO_SEQ_SURROUND:
4905 spec->multiout.dac_nids[i] = 0x11;
4906 break;
4911 return 0;
4914 /* add playback controls from the parsed DAC table */
4915 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4916 const struct auto_pin_cfg *cfg)
4918 char name[32];
4919 static const char * const chname[3] = {
4920 "Front", "Surround", "C/LFE"
4922 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4923 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4924 hda_nid_t nid, nid_vol, nid_mute;
4925 int i, err;
4927 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4928 nid = cfg->line_out_pins[i];
4930 if (!nid)
4931 continue;
4933 nid_vol = nid_vols[i];
4934 nid_mute = nid_mutes[i];
4936 if (i == AUTO_SEQ_CENLFE) {
4937 err = via_add_control(
4938 spec, VIA_CTL_WIDGET_VOL,
4939 "Center Playback Volume",
4940 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
4941 if (err < 0)
4942 return err;
4943 err = via_add_control(
4944 spec, VIA_CTL_WIDGET_VOL,
4945 "LFE Playback Volume",
4946 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
4947 if (err < 0)
4948 return err;
4949 err = via_add_control(
4950 spec, VIA_CTL_WIDGET_MUTE,
4951 "Center Playback Switch",
4952 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4953 HDA_OUTPUT));
4954 if (err < 0)
4955 return err;
4956 err = via_add_control(
4957 spec, VIA_CTL_WIDGET_MUTE,
4958 "LFE Playback Switch",
4959 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4960 HDA_OUTPUT));
4961 if (err < 0)
4962 return err;
4963 } else if (i == AUTO_SEQ_FRONT) {
4965 err = via_add_control(
4966 spec, VIA_CTL_WIDGET_VOL,
4967 "Master Front Playback Volume",
4968 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4969 if (err < 0)
4970 return err;
4971 err = via_add_control(
4972 spec, VIA_CTL_WIDGET_MUTE,
4973 "Master Front Playback Switch",
4974 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4975 if (err < 0)
4976 return err;
4978 sprintf(name, "%s Playback Volume", chname[i]);
4979 err = via_add_control(
4980 spec, VIA_CTL_WIDGET_VOL, name,
4981 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4982 if (err < 0)
4983 return err;
4984 sprintf(name, "%s Playback Switch", chname[i]);
4985 err = via_add_control(
4986 spec, VIA_CTL_WIDGET_MUTE, name,
4987 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4988 HDA_OUTPUT));
4989 if (err < 0)
4990 return err;
4991 } else {
4992 sprintf(name, "%s Playback Volume", chname[i]);
4993 err = via_add_control(
4994 spec, VIA_CTL_WIDGET_VOL, name,
4995 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4996 if (err < 0)
4997 return err;
4998 sprintf(name, "%s Playback Switch", chname[i]);
4999 err = via_add_control(
5000 spec, VIA_CTL_WIDGET_MUTE, name,
5001 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5002 HDA_OUTPUT));
5003 if (err < 0)
5004 return err;
5007 return 0;
5010 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5012 int err;
5014 if (!pin)
5015 return 0;
5017 spec->multiout.hp_nid = 0x25; /* AOW3 */
5018 spec->hp_independent_mode_index = 1;
5020 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5021 "Headphone Playback Volume",
5022 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5023 if (err < 0)
5024 return err;
5026 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5027 "Headphone Playback Switch",
5028 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5029 if (err < 0)
5030 return err;
5032 create_hp_imux(spec);
5033 return 0;
5036 /* create playback/capture controls for input pins */
5037 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5038 const struct auto_pin_cfg *cfg)
5040 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5041 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
5042 ARRAY_SIZE(pin_idxs));
5045 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5047 struct via_spec *spec = codec->spec;
5048 int err;
5050 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5051 if (err < 0)
5052 return err;
5053 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5054 if (err < 0)
5055 return err;
5056 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5057 return 0; /* can't find valid BIOS pin config */
5059 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5060 if (err < 0)
5061 return err;
5062 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5063 if (err < 0)
5064 return err;
5065 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5066 if (err < 0)
5067 return err;
5069 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5071 fill_dig_outs(codec);
5073 if (spec->kctls.list)
5074 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5076 spec->input_mux = &spec->private_imux[0];
5078 if (spec->hp_mux)
5079 via_hp_build(codec);
5081 via_smart51_build(spec);
5083 return 1;
5086 #ifdef CONFIG_SND_HDA_POWER_SAVE
5087 static struct hda_amp_list vt1716S_loopbacks[] = {
5088 { 0x16, HDA_INPUT, 1 },
5089 { 0x16, HDA_INPUT, 2 },
5090 { 0x16, HDA_INPUT, 3 },
5091 { 0x16, HDA_INPUT, 4 },
5092 { } /* end */
5094 #endif
5096 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5098 struct via_spec *spec = codec->spec;
5099 int imux_is_smixer;
5100 unsigned int parm;
5101 unsigned int mono_out, present;
5102 /* SW0 (17h) = stereo mixer */
5103 imux_is_smixer =
5104 (snd_hda_codec_read(codec, 0x17, 0,
5105 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5106 /* inputs */
5107 /* PW 1/2/5 (1ah/1bh/1eh) */
5108 parm = AC_PWRST_D3;
5109 set_pin_power_state(codec, 0x1a, &parm);
5110 set_pin_power_state(codec, 0x1b, &parm);
5111 set_pin_power_state(codec, 0x1e, &parm);
5112 if (imux_is_smixer)
5113 parm = AC_PWRST_D0;
5114 /* SW0 (17h), AIW0(13h) */
5115 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5116 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5118 parm = AC_PWRST_D3;
5119 set_pin_power_state(codec, 0x1e, &parm);
5120 /* PW11 (22h) */
5121 if (spec->dmic_enabled)
5122 set_pin_power_state(codec, 0x22, &parm);
5123 else
5124 snd_hda_codec_write(codec, 0x22, 0,
5125 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5127 /* SW2(26h), AIW1(14h) */
5128 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5129 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5131 /* outputs */
5132 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5133 parm = AC_PWRST_D3;
5134 set_pin_power_state(codec, 0x19, &parm);
5135 /* Smart 5.1 PW2(1bh) */
5136 if (spec->smart51_enabled)
5137 set_pin_power_state(codec, 0x1b, &parm);
5138 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5139 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5141 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5142 parm = AC_PWRST_D3;
5143 set_pin_power_state(codec, 0x23, &parm);
5144 /* Smart 5.1 PW1(1ah) */
5145 if (spec->smart51_enabled)
5146 set_pin_power_state(codec, 0x1a, &parm);
5147 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5149 /* Smart 5.1 PW5(1eh) */
5150 if (spec->smart51_enabled)
5151 set_pin_power_state(codec, 0x1e, &parm);
5152 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5154 /* Mono out */
5155 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5156 present = snd_hda_jack_detect(codec, 0x1c);
5158 if (present)
5159 mono_out = 0;
5160 else {
5161 present = snd_hda_jack_detect(codec, 0x1d);
5162 if (!spec->hp_independent_mode && present)
5163 mono_out = 0;
5164 else
5165 mono_out = 1;
5167 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5168 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5169 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5170 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5172 /* PW 3/4 (1ch/1dh) */
5173 parm = AC_PWRST_D3;
5174 set_pin_power_state(codec, 0x1c, &parm);
5175 set_pin_power_state(codec, 0x1d, &parm);
5176 /* HP Independent Mode, power on AOW3 */
5177 if (spec->hp_independent_mode)
5178 snd_hda_codec_write(codec, 0x25, 0,
5179 AC_VERB_SET_POWER_STATE, parm);
5181 /* force to D0 for internal Speaker */
5182 /* MW0 (16h), AOW0 (10h) */
5183 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5184 imux_is_smixer ? AC_PWRST_D0 : parm);
5185 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5186 mono_out ? AC_PWRST_D0 : parm);
5189 static int patch_vt1716S(struct hda_codec *codec)
5191 struct via_spec *spec;
5192 int err;
5194 /* create a codec specific record */
5195 spec = via_new_spec(codec);
5196 if (spec == NULL)
5197 return -ENOMEM;
5199 /* automatic parse from the BIOS config */
5200 err = vt1716S_parse_auto_config(codec);
5201 if (err < 0) {
5202 via_free(codec);
5203 return err;
5204 } else if (!err) {
5205 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5206 "from BIOS. Using genenic mode...\n");
5209 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5210 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5212 spec->stream_name_analog = "VT1716S Analog";
5213 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5214 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5216 spec->stream_name_digital = "VT1716S Digital";
5217 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5219 if (!spec->adc_nids && spec->input_mux) {
5220 spec->adc_nids = vt1716S_adc_nids;
5221 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5222 get_mux_nids(codec);
5223 override_mic_boost(codec, 0x1a, 0, 3, 40);
5224 override_mic_boost(codec, 0x1e, 0, 3, 40);
5225 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5226 spec->num_mixers++;
5229 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5230 spec->num_mixers++;
5232 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5234 codec->patch_ops = via_patch_ops;
5236 codec->patch_ops.init = via_auto_init;
5237 codec->patch_ops.unsol_event = via_unsol_event;
5239 #ifdef CONFIG_SND_HDA_POWER_SAVE
5240 spec->loopback.amplist = vt1716S_loopbacks;
5241 #endif
5243 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
5244 return 0;
5247 /* for vt2002P */
5249 /* capture mixer elements */
5250 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5251 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5252 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5253 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5254 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5255 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5256 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5257 HDA_INPUT),
5259 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5260 /* The multiple "Capture Source" controls confuse alsamixer
5261 * So call somewhat different..
5263 /* .name = "Capture Source", */
5264 .name = "Input Source",
5265 .count = 2,
5266 .info = via_mux_enum_info,
5267 .get = via_mux_enum_get,
5268 .put = via_mux_enum_put,
5270 { } /* end */
5273 static struct hda_verb vt2002P_volume_init_verbs[] = {
5274 /* Class-D speaker related verbs */
5275 {0x1, 0xfe0, 0x4},
5276 {0x1, 0xfe9, 0x80},
5277 {0x1, 0xfe2, 0x22},
5279 * Unmute ADC0-1 and set the default input to mic-in
5281 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5282 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5285 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5286 * mixer widget
5288 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5289 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5290 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5291 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5292 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5293 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5295 /* MUX Indices: Mic = 0 */
5296 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5297 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5299 /* PW9 Output enable */
5300 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5302 /* Enable Boost Volume backdoor */
5303 {0x1, 0xfb9, 0x24},
5305 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5306 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5307 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5308 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5309 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5310 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5311 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5312 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5313 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5315 /* set MUX0/1/4/8 = 0 (AOW0) */
5316 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5317 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5318 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5319 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5321 /* set PW0 index=0 (MW0) */
5322 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5324 /* Enable AOW0 to MW9 */
5325 {0x1, 0xfb8, 0x88},
5328 static struct hda_verb vt1802_volume_init_verbs[] = {
5330 * Unmute ADC0-1 and set the default input to mic-in
5332 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5333 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5336 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5337 * mixer widget
5339 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5340 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5341 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5342 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5343 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5344 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5346 /* MUX Indices: Mic = 0 */
5347 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5348 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5350 /* PW9 Output enable */
5351 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5353 /* Enable Boost Volume backdoor */
5354 {0x1, 0xfb9, 0x24},
5356 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5357 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5358 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5359 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5360 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5361 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5362 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5363 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5364 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5366 /* set MUX0/1/4/8 = 0 (AOW0) */
5367 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5368 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5369 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5370 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5372 /* set PW0 index=0 (MW0) */
5373 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5375 /* Enable AOW0 to MW9 */
5376 {0x1, 0xfb8, 0x88},
5381 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5382 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5383 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5384 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5385 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5386 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5387 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5388 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5391 static struct hda_verb vt1802_uniwill_init_verbs[] = {
5392 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5393 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5394 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5395 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5396 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5397 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5398 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5402 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5403 .substreams = 2,
5404 .channels_min = 2,
5405 .channels_max = 2,
5406 .nid = 0x8, /* NID to query formats and rates */
5407 .ops = {
5408 .open = via_playback_pcm_open,
5409 .prepare = via_playback_multi_pcm_prepare,
5410 .cleanup = via_playback_multi_pcm_cleanup,
5411 .close = via_pcm_open_close,
5415 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5416 .substreams = 2,
5417 .channels_min = 2,
5418 .channels_max = 2,
5419 .nid = 0x10, /* NID to query formats and rates */
5420 .ops = {
5421 .open = via_pcm_open_close,
5422 .prepare = via_capture_pcm_prepare,
5423 .cleanup = via_capture_pcm_cleanup,
5424 .close = via_pcm_open_close,
5428 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5429 .substreams = 1,
5430 .channels_min = 2,
5431 .channels_max = 2,
5432 /* NID is set in via_build_pcms */
5433 .ops = {
5434 .open = via_dig_playback_pcm_open,
5435 .close = via_dig_playback_pcm_close,
5436 .prepare = via_dig_playback_pcm_prepare,
5437 .cleanup = via_dig_playback_pcm_cleanup
5441 /* fill in the dac_nids table from the parsed pin configuration */
5442 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5443 const struct auto_pin_cfg *cfg)
5445 spec->multiout.num_dacs = 1;
5446 spec->multiout.dac_nids = spec->private_dac_nids;
5447 if (cfg->line_out_pins[0])
5448 spec->multiout.dac_nids[0] = 0x8;
5449 return 0;
5452 /* add playback controls from the parsed DAC table */
5453 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5454 const struct auto_pin_cfg *cfg)
5456 int err;
5457 hda_nid_t sw_nid;
5459 if (!cfg->line_out_pins[0])
5460 return -1;
5462 if (spec->codec_type == VT1802)
5463 sw_nid = 0x28;
5464 else
5465 sw_nid = 0x26;
5467 /* Line-Out: PortE */
5468 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5469 "Master Front Playback Volume",
5470 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5471 if (err < 0)
5472 return err;
5473 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5474 "Master Front Playback Switch",
5475 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
5476 if (err < 0)
5477 return err;
5479 return 0;
5482 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5484 int err;
5486 if (!pin)
5487 return 0;
5489 spec->multiout.hp_nid = 0x9;
5490 spec->hp_independent_mode_index = 1;
5492 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5493 "Headphone Playback Volume",
5494 HDA_COMPOSE_AMP_VAL(
5495 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5496 if (err < 0)
5497 return err;
5499 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5500 "Headphone Playback Switch",
5501 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5502 if (err < 0)
5503 return err;
5505 create_hp_imux(spec);
5506 return 0;
5509 /* create playback/capture controls for input pins */
5510 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5511 const struct auto_pin_cfg *cfg)
5513 struct via_spec *spec = codec->spec;
5514 struct hda_input_mux *imux = &spec->private_imux[0];
5515 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5516 int err;
5518 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5519 ARRAY_SIZE(pin_idxs));
5520 if (err < 0)
5521 return err;
5522 /* build volume/mute control of loopback */
5523 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
5524 if (err < 0)
5525 return err;
5527 /* for digital mic select */
5528 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
5530 return 0;
5533 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5535 struct via_spec *spec = codec->spec;
5536 int err;
5539 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5540 if (err < 0)
5541 return err;
5543 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5544 if (err < 0)
5545 return err;
5547 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5548 return 0; /* can't find valid BIOS pin config */
5550 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5551 if (err < 0)
5552 return err;
5553 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5554 if (err < 0)
5555 return err;
5556 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5557 if (err < 0)
5558 return err;
5560 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5562 fill_dig_outs(codec);
5564 if (spec->kctls.list)
5565 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5567 spec->input_mux = &spec->private_imux[0];
5569 if (spec->hp_mux)
5570 via_hp_build(codec);
5572 return 1;
5575 #ifdef CONFIG_SND_HDA_POWER_SAVE
5576 static struct hda_amp_list vt2002P_loopbacks[] = {
5577 { 0x21, HDA_INPUT, 0 },
5578 { 0x21, HDA_INPUT, 1 },
5579 { 0x21, HDA_INPUT, 2 },
5580 { } /* end */
5582 #endif
5584 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5586 struct via_spec *spec = codec->spec;
5587 int imux_is_smixer;
5588 unsigned int parm;
5589 unsigned int present;
5590 /* MUX9 (1eh) = stereo mixer */
5591 imux_is_smixer =
5592 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5593 /* inputs */
5594 /* PW 5/6/7 (29h/2ah/2bh) */
5595 parm = AC_PWRST_D3;
5596 set_pin_power_state(codec, 0x29, &parm);
5597 set_pin_power_state(codec, 0x2a, &parm);
5598 set_pin_power_state(codec, 0x2b, &parm);
5599 parm = AC_PWRST_D0;
5600 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5601 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5602 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5603 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5604 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5606 /* outputs */
5607 /* AOW0 (8h)*/
5608 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5610 if (spec->codec_type == VT1802) {
5611 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5612 parm = AC_PWRST_D3;
5613 set_pin_power_state(codec, 0x28, &parm);
5614 snd_hda_codec_write(codec, 0x18, 0,
5615 AC_VERB_SET_POWER_STATE, parm);
5616 snd_hda_codec_write(codec, 0x38, 0,
5617 AC_VERB_SET_POWER_STATE, parm);
5618 } else {
5619 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5620 parm = AC_PWRST_D3;
5621 set_pin_power_state(codec, 0x26, &parm);
5622 snd_hda_codec_write(codec, 0x1c, 0,
5623 AC_VERB_SET_POWER_STATE, parm);
5624 snd_hda_codec_write(codec, 0x37, 0,
5625 AC_VERB_SET_POWER_STATE, parm);
5628 if (spec->codec_type == VT1802) {
5629 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5630 parm = AC_PWRST_D3;
5631 set_pin_power_state(codec, 0x25, &parm);
5632 snd_hda_codec_write(codec, 0x15, 0,
5633 AC_VERB_SET_POWER_STATE, parm);
5634 snd_hda_codec_write(codec, 0x35, 0,
5635 AC_VERB_SET_POWER_STATE, parm);
5636 } else {
5637 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5638 parm = AC_PWRST_D3;
5639 set_pin_power_state(codec, 0x25, &parm);
5640 snd_hda_codec_write(codec, 0x19, 0,
5641 AC_VERB_SET_POWER_STATE, parm);
5642 snd_hda_codec_write(codec, 0x35, 0,
5643 AC_VERB_SET_POWER_STATE, parm);
5646 if (spec->hp_independent_mode)
5647 snd_hda_codec_write(codec, 0x9, 0,
5648 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5650 /* Class-D */
5651 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5652 present = snd_hda_jack_detect(codec, 0x25);
5654 parm = AC_PWRST_D3;
5655 set_pin_power_state(codec, 0x24, &parm);
5656 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5657 if (spec->codec_type == VT1802)
5658 snd_hda_codec_write(codec, 0x14, 0,
5659 AC_VERB_SET_POWER_STATE, parm);
5660 else
5661 snd_hda_codec_write(codec, 0x18, 0,
5662 AC_VERB_SET_POWER_STATE, parm);
5663 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5665 /* Mono Out */
5666 present = snd_hda_jack_detect(codec, 0x26);
5668 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5669 if (spec->codec_type == VT1802) {
5670 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5671 snd_hda_codec_write(codec, 0x33, 0,
5672 AC_VERB_SET_POWER_STATE, parm);
5673 snd_hda_codec_write(codec, 0x1c, 0,
5674 AC_VERB_SET_POWER_STATE, parm);
5675 snd_hda_codec_write(codec, 0x3c, 0,
5676 AC_VERB_SET_POWER_STATE, parm);
5677 } else {
5678 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5679 snd_hda_codec_write(codec, 0x31, 0,
5680 AC_VERB_SET_POWER_STATE, parm);
5681 snd_hda_codec_write(codec, 0x17, 0,
5682 AC_VERB_SET_POWER_STATE, parm);
5683 snd_hda_codec_write(codec, 0x3b, 0,
5684 AC_VERB_SET_POWER_STATE, parm);
5686 /* MW9 (21h) */
5687 if (imux_is_smixer || !is_aa_path_mute(codec))
5688 snd_hda_codec_write(codec, 0x21, 0,
5689 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5690 else
5691 snd_hda_codec_write(codec, 0x21, 0,
5692 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5695 /* patch for vt2002P */
5696 static int patch_vt2002P(struct hda_codec *codec)
5698 struct via_spec *spec;
5699 int err;
5701 /* create a codec specific record */
5702 spec = via_new_spec(codec);
5703 if (spec == NULL)
5704 return -ENOMEM;
5706 /* automatic parse from the BIOS config */
5707 err = vt2002P_parse_auto_config(codec);
5708 if (err < 0) {
5709 via_free(codec);
5710 return err;
5711 } else if (!err) {
5712 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5713 "from BIOS. Using genenic mode...\n");
5716 if (spec->codec_type == VT1802)
5717 spec->init_verbs[spec->num_iverbs++] =
5718 vt1802_volume_init_verbs;
5719 else
5720 spec->init_verbs[spec->num_iverbs++] =
5721 vt2002P_volume_init_verbs;
5723 if (spec->codec_type == VT1802)
5724 spec->init_verbs[spec->num_iverbs++] =
5725 vt1802_uniwill_init_verbs;
5726 else
5727 spec->init_verbs[spec->num_iverbs++] =
5728 vt2002P_uniwill_init_verbs;
5730 if (spec->codec_type == VT1802)
5731 spec->stream_name_analog = "VT1802 Analog";
5732 else
5733 spec->stream_name_analog = "VT2002P Analog";
5734 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5735 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5737 if (spec->codec_type == VT1802)
5738 spec->stream_name_digital = "VT1802 Digital";
5739 else
5740 spec->stream_name_digital = "VT2002P Digital";
5741 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5743 if (!spec->adc_nids && spec->input_mux) {
5744 spec->adc_nids = vt2002P_adc_nids;
5745 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5746 get_mux_nids(codec);
5747 override_mic_boost(codec, 0x2b, 0, 3, 40);
5748 override_mic_boost(codec, 0x29, 0, 3, 40);
5749 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5750 spec->num_mixers++;
5753 codec->patch_ops = via_patch_ops;
5755 codec->patch_ops.init = via_auto_init;
5756 codec->patch_ops.unsol_event = via_unsol_event;
5758 #ifdef CONFIG_SND_HDA_POWER_SAVE
5759 spec->loopback.amplist = vt2002P_loopbacks;
5760 #endif
5762 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
5763 return 0;
5766 /* for vt1812 */
5768 /* capture mixer elements */
5769 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5770 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5771 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5772 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5773 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5774 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5775 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5776 HDA_INPUT),
5778 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5779 /* The multiple "Capture Source" controls confuse alsamixer
5780 * So call somewhat different..
5782 .name = "Input Source",
5783 .count = 2,
5784 .info = via_mux_enum_info,
5785 .get = via_mux_enum_get,
5786 .put = via_mux_enum_put,
5788 { } /* end */
5791 static struct hda_verb vt1812_volume_init_verbs[] = {
5793 * Unmute ADC0-1 and set the default input to mic-in
5795 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5796 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5799 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5800 * mixer widget
5802 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5803 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5804 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5805 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5806 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5807 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5809 /* MUX Indices: Mic = 0 */
5810 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5811 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5813 /* PW9 Output enable */
5814 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5816 /* Enable Boost Volume backdoor */
5817 {0x1, 0xfb9, 0x24},
5819 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5820 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5821 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5822 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5823 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5824 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5825 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5826 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5827 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5828 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5829 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5831 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5832 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5833 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5834 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5835 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5836 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5838 /* Enable AOW0 to MW9 */
5839 {0x1, 0xfb8, 0xa8},
5844 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5845 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5846 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5847 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5848 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5849 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5850 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5851 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5852 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5856 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5857 .substreams = 2,
5858 .channels_min = 2,
5859 .channels_max = 2,
5860 .nid = 0x8, /* NID to query formats and rates */
5861 .ops = {
5862 .open = via_playback_pcm_open,
5863 .prepare = via_playback_multi_pcm_prepare,
5864 .cleanup = via_playback_multi_pcm_cleanup,
5865 .close = via_pcm_open_close,
5869 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5870 .substreams = 2,
5871 .channels_min = 2,
5872 .channels_max = 2,
5873 .nid = 0x10, /* NID to query formats and rates */
5874 .ops = {
5875 .open = via_pcm_open_close,
5876 .prepare = via_capture_pcm_prepare,
5877 .cleanup = via_capture_pcm_cleanup,
5878 .close = via_pcm_open_close,
5882 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5883 .substreams = 1,
5884 .channels_min = 2,
5885 .channels_max = 2,
5886 /* NID is set in via_build_pcms */
5887 .ops = {
5888 .open = via_dig_playback_pcm_open,
5889 .close = via_dig_playback_pcm_close,
5890 .prepare = via_dig_playback_pcm_prepare,
5891 .cleanup = via_dig_playback_pcm_cleanup
5894 /* fill in the dac_nids table from the parsed pin configuration */
5895 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5896 const struct auto_pin_cfg *cfg)
5898 spec->multiout.num_dacs = 1;
5899 spec->multiout.dac_nids = spec->private_dac_nids;
5900 if (cfg->line_out_pins[0])
5901 spec->multiout.dac_nids[0] = 0x8;
5902 return 0;
5906 /* add playback controls from the parsed DAC table */
5907 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5908 const struct auto_pin_cfg *cfg)
5910 int err;
5912 if (!cfg->line_out_pins[0])
5913 return -1;
5915 /* Line-Out: PortE */
5916 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5917 "Front Playback Volume",
5918 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5919 if (err < 0)
5920 return err;
5921 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5922 "Front Playback Switch",
5923 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5924 if (err < 0)
5925 return err;
5927 return 0;
5930 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5932 int err;
5934 if (!pin)
5935 return 0;
5937 spec->multiout.hp_nid = 0x9;
5938 spec->hp_independent_mode_index = 1;
5941 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5942 "Headphone Playback Volume",
5943 HDA_COMPOSE_AMP_VAL(
5944 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5945 if (err < 0)
5946 return err;
5948 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5949 "Headphone Playback Switch",
5950 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5951 if (err < 0)
5952 return err;
5954 create_hp_imux(spec);
5955 return 0;
5958 /* create playback/capture controls for input pins */
5959 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5960 const struct auto_pin_cfg *cfg)
5962 struct via_spec *spec = codec->spec;
5963 struct hda_input_mux *imux = &spec->private_imux[0];
5964 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5965 int err;
5967 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5968 ARRAY_SIZE(pin_idxs));
5969 if (err < 0)
5970 return err;
5972 /* build volume/mute control of loopback */
5973 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
5974 if (err < 0)
5975 return err;
5977 /* for digital mic select */
5978 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
5980 return 0;
5983 static int vt1812_parse_auto_config(struct hda_codec *codec)
5985 struct via_spec *spec = codec->spec;
5986 int err;
5989 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5990 if (err < 0)
5991 return err;
5992 fill_dig_outs(codec);
5993 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5994 if (err < 0)
5995 return err;
5997 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5998 return 0; /* can't find valid BIOS pin config */
6000 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6001 if (err < 0)
6002 return err;
6003 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6004 if (err < 0)
6005 return err;
6006 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
6007 if (err < 0)
6008 return err;
6010 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6012 fill_dig_outs(codec);
6014 if (spec->kctls.list)
6015 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6017 spec->input_mux = &spec->private_imux[0];
6019 if (spec->hp_mux)
6020 via_hp_build(codec);
6022 return 1;
6025 #ifdef CONFIG_SND_HDA_POWER_SAVE
6026 static struct hda_amp_list vt1812_loopbacks[] = {
6027 { 0x21, HDA_INPUT, 0 },
6028 { 0x21, HDA_INPUT, 1 },
6029 { 0x21, HDA_INPUT, 2 },
6030 { } /* end */
6032 #endif
6034 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
6036 struct via_spec *spec = codec->spec;
6037 int imux_is_smixer =
6038 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
6039 unsigned int parm;
6040 unsigned int present;
6041 /* MUX10 (1eh) = stereo mixer */
6042 imux_is_smixer =
6043 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
6044 /* inputs */
6045 /* PW 5/6/7 (29h/2ah/2bh) */
6046 parm = AC_PWRST_D3;
6047 set_pin_power_state(codec, 0x29, &parm);
6048 set_pin_power_state(codec, 0x2a, &parm);
6049 set_pin_power_state(codec, 0x2b, &parm);
6050 parm = AC_PWRST_D0;
6051 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
6052 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
6053 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
6054 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
6055 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
6057 /* outputs */
6058 /* AOW0 (8h)*/
6059 snd_hda_codec_write(codec, 0x8, 0,
6060 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6062 /* PW4 (28h), MW4 (18h), MUX4(38h) */
6063 parm = AC_PWRST_D3;
6064 set_pin_power_state(codec, 0x28, &parm);
6065 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
6066 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
6068 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
6069 parm = AC_PWRST_D3;
6070 set_pin_power_state(codec, 0x25, &parm);
6071 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
6072 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
6073 if (spec->hp_independent_mode)
6074 snd_hda_codec_write(codec, 0x9, 0,
6075 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6077 /* Internal Speaker */
6078 /* PW0 (24h), MW0(14h), MUX0(34h) */
6079 present = snd_hda_jack_detect(codec, 0x25);
6081 parm = AC_PWRST_D3;
6082 set_pin_power_state(codec, 0x24, &parm);
6083 if (present) {
6084 snd_hda_codec_write(codec, 0x14, 0,
6085 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6086 snd_hda_codec_write(codec, 0x34, 0,
6087 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6088 } else {
6089 snd_hda_codec_write(codec, 0x14, 0,
6090 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6091 snd_hda_codec_write(codec, 0x34, 0,
6092 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6096 /* Mono Out */
6097 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6098 present = snd_hda_jack_detect(codec, 0x28);
6100 parm = AC_PWRST_D3;
6101 set_pin_power_state(codec, 0x31, &parm);
6102 if (present) {
6103 snd_hda_codec_write(codec, 0x1c, 0,
6104 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6105 snd_hda_codec_write(codec, 0x3c, 0,
6106 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6107 snd_hda_codec_write(codec, 0x3e, 0,
6108 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6109 } else {
6110 snd_hda_codec_write(codec, 0x1c, 0,
6111 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6112 snd_hda_codec_write(codec, 0x3c, 0,
6113 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6114 snd_hda_codec_write(codec, 0x3e, 0,
6115 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6118 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6119 parm = AC_PWRST_D3;
6120 set_pin_power_state(codec, 0x33, &parm);
6121 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6122 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6126 /* patch for vt1812 */
6127 static int patch_vt1812(struct hda_codec *codec)
6129 struct via_spec *spec;
6130 int err;
6132 /* create a codec specific record */
6133 spec = via_new_spec(codec);
6134 if (spec == NULL)
6135 return -ENOMEM;
6137 /* automatic parse from the BIOS config */
6138 err = vt1812_parse_auto_config(codec);
6139 if (err < 0) {
6140 via_free(codec);
6141 return err;
6142 } else if (!err) {
6143 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6144 "from BIOS. Using genenic mode...\n");
6148 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6149 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6151 spec->stream_name_analog = "VT1812 Analog";
6152 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6153 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6155 spec->stream_name_digital = "VT1812 Digital";
6156 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6159 if (!spec->adc_nids && spec->input_mux) {
6160 spec->adc_nids = vt1812_adc_nids;
6161 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6162 get_mux_nids(codec);
6163 override_mic_boost(codec, 0x2b, 0, 3, 40);
6164 override_mic_boost(codec, 0x29, 0, 3, 40);
6165 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6166 spec->num_mixers++;
6169 codec->patch_ops = via_patch_ops;
6171 codec->patch_ops.init = via_auto_init;
6172 codec->patch_ops.unsol_event = via_unsol_event;
6174 #ifdef CONFIG_SND_HDA_POWER_SAVE
6175 spec->loopback.amplist = vt1812_loopbacks;
6176 #endif
6178 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
6179 return 0;
6183 * patch entries
6185 static struct hda_codec_preset snd_hda_preset_via[] = {
6186 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6187 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6188 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6189 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6190 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6191 .patch = patch_vt1709_10ch},
6192 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6193 .patch = patch_vt1709_10ch},
6194 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6195 .patch = patch_vt1709_10ch},
6196 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6197 .patch = patch_vt1709_10ch},
6198 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6199 .patch = patch_vt1709_6ch},
6200 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6201 .patch = patch_vt1709_6ch},
6202 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6203 .patch = patch_vt1709_6ch},
6204 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6205 .patch = patch_vt1709_6ch},
6206 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6207 .patch = patch_vt1708B_8ch},
6208 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6209 .patch = patch_vt1708B_8ch},
6210 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6211 .patch = patch_vt1708B_8ch},
6212 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6213 .patch = patch_vt1708B_8ch},
6214 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6215 .patch = patch_vt1708B_4ch},
6216 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6217 .patch = patch_vt1708B_4ch},
6218 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6219 .patch = patch_vt1708B_4ch},
6220 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6221 .patch = patch_vt1708B_4ch},
6222 { .id = 0x11060397, .name = "VT1708S",
6223 .patch = patch_vt1708S},
6224 { .id = 0x11061397, .name = "VT1708S",
6225 .patch = patch_vt1708S},
6226 { .id = 0x11062397, .name = "VT1708S",
6227 .patch = patch_vt1708S},
6228 { .id = 0x11063397, .name = "VT1708S",
6229 .patch = patch_vt1708S},
6230 { .id = 0x11064397, .name = "VT1705",
6231 .patch = patch_vt1708S},
6232 { .id = 0x11065397, .name = "VT1708S",
6233 .patch = patch_vt1708S},
6234 { .id = 0x11066397, .name = "VT1708S",
6235 .patch = patch_vt1708S},
6236 { .id = 0x11067397, .name = "VT1708S",
6237 .patch = patch_vt1708S},
6238 { .id = 0x11060398, .name = "VT1702",
6239 .patch = patch_vt1702},
6240 { .id = 0x11061398, .name = "VT1702",
6241 .patch = patch_vt1702},
6242 { .id = 0x11062398, .name = "VT1702",
6243 .patch = patch_vt1702},
6244 { .id = 0x11063398, .name = "VT1702",
6245 .patch = patch_vt1702},
6246 { .id = 0x11064398, .name = "VT1702",
6247 .patch = patch_vt1702},
6248 { .id = 0x11065398, .name = "VT1702",
6249 .patch = patch_vt1702},
6250 { .id = 0x11066398, .name = "VT1702",
6251 .patch = patch_vt1702},
6252 { .id = 0x11067398, .name = "VT1702",
6253 .patch = patch_vt1702},
6254 { .id = 0x11060428, .name = "VT1718S",
6255 .patch = patch_vt1718S},
6256 { .id = 0x11064428, .name = "VT1718S",
6257 .patch = patch_vt1718S},
6258 { .id = 0x11060441, .name = "VT2020",
6259 .patch = patch_vt1718S},
6260 { .id = 0x11064441, .name = "VT1828S",
6261 .patch = patch_vt1718S},
6262 { .id = 0x11060433, .name = "VT1716S",
6263 .patch = patch_vt1716S},
6264 { .id = 0x1106a721, .name = "VT1716S",
6265 .patch = patch_vt1716S},
6266 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6267 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6268 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6269 { .id = 0x11060440, .name = "VT1818S",
6270 .patch = patch_vt1708S},
6271 { .id = 0x11060446, .name = "VT1802",
6272 .patch = patch_vt2002P},
6273 { .id = 0x11068446, .name = "VT1802",
6274 .patch = patch_vt2002P},
6275 {} /* terminator */
6278 MODULE_ALIAS("snd-hda-codec-id:1106*");
6280 static struct hda_codec_preset_list via_list = {
6281 .preset = snd_hda_preset_via,
6282 .owner = THIS_MODULE,
6285 MODULE_LICENSE("GPL");
6286 MODULE_DESCRIPTION("VIA HD-audio codec");
6288 static int __init patch_via_init(void)
6290 return snd_hda_add_codec_preset(&via_list);
6293 static void __exit patch_via_exit(void)
6295 snd_hda_delete_codec_preset(&via_list);
6298 module_init(patch_via_init)
6299 module_exit(patch_via_exit)