]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - sound/pci/hda/patch_via.c
ALSA: hda - consitify string arrays
[mirror_ubuntu-zesty-kernel.git] / sound / pci / hda / patch_via.c
1 /*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
5 *
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
8 *
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.
13 *
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.
18 *
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
22 */
23
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 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
47
48
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"
56
57 #define NID_MAPPING (-1)
58
59 /* amp values */
60 #define AMP_VAL_IDX_SHIFT 19
61 #define AMP_VAL_IDX_MASK (0x0f<<19)
62
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
70
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
75
76 #define VT1708B_HP_NID 0x25
77 #define VT1708B_DIGOUT_NID 0x12
78 #define VT1708B_DIGIN_NID 0x15
79 #define VT1708B_DIGIN_PIN 0x21
80
81 #define VT1708S_HP_NID 0x25
82 #define VT1708S_DIGOUT_NID 0x12
83
84 #define VT1702_HP_NID 0x17
85 #define VT1702_DIGOUT_NID 0x11
86
87 enum VIA_HDA_CODEC {
88 UNKNOWN = -1,
89 VT1708,
90 VT1709_10CH,
91 VT1709_6CH,
92 VT1708B_8CH,
93 VT1708B_4CH,
94 VT1708S,
95 VT1708BCE,
96 VT1702,
97 VT1718S,
98 VT1716S,
99 VT2002P,
100 VT1812,
101 CODEC_TYPES,
102 };
103
104 struct via_spec {
105 /* codec parameterization */
106 struct snd_kcontrol_new *mixers[6];
107 unsigned int num_mixers;
108
109 struct hda_verb *init_verbs[5];
110 unsigned int num_iverbs;
111
112 char *stream_name_analog;
113 struct hda_pcm_stream *stream_analog_playback;
114 struct hda_pcm_stream *stream_analog_capture;
115
116 char *stream_name_digital;
117 struct hda_pcm_stream *stream_digital_playback;
118 struct hda_pcm_stream *stream_digital_capture;
119
120 /* playback */
121 struct hda_multi_out multiout;
122 hda_nid_t slave_dig_outs[2];
123
124 /* capture */
125 unsigned int num_adc_nids;
126 hda_nid_t *adc_nids;
127 hda_nid_t mux_nids[3];
128 hda_nid_t dig_in_nid;
129 hda_nid_t dig_in_pin;
130
131 /* capture source */
132 const struct hda_input_mux *input_mux;
133 unsigned int cur_mux[3];
134
135 /* PCM information */
136 struct hda_pcm pcm_rec[3];
137
138 /* dynamic controls, init_verbs and input_mux */
139 struct auto_pin_cfg autocfg;
140 struct snd_array kctls;
141 struct hda_input_mux private_imux[2];
142 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
143
144 /* HP mode source */
145 const struct hda_input_mux *hp_mux;
146 unsigned int hp_independent_mode;
147 unsigned int hp_independent_mode_index;
148 unsigned int smart51_enabled;
149 unsigned int dmic_enabled;
150 enum VIA_HDA_CODEC codec_type;
151
152 /* work to check hp jack state */
153 struct hda_codec *codec;
154 struct delayed_work vt1708_hp_work;
155 int vt1708_jack_detectect;
156 int vt1708_hp_present;
157 #ifdef CONFIG_SND_HDA_POWER_SAVE
158 struct hda_loopback_check loopback;
159 #endif
160 };
161
162 static struct via_spec * via_new_spec(struct hda_codec *codec)
163 {
164 struct via_spec *spec;
165
166 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
167 if (spec == NULL)
168 return NULL;
169
170 codec->spec = spec;
171 spec->codec = codec;
172 return spec;
173 }
174
175 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
176 {
177 u32 vendor_id = codec->vendor_id;
178 u16 ven_id = vendor_id >> 16;
179 u16 dev_id = vendor_id & 0xffff;
180 enum VIA_HDA_CODEC codec_type;
181
182 /* get codec type */
183 if (ven_id != 0x1106)
184 codec_type = UNKNOWN;
185 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
186 codec_type = VT1708;
187 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
188 codec_type = VT1709_10CH;
189 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
190 codec_type = VT1709_6CH;
191 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
192 codec_type = VT1708B_8CH;
193 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
194 codec_type = VT1708BCE;
195 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
196 codec_type = VT1708B_4CH;
197 else if ((dev_id & 0xfff) == 0x397
198 && (dev_id >> 12) < 8)
199 codec_type = VT1708S;
200 else if ((dev_id & 0xfff) == 0x398
201 && (dev_id >> 12) < 8)
202 codec_type = VT1702;
203 else if ((dev_id & 0xfff) == 0x428
204 && (dev_id >> 12) < 8)
205 codec_type = VT1718S;
206 else if (dev_id == 0x0433 || dev_id == 0xa721)
207 codec_type = VT1716S;
208 else if (dev_id == 0x0441 || dev_id == 0x4441)
209 codec_type = VT1718S;
210 else if (dev_id == 0x0438 || dev_id == 0x4438)
211 codec_type = VT2002P;
212 else if (dev_id == 0x0448)
213 codec_type = VT1812;
214 else if (dev_id == 0x0440)
215 codec_type = VT1708S;
216 else
217 codec_type = UNKNOWN;
218 return codec_type;
219 };
220
221 #define VIA_HP_EVENT 0x01
222 #define VIA_GPIO_EVENT 0x02
223 #define VIA_JACK_EVENT 0x04
224 #define VIA_MONO_EVENT 0x08
225 #define VIA_SPEAKER_EVENT 0x10
226 #define VIA_BIND_HP_EVENT 0x20
227
228 enum {
229 VIA_CTL_WIDGET_VOL,
230 VIA_CTL_WIDGET_MUTE,
231 VIA_CTL_WIDGET_ANALOG_MUTE,
232 VIA_CTL_WIDGET_BIND_PIN_MUTE,
233 };
234
235 enum {
236 AUTO_SEQ_FRONT = 0,
237 AUTO_SEQ_SURROUND,
238 AUTO_SEQ_CENLFE,
239 AUTO_SEQ_SIDE
240 };
241
242 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
243 static void set_jack_power_state(struct hda_codec *codec);
244 static int is_aa_path_mute(struct hda_codec *codec);
245
246 static void vt1708_start_hp_work(struct via_spec *spec)
247 {
248 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
249 return;
250 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
251 !spec->vt1708_jack_detectect);
252 if (!delayed_work_pending(&spec->vt1708_hp_work))
253 schedule_delayed_work(&spec->vt1708_hp_work,
254 msecs_to_jiffies(100));
255 }
256
257 static void vt1708_stop_hp_work(struct via_spec *spec)
258 {
259 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
260 return;
261 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
262 && !is_aa_path_mute(spec->codec))
263 return;
264 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
265 !spec->vt1708_jack_detectect);
266 cancel_delayed_work(&spec->vt1708_hp_work);
267 flush_scheduled_work();
268 }
269
270
271 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
272 struct snd_ctl_elem_value *ucontrol)
273 {
274 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
275 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
276
277 set_jack_power_state(codec);
278 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
279 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
280 if (is_aa_path_mute(codec))
281 vt1708_start_hp_work(codec->spec);
282 else
283 vt1708_stop_hp_work(codec->spec);
284 }
285 return change;
286 }
287
288 /* modify .put = snd_hda_mixer_amp_switch_put */
289 #define ANALOG_INPUT_MUTE \
290 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
291 .name = NULL, \
292 .index = 0, \
293 .info = snd_hda_mixer_amp_switch_info, \
294 .get = snd_hda_mixer_amp_switch_get, \
295 .put = analog_input_switch_put, \
296 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
297
298 static void via_hp_bind_automute(struct hda_codec *codec);
299
300 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
301 struct snd_ctl_elem_value *ucontrol)
302 {
303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
304 struct via_spec *spec = codec->spec;
305 int i;
306 int change = 0;
307
308 long *valp = ucontrol->value.integer.value;
309 int lmute, rmute;
310 if (strstr(kcontrol->id.name, "Switch") == NULL) {
311 snd_printd("Invalid control!\n");
312 return change;
313 }
314 change = snd_hda_mixer_amp_switch_put(kcontrol,
315 ucontrol);
316 /* Get mute value */
317 lmute = *valp ? 0 : HDA_AMP_MUTE;
318 valp++;
319 rmute = *valp ? 0 : HDA_AMP_MUTE;
320
321 /* Set hp pins */
322 if (!spec->hp_independent_mode) {
323 for (i = 0; i < spec->autocfg.hp_outs; i++) {
324 snd_hda_codec_amp_update(
325 codec, spec->autocfg.hp_pins[i],
326 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
327 lmute);
328 snd_hda_codec_amp_update(
329 codec, spec->autocfg.hp_pins[i],
330 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
331 rmute);
332 }
333 }
334
335 if (!lmute && !rmute) {
336 /* Line Outs */
337 for (i = 0; i < spec->autocfg.line_outs; i++)
338 snd_hda_codec_amp_stereo(
339 codec, spec->autocfg.line_out_pins[i],
340 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
341 /* Speakers */
342 for (i = 0; i < spec->autocfg.speaker_outs; i++)
343 snd_hda_codec_amp_stereo(
344 codec, spec->autocfg.speaker_pins[i],
345 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
346 /* unmute */
347 via_hp_bind_automute(codec);
348
349 } else {
350 if (lmute) {
351 /* Mute all left channels */
352 for (i = 1; i < spec->autocfg.line_outs; i++)
353 snd_hda_codec_amp_update(
354 codec,
355 spec->autocfg.line_out_pins[i],
356 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
357 lmute);
358 for (i = 0; i < spec->autocfg.speaker_outs; i++)
359 snd_hda_codec_amp_update(
360 codec,
361 spec->autocfg.speaker_pins[i],
362 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
363 lmute);
364 }
365 if (rmute) {
366 /* mute all right channels */
367 for (i = 1; i < spec->autocfg.line_outs; i++)
368 snd_hda_codec_amp_update(
369 codec,
370 spec->autocfg.line_out_pins[i],
371 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
372 rmute);
373 for (i = 0; i < spec->autocfg.speaker_outs; i++)
374 snd_hda_codec_amp_update(
375 codec,
376 spec->autocfg.speaker_pins[i],
377 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
378 rmute);
379 }
380 }
381 return change;
382 }
383
384 #define BIND_PIN_MUTE \
385 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
386 .name = NULL, \
387 .index = 0, \
388 .info = snd_hda_mixer_amp_switch_info, \
389 .get = snd_hda_mixer_amp_switch_get, \
390 .put = bind_pin_switch_put, \
391 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
392
393 static struct snd_kcontrol_new via_control_templates[] = {
394 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
395 HDA_CODEC_MUTE(NULL, 0, 0, 0),
396 ANALOG_INPUT_MUTE,
397 BIND_PIN_MUTE,
398 };
399
400 static hda_nid_t vt1708_adc_nids[2] = {
401 /* ADC1-2 */
402 0x15, 0x27
403 };
404
405 static hda_nid_t vt1709_adc_nids[3] = {
406 /* ADC1-2 */
407 0x14, 0x15, 0x16
408 };
409
410 static hda_nid_t vt1708B_adc_nids[2] = {
411 /* ADC1-2 */
412 0x13, 0x14
413 };
414
415 static hda_nid_t vt1708S_adc_nids[2] = {
416 /* ADC1-2 */
417 0x13, 0x14
418 };
419
420 static hda_nid_t vt1702_adc_nids[3] = {
421 /* ADC1-2 */
422 0x12, 0x20, 0x1F
423 };
424
425 static hda_nid_t vt1718S_adc_nids[2] = {
426 /* ADC1-2 */
427 0x10, 0x11
428 };
429
430 static hda_nid_t vt1716S_adc_nids[2] = {
431 /* ADC1-2 */
432 0x13, 0x14
433 };
434
435 static hda_nid_t vt2002P_adc_nids[2] = {
436 /* ADC1-2 */
437 0x10, 0x11
438 };
439
440 static hda_nid_t vt1812_adc_nids[2] = {
441 /* ADC1-2 */
442 0x10, 0x11
443 };
444
445
446 /* add dynamic controls */
447 static int __via_add_control(struct via_spec *spec, int type, const char *name,
448 int idx, unsigned long val)
449 {
450 struct snd_kcontrol_new *knew;
451
452 snd_array_init(&spec->kctls, sizeof(*knew), 32);
453 knew = snd_array_new(&spec->kctls);
454 if (!knew)
455 return -ENOMEM;
456 *knew = via_control_templates[type];
457 knew->name = kstrdup(name, GFP_KERNEL);
458 if (!knew->name)
459 return -ENOMEM;
460 if (get_amp_nid_(val))
461 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
462 knew->private_value = val;
463 return 0;
464 }
465
466 #define via_add_control(spec, type, name, val) \
467 __via_add_control(spec, type, name, 0, val)
468
469 static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
470 struct snd_kcontrol_new *tmpl)
471 {
472 struct snd_kcontrol_new *knew;
473
474 snd_array_init(&spec->kctls, sizeof(*knew), 32);
475 knew = snd_array_new(&spec->kctls);
476 if (!knew)
477 return NULL;
478 *knew = *tmpl;
479 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
480 if (!knew->name)
481 return NULL;
482 return knew;
483 }
484
485 static void via_free_kctls(struct hda_codec *codec)
486 {
487 struct via_spec *spec = codec->spec;
488
489 if (spec->kctls.list) {
490 struct snd_kcontrol_new *kctl = spec->kctls.list;
491 int i;
492 for (i = 0; i < spec->kctls.used; i++)
493 kfree(kctl[i].name);
494 }
495 snd_array_free(&spec->kctls);
496 }
497
498 /* create input playback/capture controls for the given pin */
499 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
500 int type_idx, int idx, int mix_nid)
501 {
502 char name[32];
503 int err;
504
505 sprintf(name, "%s Playback Volume", ctlname);
506 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
507 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
508 if (err < 0)
509 return err;
510 sprintf(name, "%s Playback Switch", ctlname);
511 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
512 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
513 if (err < 0)
514 return err;
515 return 0;
516 }
517
518 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
519 hda_nid_t nid, int pin_type,
520 int dac_idx)
521 {
522 /* set as output */
523 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
524 pin_type);
525 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
526 AMP_OUT_UNMUTE);
527 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
528 snd_hda_codec_write(codec, nid, 0,
529 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
530 }
531
532
533 static void via_auto_init_multi_out(struct hda_codec *codec)
534 {
535 struct via_spec *spec = codec->spec;
536 int i;
537
538 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
539 hda_nid_t nid = spec->autocfg.line_out_pins[i];
540 if (nid)
541 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
542 }
543 }
544
545 static void via_auto_init_hp_out(struct hda_codec *codec)
546 {
547 struct via_spec *spec = codec->spec;
548 hda_nid_t pin;
549 int i;
550
551 for (i = 0; i < spec->autocfg.hp_outs; i++) {
552 pin = spec->autocfg.hp_pins[i];
553 if (pin) /* connect to front */
554 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
555 }
556 }
557
558 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
559
560 static void via_auto_init_analog_input(struct hda_codec *codec)
561 {
562 struct via_spec *spec = codec->spec;
563 const struct auto_pin_cfg *cfg = &spec->autocfg;
564 unsigned int ctl;
565 int i;
566
567 for (i = 0; i < cfg->num_inputs; i++) {
568 hda_nid_t nid = cfg->inputs[i].pin;
569 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
570 ctl = PIN_OUT;
571 else if (i == AUTO_PIN_MIC)
572 ctl = PIN_VREF50;
573 else
574 ctl = PIN_IN;
575 snd_hda_codec_write(codec, nid, 0,
576 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
577 }
578 }
579
580 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
581 unsigned int *affected_parm)
582 {
583 unsigned parm;
584 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
585 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
586 >> AC_DEFCFG_MISC_SHIFT
587 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
588 unsigned present = snd_hda_jack_detect(codec, nid);
589 struct via_spec *spec = codec->spec;
590 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
591 || ((no_presence || present)
592 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
593 *affected_parm = AC_PWRST_D0; /* if it's connected */
594 parm = AC_PWRST_D0;
595 } else
596 parm = AC_PWRST_D3;
597
598 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
599 }
600
601 static void set_jack_power_state(struct hda_codec *codec)
602 {
603 struct via_spec *spec = codec->spec;
604 int imux_is_smixer;
605 unsigned int parm;
606
607 if (spec->codec_type == VT1702) {
608 imux_is_smixer = snd_hda_codec_read(
609 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
610 /* inputs */
611 /* PW 1/2/5 (14h/15h/18h) */
612 parm = AC_PWRST_D3;
613 set_pin_power_state(codec, 0x14, &parm);
614 set_pin_power_state(codec, 0x15, &parm);
615 set_pin_power_state(codec, 0x18, &parm);
616 if (imux_is_smixer)
617 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
618 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
619 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
620 parm);
621 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
622 parm);
623 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
624 parm);
625 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
626 parm);
627
628 /* outputs */
629 /* PW 3/4 (16h/17h) */
630 parm = AC_PWRST_D3;
631 set_pin_power_state(codec, 0x16, &parm);
632 set_pin_power_state(codec, 0x17, &parm);
633 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
634 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
635 imux_is_smixer ? AC_PWRST_D0 : parm);
636 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
637 parm);
638 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
639 parm);
640 } else if (spec->codec_type == VT1708B_8CH
641 || spec->codec_type == VT1708B_4CH
642 || spec->codec_type == VT1708S) {
643 /* SW0 (17h) = stereo mixer */
644 int is_8ch = spec->codec_type != VT1708B_4CH;
645 imux_is_smixer = snd_hda_codec_read(
646 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
647 == ((spec->codec_type == VT1708S) ? 5 : 0);
648 /* inputs */
649 /* PW 1/2/5 (1ah/1bh/1eh) */
650 parm = AC_PWRST_D3;
651 set_pin_power_state(codec, 0x1a, &parm);
652 set_pin_power_state(codec, 0x1b, &parm);
653 set_pin_power_state(codec, 0x1e, &parm);
654 if (imux_is_smixer)
655 parm = AC_PWRST_D0;
656 /* SW0 (17h), AIW 0/1 (13h/14h) */
657 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
658 parm);
659 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
660 parm);
661 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
662 parm);
663
664 /* outputs */
665 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
666 parm = AC_PWRST_D3;
667 set_pin_power_state(codec, 0x19, &parm);
668 if (spec->smart51_enabled)
669 parm = AC_PWRST_D0;
670 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
671 parm);
672 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
673 parm);
674
675 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
676 if (is_8ch) {
677 parm = AC_PWRST_D3;
678 set_pin_power_state(codec, 0x22, &parm);
679 if (spec->smart51_enabled)
680 parm = AC_PWRST_D0;
681 snd_hda_codec_write(codec, 0x26, 0,
682 AC_VERB_SET_POWER_STATE, parm);
683 snd_hda_codec_write(codec, 0x24, 0,
684 AC_VERB_SET_POWER_STATE, parm);
685 }
686
687 /* PW 3/4/7 (1ch/1dh/23h) */
688 parm = AC_PWRST_D3;
689 /* force to D0 for internal Speaker */
690 set_pin_power_state(codec, 0x1c, &parm);
691 set_pin_power_state(codec, 0x1d, &parm);
692 if (is_8ch)
693 set_pin_power_state(codec, 0x23, &parm);
694 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
695 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
696 imux_is_smixer ? AC_PWRST_D0 : parm);
697 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
698 parm);
699 if (is_8ch) {
700 snd_hda_codec_write(codec, 0x25, 0,
701 AC_VERB_SET_POWER_STATE, parm);
702 snd_hda_codec_write(codec, 0x27, 0,
703 AC_VERB_SET_POWER_STATE, parm);
704 }
705 } else if (spec->codec_type == VT1718S) {
706 /* MUX6 (1eh) = stereo mixer */
707 imux_is_smixer = snd_hda_codec_read(
708 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
709 /* inputs */
710 /* PW 5/6/7 (29h/2ah/2bh) */
711 parm = AC_PWRST_D3;
712 set_pin_power_state(codec, 0x29, &parm);
713 set_pin_power_state(codec, 0x2a, &parm);
714 set_pin_power_state(codec, 0x2b, &parm);
715 if (imux_is_smixer)
716 parm = AC_PWRST_D0;
717 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
718 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
719 parm);
720 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
721 parm);
722 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
723 parm);
724 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
725 parm);
726
727 /* outputs */
728 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
729 parm = AC_PWRST_D3;
730 set_pin_power_state(codec, 0x27, &parm);
731 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
732 parm);
733 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
734 parm);
735
736 /* PW2 (26h), AOW2 (ah) */
737 parm = AC_PWRST_D3;
738 set_pin_power_state(codec, 0x26, &parm);
739 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
740 parm);
741
742 /* PW0/1 (24h/25h) */
743 parm = AC_PWRST_D3;
744 set_pin_power_state(codec, 0x24, &parm);
745 set_pin_power_state(codec, 0x25, &parm);
746 if (!spec->hp_independent_mode) /* check for redirected HP */
747 set_pin_power_state(codec, 0x28, &parm);
748 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
749 parm);
750 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
751 parm);
752 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
753 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
754 imux_is_smixer ? AC_PWRST_D0 : parm);
755 if (spec->hp_independent_mode) {
756 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
757 parm = AC_PWRST_D3;
758 set_pin_power_state(codec, 0x28, &parm);
759 snd_hda_codec_write(codec, 0x1b, 0,
760 AC_VERB_SET_POWER_STATE, parm);
761 snd_hda_codec_write(codec, 0x34, 0,
762 AC_VERB_SET_POWER_STATE, parm);
763 snd_hda_codec_write(codec, 0xc, 0,
764 AC_VERB_SET_POWER_STATE, parm);
765 }
766 } else if (spec->codec_type == VT1716S) {
767 unsigned int mono_out, present;
768 /* SW0 (17h) = stereo mixer */
769 imux_is_smixer = snd_hda_codec_read(
770 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
771 /* inputs */
772 /* PW 1/2/5 (1ah/1bh/1eh) */
773 parm = AC_PWRST_D3;
774 set_pin_power_state(codec, 0x1a, &parm);
775 set_pin_power_state(codec, 0x1b, &parm);
776 set_pin_power_state(codec, 0x1e, &parm);
777 if (imux_is_smixer)
778 parm = AC_PWRST_D0;
779 /* SW0 (17h), AIW0(13h) */
780 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
781 parm);
782 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
783 parm);
784
785 parm = AC_PWRST_D3;
786 set_pin_power_state(codec, 0x1e, &parm);
787 /* PW11 (22h) */
788 if (spec->dmic_enabled)
789 set_pin_power_state(codec, 0x22, &parm);
790 else
791 snd_hda_codec_write(
792 codec, 0x22, 0,
793 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
794
795 /* SW2(26h), AIW1(14h) */
796 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
797 parm);
798 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
799 parm);
800
801 /* outputs */
802 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
803 parm = AC_PWRST_D3;
804 set_pin_power_state(codec, 0x19, &parm);
805 /* Smart 5.1 PW2(1bh) */
806 if (spec->smart51_enabled)
807 set_pin_power_state(codec, 0x1b, &parm);
808 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
809 parm);
810 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
811 parm);
812
813 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
814 parm = AC_PWRST_D3;
815 set_pin_power_state(codec, 0x23, &parm);
816 /* Smart 5.1 PW1(1ah) */
817 if (spec->smart51_enabled)
818 set_pin_power_state(codec, 0x1a, &parm);
819 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
820 parm);
821
822 /* Smart 5.1 PW5(1eh) */
823 if (spec->smart51_enabled)
824 set_pin_power_state(codec, 0x1e, &parm);
825 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
826 parm);
827
828 /* Mono out */
829 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
830 present = snd_hda_jack_detect(codec, 0x1c);
831 if (present)
832 mono_out = 0;
833 else {
834 present = snd_hda_jack_detect(codec, 0x1d);
835 if (!spec->hp_independent_mode && present)
836 mono_out = 0;
837 else
838 mono_out = 1;
839 }
840 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
841 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
842 parm);
843 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
844 parm);
845 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
846 parm);
847
848 /* PW 3/4 (1ch/1dh) */
849 parm = AC_PWRST_D3;
850 set_pin_power_state(codec, 0x1c, &parm);
851 set_pin_power_state(codec, 0x1d, &parm);
852 /* HP Independent Mode, power on AOW3 */
853 if (spec->hp_independent_mode)
854 snd_hda_codec_write(codec, 0x25, 0,
855 AC_VERB_SET_POWER_STATE, parm);
856
857 /* force to D0 for internal Speaker */
858 /* MW0 (16h), AOW0 (10h) */
859 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
860 imux_is_smixer ? AC_PWRST_D0 : parm);
861 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
862 mono_out ? AC_PWRST_D0 : parm);
863 } else if (spec->codec_type == VT2002P) {
864 unsigned int present;
865 /* MUX9 (1eh) = stereo mixer */
866 imux_is_smixer = snd_hda_codec_read(
867 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
868 /* inputs */
869 /* PW 5/6/7 (29h/2ah/2bh) */
870 parm = AC_PWRST_D3;
871 set_pin_power_state(codec, 0x29, &parm);
872 set_pin_power_state(codec, 0x2a, &parm);
873 set_pin_power_state(codec, 0x2b, &parm);
874 if (imux_is_smixer)
875 parm = AC_PWRST_D0;
876 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
877 snd_hda_codec_write(codec, 0x1e, 0,
878 AC_VERB_SET_POWER_STATE, parm);
879 snd_hda_codec_write(codec, 0x1f, 0,
880 AC_VERB_SET_POWER_STATE, parm);
881 snd_hda_codec_write(codec, 0x10, 0,
882 AC_VERB_SET_POWER_STATE, parm);
883 snd_hda_codec_write(codec, 0x11, 0,
884 AC_VERB_SET_POWER_STATE, parm);
885
886 /* outputs */
887 /* AOW0 (8h)*/
888 snd_hda_codec_write(codec, 0x8, 0,
889 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
890
891 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
892 parm = AC_PWRST_D3;
893 set_pin_power_state(codec, 0x26, &parm);
894 snd_hda_codec_write(codec, 0x1c, 0,
895 AC_VERB_SET_POWER_STATE, parm);
896 snd_hda_codec_write(codec, 0x37,
897 0, AC_VERB_SET_POWER_STATE, parm);
898
899 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
900 parm = AC_PWRST_D3;
901 set_pin_power_state(codec, 0x25, &parm);
902 snd_hda_codec_write(codec, 0x19, 0,
903 AC_VERB_SET_POWER_STATE, parm);
904 snd_hda_codec_write(codec, 0x35, 0,
905 AC_VERB_SET_POWER_STATE, parm);
906 if (spec->hp_independent_mode) {
907 snd_hda_codec_write(codec, 0x9, 0,
908 AC_VERB_SET_POWER_STATE, parm);
909 }
910
911 /* Class-D */
912 /* PW0 (24h), MW0(18h), MUX0(34h) */
913 present = snd_hda_jack_detect(codec, 0x25);
914 parm = AC_PWRST_D3;
915 set_pin_power_state(codec, 0x24, &parm);
916 if (present) {
917 snd_hda_codec_write(
918 codec, 0x18, 0,
919 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
920 snd_hda_codec_write(
921 codec, 0x34, 0,
922 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
923 } else {
924 snd_hda_codec_write(
925 codec, 0x18, 0,
926 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
927 snd_hda_codec_write(
928 codec, 0x34, 0,
929 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
930 }
931
932 /* Mono Out */
933 /* PW15 (31h), MW8(17h), MUX8(3bh) */
934 present = snd_hda_jack_detect(codec, 0x26);
935 parm = AC_PWRST_D3;
936 set_pin_power_state(codec, 0x31, &parm);
937 if (present) {
938 snd_hda_codec_write(
939 codec, 0x17, 0,
940 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
941 snd_hda_codec_write(
942 codec, 0x3b, 0,
943 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
944 } else {
945 snd_hda_codec_write(
946 codec, 0x17, 0,
947 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
948 snd_hda_codec_write(
949 codec, 0x3b, 0,
950 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
951 }
952
953 /* MW9 (21h) */
954 if (imux_is_smixer || !is_aa_path_mute(codec))
955 snd_hda_codec_write(
956 codec, 0x21, 0,
957 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
958 else
959 snd_hda_codec_write(
960 codec, 0x21, 0,
961 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
962 } else if (spec->codec_type == VT1812) {
963 unsigned int present;
964 /* MUX10 (1eh) = stereo mixer */
965 imux_is_smixer = snd_hda_codec_read(
966 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
967 /* inputs */
968 /* PW 5/6/7 (29h/2ah/2bh) */
969 parm = AC_PWRST_D3;
970 set_pin_power_state(codec, 0x29, &parm);
971 set_pin_power_state(codec, 0x2a, &parm);
972 set_pin_power_state(codec, 0x2b, &parm);
973 if (imux_is_smixer)
974 parm = AC_PWRST_D0;
975 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
976 snd_hda_codec_write(codec, 0x1e, 0,
977 AC_VERB_SET_POWER_STATE, parm);
978 snd_hda_codec_write(codec, 0x1f, 0,
979 AC_VERB_SET_POWER_STATE, parm);
980 snd_hda_codec_write(codec, 0x10, 0,
981 AC_VERB_SET_POWER_STATE, parm);
982 snd_hda_codec_write(codec, 0x11, 0,
983 AC_VERB_SET_POWER_STATE, parm);
984
985 /* outputs */
986 /* AOW0 (8h)*/
987 snd_hda_codec_write(codec, 0x8, 0,
988 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
989
990 /* PW4 (28h), MW4 (18h), MUX4(38h) */
991 parm = AC_PWRST_D3;
992 set_pin_power_state(codec, 0x28, &parm);
993 snd_hda_codec_write(codec, 0x18, 0,
994 AC_VERB_SET_POWER_STATE, parm);
995 snd_hda_codec_write(codec, 0x38, 0,
996 AC_VERB_SET_POWER_STATE, parm);
997
998 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
999 parm = AC_PWRST_D3;
1000 set_pin_power_state(codec, 0x25, &parm);
1001 snd_hda_codec_write(codec, 0x15, 0,
1002 AC_VERB_SET_POWER_STATE, parm);
1003 snd_hda_codec_write(codec, 0x35, 0,
1004 AC_VERB_SET_POWER_STATE, parm);
1005 if (spec->hp_independent_mode) {
1006 snd_hda_codec_write(codec, 0x9, 0,
1007 AC_VERB_SET_POWER_STATE, parm);
1008 }
1009
1010 /* Internal Speaker */
1011 /* PW0 (24h), MW0(14h), MUX0(34h) */
1012 present = snd_hda_jack_detect(codec, 0x25);
1013 parm = AC_PWRST_D3;
1014 set_pin_power_state(codec, 0x24, &parm);
1015 if (present) {
1016 snd_hda_codec_write(codec, 0x14, 0,
1017 AC_VERB_SET_POWER_STATE,
1018 AC_PWRST_D3);
1019 snd_hda_codec_write(codec, 0x34, 0,
1020 AC_VERB_SET_POWER_STATE,
1021 AC_PWRST_D3);
1022 } else {
1023 snd_hda_codec_write(codec, 0x14, 0,
1024 AC_VERB_SET_POWER_STATE,
1025 AC_PWRST_D0);
1026 snd_hda_codec_write(codec, 0x34, 0,
1027 AC_VERB_SET_POWER_STATE,
1028 AC_PWRST_D0);
1029 }
1030 /* Mono Out */
1031 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1032 present = snd_hda_jack_detect(codec, 0x28);
1033 parm = AC_PWRST_D3;
1034 set_pin_power_state(codec, 0x31, &parm);
1035 if (present) {
1036 snd_hda_codec_write(codec, 0x1c, 0,
1037 AC_VERB_SET_POWER_STATE,
1038 AC_PWRST_D3);
1039 snd_hda_codec_write(codec, 0x3c, 0,
1040 AC_VERB_SET_POWER_STATE,
1041 AC_PWRST_D3);
1042 snd_hda_codec_write(codec, 0x3e, 0,
1043 AC_VERB_SET_POWER_STATE,
1044 AC_PWRST_D3);
1045 } else {
1046 snd_hda_codec_write(codec, 0x1c, 0,
1047 AC_VERB_SET_POWER_STATE,
1048 AC_PWRST_D0);
1049 snd_hda_codec_write(codec, 0x3c, 0,
1050 AC_VERB_SET_POWER_STATE,
1051 AC_PWRST_D0);
1052 snd_hda_codec_write(codec, 0x3e, 0,
1053 AC_VERB_SET_POWER_STATE,
1054 AC_PWRST_D0);
1055 }
1056
1057 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1058 parm = AC_PWRST_D3;
1059 set_pin_power_state(codec, 0x33, &parm);
1060 snd_hda_codec_write(codec, 0x1d, 0,
1061 AC_VERB_SET_POWER_STATE, parm);
1062 snd_hda_codec_write(codec, 0x3d, 0,
1063 AC_VERB_SET_POWER_STATE, parm);
1064
1065 /* MW9 (21h) */
1066 if (imux_is_smixer || !is_aa_path_mute(codec))
1067 snd_hda_codec_write(
1068 codec, 0x21, 0,
1069 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1070 else
1071 snd_hda_codec_write(
1072 codec, 0x21, 0,
1073 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1074 }
1075 }
1076
1077 /*
1078 * input MUX handling
1079 */
1080 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1081 struct snd_ctl_elem_info *uinfo)
1082 {
1083 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1084 struct via_spec *spec = codec->spec;
1085 return snd_hda_input_mux_info(spec->input_mux, uinfo);
1086 }
1087
1088 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1089 struct snd_ctl_elem_value *ucontrol)
1090 {
1091 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1092 struct via_spec *spec = codec->spec;
1093 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1094
1095 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
1096 return 0;
1097 }
1098
1099 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1100 struct snd_ctl_elem_value *ucontrol)
1101 {
1102 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1103 struct via_spec *spec = codec->spec;
1104 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1105
1106 if (!spec->mux_nids[adc_idx])
1107 return -EINVAL;
1108 /* switch to D0 beofre change index */
1109 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1110 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1111 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1112 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1113 /* update jack power state */
1114 set_jack_power_state(codec);
1115
1116 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1117 spec->mux_nids[adc_idx],
1118 &spec->cur_mux[adc_idx]);
1119 }
1120
1121 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
1122 struct snd_ctl_elem_info *uinfo)
1123 {
1124 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1125 struct via_spec *spec = codec->spec;
1126 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
1127 }
1128
1129 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
1130 struct snd_ctl_elem_value *ucontrol)
1131 {
1132 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1133 hda_nid_t nid = kcontrol->private_value;
1134 unsigned int pinsel;
1135
1136 /* use !! to translate conn sel 2 for VT1718S */
1137 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1138 AC_VERB_GET_CONNECT_SEL,
1139 0x00);
1140 ucontrol->value.enumerated.item[0] = pinsel;
1141
1142 return 0;
1143 }
1144
1145 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1146 {
1147 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1148 if (ctl) {
1149 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1150 ctl->vd[0].access |= active
1151 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1152 snd_ctl_notify(codec->bus->card,
1153 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1154 }
1155 }
1156
1157 static hda_nid_t side_mute_channel(struct via_spec *spec)
1158 {
1159 switch (spec->codec_type) {
1160 case VT1708: return 0x1b;
1161 case VT1709_10CH: return 0x29;
1162 case VT1708B_8CH: /* fall thru */
1163 case VT1708S: return 0x27;
1164 default: return 0;
1165 }
1166 }
1167
1168 static int update_side_mute_status(struct hda_codec *codec)
1169 {
1170 /* mute side channel */
1171 struct via_spec *spec = codec->spec;
1172 unsigned int parm = spec->hp_independent_mode
1173 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1174 hda_nid_t sw3 = side_mute_channel(spec);
1175
1176 if (sw3)
1177 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1178 parm);
1179 return 0;
1180 }
1181
1182 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
1183 struct snd_ctl_elem_value *ucontrol)
1184 {
1185 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1186 struct via_spec *spec = codec->spec;
1187 hda_nid_t nid = kcontrol->private_value;
1188 unsigned int pinsel = ucontrol->value.enumerated.item[0];
1189 /* Get Independent Mode index of headphone pin widget */
1190 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1191 ? 1 : 0;
1192 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
1193
1194 if (spec->multiout.hp_nid && spec->multiout.hp_nid
1195 != spec->multiout.dac_nids[HDA_FRONT])
1196 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
1197 0, 0, 0);
1198
1199 update_side_mute_status(codec);
1200 /* update HP volume/swtich active state */
1201 if (spec->codec_type == VT1708S
1202 || spec->codec_type == VT1702
1203 || spec->codec_type == VT1718S
1204 || spec->codec_type == VT1716S
1205 || spec->codec_type == VT2002P
1206 || spec->codec_type == VT1812) {
1207 activate_ctl(codec, "Headphone Playback Volume",
1208 spec->hp_independent_mode);
1209 activate_ctl(codec, "Headphone Playback Switch",
1210 spec->hp_independent_mode);
1211 }
1212 return 0;
1213 }
1214
1215 static struct snd_kcontrol_new via_hp_mixer[2] = {
1216 {
1217 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1218 .name = "Independent HP",
1219 .info = via_independent_hp_info,
1220 .get = via_independent_hp_get,
1221 .put = via_independent_hp_put,
1222 },
1223 {
1224 .iface = NID_MAPPING,
1225 .name = "Independent HP",
1226 },
1227 };
1228
1229 static int via_hp_build(struct hda_codec *codec)
1230 {
1231 struct via_spec *spec = codec->spec;
1232 struct snd_kcontrol_new *knew;
1233 hda_nid_t nid;
1234 int nums;
1235 hda_nid_t conn[HDA_MAX_CONNECTIONS];
1236
1237 switch (spec->codec_type) {
1238 case VT1718S:
1239 nid = 0x34;
1240 break;
1241 case VT2002P:
1242 nid = 0x35;
1243 break;
1244 case VT1812:
1245 nid = 0x3d;
1246 break;
1247 default:
1248 nid = spec->autocfg.hp_pins[0];
1249 break;
1250 }
1251
1252 nums = snd_hda_get_connections(codec, nid, conn, HDA_MAX_CONNECTIONS);
1253 if (nums <= 1)
1254 return 0;
1255
1256 knew = via_clone_control(spec, &via_hp_mixer[0]);
1257 if (knew == NULL)
1258 return -ENOMEM;
1259
1260 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
1261 knew->private_value = nid;
1262
1263 knew = via_clone_control(spec, &via_hp_mixer[1]);
1264 if (knew == NULL)
1265 return -ENOMEM;
1266 knew->subdevice = side_mute_channel(spec);
1267
1268 return 0;
1269 }
1270
1271 static void notify_aa_path_ctls(struct hda_codec *codec)
1272 {
1273 int i;
1274 struct snd_ctl_elem_id id;
1275 const char *labels[] = {"Mic", "Front Mic", "Line"};
1276
1277 memset(&id, 0, sizeof(id));
1278 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1279 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1280 sprintf(id.name, "%s Playback Volume", labels[i]);
1281 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1282 &id);
1283 }
1284 }
1285
1286 static void mute_aa_path(struct hda_codec *codec, int mute)
1287 {
1288 struct via_spec *spec = codec->spec;
1289 hda_nid_t nid_mixer;
1290 int start_idx;
1291 int end_idx;
1292 int i;
1293 /* get nid of MW0 and start & end index */
1294 switch (spec->codec_type) {
1295 case VT1708:
1296 nid_mixer = 0x17;
1297 start_idx = 2;
1298 end_idx = 4;
1299 break;
1300 case VT1709_10CH:
1301 case VT1709_6CH:
1302 nid_mixer = 0x18;
1303 start_idx = 2;
1304 end_idx = 4;
1305 break;
1306 case VT1708B_8CH:
1307 case VT1708B_4CH:
1308 case VT1708S:
1309 case VT1716S:
1310 nid_mixer = 0x16;
1311 start_idx = 2;
1312 end_idx = 4;
1313 break;
1314 default:
1315 return;
1316 }
1317 /* check AA path's mute status */
1318 for (i = start_idx; i <= end_idx; i++) {
1319 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1320 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1321 HDA_AMP_MUTE, val);
1322 }
1323 }
1324 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1325 {
1326 const struct auto_pin_cfg *cfg = &spec->autocfg;
1327 int i;
1328
1329 for (i = 0; i < cfg->num_inputs; i++) {
1330 if (pin == cfg->inputs[i].pin)
1331 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
1332 }
1333 return 0;
1334 }
1335
1336 static int via_smart51_info(struct snd_kcontrol *kcontrol,
1337 struct snd_ctl_elem_info *uinfo)
1338 {
1339 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1340 uinfo->count = 1;
1341 uinfo->value.integer.min = 0;
1342 uinfo->value.integer.max = 1;
1343 return 0;
1344 }
1345
1346 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1347 struct snd_ctl_elem_value *ucontrol)
1348 {
1349 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1350 struct via_spec *spec = codec->spec;
1351 const struct auto_pin_cfg *cfg = &spec->autocfg;
1352 int on = 1;
1353 int i;
1354
1355 for (i = 0; i < cfg->num_inputs; i++) {
1356 hda_nid_t nid = cfg->inputs[i].pin;
1357 int ctl = snd_hda_codec_read(codec, nid, 0,
1358 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1359 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1360 continue;
1361 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1362 spec->hp_independent_mode && spec->codec_type != VT1718S)
1363 continue; /* ignore FMic for independent HP */
1364 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
1365 on = 0;
1366 }
1367 *ucontrol->value.integer.value = on;
1368 return 0;
1369 }
1370
1371 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1372 struct snd_ctl_elem_value *ucontrol)
1373 {
1374 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1375 struct via_spec *spec = codec->spec;
1376 const struct auto_pin_cfg *cfg = &spec->autocfg;
1377 int out_in = *ucontrol->value.integer.value
1378 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1379 int i;
1380
1381 for (i = 0; i < cfg->num_inputs; i++) {
1382 hda_nid_t nid = cfg->inputs[i].pin;
1383 unsigned int parm;
1384
1385 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1386 continue;
1387 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1388 spec->hp_independent_mode && spec->codec_type != VT1718S)
1389 continue; /* don't retask FMic for independent HP */
1390
1391 parm = snd_hda_codec_read(codec, nid, 0,
1392 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1393 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1394 parm |= out_in;
1395 snd_hda_codec_write(codec, nid, 0,
1396 AC_VERB_SET_PIN_WIDGET_CONTROL,
1397 parm);
1398 if (out_in == AC_PINCTL_OUT_EN) {
1399 mute_aa_path(codec, 1);
1400 notify_aa_path_ctls(codec);
1401 }
1402 if (spec->codec_type == VT1718S) {
1403 snd_hda_codec_amp_stereo(
1404 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1405 HDA_AMP_UNMUTE);
1406 }
1407 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
1408 if (spec->codec_type == VT1708S
1409 || spec->codec_type == VT1716S) {
1410 /* input = index 1 (AOW3) */
1411 snd_hda_codec_write(
1412 codec, nid, 0,
1413 AC_VERB_SET_CONNECT_SEL, 1);
1414 snd_hda_codec_amp_stereo(
1415 codec, nid, HDA_OUTPUT,
1416 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1417 }
1418 }
1419 }
1420 spec->smart51_enabled = *ucontrol->value.integer.value;
1421 set_jack_power_state(codec);
1422 return 1;
1423 }
1424
1425 static struct snd_kcontrol_new via_smart51_mixer[2] = {
1426 {
1427 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1428 .name = "Smart 5.1",
1429 .count = 1,
1430 .info = via_smart51_info,
1431 .get = via_smart51_get,
1432 .put = via_smart51_put,
1433 },
1434 {
1435 .iface = NID_MAPPING,
1436 .name = "Smart 5.1",
1437 }
1438 };
1439
1440 static int via_smart51_build(struct via_spec *spec)
1441 {
1442 struct snd_kcontrol_new *knew;
1443 const struct auto_pin_cfg *cfg = &spec->autocfg;
1444 hda_nid_t nid;
1445 int i;
1446
1447 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1448 if (knew == NULL)
1449 return -ENOMEM;
1450
1451 for (i = 0; i < cfg->num_inputs; i++) {
1452 nid = cfg->inputs[i].pin;
1453 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1454 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1455 if (knew == NULL)
1456 return -ENOMEM;
1457 knew->subdevice = nid;
1458 break;
1459 }
1460 }
1461
1462 return 0;
1463 }
1464
1465 /* capture mixer elements */
1466 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1467 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1468 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1469 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1470 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1471 {
1472 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1473 /* The multiple "Capture Source" controls confuse alsamixer
1474 * So call somewhat different..
1475 */
1476 /* .name = "Capture Source", */
1477 .name = "Input Source",
1478 .count = 1,
1479 .info = via_mux_enum_info,
1480 .get = via_mux_enum_get,
1481 .put = via_mux_enum_put,
1482 },
1483 { } /* end */
1484 };
1485
1486 /* check AA path's mute statue */
1487 static int is_aa_path_mute(struct hda_codec *codec)
1488 {
1489 int mute = 1;
1490 hda_nid_t nid_mixer;
1491 int start_idx;
1492 int end_idx;
1493 int i;
1494 struct via_spec *spec = codec->spec;
1495 /* get nid of MW0 and start & end index */
1496 switch (spec->codec_type) {
1497 case VT1708B_8CH:
1498 case VT1708B_4CH:
1499 case VT1708S:
1500 case VT1716S:
1501 nid_mixer = 0x16;
1502 start_idx = 2;
1503 end_idx = 4;
1504 break;
1505 case VT1702:
1506 nid_mixer = 0x1a;
1507 start_idx = 1;
1508 end_idx = 3;
1509 break;
1510 case VT1718S:
1511 nid_mixer = 0x21;
1512 start_idx = 1;
1513 end_idx = 3;
1514 break;
1515 case VT2002P:
1516 case VT1812:
1517 nid_mixer = 0x21;
1518 start_idx = 0;
1519 end_idx = 2;
1520 break;
1521 default:
1522 return 0;
1523 }
1524 /* check AA path's mute status */
1525 for (i = start_idx; i <= end_idx; i++) {
1526 unsigned int con_list = snd_hda_codec_read(
1527 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1528 int shift = 8 * (i % 4);
1529 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1530 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1531 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1532 /* check mute status while the pin is connected */
1533 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1534 HDA_INPUT, i) >> 7;
1535 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1536 HDA_INPUT, i) >> 7;
1537 if (!mute_l || !mute_r) {
1538 mute = 0;
1539 break;
1540 }
1541 }
1542 }
1543 return mute;
1544 }
1545
1546 /* enter/exit analog low-current mode */
1547 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1548 {
1549 struct via_spec *spec = codec->spec;
1550 static int saved_stream_idle = 1; /* saved stream idle status */
1551 int enable = is_aa_path_mute(codec);
1552 unsigned int verb = 0;
1553 unsigned int parm = 0;
1554
1555 if (stream_idle == -1) /* stream status did not change */
1556 enable = enable && saved_stream_idle;
1557 else {
1558 enable = enable && stream_idle;
1559 saved_stream_idle = stream_idle;
1560 }
1561
1562 /* decide low current mode's verb & parameter */
1563 switch (spec->codec_type) {
1564 case VT1708B_8CH:
1565 case VT1708B_4CH:
1566 verb = 0xf70;
1567 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1568 break;
1569 case VT1708S:
1570 case VT1718S:
1571 case VT1716S:
1572 verb = 0xf73;
1573 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1574 break;
1575 case VT1702:
1576 verb = 0xf73;
1577 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1578 break;
1579 case VT2002P:
1580 case VT1812:
1581 verb = 0xf93;
1582 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1583 break;
1584 default:
1585 return; /* other codecs are not supported */
1586 }
1587 /* send verb */
1588 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1589 }
1590
1591 /*
1592 * generic initialization of ADC, input mixers and output mixers
1593 */
1594 static struct hda_verb vt1708_volume_init_verbs[] = {
1595 /*
1596 * Unmute ADC0-1 and set the default input to mic-in
1597 */
1598 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1599 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1600
1601
1602 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1603 * mixer widget
1604 */
1605 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1606 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1607 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1608 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1609 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1610 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1611
1612 /*
1613 * Set up output mixers (0x19 - 0x1b)
1614 */
1615 /* set vol=0 to output mixers */
1616 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1617 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1618 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1619
1620 /* Setup default input MW0 to PW4 */
1621 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1622 /* PW9 Output enable */
1623 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1624 { }
1625 };
1626
1627 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1628 struct hda_codec *codec,
1629 struct snd_pcm_substream *substream)
1630 {
1631 struct via_spec *spec = codec->spec;
1632 int idle = substream->pstr->substream_opened == 1
1633 && substream->ref_count == 0;
1634 analog_low_current_mode(codec, idle);
1635 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1636 hinfo);
1637 }
1638
1639 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1640 unsigned int stream_tag,
1641 unsigned int format,
1642 struct snd_pcm_substream *substream)
1643 {
1644 struct via_spec *spec = codec->spec;
1645 struct hda_multi_out *mout = &spec->multiout;
1646 hda_nid_t *nids = mout->dac_nids;
1647 int chs = substream->runtime->channels;
1648 int i;
1649
1650 mutex_lock(&codec->spdif_mutex);
1651 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1652 if (chs == 2 &&
1653 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1654 format) &&
1655 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1656 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1657 /* turn off SPDIF once; otherwise the IEC958 bits won't
1658 * be updated */
1659 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1660 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1661 AC_VERB_SET_DIGI_CONVERT_1,
1662 codec->spdif_ctls &
1663 ~AC_DIG1_ENABLE & 0xff);
1664 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1665 stream_tag, 0, format);
1666 /* turn on again (if needed) */
1667 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1668 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1669 AC_VERB_SET_DIGI_CONVERT_1,
1670 codec->spdif_ctls & 0xff);
1671 } else {
1672 mout->dig_out_used = 0;
1673 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1674 0, 0, 0);
1675 }
1676 }
1677 mutex_unlock(&codec->spdif_mutex);
1678
1679 /* front */
1680 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1681 0, format);
1682
1683 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1684 && !spec->hp_independent_mode)
1685 /* headphone out will just decode front left/right (stereo) */
1686 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1687 0, format);
1688
1689 /* extra outputs copied from front */
1690 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1691 if (mout->extra_out_nid[i])
1692 snd_hda_codec_setup_stream(codec,
1693 mout->extra_out_nid[i],
1694 stream_tag, 0, format);
1695
1696 /* surrounds */
1697 for (i = 1; i < mout->num_dacs; i++) {
1698 if (chs >= (i + 1) * 2) /* independent out */
1699 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1700 i * 2, format);
1701 else /* copy front */
1702 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1703 0, format);
1704 }
1705 }
1706
1707 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1708 struct hda_codec *codec,
1709 unsigned int stream_tag,
1710 unsigned int format,
1711 struct snd_pcm_substream *substream)
1712 {
1713 struct via_spec *spec = codec->spec;
1714 struct hda_multi_out *mout = &spec->multiout;
1715 hda_nid_t *nids = mout->dac_nids;
1716
1717 if (substream->number == 0)
1718 playback_multi_pcm_prep_0(codec, stream_tag, format,
1719 substream);
1720 else {
1721 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1722 spec->hp_independent_mode)
1723 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1724 stream_tag, 0, format);
1725 }
1726 vt1708_start_hp_work(spec);
1727 return 0;
1728 }
1729
1730 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1731 struct hda_codec *codec,
1732 struct snd_pcm_substream *substream)
1733 {
1734 struct via_spec *spec = codec->spec;
1735 struct hda_multi_out *mout = &spec->multiout;
1736 hda_nid_t *nids = mout->dac_nids;
1737 int i;
1738
1739 if (substream->number == 0) {
1740 for (i = 0; i < mout->num_dacs; i++)
1741 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1742
1743 if (mout->hp_nid && !spec->hp_independent_mode)
1744 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1745 0, 0, 0);
1746
1747 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1748 if (mout->extra_out_nid[i])
1749 snd_hda_codec_setup_stream(codec,
1750 mout->extra_out_nid[i],
1751 0, 0, 0);
1752 mutex_lock(&codec->spdif_mutex);
1753 if (mout->dig_out_nid &&
1754 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1755 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1756 0, 0, 0);
1757 mout->dig_out_used = 0;
1758 }
1759 mutex_unlock(&codec->spdif_mutex);
1760 } else {
1761 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1762 spec->hp_independent_mode)
1763 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1764 0, 0, 0);
1765 }
1766 vt1708_stop_hp_work(spec);
1767 return 0;
1768 }
1769
1770 /*
1771 * Digital out
1772 */
1773 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1774 struct hda_codec *codec,
1775 struct snd_pcm_substream *substream)
1776 {
1777 struct via_spec *spec = codec->spec;
1778 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1779 }
1780
1781 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1782 struct hda_codec *codec,
1783 struct snd_pcm_substream *substream)
1784 {
1785 struct via_spec *spec = codec->spec;
1786 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1787 }
1788
1789 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1790 struct hda_codec *codec,
1791 unsigned int stream_tag,
1792 unsigned int format,
1793 struct snd_pcm_substream *substream)
1794 {
1795 struct via_spec *spec = codec->spec;
1796 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1797 stream_tag, format, substream);
1798 }
1799
1800 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1801 struct hda_codec *codec,
1802 struct snd_pcm_substream *substream)
1803 {
1804 struct via_spec *spec = codec->spec;
1805 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1806 return 0;
1807 }
1808
1809 /*
1810 * Analog capture
1811 */
1812 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1813 struct hda_codec *codec,
1814 unsigned int stream_tag,
1815 unsigned int format,
1816 struct snd_pcm_substream *substream)
1817 {
1818 struct via_spec *spec = codec->spec;
1819
1820 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1821 stream_tag, 0, format);
1822 return 0;
1823 }
1824
1825 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1826 struct hda_codec *codec,
1827 struct snd_pcm_substream *substream)
1828 {
1829 struct via_spec *spec = codec->spec;
1830 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1831 return 0;
1832 }
1833
1834 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1835 .substreams = 2,
1836 .channels_min = 2,
1837 .channels_max = 8,
1838 .nid = 0x10, /* NID to query formats and rates */
1839 .ops = {
1840 .open = via_playback_pcm_open,
1841 .prepare = via_playback_multi_pcm_prepare,
1842 .cleanup = via_playback_multi_pcm_cleanup
1843 },
1844 };
1845
1846 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1847 .substreams = 2,
1848 .channels_min = 2,
1849 .channels_max = 8,
1850 .nid = 0x10, /* NID to query formats and rates */
1851 /* We got noisy outputs on the right channel on VT1708 when
1852 * 24bit samples are used. Until any workaround is found,
1853 * disable the 24bit format, so far.
1854 */
1855 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1856 .ops = {
1857 .open = via_playback_pcm_open,
1858 .prepare = via_playback_multi_pcm_prepare,
1859 .cleanup = via_playback_multi_pcm_cleanup
1860 },
1861 };
1862
1863 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1864 .substreams = 2,
1865 .channels_min = 2,
1866 .channels_max = 2,
1867 .nid = 0x15, /* NID to query formats and rates */
1868 .ops = {
1869 .prepare = via_capture_pcm_prepare,
1870 .cleanup = via_capture_pcm_cleanup
1871 },
1872 };
1873
1874 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1875 .substreams = 1,
1876 .channels_min = 2,
1877 .channels_max = 2,
1878 /* NID is set in via_build_pcms */
1879 .ops = {
1880 .open = via_dig_playback_pcm_open,
1881 .close = via_dig_playback_pcm_close,
1882 .prepare = via_dig_playback_pcm_prepare,
1883 .cleanup = via_dig_playback_pcm_cleanup
1884 },
1885 };
1886
1887 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1888 .substreams = 1,
1889 .channels_min = 2,
1890 .channels_max = 2,
1891 };
1892
1893 static int via_build_controls(struct hda_codec *codec)
1894 {
1895 struct via_spec *spec = codec->spec;
1896 struct snd_kcontrol *kctl;
1897 struct snd_kcontrol_new *knew;
1898 int err, i;
1899
1900 for (i = 0; i < spec->num_mixers; i++) {
1901 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1902 if (err < 0)
1903 return err;
1904 }
1905
1906 if (spec->multiout.dig_out_nid) {
1907 err = snd_hda_create_spdif_out_ctls(codec,
1908 spec->multiout.dig_out_nid);
1909 if (err < 0)
1910 return err;
1911 err = snd_hda_create_spdif_share_sw(codec,
1912 &spec->multiout);
1913 if (err < 0)
1914 return err;
1915 spec->multiout.share_spdif = 1;
1916 }
1917 if (spec->dig_in_nid) {
1918 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1919 if (err < 0)
1920 return err;
1921 }
1922
1923 /* assign Capture Source enums to NID */
1924 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1925 for (i = 0; kctl && i < kctl->count; i++) {
1926 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1927 if (err < 0)
1928 return err;
1929 }
1930
1931 /* other nid->control mapping */
1932 for (i = 0; i < spec->num_mixers; i++) {
1933 for (knew = spec->mixers[i]; knew->name; knew++) {
1934 if (knew->iface != NID_MAPPING)
1935 continue;
1936 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1937 if (kctl == NULL)
1938 continue;
1939 err = snd_hda_add_nid(codec, kctl, 0,
1940 knew->subdevice);
1941 }
1942 }
1943
1944 /* init power states */
1945 set_jack_power_state(codec);
1946 analog_low_current_mode(codec, 1);
1947
1948 via_free_kctls(codec); /* no longer needed */
1949 return 0;
1950 }
1951
1952 static int via_build_pcms(struct hda_codec *codec)
1953 {
1954 struct via_spec *spec = codec->spec;
1955 struct hda_pcm *info = spec->pcm_rec;
1956
1957 codec->num_pcms = 1;
1958 codec->pcm_info = info;
1959
1960 info->name = spec->stream_name_analog;
1961 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1962 *(spec->stream_analog_playback);
1963 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1964 spec->multiout.dac_nids[0];
1965 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1966 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1967
1968 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1969 spec->multiout.max_channels;
1970
1971 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1972 codec->num_pcms++;
1973 info++;
1974 info->name = spec->stream_name_digital;
1975 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1976 if (spec->multiout.dig_out_nid) {
1977 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1978 *(spec->stream_digital_playback);
1979 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1980 spec->multiout.dig_out_nid;
1981 }
1982 if (spec->dig_in_nid) {
1983 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1984 *(spec->stream_digital_capture);
1985 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1986 spec->dig_in_nid;
1987 }
1988 }
1989
1990 return 0;
1991 }
1992
1993 static void via_free(struct hda_codec *codec)
1994 {
1995 struct via_spec *spec = codec->spec;
1996
1997 if (!spec)
1998 return;
1999
2000 via_free_kctls(codec);
2001 vt1708_stop_hp_work(spec);
2002 kfree(codec->spec);
2003 }
2004
2005 /* mute internal speaker if HP is plugged */
2006 static void via_hp_automute(struct hda_codec *codec)
2007 {
2008 unsigned int present = 0;
2009 struct via_spec *spec = codec->spec;
2010
2011 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2012
2013 if (!spec->hp_independent_mode) {
2014 struct snd_ctl_elem_id id;
2015 /* auto mute */
2016 snd_hda_codec_amp_stereo(
2017 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
2018 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2019 /* notify change */
2020 memset(&id, 0, sizeof(id));
2021 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2022 strcpy(id.name, "Front Playback Switch");
2023 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2024 &id);
2025 }
2026 }
2027
2028 /* mute mono out if HP or Line out is plugged */
2029 static void via_mono_automute(struct hda_codec *codec)
2030 {
2031 unsigned int hp_present, lineout_present;
2032 struct via_spec *spec = codec->spec;
2033
2034 if (spec->codec_type != VT1716S)
2035 return;
2036
2037 lineout_present = snd_hda_jack_detect(codec,
2038 spec->autocfg.line_out_pins[0]);
2039
2040 /* Mute Mono Out if Line Out is plugged */
2041 if (lineout_present) {
2042 snd_hda_codec_amp_stereo(
2043 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
2044 return;
2045 }
2046
2047 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2048
2049 if (!spec->hp_independent_mode)
2050 snd_hda_codec_amp_stereo(
2051 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
2052 hp_present ? HDA_AMP_MUTE : 0);
2053 }
2054
2055 static void via_gpio_control(struct hda_codec *codec)
2056 {
2057 unsigned int gpio_data;
2058 unsigned int vol_counter;
2059 unsigned int vol;
2060 unsigned int master_vol;
2061
2062 struct via_spec *spec = codec->spec;
2063
2064 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
2065 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
2066
2067 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
2068 0xF84, 0) & 0x3F0000) >> 16;
2069
2070 vol = vol_counter & 0x1F;
2071 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
2072 AC_VERB_GET_AMP_GAIN_MUTE,
2073 AC_AMP_GET_INPUT);
2074
2075 if (gpio_data == 0x02) {
2076 /* unmute line out */
2077 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
2078 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
2079
2080 if (vol_counter & 0x20) {
2081 /* decrease volume */
2082 if (vol > master_vol)
2083 vol = master_vol;
2084 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
2085 0, HDA_AMP_VOLMASK,
2086 master_vol-vol);
2087 } else {
2088 /* increase volume */
2089 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
2090 HDA_AMP_VOLMASK,
2091 ((master_vol+vol) > 0x2A) ? 0x2A :
2092 (master_vol+vol));
2093 }
2094 } else if (!(gpio_data & 0x02)) {
2095 /* mute line out */
2096 snd_hda_codec_amp_stereo(codec,
2097 spec->autocfg.line_out_pins[0],
2098 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2099 HDA_AMP_MUTE);
2100 }
2101 }
2102
2103 /* mute Internal-Speaker if HP is plugged */
2104 static void via_speaker_automute(struct hda_codec *codec)
2105 {
2106 unsigned int hp_present;
2107 struct via_spec *spec = codec->spec;
2108
2109 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2110 return;
2111
2112 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2113
2114 if (!spec->hp_independent_mode) {
2115 struct snd_ctl_elem_id id;
2116 snd_hda_codec_amp_stereo(
2117 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2118 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2119 /* notify change */
2120 memset(&id, 0, sizeof(id));
2121 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2122 strcpy(id.name, "Speaker Playback Switch");
2123 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2124 &id);
2125 }
2126 }
2127
2128 /* mute line-out and internal speaker if HP is plugged */
2129 static void via_hp_bind_automute(struct hda_codec *codec)
2130 {
2131 /* use long instead of int below just to avoid an internal compiler
2132 * error with gcc 4.0.x
2133 */
2134 unsigned long hp_present, present = 0;
2135 struct via_spec *spec = codec->spec;
2136 int i;
2137
2138 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2139 return;
2140
2141 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2142
2143 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2144
2145 if (!spec->hp_independent_mode) {
2146 /* Mute Line-Outs */
2147 for (i = 0; i < spec->autocfg.line_outs; i++)
2148 snd_hda_codec_amp_stereo(
2149 codec, spec->autocfg.line_out_pins[i],
2150 HDA_OUTPUT, 0,
2151 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2152 if (hp_present)
2153 present = hp_present;
2154 }
2155 /* Speakers */
2156 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2157 snd_hda_codec_amp_stereo(
2158 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2159 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2160 }
2161
2162
2163 /* unsolicited event for jack sensing */
2164 static void via_unsol_event(struct hda_codec *codec,
2165 unsigned int res)
2166 {
2167 res >>= 26;
2168 if (res & VIA_HP_EVENT)
2169 via_hp_automute(codec);
2170 if (res & VIA_GPIO_EVENT)
2171 via_gpio_control(codec);
2172 if (res & VIA_JACK_EVENT)
2173 set_jack_power_state(codec);
2174 if (res & VIA_MONO_EVENT)
2175 via_mono_automute(codec);
2176 if (res & VIA_SPEAKER_EVENT)
2177 via_speaker_automute(codec);
2178 if (res & VIA_BIND_HP_EVENT)
2179 via_hp_bind_automute(codec);
2180 }
2181
2182 static int via_init(struct hda_codec *codec)
2183 {
2184 struct via_spec *spec = codec->spec;
2185 int i;
2186 for (i = 0; i < spec->num_iverbs; i++)
2187 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2188
2189 spec->codec_type = get_codec_type(codec);
2190 if (spec->codec_type == VT1708BCE)
2191 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2192 same */
2193 /* Lydia Add for EAPD enable */
2194 if (!spec->dig_in_nid) { /* No Digital In connection */
2195 if (spec->dig_in_pin) {
2196 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2197 AC_VERB_SET_PIN_WIDGET_CONTROL,
2198 PIN_OUT);
2199 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2200 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2201 }
2202 } else /* enable SPDIF-input pin */
2203 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2204 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2205
2206 /* assign slave outs */
2207 if (spec->slave_dig_outs[0])
2208 codec->slave_dig_outs = spec->slave_dig_outs;
2209
2210 return 0;
2211 }
2212
2213 #ifdef SND_HDA_NEEDS_RESUME
2214 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2215 {
2216 struct via_spec *spec = codec->spec;
2217 vt1708_stop_hp_work(spec);
2218 return 0;
2219 }
2220 #endif
2221
2222 #ifdef CONFIG_SND_HDA_POWER_SAVE
2223 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2224 {
2225 struct via_spec *spec = codec->spec;
2226 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2227 }
2228 #endif
2229
2230 /*
2231 */
2232 static struct hda_codec_ops via_patch_ops = {
2233 .build_controls = via_build_controls,
2234 .build_pcms = via_build_pcms,
2235 .init = via_init,
2236 .free = via_free,
2237 #ifdef SND_HDA_NEEDS_RESUME
2238 .suspend = via_suspend,
2239 #endif
2240 #ifdef CONFIG_SND_HDA_POWER_SAVE
2241 .check_power_status = via_check_power_status,
2242 #endif
2243 };
2244
2245 /* fill in the dac_nids table from the parsed pin configuration */
2246 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2247 const struct auto_pin_cfg *cfg)
2248 {
2249 int i;
2250 hda_nid_t nid;
2251
2252 spec->multiout.num_dacs = cfg->line_outs;
2253
2254 spec->multiout.dac_nids = spec->private_dac_nids;
2255
2256 for (i = 0; i < 4; i++) {
2257 nid = cfg->line_out_pins[i];
2258 if (nid) {
2259 /* config dac list */
2260 switch (i) {
2261 case AUTO_SEQ_FRONT:
2262 spec->multiout.dac_nids[i] = 0x10;
2263 break;
2264 case AUTO_SEQ_CENLFE:
2265 spec->multiout.dac_nids[i] = 0x12;
2266 break;
2267 case AUTO_SEQ_SURROUND:
2268 spec->multiout.dac_nids[i] = 0x11;
2269 break;
2270 case AUTO_SEQ_SIDE:
2271 spec->multiout.dac_nids[i] = 0x13;
2272 break;
2273 }
2274 }
2275 }
2276
2277 return 0;
2278 }
2279
2280 /* add playback controls from the parsed DAC table */
2281 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2282 const struct auto_pin_cfg *cfg)
2283 {
2284 char name[32];
2285 static const char * const chname[4] = {
2286 "Front", "Surround", "C/LFE", "Side"
2287 };
2288 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2289 int i, err;
2290
2291 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2292 nid = cfg->line_out_pins[i];
2293
2294 if (!nid)
2295 continue;
2296
2297 nid_vol = nid_vols[i];
2298
2299 if (i == AUTO_SEQ_CENLFE) {
2300 /* Center/LFE */
2301 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2302 "Center Playback Volume",
2303 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2304 HDA_OUTPUT));
2305 if (err < 0)
2306 return err;
2307 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2308 "LFE Playback Volume",
2309 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2310 HDA_OUTPUT));
2311 if (err < 0)
2312 return err;
2313 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2314 "Center Playback Switch",
2315 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2316 HDA_OUTPUT));
2317 if (err < 0)
2318 return err;
2319 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2320 "LFE Playback Switch",
2321 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2322 HDA_OUTPUT));
2323 if (err < 0)
2324 return err;
2325 } else if (i == AUTO_SEQ_FRONT) {
2326 /* add control to mixer index 0 */
2327 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2328 "Master Front Playback Volume",
2329 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2330 HDA_INPUT));
2331 if (err < 0)
2332 return err;
2333 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2334 "Master Front Playback Switch",
2335 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2336 HDA_INPUT));
2337 if (err < 0)
2338 return err;
2339
2340 /* add control to PW3 */
2341 sprintf(name, "%s Playback Volume", chname[i]);
2342 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2343 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2344 HDA_OUTPUT));
2345 if (err < 0)
2346 return err;
2347 sprintf(name, "%s Playback Switch", chname[i]);
2348 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2349 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2350 HDA_OUTPUT));
2351 if (err < 0)
2352 return err;
2353 } else {
2354 sprintf(name, "%s Playback Volume", chname[i]);
2355 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2356 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2357 HDA_OUTPUT));
2358 if (err < 0)
2359 return err;
2360 sprintf(name, "%s Playback Switch", chname[i]);
2361 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2362 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2363 HDA_OUTPUT));
2364 if (err < 0)
2365 return err;
2366 }
2367 }
2368
2369 return 0;
2370 }
2371
2372 static void create_hp_imux(struct via_spec *spec)
2373 {
2374 int i;
2375 struct hda_input_mux *imux = &spec->private_imux[1];
2376 static const char * const texts[] = { "OFF", "ON", NULL};
2377
2378 /* for hp mode select */
2379 for (i = 0; texts[i]; i++)
2380 snd_hda_add_imux_item(imux, texts[i], i, NULL);
2381
2382 spec->hp_mux = &spec->private_imux[1];
2383 }
2384
2385 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2386 {
2387 int err;
2388
2389 if (!pin)
2390 return 0;
2391
2392 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2393 spec->hp_independent_mode_index = 1;
2394
2395 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2396 "Headphone Playback Volume",
2397 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2398 if (err < 0)
2399 return err;
2400 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2401 "Headphone Playback Switch",
2402 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2403 if (err < 0)
2404 return err;
2405
2406 create_hp_imux(spec);
2407
2408 return 0;
2409 }
2410
2411 /* create playback/capture controls for input pins */
2412 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
2413 const struct auto_pin_cfg *cfg,
2414 hda_nid_t cap_nid,
2415 hda_nid_t pin_idxs[], int num_idxs)
2416 {
2417 struct via_spec *spec = codec->spec;
2418 struct hda_input_mux *imux = &spec->private_imux[0];
2419 int i, err, idx, type, type_idx = 0;
2420
2421 /* for internal loopback recording select */
2422 for (idx = 0; idx < num_idxs; idx++) {
2423 if (pin_idxs[idx] == 0xff) {
2424 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2425 break;
2426 }
2427 }
2428
2429 for (i = 0; i < cfg->num_inputs; i++) {
2430 const char *label;
2431 type = cfg->inputs[i].type;
2432 for (idx = 0; idx < num_idxs; idx++)
2433 if (pin_idxs[idx] == cfg->inputs[i].pin)
2434 break;
2435 if (idx >= num_idxs)
2436 continue;
2437 if (i > 0 && type == cfg->inputs[i - 1].type)
2438 type_idx++;
2439 else
2440 type_idx = 0;
2441 label = hda_get_autocfg_input_label(codec, cfg, i);
2442 err = via_new_analog_input(spec, label, type_idx, idx, cap_nid);
2443 if (err < 0)
2444 return err;
2445 snd_hda_add_imux_item(imux, label, idx, NULL);
2446 }
2447 return 0;
2448 }
2449
2450 /* create playback/capture controls for input pins */
2451 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2452 const struct auto_pin_cfg *cfg)
2453 {
2454 static hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2455 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
2456 ARRAY_SIZE(pin_idxs));
2457 }
2458
2459 #ifdef CONFIG_SND_HDA_POWER_SAVE
2460 static struct hda_amp_list vt1708_loopbacks[] = {
2461 { 0x17, HDA_INPUT, 1 },
2462 { 0x17, HDA_INPUT, 2 },
2463 { 0x17, HDA_INPUT, 3 },
2464 { 0x17, HDA_INPUT, 4 },
2465 { } /* end */
2466 };
2467 #endif
2468
2469 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2470 {
2471 unsigned int def_conf;
2472 unsigned char seqassoc;
2473
2474 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2475 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2476 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2477 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2478 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2479 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2480 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2481 }
2482
2483 return;
2484 }
2485
2486 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2487 struct snd_ctl_elem_value *ucontrol)
2488 {
2489 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2490 struct via_spec *spec = codec->spec;
2491
2492 if (spec->codec_type != VT1708)
2493 return 0;
2494 spec->vt1708_jack_detectect =
2495 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2496 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2497 return 0;
2498 }
2499
2500 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2501 struct snd_ctl_elem_value *ucontrol)
2502 {
2503 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2504 struct via_spec *spec = codec->spec;
2505 int change;
2506
2507 if (spec->codec_type != VT1708)
2508 return 0;
2509 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2510 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2511 == !spec->vt1708_jack_detectect;
2512 if (spec->vt1708_jack_detectect) {
2513 mute_aa_path(codec, 1);
2514 notify_aa_path_ctls(codec);
2515 }
2516 return change;
2517 }
2518
2519 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2520 {
2521 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2522 .name = "Jack Detect",
2523 .count = 1,
2524 .info = snd_ctl_boolean_mono_info,
2525 .get = vt1708_jack_detectect_get,
2526 .put = vt1708_jack_detectect_put,
2527 },
2528 {} /* end */
2529 };
2530
2531 static int vt1708_parse_auto_config(struct hda_codec *codec)
2532 {
2533 struct via_spec *spec = codec->spec;
2534 int err;
2535
2536 /* Add HP and CD pin config connect bit re-config action */
2537 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2538 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2539
2540 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2541 if (err < 0)
2542 return err;
2543 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2544 if (err < 0)
2545 return err;
2546 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2547 return 0; /* can't find valid BIOS pin config */
2548
2549 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2550 if (err < 0)
2551 return err;
2552 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2553 if (err < 0)
2554 return err;
2555 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2556 if (err < 0)
2557 return err;
2558 /* add jack detect on/off control */
2559 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2560 if (err < 0)
2561 return err;
2562
2563 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2564
2565 if (spec->autocfg.dig_outs)
2566 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2567 spec->dig_in_pin = VT1708_DIGIN_PIN;
2568 if (spec->autocfg.dig_in_pin)
2569 spec->dig_in_nid = VT1708_DIGIN_NID;
2570
2571 if (spec->kctls.list)
2572 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2573
2574 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2575
2576 spec->input_mux = &spec->private_imux[0];
2577
2578 if (spec->hp_mux)
2579 via_hp_build(codec);
2580
2581 via_smart51_build(spec);
2582 return 1;
2583 }
2584
2585 /* init callback for auto-configuration model -- overriding the default init */
2586 static int via_auto_init(struct hda_codec *codec)
2587 {
2588 struct via_spec *spec = codec->spec;
2589
2590 via_init(codec);
2591 via_auto_init_multi_out(codec);
2592 via_auto_init_hp_out(codec);
2593 via_auto_init_analog_input(codec);
2594 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2595 via_hp_bind_automute(codec);
2596 } else {
2597 via_hp_automute(codec);
2598 via_speaker_automute(codec);
2599 }
2600
2601 return 0;
2602 }
2603
2604 static void vt1708_update_hp_jack_state(struct work_struct *work)
2605 {
2606 struct via_spec *spec = container_of(work, struct via_spec,
2607 vt1708_hp_work.work);
2608 if (spec->codec_type != VT1708)
2609 return;
2610 /* if jack state toggled */
2611 if (spec->vt1708_hp_present
2612 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2613 spec->vt1708_hp_present ^= 1;
2614 via_hp_automute(spec->codec);
2615 }
2616 vt1708_start_hp_work(spec);
2617 }
2618
2619 static int get_mux_nids(struct hda_codec *codec)
2620 {
2621 struct via_spec *spec = codec->spec;
2622 hda_nid_t nid, conn[8];
2623 unsigned int type;
2624 int i, n;
2625
2626 for (i = 0; i < spec->num_adc_nids; i++) {
2627 nid = spec->adc_nids[i];
2628 while (nid) {
2629 type = get_wcaps_type(get_wcaps(codec, nid));
2630 if (type == AC_WID_PIN)
2631 break;
2632 n = snd_hda_get_connections(codec, nid, conn,
2633 ARRAY_SIZE(conn));
2634 if (n <= 0)
2635 break;
2636 if (n > 1) {
2637 spec->mux_nids[i] = nid;
2638 break;
2639 }
2640 nid = conn[0];
2641 }
2642 }
2643 return 0;
2644 }
2645
2646 static int patch_vt1708(struct hda_codec *codec)
2647 {
2648 struct via_spec *spec;
2649 int err;
2650
2651 /* create a codec specific record */
2652 spec = via_new_spec(codec);
2653 if (spec == NULL)
2654 return -ENOMEM;
2655
2656 /* automatic parse from the BIOS config */
2657 err = vt1708_parse_auto_config(codec);
2658 if (err < 0) {
2659 via_free(codec);
2660 return err;
2661 } else if (!err) {
2662 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2663 "from BIOS. Using genenic mode...\n");
2664 }
2665
2666
2667 spec->stream_name_analog = "VT1708 Analog";
2668 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2669 /* disable 32bit format on VT1708 */
2670 if (codec->vendor_id == 0x11061708)
2671 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2672 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2673
2674 spec->stream_name_digital = "VT1708 Digital";
2675 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2676 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2677
2678
2679 if (!spec->adc_nids && spec->input_mux) {
2680 spec->adc_nids = vt1708_adc_nids;
2681 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2682 get_mux_nids(codec);
2683 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2684 spec->num_mixers++;
2685 }
2686
2687 codec->patch_ops = via_patch_ops;
2688
2689 codec->patch_ops.init = via_auto_init;
2690 #ifdef CONFIG_SND_HDA_POWER_SAVE
2691 spec->loopback.amplist = vt1708_loopbacks;
2692 #endif
2693 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2694 return 0;
2695 }
2696
2697 /* capture mixer elements */
2698 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2699 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2700 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2701 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2702 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2703 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2704 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2705 {
2706 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2707 /* The multiple "Capture Source" controls confuse alsamixer
2708 * So call somewhat different..
2709 */
2710 /* .name = "Capture Source", */
2711 .name = "Input Source",
2712 .count = 1,
2713 .info = via_mux_enum_info,
2714 .get = via_mux_enum_get,
2715 .put = via_mux_enum_put,
2716 },
2717 { } /* end */
2718 };
2719
2720 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2721 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2722 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2723 { }
2724 };
2725
2726 /*
2727 * generic initialization of ADC, input mixers and output mixers
2728 */
2729 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2730 /*
2731 * Unmute ADC0-2 and set the default input to mic-in
2732 */
2733 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2734 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2735 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2736
2737
2738 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2739 * mixer widget
2740 */
2741 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2742 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2743 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2744 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2745 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2746 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2747
2748 /*
2749 * Set up output selector (0x1a, 0x1b, 0x29)
2750 */
2751 /* set vol=0 to output mixers */
2752 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2753 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2754 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2755
2756 /*
2757 * Unmute PW3 and PW4
2758 */
2759 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2760 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2761
2762 /* Set input of PW4 as MW0 */
2763 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2764 /* PW9 Output enable */
2765 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2766 { }
2767 };
2768
2769 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2770 .substreams = 1,
2771 .channels_min = 2,
2772 .channels_max = 10,
2773 .nid = 0x10, /* NID to query formats and rates */
2774 .ops = {
2775 .open = via_playback_pcm_open,
2776 .prepare = via_playback_multi_pcm_prepare,
2777 .cleanup = via_playback_multi_pcm_cleanup,
2778 },
2779 };
2780
2781 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2782 .substreams = 1,
2783 .channels_min = 2,
2784 .channels_max = 6,
2785 .nid = 0x10, /* NID to query formats and rates */
2786 .ops = {
2787 .open = via_playback_pcm_open,
2788 .prepare = via_playback_multi_pcm_prepare,
2789 .cleanup = via_playback_multi_pcm_cleanup,
2790 },
2791 };
2792
2793 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2794 .substreams = 2,
2795 .channels_min = 2,
2796 .channels_max = 2,
2797 .nid = 0x14, /* NID to query formats and rates */
2798 .ops = {
2799 .prepare = via_capture_pcm_prepare,
2800 .cleanup = via_capture_pcm_cleanup
2801 },
2802 };
2803
2804 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2805 .substreams = 1,
2806 .channels_min = 2,
2807 .channels_max = 2,
2808 /* NID is set in via_build_pcms */
2809 .ops = {
2810 .open = via_dig_playback_pcm_open,
2811 .close = via_dig_playback_pcm_close
2812 },
2813 };
2814
2815 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2816 .substreams = 1,
2817 .channels_min = 2,
2818 .channels_max = 2,
2819 };
2820
2821 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2822 const struct auto_pin_cfg *cfg)
2823 {
2824 int i;
2825 hda_nid_t nid;
2826
2827 if (cfg->line_outs == 4) /* 10 channels */
2828 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2829 else if (cfg->line_outs == 3) /* 6 channels */
2830 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2831
2832 spec->multiout.dac_nids = spec->private_dac_nids;
2833
2834 if (cfg->line_outs == 4) { /* 10 channels */
2835 for (i = 0; i < cfg->line_outs; i++) {
2836 nid = cfg->line_out_pins[i];
2837 if (nid) {
2838 /* config dac list */
2839 switch (i) {
2840 case AUTO_SEQ_FRONT:
2841 /* AOW0 */
2842 spec->multiout.dac_nids[i] = 0x10;
2843 break;
2844 case AUTO_SEQ_CENLFE:
2845 /* AOW2 */
2846 spec->multiout.dac_nids[i] = 0x12;
2847 break;
2848 case AUTO_SEQ_SURROUND:
2849 /* AOW3 */
2850 spec->multiout.dac_nids[i] = 0x11;
2851 break;
2852 case AUTO_SEQ_SIDE:
2853 /* AOW1 */
2854 spec->multiout.dac_nids[i] = 0x27;
2855 break;
2856 default:
2857 break;
2858 }
2859 }
2860 }
2861 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2862
2863 } else if (cfg->line_outs == 3) { /* 6 channels */
2864 for (i = 0; i < cfg->line_outs; i++) {
2865 nid = cfg->line_out_pins[i];
2866 if (nid) {
2867 /* config dac list */
2868 switch (i) {
2869 case AUTO_SEQ_FRONT:
2870 /* AOW0 */
2871 spec->multiout.dac_nids[i] = 0x10;
2872 break;
2873 case AUTO_SEQ_CENLFE:
2874 /* AOW2 */
2875 spec->multiout.dac_nids[i] = 0x12;
2876 break;
2877 case AUTO_SEQ_SURROUND:
2878 /* AOW1 */
2879 spec->multiout.dac_nids[i] = 0x11;
2880 break;
2881 default:
2882 break;
2883 }
2884 }
2885 }
2886 }
2887
2888 return 0;
2889 }
2890
2891 /* add playback controls from the parsed DAC table */
2892 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2893 const struct auto_pin_cfg *cfg)
2894 {
2895 char name[32];
2896 static const char * const chname[4] = {
2897 "Front", "Surround", "C/LFE", "Side"
2898 };
2899 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2900 int i, err;
2901
2902 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2903 nid = cfg->line_out_pins[i];
2904
2905 if (!nid)
2906 continue;
2907
2908 nid_vol = nid_vols[i];
2909
2910 if (i == AUTO_SEQ_CENLFE) {
2911 /* Center/LFE */
2912 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2913 "Center Playback Volume",
2914 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2915 HDA_OUTPUT));
2916 if (err < 0)
2917 return err;
2918 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2919 "LFE Playback Volume",
2920 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2921 HDA_OUTPUT));
2922 if (err < 0)
2923 return err;
2924 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2925 "Center Playback Switch",
2926 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2927 HDA_OUTPUT));
2928 if (err < 0)
2929 return err;
2930 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2931 "LFE Playback Switch",
2932 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2933 HDA_OUTPUT));
2934 if (err < 0)
2935 return err;
2936 } else if (i == AUTO_SEQ_FRONT) {
2937 /* ADD control to mixer index 0 */
2938 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2939 "Master Front Playback Volume",
2940 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2941 HDA_INPUT));
2942 if (err < 0)
2943 return err;
2944 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2945 "Master Front Playback Switch",
2946 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2947 HDA_INPUT));
2948 if (err < 0)
2949 return err;
2950
2951 /* add control to PW3 */
2952 sprintf(name, "%s Playback Volume", chname[i]);
2953 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2954 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2955 HDA_OUTPUT));
2956 if (err < 0)
2957 return err;
2958 sprintf(name, "%s Playback Switch", chname[i]);
2959 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2960 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2961 HDA_OUTPUT));
2962 if (err < 0)
2963 return err;
2964 } else if (i == AUTO_SEQ_SURROUND) {
2965 sprintf(name, "%s Playback Volume", chname[i]);
2966 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2967 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2968 HDA_OUTPUT));
2969 if (err < 0)
2970 return err;
2971 sprintf(name, "%s Playback Switch", chname[i]);
2972 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2973 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2974 HDA_OUTPUT));
2975 if (err < 0)
2976 return err;
2977 } else if (i == AUTO_SEQ_SIDE) {
2978 sprintf(name, "%s Playback Volume", chname[i]);
2979 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2980 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2981 HDA_OUTPUT));
2982 if (err < 0)
2983 return err;
2984 sprintf(name, "%s Playback Switch", chname[i]);
2985 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2986 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2987 HDA_OUTPUT));
2988 if (err < 0)
2989 return err;
2990 }
2991 }
2992
2993 return 0;
2994 }
2995
2996 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2997 {
2998 int err;
2999
3000 if (!pin)
3001 return 0;
3002
3003 if (spec->multiout.num_dacs == 5) /* 10 channels */
3004 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
3005 else if (spec->multiout.num_dacs == 3) /* 6 channels */
3006 spec->multiout.hp_nid = 0;
3007 spec->hp_independent_mode_index = 1;
3008
3009 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3010 "Headphone Playback Volume",
3011 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3012 if (err < 0)
3013 return err;
3014 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3015 "Headphone Playback Switch",
3016 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3017 if (err < 0)
3018 return err;
3019
3020 return 0;
3021 }
3022
3023 /* create playback/capture controls for input pins */
3024 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
3025 const struct auto_pin_cfg *cfg)
3026 {
3027 static hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
3028 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
3029 ARRAY_SIZE(pin_idxs));
3030 }
3031
3032 static int vt1709_parse_auto_config(struct hda_codec *codec)
3033 {
3034 struct via_spec *spec = codec->spec;
3035 int err;
3036
3037 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3038 if (err < 0)
3039 return err;
3040 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
3041 if (err < 0)
3042 return err;
3043 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3044 return 0; /* can't find valid BIOS pin config */
3045
3046 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
3047 if (err < 0)
3048 return err;
3049 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3050 if (err < 0)
3051 return err;
3052 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
3053 if (err < 0)
3054 return err;
3055
3056 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3057
3058 if (spec->autocfg.dig_outs)
3059 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3060 spec->dig_in_pin = VT1709_DIGIN_PIN;
3061 if (spec->autocfg.dig_in_pin)
3062 spec->dig_in_nid = VT1709_DIGIN_NID;
3063
3064 if (spec->kctls.list)
3065 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3066
3067 spec->input_mux = &spec->private_imux[0];
3068
3069 if (spec->hp_mux)
3070 via_hp_build(codec);
3071
3072 via_smart51_build(spec);
3073 return 1;
3074 }
3075
3076 #ifdef CONFIG_SND_HDA_POWER_SAVE
3077 static struct hda_amp_list vt1709_loopbacks[] = {
3078 { 0x18, HDA_INPUT, 1 },
3079 { 0x18, HDA_INPUT, 2 },
3080 { 0x18, HDA_INPUT, 3 },
3081 { 0x18, HDA_INPUT, 4 },
3082 { } /* end */
3083 };
3084 #endif
3085
3086 static int patch_vt1709_10ch(struct hda_codec *codec)
3087 {
3088 struct via_spec *spec;
3089 int err;
3090
3091 /* create a codec specific record */
3092 spec = via_new_spec(codec);
3093 if (spec == NULL)
3094 return -ENOMEM;
3095
3096 err = vt1709_parse_auto_config(codec);
3097 if (err < 0) {
3098 via_free(codec);
3099 return err;
3100 } else if (!err) {
3101 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3102 "Using genenic mode...\n");
3103 }
3104
3105 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3106 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3107
3108 spec->stream_name_analog = "VT1709 Analog";
3109 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3110 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3111
3112 spec->stream_name_digital = "VT1709 Digital";
3113 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3114 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3115
3116
3117 if (!spec->adc_nids && spec->input_mux) {
3118 spec->adc_nids = vt1709_adc_nids;
3119 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3120 get_mux_nids(codec);
3121 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3122 spec->num_mixers++;
3123 }
3124
3125 codec->patch_ops = via_patch_ops;
3126
3127 codec->patch_ops.init = via_auto_init;
3128 codec->patch_ops.unsol_event = via_unsol_event;
3129 #ifdef CONFIG_SND_HDA_POWER_SAVE
3130 spec->loopback.amplist = vt1709_loopbacks;
3131 #endif
3132
3133 return 0;
3134 }
3135 /*
3136 * generic initialization of ADC, input mixers and output mixers
3137 */
3138 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3139 /*
3140 * Unmute ADC0-2 and set the default input to mic-in
3141 */
3142 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3143 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3144 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3145
3146
3147 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3148 * mixer widget
3149 */
3150 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3151 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3152 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3153 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3154 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3155 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3156
3157 /*
3158 * Set up output selector (0x1a, 0x1b, 0x29)
3159 */
3160 /* set vol=0 to output mixers */
3161 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3162 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3163 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3164
3165 /*
3166 * Unmute PW3 and PW4
3167 */
3168 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3169 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3170
3171 /* Set input of PW4 as MW0 */
3172 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3173 /* PW9 Output enable */
3174 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3175 { }
3176 };
3177
3178 static int patch_vt1709_6ch(struct hda_codec *codec)
3179 {
3180 struct via_spec *spec;
3181 int err;
3182
3183 /* create a codec specific record */
3184 spec = via_new_spec(codec);
3185 if (spec == NULL)
3186 return -ENOMEM;
3187
3188 err = vt1709_parse_auto_config(codec);
3189 if (err < 0) {
3190 via_free(codec);
3191 return err;
3192 } else if (!err) {
3193 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3194 "Using genenic mode...\n");
3195 }
3196
3197 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3198 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3199
3200 spec->stream_name_analog = "VT1709 Analog";
3201 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3202 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3203
3204 spec->stream_name_digital = "VT1709 Digital";
3205 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3206 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3207
3208
3209 if (!spec->adc_nids && spec->input_mux) {
3210 spec->adc_nids = vt1709_adc_nids;
3211 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3212 get_mux_nids(codec);
3213 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3214 spec->num_mixers++;
3215 }
3216
3217 codec->patch_ops = via_patch_ops;
3218
3219 codec->patch_ops.init = via_auto_init;
3220 codec->patch_ops.unsol_event = via_unsol_event;
3221 #ifdef CONFIG_SND_HDA_POWER_SAVE
3222 spec->loopback.amplist = vt1709_loopbacks;
3223 #endif
3224 return 0;
3225 }
3226
3227 /* capture mixer elements */
3228 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3229 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3230 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3231 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3232 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3233 {
3234 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3235 /* The multiple "Capture Source" controls confuse alsamixer
3236 * So call somewhat different..
3237 */
3238 /* .name = "Capture Source", */
3239 .name = "Input Source",
3240 .count = 1,
3241 .info = via_mux_enum_info,
3242 .get = via_mux_enum_get,
3243 .put = via_mux_enum_put,
3244 },
3245 { } /* end */
3246 };
3247 /*
3248 * generic initialization of ADC, input mixers and output mixers
3249 */
3250 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3251 /*
3252 * Unmute ADC0-1 and set the default input to mic-in
3253 */
3254 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3255 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3256
3257
3258 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3259 * mixer widget
3260 */
3261 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3262 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3263 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3264 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3265 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3266 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3267
3268 /*
3269 * Set up output mixers
3270 */
3271 /* set vol=0 to output mixers */
3272 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3273 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3274 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3275
3276 /* Setup default input to PW4 */
3277 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3278 /* PW9 Output enable */
3279 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3280 /* PW10 Input enable */
3281 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3282 { }
3283 };
3284
3285 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3286 /*
3287 * Unmute ADC0-1 and set the default input to mic-in
3288 */
3289 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3290 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3291
3292
3293 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3294 * mixer widget
3295 */
3296 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3297 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3298 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3299 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3300 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3301 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3302
3303 /*
3304 * Set up output mixers
3305 */
3306 /* set vol=0 to output mixers */
3307 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3308 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3309 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3310
3311 /* Setup default input of PW4 to MW0 */
3312 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3313 /* PW9 Output enable */
3314 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3315 /* PW10 Input enable */
3316 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3317 { }
3318 };
3319
3320 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3321 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3322 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3323 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3324 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3325 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3326 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3327 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3328 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3329 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3330 { }
3331 };
3332
3333 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3334 struct hda_codec *codec,
3335 struct snd_pcm_substream *substream)
3336 {
3337 int idle = substream->pstr->substream_opened == 1
3338 && substream->ref_count == 0;
3339
3340 analog_low_current_mode(codec, idle);
3341 return 0;
3342 }
3343
3344 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3345 .substreams = 2,
3346 .channels_min = 2,
3347 .channels_max = 8,
3348 .nid = 0x10, /* NID to query formats and rates */
3349 .ops = {
3350 .open = via_playback_pcm_open,
3351 .prepare = via_playback_multi_pcm_prepare,
3352 .cleanup = via_playback_multi_pcm_cleanup,
3353 .close = via_pcm_open_close
3354 },
3355 };
3356
3357 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3358 .substreams = 2,
3359 .channels_min = 2,
3360 .channels_max = 4,
3361 .nid = 0x10, /* NID to query formats and rates */
3362 .ops = {
3363 .open = via_playback_pcm_open,
3364 .prepare = via_playback_multi_pcm_prepare,
3365 .cleanup = via_playback_multi_pcm_cleanup
3366 },
3367 };
3368
3369 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3370 .substreams = 2,
3371 .channels_min = 2,
3372 .channels_max = 2,
3373 .nid = 0x13, /* NID to query formats and rates */
3374 .ops = {
3375 .open = via_pcm_open_close,
3376 .prepare = via_capture_pcm_prepare,
3377 .cleanup = via_capture_pcm_cleanup,
3378 .close = via_pcm_open_close
3379 },
3380 };
3381
3382 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3383 .substreams = 1,
3384 .channels_min = 2,
3385 .channels_max = 2,
3386 /* NID is set in via_build_pcms */
3387 .ops = {
3388 .open = via_dig_playback_pcm_open,
3389 .close = via_dig_playback_pcm_close,
3390 .prepare = via_dig_playback_pcm_prepare,
3391 .cleanup = via_dig_playback_pcm_cleanup
3392 },
3393 };
3394
3395 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3396 .substreams = 1,
3397 .channels_min = 2,
3398 .channels_max = 2,
3399 };
3400
3401 /* fill in the dac_nids table from the parsed pin configuration */
3402 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3403 const struct auto_pin_cfg *cfg)
3404 {
3405 int i;
3406 hda_nid_t nid;
3407
3408 spec->multiout.num_dacs = cfg->line_outs;
3409
3410 spec->multiout.dac_nids = spec->private_dac_nids;
3411
3412 for (i = 0; i < 4; i++) {
3413 nid = cfg->line_out_pins[i];
3414 if (nid) {
3415 /* config dac list */
3416 switch (i) {
3417 case AUTO_SEQ_FRONT:
3418 spec->multiout.dac_nids[i] = 0x10;
3419 break;
3420 case AUTO_SEQ_CENLFE:
3421 spec->multiout.dac_nids[i] = 0x24;
3422 break;
3423 case AUTO_SEQ_SURROUND:
3424 spec->multiout.dac_nids[i] = 0x11;
3425 break;
3426 case AUTO_SEQ_SIDE:
3427 spec->multiout.dac_nids[i] = 0x25;
3428 break;
3429 }
3430 }
3431 }
3432
3433 return 0;
3434 }
3435
3436 /* add playback controls from the parsed DAC table */
3437 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3438 const struct auto_pin_cfg *cfg)
3439 {
3440 char name[32];
3441 static const char * const chname[4] = {
3442 "Front", "Surround", "C/LFE", "Side"
3443 };
3444 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3445 hda_nid_t nid, nid_vol = 0;
3446 int i, err;
3447
3448 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3449 nid = cfg->line_out_pins[i];
3450
3451 if (!nid)
3452 continue;
3453
3454 nid_vol = nid_vols[i];
3455
3456 if (i == AUTO_SEQ_CENLFE) {
3457 /* Center/LFE */
3458 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3459 "Center Playback Volume",
3460 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3461 HDA_OUTPUT));
3462 if (err < 0)
3463 return err;
3464 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3465 "LFE Playback Volume",
3466 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3467 HDA_OUTPUT));
3468 if (err < 0)
3469 return err;
3470 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3471 "Center Playback Switch",
3472 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3473 HDA_OUTPUT));
3474 if (err < 0)
3475 return err;
3476 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3477 "LFE Playback Switch",
3478 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3479 HDA_OUTPUT));
3480 if (err < 0)
3481 return err;
3482 } else if (i == AUTO_SEQ_FRONT) {
3483 /* add control to mixer index 0 */
3484 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3485 "Master Front Playback Volume",
3486 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3487 HDA_INPUT));
3488 if (err < 0)
3489 return err;
3490 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3491 "Master Front Playback Switch",
3492 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3493 HDA_INPUT));
3494 if (err < 0)
3495 return err;
3496
3497 /* add control to PW3 */
3498 sprintf(name, "%s Playback Volume", chname[i]);
3499 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3500 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3501 HDA_OUTPUT));
3502 if (err < 0)
3503 return err;
3504 sprintf(name, "%s Playback Switch", chname[i]);
3505 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3506 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3507 HDA_OUTPUT));
3508 if (err < 0)
3509 return err;
3510 } else {
3511 sprintf(name, "%s Playback Volume", chname[i]);
3512 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3513 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3514 HDA_OUTPUT));
3515 if (err < 0)
3516 return err;
3517 sprintf(name, "%s Playback Switch", chname[i]);
3518 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3519 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3520 HDA_OUTPUT));
3521 if (err < 0)
3522 return err;
3523 }
3524 }
3525
3526 return 0;
3527 }
3528
3529 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3530 {
3531 int err;
3532
3533 if (!pin)
3534 return 0;
3535
3536 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3537 spec->hp_independent_mode_index = 1;
3538
3539 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3540 "Headphone Playback Volume",
3541 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3542 if (err < 0)
3543 return err;
3544 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3545 "Headphone Playback Switch",
3546 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3547 if (err < 0)
3548 return err;
3549
3550 create_hp_imux(spec);
3551
3552 return 0;
3553 }
3554
3555 /* create playback/capture controls for input pins */
3556 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3557 const struct auto_pin_cfg *cfg)
3558 {
3559 static hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3560 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3561 ARRAY_SIZE(pin_idxs));
3562 }
3563
3564 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3565 {
3566 struct via_spec *spec = codec->spec;
3567 int err;
3568
3569 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3570 if (err < 0)
3571 return err;
3572 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3573 if (err < 0)
3574 return err;
3575 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3576 return 0; /* can't find valid BIOS pin config */
3577
3578 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3579 if (err < 0)
3580 return err;
3581 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3582 if (err < 0)
3583 return err;
3584 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3585 if (err < 0)
3586 return err;
3587
3588 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3589
3590 if (spec->autocfg.dig_outs)
3591 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3592 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3593 if (spec->autocfg.dig_in_pin)
3594 spec->dig_in_nid = VT1708B_DIGIN_NID;
3595
3596 if (spec->kctls.list)
3597 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3598
3599 spec->input_mux = &spec->private_imux[0];
3600
3601 if (spec->hp_mux)
3602 via_hp_build(codec);
3603
3604 via_smart51_build(spec);
3605 return 1;
3606 }
3607
3608 #ifdef CONFIG_SND_HDA_POWER_SAVE
3609 static struct hda_amp_list vt1708B_loopbacks[] = {
3610 { 0x16, HDA_INPUT, 1 },
3611 { 0x16, HDA_INPUT, 2 },
3612 { 0x16, HDA_INPUT, 3 },
3613 { 0x16, HDA_INPUT, 4 },
3614 { } /* end */
3615 };
3616 #endif
3617 static int patch_vt1708S(struct hda_codec *codec);
3618 static int patch_vt1708B_8ch(struct hda_codec *codec)
3619 {
3620 struct via_spec *spec;
3621 int err;
3622
3623 if (get_codec_type(codec) == VT1708BCE)
3624 return patch_vt1708S(codec);
3625 /* create a codec specific record */
3626 spec = via_new_spec(codec);
3627 if (spec == NULL)
3628 return -ENOMEM;
3629
3630 /* automatic parse from the BIOS config */
3631 err = vt1708B_parse_auto_config(codec);
3632 if (err < 0) {
3633 via_free(codec);
3634 return err;
3635 } else if (!err) {
3636 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3637 "from BIOS. Using genenic mode...\n");
3638 }
3639
3640 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3641 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3642
3643 spec->stream_name_analog = "VT1708B Analog";
3644 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3645 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3646
3647 spec->stream_name_digital = "VT1708B Digital";
3648 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3649 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3650
3651 if (!spec->adc_nids && spec->input_mux) {
3652 spec->adc_nids = vt1708B_adc_nids;
3653 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3654 get_mux_nids(codec);
3655 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3656 spec->num_mixers++;
3657 }
3658
3659 codec->patch_ops = via_patch_ops;
3660
3661 codec->patch_ops.init = via_auto_init;
3662 codec->patch_ops.unsol_event = via_unsol_event;
3663 #ifdef CONFIG_SND_HDA_POWER_SAVE
3664 spec->loopback.amplist = vt1708B_loopbacks;
3665 #endif
3666
3667 return 0;
3668 }
3669
3670 static int patch_vt1708B_4ch(struct hda_codec *codec)
3671 {
3672 struct via_spec *spec;
3673 int err;
3674
3675 /* create a codec specific record */
3676 spec = via_new_spec(codec);
3677 if (spec == NULL)
3678 return -ENOMEM;
3679
3680 /* automatic parse from the BIOS config */
3681 err = vt1708B_parse_auto_config(codec);
3682 if (err < 0) {
3683 via_free(codec);
3684 return err;
3685 } else if (!err) {
3686 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3687 "from BIOS. Using genenic mode...\n");
3688 }
3689
3690 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3691 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3692
3693 spec->stream_name_analog = "VT1708B Analog";
3694 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3695 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3696
3697 spec->stream_name_digital = "VT1708B Digital";
3698 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3699 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3700
3701 if (!spec->adc_nids && spec->input_mux) {
3702 spec->adc_nids = vt1708B_adc_nids;
3703 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3704 get_mux_nids(codec);
3705 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3706 spec->num_mixers++;
3707 }
3708
3709 codec->patch_ops = via_patch_ops;
3710
3711 codec->patch_ops.init = via_auto_init;
3712 codec->patch_ops.unsol_event = via_unsol_event;
3713 #ifdef CONFIG_SND_HDA_POWER_SAVE
3714 spec->loopback.amplist = vt1708B_loopbacks;
3715 #endif
3716
3717 return 0;
3718 }
3719
3720 /* Patch for VT1708S */
3721
3722 /* capture mixer elements */
3723 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3724 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3725 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3726 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3727 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3728 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3729 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3730 HDA_INPUT),
3731 {
3732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3733 /* The multiple "Capture Source" controls confuse alsamixer
3734 * So call somewhat different..
3735 */
3736 /* .name = "Capture Source", */
3737 .name = "Input Source",
3738 .count = 1,
3739 .info = via_mux_enum_info,
3740 .get = via_mux_enum_get,
3741 .put = via_mux_enum_put,
3742 },
3743 { } /* end */
3744 };
3745
3746 static struct hda_verb vt1708S_volume_init_verbs[] = {
3747 /* Unmute ADC0-1 and set the default input to mic-in */
3748 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3749 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3750
3751 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3752 * analog-loopback mixer widget */
3753 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3754 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3755 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3756 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3757 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3758 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3759
3760 /* Setup default input of PW4 to MW0 */
3761 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3762 /* PW9, PW10 Output enable */
3763 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3764 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3765 /* Enable Mic Boost Volume backdoor */
3766 {0x1, 0xf98, 0x1},
3767 /* don't bybass mixer */
3768 {0x1, 0xf88, 0xc0},
3769 { }
3770 };
3771
3772 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3773 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3774 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3775 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3776 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3777 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3778 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3779 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3780 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3781 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3782 { }
3783 };
3784
3785 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3786 .substreams = 2,
3787 .channels_min = 2,
3788 .channels_max = 8,
3789 .nid = 0x10, /* NID to query formats and rates */
3790 .ops = {
3791 .open = via_playback_pcm_open,
3792 .prepare = via_playback_multi_pcm_prepare,
3793 .cleanup = via_playback_multi_pcm_cleanup,
3794 .close = via_pcm_open_close
3795 },
3796 };
3797
3798 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3799 .substreams = 2,
3800 .channels_min = 2,
3801 .channels_max = 2,
3802 .nid = 0x13, /* NID to query formats and rates */
3803 .ops = {
3804 .open = via_pcm_open_close,
3805 .prepare = via_capture_pcm_prepare,
3806 .cleanup = via_capture_pcm_cleanup,
3807 .close = via_pcm_open_close
3808 },
3809 };
3810
3811 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3812 .substreams = 1,
3813 .channels_min = 2,
3814 .channels_max = 2,
3815 /* NID is set in via_build_pcms */
3816 .ops = {
3817 .open = via_dig_playback_pcm_open,
3818 .close = via_dig_playback_pcm_close,
3819 .prepare = via_dig_playback_pcm_prepare,
3820 .cleanup = via_dig_playback_pcm_cleanup
3821 },
3822 };
3823
3824 /* fill in the dac_nids table from the parsed pin configuration */
3825 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3826 const struct auto_pin_cfg *cfg)
3827 {
3828 int i;
3829 hda_nid_t nid;
3830
3831 spec->multiout.num_dacs = cfg->line_outs;
3832
3833 spec->multiout.dac_nids = spec->private_dac_nids;
3834
3835 for (i = 0; i < 4; i++) {
3836 nid = cfg->line_out_pins[i];
3837 if (nid) {
3838 /* config dac list */
3839 switch (i) {
3840 case AUTO_SEQ_FRONT:
3841 spec->multiout.dac_nids[i] = 0x10;
3842 break;
3843 case AUTO_SEQ_CENLFE:
3844 spec->multiout.dac_nids[i] = 0x24;
3845 break;
3846 case AUTO_SEQ_SURROUND:
3847 spec->multiout.dac_nids[i] = 0x11;
3848 break;
3849 case AUTO_SEQ_SIDE:
3850 spec->multiout.dac_nids[i] = 0x25;
3851 break;
3852 }
3853 }
3854 }
3855
3856 /* for Smart 5.1, line/mic inputs double as output pins */
3857 if (cfg->line_outs == 1) {
3858 spec->multiout.num_dacs = 3;
3859 spec->multiout.dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3860 spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3861 }
3862
3863 return 0;
3864 }
3865
3866 /* add playback controls from the parsed DAC table */
3867 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3868 const struct auto_pin_cfg *cfg)
3869 {
3870 char name[32];
3871 static const char * const chname[4] = {
3872 "Front", "Surround", "C/LFE", "Side"
3873 };
3874 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3875 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3876 hda_nid_t nid, nid_vol, nid_mute;
3877 int i, err;
3878
3879 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3880 nid = cfg->line_out_pins[i];
3881
3882 /* for Smart 5.1, there are always at least six channels */
3883 if (!nid && i > AUTO_SEQ_CENLFE)
3884 continue;
3885
3886 nid_vol = nid_vols[i];
3887 nid_mute = nid_mutes[i];
3888
3889 if (i == AUTO_SEQ_CENLFE) {
3890 /* Center/LFE */
3891 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3892 "Center Playback Volume",
3893 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3894 HDA_OUTPUT));
3895 if (err < 0)
3896 return err;
3897 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3898 "LFE Playback Volume",
3899 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3900 HDA_OUTPUT));
3901 if (err < 0)
3902 return err;
3903 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3904 "Center Playback Switch",
3905 HDA_COMPOSE_AMP_VAL(nid_mute,
3906 1, 0,
3907 HDA_OUTPUT));
3908 if (err < 0)
3909 return err;
3910 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3911 "LFE Playback Switch",
3912 HDA_COMPOSE_AMP_VAL(nid_mute,
3913 2, 0,
3914 HDA_OUTPUT));
3915 if (err < 0)
3916 return err;
3917 } else if (i == AUTO_SEQ_FRONT) {
3918 /* add control to mixer index 0 */
3919 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3920 "Master Front Playback Volume",
3921 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3922 HDA_INPUT));
3923 if (err < 0)
3924 return err;
3925 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3926 "Master Front Playback Switch",
3927 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3928 HDA_INPUT));
3929 if (err < 0)
3930 return err;
3931
3932 /* Front */
3933 sprintf(name, "%s Playback Volume", chname[i]);
3934 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3935 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3936 HDA_OUTPUT));
3937 if (err < 0)
3938 return err;
3939 sprintf(name, "%s Playback Switch", chname[i]);
3940 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3941 HDA_COMPOSE_AMP_VAL(nid_mute,
3942 3, 0,
3943 HDA_OUTPUT));
3944 if (err < 0)
3945 return err;
3946 } else {
3947 sprintf(name, "%s Playback Volume", chname[i]);
3948 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3949 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3950 HDA_OUTPUT));
3951 if (err < 0)
3952 return err;
3953 sprintf(name, "%s Playback Switch", chname[i]);
3954 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3955 HDA_COMPOSE_AMP_VAL(nid_mute,
3956 3, 0,
3957 HDA_OUTPUT));
3958 if (err < 0)
3959 return err;
3960 }
3961 }
3962
3963 return 0;
3964 }
3965
3966 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3967 {
3968 int err;
3969
3970 if (!pin)
3971 return 0;
3972
3973 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3974 spec->hp_independent_mode_index = 1;
3975
3976 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3977 "Headphone Playback Volume",
3978 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3979 if (err < 0)
3980 return err;
3981
3982 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3983 "Headphone Playback Switch",
3984 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3985 if (err < 0)
3986 return err;
3987
3988 create_hp_imux(spec);
3989
3990 return 0;
3991 }
3992
3993 /* create playback/capture controls for input pins */
3994 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
3995 const struct auto_pin_cfg *cfg)
3996 {
3997 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
3998 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3999 ARRAY_SIZE(pin_idxs));
4000 }
4001
4002 /* fill out digital output widgets; one for master and one for slave outputs */
4003 static void fill_dig_outs(struct hda_codec *codec)
4004 {
4005 struct via_spec *spec = codec->spec;
4006 int i;
4007
4008 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4009 hda_nid_t nid;
4010 int conn;
4011
4012 nid = spec->autocfg.dig_out_pins[i];
4013 if (!nid)
4014 continue;
4015 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4016 if (conn < 1)
4017 continue;
4018 if (!spec->multiout.dig_out_nid)
4019 spec->multiout.dig_out_nid = nid;
4020 else {
4021 spec->slave_dig_outs[0] = nid;
4022 break; /* at most two dig outs */
4023 }
4024 }
4025 }
4026
4027 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4028 {
4029 struct via_spec *spec = codec->spec;
4030 int err;
4031
4032 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4033 if (err < 0)
4034 return err;
4035 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4036 if (err < 0)
4037 return err;
4038 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4039 return 0; /* can't find valid BIOS pin config */
4040
4041 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4042 if (err < 0)
4043 return err;
4044 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4045 if (err < 0)
4046 return err;
4047 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4048 if (err < 0)
4049 return err;
4050
4051 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4052
4053 fill_dig_outs(codec);
4054
4055 if (spec->kctls.list)
4056 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4057
4058 spec->input_mux = &spec->private_imux[0];
4059
4060 if (spec->hp_mux)
4061 via_hp_build(codec);
4062
4063 via_smart51_build(spec);
4064 return 1;
4065 }
4066
4067 #ifdef CONFIG_SND_HDA_POWER_SAVE
4068 static struct hda_amp_list vt1708S_loopbacks[] = {
4069 { 0x16, HDA_INPUT, 1 },
4070 { 0x16, HDA_INPUT, 2 },
4071 { 0x16, HDA_INPUT, 3 },
4072 { 0x16, HDA_INPUT, 4 },
4073 { } /* end */
4074 };
4075 #endif
4076
4077 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4078 int offset, int num_steps, int step_size)
4079 {
4080 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4081 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4082 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4083 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4084 (0 << AC_AMPCAP_MUTE_SHIFT));
4085 }
4086
4087 static int patch_vt1708S(struct hda_codec *codec)
4088 {
4089 struct via_spec *spec;
4090 int err;
4091
4092 /* create a codec specific record */
4093 spec = via_new_spec(codec);
4094 if (spec == NULL)
4095 return -ENOMEM;
4096
4097 /* automatic parse from the BIOS config */
4098 err = vt1708S_parse_auto_config(codec);
4099 if (err < 0) {
4100 via_free(codec);
4101 return err;
4102 } else if (!err) {
4103 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4104 "from BIOS. Using genenic mode...\n");
4105 }
4106
4107 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4108 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4109
4110 if (codec->vendor_id == 0x11060440)
4111 spec->stream_name_analog = "VT1818S Analog";
4112 else
4113 spec->stream_name_analog = "VT1708S Analog";
4114 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4115 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4116
4117 if (codec->vendor_id == 0x11060440)
4118 spec->stream_name_digital = "VT1818S Digital";
4119 else
4120 spec->stream_name_digital = "VT1708S Digital";
4121 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4122
4123 if (!spec->adc_nids && spec->input_mux) {
4124 spec->adc_nids = vt1708S_adc_nids;
4125 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4126 get_mux_nids(codec);
4127 override_mic_boost(codec, 0x1a, 0, 3, 40);
4128 override_mic_boost(codec, 0x1e, 0, 3, 40);
4129 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4130 spec->num_mixers++;
4131 }
4132
4133 codec->patch_ops = via_patch_ops;
4134
4135 codec->patch_ops.init = via_auto_init;
4136 codec->patch_ops.unsol_event = via_unsol_event;
4137 #ifdef CONFIG_SND_HDA_POWER_SAVE
4138 spec->loopback.amplist = vt1708S_loopbacks;
4139 #endif
4140
4141 /* correct names for VT1708BCE */
4142 if (get_codec_type(codec) == VT1708BCE) {
4143 kfree(codec->chip_name);
4144 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4145 snprintf(codec->bus->card->mixername,
4146 sizeof(codec->bus->card->mixername),
4147 "%s %s", codec->vendor_name, codec->chip_name);
4148 spec->stream_name_analog = "VT1708BCE Analog";
4149 spec->stream_name_digital = "VT1708BCE Digital";
4150 }
4151 return 0;
4152 }
4153
4154 /* Patch for VT1702 */
4155
4156 /* capture mixer elements */
4157 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4158 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4159 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4160 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4161 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4162 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4163 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4164 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4165 HDA_INPUT),
4166 {
4167 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4168 /* The multiple "Capture Source" controls confuse alsamixer
4169 * So call somewhat different..
4170 */
4171 /* .name = "Capture Source", */
4172 .name = "Input Source",
4173 .count = 1,
4174 .info = via_mux_enum_info,
4175 .get = via_mux_enum_get,
4176 .put = via_mux_enum_put,
4177 },
4178 { } /* end */
4179 };
4180
4181 static struct hda_verb vt1702_volume_init_verbs[] = {
4182 /*
4183 * Unmute ADC0-1 and set the default input to mic-in
4184 */
4185 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4186 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4187 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4188
4189
4190 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4191 * mixer widget
4192 */
4193 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4194 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4195 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4196 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4197 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4198 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4199
4200 /* Setup default input of PW4 to MW0 */
4201 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4202 /* PW6 PW7 Output enable */
4203 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4204 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4205 /* mixer enable */
4206 {0x1, 0xF88, 0x3},
4207 /* GPIO 0~2 */
4208 {0x1, 0xF82, 0x3F},
4209 { }
4210 };
4211
4212 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4213 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4214 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4215 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4216 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4217 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4218 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4219 { }
4220 };
4221
4222 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4223 .substreams = 2,
4224 .channels_min = 2,
4225 .channels_max = 2,
4226 .nid = 0x10, /* NID to query formats and rates */
4227 .ops = {
4228 .open = via_playback_pcm_open,
4229 .prepare = via_playback_multi_pcm_prepare,
4230 .cleanup = via_playback_multi_pcm_cleanup,
4231 .close = via_pcm_open_close
4232 },
4233 };
4234
4235 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4236 .substreams = 3,
4237 .channels_min = 2,
4238 .channels_max = 2,
4239 .nid = 0x12, /* NID to query formats and rates */
4240 .ops = {
4241 .open = via_pcm_open_close,
4242 .prepare = via_capture_pcm_prepare,
4243 .cleanup = via_capture_pcm_cleanup,
4244 .close = via_pcm_open_close
4245 },
4246 };
4247
4248 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4249 .substreams = 2,
4250 .channels_min = 2,
4251 .channels_max = 2,
4252 /* NID is set in via_build_pcms */
4253 .ops = {
4254 .open = via_dig_playback_pcm_open,
4255 .close = via_dig_playback_pcm_close,
4256 .prepare = via_dig_playback_pcm_prepare,
4257 .cleanup = via_dig_playback_pcm_cleanup
4258 },
4259 };
4260
4261 /* fill in the dac_nids table from the parsed pin configuration */
4262 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4263 const struct auto_pin_cfg *cfg)
4264 {
4265 spec->multiout.num_dacs = 1;
4266 spec->multiout.dac_nids = spec->private_dac_nids;
4267
4268 if (cfg->line_out_pins[0]) {
4269 /* config dac list */
4270 spec->multiout.dac_nids[0] = 0x10;
4271 }
4272
4273 return 0;
4274 }
4275
4276 /* add playback controls from the parsed DAC table */
4277 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4278 const struct auto_pin_cfg *cfg)
4279 {
4280 int err;
4281
4282 if (!cfg->line_out_pins[0])
4283 return -1;
4284
4285 /* add control to mixer index 0 */
4286 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4287 "Master Front Playback Volume",
4288 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4289 if (err < 0)
4290 return err;
4291 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4292 "Master Front Playback Switch",
4293 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4294 if (err < 0)
4295 return err;
4296
4297 /* Front */
4298 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4299 "Front Playback Volume",
4300 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4301 if (err < 0)
4302 return err;
4303 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4304 "Front Playback Switch",
4305 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4306 if (err < 0)
4307 return err;
4308
4309 return 0;
4310 }
4311
4312 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4313 {
4314 int err, i;
4315 struct hda_input_mux *imux;
4316 static const char * const texts[] = { "ON", "OFF", NULL};
4317 if (!pin)
4318 return 0;
4319 spec->multiout.hp_nid = 0x1D;
4320 spec->hp_independent_mode_index = 0;
4321
4322 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4323 "Headphone Playback Volume",
4324 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4325 if (err < 0)
4326 return err;
4327
4328 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4329 "Headphone Playback Switch",
4330 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4331 if (err < 0)
4332 return err;
4333
4334 imux = &spec->private_imux[1];
4335
4336 /* for hp mode select */
4337 for (i = 0; texts[i]; i++)
4338 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4339
4340 spec->hp_mux = &spec->private_imux[1];
4341 return 0;
4342 }
4343
4344 /* create playback/capture controls for input pins */
4345 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4346 const struct auto_pin_cfg *cfg)
4347 {
4348 static hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4349 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
4350 ARRAY_SIZE(pin_idxs));
4351 }
4352
4353 static int vt1702_parse_auto_config(struct hda_codec *codec)
4354 {
4355 struct via_spec *spec = codec->spec;
4356 int err;
4357
4358 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4359 if (err < 0)
4360 return err;
4361 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4362 if (err < 0)
4363 return err;
4364 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4365 return 0; /* can't find valid BIOS pin config */
4366
4367 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4368 if (err < 0)
4369 return err;
4370 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4371 if (err < 0)
4372 return err;
4373 /* limit AA path volume to 0 dB */
4374 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4375 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4376 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4377 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4378 (1 << AC_AMPCAP_MUTE_SHIFT));
4379 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4380 if (err < 0)
4381 return err;
4382
4383 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4384
4385 fill_dig_outs(codec);
4386
4387 if (spec->kctls.list)
4388 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4389
4390 spec->input_mux = &spec->private_imux[0];
4391
4392 if (spec->hp_mux)
4393 via_hp_build(codec);
4394
4395 return 1;
4396 }
4397
4398 #ifdef CONFIG_SND_HDA_POWER_SAVE
4399 static struct hda_amp_list vt1702_loopbacks[] = {
4400 { 0x1A, HDA_INPUT, 1 },
4401 { 0x1A, HDA_INPUT, 2 },
4402 { 0x1A, HDA_INPUT, 3 },
4403 { 0x1A, HDA_INPUT, 4 },
4404 { } /* end */
4405 };
4406 #endif
4407
4408 static int patch_vt1702(struct hda_codec *codec)
4409 {
4410 struct via_spec *spec;
4411 int err;
4412
4413 /* create a codec specific record */
4414 spec = via_new_spec(codec);
4415 if (spec == NULL)
4416 return -ENOMEM;
4417
4418 /* automatic parse from the BIOS config */
4419 err = vt1702_parse_auto_config(codec);
4420 if (err < 0) {
4421 via_free(codec);
4422 return err;
4423 } else if (!err) {
4424 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4425 "from BIOS. Using genenic mode...\n");
4426 }
4427
4428 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4429 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4430
4431 spec->stream_name_analog = "VT1702 Analog";
4432 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4433 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4434
4435 spec->stream_name_digital = "VT1702 Digital";
4436 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4437
4438 if (!spec->adc_nids && spec->input_mux) {
4439 spec->adc_nids = vt1702_adc_nids;
4440 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4441 get_mux_nids(codec);
4442 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4443 spec->num_mixers++;
4444 }
4445
4446 codec->patch_ops = via_patch_ops;
4447
4448 codec->patch_ops.init = via_auto_init;
4449 codec->patch_ops.unsol_event = via_unsol_event;
4450 #ifdef CONFIG_SND_HDA_POWER_SAVE
4451 spec->loopback.amplist = vt1702_loopbacks;
4452 #endif
4453
4454 return 0;
4455 }
4456
4457 /* Patch for VT1718S */
4458
4459 /* capture mixer elements */
4460 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4461 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4462 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4463 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4464 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4465 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4466 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4467 HDA_INPUT),
4468 {
4469 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4470 /* The multiple "Capture Source" controls confuse alsamixer
4471 * So call somewhat different..
4472 */
4473 .name = "Input Source",
4474 .count = 2,
4475 .info = via_mux_enum_info,
4476 .get = via_mux_enum_get,
4477 .put = via_mux_enum_put,
4478 },
4479 { } /* end */
4480 };
4481
4482 static struct hda_verb vt1718S_volume_init_verbs[] = {
4483 /*
4484 * Unmute ADC0-1 and set the default input to mic-in
4485 */
4486 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4487 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4488
4489
4490 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4491 * mixer widget
4492 */
4493 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4494 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4495 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4496 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4497 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4498 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4499
4500 /* Setup default input of Front HP to MW9 */
4501 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4502 /* PW9 PW10 Output enable */
4503 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4504 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4505 /* PW11 Input enable */
4506 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4507 /* Enable Boost Volume backdoor */
4508 {0x1, 0xf88, 0x8},
4509 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4510 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4511 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4512 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4513 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4514 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4515 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4516 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4517 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4518 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4519 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4520 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4521 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4522 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4523 /* Unmute MW4's index 0 */
4524 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4525 { }
4526 };
4527
4528
4529 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4530 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4531 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4532 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4533 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4534 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4535 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4536 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4537 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4538 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4539 { }
4540 };
4541
4542 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4543 .substreams = 2,
4544 .channels_min = 2,
4545 .channels_max = 10,
4546 .nid = 0x8, /* NID to query formats and rates */
4547 .ops = {
4548 .open = via_playback_pcm_open,
4549 .prepare = via_playback_multi_pcm_prepare,
4550 .cleanup = via_playback_multi_pcm_cleanup,
4551 .close = via_pcm_open_close,
4552 },
4553 };
4554
4555 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4556 .substreams = 2,
4557 .channels_min = 2,
4558 .channels_max = 2,
4559 .nid = 0x10, /* NID to query formats and rates */
4560 .ops = {
4561 .open = via_pcm_open_close,
4562 .prepare = via_capture_pcm_prepare,
4563 .cleanup = via_capture_pcm_cleanup,
4564 .close = via_pcm_open_close,
4565 },
4566 };
4567
4568 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4569 .substreams = 2,
4570 .channels_min = 2,
4571 .channels_max = 2,
4572 /* NID is set in via_build_pcms */
4573 .ops = {
4574 .open = via_dig_playback_pcm_open,
4575 .close = via_dig_playback_pcm_close,
4576 .prepare = via_dig_playback_pcm_prepare,
4577 .cleanup = via_dig_playback_pcm_cleanup
4578 },
4579 };
4580
4581 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4582 .substreams = 1,
4583 .channels_min = 2,
4584 .channels_max = 2,
4585 };
4586
4587 /* fill in the dac_nids table from the parsed pin configuration */
4588 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4589 const struct auto_pin_cfg *cfg)
4590 {
4591 int i;
4592 hda_nid_t nid;
4593
4594 spec->multiout.num_dacs = cfg->line_outs;
4595
4596 spec->multiout.dac_nids = spec->private_dac_nids;
4597
4598 for (i = 0; i < 4; i++) {
4599 nid = cfg->line_out_pins[i];
4600 if (nid) {
4601 /* config dac list */
4602 switch (i) {
4603 case AUTO_SEQ_FRONT:
4604 spec->multiout.dac_nids[i] = 0x8;
4605 break;
4606 case AUTO_SEQ_CENLFE:
4607 spec->multiout.dac_nids[i] = 0xa;
4608 break;
4609 case AUTO_SEQ_SURROUND:
4610 spec->multiout.dac_nids[i] = 0x9;
4611 break;
4612 case AUTO_SEQ_SIDE:
4613 spec->multiout.dac_nids[i] = 0xb;
4614 break;
4615 }
4616 }
4617 }
4618
4619 return 0;
4620 }
4621
4622 /* add playback controls from the parsed DAC table */
4623 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4624 const struct auto_pin_cfg *cfg)
4625 {
4626 char name[32];
4627 static const char * const chname[4] = {
4628 "Front", "Surround", "C/LFE", "Side"
4629 };
4630 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4631 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4632 hda_nid_t nid, nid_vol, nid_mute = 0;
4633 int i, err;
4634
4635 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4636 nid = cfg->line_out_pins[i];
4637
4638 if (!nid)
4639 continue;
4640 nid_vol = nid_vols[i];
4641 nid_mute = nid_mutes[i];
4642
4643 if (i == AUTO_SEQ_CENLFE) {
4644 /* Center/LFE */
4645 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4646 "Center Playback Volume",
4647 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4648 HDA_OUTPUT));
4649 if (err < 0)
4650 return err;
4651 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4652 "LFE Playback Volume",
4653 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4654 HDA_OUTPUT));
4655 if (err < 0)
4656 return err;
4657 err = via_add_control(
4658 spec, VIA_CTL_WIDGET_MUTE,
4659 "Center Playback Switch",
4660 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4661 HDA_OUTPUT));
4662 if (err < 0)
4663 return err;
4664 err = via_add_control(
4665 spec, VIA_CTL_WIDGET_MUTE,
4666 "LFE Playback Switch",
4667 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4668 HDA_OUTPUT));
4669 if (err < 0)
4670 return err;
4671 } else if (i == AUTO_SEQ_FRONT) {
4672 /* Front */
4673 sprintf(name, "%s Playback Volume", chname[i]);
4674 err = via_add_control(
4675 spec, VIA_CTL_WIDGET_VOL, name,
4676 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4677 if (err < 0)
4678 return err;
4679 sprintf(name, "%s Playback Switch", chname[i]);
4680 err = via_add_control(
4681 spec, VIA_CTL_WIDGET_MUTE, name,
4682 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4683 HDA_OUTPUT));
4684 if (err < 0)
4685 return err;
4686 } else {
4687 sprintf(name, "%s Playback Volume", chname[i]);
4688 err = via_add_control(
4689 spec, VIA_CTL_WIDGET_VOL, name,
4690 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4691 if (err < 0)
4692 return err;
4693 sprintf(name, "%s Playback Switch", chname[i]);
4694 err = via_add_control(
4695 spec, VIA_CTL_WIDGET_MUTE, name,
4696 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4697 HDA_OUTPUT));
4698 if (err < 0)
4699 return err;
4700 }
4701 }
4702 return 0;
4703 }
4704
4705 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4706 {
4707 int err;
4708
4709 if (!pin)
4710 return 0;
4711
4712 spec->multiout.hp_nid = 0xc; /* AOW4 */
4713 spec->hp_independent_mode_index = 1;
4714
4715 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4716 "Headphone Playback Volume",
4717 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4718 if (err < 0)
4719 return err;
4720
4721 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4722 "Headphone Playback Switch",
4723 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4724 if (err < 0)
4725 return err;
4726
4727 create_hp_imux(spec);
4728 return 0;
4729 }
4730
4731 /* create playback/capture controls for input pins */
4732 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4733 const struct auto_pin_cfg *cfg)
4734 {
4735 static hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4736 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
4737 ARRAY_SIZE(pin_idxs));
4738 }
4739
4740 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4741 {
4742 struct via_spec *spec = codec->spec;
4743 int err;
4744
4745 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4746
4747 if (err < 0)
4748 return err;
4749 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4750 if (err < 0)
4751 return err;
4752 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4753 return 0; /* can't find valid BIOS pin config */
4754
4755 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4756 if (err < 0)
4757 return err;
4758 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4759 if (err < 0)
4760 return err;
4761 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4762 if (err < 0)
4763 return err;
4764
4765 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4766
4767 fill_dig_outs(codec);
4768
4769 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4770 spec->dig_in_nid = 0x13;
4771
4772 if (spec->kctls.list)
4773 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4774
4775 spec->input_mux = &spec->private_imux[0];
4776
4777 if (spec->hp_mux)
4778 via_hp_build(codec);
4779
4780 via_smart51_build(spec);
4781
4782 return 1;
4783 }
4784
4785 #ifdef CONFIG_SND_HDA_POWER_SAVE
4786 static struct hda_amp_list vt1718S_loopbacks[] = {
4787 { 0x21, HDA_INPUT, 1 },
4788 { 0x21, HDA_INPUT, 2 },
4789 { 0x21, HDA_INPUT, 3 },
4790 { 0x21, HDA_INPUT, 4 },
4791 { } /* end */
4792 };
4793 #endif
4794
4795 static int patch_vt1718S(struct hda_codec *codec)
4796 {
4797 struct via_spec *spec;
4798 int err;
4799
4800 /* create a codec specific record */
4801 spec = via_new_spec(codec);
4802 if (spec == NULL)
4803 return -ENOMEM;
4804
4805 /* automatic parse from the BIOS config */
4806 err = vt1718S_parse_auto_config(codec);
4807 if (err < 0) {
4808 via_free(codec);
4809 return err;
4810 } else if (!err) {
4811 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4812 "from BIOS. Using genenic mode...\n");
4813 }
4814
4815 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4816 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4817
4818 if (codec->vendor_id == 0x11060441)
4819 spec->stream_name_analog = "VT2020 Analog";
4820 else if (codec->vendor_id == 0x11064441)
4821 spec->stream_name_analog = "VT1828S Analog";
4822 else
4823 spec->stream_name_analog = "VT1718S Analog";
4824 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4825 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4826
4827 if (codec->vendor_id == 0x11060441)
4828 spec->stream_name_digital = "VT2020 Digital";
4829 else if (codec->vendor_id == 0x11064441)
4830 spec->stream_name_digital = "VT1828S Digital";
4831 else
4832 spec->stream_name_digital = "VT1718S Digital";
4833 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4834 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4835 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4836
4837 if (!spec->adc_nids && spec->input_mux) {
4838 spec->adc_nids = vt1718S_adc_nids;
4839 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4840 get_mux_nids(codec);
4841 override_mic_boost(codec, 0x2b, 0, 3, 40);
4842 override_mic_boost(codec, 0x29, 0, 3, 40);
4843 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4844 spec->num_mixers++;
4845 }
4846
4847 codec->patch_ops = via_patch_ops;
4848
4849 codec->patch_ops.init = via_auto_init;
4850 codec->patch_ops.unsol_event = via_unsol_event;
4851
4852 #ifdef CONFIG_SND_HDA_POWER_SAVE
4853 spec->loopback.amplist = vt1718S_loopbacks;
4854 #endif
4855
4856 return 0;
4857 }
4858
4859 /* Patch for VT1716S */
4860
4861 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4862 struct snd_ctl_elem_info *uinfo)
4863 {
4864 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4865 uinfo->count = 1;
4866 uinfo->value.integer.min = 0;
4867 uinfo->value.integer.max = 1;
4868 return 0;
4869 }
4870
4871 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4872 struct snd_ctl_elem_value *ucontrol)
4873 {
4874 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4875 int index = 0;
4876
4877 index = snd_hda_codec_read(codec, 0x26, 0,
4878 AC_VERB_GET_CONNECT_SEL, 0);
4879 if (index != -1)
4880 *ucontrol->value.integer.value = index;
4881
4882 return 0;
4883 }
4884
4885 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4886 struct snd_ctl_elem_value *ucontrol)
4887 {
4888 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4889 struct via_spec *spec = codec->spec;
4890 int index = *ucontrol->value.integer.value;
4891
4892 snd_hda_codec_write(codec, 0x26, 0,
4893 AC_VERB_SET_CONNECT_SEL, index);
4894 spec->dmic_enabled = index;
4895 set_jack_power_state(codec);
4896
4897 return 1;
4898 }
4899
4900 /* capture mixer elements */
4901 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4902 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4903 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4904 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4905 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4906 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4907 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4908 HDA_INPUT),
4909 {
4910 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4911 .name = "Input Source",
4912 .count = 1,
4913 .info = via_mux_enum_info,
4914 .get = via_mux_enum_get,
4915 .put = via_mux_enum_put,
4916 },
4917 { } /* end */
4918 };
4919
4920 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4921 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4922 {
4923 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4924 .name = "Digital Mic Capture Switch",
4925 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4926 .count = 1,
4927 .info = vt1716s_dmic_info,
4928 .get = vt1716s_dmic_get,
4929 .put = vt1716s_dmic_put,
4930 },
4931 {} /* end */
4932 };
4933
4934
4935 /* mono-out mixer elements */
4936 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4937 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4938 { } /* end */
4939 };
4940
4941 static struct hda_verb vt1716S_volume_init_verbs[] = {
4942 /*
4943 * Unmute ADC0-1 and set the default input to mic-in
4944 */
4945 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4946 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4947
4948
4949 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4950 * mixer widget
4951 */
4952 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4953 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4954 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4955 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4956 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4957 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4958
4959 /* MUX Indices: Stereo Mixer = 5 */
4960 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4961
4962 /* Setup default input of PW4 to MW0 */
4963 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4964
4965 /* Setup default input of SW1 as MW0 */
4966 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4967
4968 /* Setup default input of SW4 as AOW0 */
4969 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4970
4971 /* PW9 PW10 Output enable */
4972 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4973 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4974
4975 /* Unmute SW1, PW12 */
4976 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4977 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4978 /* PW12 Output enable */
4979 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4980 /* Enable Boost Volume backdoor */
4981 {0x1, 0xf8a, 0x80},
4982 /* don't bybass mixer */
4983 {0x1, 0xf88, 0xc0},
4984 /* Enable mono output */
4985 {0x1, 0xf90, 0x08},
4986 { }
4987 };
4988
4989
4990 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
4991 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4992 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4993 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4994 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4995 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4996 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4997 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4998 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4999 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5000 { }
5001 };
5002
5003 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5004 .substreams = 2,
5005 .channels_min = 2,
5006 .channels_max = 6,
5007 .nid = 0x10, /* NID to query formats and rates */
5008 .ops = {
5009 .open = via_playback_pcm_open,
5010 .prepare = via_playback_multi_pcm_prepare,
5011 .cleanup = via_playback_multi_pcm_cleanup,
5012 .close = via_pcm_open_close,
5013 },
5014 };
5015
5016 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5017 .substreams = 2,
5018 .channels_min = 2,
5019 .channels_max = 2,
5020 .nid = 0x13, /* NID to query formats and rates */
5021 .ops = {
5022 .open = via_pcm_open_close,
5023 .prepare = via_capture_pcm_prepare,
5024 .cleanup = via_capture_pcm_cleanup,
5025 .close = via_pcm_open_close,
5026 },
5027 };
5028
5029 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5030 .substreams = 2,
5031 .channels_min = 2,
5032 .channels_max = 2,
5033 /* NID is set in via_build_pcms */
5034 .ops = {
5035 .open = via_dig_playback_pcm_open,
5036 .close = via_dig_playback_pcm_close,
5037 .prepare = via_dig_playback_pcm_prepare,
5038 .cleanup = via_dig_playback_pcm_cleanup
5039 },
5040 };
5041
5042 /* fill in the dac_nids table from the parsed pin configuration */
5043 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5044 const struct auto_pin_cfg *cfg)
5045 { int i;
5046 hda_nid_t nid;
5047
5048 spec->multiout.num_dacs = cfg->line_outs;
5049
5050 spec->multiout.dac_nids = spec->private_dac_nids;
5051
5052 for (i = 0; i < 3; i++) {
5053 nid = cfg->line_out_pins[i];
5054 if (nid) {
5055 /* config dac list */
5056 switch (i) {
5057 case AUTO_SEQ_FRONT:
5058 spec->multiout.dac_nids[i] = 0x10;
5059 break;
5060 case AUTO_SEQ_CENLFE:
5061 spec->multiout.dac_nids[i] = 0x25;
5062 break;
5063 case AUTO_SEQ_SURROUND:
5064 spec->multiout.dac_nids[i] = 0x11;
5065 break;
5066 }
5067 }
5068 }
5069
5070 return 0;
5071 }
5072
5073 /* add playback controls from the parsed DAC table */
5074 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5075 const struct auto_pin_cfg *cfg)
5076 {
5077 char name[32];
5078 static const char * const chname[3] = {
5079 "Front", "Surround", "C/LFE"
5080 };
5081 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5082 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5083 hda_nid_t nid, nid_vol, nid_mute;
5084 int i, err;
5085
5086 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5087 nid = cfg->line_out_pins[i];
5088
5089 if (!nid)
5090 continue;
5091
5092 nid_vol = nid_vols[i];
5093 nid_mute = nid_mutes[i];
5094
5095 if (i == AUTO_SEQ_CENLFE) {
5096 err = via_add_control(
5097 spec, VIA_CTL_WIDGET_VOL,
5098 "Center Playback Volume",
5099 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5100 if (err < 0)
5101 return err;
5102 err = via_add_control(
5103 spec, VIA_CTL_WIDGET_VOL,
5104 "LFE Playback Volume",
5105 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5106 if (err < 0)
5107 return err;
5108 err = via_add_control(
5109 spec, VIA_CTL_WIDGET_MUTE,
5110 "Center Playback Switch",
5111 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5112 HDA_OUTPUT));
5113 if (err < 0)
5114 return err;
5115 err = via_add_control(
5116 spec, VIA_CTL_WIDGET_MUTE,
5117 "LFE Playback Switch",
5118 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5119 HDA_OUTPUT));
5120 if (err < 0)
5121 return err;
5122 } else if (i == AUTO_SEQ_FRONT) {
5123
5124 err = via_add_control(
5125 spec, VIA_CTL_WIDGET_VOL,
5126 "Master Front Playback Volume",
5127 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5128 if (err < 0)
5129 return err;
5130 err = via_add_control(
5131 spec, VIA_CTL_WIDGET_MUTE,
5132 "Master Front Playback Switch",
5133 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5134 if (err < 0)
5135 return err;
5136
5137 sprintf(name, "%s Playback Volume", chname[i]);
5138 err = via_add_control(
5139 spec, VIA_CTL_WIDGET_VOL, name,
5140 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5141 if (err < 0)
5142 return err;
5143 sprintf(name, "%s Playback Switch", chname[i]);
5144 err = via_add_control(
5145 spec, VIA_CTL_WIDGET_MUTE, name,
5146 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5147 HDA_OUTPUT));
5148 if (err < 0)
5149 return err;
5150 } else {
5151 sprintf(name, "%s Playback Volume", chname[i]);
5152 err = via_add_control(
5153 spec, VIA_CTL_WIDGET_VOL, name,
5154 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5155 if (err < 0)
5156 return err;
5157 sprintf(name, "%s Playback Switch", chname[i]);
5158 err = via_add_control(
5159 spec, VIA_CTL_WIDGET_MUTE, name,
5160 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5161 HDA_OUTPUT));
5162 if (err < 0)
5163 return err;
5164 }
5165 }
5166 return 0;
5167 }
5168
5169 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5170 {
5171 int err;
5172
5173 if (!pin)
5174 return 0;
5175
5176 spec->multiout.hp_nid = 0x25; /* AOW3 */
5177 spec->hp_independent_mode_index = 1;
5178
5179 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5180 "Headphone Playback Volume",
5181 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5182 if (err < 0)
5183 return err;
5184
5185 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5186 "Headphone Playback Switch",
5187 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5188 if (err < 0)
5189 return err;
5190
5191 create_hp_imux(spec);
5192 return 0;
5193 }
5194
5195 /* create playback/capture controls for input pins */
5196 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5197 const struct auto_pin_cfg *cfg)
5198 {
5199 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5200 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
5201 ARRAY_SIZE(pin_idxs));
5202 }
5203
5204 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5205 {
5206 struct via_spec *spec = codec->spec;
5207 int err;
5208
5209 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5210 if (err < 0)
5211 return err;
5212 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5213 if (err < 0)
5214 return err;
5215 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5216 return 0; /* can't find valid BIOS pin config */
5217
5218 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5219 if (err < 0)
5220 return err;
5221 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5222 if (err < 0)
5223 return err;
5224 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5225 if (err < 0)
5226 return err;
5227
5228 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5229
5230 fill_dig_outs(codec);
5231
5232 if (spec->kctls.list)
5233 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5234
5235 spec->input_mux = &spec->private_imux[0];
5236
5237 if (spec->hp_mux)
5238 via_hp_build(codec);
5239
5240 via_smart51_build(spec);
5241
5242 return 1;
5243 }
5244
5245 #ifdef CONFIG_SND_HDA_POWER_SAVE
5246 static struct hda_amp_list vt1716S_loopbacks[] = {
5247 { 0x16, HDA_INPUT, 1 },
5248 { 0x16, HDA_INPUT, 2 },
5249 { 0x16, HDA_INPUT, 3 },
5250 { 0x16, HDA_INPUT, 4 },
5251 { } /* end */
5252 };
5253 #endif
5254
5255 static int patch_vt1716S(struct hda_codec *codec)
5256 {
5257 struct via_spec *spec;
5258 int err;
5259
5260 /* create a codec specific record */
5261 spec = via_new_spec(codec);
5262 if (spec == NULL)
5263 return -ENOMEM;
5264
5265 /* automatic parse from the BIOS config */
5266 err = vt1716S_parse_auto_config(codec);
5267 if (err < 0) {
5268 via_free(codec);
5269 return err;
5270 } else if (!err) {
5271 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5272 "from BIOS. Using genenic mode...\n");
5273 }
5274
5275 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5276 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5277
5278 spec->stream_name_analog = "VT1716S Analog";
5279 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5280 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5281
5282 spec->stream_name_digital = "VT1716S Digital";
5283 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5284
5285 if (!spec->adc_nids && spec->input_mux) {
5286 spec->adc_nids = vt1716S_adc_nids;
5287 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5288 get_mux_nids(codec);
5289 override_mic_boost(codec, 0x1a, 0, 3, 40);
5290 override_mic_boost(codec, 0x1e, 0, 3, 40);
5291 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5292 spec->num_mixers++;
5293 }
5294
5295 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5296 spec->num_mixers++;
5297
5298 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5299
5300 codec->patch_ops = via_patch_ops;
5301
5302 codec->patch_ops.init = via_auto_init;
5303 codec->patch_ops.unsol_event = via_unsol_event;
5304
5305 #ifdef CONFIG_SND_HDA_POWER_SAVE
5306 spec->loopback.amplist = vt1716S_loopbacks;
5307 #endif
5308
5309 return 0;
5310 }
5311
5312 /* for vt2002P */
5313
5314 /* capture mixer elements */
5315 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5316 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5317 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5318 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5319 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5320 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5321 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5322 HDA_INPUT),
5323 {
5324 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5325 /* The multiple "Capture Source" controls confuse alsamixer
5326 * So call somewhat different..
5327 */
5328 /* .name = "Capture Source", */
5329 .name = "Input Source",
5330 .count = 2,
5331 .info = via_mux_enum_info,
5332 .get = via_mux_enum_get,
5333 .put = via_mux_enum_put,
5334 },
5335 { } /* end */
5336 };
5337
5338 static struct hda_verb vt2002P_volume_init_verbs[] = {
5339 /*
5340 * Unmute ADC0-1 and set the default input to mic-in
5341 */
5342 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5343 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5344
5345
5346 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5347 * mixer widget
5348 */
5349 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5350 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5351 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5352 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5353 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5354 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5355
5356 /* MUX Indices: Mic = 0 */
5357 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5358 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5359
5360 /* PW9 Output enable */
5361 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5362
5363 /* Enable Boost Volume backdoor */
5364 {0x1, 0xfb9, 0x24},
5365
5366 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5367 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5368 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5369 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5370 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5371 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5372 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5373 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5374 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5375
5376 /* set MUX0/1/4/8 = 0 (AOW0) */
5377 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5378 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5379 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5380 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5381
5382 /* set PW0 index=0 (MW0) */
5383 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5384
5385 /* Enable AOW0 to MW9 */
5386 {0x1, 0xfb8, 0x88},
5387 { }
5388 };
5389
5390
5391 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5392 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5393 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5394 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5395 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5396 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5397 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5398 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5399 { }
5400 };
5401
5402 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5403 .substreams = 2,
5404 .channels_min = 2,
5405 .channels_max = 2,
5406 .nid = 0x8, /* NID to query formats and rates */
5407 .ops = {
5408 .open = via_playback_pcm_open,
5409 .prepare = via_playback_multi_pcm_prepare,
5410 .cleanup = via_playback_multi_pcm_cleanup,
5411 .close = via_pcm_open_close,
5412 },
5413 };
5414
5415 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5416 .substreams = 2,
5417 .channels_min = 2,
5418 .channels_max = 2,
5419 .nid = 0x10, /* NID to query formats and rates */
5420 .ops = {
5421 .open = via_pcm_open_close,
5422 .prepare = via_capture_pcm_prepare,
5423 .cleanup = via_capture_pcm_cleanup,
5424 .close = via_pcm_open_close,
5425 },
5426 };
5427
5428 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5429 .substreams = 1,
5430 .channels_min = 2,
5431 .channels_max = 2,
5432 /* NID is set in via_build_pcms */
5433 .ops = {
5434 .open = via_dig_playback_pcm_open,
5435 .close = via_dig_playback_pcm_close,
5436 .prepare = via_dig_playback_pcm_prepare,
5437 .cleanup = via_dig_playback_pcm_cleanup
5438 },
5439 };
5440
5441 /* fill in the dac_nids table from the parsed pin configuration */
5442 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5443 const struct auto_pin_cfg *cfg)
5444 {
5445 spec->multiout.num_dacs = 1;
5446 spec->multiout.dac_nids = spec->private_dac_nids;
5447 if (cfg->line_out_pins[0])
5448 spec->multiout.dac_nids[0] = 0x8;
5449 return 0;
5450 }
5451
5452 /* add playback controls from the parsed DAC table */
5453 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5454 const struct auto_pin_cfg *cfg)
5455 {
5456 int err;
5457
5458 if (!cfg->line_out_pins[0])
5459 return -1;
5460
5461
5462 /* Line-Out: PortE */
5463 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5464 "Master Front Playback Volume",
5465 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5466 if (err < 0)
5467 return err;
5468 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5469 "Master Front Playback Switch",
5470 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5471 if (err < 0)
5472 return err;
5473
5474 return 0;
5475 }
5476
5477 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5478 {
5479 int err;
5480
5481 if (!pin)
5482 return 0;
5483
5484 spec->multiout.hp_nid = 0x9;
5485 spec->hp_independent_mode_index = 1;
5486
5487 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5488 "Headphone Playback Volume",
5489 HDA_COMPOSE_AMP_VAL(
5490 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5491 if (err < 0)
5492 return err;
5493
5494 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5495 "Headphone Playback Switch",
5496 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5497 if (err < 0)
5498 return err;
5499
5500 create_hp_imux(spec);
5501 return 0;
5502 }
5503
5504 /* create playback/capture controls for input pins */
5505 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5506 const struct auto_pin_cfg *cfg)
5507 {
5508 struct via_spec *spec = codec->spec;
5509 struct hda_input_mux *imux = &spec->private_imux[0];
5510 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5511 int err;
5512
5513 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5514 ARRAY_SIZE(pin_idxs));
5515 if (err < 0)
5516 return err;
5517 /* build volume/mute control of loopback */
5518 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
5519 if (err < 0)
5520 return err;
5521
5522 /* for digital mic select */
5523 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
5524
5525 return 0;
5526 }
5527
5528 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5529 {
5530 struct via_spec *spec = codec->spec;
5531 int err;
5532
5533
5534 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5535 if (err < 0)
5536 return err;
5537
5538 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5539 if (err < 0)
5540 return err;
5541
5542 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5543 return 0; /* can't find valid BIOS pin config */
5544
5545 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5546 if (err < 0)
5547 return err;
5548 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5549 if (err < 0)
5550 return err;
5551 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5552 if (err < 0)
5553 return err;
5554
5555 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5556
5557 fill_dig_outs(codec);
5558
5559 if (spec->kctls.list)
5560 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5561
5562 spec->input_mux = &spec->private_imux[0];
5563
5564 if (spec->hp_mux)
5565 via_hp_build(codec);
5566
5567 return 1;
5568 }
5569
5570 #ifdef CONFIG_SND_HDA_POWER_SAVE
5571 static struct hda_amp_list vt2002P_loopbacks[] = {
5572 { 0x21, HDA_INPUT, 0 },
5573 { 0x21, HDA_INPUT, 1 },
5574 { 0x21, HDA_INPUT, 2 },
5575 { } /* end */
5576 };
5577 #endif
5578
5579
5580 /* patch for vt2002P */
5581 static int patch_vt2002P(struct hda_codec *codec)
5582 {
5583 struct via_spec *spec;
5584 int err;
5585
5586 /* create a codec specific record */
5587 spec = via_new_spec(codec);
5588 if (spec == NULL)
5589 return -ENOMEM;
5590
5591 /* automatic parse from the BIOS config */
5592 err = vt2002P_parse_auto_config(codec);
5593 if (err < 0) {
5594 via_free(codec);
5595 return err;
5596 } else if (!err) {
5597 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5598 "from BIOS. Using genenic mode...\n");
5599 }
5600
5601 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5602 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5603
5604 spec->stream_name_analog = "VT2002P Analog";
5605 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5606 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5607
5608 spec->stream_name_digital = "VT2002P Digital";
5609 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5610
5611 if (!spec->adc_nids && spec->input_mux) {
5612 spec->adc_nids = vt2002P_adc_nids;
5613 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5614 get_mux_nids(codec);
5615 override_mic_boost(codec, 0x2b, 0, 3, 40);
5616 override_mic_boost(codec, 0x29, 0, 3, 40);
5617 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5618 spec->num_mixers++;
5619 }
5620
5621 codec->patch_ops = via_patch_ops;
5622
5623 codec->patch_ops.init = via_auto_init;
5624 codec->patch_ops.unsol_event = via_unsol_event;
5625
5626 #ifdef CONFIG_SND_HDA_POWER_SAVE
5627 spec->loopback.amplist = vt2002P_loopbacks;
5628 #endif
5629
5630 return 0;
5631 }
5632
5633 /* for vt1812 */
5634
5635 /* capture mixer elements */
5636 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5637 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5638 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5639 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5640 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5641 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5642 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5643 HDA_INPUT),
5644 {
5645 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5646 /* The multiple "Capture Source" controls confuse alsamixer
5647 * So call somewhat different..
5648 */
5649 .name = "Input Source",
5650 .count = 2,
5651 .info = via_mux_enum_info,
5652 .get = via_mux_enum_get,
5653 .put = via_mux_enum_put,
5654 },
5655 { } /* end */
5656 };
5657
5658 static struct hda_verb vt1812_volume_init_verbs[] = {
5659 /*
5660 * Unmute ADC0-1 and set the default input to mic-in
5661 */
5662 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5663 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5664
5665
5666 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5667 * mixer widget
5668 */
5669 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5670 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5671 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5672 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5673 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5674 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5675
5676 /* MUX Indices: Mic = 0 */
5677 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5678 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5679
5680 /* PW9 Output enable */
5681 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5682
5683 /* Enable Boost Volume backdoor */
5684 {0x1, 0xfb9, 0x24},
5685
5686 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5687 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5688 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5689 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5690 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5691 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5692 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5693 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5694 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5695 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5696 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5697
5698 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5699 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5700 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5701 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5702 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5703 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5704
5705 /* Enable AOW0 to MW9 */
5706 {0x1, 0xfb8, 0xa8},
5707 { }
5708 };
5709
5710
5711 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5712 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5713 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5714 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5715 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5716 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5717 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5718 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5719 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5720 { }
5721 };
5722
5723 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5724 .substreams = 2,
5725 .channels_min = 2,
5726 .channels_max = 2,
5727 .nid = 0x8, /* NID to query formats and rates */
5728 .ops = {
5729 .open = via_playback_pcm_open,
5730 .prepare = via_playback_multi_pcm_prepare,
5731 .cleanup = via_playback_multi_pcm_cleanup,
5732 .close = via_pcm_open_close,
5733 },
5734 };
5735
5736 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5737 .substreams = 2,
5738 .channels_min = 2,
5739 .channels_max = 2,
5740 .nid = 0x10, /* NID to query formats and rates */
5741 .ops = {
5742 .open = via_pcm_open_close,
5743 .prepare = via_capture_pcm_prepare,
5744 .cleanup = via_capture_pcm_cleanup,
5745 .close = via_pcm_open_close,
5746 },
5747 };
5748
5749 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5750 .substreams = 1,
5751 .channels_min = 2,
5752 .channels_max = 2,
5753 /* NID is set in via_build_pcms */
5754 .ops = {
5755 .open = via_dig_playback_pcm_open,
5756 .close = via_dig_playback_pcm_close,
5757 .prepare = via_dig_playback_pcm_prepare,
5758 .cleanup = via_dig_playback_pcm_cleanup
5759 },
5760 };
5761 /* fill in the dac_nids table from the parsed pin configuration */
5762 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5763 const struct auto_pin_cfg *cfg)
5764 {
5765 spec->multiout.num_dacs = 1;
5766 spec->multiout.dac_nids = spec->private_dac_nids;
5767 if (cfg->line_out_pins[0])
5768 spec->multiout.dac_nids[0] = 0x8;
5769 return 0;
5770 }
5771
5772
5773 /* add playback controls from the parsed DAC table */
5774 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5775 const struct auto_pin_cfg *cfg)
5776 {
5777 int err;
5778
5779 if (!cfg->line_out_pins[0])
5780 return -1;
5781
5782 /* Line-Out: PortE */
5783 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5784 "Front Playback Volume",
5785 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5786 if (err < 0)
5787 return err;
5788 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5789 "Front Playback Switch",
5790 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5791 if (err < 0)
5792 return err;
5793
5794 return 0;
5795 }
5796
5797 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5798 {
5799 int err;
5800
5801 if (!pin)
5802 return 0;
5803
5804 spec->multiout.hp_nid = 0x9;
5805 spec->hp_independent_mode_index = 1;
5806
5807
5808 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5809 "Headphone Playback Volume",
5810 HDA_COMPOSE_AMP_VAL(
5811 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5812 if (err < 0)
5813 return err;
5814
5815 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5816 "Headphone Playback Switch",
5817 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5818 if (err < 0)
5819 return err;
5820
5821 create_hp_imux(spec);
5822 return 0;
5823 }
5824
5825 /* create playback/capture controls for input pins */
5826 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5827 const struct auto_pin_cfg *cfg)
5828 {
5829 struct via_spec *spec = codec->spec;
5830 struct hda_input_mux *imux = &spec->private_imux[0];
5831 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5832 int err;
5833
5834 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5835 ARRAY_SIZE(pin_idxs));
5836 if (err < 0)
5837 return err;
5838
5839 /* build volume/mute control of loopback */
5840 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
5841 if (err < 0)
5842 return err;
5843
5844 /* for digital mic select */
5845 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
5846
5847 return 0;
5848 }
5849
5850 static int vt1812_parse_auto_config(struct hda_codec *codec)
5851 {
5852 struct via_spec *spec = codec->spec;
5853 int err;
5854
5855
5856 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5857 if (err < 0)
5858 return err;
5859 fill_dig_outs(codec);
5860 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5861 if (err < 0)
5862 return err;
5863
5864 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5865 return 0; /* can't find valid BIOS pin config */
5866
5867 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5868 if (err < 0)
5869 return err;
5870 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5871 if (err < 0)
5872 return err;
5873 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
5874 if (err < 0)
5875 return err;
5876
5877 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5878
5879 fill_dig_outs(codec);
5880
5881 if (spec->kctls.list)
5882 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5883
5884 spec->input_mux = &spec->private_imux[0];
5885
5886 if (spec->hp_mux)
5887 via_hp_build(codec);
5888
5889 return 1;
5890 }
5891
5892 #ifdef CONFIG_SND_HDA_POWER_SAVE
5893 static struct hda_amp_list vt1812_loopbacks[] = {
5894 { 0x21, HDA_INPUT, 0 },
5895 { 0x21, HDA_INPUT, 1 },
5896 { 0x21, HDA_INPUT, 2 },
5897 { } /* end */
5898 };
5899 #endif
5900
5901
5902 /* patch for vt1812 */
5903 static int patch_vt1812(struct hda_codec *codec)
5904 {
5905 struct via_spec *spec;
5906 int err;
5907
5908 /* create a codec specific record */
5909 spec = via_new_spec(codec);
5910 if (spec == NULL)
5911 return -ENOMEM;
5912
5913 /* automatic parse from the BIOS config */
5914 err = vt1812_parse_auto_config(codec);
5915 if (err < 0) {
5916 via_free(codec);
5917 return err;
5918 } else if (!err) {
5919 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5920 "from BIOS. Using genenic mode...\n");
5921 }
5922
5923
5924 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
5925 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
5926
5927 spec->stream_name_analog = "VT1812 Analog";
5928 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
5929 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
5930
5931 spec->stream_name_digital = "VT1812 Digital";
5932 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
5933
5934
5935 if (!spec->adc_nids && spec->input_mux) {
5936 spec->adc_nids = vt1812_adc_nids;
5937 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
5938 get_mux_nids(codec);
5939 override_mic_boost(codec, 0x2b, 0, 3, 40);
5940 override_mic_boost(codec, 0x29, 0, 3, 40);
5941 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
5942 spec->num_mixers++;
5943 }
5944
5945 codec->patch_ops = via_patch_ops;
5946
5947 codec->patch_ops.init = via_auto_init;
5948 codec->patch_ops.unsol_event = via_unsol_event;
5949
5950 #ifdef CONFIG_SND_HDA_POWER_SAVE
5951 spec->loopback.amplist = vt1812_loopbacks;
5952 #endif
5953
5954 return 0;
5955 }
5956
5957 /*
5958 * patch entries
5959 */
5960 static struct hda_codec_preset snd_hda_preset_via[] = {
5961 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
5962 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
5963 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
5964 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
5965 { .id = 0x1106e710, .name = "VT1709 10-Ch",
5966 .patch = patch_vt1709_10ch},
5967 { .id = 0x1106e711, .name = "VT1709 10-Ch",
5968 .patch = patch_vt1709_10ch},
5969 { .id = 0x1106e712, .name = "VT1709 10-Ch",
5970 .patch = patch_vt1709_10ch},
5971 { .id = 0x1106e713, .name = "VT1709 10-Ch",
5972 .patch = patch_vt1709_10ch},
5973 { .id = 0x1106e714, .name = "VT1709 6-Ch",
5974 .patch = patch_vt1709_6ch},
5975 { .id = 0x1106e715, .name = "VT1709 6-Ch",
5976 .patch = patch_vt1709_6ch},
5977 { .id = 0x1106e716, .name = "VT1709 6-Ch",
5978 .patch = patch_vt1709_6ch},
5979 { .id = 0x1106e717, .name = "VT1709 6-Ch",
5980 .patch = patch_vt1709_6ch},
5981 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
5982 .patch = patch_vt1708B_8ch},
5983 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
5984 .patch = patch_vt1708B_8ch},
5985 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
5986 .patch = patch_vt1708B_8ch},
5987 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
5988 .patch = patch_vt1708B_8ch},
5989 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
5990 .patch = patch_vt1708B_4ch},
5991 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
5992 .patch = patch_vt1708B_4ch},
5993 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
5994 .patch = patch_vt1708B_4ch},
5995 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
5996 .patch = patch_vt1708B_4ch},
5997 { .id = 0x11060397, .name = "VT1708S",
5998 .patch = patch_vt1708S},
5999 { .id = 0x11061397, .name = "VT1708S",
6000 .patch = patch_vt1708S},
6001 { .id = 0x11062397, .name = "VT1708S",
6002 .patch = patch_vt1708S},
6003 { .id = 0x11063397, .name = "VT1708S",
6004 .patch = patch_vt1708S},
6005 { .id = 0x11064397, .name = "VT1708S",
6006 .patch = patch_vt1708S},
6007 { .id = 0x11065397, .name = "VT1708S",
6008 .patch = patch_vt1708S},
6009 { .id = 0x11066397, .name = "VT1708S",
6010 .patch = patch_vt1708S},
6011 { .id = 0x11067397, .name = "VT1708S",
6012 .patch = patch_vt1708S},
6013 { .id = 0x11060398, .name = "VT1702",
6014 .patch = patch_vt1702},
6015 { .id = 0x11061398, .name = "VT1702",
6016 .patch = patch_vt1702},
6017 { .id = 0x11062398, .name = "VT1702",
6018 .patch = patch_vt1702},
6019 { .id = 0x11063398, .name = "VT1702",
6020 .patch = patch_vt1702},
6021 { .id = 0x11064398, .name = "VT1702",
6022 .patch = patch_vt1702},
6023 { .id = 0x11065398, .name = "VT1702",
6024 .patch = patch_vt1702},
6025 { .id = 0x11066398, .name = "VT1702",
6026 .patch = patch_vt1702},
6027 { .id = 0x11067398, .name = "VT1702",
6028 .patch = patch_vt1702},
6029 { .id = 0x11060428, .name = "VT1718S",
6030 .patch = patch_vt1718S},
6031 { .id = 0x11064428, .name = "VT1718S",
6032 .patch = patch_vt1718S},
6033 { .id = 0x11060441, .name = "VT2020",
6034 .patch = patch_vt1718S},
6035 { .id = 0x11064441, .name = "VT1828S",
6036 .patch = patch_vt1718S},
6037 { .id = 0x11060433, .name = "VT1716S",
6038 .patch = patch_vt1716S},
6039 { .id = 0x1106a721, .name = "VT1716S",
6040 .patch = patch_vt1716S},
6041 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6042 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6043 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6044 { .id = 0x11060440, .name = "VT1818S",
6045 .patch = patch_vt1708S},
6046 {} /* terminator */
6047 };
6048
6049 MODULE_ALIAS("snd-hda-codec-id:1106*");
6050
6051 static struct hda_codec_preset_list via_list = {
6052 .preset = snd_hda_preset_via,
6053 .owner = THIS_MODULE,
6054 };
6055
6056 MODULE_LICENSE("GPL");
6057 MODULE_DESCRIPTION("VIA HD-audio codec");
6058
6059 static int __init patch_via_init(void)
6060 {
6061 return snd_hda_add_codec_preset(&via_list);
6062 }
6063
6064 static void __exit patch_via_exit(void)
6065 {
6066 snd_hda_delete_codec_preset(&via_list);
6067 }
6068
6069 module_init(patch_via_init)
6070 module_exit(patch_via_exit)