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