Input: wacom - revert "Cintiq 21UX2 does not have menu strips"
[linux-btrfs-devel.git] / sound / pci / hda / patch_via.c
blobc952582fb21810933fc9891b687f516d84cf881e
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 const struct snd_kcontrol_new *mixers[6];
113 unsigned int num_mixers;
115 const struct hda_verb *init_verbs[5];
116 unsigned int num_iverbs;
118 char *stream_name_analog;
119 const struct hda_pcm_stream *stream_analog_playback;
120 const struct hda_pcm_stream *stream_analog_capture;
122 char *stream_name_digital;
123 const struct hda_pcm_stream *stream_digital_playback;
124 const 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 const 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 const 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 const hda_nid_t vt1708_adc_nids[2] = {
421 /* ADC1-2 */
422 0x15, 0x27
425 static const hda_nid_t vt1709_adc_nids[3] = {
426 /* ADC1-2 */
427 0x14, 0x15, 0x16
430 static const hda_nid_t vt1708B_adc_nids[2] = {
431 /* ADC1-2 */
432 0x13, 0x14
435 static const hda_nid_t vt1708S_adc_nids[2] = {
436 /* ADC1-2 */
437 0x13, 0x14
440 static const hda_nid_t vt1702_adc_nids[3] = {
441 /* ADC1-2 */
442 0x12, 0x20, 0x1F
445 static const hda_nid_t vt1718S_adc_nids[2] = {
446 /* ADC1-2 */
447 0x10, 0x11
450 static const hda_nid_t vt1716S_adc_nids[2] = {
451 /* ADC1-2 */
452 0x13, 0x14
455 static const hda_nid_t vt2002P_adc_nids[2] = {
456 /* ADC1-2 */
457 0x10, 0x11
460 static const 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 const 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 const 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 nid = side_mute_channel(spec);
836 if (nid) {
837 knew = via_clone_control(spec, &via_hp_mixer[1]);
838 if (knew == NULL)
839 return -ENOMEM;
840 knew->subdevice = nid;
843 return 0;
846 static void notify_aa_path_ctls(struct hda_codec *codec)
848 int i;
849 struct snd_ctl_elem_id id;
850 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
851 struct snd_kcontrol *ctl;
853 memset(&id, 0, sizeof(id));
854 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
855 for (i = 0; i < ARRAY_SIZE(labels); i++) {
856 sprintf(id.name, "%s Playback Volume", labels[i]);
857 ctl = snd_hda_find_mixer_ctl(codec, id.name);
858 if (ctl)
859 snd_ctl_notify(codec->bus->card,
860 SNDRV_CTL_EVENT_MASK_VALUE,
861 &ctl->id);
865 static void mute_aa_path(struct hda_codec *codec, int mute)
867 struct via_spec *spec = codec->spec;
868 hda_nid_t nid_mixer;
869 int start_idx;
870 int end_idx;
871 int i;
872 /* get nid of MW0 and start & end index */
873 switch (spec->codec_type) {
874 case VT1708:
875 nid_mixer = 0x17;
876 start_idx = 2;
877 end_idx = 4;
878 break;
879 case VT1709_10CH:
880 case VT1709_6CH:
881 nid_mixer = 0x18;
882 start_idx = 2;
883 end_idx = 4;
884 break;
885 case VT1708B_8CH:
886 case VT1708B_4CH:
887 case VT1708S:
888 case VT1716S:
889 nid_mixer = 0x16;
890 start_idx = 2;
891 end_idx = 4;
892 break;
893 case VT1718S:
894 nid_mixer = 0x21;
895 start_idx = 1;
896 end_idx = 3;
897 break;
898 default:
899 return;
901 /* check AA path's mute status */
902 for (i = start_idx; i <= end_idx; i++) {
903 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
904 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
905 HDA_AMP_MUTE, val);
908 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
910 const struct auto_pin_cfg *cfg = &spec->autocfg;
911 int i;
913 for (i = 0; i < cfg->num_inputs; i++) {
914 if (pin == cfg->inputs[i].pin)
915 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
917 return 0;
920 static int via_smart51_info(struct snd_kcontrol *kcontrol,
921 struct snd_ctl_elem_info *uinfo)
923 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
924 uinfo->count = 1;
925 uinfo->value.integer.min = 0;
926 uinfo->value.integer.max = 1;
927 return 0;
930 static int via_smart51_get(struct snd_kcontrol *kcontrol,
931 struct snd_ctl_elem_value *ucontrol)
933 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
934 struct via_spec *spec = codec->spec;
935 const struct auto_pin_cfg *cfg = &spec->autocfg;
936 int on = 1;
937 int i;
939 for (i = 0; i < cfg->num_inputs; i++) {
940 hda_nid_t nid = cfg->inputs[i].pin;
941 int ctl = snd_hda_codec_read(codec, nid, 0,
942 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
943 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
944 continue;
945 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
946 spec->hp_independent_mode && spec->codec_type != VT1718S)
947 continue; /* ignore FMic for independent HP */
948 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
949 on = 0;
951 *ucontrol->value.integer.value = on;
952 return 0;
955 static int via_smart51_put(struct snd_kcontrol *kcontrol,
956 struct snd_ctl_elem_value *ucontrol)
958 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
959 struct via_spec *spec = codec->spec;
960 const struct auto_pin_cfg *cfg = &spec->autocfg;
961 int out_in = *ucontrol->value.integer.value
962 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
963 int i;
965 for (i = 0; i < cfg->num_inputs; i++) {
966 hda_nid_t nid = cfg->inputs[i].pin;
967 unsigned int parm;
969 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
970 continue;
971 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
972 spec->hp_independent_mode && spec->codec_type != VT1718S)
973 continue; /* don't retask FMic for independent HP */
975 parm = snd_hda_codec_read(codec, nid, 0,
976 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
977 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
978 parm |= out_in;
979 snd_hda_codec_write(codec, nid, 0,
980 AC_VERB_SET_PIN_WIDGET_CONTROL,
981 parm);
982 if (out_in == AC_PINCTL_OUT_EN) {
983 mute_aa_path(codec, 1);
984 notify_aa_path_ctls(codec);
986 if (spec->codec_type == VT1718S) {
987 snd_hda_codec_amp_stereo(
988 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
989 HDA_AMP_UNMUTE);
991 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
992 if (spec->codec_type == VT1708S
993 || spec->codec_type == VT1716S) {
994 /* input = index 1 (AOW3) */
995 snd_hda_codec_write(
996 codec, nid, 0,
997 AC_VERB_SET_CONNECT_SEL, 1);
998 snd_hda_codec_amp_stereo(
999 codec, nid, HDA_OUTPUT,
1000 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1004 spec->smart51_enabled = *ucontrol->value.integer.value;
1005 set_widgets_power_state(codec);
1006 return 1;
1009 static const struct snd_kcontrol_new via_smart51_mixer[2] = {
1011 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1012 .name = "Smart 5.1",
1013 .count = 1,
1014 .info = via_smart51_info,
1015 .get = via_smart51_get,
1016 .put = via_smart51_put,
1019 .iface = NID_MAPPING,
1020 .name = "Smart 5.1",
1024 static int via_smart51_build(struct via_spec *spec)
1026 struct snd_kcontrol_new *knew;
1027 const struct auto_pin_cfg *cfg = &spec->autocfg;
1028 hda_nid_t nid;
1029 int i;
1031 if (!cfg)
1032 return 0;
1033 if (cfg->line_outs > 2)
1034 return 0;
1036 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1037 if (knew == NULL)
1038 return -ENOMEM;
1040 for (i = 0; i < cfg->num_inputs; i++) {
1041 nid = cfg->inputs[i].pin;
1042 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1043 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1044 if (knew == NULL)
1045 return -ENOMEM;
1046 knew->subdevice = nid;
1047 break;
1051 return 0;
1054 /* capture mixer elements */
1055 static const struct snd_kcontrol_new vt1708_capture_mixer[] = {
1056 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1057 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1058 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1059 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1061 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1062 /* The multiple "Capture Source" controls confuse alsamixer
1063 * So call somewhat different..
1065 /* .name = "Capture Source", */
1066 .name = "Input Source",
1067 .count = 1,
1068 .info = via_mux_enum_info,
1069 .get = via_mux_enum_get,
1070 .put = via_mux_enum_put,
1072 { } /* end */
1075 /* check AA path's mute statue */
1076 static int is_aa_path_mute(struct hda_codec *codec)
1078 int mute = 1;
1079 hda_nid_t nid_mixer;
1080 int start_idx;
1081 int end_idx;
1082 int i;
1083 struct via_spec *spec = codec->spec;
1084 /* get nid of MW0 and start & end index */
1085 switch (spec->codec_type) {
1086 case VT1708B_8CH:
1087 case VT1708B_4CH:
1088 case VT1708S:
1089 case VT1716S:
1090 nid_mixer = 0x16;
1091 start_idx = 2;
1092 end_idx = 4;
1093 break;
1094 case VT1702:
1095 nid_mixer = 0x1a;
1096 start_idx = 1;
1097 end_idx = 3;
1098 break;
1099 case VT1718S:
1100 nid_mixer = 0x21;
1101 start_idx = 1;
1102 end_idx = 3;
1103 break;
1104 case VT2002P:
1105 case VT1812:
1106 case VT1802:
1107 nid_mixer = 0x21;
1108 start_idx = 0;
1109 end_idx = 2;
1110 break;
1111 default:
1112 return 0;
1114 /* check AA path's mute status */
1115 for (i = start_idx; i <= end_idx; i++) {
1116 unsigned int con_list = snd_hda_codec_read(
1117 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1118 int shift = 8 * (i % 4);
1119 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1120 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1121 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1122 /* check mute status while the pin is connected */
1123 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1124 HDA_INPUT, i) >> 7;
1125 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1126 HDA_INPUT, i) >> 7;
1127 if (!mute_l || !mute_r) {
1128 mute = 0;
1129 break;
1133 return mute;
1136 /* enter/exit analog low-current mode */
1137 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1139 struct via_spec *spec = codec->spec;
1140 static int saved_stream_idle = 1; /* saved stream idle status */
1141 int enable = is_aa_path_mute(codec);
1142 unsigned int verb = 0;
1143 unsigned int parm = 0;
1145 if (stream_idle == -1) /* stream status did not change */
1146 enable = enable && saved_stream_idle;
1147 else {
1148 enable = enable && stream_idle;
1149 saved_stream_idle = stream_idle;
1152 /* decide low current mode's verb & parameter */
1153 switch (spec->codec_type) {
1154 case VT1708B_8CH:
1155 case VT1708B_4CH:
1156 verb = 0xf70;
1157 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1158 break;
1159 case VT1708S:
1160 case VT1718S:
1161 case VT1716S:
1162 verb = 0xf73;
1163 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1164 break;
1165 case VT1702:
1166 verb = 0xf73;
1167 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1168 break;
1169 case VT2002P:
1170 case VT1812:
1171 case VT1802:
1172 verb = 0xf93;
1173 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1174 break;
1175 default:
1176 return; /* other codecs are not supported */
1178 /* send verb */
1179 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1183 * generic initialization of ADC, input mixers and output mixers
1185 static const struct hda_verb vt1708_volume_init_verbs[] = {
1187 * Unmute ADC0-1 and set the default input to mic-in
1189 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1190 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1193 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1194 * mixer widget
1196 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1197 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1198 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1199 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1200 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1201 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1204 * Set up output mixers (0x19 - 0x1b)
1206 /* set vol=0 to output mixers */
1207 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1208 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1209 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1211 /* Setup default input MW0 to PW4 */
1212 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1213 /* PW9 Output enable */
1214 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1215 /* power down jack detect function */
1216 {0x1, 0xf81, 0x1},
1220 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1221 struct hda_codec *codec,
1222 struct snd_pcm_substream *substream)
1224 struct via_spec *spec = codec->spec;
1225 int idle = substream->pstr->substream_opened == 1
1226 && substream->ref_count == 0;
1227 analog_low_current_mode(codec, idle);
1228 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1229 hinfo);
1232 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1233 unsigned int stream_tag,
1234 unsigned int format,
1235 struct snd_pcm_substream *substream)
1237 struct via_spec *spec = codec->spec;
1238 struct hda_multi_out *mout = &spec->multiout;
1239 const hda_nid_t *nids = mout->dac_nids;
1240 int chs = substream->runtime->channels;
1241 int i;
1243 mutex_lock(&codec->spdif_mutex);
1244 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1245 if (chs == 2 &&
1246 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1247 format) &&
1248 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1249 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1250 /* turn off SPDIF once; otherwise the IEC958 bits won't
1251 * be updated */
1252 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1253 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1254 AC_VERB_SET_DIGI_CONVERT_1,
1255 codec->spdif_ctls &
1256 ~AC_DIG1_ENABLE & 0xff);
1257 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1258 stream_tag, 0, format);
1259 /* turn on again (if needed) */
1260 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1261 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1262 AC_VERB_SET_DIGI_CONVERT_1,
1263 codec->spdif_ctls & 0xff);
1264 } else {
1265 mout->dig_out_used = 0;
1266 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1267 0, 0, 0);
1270 mutex_unlock(&codec->spdif_mutex);
1272 /* front */
1273 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1274 0, format);
1276 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1277 && !spec->hp_independent_mode)
1278 /* headphone out will just decode front left/right (stereo) */
1279 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1280 0, format);
1282 /* extra outputs copied from front */
1283 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1284 if (mout->extra_out_nid[i])
1285 snd_hda_codec_setup_stream(codec,
1286 mout->extra_out_nid[i],
1287 stream_tag, 0, format);
1289 /* surrounds */
1290 for (i = 1; i < mout->num_dacs; i++) {
1291 if (chs >= (i + 1) * 2) /* independent out */
1292 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1293 i * 2, format);
1294 else /* copy front */
1295 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1296 0, format);
1300 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1301 struct hda_codec *codec,
1302 unsigned int stream_tag,
1303 unsigned int format,
1304 struct snd_pcm_substream *substream)
1306 struct via_spec *spec = codec->spec;
1307 struct hda_multi_out *mout = &spec->multiout;
1308 const hda_nid_t *nids = mout->dac_nids;
1310 if (substream->number == 0)
1311 playback_multi_pcm_prep_0(codec, stream_tag, format,
1312 substream);
1313 else {
1314 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1315 spec->hp_independent_mode)
1316 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1317 stream_tag, 0, format);
1319 vt1708_start_hp_work(spec);
1320 return 0;
1323 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1324 struct hda_codec *codec,
1325 struct snd_pcm_substream *substream)
1327 struct via_spec *spec = codec->spec;
1328 struct hda_multi_out *mout = &spec->multiout;
1329 const hda_nid_t *nids = mout->dac_nids;
1330 int i;
1332 if (substream->number == 0) {
1333 for (i = 0; i < mout->num_dacs; i++)
1334 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1336 if (mout->hp_nid && !spec->hp_independent_mode)
1337 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1338 0, 0, 0);
1340 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1341 if (mout->extra_out_nid[i])
1342 snd_hda_codec_setup_stream(codec,
1343 mout->extra_out_nid[i],
1344 0, 0, 0);
1345 mutex_lock(&codec->spdif_mutex);
1346 if (mout->dig_out_nid &&
1347 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1348 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1349 0, 0, 0);
1350 mout->dig_out_used = 0;
1352 mutex_unlock(&codec->spdif_mutex);
1353 } else {
1354 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1355 spec->hp_independent_mode)
1356 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1357 0, 0, 0);
1359 vt1708_stop_hp_work(spec);
1360 return 0;
1364 * Digital out
1366 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1367 struct hda_codec *codec,
1368 struct snd_pcm_substream *substream)
1370 struct via_spec *spec = codec->spec;
1371 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1374 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1375 struct hda_codec *codec,
1376 struct snd_pcm_substream *substream)
1378 struct via_spec *spec = codec->spec;
1379 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1382 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1383 struct hda_codec *codec,
1384 unsigned int stream_tag,
1385 unsigned int format,
1386 struct snd_pcm_substream *substream)
1388 struct via_spec *spec = codec->spec;
1389 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1390 stream_tag, format, substream);
1393 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1394 struct hda_codec *codec,
1395 struct snd_pcm_substream *substream)
1397 struct via_spec *spec = codec->spec;
1398 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1399 return 0;
1403 * Analog capture
1405 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1406 struct hda_codec *codec,
1407 unsigned int stream_tag,
1408 unsigned int format,
1409 struct snd_pcm_substream *substream)
1411 struct via_spec *spec = codec->spec;
1413 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1414 stream_tag, 0, format);
1415 return 0;
1418 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1419 struct hda_codec *codec,
1420 struct snd_pcm_substream *substream)
1422 struct via_spec *spec = codec->spec;
1423 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1424 return 0;
1427 static const struct hda_pcm_stream vt1708_pcm_analog_playback = {
1428 .substreams = 2,
1429 .channels_min = 2,
1430 .channels_max = 8,
1431 .nid = 0x10, /* NID to query formats and rates */
1432 .ops = {
1433 .open = via_playback_pcm_open,
1434 .prepare = via_playback_multi_pcm_prepare,
1435 .cleanup = via_playback_multi_pcm_cleanup
1439 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1440 .substreams = 2,
1441 .channels_min = 2,
1442 .channels_max = 8,
1443 .nid = 0x10, /* NID to query formats and rates */
1444 /* We got noisy outputs on the right channel on VT1708 when
1445 * 24bit samples are used. Until any workaround is found,
1446 * disable the 24bit format, so far.
1448 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1449 .ops = {
1450 .open = via_playback_pcm_open,
1451 .prepare = via_playback_multi_pcm_prepare,
1452 .cleanup = via_playback_multi_pcm_cleanup
1456 static const struct hda_pcm_stream vt1708_pcm_analog_capture = {
1457 .substreams = 2,
1458 .channels_min = 2,
1459 .channels_max = 2,
1460 .nid = 0x15, /* NID to query formats and rates */
1461 .ops = {
1462 .prepare = via_capture_pcm_prepare,
1463 .cleanup = via_capture_pcm_cleanup
1467 static const struct hda_pcm_stream vt1708_pcm_digital_playback = {
1468 .substreams = 1,
1469 .channels_min = 2,
1470 .channels_max = 2,
1471 /* NID is set in via_build_pcms */
1472 .ops = {
1473 .open = via_dig_playback_pcm_open,
1474 .close = via_dig_playback_pcm_close,
1475 .prepare = via_dig_playback_pcm_prepare,
1476 .cleanup = via_dig_playback_pcm_cleanup
1480 static const struct hda_pcm_stream vt1708_pcm_digital_capture = {
1481 .substreams = 1,
1482 .channels_min = 2,
1483 .channels_max = 2,
1486 static int via_build_controls(struct hda_codec *codec)
1488 struct via_spec *spec = codec->spec;
1489 struct snd_kcontrol *kctl;
1490 const struct snd_kcontrol_new *knew;
1491 int err, i;
1493 for (i = 0; i < spec->num_mixers; i++) {
1494 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1495 if (err < 0)
1496 return err;
1499 if (spec->multiout.dig_out_nid) {
1500 err = snd_hda_create_spdif_out_ctls(codec,
1501 spec->multiout.dig_out_nid);
1502 if (err < 0)
1503 return err;
1504 err = snd_hda_create_spdif_share_sw(codec,
1505 &spec->multiout);
1506 if (err < 0)
1507 return err;
1508 spec->multiout.share_spdif = 1;
1510 if (spec->dig_in_nid) {
1511 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1512 if (err < 0)
1513 return err;
1516 /* assign Capture Source enums to NID */
1517 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1518 for (i = 0; kctl && i < kctl->count; i++) {
1519 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1520 if (err < 0)
1521 return err;
1524 /* other nid->control mapping */
1525 for (i = 0; i < spec->num_mixers; i++) {
1526 for (knew = spec->mixers[i]; knew->name; knew++) {
1527 if (knew->iface != NID_MAPPING)
1528 continue;
1529 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1530 if (kctl == NULL)
1531 continue;
1532 err = snd_hda_add_nid(codec, kctl, 0,
1533 knew->subdevice);
1537 /* init power states */
1538 set_widgets_power_state(codec);
1539 analog_low_current_mode(codec, 1);
1541 via_free_kctls(codec); /* no longer needed */
1542 return 0;
1545 static int via_build_pcms(struct hda_codec *codec)
1547 struct via_spec *spec = codec->spec;
1548 struct hda_pcm *info = spec->pcm_rec;
1550 codec->num_pcms = 1;
1551 codec->pcm_info = info;
1553 info->name = spec->stream_name_analog;
1554 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1555 *(spec->stream_analog_playback);
1556 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1557 spec->multiout.dac_nids[0];
1558 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1559 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1561 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1562 spec->multiout.max_channels;
1564 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1565 codec->num_pcms++;
1566 info++;
1567 info->name = spec->stream_name_digital;
1568 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1569 if (spec->multiout.dig_out_nid) {
1570 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1571 *(spec->stream_digital_playback);
1572 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1573 spec->multiout.dig_out_nid;
1575 if (spec->dig_in_nid) {
1576 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1577 *(spec->stream_digital_capture);
1578 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1579 spec->dig_in_nid;
1583 return 0;
1586 static void via_free(struct hda_codec *codec)
1588 struct via_spec *spec = codec->spec;
1590 if (!spec)
1591 return;
1593 via_free_kctls(codec);
1594 vt1708_stop_hp_work(spec);
1595 kfree(codec->spec);
1598 /* mute internal speaker if HP is plugged */
1599 static void via_hp_automute(struct hda_codec *codec)
1601 unsigned int present = 0;
1602 struct via_spec *spec = codec->spec;
1604 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1606 if (!spec->hp_independent_mode) {
1607 struct snd_ctl_elem_id id;
1608 /* auto mute */
1609 snd_hda_codec_amp_stereo(
1610 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1611 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1612 /* notify change */
1613 memset(&id, 0, sizeof(id));
1614 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1615 strcpy(id.name, "Front Playback Switch");
1616 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1617 &id);
1621 /* mute mono out if HP or Line out is plugged */
1622 static void via_mono_automute(struct hda_codec *codec)
1624 unsigned int hp_present, lineout_present;
1625 struct via_spec *spec = codec->spec;
1627 if (spec->codec_type != VT1716S)
1628 return;
1630 lineout_present = snd_hda_jack_detect(codec,
1631 spec->autocfg.line_out_pins[0]);
1633 /* Mute Mono Out if Line Out is plugged */
1634 if (lineout_present) {
1635 snd_hda_codec_amp_stereo(
1636 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1637 return;
1640 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1642 if (!spec->hp_independent_mode)
1643 snd_hda_codec_amp_stereo(
1644 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1645 hp_present ? HDA_AMP_MUTE : 0);
1648 static void via_gpio_control(struct hda_codec *codec)
1650 unsigned int gpio_data;
1651 unsigned int vol_counter;
1652 unsigned int vol;
1653 unsigned int master_vol;
1655 struct via_spec *spec = codec->spec;
1657 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1658 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1660 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1661 0xF84, 0) & 0x3F0000) >> 16;
1663 vol = vol_counter & 0x1F;
1664 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1665 AC_VERB_GET_AMP_GAIN_MUTE,
1666 AC_AMP_GET_INPUT);
1668 if (gpio_data == 0x02) {
1669 /* unmute line out */
1670 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1671 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1673 if (vol_counter & 0x20) {
1674 /* decrease volume */
1675 if (vol > master_vol)
1676 vol = master_vol;
1677 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1678 0, HDA_AMP_VOLMASK,
1679 master_vol-vol);
1680 } else {
1681 /* increase volume */
1682 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1683 HDA_AMP_VOLMASK,
1684 ((master_vol+vol) > 0x2A) ? 0x2A :
1685 (master_vol+vol));
1687 } else if (!(gpio_data & 0x02)) {
1688 /* mute line out */
1689 snd_hda_codec_amp_stereo(codec,
1690 spec->autocfg.line_out_pins[0],
1691 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1692 HDA_AMP_MUTE);
1696 /* mute Internal-Speaker if HP is plugged */
1697 static void via_speaker_automute(struct hda_codec *codec)
1699 unsigned int hp_present;
1700 struct via_spec *spec = codec->spec;
1702 if (!VT2002P_COMPATIBLE(spec))
1703 return;
1705 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1707 if (!spec->hp_independent_mode) {
1708 struct snd_ctl_elem_id id;
1709 snd_hda_codec_amp_stereo(
1710 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
1711 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1712 /* notify change */
1713 memset(&id, 0, sizeof(id));
1714 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1715 strcpy(id.name, "Speaker Playback Switch");
1716 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1717 &id);
1721 /* mute line-out and internal speaker if HP is plugged */
1722 static void via_hp_bind_automute(struct hda_codec *codec)
1724 /* use long instead of int below just to avoid an internal compiler
1725 * error with gcc 4.0.x
1727 unsigned long hp_present, present = 0;
1728 struct via_spec *spec = codec->spec;
1729 int i;
1731 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1732 return;
1734 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1736 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
1738 if (!spec->hp_independent_mode) {
1739 /* Mute Line-Outs */
1740 for (i = 0; i < spec->autocfg.line_outs; i++)
1741 snd_hda_codec_amp_stereo(
1742 codec, spec->autocfg.line_out_pins[i],
1743 HDA_OUTPUT, 0,
1744 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1745 if (hp_present)
1746 present = hp_present;
1748 /* Speakers */
1749 for (i = 0; i < spec->autocfg.speaker_outs; i++)
1750 snd_hda_codec_amp_stereo(
1751 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
1752 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1756 /* unsolicited event for jack sensing */
1757 static void via_unsol_event(struct hda_codec *codec,
1758 unsigned int res)
1760 res >>= 26;
1762 if (res & VIA_JACK_EVENT)
1763 set_widgets_power_state(codec);
1765 res &= ~VIA_JACK_EVENT;
1767 if (res == VIA_HP_EVENT)
1768 via_hp_automute(codec);
1769 else if (res == VIA_GPIO_EVENT)
1770 via_gpio_control(codec);
1771 else if (res == VIA_MONO_EVENT)
1772 via_mono_automute(codec);
1773 else if (res == VIA_SPEAKER_EVENT)
1774 via_speaker_automute(codec);
1775 else if (res == VIA_BIND_HP_EVENT)
1776 via_hp_bind_automute(codec);
1779 static int via_init(struct hda_codec *codec)
1781 struct via_spec *spec = codec->spec;
1782 int i;
1783 for (i = 0; i < spec->num_iverbs; i++)
1784 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1786 /* Lydia Add for EAPD enable */
1787 if (!spec->dig_in_nid) { /* No Digital In connection */
1788 if (spec->dig_in_pin) {
1789 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1790 AC_VERB_SET_PIN_WIDGET_CONTROL,
1791 PIN_OUT);
1792 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1793 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1795 } else /* enable SPDIF-input pin */
1796 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1797 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1799 /* assign slave outs */
1800 if (spec->slave_dig_outs[0])
1801 codec->slave_dig_outs = spec->slave_dig_outs;
1803 return 0;
1806 #ifdef SND_HDA_NEEDS_RESUME
1807 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1809 struct via_spec *spec = codec->spec;
1810 vt1708_stop_hp_work(spec);
1811 return 0;
1813 #endif
1815 #ifdef CONFIG_SND_HDA_POWER_SAVE
1816 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1818 struct via_spec *spec = codec->spec;
1819 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1821 #endif
1825 static const struct hda_codec_ops via_patch_ops = {
1826 .build_controls = via_build_controls,
1827 .build_pcms = via_build_pcms,
1828 .init = via_init,
1829 .free = via_free,
1830 #ifdef SND_HDA_NEEDS_RESUME
1831 .suspend = via_suspend,
1832 #endif
1833 #ifdef CONFIG_SND_HDA_POWER_SAVE
1834 .check_power_status = via_check_power_status,
1835 #endif
1838 /* fill in the dac_nids table from the parsed pin configuration */
1839 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1840 const struct auto_pin_cfg *cfg)
1842 int i;
1843 hda_nid_t nid;
1845 spec->multiout.num_dacs = cfg->line_outs;
1847 spec->multiout.dac_nids = spec->private_dac_nids;
1849 for (i = 0; i < 4; i++) {
1850 nid = cfg->line_out_pins[i];
1851 if (nid) {
1852 /* config dac list */
1853 switch (i) {
1854 case AUTO_SEQ_FRONT:
1855 spec->private_dac_nids[i] = 0x10;
1856 break;
1857 case AUTO_SEQ_CENLFE:
1858 spec->private_dac_nids[i] = 0x12;
1859 break;
1860 case AUTO_SEQ_SURROUND:
1861 spec->private_dac_nids[i] = 0x11;
1862 break;
1863 case AUTO_SEQ_SIDE:
1864 spec->private_dac_nids[i] = 0x13;
1865 break;
1870 return 0;
1873 /* add playback controls from the parsed DAC table */
1874 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1875 const struct auto_pin_cfg *cfg)
1877 char name[32];
1878 static const char * const chname[4] = {
1879 "Front", "Surround", "C/LFE", "Side"
1881 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
1882 int i, err;
1884 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1885 nid = cfg->line_out_pins[i];
1887 if (!nid)
1888 continue;
1890 nid_vol = nid_vols[i];
1892 if (i == AUTO_SEQ_CENLFE) {
1893 /* Center/LFE */
1894 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1895 "Center Playback Volume",
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_VOL,
1901 "LFE Playback Volume",
1902 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1903 HDA_OUTPUT));
1904 if (err < 0)
1905 return err;
1906 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1907 "Center Playback Switch",
1908 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1909 HDA_OUTPUT));
1910 if (err < 0)
1911 return err;
1912 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1913 "LFE Playback Switch",
1914 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1915 HDA_OUTPUT));
1916 if (err < 0)
1917 return err;
1918 } else if (i == AUTO_SEQ_FRONT) {
1919 /* add control to mixer index 0 */
1920 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1921 "Master Front Playback Volume",
1922 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1923 HDA_INPUT));
1924 if (err < 0)
1925 return err;
1926 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1927 "Master Front Playback Switch",
1928 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1929 HDA_INPUT));
1930 if (err < 0)
1931 return err;
1933 /* add control to PW3 */
1934 sprintf(name, "%s Playback Volume", chname[i]);
1935 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1936 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1937 HDA_OUTPUT));
1938 if (err < 0)
1939 return err;
1940 sprintf(name, "%s Playback Switch", chname[i]);
1941 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1942 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1943 HDA_OUTPUT));
1944 if (err < 0)
1945 return err;
1946 } else {
1947 sprintf(name, "%s Playback Volume", chname[i]);
1948 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1949 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1950 HDA_OUTPUT));
1951 if (err < 0)
1952 return err;
1953 sprintf(name, "%s Playback Switch", chname[i]);
1954 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1955 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1956 HDA_OUTPUT));
1957 if (err < 0)
1958 return err;
1962 return 0;
1965 static void create_hp_imux(struct via_spec *spec)
1967 int i;
1968 struct hda_input_mux *imux = &spec->private_imux[1];
1969 static const char * const texts[] = { "OFF", "ON", NULL};
1971 /* for hp mode select */
1972 for (i = 0; texts[i]; i++)
1973 snd_hda_add_imux_item(imux, texts[i], i, NULL);
1975 spec->hp_mux = &spec->private_imux[1];
1978 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1980 int err;
1982 if (!pin)
1983 return 0;
1985 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1986 spec->hp_independent_mode_index = 1;
1988 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1989 "Headphone Playback Volume",
1990 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1991 if (err < 0)
1992 return err;
1993 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1994 "Headphone Playback Switch",
1995 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1996 if (err < 0)
1997 return err;
1999 create_hp_imux(spec);
2001 return 0;
2004 /* create playback/capture controls for input pins */
2005 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
2006 const struct auto_pin_cfg *cfg,
2007 hda_nid_t cap_nid,
2008 const hda_nid_t pin_idxs[],
2009 int num_idxs)
2011 struct via_spec *spec = codec->spec;
2012 struct hda_input_mux *imux = &spec->private_imux[0];
2013 int i, err, idx, type, type_idx = 0;
2015 /* for internal loopback recording select */
2016 for (idx = 0; idx < num_idxs; idx++) {
2017 if (pin_idxs[idx] == 0xff) {
2018 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2019 break;
2023 for (i = 0; i < cfg->num_inputs; i++) {
2024 const char *label;
2025 type = cfg->inputs[i].type;
2026 for (idx = 0; idx < num_idxs; idx++)
2027 if (pin_idxs[idx] == cfg->inputs[i].pin)
2028 break;
2029 if (idx >= num_idxs)
2030 continue;
2031 if (i > 0 && type == cfg->inputs[i - 1].type)
2032 type_idx++;
2033 else
2034 type_idx = 0;
2035 label = hda_get_autocfg_input_label(codec, cfg, i);
2036 if (spec->codec_type == VT1708S ||
2037 spec->codec_type == VT1702 ||
2038 spec->codec_type == VT1716S)
2039 err = via_new_analog_input(spec, label, type_idx,
2040 idx+1, cap_nid);
2041 else
2042 err = via_new_analog_input(spec, label, type_idx,
2043 idx, cap_nid);
2044 if (err < 0)
2045 return err;
2046 snd_hda_add_imux_item(imux, label, idx, NULL);
2048 return 0;
2051 /* create playback/capture controls for input pins */
2052 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2053 const struct auto_pin_cfg *cfg)
2055 static const hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2056 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
2057 ARRAY_SIZE(pin_idxs));
2060 #ifdef CONFIG_SND_HDA_POWER_SAVE
2061 static const struct hda_amp_list vt1708_loopbacks[] = {
2062 { 0x17, HDA_INPUT, 1 },
2063 { 0x17, HDA_INPUT, 2 },
2064 { 0x17, HDA_INPUT, 3 },
2065 { 0x17, HDA_INPUT, 4 },
2066 { } /* end */
2068 #endif
2070 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2072 unsigned int def_conf;
2073 unsigned char seqassoc;
2075 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2076 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2077 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2078 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2079 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2080 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2081 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2084 return;
2087 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2088 struct snd_ctl_elem_value *ucontrol)
2090 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2091 struct via_spec *spec = codec->spec;
2093 if (spec->codec_type != VT1708)
2094 return 0;
2095 spec->vt1708_jack_detectect =
2096 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2097 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2098 return 0;
2101 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2102 struct snd_ctl_elem_value *ucontrol)
2104 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2105 struct via_spec *spec = codec->spec;
2106 int change;
2108 if (spec->codec_type != VT1708)
2109 return 0;
2110 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2111 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2112 == !spec->vt1708_jack_detectect;
2113 if (spec->vt1708_jack_detectect) {
2114 mute_aa_path(codec, 1);
2115 notify_aa_path_ctls(codec);
2117 return change;
2120 static const struct snd_kcontrol_new vt1708_jack_detectect[] = {
2122 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2123 .name = "Jack Detect",
2124 .count = 1,
2125 .info = snd_ctl_boolean_mono_info,
2126 .get = vt1708_jack_detectect_get,
2127 .put = vt1708_jack_detectect_put,
2129 {} /* end */
2132 static int vt1708_parse_auto_config(struct hda_codec *codec)
2134 struct via_spec *spec = codec->spec;
2135 int err;
2137 /* Add HP and CD pin config connect bit re-config action */
2138 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2139 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2141 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2142 if (err < 0)
2143 return err;
2144 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2145 if (err < 0)
2146 return err;
2147 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2148 return 0; /* can't find valid BIOS pin config */
2150 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2151 if (err < 0)
2152 return err;
2153 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2154 if (err < 0)
2155 return err;
2156 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2157 if (err < 0)
2158 return err;
2159 /* add jack detect on/off control */
2160 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2161 if (err < 0)
2162 return err;
2164 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2166 if (spec->autocfg.dig_outs)
2167 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2168 spec->dig_in_pin = VT1708_DIGIN_PIN;
2169 if (spec->autocfg.dig_in_pin)
2170 spec->dig_in_nid = VT1708_DIGIN_NID;
2172 if (spec->kctls.list)
2173 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2175 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2177 spec->input_mux = &spec->private_imux[0];
2179 if (spec->hp_mux)
2180 via_hp_build(codec);
2182 via_smart51_build(spec);
2183 return 1;
2186 /* init callback for auto-configuration model -- overriding the default init */
2187 static int via_auto_init(struct hda_codec *codec)
2189 struct via_spec *spec = codec->spec;
2191 via_init(codec);
2192 via_auto_init_multi_out(codec);
2193 via_auto_init_hp_out(codec);
2194 via_auto_init_analog_input(codec);
2196 if (VT2002P_COMPATIBLE(spec)) {
2197 via_hp_bind_automute(codec);
2198 } else {
2199 via_hp_automute(codec);
2200 via_speaker_automute(codec);
2203 return 0;
2206 static void vt1708_update_hp_jack_state(struct work_struct *work)
2208 struct via_spec *spec = container_of(work, struct via_spec,
2209 vt1708_hp_work.work);
2210 if (spec->codec_type != VT1708)
2211 return;
2212 /* if jack state toggled */
2213 if (spec->vt1708_hp_present
2214 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2215 spec->vt1708_hp_present ^= 1;
2216 via_hp_automute(spec->codec);
2218 vt1708_start_hp_work(spec);
2221 static int get_mux_nids(struct hda_codec *codec)
2223 struct via_spec *spec = codec->spec;
2224 hda_nid_t nid, conn[8];
2225 unsigned int type;
2226 int i, n;
2228 for (i = 0; i < spec->num_adc_nids; i++) {
2229 nid = spec->adc_nids[i];
2230 while (nid) {
2231 type = get_wcaps_type(get_wcaps(codec, nid));
2232 if (type == AC_WID_PIN)
2233 break;
2234 n = snd_hda_get_connections(codec, nid, conn,
2235 ARRAY_SIZE(conn));
2236 if (n <= 0)
2237 break;
2238 if (n > 1) {
2239 spec->mux_nids[i] = nid;
2240 break;
2242 nid = conn[0];
2245 return 0;
2248 static int patch_vt1708(struct hda_codec *codec)
2250 struct via_spec *spec;
2251 int err;
2253 /* create a codec specific record */
2254 spec = via_new_spec(codec);
2255 if (spec == NULL)
2256 return -ENOMEM;
2258 /* automatic parse from the BIOS config */
2259 err = vt1708_parse_auto_config(codec);
2260 if (err < 0) {
2261 via_free(codec);
2262 return err;
2263 } else if (!err) {
2264 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2265 "from BIOS. Using genenic mode...\n");
2269 spec->stream_name_analog = "VT1708 Analog";
2270 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2271 /* disable 32bit format on VT1708 */
2272 if (codec->vendor_id == 0x11061708)
2273 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2274 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2276 spec->stream_name_digital = "VT1708 Digital";
2277 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2278 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2281 if (!spec->adc_nids && spec->input_mux) {
2282 spec->adc_nids = vt1708_adc_nids;
2283 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2284 get_mux_nids(codec);
2285 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2286 spec->num_mixers++;
2289 codec->patch_ops = via_patch_ops;
2291 codec->patch_ops.init = via_auto_init;
2292 #ifdef CONFIG_SND_HDA_POWER_SAVE
2293 spec->loopback.amplist = vt1708_loopbacks;
2294 #endif
2295 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2296 return 0;
2299 /* capture mixer elements */
2300 static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
2301 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2302 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2303 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2304 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2305 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2306 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2308 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2309 /* The multiple "Capture Source" controls confuse alsamixer
2310 * So call somewhat different..
2312 /* .name = "Capture Source", */
2313 .name = "Input Source",
2314 .count = 1,
2315 .info = via_mux_enum_info,
2316 .get = via_mux_enum_get,
2317 .put = via_mux_enum_put,
2319 { } /* end */
2322 static const struct hda_verb vt1709_uniwill_init_verbs[] = {
2323 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2324 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2329 * generic initialization of ADC, input mixers and output mixers
2331 static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2333 * Unmute ADC0-2 and set the default input to mic-in
2335 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2336 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2337 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2340 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2341 * mixer widget
2343 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2344 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2345 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2346 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2347 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2348 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2351 * Set up output selector (0x1a, 0x1b, 0x29)
2353 /* set vol=0 to output mixers */
2354 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2355 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2356 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2359 * Unmute PW3 and PW4
2361 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2362 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2364 /* Set input of PW4 as MW0 */
2365 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2366 /* PW9 Output enable */
2367 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2371 static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2372 .substreams = 1,
2373 .channels_min = 2,
2374 .channels_max = 10,
2375 .nid = 0x10, /* NID to query formats and rates */
2376 .ops = {
2377 .open = via_playback_pcm_open,
2378 .prepare = via_playback_multi_pcm_prepare,
2379 .cleanup = via_playback_multi_pcm_cleanup,
2383 static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2384 .substreams = 1,
2385 .channels_min = 2,
2386 .channels_max = 6,
2387 .nid = 0x10, /* NID to query formats and rates */
2388 .ops = {
2389 .open = via_playback_pcm_open,
2390 .prepare = via_playback_multi_pcm_prepare,
2391 .cleanup = via_playback_multi_pcm_cleanup,
2395 static const struct hda_pcm_stream vt1709_pcm_analog_capture = {
2396 .substreams = 2,
2397 .channels_min = 2,
2398 .channels_max = 2,
2399 .nid = 0x14, /* NID to query formats and rates */
2400 .ops = {
2401 .prepare = via_capture_pcm_prepare,
2402 .cleanup = via_capture_pcm_cleanup
2406 static const struct hda_pcm_stream vt1709_pcm_digital_playback = {
2407 .substreams = 1,
2408 .channels_min = 2,
2409 .channels_max = 2,
2410 /* NID is set in via_build_pcms */
2411 .ops = {
2412 .open = via_dig_playback_pcm_open,
2413 .close = via_dig_playback_pcm_close
2417 static const struct hda_pcm_stream vt1709_pcm_digital_capture = {
2418 .substreams = 1,
2419 .channels_min = 2,
2420 .channels_max = 2,
2423 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2424 const struct auto_pin_cfg *cfg)
2426 int i;
2427 hda_nid_t nid;
2429 if (cfg->line_outs == 4) /* 10 channels */
2430 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2431 else if (cfg->line_outs == 3) /* 6 channels */
2432 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2434 spec->multiout.dac_nids = spec->private_dac_nids;
2436 if (cfg->line_outs == 4) { /* 10 channels */
2437 for (i = 0; i < cfg->line_outs; i++) {
2438 nid = cfg->line_out_pins[i];
2439 if (nid) {
2440 /* config dac list */
2441 switch (i) {
2442 case AUTO_SEQ_FRONT:
2443 /* AOW0 */
2444 spec->private_dac_nids[i] = 0x10;
2445 break;
2446 case AUTO_SEQ_CENLFE:
2447 /* AOW2 */
2448 spec->private_dac_nids[i] = 0x12;
2449 break;
2450 case AUTO_SEQ_SURROUND:
2451 /* AOW3 */
2452 spec->private_dac_nids[i] = 0x11;
2453 break;
2454 case AUTO_SEQ_SIDE:
2455 /* AOW1 */
2456 spec->private_dac_nids[i] = 0x27;
2457 break;
2458 default:
2459 break;
2463 spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2465 } else if (cfg->line_outs == 3) { /* 6 channels */
2466 for (i = 0; i < cfg->line_outs; i++) {
2467 nid = cfg->line_out_pins[i];
2468 if (nid) {
2469 /* config dac list */
2470 switch (i) {
2471 case AUTO_SEQ_FRONT:
2472 /* AOW0 */
2473 spec->private_dac_nids[i] = 0x10;
2474 break;
2475 case AUTO_SEQ_CENLFE:
2476 /* AOW2 */
2477 spec->private_dac_nids[i] = 0x12;
2478 break;
2479 case AUTO_SEQ_SURROUND:
2480 /* AOW1 */
2481 spec->private_dac_nids[i] = 0x11;
2482 break;
2483 default:
2484 break;
2490 return 0;
2493 /* add playback controls from the parsed DAC table */
2494 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2495 const struct auto_pin_cfg *cfg)
2497 char name[32];
2498 static const char * const chname[4] = {
2499 "Front", "Surround", "C/LFE", "Side"
2501 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2502 int i, err;
2504 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2505 nid = cfg->line_out_pins[i];
2507 if (!nid)
2508 continue;
2510 nid_vol = nid_vols[i];
2512 if (i == AUTO_SEQ_CENLFE) {
2513 /* Center/LFE */
2514 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2515 "Center Playback Volume",
2516 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2517 HDA_OUTPUT));
2518 if (err < 0)
2519 return err;
2520 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2521 "LFE Playback Volume",
2522 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2523 HDA_OUTPUT));
2524 if (err < 0)
2525 return err;
2526 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2527 "Center Playback Switch",
2528 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2529 HDA_OUTPUT));
2530 if (err < 0)
2531 return err;
2532 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2533 "LFE Playback Switch",
2534 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2535 HDA_OUTPUT));
2536 if (err < 0)
2537 return err;
2538 } else if (i == AUTO_SEQ_FRONT) {
2539 /* ADD control to mixer index 0 */
2540 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2541 "Master Front Playback Volume",
2542 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2543 HDA_INPUT));
2544 if (err < 0)
2545 return err;
2546 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2547 "Master Front Playback Switch",
2548 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2549 HDA_INPUT));
2550 if (err < 0)
2551 return err;
2553 /* add control to PW3 */
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, 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, 3, 0,
2563 HDA_OUTPUT));
2564 if (err < 0)
2565 return err;
2566 } else if (i == AUTO_SEQ_SURROUND) {
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;
2579 } else if (i == AUTO_SEQ_SIDE) {
2580 sprintf(name, "%s Playback Volume", chname[i]);
2581 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2582 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2583 HDA_OUTPUT));
2584 if (err < 0)
2585 return err;
2586 sprintf(name, "%s Playback Switch", chname[i]);
2587 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2588 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2589 HDA_OUTPUT));
2590 if (err < 0)
2591 return err;
2595 return 0;
2598 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2600 int err;
2602 if (!pin)
2603 return 0;
2605 if (spec->multiout.num_dacs == 5) /* 10 channels */
2606 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2607 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2608 spec->multiout.hp_nid = 0;
2609 spec->hp_independent_mode_index = 1;
2611 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2612 "Headphone Playback Volume",
2613 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2614 if (err < 0)
2615 return err;
2616 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2617 "Headphone Playback Switch",
2618 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2619 if (err < 0)
2620 return err;
2622 return 0;
2625 /* create playback/capture controls for input pins */
2626 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
2627 const struct auto_pin_cfg *cfg)
2629 static const hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
2630 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
2631 ARRAY_SIZE(pin_idxs));
2634 static int vt1709_parse_auto_config(struct hda_codec *codec)
2636 struct via_spec *spec = codec->spec;
2637 int err;
2639 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2640 if (err < 0)
2641 return err;
2642 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2643 if (err < 0)
2644 return err;
2645 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2646 return 0; /* can't find valid BIOS pin config */
2648 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2649 if (err < 0)
2650 return err;
2651 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2652 if (err < 0)
2653 return err;
2654 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
2655 if (err < 0)
2656 return err;
2658 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2660 if (spec->autocfg.dig_outs)
2661 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
2662 spec->dig_in_pin = VT1709_DIGIN_PIN;
2663 if (spec->autocfg.dig_in_pin)
2664 spec->dig_in_nid = VT1709_DIGIN_NID;
2666 if (spec->kctls.list)
2667 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2669 spec->input_mux = &spec->private_imux[0];
2671 if (spec->hp_mux)
2672 via_hp_build(codec);
2674 via_smart51_build(spec);
2675 return 1;
2678 #ifdef CONFIG_SND_HDA_POWER_SAVE
2679 static const struct hda_amp_list vt1709_loopbacks[] = {
2680 { 0x18, HDA_INPUT, 1 },
2681 { 0x18, HDA_INPUT, 2 },
2682 { 0x18, HDA_INPUT, 3 },
2683 { 0x18, HDA_INPUT, 4 },
2684 { } /* end */
2686 #endif
2688 static int patch_vt1709_10ch(struct hda_codec *codec)
2690 struct via_spec *spec;
2691 int err;
2693 /* create a codec specific record */
2694 spec = via_new_spec(codec);
2695 if (spec == NULL)
2696 return -ENOMEM;
2698 err = vt1709_parse_auto_config(codec);
2699 if (err < 0) {
2700 via_free(codec);
2701 return err;
2702 } else if (!err) {
2703 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2704 "Using genenic mode...\n");
2707 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2708 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2710 spec->stream_name_analog = "VT1709 Analog";
2711 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2712 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2714 spec->stream_name_digital = "VT1709 Digital";
2715 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2716 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2719 if (!spec->adc_nids && spec->input_mux) {
2720 spec->adc_nids = vt1709_adc_nids;
2721 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
2722 get_mux_nids(codec);
2723 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2724 spec->num_mixers++;
2727 codec->patch_ops = via_patch_ops;
2729 codec->patch_ops.init = via_auto_init;
2730 codec->patch_ops.unsol_event = via_unsol_event;
2731 #ifdef CONFIG_SND_HDA_POWER_SAVE
2732 spec->loopback.amplist = vt1709_loopbacks;
2733 #endif
2735 return 0;
2738 * generic initialization of ADC, input mixers and output mixers
2740 static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
2742 * Unmute ADC0-2 and set the default input to mic-in
2744 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2745 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2746 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2749 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2750 * mixer widget
2752 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2753 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2754 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2755 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2756 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2757 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2760 * Set up output selector (0x1a, 0x1b, 0x29)
2762 /* set vol=0 to output mixers */
2763 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2764 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2765 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2768 * Unmute PW3 and PW4
2770 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2771 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2773 /* Set input of PW4 as MW0 */
2774 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2775 /* PW9 Output enable */
2776 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2780 static int patch_vt1709_6ch(struct hda_codec *codec)
2782 struct via_spec *spec;
2783 int err;
2785 /* create a codec specific record */
2786 spec = via_new_spec(codec);
2787 if (spec == NULL)
2788 return -ENOMEM;
2790 err = vt1709_parse_auto_config(codec);
2791 if (err < 0) {
2792 via_free(codec);
2793 return err;
2794 } else if (!err) {
2795 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2796 "Using genenic mode...\n");
2799 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2800 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2802 spec->stream_name_analog = "VT1709 Analog";
2803 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2804 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2806 spec->stream_name_digital = "VT1709 Digital";
2807 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2808 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2811 if (!spec->adc_nids && spec->input_mux) {
2812 spec->adc_nids = vt1709_adc_nids;
2813 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
2814 get_mux_nids(codec);
2815 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2816 spec->num_mixers++;
2819 codec->patch_ops = via_patch_ops;
2821 codec->patch_ops.init = via_auto_init;
2822 codec->patch_ops.unsol_event = via_unsol_event;
2823 #ifdef CONFIG_SND_HDA_POWER_SAVE
2824 spec->loopback.amplist = vt1709_loopbacks;
2825 #endif
2826 return 0;
2829 /* capture mixer elements */
2830 static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
2831 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2832 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2833 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2834 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2836 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2837 /* The multiple "Capture Source" controls confuse alsamixer
2838 * So call somewhat different..
2840 /* .name = "Capture Source", */
2841 .name = "Input Source",
2842 .count = 1,
2843 .info = via_mux_enum_info,
2844 .get = via_mux_enum_get,
2845 .put = via_mux_enum_put,
2847 { } /* end */
2850 * generic initialization of ADC, input mixers and output mixers
2852 static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2854 * Unmute ADC0-1 and set the default input to mic-in
2856 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2857 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2860 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2861 * mixer widget
2863 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2864 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2865 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2866 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2867 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2868 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2871 * Set up output mixers
2873 /* set vol=0 to output mixers */
2874 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2875 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2876 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2878 /* Setup default input to PW4 */
2879 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2880 /* PW9 Output enable */
2881 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2882 /* PW10 Input enable */
2883 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2887 static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2889 * Unmute ADC0-1 and set the default input to mic-in
2891 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2892 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2895 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2896 * mixer widget
2898 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2899 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2900 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2901 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2902 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2903 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2906 * Set up output mixers
2908 /* set vol=0 to output mixers */
2909 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2910 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2911 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2913 /* Setup default input of PW4 to MW0 */
2914 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2915 /* PW9 Output enable */
2916 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2917 /* PW10 Input enable */
2918 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2922 static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
2923 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2924 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2925 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2926 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2927 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2928 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2929 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2930 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2931 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2935 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2936 struct hda_codec *codec,
2937 struct snd_pcm_substream *substream)
2939 int idle = substream->pstr->substream_opened == 1
2940 && substream->ref_count == 0;
2942 analog_low_current_mode(codec, idle);
2943 return 0;
2946 static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2947 .substreams = 2,
2948 .channels_min = 2,
2949 .channels_max = 8,
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,
2955 .close = via_pcm_open_close
2959 static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
2960 .substreams = 2,
2961 .channels_min = 2,
2962 .channels_max = 4,
2963 .nid = 0x10, /* NID to query formats and rates */
2964 .ops = {
2965 .open = via_playback_pcm_open,
2966 .prepare = via_playback_multi_pcm_prepare,
2967 .cleanup = via_playback_multi_pcm_cleanup
2971 static const struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2972 .substreams = 2,
2973 .channels_min = 2,
2974 .channels_max = 2,
2975 .nid = 0x13, /* NID to query formats and rates */
2976 .ops = {
2977 .open = via_pcm_open_close,
2978 .prepare = via_capture_pcm_prepare,
2979 .cleanup = via_capture_pcm_cleanup,
2980 .close = via_pcm_open_close
2984 static const struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2985 .substreams = 1,
2986 .channels_min = 2,
2987 .channels_max = 2,
2988 /* NID is set in via_build_pcms */
2989 .ops = {
2990 .open = via_dig_playback_pcm_open,
2991 .close = via_dig_playback_pcm_close,
2992 .prepare = via_dig_playback_pcm_prepare,
2993 .cleanup = via_dig_playback_pcm_cleanup
2997 static const struct hda_pcm_stream vt1708B_pcm_digital_capture = {
2998 .substreams = 1,
2999 .channels_min = 2,
3000 .channels_max = 2,
3003 /* fill in the dac_nids table from the parsed pin configuration */
3004 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3005 const struct auto_pin_cfg *cfg)
3007 int i;
3008 hda_nid_t nid;
3010 spec->multiout.num_dacs = cfg->line_outs;
3012 spec->multiout.dac_nids = spec->private_dac_nids;
3014 for (i = 0; i < 4; i++) {
3015 nid = cfg->line_out_pins[i];
3016 if (nid) {
3017 /* config dac list */
3018 switch (i) {
3019 case AUTO_SEQ_FRONT:
3020 spec->private_dac_nids[i] = 0x10;
3021 break;
3022 case AUTO_SEQ_CENLFE:
3023 spec->private_dac_nids[i] = 0x24;
3024 break;
3025 case AUTO_SEQ_SURROUND:
3026 spec->private_dac_nids[i] = 0x11;
3027 break;
3028 case AUTO_SEQ_SIDE:
3029 spec->private_dac_nids[i] = 0x25;
3030 break;
3035 return 0;
3038 /* add playback controls from the parsed DAC table */
3039 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3040 const struct auto_pin_cfg *cfg)
3042 char name[32];
3043 static const char * const chname[4] = {
3044 "Front", "Surround", "C/LFE", "Side"
3046 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3047 hda_nid_t nid, nid_vol = 0;
3048 int i, err;
3050 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3051 nid = cfg->line_out_pins[i];
3053 if (!nid)
3054 continue;
3056 nid_vol = nid_vols[i];
3058 if (i == AUTO_SEQ_CENLFE) {
3059 /* Center/LFE */
3060 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3061 "Center Playback Volume",
3062 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3063 HDA_OUTPUT));
3064 if (err < 0)
3065 return err;
3066 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3067 "LFE Playback Volume",
3068 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3069 HDA_OUTPUT));
3070 if (err < 0)
3071 return err;
3072 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3073 "Center Playback Switch",
3074 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3075 HDA_OUTPUT));
3076 if (err < 0)
3077 return err;
3078 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3079 "LFE Playback Switch",
3080 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3081 HDA_OUTPUT));
3082 if (err < 0)
3083 return err;
3084 } else if (i == AUTO_SEQ_FRONT) {
3085 /* add control to mixer index 0 */
3086 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3087 "Master Front Playback Volume",
3088 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3089 HDA_INPUT));
3090 if (err < 0)
3091 return err;
3092 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3093 "Master Front Playback Switch",
3094 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3095 HDA_INPUT));
3096 if (err < 0)
3097 return err;
3099 /* add control to PW3 */
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, 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, 3, 0,
3109 HDA_OUTPUT));
3110 if (err < 0)
3111 return err;
3112 } else {
3113 sprintf(name, "%s Playback Volume", chname[i]);
3114 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3115 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3116 HDA_OUTPUT));
3117 if (err < 0)
3118 return err;
3119 sprintf(name, "%s Playback Switch", chname[i]);
3120 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3121 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3122 HDA_OUTPUT));
3123 if (err < 0)
3124 return err;
3128 return 0;
3131 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3133 int err;
3135 if (!pin)
3136 return 0;
3138 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3139 spec->hp_independent_mode_index = 1;
3141 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3142 "Headphone Playback Volume",
3143 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3144 if (err < 0)
3145 return err;
3146 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3147 "Headphone Playback Switch",
3148 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3149 if (err < 0)
3150 return err;
3152 create_hp_imux(spec);
3154 return 0;
3157 /* create playback/capture controls for input pins */
3158 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3159 const struct auto_pin_cfg *cfg)
3161 static const hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3162 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3163 ARRAY_SIZE(pin_idxs));
3166 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3168 struct via_spec *spec = codec->spec;
3169 int err;
3171 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3172 if (err < 0)
3173 return err;
3174 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3175 if (err < 0)
3176 return err;
3177 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3178 return 0; /* can't find valid BIOS pin config */
3180 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3181 if (err < 0)
3182 return err;
3183 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3184 if (err < 0)
3185 return err;
3186 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3187 if (err < 0)
3188 return err;
3190 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3192 if (spec->autocfg.dig_outs)
3193 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3194 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3195 if (spec->autocfg.dig_in_pin)
3196 spec->dig_in_nid = VT1708B_DIGIN_NID;
3198 if (spec->kctls.list)
3199 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3201 spec->input_mux = &spec->private_imux[0];
3203 if (spec->hp_mux)
3204 via_hp_build(codec);
3206 via_smart51_build(spec);
3207 return 1;
3210 #ifdef CONFIG_SND_HDA_POWER_SAVE
3211 static const struct hda_amp_list vt1708B_loopbacks[] = {
3212 { 0x16, HDA_INPUT, 1 },
3213 { 0x16, HDA_INPUT, 2 },
3214 { 0x16, HDA_INPUT, 3 },
3215 { 0x16, HDA_INPUT, 4 },
3216 { } /* end */
3218 #endif
3220 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3222 struct via_spec *spec = codec->spec;
3223 int imux_is_smixer;
3224 unsigned int parm;
3225 int is_8ch = 0;
3226 if ((spec->codec_type != VT1708B_4CH) &&
3227 (codec->vendor_id != 0x11064397))
3228 is_8ch = 1;
3230 /* SW0 (17h) = stereo mixer */
3231 imux_is_smixer =
3232 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3233 == ((spec->codec_type == VT1708S) ? 5 : 0));
3234 /* inputs */
3235 /* PW 1/2/5 (1ah/1bh/1eh) */
3236 parm = AC_PWRST_D3;
3237 set_pin_power_state(codec, 0x1a, &parm);
3238 set_pin_power_state(codec, 0x1b, &parm);
3239 set_pin_power_state(codec, 0x1e, &parm);
3240 if (imux_is_smixer)
3241 parm = AC_PWRST_D0;
3242 /* SW0 (17h), AIW 0/1 (13h/14h) */
3243 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3244 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3245 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3247 /* outputs */
3248 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3249 parm = AC_PWRST_D3;
3250 set_pin_power_state(codec, 0x19, &parm);
3251 if (spec->smart51_enabled)
3252 set_pin_power_state(codec, 0x1b, &parm);
3253 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3254 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3256 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3257 if (is_8ch) {
3258 parm = AC_PWRST_D3;
3259 set_pin_power_state(codec, 0x22, &parm);
3260 if (spec->smart51_enabled)
3261 set_pin_power_state(codec, 0x1a, &parm);
3262 snd_hda_codec_write(codec, 0x26, 0,
3263 AC_VERB_SET_POWER_STATE, parm);
3264 snd_hda_codec_write(codec, 0x24, 0,
3265 AC_VERB_SET_POWER_STATE, parm);
3266 } else if (codec->vendor_id == 0x11064397) {
3267 /* PW7(23h), SW2(27h), AOW2(25h) */
3268 parm = AC_PWRST_D3;
3269 set_pin_power_state(codec, 0x23, &parm);
3270 if (spec->smart51_enabled)
3271 set_pin_power_state(codec, 0x1a, &parm);
3272 snd_hda_codec_write(codec, 0x27, 0,
3273 AC_VERB_SET_POWER_STATE, parm);
3274 snd_hda_codec_write(codec, 0x25, 0,
3275 AC_VERB_SET_POWER_STATE, parm);
3278 /* PW 3/4/7 (1ch/1dh/23h) */
3279 parm = AC_PWRST_D3;
3280 /* force to D0 for internal Speaker */
3281 set_pin_power_state(codec, 0x1c, &parm);
3282 set_pin_power_state(codec, 0x1d, &parm);
3283 if (is_8ch)
3284 set_pin_power_state(codec, 0x23, &parm);
3286 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3287 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3288 imux_is_smixer ? AC_PWRST_D0 : parm);
3289 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3290 if (is_8ch) {
3291 snd_hda_codec_write(codec, 0x25, 0,
3292 AC_VERB_SET_POWER_STATE, parm);
3293 snd_hda_codec_write(codec, 0x27, 0,
3294 AC_VERB_SET_POWER_STATE, parm);
3295 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3296 snd_hda_codec_write(codec, 0x25, 0,
3297 AC_VERB_SET_POWER_STATE, parm);
3300 static int patch_vt1708S(struct hda_codec *codec);
3301 static int patch_vt1708B_8ch(struct hda_codec *codec)
3303 struct via_spec *spec;
3304 int err;
3306 if (get_codec_type(codec) == VT1708BCE)
3307 return patch_vt1708S(codec);
3308 /* create a codec specific record */
3309 spec = via_new_spec(codec);
3310 if (spec == NULL)
3311 return -ENOMEM;
3313 /* automatic parse from the BIOS config */
3314 err = vt1708B_parse_auto_config(codec);
3315 if (err < 0) {
3316 via_free(codec);
3317 return err;
3318 } else if (!err) {
3319 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3320 "from BIOS. Using genenic mode...\n");
3323 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3324 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3326 spec->stream_name_analog = "VT1708B Analog";
3327 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3328 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3330 spec->stream_name_digital = "VT1708B Digital";
3331 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3332 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3334 if (!spec->adc_nids && spec->input_mux) {
3335 spec->adc_nids = vt1708B_adc_nids;
3336 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3337 get_mux_nids(codec);
3338 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3339 spec->num_mixers++;
3342 codec->patch_ops = via_patch_ops;
3344 codec->patch_ops.init = via_auto_init;
3345 codec->patch_ops.unsol_event = via_unsol_event;
3346 #ifdef CONFIG_SND_HDA_POWER_SAVE
3347 spec->loopback.amplist = vt1708B_loopbacks;
3348 #endif
3350 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3352 return 0;
3355 static int patch_vt1708B_4ch(struct hda_codec *codec)
3357 struct via_spec *spec;
3358 int err;
3360 /* create a codec specific record */
3361 spec = via_new_spec(codec);
3362 if (spec == NULL)
3363 return -ENOMEM;
3365 /* automatic parse from the BIOS config */
3366 err = vt1708B_parse_auto_config(codec);
3367 if (err < 0) {
3368 via_free(codec);
3369 return err;
3370 } else if (!err) {
3371 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3372 "from BIOS. Using genenic mode...\n");
3375 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3376 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3378 spec->stream_name_analog = "VT1708B Analog";
3379 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3380 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3382 spec->stream_name_digital = "VT1708B Digital";
3383 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3384 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3386 if (!spec->adc_nids && spec->input_mux) {
3387 spec->adc_nids = vt1708B_adc_nids;
3388 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3389 get_mux_nids(codec);
3390 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3391 spec->num_mixers++;
3394 codec->patch_ops = via_patch_ops;
3396 codec->patch_ops.init = via_auto_init;
3397 codec->patch_ops.unsol_event = via_unsol_event;
3398 #ifdef CONFIG_SND_HDA_POWER_SAVE
3399 spec->loopback.amplist = vt1708B_loopbacks;
3400 #endif
3402 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3404 return 0;
3407 /* Patch for VT1708S */
3409 /* capture mixer elements */
3410 static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3411 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3412 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3413 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3414 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3415 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3416 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3417 HDA_INPUT),
3419 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3420 /* The multiple "Capture Source" controls confuse alsamixer
3421 * So call somewhat different..
3423 /* .name = "Capture Source", */
3424 .name = "Input Source",
3425 .count = 1,
3426 .info = via_mux_enum_info,
3427 .get = via_mux_enum_get,
3428 .put = via_mux_enum_put,
3430 { } /* end */
3433 static const struct hda_verb vt1708S_volume_init_verbs[] = {
3434 /* Unmute ADC0-1 and set the default input to mic-in */
3435 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3436 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3438 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3439 * analog-loopback mixer widget */
3440 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3441 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3442 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3443 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3444 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3445 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3447 /* Setup default input of PW4 to MW0 */
3448 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3449 /* PW9, PW10 Output enable */
3450 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3451 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3452 /* Enable Mic Boost Volume backdoor */
3453 {0x1, 0xf98, 0x1},
3454 /* don't bybass mixer */
3455 {0x1, 0xf88, 0xc0},
3459 static const struct hda_verb vt1708S_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 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3468 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3472 static const struct hda_verb vt1705_uniwill_init_verbs[] = {
3473 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3474 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3475 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3476 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3477 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3478 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3479 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3480 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3484 static const struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3485 .substreams = 2,
3486 .channels_min = 2,
3487 .channels_max = 8,
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 const struct hda_pcm_stream vt1705_pcm_analog_playback = {
3498 .substreams = 2,
3499 .channels_min = 2,
3500 .channels_max = 6,
3501 .nid = 0x10, /* NID to query formats and rates */
3502 .ops = {
3503 .open = via_playback_pcm_open,
3504 .prepare = via_playback_multi_pcm_prepare,
3505 .cleanup = via_playback_multi_pcm_cleanup,
3506 .close = via_pcm_open_close
3510 static const struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3511 .substreams = 2,
3512 .channels_min = 2,
3513 .channels_max = 2,
3514 .nid = 0x13, /* NID to query formats and rates */
3515 .ops = {
3516 .open = via_pcm_open_close,
3517 .prepare = via_capture_pcm_prepare,
3518 .cleanup = via_capture_pcm_cleanup,
3519 .close = via_pcm_open_close
3523 static const struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3524 .substreams = 1,
3525 .channels_min = 2,
3526 .channels_max = 2,
3527 /* NID is set in via_build_pcms */
3528 .ops = {
3529 .open = via_dig_playback_pcm_open,
3530 .close = via_dig_playback_pcm_close,
3531 .prepare = via_dig_playback_pcm_prepare,
3532 .cleanup = via_dig_playback_pcm_cleanup
3536 /* fill in the dac_nids table from the parsed pin configuration */
3537 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3538 const struct auto_pin_cfg *cfg)
3540 int i;
3541 hda_nid_t nid;
3543 spec->multiout.num_dacs = cfg->line_outs;
3545 spec->multiout.dac_nids = spec->private_dac_nids;
3547 for (i = 0; i < 4; i++) {
3548 nid = cfg->line_out_pins[i];
3549 if (nid) {
3550 /* config dac list */
3551 switch (i) {
3552 case AUTO_SEQ_FRONT:
3553 spec->private_dac_nids[i] = 0x10;
3554 break;
3555 case AUTO_SEQ_CENLFE:
3556 if (spec->codec->vendor_id == 0x11064397)
3557 spec->private_dac_nids[i] = 0x25;
3558 else
3559 spec->private_dac_nids[i] = 0x24;
3560 break;
3561 case AUTO_SEQ_SURROUND:
3562 spec->private_dac_nids[i] = 0x11;
3563 break;
3564 case AUTO_SEQ_SIDE:
3565 spec->private_dac_nids[i] = 0x25;
3566 break;
3571 /* for Smart 5.1, line/mic inputs double as output pins */
3572 if (cfg->line_outs == 1) {
3573 spec->multiout.num_dacs = 3;
3574 spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3575 if (spec->codec->vendor_id == 0x11064397)
3576 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25;
3577 else
3578 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3581 return 0;
3584 /* add playback controls from the parsed DAC table */
3585 static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
3586 const struct auto_pin_cfg *cfg)
3588 struct via_spec *spec = codec->spec;
3589 char name[32];
3590 static const char * const chname[4] = {
3591 "Front", "Surround", "C/LFE", "Side"
3593 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3594 {0x10, 0x11, 0x25, 0} };
3595 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3596 {0x1C, 0x18, 0x27, 0} };
3597 hda_nid_t nid, nid_vol, nid_mute;
3598 int i, err;
3600 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3601 nid = cfg->line_out_pins[i];
3603 /* for Smart 5.1, there are always at least six channels */
3604 if (!nid && i > AUTO_SEQ_CENLFE)
3605 continue;
3607 if (codec->vendor_id == 0x11064397) {
3608 nid_vol = nid_vols[1][i];
3609 nid_mute = nid_mutes[1][i];
3610 } else {
3611 nid_vol = nid_vols[0][i];
3612 nid_mute = nid_mutes[0][i];
3614 if (!nid_vol && !nid_mute)
3615 continue;
3617 if (i == AUTO_SEQ_CENLFE) {
3618 /* Center/LFE */
3619 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3620 "Center Playback Volume",
3621 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3622 HDA_OUTPUT));
3623 if (err < 0)
3624 return err;
3625 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3626 "LFE Playback Volume",
3627 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3628 HDA_OUTPUT));
3629 if (err < 0)
3630 return err;
3631 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3632 "Center Playback Switch",
3633 HDA_COMPOSE_AMP_VAL(nid_mute,
3634 1, 0,
3635 HDA_OUTPUT));
3636 if (err < 0)
3637 return err;
3638 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3639 "LFE Playback Switch",
3640 HDA_COMPOSE_AMP_VAL(nid_mute,
3641 2, 0,
3642 HDA_OUTPUT));
3643 if (err < 0)
3644 return err;
3645 } else if (i == AUTO_SEQ_FRONT) {
3646 /* add control to mixer index 0 */
3647 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3648 "Master Front Playback Volume",
3649 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3650 HDA_INPUT));
3651 if (err < 0)
3652 return err;
3653 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3654 "Master Front Playback Switch",
3655 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3656 HDA_INPUT));
3657 if (err < 0)
3658 return err;
3660 /* Front */
3661 sprintf(name, "%s Playback Volume", chname[i]);
3662 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3663 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3664 HDA_OUTPUT));
3665 if (err < 0)
3666 return err;
3667 sprintf(name, "%s Playback Switch", chname[i]);
3668 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3669 HDA_COMPOSE_AMP_VAL(nid_mute,
3670 3, 0,
3671 HDA_OUTPUT));
3672 if (err < 0)
3673 return err;
3674 } else {
3675 sprintf(name, "%s Playback Volume", chname[i]);
3676 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3677 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3678 HDA_OUTPUT));
3679 if (err < 0)
3680 return err;
3681 sprintf(name, "%s Playback Switch", chname[i]);
3682 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3683 HDA_COMPOSE_AMP_VAL(nid_mute,
3684 3, 0,
3685 HDA_OUTPUT));
3686 if (err < 0)
3687 return err;
3691 return 0;
3694 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3696 int err;
3698 if (!pin)
3699 return 0;
3701 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3702 spec->hp_independent_mode_index = 1;
3704 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3705 "Headphone Playback Volume",
3706 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3707 if (err < 0)
3708 return err;
3710 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3711 "Headphone Playback Switch",
3712 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3713 if (err < 0)
3714 return err;
3716 create_hp_imux(spec);
3718 return 0;
3721 /* create playback/capture controls for input pins */
3722 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
3723 const struct auto_pin_cfg *cfg)
3725 static const hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
3726 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3727 ARRAY_SIZE(pin_idxs));
3730 /* fill out digital output widgets; one for master and one for slave outputs */
3731 static void fill_dig_outs(struct hda_codec *codec)
3733 struct via_spec *spec = codec->spec;
3734 int i;
3736 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3737 hda_nid_t nid;
3738 int conn;
3740 nid = spec->autocfg.dig_out_pins[i];
3741 if (!nid)
3742 continue;
3743 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3744 if (conn < 1)
3745 continue;
3746 if (!spec->multiout.dig_out_nid)
3747 spec->multiout.dig_out_nid = nid;
3748 else {
3749 spec->slave_dig_outs[0] = nid;
3750 break; /* at most two dig outs */
3755 static int vt1708S_parse_auto_config(struct hda_codec *codec)
3757 struct via_spec *spec = codec->spec;
3758 int err;
3760 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3761 if (err < 0)
3762 return err;
3763 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3764 if (err < 0)
3765 return err;
3766 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3767 return 0; /* can't find valid BIOS pin config */
3769 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
3770 if (err < 0)
3771 return err;
3772 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3773 if (err < 0)
3774 return err;
3775 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
3776 if (err < 0)
3777 return err;
3779 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3781 fill_dig_outs(codec);
3783 if (spec->kctls.list)
3784 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3786 spec->input_mux = &spec->private_imux[0];
3788 if (spec->hp_mux)
3789 via_hp_build(codec);
3791 via_smart51_build(spec);
3792 return 1;
3795 #ifdef CONFIG_SND_HDA_POWER_SAVE
3796 static const struct hda_amp_list vt1708S_loopbacks[] = {
3797 { 0x16, HDA_INPUT, 1 },
3798 { 0x16, HDA_INPUT, 2 },
3799 { 0x16, HDA_INPUT, 3 },
3800 { 0x16, HDA_INPUT, 4 },
3801 { } /* end */
3803 #endif
3805 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3806 int offset, int num_steps, int step_size)
3808 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3809 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3810 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3811 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3812 (0 << AC_AMPCAP_MUTE_SHIFT));
3815 static int patch_vt1708S(struct hda_codec *codec)
3817 struct via_spec *spec;
3818 int err;
3820 /* create a codec specific record */
3821 spec = via_new_spec(codec);
3822 if (spec == NULL)
3823 return -ENOMEM;
3825 /* automatic parse from the BIOS config */
3826 err = vt1708S_parse_auto_config(codec);
3827 if (err < 0) {
3828 via_free(codec);
3829 return err;
3830 } else if (!err) {
3831 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3832 "from BIOS. Using genenic mode...\n");
3835 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
3836 if (codec->vendor_id == 0x11064397)
3837 spec->init_verbs[spec->num_iverbs++] =
3838 vt1705_uniwill_init_verbs;
3839 else
3840 spec->init_verbs[spec->num_iverbs++] =
3841 vt1708S_uniwill_init_verbs;
3843 if (codec->vendor_id == 0x11060440)
3844 spec->stream_name_analog = "VT1818S Analog";
3845 else if (codec->vendor_id == 0x11064397)
3846 spec->stream_name_analog = "VT1705 Analog";
3847 else
3848 spec->stream_name_analog = "VT1708S Analog";
3849 if (codec->vendor_id == 0x11064397)
3850 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3851 else
3852 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
3853 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3855 if (codec->vendor_id == 0x11060440)
3856 spec->stream_name_digital = "VT1818S Digital";
3857 else if (codec->vendor_id == 0x11064397)
3858 spec->stream_name_digital = "VT1705 Digital";
3859 else
3860 spec->stream_name_digital = "VT1708S Digital";
3861 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3863 if (!spec->adc_nids && spec->input_mux) {
3864 spec->adc_nids = vt1708S_adc_nids;
3865 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
3866 get_mux_nids(codec);
3867 override_mic_boost(codec, 0x1a, 0, 3, 40);
3868 override_mic_boost(codec, 0x1e, 0, 3, 40);
3869 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3870 spec->num_mixers++;
3873 codec->patch_ops = via_patch_ops;
3875 codec->patch_ops.init = via_auto_init;
3876 codec->patch_ops.unsol_event = via_unsol_event;
3877 #ifdef CONFIG_SND_HDA_POWER_SAVE
3878 spec->loopback.amplist = vt1708S_loopbacks;
3879 #endif
3881 /* correct names for VT1708BCE */
3882 if (get_codec_type(codec) == VT1708BCE) {
3883 kfree(codec->chip_name);
3884 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3885 snprintf(codec->bus->card->mixername,
3886 sizeof(codec->bus->card->mixername),
3887 "%s %s", codec->vendor_name, codec->chip_name);
3888 spec->stream_name_analog = "VT1708BCE Analog";
3889 spec->stream_name_digital = "VT1708BCE Digital";
3891 /* correct names for VT1818S */
3892 if (codec->vendor_id == 0x11060440) {
3893 spec->stream_name_analog = "VT1818S Analog";
3894 spec->stream_name_digital = "VT1818S Digital";
3896 /* correct names for VT1705 */
3897 if (codec->vendor_id == 0x11064397) {
3898 kfree(codec->chip_name);
3899 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3900 snprintf(codec->bus->card->mixername,
3901 sizeof(codec->bus->card->mixername),
3902 "%s %s", codec->vendor_name, codec->chip_name);
3904 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3905 return 0;
3908 /* Patch for VT1702 */
3910 /* capture mixer elements */
3911 static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
3912 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3913 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3914 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3915 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3916 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3917 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3918 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3919 HDA_INPUT),
3921 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3922 /* The multiple "Capture Source" controls confuse alsamixer
3923 * So call somewhat different..
3925 /* .name = "Capture Source", */
3926 .name = "Input Source",
3927 .count = 1,
3928 .info = via_mux_enum_info,
3929 .get = via_mux_enum_get,
3930 .put = via_mux_enum_put,
3932 { } /* end */
3935 static const struct hda_verb vt1702_volume_init_verbs[] = {
3937 * Unmute ADC0-1 and set the default input to mic-in
3939 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3940 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3941 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3944 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3945 * mixer widget
3947 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3948 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3949 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3950 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3951 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3952 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3954 /* Setup default input of PW4 to MW0 */
3955 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3956 /* PW6 PW7 Output enable */
3957 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3958 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3959 /* mixer enable */
3960 {0x1, 0xF88, 0x3},
3961 /* GPIO 0~2 */
3962 {0x1, 0xF82, 0x3F},
3966 static const struct hda_verb vt1702_uniwill_init_verbs[] = {
3967 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3968 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3969 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3970 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3971 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3972 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3976 static const struct hda_pcm_stream vt1702_pcm_analog_playback = {
3977 .substreams = 2,
3978 .channels_min = 2,
3979 .channels_max = 2,
3980 .nid = 0x10, /* NID to query formats and rates */
3981 .ops = {
3982 .open = via_playback_pcm_open,
3983 .prepare = via_playback_multi_pcm_prepare,
3984 .cleanup = via_playback_multi_pcm_cleanup,
3985 .close = via_pcm_open_close
3989 static const struct hda_pcm_stream vt1702_pcm_analog_capture = {
3990 .substreams = 3,
3991 .channels_min = 2,
3992 .channels_max = 2,
3993 .nid = 0x12, /* NID to query formats and rates */
3994 .ops = {
3995 .open = via_pcm_open_close,
3996 .prepare = via_capture_pcm_prepare,
3997 .cleanup = via_capture_pcm_cleanup,
3998 .close = via_pcm_open_close
4002 static const struct hda_pcm_stream vt1702_pcm_digital_playback = {
4003 .substreams = 2,
4004 .channels_min = 2,
4005 .channels_max = 2,
4006 /* NID is set in via_build_pcms */
4007 .ops = {
4008 .open = via_dig_playback_pcm_open,
4009 .close = via_dig_playback_pcm_close,
4010 .prepare = via_dig_playback_pcm_prepare,
4011 .cleanup = via_dig_playback_pcm_cleanup
4015 /* fill in the dac_nids table from the parsed pin configuration */
4016 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4017 const struct auto_pin_cfg *cfg)
4019 spec->multiout.num_dacs = 1;
4020 spec->multiout.dac_nids = spec->private_dac_nids;
4022 if (cfg->line_out_pins[0]) {
4023 /* config dac list */
4024 spec->private_dac_nids[0] = 0x10;
4027 return 0;
4030 /* add playback controls from the parsed DAC table */
4031 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4032 const struct auto_pin_cfg *cfg)
4034 int err;
4036 if (!cfg->line_out_pins[0])
4037 return -1;
4039 /* add control to mixer index 0 */
4040 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4041 "Master Front Playback Volume",
4042 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4043 if (err < 0)
4044 return err;
4045 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4046 "Master Front Playback Switch",
4047 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4048 if (err < 0)
4049 return err;
4051 /* Front */
4052 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4053 "Front Playback Volume",
4054 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4055 if (err < 0)
4056 return err;
4057 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4058 "Front Playback Switch",
4059 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4060 if (err < 0)
4061 return err;
4063 return 0;
4066 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4068 int err, i;
4069 struct hda_input_mux *imux;
4070 static const char * const texts[] = { "ON", "OFF", NULL};
4071 if (!pin)
4072 return 0;
4073 spec->multiout.hp_nid = 0x1D;
4074 spec->hp_independent_mode_index = 0;
4076 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4077 "Headphone Playback Volume",
4078 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4079 if (err < 0)
4080 return err;
4082 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4083 "Headphone Playback Switch",
4084 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4085 if (err < 0)
4086 return err;
4088 imux = &spec->private_imux[1];
4090 /* for hp mode select */
4091 for (i = 0; texts[i]; i++)
4092 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4094 spec->hp_mux = &spec->private_imux[1];
4095 return 0;
4098 /* create playback/capture controls for input pins */
4099 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4100 const struct auto_pin_cfg *cfg)
4102 static const hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4103 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
4104 ARRAY_SIZE(pin_idxs));
4107 static int vt1702_parse_auto_config(struct hda_codec *codec)
4109 struct via_spec *spec = codec->spec;
4110 int err;
4112 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4113 if (err < 0)
4114 return err;
4115 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4116 if (err < 0)
4117 return err;
4118 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4119 return 0; /* can't find valid BIOS pin config */
4121 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4122 if (err < 0)
4123 return err;
4124 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4125 if (err < 0)
4126 return err;
4127 /* limit AA path volume to 0 dB */
4128 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4129 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4130 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4131 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4132 (1 << AC_AMPCAP_MUTE_SHIFT));
4133 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4134 if (err < 0)
4135 return err;
4137 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4139 fill_dig_outs(codec);
4141 if (spec->kctls.list)
4142 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4144 spec->input_mux = &spec->private_imux[0];
4146 if (spec->hp_mux)
4147 via_hp_build(codec);
4149 return 1;
4152 #ifdef CONFIG_SND_HDA_POWER_SAVE
4153 static const struct hda_amp_list vt1702_loopbacks[] = {
4154 { 0x1A, HDA_INPUT, 1 },
4155 { 0x1A, HDA_INPUT, 2 },
4156 { 0x1A, HDA_INPUT, 3 },
4157 { 0x1A, HDA_INPUT, 4 },
4158 { } /* end */
4160 #endif
4162 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4164 int imux_is_smixer =
4165 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4166 unsigned int parm;
4167 /* inputs */
4168 /* PW 1/2/5 (14h/15h/18h) */
4169 parm = AC_PWRST_D3;
4170 set_pin_power_state(codec, 0x14, &parm);
4171 set_pin_power_state(codec, 0x15, &parm);
4172 set_pin_power_state(codec, 0x18, &parm);
4173 if (imux_is_smixer)
4174 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4175 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4176 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4177 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4178 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4179 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4181 /* outputs */
4182 /* PW 3/4 (16h/17h) */
4183 parm = AC_PWRST_D3;
4184 set_pin_power_state(codec, 0x17, &parm);
4185 set_pin_power_state(codec, 0x16, &parm);
4186 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4187 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4188 imux_is_smixer ? AC_PWRST_D0 : parm);
4189 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4190 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4193 static int patch_vt1702(struct hda_codec *codec)
4195 struct via_spec *spec;
4196 int err;
4198 /* create a codec specific record */
4199 spec = via_new_spec(codec);
4200 if (spec == NULL)
4201 return -ENOMEM;
4203 /* automatic parse from the BIOS config */
4204 err = vt1702_parse_auto_config(codec);
4205 if (err < 0) {
4206 via_free(codec);
4207 return err;
4208 } else if (!err) {
4209 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4210 "from BIOS. Using genenic mode...\n");
4213 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4214 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4216 spec->stream_name_analog = "VT1702 Analog";
4217 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4218 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4220 spec->stream_name_digital = "VT1702 Digital";
4221 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4223 if (!spec->adc_nids && spec->input_mux) {
4224 spec->adc_nids = vt1702_adc_nids;
4225 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4226 get_mux_nids(codec);
4227 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4228 spec->num_mixers++;
4231 codec->patch_ops = via_patch_ops;
4233 codec->patch_ops.init = via_auto_init;
4234 codec->patch_ops.unsol_event = via_unsol_event;
4235 #ifdef CONFIG_SND_HDA_POWER_SAVE
4236 spec->loopback.amplist = vt1702_loopbacks;
4237 #endif
4239 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
4240 return 0;
4243 /* Patch for VT1718S */
4245 /* capture mixer elements */
4246 static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4247 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4248 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4249 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4250 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4251 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4252 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4253 HDA_INPUT),
4255 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4256 /* The multiple "Capture Source" controls confuse alsamixer
4257 * So call somewhat different..
4259 .name = "Input Source",
4260 .count = 2,
4261 .info = via_mux_enum_info,
4262 .get = via_mux_enum_get,
4263 .put = via_mux_enum_put,
4265 { } /* end */
4268 static const struct hda_verb vt1718S_volume_init_verbs[] = {
4270 * Unmute ADC0-1 and set the default input to mic-in
4272 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4273 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4275 /* Enable MW0 adjust Gain 5 */
4276 {0x1, 0xfb2, 0x10},
4277 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4278 * mixer widget
4280 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4281 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4282 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4283 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4284 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4285 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
4287 /* Setup default input of Front HP to MW9 */
4288 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4289 /* PW9 PW10 Output enable */
4290 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4291 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4292 /* PW11 Input enable */
4293 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4294 /* Enable Boost Volume backdoor */
4295 {0x1, 0xf88, 0x8},
4296 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4297 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4298 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4299 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4300 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4301 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4302 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4303 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4304 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4305 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4306 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4307 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4308 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4309 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4310 /* Unmute MW4's index 0 */
4311 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4316 static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
4317 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4318 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4319 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4320 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4321 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4322 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4323 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4324 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4325 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4329 static const struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4330 .substreams = 2,
4331 .channels_min = 2,
4332 .channels_max = 10,
4333 .nid = 0x8, /* NID to query formats and rates */
4334 .ops = {
4335 .open = via_playback_pcm_open,
4336 .prepare = via_playback_multi_pcm_prepare,
4337 .cleanup = via_playback_multi_pcm_cleanup,
4338 .close = via_pcm_open_close,
4342 static const struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4343 .substreams = 2,
4344 .channels_min = 2,
4345 .channels_max = 2,
4346 .nid = 0x10, /* NID to query formats and rates */
4347 .ops = {
4348 .open = via_pcm_open_close,
4349 .prepare = via_capture_pcm_prepare,
4350 .cleanup = via_capture_pcm_cleanup,
4351 .close = via_pcm_open_close,
4355 static const struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4356 .substreams = 2,
4357 .channels_min = 2,
4358 .channels_max = 2,
4359 /* NID is set in via_build_pcms */
4360 .ops = {
4361 .open = via_dig_playback_pcm_open,
4362 .close = via_dig_playback_pcm_close,
4363 .prepare = via_dig_playback_pcm_prepare,
4364 .cleanup = via_dig_playback_pcm_cleanup
4368 static const struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4369 .substreams = 1,
4370 .channels_min = 2,
4371 .channels_max = 2,
4374 /* fill in the dac_nids table from the parsed pin configuration */
4375 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4376 const struct auto_pin_cfg *cfg)
4378 int i;
4379 hda_nid_t nid;
4381 spec->multiout.num_dacs = cfg->line_outs;
4383 spec->multiout.dac_nids = spec->private_dac_nids;
4385 for (i = 0; i < 4; i++) {
4386 nid = cfg->line_out_pins[i];
4387 if (nid) {
4388 /* config dac list */
4389 switch (i) {
4390 case AUTO_SEQ_FRONT:
4391 spec->private_dac_nids[i] = 0x8;
4392 break;
4393 case AUTO_SEQ_CENLFE:
4394 spec->private_dac_nids[i] = 0xa;
4395 break;
4396 case AUTO_SEQ_SURROUND:
4397 spec->private_dac_nids[i] = 0x9;
4398 break;
4399 case AUTO_SEQ_SIDE:
4400 spec->private_dac_nids[i] = 0xb;
4401 break;
4406 return 0;
4409 /* add playback controls from the parsed DAC table */
4410 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4411 const struct auto_pin_cfg *cfg)
4413 char name[32];
4414 static const char * const chname[4] = {
4415 "Front", "Surround", "C/LFE", "Side"
4417 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4418 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4419 hda_nid_t nid, nid_vol, nid_mute = 0;
4420 int i, err;
4422 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4423 nid = cfg->line_out_pins[i];
4425 if (!nid)
4426 continue;
4427 nid_vol = nid_vols[i];
4428 nid_mute = nid_mutes[i];
4430 if (i == AUTO_SEQ_CENLFE) {
4431 /* Center/LFE */
4432 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4433 "Center Playback Volume",
4434 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4435 HDA_OUTPUT));
4436 if (err < 0)
4437 return err;
4438 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4439 "LFE Playback Volume",
4440 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4441 HDA_OUTPUT));
4442 if (err < 0)
4443 return err;
4444 err = via_add_control(
4445 spec, VIA_CTL_WIDGET_MUTE,
4446 "Center Playback Switch",
4447 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4448 HDA_OUTPUT));
4449 if (err < 0)
4450 return err;
4451 err = via_add_control(
4452 spec, VIA_CTL_WIDGET_MUTE,
4453 "LFE Playback Switch",
4454 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4455 HDA_OUTPUT));
4456 if (err < 0)
4457 return err;
4458 } else if (i == AUTO_SEQ_FRONT) {
4459 /* Front */
4460 sprintf(name, "%s Playback Volume", chname[i]);
4461 err = via_add_control(
4462 spec, VIA_CTL_WIDGET_VOL, name,
4463 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4464 if (err < 0)
4465 return err;
4466 sprintf(name, "%s Playback Switch", chname[i]);
4467 err = via_add_control(
4468 spec, VIA_CTL_WIDGET_MUTE, name,
4469 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4470 HDA_OUTPUT));
4471 if (err < 0)
4472 return err;
4473 } else {
4474 sprintf(name, "%s Playback Volume", chname[i]);
4475 err = via_add_control(
4476 spec, VIA_CTL_WIDGET_VOL, name,
4477 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4478 if (err < 0)
4479 return err;
4480 sprintf(name, "%s Playback Switch", chname[i]);
4481 err = via_add_control(
4482 spec, VIA_CTL_WIDGET_MUTE, name,
4483 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4484 HDA_OUTPUT));
4485 if (err < 0)
4486 return err;
4489 return 0;
4492 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4494 int err;
4496 if (!pin)
4497 return 0;
4499 spec->multiout.hp_nid = 0xc; /* AOW4 */
4500 spec->hp_independent_mode_index = 1;
4502 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4503 "Headphone Playback Volume",
4504 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4505 if (err < 0)
4506 return err;
4508 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4509 "Headphone Playback Switch",
4510 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4511 if (err < 0)
4512 return err;
4514 create_hp_imux(spec);
4515 return 0;
4518 /* create playback/capture controls for input pins */
4519 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4520 const struct auto_pin_cfg *cfg)
4522 static const hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4523 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
4524 ARRAY_SIZE(pin_idxs));
4527 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4529 struct via_spec *spec = codec->spec;
4530 int err;
4532 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4534 if (err < 0)
4535 return err;
4536 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4537 if (err < 0)
4538 return err;
4539 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4540 return 0; /* can't find valid BIOS pin config */
4542 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4543 if (err < 0)
4544 return err;
4545 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4546 if (err < 0)
4547 return err;
4548 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4549 if (err < 0)
4550 return err;
4552 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4554 fill_dig_outs(codec);
4556 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4557 spec->dig_in_nid = 0x13;
4559 if (spec->kctls.list)
4560 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4562 spec->input_mux = &spec->private_imux[0];
4564 if (spec->hp_mux)
4565 via_hp_build(codec);
4567 via_smart51_build(spec);
4569 return 1;
4572 #ifdef CONFIG_SND_HDA_POWER_SAVE
4573 static const struct hda_amp_list vt1718S_loopbacks[] = {
4574 { 0x21, HDA_INPUT, 1 },
4575 { 0x21, HDA_INPUT, 2 },
4576 { 0x21, HDA_INPUT, 3 },
4577 { 0x21, HDA_INPUT, 4 },
4578 { } /* end */
4580 #endif
4582 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4584 struct via_spec *spec = codec->spec;
4585 int imux_is_smixer;
4586 unsigned int parm;
4587 /* MUX6 (1eh) = stereo mixer */
4588 imux_is_smixer =
4589 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4590 /* inputs */
4591 /* PW 5/6/7 (29h/2ah/2bh) */
4592 parm = AC_PWRST_D3;
4593 set_pin_power_state(codec, 0x29, &parm);
4594 set_pin_power_state(codec, 0x2a, &parm);
4595 set_pin_power_state(codec, 0x2b, &parm);
4596 if (imux_is_smixer)
4597 parm = AC_PWRST_D0;
4598 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4599 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4600 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4601 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4602 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4604 /* outputs */
4605 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4606 parm = AC_PWRST_D3;
4607 set_pin_power_state(codec, 0x27, &parm);
4608 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4609 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4611 /* PW2 (26h), AOW2 (ah) */
4612 parm = AC_PWRST_D3;
4613 set_pin_power_state(codec, 0x26, &parm);
4614 if (spec->smart51_enabled)
4615 set_pin_power_state(codec, 0x2b, &parm);
4616 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4618 /* PW0 (24h), AOW0 (8h) */
4619 parm = AC_PWRST_D3;
4620 set_pin_power_state(codec, 0x24, &parm);
4621 if (!spec->hp_independent_mode) /* check for redirected HP */
4622 set_pin_power_state(codec, 0x28, &parm);
4623 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4624 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4625 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4626 imux_is_smixer ? AC_PWRST_D0 : parm);
4628 /* PW1 (25h), AOW1 (9h) */
4629 parm = AC_PWRST_D3;
4630 set_pin_power_state(codec, 0x25, &parm);
4631 if (spec->smart51_enabled)
4632 set_pin_power_state(codec, 0x2a, &parm);
4633 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4635 if (spec->hp_independent_mode) {
4636 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4637 parm = AC_PWRST_D3;
4638 set_pin_power_state(codec, 0x28, &parm);
4639 snd_hda_codec_write(codec, 0x1b, 0,
4640 AC_VERB_SET_POWER_STATE, parm);
4641 snd_hda_codec_write(codec, 0x34, 0,
4642 AC_VERB_SET_POWER_STATE, parm);
4643 snd_hda_codec_write(codec, 0xc, 0,
4644 AC_VERB_SET_POWER_STATE, parm);
4648 static int patch_vt1718S(struct hda_codec *codec)
4650 struct via_spec *spec;
4651 int err;
4653 /* create a codec specific record */
4654 spec = via_new_spec(codec);
4655 if (spec == NULL)
4656 return -ENOMEM;
4658 /* automatic parse from the BIOS config */
4659 err = vt1718S_parse_auto_config(codec);
4660 if (err < 0) {
4661 via_free(codec);
4662 return err;
4663 } else if (!err) {
4664 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4665 "from BIOS. Using genenic mode...\n");
4668 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4669 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4671 if (codec->vendor_id == 0x11060441)
4672 spec->stream_name_analog = "VT2020 Analog";
4673 else if (codec->vendor_id == 0x11064441)
4674 spec->stream_name_analog = "VT1828S Analog";
4675 else
4676 spec->stream_name_analog = "VT1718S Analog";
4677 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4678 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4680 if (codec->vendor_id == 0x11060441)
4681 spec->stream_name_digital = "VT2020 Digital";
4682 else if (codec->vendor_id == 0x11064441)
4683 spec->stream_name_digital = "VT1828S Digital";
4684 else
4685 spec->stream_name_digital = "VT1718S Digital";
4686 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4687 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4688 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4690 if (!spec->adc_nids && spec->input_mux) {
4691 spec->adc_nids = vt1718S_adc_nids;
4692 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4693 get_mux_nids(codec);
4694 override_mic_boost(codec, 0x2b, 0, 3, 40);
4695 override_mic_boost(codec, 0x29, 0, 3, 40);
4696 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4697 spec->num_mixers++;
4700 codec->patch_ops = via_patch_ops;
4702 codec->patch_ops.init = via_auto_init;
4703 codec->patch_ops.unsol_event = via_unsol_event;
4705 #ifdef CONFIG_SND_HDA_POWER_SAVE
4706 spec->loopback.amplist = vt1718S_loopbacks;
4707 #endif
4709 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4711 return 0;
4714 /* Patch for VT1716S */
4716 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4717 struct snd_ctl_elem_info *uinfo)
4719 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4720 uinfo->count = 1;
4721 uinfo->value.integer.min = 0;
4722 uinfo->value.integer.max = 1;
4723 return 0;
4726 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4727 struct snd_ctl_elem_value *ucontrol)
4729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4730 int index = 0;
4732 index = snd_hda_codec_read(codec, 0x26, 0,
4733 AC_VERB_GET_CONNECT_SEL, 0);
4734 if (index != -1)
4735 *ucontrol->value.integer.value = index;
4737 return 0;
4740 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4741 struct snd_ctl_elem_value *ucontrol)
4743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4744 struct via_spec *spec = codec->spec;
4745 int index = *ucontrol->value.integer.value;
4747 snd_hda_codec_write(codec, 0x26, 0,
4748 AC_VERB_SET_CONNECT_SEL, index);
4749 spec->dmic_enabled = index;
4750 set_widgets_power_state(codec);
4751 return 1;
4754 /* capture mixer elements */
4755 static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4756 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4757 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4758 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4759 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4760 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4761 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4762 HDA_INPUT),
4764 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4765 .name = "Input Source",
4766 .count = 1,
4767 .info = via_mux_enum_info,
4768 .get = via_mux_enum_get,
4769 .put = via_mux_enum_put,
4771 { } /* end */
4774 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4775 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4777 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4778 .name = "Digital Mic Capture Switch",
4779 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4780 .count = 1,
4781 .info = vt1716s_dmic_info,
4782 .get = vt1716s_dmic_get,
4783 .put = vt1716s_dmic_put,
4785 {} /* end */
4789 /* mono-out mixer elements */
4790 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4791 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4792 { } /* end */
4795 static const struct hda_verb vt1716S_volume_init_verbs[] = {
4797 * Unmute ADC0-1 and set the default input to mic-in
4799 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4800 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4803 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4804 * mixer widget
4806 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4807 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4808 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4809 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4810 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4811 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4813 /* MUX Indices: Stereo Mixer = 5 */
4814 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4816 /* Setup default input of PW4 to MW0 */
4817 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4819 /* Setup default input of SW1 as MW0 */
4820 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4822 /* Setup default input of SW4 as AOW0 */
4823 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4825 /* PW9 PW10 Output enable */
4826 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4827 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4829 /* Unmute SW1, PW12 */
4830 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4831 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4832 /* PW12 Output enable */
4833 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4834 /* Enable Boost Volume backdoor */
4835 {0x1, 0xf8a, 0x80},
4836 /* don't bybass mixer */
4837 {0x1, 0xf88, 0xc0},
4838 /* Enable mono output */
4839 {0x1, 0xf90, 0x08},
4844 static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
4845 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4846 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4847 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4848 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4849 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4850 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4851 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4852 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4853 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4857 static const struct hda_pcm_stream vt1716S_pcm_analog_playback = {
4858 .substreams = 2,
4859 .channels_min = 2,
4860 .channels_max = 6,
4861 .nid = 0x10, /* NID to query formats and rates */
4862 .ops = {
4863 .open = via_playback_pcm_open,
4864 .prepare = via_playback_multi_pcm_prepare,
4865 .cleanup = via_playback_multi_pcm_cleanup,
4866 .close = via_pcm_open_close,
4870 static const struct hda_pcm_stream vt1716S_pcm_analog_capture = {
4871 .substreams = 2,
4872 .channels_min = 2,
4873 .channels_max = 2,
4874 .nid = 0x13, /* NID to query formats and rates */
4875 .ops = {
4876 .open = via_pcm_open_close,
4877 .prepare = via_capture_pcm_prepare,
4878 .cleanup = via_capture_pcm_cleanup,
4879 .close = via_pcm_open_close,
4883 static const struct hda_pcm_stream vt1716S_pcm_digital_playback = {
4884 .substreams = 2,
4885 .channels_min = 2,
4886 .channels_max = 2,
4887 /* NID is set in via_build_pcms */
4888 .ops = {
4889 .open = via_dig_playback_pcm_open,
4890 .close = via_dig_playback_pcm_close,
4891 .prepare = via_dig_playback_pcm_prepare,
4892 .cleanup = via_dig_playback_pcm_cleanup
4896 /* fill in the dac_nids table from the parsed pin configuration */
4897 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4898 const struct auto_pin_cfg *cfg)
4899 { int i;
4900 hda_nid_t nid;
4902 spec->multiout.num_dacs = cfg->line_outs;
4904 spec->multiout.dac_nids = spec->private_dac_nids;
4906 for (i = 0; i < 3; i++) {
4907 nid = cfg->line_out_pins[i];
4908 if (nid) {
4909 /* config dac list */
4910 switch (i) {
4911 case AUTO_SEQ_FRONT:
4912 spec->private_dac_nids[i] = 0x10;
4913 break;
4914 case AUTO_SEQ_CENLFE:
4915 spec->private_dac_nids[i] = 0x25;
4916 break;
4917 case AUTO_SEQ_SURROUND:
4918 spec->private_dac_nids[i] = 0x11;
4919 break;
4924 return 0;
4927 /* add playback controls from the parsed DAC table */
4928 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4929 const struct auto_pin_cfg *cfg)
4931 char name[32];
4932 static const char * const chname[3] = {
4933 "Front", "Surround", "C/LFE"
4935 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4936 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4937 hda_nid_t nid, nid_vol, nid_mute;
4938 int i, err;
4940 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4941 nid = cfg->line_out_pins[i];
4943 if (!nid)
4944 continue;
4946 nid_vol = nid_vols[i];
4947 nid_mute = nid_mutes[i];
4949 if (i == AUTO_SEQ_CENLFE) {
4950 err = via_add_control(
4951 spec, VIA_CTL_WIDGET_VOL,
4952 "Center Playback Volume",
4953 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
4954 if (err < 0)
4955 return err;
4956 err = via_add_control(
4957 spec, VIA_CTL_WIDGET_VOL,
4958 "LFE Playback Volume",
4959 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
4960 if (err < 0)
4961 return err;
4962 err = via_add_control(
4963 spec, VIA_CTL_WIDGET_MUTE,
4964 "Center Playback Switch",
4965 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4966 HDA_OUTPUT));
4967 if (err < 0)
4968 return err;
4969 err = via_add_control(
4970 spec, VIA_CTL_WIDGET_MUTE,
4971 "LFE Playback Switch",
4972 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4973 HDA_OUTPUT));
4974 if (err < 0)
4975 return err;
4976 } else if (i == AUTO_SEQ_FRONT) {
4978 err = via_add_control(
4979 spec, VIA_CTL_WIDGET_VOL,
4980 "Master Front Playback Volume",
4981 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4982 if (err < 0)
4983 return err;
4984 err = via_add_control(
4985 spec, VIA_CTL_WIDGET_MUTE,
4986 "Master Front Playback Switch",
4987 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4988 if (err < 0)
4989 return err;
4991 sprintf(name, "%s Playback Volume", chname[i]);
4992 err = via_add_control(
4993 spec, VIA_CTL_WIDGET_VOL, name,
4994 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4995 if (err < 0)
4996 return err;
4997 sprintf(name, "%s Playback Switch", chname[i]);
4998 err = via_add_control(
4999 spec, VIA_CTL_WIDGET_MUTE, name,
5000 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5001 HDA_OUTPUT));
5002 if (err < 0)
5003 return err;
5004 } else {
5005 sprintf(name, "%s Playback Volume", chname[i]);
5006 err = via_add_control(
5007 spec, VIA_CTL_WIDGET_VOL, name,
5008 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5009 if (err < 0)
5010 return err;
5011 sprintf(name, "%s Playback Switch", chname[i]);
5012 err = via_add_control(
5013 spec, VIA_CTL_WIDGET_MUTE, name,
5014 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5015 HDA_OUTPUT));
5016 if (err < 0)
5017 return err;
5020 return 0;
5023 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5025 int err;
5027 if (!pin)
5028 return 0;
5030 spec->multiout.hp_nid = 0x25; /* AOW3 */
5031 spec->hp_independent_mode_index = 1;
5033 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5034 "Headphone Playback Volume",
5035 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5036 if (err < 0)
5037 return err;
5039 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5040 "Headphone Playback Switch",
5041 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5042 if (err < 0)
5043 return err;
5045 create_hp_imux(spec);
5046 return 0;
5049 /* create playback/capture controls for input pins */
5050 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5051 const struct auto_pin_cfg *cfg)
5053 static const hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5054 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
5055 ARRAY_SIZE(pin_idxs));
5058 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5060 struct via_spec *spec = codec->spec;
5061 int err;
5063 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5064 if (err < 0)
5065 return err;
5066 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5067 if (err < 0)
5068 return err;
5069 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5070 return 0; /* can't find valid BIOS pin config */
5072 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5073 if (err < 0)
5074 return err;
5075 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5076 if (err < 0)
5077 return err;
5078 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5079 if (err < 0)
5080 return err;
5082 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5084 fill_dig_outs(codec);
5086 if (spec->kctls.list)
5087 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5089 spec->input_mux = &spec->private_imux[0];
5091 if (spec->hp_mux)
5092 via_hp_build(codec);
5094 via_smart51_build(spec);
5096 return 1;
5099 #ifdef CONFIG_SND_HDA_POWER_SAVE
5100 static const struct hda_amp_list vt1716S_loopbacks[] = {
5101 { 0x16, HDA_INPUT, 1 },
5102 { 0x16, HDA_INPUT, 2 },
5103 { 0x16, HDA_INPUT, 3 },
5104 { 0x16, HDA_INPUT, 4 },
5105 { } /* end */
5107 #endif
5109 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5111 struct via_spec *spec = codec->spec;
5112 int imux_is_smixer;
5113 unsigned int parm;
5114 unsigned int mono_out, present;
5115 /* SW0 (17h) = stereo mixer */
5116 imux_is_smixer =
5117 (snd_hda_codec_read(codec, 0x17, 0,
5118 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5119 /* inputs */
5120 /* PW 1/2/5 (1ah/1bh/1eh) */
5121 parm = AC_PWRST_D3;
5122 set_pin_power_state(codec, 0x1a, &parm);
5123 set_pin_power_state(codec, 0x1b, &parm);
5124 set_pin_power_state(codec, 0x1e, &parm);
5125 if (imux_is_smixer)
5126 parm = AC_PWRST_D0;
5127 /* SW0 (17h), AIW0(13h) */
5128 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5129 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5131 parm = AC_PWRST_D3;
5132 set_pin_power_state(codec, 0x1e, &parm);
5133 /* PW11 (22h) */
5134 if (spec->dmic_enabled)
5135 set_pin_power_state(codec, 0x22, &parm);
5136 else
5137 snd_hda_codec_write(codec, 0x22, 0,
5138 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5140 /* SW2(26h), AIW1(14h) */
5141 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5142 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5144 /* outputs */
5145 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5146 parm = AC_PWRST_D3;
5147 set_pin_power_state(codec, 0x19, &parm);
5148 /* Smart 5.1 PW2(1bh) */
5149 if (spec->smart51_enabled)
5150 set_pin_power_state(codec, 0x1b, &parm);
5151 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5152 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5154 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5155 parm = AC_PWRST_D3;
5156 set_pin_power_state(codec, 0x23, &parm);
5157 /* Smart 5.1 PW1(1ah) */
5158 if (spec->smart51_enabled)
5159 set_pin_power_state(codec, 0x1a, &parm);
5160 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5162 /* Smart 5.1 PW5(1eh) */
5163 if (spec->smart51_enabled)
5164 set_pin_power_state(codec, 0x1e, &parm);
5165 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5167 /* Mono out */
5168 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5169 present = snd_hda_jack_detect(codec, 0x1c);
5171 if (present)
5172 mono_out = 0;
5173 else {
5174 present = snd_hda_jack_detect(codec, 0x1d);
5175 if (!spec->hp_independent_mode && present)
5176 mono_out = 0;
5177 else
5178 mono_out = 1;
5180 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5181 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5182 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5183 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5185 /* PW 3/4 (1ch/1dh) */
5186 parm = AC_PWRST_D3;
5187 set_pin_power_state(codec, 0x1c, &parm);
5188 set_pin_power_state(codec, 0x1d, &parm);
5189 /* HP Independent Mode, power on AOW3 */
5190 if (spec->hp_independent_mode)
5191 snd_hda_codec_write(codec, 0x25, 0,
5192 AC_VERB_SET_POWER_STATE, parm);
5194 /* force to D0 for internal Speaker */
5195 /* MW0 (16h), AOW0 (10h) */
5196 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5197 imux_is_smixer ? AC_PWRST_D0 : parm);
5198 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5199 mono_out ? AC_PWRST_D0 : parm);
5202 static int patch_vt1716S(struct hda_codec *codec)
5204 struct via_spec *spec;
5205 int err;
5207 /* create a codec specific record */
5208 spec = via_new_spec(codec);
5209 if (spec == NULL)
5210 return -ENOMEM;
5212 /* automatic parse from the BIOS config */
5213 err = vt1716S_parse_auto_config(codec);
5214 if (err < 0) {
5215 via_free(codec);
5216 return err;
5217 } else if (!err) {
5218 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5219 "from BIOS. Using genenic mode...\n");
5222 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5223 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5225 spec->stream_name_analog = "VT1716S Analog";
5226 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5227 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5229 spec->stream_name_digital = "VT1716S Digital";
5230 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5232 if (!spec->adc_nids && spec->input_mux) {
5233 spec->adc_nids = vt1716S_adc_nids;
5234 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5235 get_mux_nids(codec);
5236 override_mic_boost(codec, 0x1a, 0, 3, 40);
5237 override_mic_boost(codec, 0x1e, 0, 3, 40);
5238 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5239 spec->num_mixers++;
5242 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5243 spec->num_mixers++;
5245 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5247 codec->patch_ops = via_patch_ops;
5249 codec->patch_ops.init = via_auto_init;
5250 codec->patch_ops.unsol_event = via_unsol_event;
5252 #ifdef CONFIG_SND_HDA_POWER_SAVE
5253 spec->loopback.amplist = vt1716S_loopbacks;
5254 #endif
5256 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
5257 return 0;
5260 /* for vt2002P */
5262 /* capture mixer elements */
5263 static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5264 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5265 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5266 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5267 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5268 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5269 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5270 HDA_INPUT),
5272 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5273 /* The multiple "Capture Source" controls confuse alsamixer
5274 * So call somewhat different..
5276 /* .name = "Capture Source", */
5277 .name = "Input Source",
5278 .count = 2,
5279 .info = via_mux_enum_info,
5280 .get = via_mux_enum_get,
5281 .put = via_mux_enum_put,
5283 { } /* end */
5286 static const struct hda_verb vt2002P_volume_init_verbs[] = {
5287 /* Class-D speaker related verbs */
5288 {0x1, 0xfe0, 0x4},
5289 {0x1, 0xfe9, 0x80},
5290 {0x1, 0xfe2, 0x22},
5292 * Unmute ADC0-1 and set the default input to mic-in
5294 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5295 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5298 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5299 * mixer widget
5301 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5302 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5303 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5304 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5305 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5306 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5308 /* MUX Indices: Mic = 0 */
5309 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5310 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5312 /* PW9 Output enable */
5313 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5315 /* Enable Boost Volume backdoor */
5316 {0x1, 0xfb9, 0x24},
5318 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5319 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5320 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5321 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5322 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5323 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5324 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5325 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5326 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5328 /* set MUX0/1/4/8 = 0 (AOW0) */
5329 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5330 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5331 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5332 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5334 /* set PW0 index=0 (MW0) */
5335 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5337 /* Enable AOW0 to MW9 */
5338 {0x1, 0xfb8, 0x88},
5341 static const struct hda_verb vt1802_volume_init_verbs[] = {
5343 * Unmute ADC0-1 and set the default input to mic-in
5345 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5346 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5349 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5350 * mixer widget
5352 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5353 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5354 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5355 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5356 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5357 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5359 /* MUX Indices: Mic = 0 */
5360 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5361 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5363 /* PW9 Output enable */
5364 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5366 /* Enable Boost Volume backdoor */
5367 {0x1, 0xfb9, 0x24},
5369 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5370 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5371 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5372 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5373 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5374 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5375 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5376 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5377 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5379 /* set MUX0/1/4/8 = 0 (AOW0) */
5380 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5381 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5382 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5383 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5385 /* set PW0 index=0 (MW0) */
5386 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5388 /* Enable AOW0 to MW9 */
5389 {0x1, 0xfb8, 0x88},
5394 static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
5395 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5396 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5397 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5398 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5399 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5400 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5401 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5404 static const struct hda_verb vt1802_uniwill_init_verbs[] = {
5405 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5406 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5407 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5408 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5409 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5410 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5411 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5415 static const struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5416 .substreams = 2,
5417 .channels_min = 2,
5418 .channels_max = 2,
5419 .nid = 0x8, /* NID to query formats and rates */
5420 .ops = {
5421 .open = via_playback_pcm_open,
5422 .prepare = via_playback_multi_pcm_prepare,
5423 .cleanup = via_playback_multi_pcm_cleanup,
5424 .close = via_pcm_open_close,
5428 static const struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5429 .substreams = 2,
5430 .channels_min = 2,
5431 .channels_max = 2,
5432 .nid = 0x10, /* NID to query formats and rates */
5433 .ops = {
5434 .open = via_pcm_open_close,
5435 .prepare = via_capture_pcm_prepare,
5436 .cleanup = via_capture_pcm_cleanup,
5437 .close = via_pcm_open_close,
5441 static const struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5442 .substreams = 1,
5443 .channels_min = 2,
5444 .channels_max = 2,
5445 /* NID is set in via_build_pcms */
5446 .ops = {
5447 .open = via_dig_playback_pcm_open,
5448 .close = via_dig_playback_pcm_close,
5449 .prepare = via_dig_playback_pcm_prepare,
5450 .cleanup = via_dig_playback_pcm_cleanup
5454 /* fill in the dac_nids table from the parsed pin configuration */
5455 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5456 const struct auto_pin_cfg *cfg)
5458 spec->multiout.num_dacs = 1;
5459 spec->multiout.dac_nids = spec->private_dac_nids;
5460 if (cfg->line_out_pins[0])
5461 spec->private_dac_nids[0] = 0x8;
5462 return 0;
5465 /* add playback controls from the parsed DAC table */
5466 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5467 const struct auto_pin_cfg *cfg)
5469 int err;
5470 hda_nid_t sw_nid;
5472 if (!cfg->line_out_pins[0])
5473 return -1;
5475 if (spec->codec_type == VT1802)
5476 sw_nid = 0x28;
5477 else
5478 sw_nid = 0x26;
5480 /* Line-Out: PortE */
5481 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5482 "Master Front Playback Volume",
5483 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5484 if (err < 0)
5485 return err;
5486 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5487 "Master Front Playback Switch",
5488 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
5489 if (err < 0)
5490 return err;
5492 return 0;
5495 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5497 int err;
5499 if (!pin)
5500 return 0;
5502 spec->multiout.hp_nid = 0x9;
5503 spec->hp_independent_mode_index = 1;
5505 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5506 "Headphone Playback Volume",
5507 HDA_COMPOSE_AMP_VAL(
5508 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5509 if (err < 0)
5510 return err;
5512 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5513 "Headphone Playback Switch",
5514 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5515 if (err < 0)
5516 return err;
5518 create_hp_imux(spec);
5519 return 0;
5522 /* create playback/capture controls for input pins */
5523 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5524 const struct auto_pin_cfg *cfg)
5526 struct via_spec *spec = codec->spec;
5527 struct hda_input_mux *imux = &spec->private_imux[0];
5528 static const hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5529 int err;
5531 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5532 ARRAY_SIZE(pin_idxs));
5533 if (err < 0)
5534 return err;
5535 /* build volume/mute control of loopback */
5536 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
5537 if (err < 0)
5538 return err;
5540 /* for digital mic select */
5541 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
5543 return 0;
5546 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5548 struct via_spec *spec = codec->spec;
5549 int err;
5552 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5553 if (err < 0)
5554 return err;
5556 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5557 if (err < 0)
5558 return err;
5560 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5561 return 0; /* can't find valid BIOS pin config */
5563 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5564 if (err < 0)
5565 return err;
5566 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5567 if (err < 0)
5568 return err;
5569 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5570 if (err < 0)
5571 return err;
5573 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5575 fill_dig_outs(codec);
5577 if (spec->kctls.list)
5578 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5580 spec->input_mux = &spec->private_imux[0];
5582 if (spec->hp_mux)
5583 via_hp_build(codec);
5585 return 1;
5588 #ifdef CONFIG_SND_HDA_POWER_SAVE
5589 static const struct hda_amp_list vt2002P_loopbacks[] = {
5590 { 0x21, HDA_INPUT, 0 },
5591 { 0x21, HDA_INPUT, 1 },
5592 { 0x21, HDA_INPUT, 2 },
5593 { } /* end */
5595 #endif
5597 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5599 struct via_spec *spec = codec->spec;
5600 int imux_is_smixer;
5601 unsigned int parm;
5602 unsigned int present;
5603 /* MUX9 (1eh) = stereo mixer */
5604 imux_is_smixer =
5605 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5606 /* inputs */
5607 /* PW 5/6/7 (29h/2ah/2bh) */
5608 parm = AC_PWRST_D3;
5609 set_pin_power_state(codec, 0x29, &parm);
5610 set_pin_power_state(codec, 0x2a, &parm);
5611 set_pin_power_state(codec, 0x2b, &parm);
5612 parm = AC_PWRST_D0;
5613 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5614 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5615 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5616 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5617 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5619 /* outputs */
5620 /* AOW0 (8h)*/
5621 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5623 if (spec->codec_type == VT1802) {
5624 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5625 parm = AC_PWRST_D3;
5626 set_pin_power_state(codec, 0x28, &parm);
5627 snd_hda_codec_write(codec, 0x18, 0,
5628 AC_VERB_SET_POWER_STATE, parm);
5629 snd_hda_codec_write(codec, 0x38, 0,
5630 AC_VERB_SET_POWER_STATE, parm);
5631 } else {
5632 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5633 parm = AC_PWRST_D3;
5634 set_pin_power_state(codec, 0x26, &parm);
5635 snd_hda_codec_write(codec, 0x1c, 0,
5636 AC_VERB_SET_POWER_STATE, parm);
5637 snd_hda_codec_write(codec, 0x37, 0,
5638 AC_VERB_SET_POWER_STATE, parm);
5641 if (spec->codec_type == VT1802) {
5642 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5643 parm = AC_PWRST_D3;
5644 set_pin_power_state(codec, 0x25, &parm);
5645 snd_hda_codec_write(codec, 0x15, 0,
5646 AC_VERB_SET_POWER_STATE, parm);
5647 snd_hda_codec_write(codec, 0x35, 0,
5648 AC_VERB_SET_POWER_STATE, parm);
5649 } else {
5650 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5651 parm = AC_PWRST_D3;
5652 set_pin_power_state(codec, 0x25, &parm);
5653 snd_hda_codec_write(codec, 0x19, 0,
5654 AC_VERB_SET_POWER_STATE, parm);
5655 snd_hda_codec_write(codec, 0x35, 0,
5656 AC_VERB_SET_POWER_STATE, parm);
5659 if (spec->hp_independent_mode)
5660 snd_hda_codec_write(codec, 0x9, 0,
5661 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5663 /* Class-D */
5664 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5665 present = snd_hda_jack_detect(codec, 0x25);
5667 parm = AC_PWRST_D3;
5668 set_pin_power_state(codec, 0x24, &parm);
5669 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5670 if (spec->codec_type == VT1802)
5671 snd_hda_codec_write(codec, 0x14, 0,
5672 AC_VERB_SET_POWER_STATE, parm);
5673 else
5674 snd_hda_codec_write(codec, 0x18, 0,
5675 AC_VERB_SET_POWER_STATE, parm);
5676 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5678 /* Mono Out */
5679 present = snd_hda_jack_detect(codec, 0x26);
5681 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5682 if (spec->codec_type == VT1802) {
5683 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5684 snd_hda_codec_write(codec, 0x33, 0,
5685 AC_VERB_SET_POWER_STATE, parm);
5686 snd_hda_codec_write(codec, 0x1c, 0,
5687 AC_VERB_SET_POWER_STATE, parm);
5688 snd_hda_codec_write(codec, 0x3c, 0,
5689 AC_VERB_SET_POWER_STATE, parm);
5690 } else {
5691 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5692 snd_hda_codec_write(codec, 0x31, 0,
5693 AC_VERB_SET_POWER_STATE, parm);
5694 snd_hda_codec_write(codec, 0x17, 0,
5695 AC_VERB_SET_POWER_STATE, parm);
5696 snd_hda_codec_write(codec, 0x3b, 0,
5697 AC_VERB_SET_POWER_STATE, parm);
5699 /* MW9 (21h) */
5700 if (imux_is_smixer || !is_aa_path_mute(codec))
5701 snd_hda_codec_write(codec, 0x21, 0,
5702 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5703 else
5704 snd_hda_codec_write(codec, 0x21, 0,
5705 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5708 /* patch for vt2002P */
5709 static int patch_vt2002P(struct hda_codec *codec)
5711 struct via_spec *spec;
5712 int err;
5714 /* create a codec specific record */
5715 spec = via_new_spec(codec);
5716 if (spec == NULL)
5717 return -ENOMEM;
5719 /* automatic parse from the BIOS config */
5720 err = vt2002P_parse_auto_config(codec);
5721 if (err < 0) {
5722 via_free(codec);
5723 return err;
5724 } else if (!err) {
5725 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5726 "from BIOS. Using genenic mode...\n");
5729 if (spec->codec_type == VT1802)
5730 spec->init_verbs[spec->num_iverbs++] =
5731 vt1802_volume_init_verbs;
5732 else
5733 spec->init_verbs[spec->num_iverbs++] =
5734 vt2002P_volume_init_verbs;
5736 if (spec->codec_type == VT1802)
5737 spec->init_verbs[spec->num_iverbs++] =
5738 vt1802_uniwill_init_verbs;
5739 else
5740 spec->init_verbs[spec->num_iverbs++] =
5741 vt2002P_uniwill_init_verbs;
5743 if (spec->codec_type == VT1802)
5744 spec->stream_name_analog = "VT1802 Analog";
5745 else
5746 spec->stream_name_analog = "VT2002P Analog";
5747 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5748 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5750 if (spec->codec_type == VT1802)
5751 spec->stream_name_digital = "VT1802 Digital";
5752 else
5753 spec->stream_name_digital = "VT2002P Digital";
5754 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5756 if (!spec->adc_nids && spec->input_mux) {
5757 spec->adc_nids = vt2002P_adc_nids;
5758 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5759 get_mux_nids(codec);
5760 override_mic_boost(codec, 0x2b, 0, 3, 40);
5761 override_mic_boost(codec, 0x29, 0, 3, 40);
5762 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5763 spec->num_mixers++;
5766 codec->patch_ops = via_patch_ops;
5768 codec->patch_ops.init = via_auto_init;
5769 codec->patch_ops.unsol_event = via_unsol_event;
5771 #ifdef CONFIG_SND_HDA_POWER_SAVE
5772 spec->loopback.amplist = vt2002P_loopbacks;
5773 #endif
5775 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
5776 return 0;
5779 /* for vt1812 */
5781 /* capture mixer elements */
5782 static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
5783 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5784 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5785 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5786 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5787 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5788 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5789 HDA_INPUT),
5791 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5792 /* The multiple "Capture Source" controls confuse alsamixer
5793 * So call somewhat different..
5795 .name = "Input Source",
5796 .count = 2,
5797 .info = via_mux_enum_info,
5798 .get = via_mux_enum_get,
5799 .put = via_mux_enum_put,
5801 { } /* end */
5804 static const struct hda_verb vt1812_volume_init_verbs[] = {
5806 * Unmute ADC0-1 and set the default input to mic-in
5808 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5809 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5812 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5813 * mixer widget
5815 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5816 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5817 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5818 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5819 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5820 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5822 /* MUX Indices: Mic = 0 */
5823 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5824 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5826 /* PW9 Output enable */
5827 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5829 /* Enable Boost Volume backdoor */
5830 {0x1, 0xfb9, 0x24},
5832 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5833 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5834 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5835 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5836 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5837 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5838 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5839 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5840 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5841 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5842 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5844 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5845 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5846 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5847 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5848 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5849 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5851 /* Enable AOW0 to MW9 */
5852 {0x1, 0xfb8, 0xa8},
5857 static const struct hda_verb vt1812_uniwill_init_verbs[] = {
5858 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5859 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5860 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5861 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5862 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5863 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5864 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5865 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5869 static const struct hda_pcm_stream vt1812_pcm_analog_playback = {
5870 .substreams = 2,
5871 .channels_min = 2,
5872 .channels_max = 2,
5873 .nid = 0x8, /* NID to query formats and rates */
5874 .ops = {
5875 .open = via_playback_pcm_open,
5876 .prepare = via_playback_multi_pcm_prepare,
5877 .cleanup = via_playback_multi_pcm_cleanup,
5878 .close = via_pcm_open_close,
5882 static const struct hda_pcm_stream vt1812_pcm_analog_capture = {
5883 .substreams = 2,
5884 .channels_min = 2,
5885 .channels_max = 2,
5886 .nid = 0x10, /* NID to query formats and rates */
5887 .ops = {
5888 .open = via_pcm_open_close,
5889 .prepare = via_capture_pcm_prepare,
5890 .cleanup = via_capture_pcm_cleanup,
5891 .close = via_pcm_open_close,
5895 static const struct hda_pcm_stream vt1812_pcm_digital_playback = {
5896 .substreams = 1,
5897 .channels_min = 2,
5898 .channels_max = 2,
5899 /* NID is set in via_build_pcms */
5900 .ops = {
5901 .open = via_dig_playback_pcm_open,
5902 .close = via_dig_playback_pcm_close,
5903 .prepare = via_dig_playback_pcm_prepare,
5904 .cleanup = via_dig_playback_pcm_cleanup
5907 /* fill in the dac_nids table from the parsed pin configuration */
5908 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5909 const struct auto_pin_cfg *cfg)
5911 spec->multiout.num_dacs = 1;
5912 spec->multiout.dac_nids = spec->private_dac_nids;
5913 if (cfg->line_out_pins[0])
5914 spec->private_dac_nids[0] = 0x8;
5915 return 0;
5919 /* add playback controls from the parsed DAC table */
5920 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5921 const struct auto_pin_cfg *cfg)
5923 int err;
5925 if (!cfg->line_out_pins[0])
5926 return -1;
5928 /* Line-Out: PortE */
5929 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5930 "Front Playback Volume",
5931 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5932 if (err < 0)
5933 return err;
5934 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5935 "Front Playback Switch",
5936 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5937 if (err < 0)
5938 return err;
5940 return 0;
5943 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5945 int err;
5947 if (!pin)
5948 return 0;
5950 spec->multiout.hp_nid = 0x9;
5951 spec->hp_independent_mode_index = 1;
5954 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5955 "Headphone Playback Volume",
5956 HDA_COMPOSE_AMP_VAL(
5957 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5958 if (err < 0)
5959 return err;
5961 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5962 "Headphone Playback Switch",
5963 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5964 if (err < 0)
5965 return err;
5967 create_hp_imux(spec);
5968 return 0;
5971 /* create playback/capture controls for input pins */
5972 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5973 const struct auto_pin_cfg *cfg)
5975 struct via_spec *spec = codec->spec;
5976 struct hda_input_mux *imux = &spec->private_imux[0];
5977 static const hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5978 int err;
5980 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5981 ARRAY_SIZE(pin_idxs));
5982 if (err < 0)
5983 return err;
5985 /* build volume/mute control of loopback */
5986 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
5987 if (err < 0)
5988 return err;
5990 /* for digital mic select */
5991 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
5993 return 0;
5996 static int vt1812_parse_auto_config(struct hda_codec *codec)
5998 struct via_spec *spec = codec->spec;
5999 int err;
6002 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6003 if (err < 0)
6004 return err;
6005 fill_dig_outs(codec);
6006 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6007 if (err < 0)
6008 return err;
6010 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6011 return 0; /* can't find valid BIOS pin config */
6013 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6014 if (err < 0)
6015 return err;
6016 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6017 if (err < 0)
6018 return err;
6019 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
6020 if (err < 0)
6021 return err;
6023 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6025 fill_dig_outs(codec);
6027 if (spec->kctls.list)
6028 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6030 spec->input_mux = &spec->private_imux[0];
6032 if (spec->hp_mux)
6033 via_hp_build(codec);
6035 return 1;
6038 #ifdef CONFIG_SND_HDA_POWER_SAVE
6039 static const struct hda_amp_list vt1812_loopbacks[] = {
6040 { 0x21, HDA_INPUT, 0 },
6041 { 0x21, HDA_INPUT, 1 },
6042 { 0x21, HDA_INPUT, 2 },
6043 { } /* end */
6045 #endif
6047 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
6049 struct via_spec *spec = codec->spec;
6050 int imux_is_smixer =
6051 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
6052 unsigned int parm;
6053 unsigned int present;
6054 /* MUX10 (1eh) = stereo mixer */
6055 imux_is_smixer =
6056 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
6057 /* inputs */
6058 /* PW 5/6/7 (29h/2ah/2bh) */
6059 parm = AC_PWRST_D3;
6060 set_pin_power_state(codec, 0x29, &parm);
6061 set_pin_power_state(codec, 0x2a, &parm);
6062 set_pin_power_state(codec, 0x2b, &parm);
6063 parm = AC_PWRST_D0;
6064 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
6065 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
6066 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
6067 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
6068 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
6070 /* outputs */
6071 /* AOW0 (8h)*/
6072 snd_hda_codec_write(codec, 0x8, 0,
6073 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6075 /* PW4 (28h), MW4 (18h), MUX4(38h) */
6076 parm = AC_PWRST_D3;
6077 set_pin_power_state(codec, 0x28, &parm);
6078 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
6079 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
6081 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
6082 parm = AC_PWRST_D3;
6083 set_pin_power_state(codec, 0x25, &parm);
6084 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
6085 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
6086 if (spec->hp_independent_mode)
6087 snd_hda_codec_write(codec, 0x9, 0,
6088 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6090 /* Internal Speaker */
6091 /* PW0 (24h), MW0(14h), MUX0(34h) */
6092 present = snd_hda_jack_detect(codec, 0x25);
6094 parm = AC_PWRST_D3;
6095 set_pin_power_state(codec, 0x24, &parm);
6096 if (present) {
6097 snd_hda_codec_write(codec, 0x14, 0,
6098 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6099 snd_hda_codec_write(codec, 0x34, 0,
6100 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6101 } else {
6102 snd_hda_codec_write(codec, 0x14, 0,
6103 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6104 snd_hda_codec_write(codec, 0x34, 0,
6105 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6109 /* Mono Out */
6110 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6111 present = snd_hda_jack_detect(codec, 0x28);
6113 parm = AC_PWRST_D3;
6114 set_pin_power_state(codec, 0x31, &parm);
6115 if (present) {
6116 snd_hda_codec_write(codec, 0x1c, 0,
6117 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6118 snd_hda_codec_write(codec, 0x3c, 0,
6119 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6120 snd_hda_codec_write(codec, 0x3e, 0,
6121 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6122 } else {
6123 snd_hda_codec_write(codec, 0x1c, 0,
6124 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6125 snd_hda_codec_write(codec, 0x3c, 0,
6126 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6127 snd_hda_codec_write(codec, 0x3e, 0,
6128 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6131 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6132 parm = AC_PWRST_D3;
6133 set_pin_power_state(codec, 0x33, &parm);
6134 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6135 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6139 /* patch for vt1812 */
6140 static int patch_vt1812(struct hda_codec *codec)
6142 struct via_spec *spec;
6143 int err;
6145 /* create a codec specific record */
6146 spec = via_new_spec(codec);
6147 if (spec == NULL)
6148 return -ENOMEM;
6150 /* automatic parse from the BIOS config */
6151 err = vt1812_parse_auto_config(codec);
6152 if (err < 0) {
6153 via_free(codec);
6154 return err;
6155 } else if (!err) {
6156 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6157 "from BIOS. Using genenic mode...\n");
6161 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6162 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6164 spec->stream_name_analog = "VT1812 Analog";
6165 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6166 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6168 spec->stream_name_digital = "VT1812 Digital";
6169 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6172 if (!spec->adc_nids && spec->input_mux) {
6173 spec->adc_nids = vt1812_adc_nids;
6174 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6175 get_mux_nids(codec);
6176 override_mic_boost(codec, 0x2b, 0, 3, 40);
6177 override_mic_boost(codec, 0x29, 0, 3, 40);
6178 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6179 spec->num_mixers++;
6182 codec->patch_ops = via_patch_ops;
6184 codec->patch_ops.init = via_auto_init;
6185 codec->patch_ops.unsol_event = via_unsol_event;
6187 #ifdef CONFIG_SND_HDA_POWER_SAVE
6188 spec->loopback.amplist = vt1812_loopbacks;
6189 #endif
6191 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
6192 return 0;
6196 * patch entries
6198 static const struct hda_codec_preset snd_hda_preset_via[] = {
6199 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6200 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6201 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6202 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6203 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6204 .patch = patch_vt1709_10ch},
6205 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6206 .patch = patch_vt1709_10ch},
6207 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6208 .patch = patch_vt1709_10ch},
6209 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6210 .patch = patch_vt1709_10ch},
6211 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6212 .patch = patch_vt1709_6ch},
6213 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6214 .patch = patch_vt1709_6ch},
6215 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6216 .patch = patch_vt1709_6ch},
6217 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6218 .patch = patch_vt1709_6ch},
6219 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6220 .patch = patch_vt1708B_8ch},
6221 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6222 .patch = patch_vt1708B_8ch},
6223 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6224 .patch = patch_vt1708B_8ch},
6225 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6226 .patch = patch_vt1708B_8ch},
6227 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6228 .patch = patch_vt1708B_4ch},
6229 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6230 .patch = patch_vt1708B_4ch},
6231 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6232 .patch = patch_vt1708B_4ch},
6233 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6234 .patch = patch_vt1708B_4ch},
6235 { .id = 0x11060397, .name = "VT1708S",
6236 .patch = patch_vt1708S},
6237 { .id = 0x11061397, .name = "VT1708S",
6238 .patch = patch_vt1708S},
6239 { .id = 0x11062397, .name = "VT1708S",
6240 .patch = patch_vt1708S},
6241 { .id = 0x11063397, .name = "VT1708S",
6242 .patch = patch_vt1708S},
6243 { .id = 0x11064397, .name = "VT1705",
6244 .patch = patch_vt1708S},
6245 { .id = 0x11065397, .name = "VT1708S",
6246 .patch = patch_vt1708S},
6247 { .id = 0x11066397, .name = "VT1708S",
6248 .patch = patch_vt1708S},
6249 { .id = 0x11067397, .name = "VT1708S",
6250 .patch = patch_vt1708S},
6251 { .id = 0x11060398, .name = "VT1702",
6252 .patch = patch_vt1702},
6253 { .id = 0x11061398, .name = "VT1702",
6254 .patch = patch_vt1702},
6255 { .id = 0x11062398, .name = "VT1702",
6256 .patch = patch_vt1702},
6257 { .id = 0x11063398, .name = "VT1702",
6258 .patch = patch_vt1702},
6259 { .id = 0x11064398, .name = "VT1702",
6260 .patch = patch_vt1702},
6261 { .id = 0x11065398, .name = "VT1702",
6262 .patch = patch_vt1702},
6263 { .id = 0x11066398, .name = "VT1702",
6264 .patch = patch_vt1702},
6265 { .id = 0x11067398, .name = "VT1702",
6266 .patch = patch_vt1702},
6267 { .id = 0x11060428, .name = "VT1718S",
6268 .patch = patch_vt1718S},
6269 { .id = 0x11064428, .name = "VT1718S",
6270 .patch = patch_vt1718S},
6271 { .id = 0x11060441, .name = "VT2020",
6272 .patch = patch_vt1718S},
6273 { .id = 0x11064441, .name = "VT1828S",
6274 .patch = patch_vt1718S},
6275 { .id = 0x11060433, .name = "VT1716S",
6276 .patch = patch_vt1716S},
6277 { .id = 0x1106a721, .name = "VT1716S",
6278 .patch = patch_vt1716S},
6279 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6280 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6281 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6282 { .id = 0x11060440, .name = "VT1818S",
6283 .patch = patch_vt1708S},
6284 { .id = 0x11060446, .name = "VT1802",
6285 .patch = patch_vt2002P},
6286 { .id = 0x11068446, .name = "VT1802",
6287 .patch = patch_vt2002P},
6288 {} /* terminator */
6291 MODULE_ALIAS("snd-hda-codec-id:1106*");
6293 static struct hda_codec_preset_list via_list = {
6294 .preset = snd_hda_preset_via,
6295 .owner = THIS_MODULE,
6298 MODULE_LICENSE("GPL");
6299 MODULE_DESCRIPTION("VIA HD-audio codec");
6301 static int __init patch_via_init(void)
6303 return snd_hda_add_codec_preset(&via_list);
6306 static void __exit patch_via_exit(void)
6308 snd_hda_delete_codec_preset(&via_list);
6311 module_init(patch_via_init)
6312 module_exit(patch_via_exit)