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