aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/patch_via.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/hda/patch_via.c')
-rw-r--r--sound/pci/hda/patch_via.c3509
1 files changed, 3211 insertions, 298 deletions
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index ee89db90c9b6..b70e26ad263f 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * Universal Interface for Intel High Definition Audio Codec 2 * Universal Interface for Intel High Definition Audio Codec
3 * 3 *
4 * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec 4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
5 * 5 *
6 * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com> 6 * (C) 2006-2009 VIA Technology, Inc.
7 * Takashi Iwai <tiwai@suse.de> 7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
8 * 8 *
9 * This driver is free software; you can redistribute it and/or modify 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 10 * it under the terms of the GNU General Public License as published by
@@ -22,21 +22,27 @@
22 */ 22 */
23 23
24/* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */ 24/* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
25/* */ 25/* */
26/* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */ 26/* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27/* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */ 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 */ 28/* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29/* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */ 29/* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30/* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */ 30/* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31/* 2007-09-17 Lydia Wang Add VT1708B codec support */ 31/* 2007-09-17 Lydia Wang Add VT1708B codec support */
32/* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */ 32/* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33/* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */ 33/* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34/* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */ 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 */ 35/* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36/* 2008-04-09 Lydia Wang Add Independent HP feature */ 36/* 2008-04-09 Lydia Wang Add Independent HP feature */
37/* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */ 37/* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38/* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */ 38/* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39/* */ 39/* 2009-02-16 Logan Li Add support for VT1718S */
40/* 2009-03-13 Logan Li Add support for VT1716S */
41/* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42/* 2009-07-08 Lydia Wang Add support for VT2002P */
43/* 2009-07-21 Lydia Wang Add support for VT1812 */
44/* 2009-09-19 Lydia Wang Add support for VT1818S */
45/* */
40/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 46/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
41 47
42 48
@@ -76,14 +82,6 @@
76#define VT1702_HP_NID 0x17 82#define VT1702_HP_NID 0x17
77#define VT1702_DIGOUT_NID 0x11 83#define VT1702_DIGOUT_NID 0x11
78 84
79#define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
80#define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
81#define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
82#define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
83#define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
84#define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
85#define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
86
87enum VIA_HDA_CODEC { 85enum VIA_HDA_CODEC {
88 UNKNOWN = -1, 86 UNKNOWN = -1,
89 VT1708, 87 VT1708,
@@ -92,12 +90,76 @@ enum VIA_HDA_CODEC {
92 VT1708B_8CH, 90 VT1708B_8CH,
93 VT1708B_4CH, 91 VT1708B_4CH,
94 VT1708S, 92 VT1708S,
93 VT1708BCE,
95 VT1702, 94 VT1702,
95 VT1718S,
96 VT1716S,
97 VT2002P,
98 VT1812,
96 CODEC_TYPES, 99 CODEC_TYPES,
97}; 100};
98 101
99static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id) 102struct via_spec {
103 /* codec parameterization */
104 struct snd_kcontrol_new *mixers[6];
105 unsigned int num_mixers;
106
107 struct hda_verb *init_verbs[5];
108 unsigned int num_iverbs;
109
110 char *stream_name_analog;
111 struct hda_pcm_stream *stream_analog_playback;
112 struct hda_pcm_stream *stream_analog_capture;
113
114 char *stream_name_digital;
115 struct hda_pcm_stream *stream_digital_playback;
116 struct hda_pcm_stream *stream_digital_capture;
117
118 /* playback */
119 struct hda_multi_out multiout;
120 hda_nid_t slave_dig_outs[2];
121
122 /* capture */
123 unsigned int num_adc_nids;
124 hda_nid_t *adc_nids;
125 hda_nid_t mux_nids[3];
126 hda_nid_t dig_in_nid;
127 hda_nid_t dig_in_pin;
128
129 /* capture source */
130 const struct hda_input_mux *input_mux;
131 unsigned int cur_mux[3];
132
133 /* PCM information */
134 struct hda_pcm pcm_rec[3];
135
136 /* dynamic controls, init_verbs and input_mux */
137 struct auto_pin_cfg autocfg;
138 struct snd_array kctls;
139 struct hda_input_mux private_imux[2];
140 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
141
142 /* HP mode source */
143 const struct hda_input_mux *hp_mux;
144 unsigned int hp_independent_mode;
145 unsigned int hp_independent_mode_index;
146 unsigned int smart51_enabled;
147 unsigned int dmic_enabled;
148 enum VIA_HDA_CODEC codec_type;
149
150 /* work to check hp jack state */
151 struct hda_codec *codec;
152 struct delayed_work vt1708_hp_work;
153 int vt1708_jack_detectect;
154 int vt1708_hp_present;
155#ifdef CONFIG_SND_HDA_POWER_SAVE
156 struct hda_loopback_check loopback;
157#endif
158};
159
160static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
100{ 161{
162 u32 vendor_id = codec->vendor_id;
101 u16 ven_id = vendor_id >> 16; 163 u16 ven_id = vendor_id >> 16;
102 u16 dev_id = vendor_id & 0xffff; 164 u16 dev_id = vendor_id & 0xffff;
103 enum VIA_HDA_CODEC codec_type; 165 enum VIA_HDA_CODEC codec_type;
@@ -111,9 +173,11 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
111 codec_type = VT1709_10CH; 173 codec_type = VT1709_10CH;
112 else if (dev_id >= 0xe714 && dev_id <= 0xe717) 174 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
113 codec_type = VT1709_6CH; 175 codec_type = VT1709_6CH;
114 else if (dev_id >= 0xe720 && dev_id <= 0xe723) 176 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
115 codec_type = VT1708B_8CH; 177 codec_type = VT1708B_8CH;
116 else if (dev_id >= 0xe724 && dev_id <= 0xe727) 178 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
179 codec_type = VT1708BCE;
180 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
117 codec_type = VT1708B_4CH; 181 codec_type = VT1708B_4CH;
118 else if ((dev_id & 0xfff) == 0x397 182 else if ((dev_id & 0xfff) == 0x397
119 && (dev_id >> 12) < 8) 183 && (dev_id >> 12) < 8)
@@ -121,6 +185,19 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
121 else if ((dev_id & 0xfff) == 0x398 185 else if ((dev_id & 0xfff) == 0x398
122 && (dev_id >> 12) < 8) 186 && (dev_id >> 12) < 8)
123 codec_type = VT1702; 187 codec_type = VT1702;
188 else if ((dev_id & 0xfff) == 0x428
189 && (dev_id >> 12) < 8)
190 codec_type = VT1718S;
191 else if (dev_id == 0x0433 || dev_id == 0xa721)
192 codec_type = VT1716S;
193 else if (dev_id == 0x0441 || dev_id == 0x4441)
194 codec_type = VT1718S;
195 else if (dev_id == 0x0438 || dev_id == 0x4438)
196 codec_type = VT2002P;
197 else if (dev_id == 0x0448)
198 codec_type = VT1812;
199 else if (dev_id == 0x0440)
200 codec_type = VT1708S;
124 else 201 else
125 codec_type = UNKNOWN; 202 codec_type = UNKNOWN;
126 return codec_type; 203 return codec_type;
@@ -128,10 +205,16 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
128 205
129#define VIA_HP_EVENT 0x01 206#define VIA_HP_EVENT 0x01
130#define VIA_GPIO_EVENT 0x02 207#define VIA_GPIO_EVENT 0x02
208#define VIA_JACK_EVENT 0x04
209#define VIA_MONO_EVENT 0x08
210#define VIA_SPEAKER_EVENT 0x10
211#define VIA_BIND_HP_EVENT 0x20
131 212
132enum { 213enum {
133 VIA_CTL_WIDGET_VOL, 214 VIA_CTL_WIDGET_VOL,
134 VIA_CTL_WIDGET_MUTE, 215 VIA_CTL_WIDGET_MUTE,
216 VIA_CTL_WIDGET_ANALOG_MUTE,
217 VIA_CTL_WIDGET_BIND_PIN_MUTE,
135}; 218};
136 219
137enum { 220enum {
@@ -141,99 +224,162 @@ enum {
141 AUTO_SEQ_SIDE 224 AUTO_SEQ_SIDE
142}; 225};
143 226
144/* Some VT1708S based boards gets the micboost setting wrong, so we have 227static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
145 * to apply some brute-force and re-write the TLV's by software. */ 228static void set_jack_power_state(struct hda_codec *codec);
146static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag, 229static int is_aa_path_mute(struct hda_codec *codec);
147 unsigned int size, unsigned int __user *_tlv) 230
231static void vt1708_start_hp_work(struct via_spec *spec)
148{ 232{
149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 233 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
150 hda_nid_t nid = get_amp_nid(kcontrol); 234 return;
235 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
236 !spec->vt1708_jack_detectect);
237 if (!delayed_work_pending(&spec->vt1708_hp_work))
238 schedule_delayed_work(&spec->vt1708_hp_work,
239 msecs_to_jiffies(100));
240}
151 241
152 if (get_codec_type(codec->vendor_id) == VT1708S 242static void vt1708_stop_hp_work(struct via_spec *spec)
153 && (nid == 0x1a || nid == 0x1e)) { 243{
154 if (size < 4 * sizeof(unsigned int)) 244 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
155 return -ENOMEM; 245 return;
156 if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */ 246 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
157 return -EFAULT; 247 && !is_aa_path_mute(spec->codec))
158 if (put_user(2 * sizeof(unsigned int), _tlv + 1)) 248 return;
159 return -EFAULT; 249 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
160 if (put_user(0, _tlv + 2)) /* offset = 0 */ 250 !spec->vt1708_jack_detectect);
161 return -EFAULT; 251 cancel_delayed_work(&spec->vt1708_hp_work);
162 if (put_user(1000, _tlv + 3)) /* step size = 10 dB */ 252 flush_scheduled_work();
163 return -EFAULT;
164 }
165 return 0;
166} 253}
167 254
168static int mic_boost_volume_info(struct snd_kcontrol *kcontrol, 255
169 struct snd_ctl_elem_info *uinfo) 256static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_value *ucontrol)
170{ 258{
259 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 260 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
172 hda_nid_t nid = get_amp_nid(kcontrol);
173 261
174 if (get_codec_type(codec->vendor_id) == VT1708S 262 set_jack_power_state(codec);
175 && (nid == 0x1a || nid == 0x1e)) { 263 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
176 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 264 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
177 uinfo->count = 2; 265 if (is_aa_path_mute(codec))
178 uinfo->value.integer.min = 0; 266 vt1708_start_hp_work(codec->spec);
179 uinfo->value.integer.max = 3; 267 else
268 vt1708_stop_hp_work(codec->spec);
180 } 269 }
181 return 0; 270 return change;
182} 271}
183 272
184static struct snd_kcontrol_new vt1708_control_templates[] = { 273/* modify .put = snd_hda_mixer_amp_switch_put */
185 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 274#define ANALOG_INPUT_MUTE \
186 HDA_CODEC_MUTE(NULL, 0, 0, 0), 275 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
187}; 276 .name = NULL, \
188 277 .index = 0, \
189 278 .info = snd_hda_mixer_amp_switch_info, \
190struct via_spec { 279 .get = snd_hda_mixer_amp_switch_get, \
191 /* codec parameterization */ 280 .put = analog_input_switch_put, \
192 struct snd_kcontrol_new *mixers[3]; 281 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
193 unsigned int num_mixers;
194 282
195 struct hda_verb *init_verbs[5]; 283static void via_hp_bind_automute(struct hda_codec *codec);
196 unsigned int num_iverbs;
197 284
198 char *stream_name_analog; 285static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
199 struct hda_pcm_stream *stream_analog_playback; 286 struct snd_ctl_elem_value *ucontrol)
200 struct hda_pcm_stream *stream_analog_capture; 287{
201 288 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
202 char *stream_name_digital; 289 struct via_spec *spec = codec->spec;
203 struct hda_pcm_stream *stream_digital_playback; 290 int i;
204 struct hda_pcm_stream *stream_digital_capture; 291 int change = 0;
205
206 /* playback */
207 struct hda_multi_out multiout;
208 hda_nid_t slave_dig_outs[2];
209
210 /* capture */
211 unsigned int num_adc_nids;
212 hda_nid_t *adc_nids;
213 hda_nid_t mux_nids[3];
214 hda_nid_t dig_in_nid;
215 hda_nid_t dig_in_pin;
216 292
217 /* capture source */ 293 long *valp = ucontrol->value.integer.value;
218 const struct hda_input_mux *input_mux; 294 int lmute, rmute;
219 unsigned int cur_mux[3]; 295 if (strstr(kcontrol->id.name, "Switch") == NULL) {
296 snd_printd("Invalid control!\n");
297 return change;
298 }
299 change = snd_hda_mixer_amp_switch_put(kcontrol,
300 ucontrol);
301 /* Get mute value */
302 lmute = *valp ? 0 : HDA_AMP_MUTE;
303 valp++;
304 rmute = *valp ? 0 : HDA_AMP_MUTE;
305
306 /* Set hp pins */
307 if (!spec->hp_independent_mode) {
308 for (i = 0; i < spec->autocfg.hp_outs; i++) {
309 snd_hda_codec_amp_update(
310 codec, spec->autocfg.hp_pins[i],
311 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
312 lmute);
313 snd_hda_codec_amp_update(
314 codec, spec->autocfg.hp_pins[i],
315 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
316 rmute);
317 }
318 }
220 319
221 /* PCM information */ 320 if (!lmute && !rmute) {
222 struct hda_pcm pcm_rec[3]; 321 /* Line Outs */
322 for (i = 0; i < spec->autocfg.line_outs; i++)
323 snd_hda_codec_amp_stereo(
324 codec, spec->autocfg.line_out_pins[i],
325 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
326 /* Speakers */
327 for (i = 0; i < spec->autocfg.speaker_outs; i++)
328 snd_hda_codec_amp_stereo(
329 codec, spec->autocfg.speaker_pins[i],
330 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
331 /* unmute */
332 via_hp_bind_automute(codec);
223 333
224 /* dynamic controls, init_verbs and input_mux */ 334 } else {
225 struct auto_pin_cfg autocfg; 335 if (lmute) {
226 struct snd_array kctls; 336 /* Mute all left channels */
227 struct hda_input_mux private_imux[2]; 337 for (i = 1; i < spec->autocfg.line_outs; i++)
228 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 338 snd_hda_codec_amp_update(
339 codec,
340 spec->autocfg.line_out_pins[i],
341 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
342 lmute);
343 for (i = 0; i < spec->autocfg.speaker_outs; i++)
344 snd_hda_codec_amp_update(
345 codec,
346 spec->autocfg.speaker_pins[i],
347 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
348 lmute);
349 }
350 if (rmute) {
351 /* mute all right channels */
352 for (i = 1; i < spec->autocfg.line_outs; i++)
353 snd_hda_codec_amp_update(
354 codec,
355 spec->autocfg.line_out_pins[i],
356 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
357 rmute);
358 for (i = 0; i < spec->autocfg.speaker_outs; i++)
359 snd_hda_codec_amp_update(
360 codec,
361 spec->autocfg.speaker_pins[i],
362 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
363 rmute);
364 }
365 }
366 return change;
367}
229 368
230 /* HP mode source */ 369#define BIND_PIN_MUTE \
231 const struct hda_input_mux *hp_mux; 370 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
232 unsigned int hp_independent_mode; 371 .name = NULL, \
372 .index = 0, \
373 .info = snd_hda_mixer_amp_switch_info, \
374 .get = snd_hda_mixer_amp_switch_get, \
375 .put = bind_pin_switch_put, \
376 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
233 377
234#ifdef CONFIG_SND_HDA_POWER_SAVE 378static struct snd_kcontrol_new via_control_templates[] = {
235 struct hda_loopback_check loopback; 379 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
236#endif 380 HDA_CODEC_MUTE(NULL, 0, 0, 0),
381 ANALOG_INPUT_MUTE,
382 BIND_PIN_MUTE,
237}; 383};
238 384
239static hda_nid_t vt1708_adc_nids[2] = { 385static hda_nid_t vt1708_adc_nids[2] = {
@@ -261,6 +407,27 @@ static hda_nid_t vt1702_adc_nids[3] = {
261 0x12, 0x20, 0x1F 407 0x12, 0x20, 0x1F
262}; 408};
263 409
410static hda_nid_t vt1718S_adc_nids[2] = {
411 /* ADC1-2 */
412 0x10, 0x11
413};
414
415static hda_nid_t vt1716S_adc_nids[2] = {
416 /* ADC1-2 */
417 0x13, 0x14
418};
419
420static hda_nid_t vt2002P_adc_nids[2] = {
421 /* ADC1-2 */
422 0x10, 0x11
423};
424
425static hda_nid_t vt1812_adc_nids[2] = {
426 /* ADC1-2 */
427 0x10, 0x11
428};
429
430
264/* add dynamic controls */ 431/* add dynamic controls */
265static int via_add_control(struct via_spec *spec, int type, const char *name, 432static int via_add_control(struct via_spec *spec, int type, const char *name,
266 unsigned long val) 433 unsigned long val)
@@ -271,10 +438,12 @@ static int via_add_control(struct via_spec *spec, int type, const char *name,
271 knew = snd_array_new(&spec->kctls); 438 knew = snd_array_new(&spec->kctls);
272 if (!knew) 439 if (!knew)
273 return -ENOMEM; 440 return -ENOMEM;
274 *knew = vt1708_control_templates[type]; 441 *knew = via_control_templates[type];
275 knew->name = kstrdup(name, GFP_KERNEL); 442 knew->name = kstrdup(name, GFP_KERNEL);
276 if (!knew->name) 443 if (!knew->name)
277 return -ENOMEM; 444 return -ENOMEM;
445 if (get_amp_nid_(val))
446 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
278 knew->private_value = val; 447 knew->private_value = val;
279 return 0; 448 return 0;
280} 449}
@@ -293,8 +462,8 @@ static void via_free_kctls(struct hda_codec *codec)
293} 462}
294 463
295/* create input playback/capture controls for the given pin */ 464/* create input playback/capture controls for the given pin */
296static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin, 465static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
297 const char *ctlname, int idx, int mix_nid) 466 int idx, int mix_nid)
298{ 467{
299 char name[32]; 468 char name[32];
300 int err; 469 int err;
@@ -305,7 +474,7 @@ static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
305 if (err < 0) 474 if (err < 0)
306 return err; 475 return err;
307 sprintf(name, "%s Playback Switch", ctlname); 476 sprintf(name, "%s Playback Switch", ctlname);
308 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 477 err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name,
309 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); 478 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
310 if (err < 0) 479 if (err < 0)
311 return err; 480 return err;
@@ -322,7 +491,7 @@ static void via_auto_set_output_and_unmute(struct hda_codec *codec,
322 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 491 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
323 AMP_OUT_UNMUTE); 492 AMP_OUT_UNMUTE);
324 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) 493 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
325 snd_hda_codec_write(codec, nid, 0, 494 snd_hda_codec_write(codec, nid, 0,
326 AC_VERB_SET_EAPD_BTLENABLE, 0x02); 495 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
327} 496}
328 497
@@ -343,10 +512,13 @@ static void via_auto_init_hp_out(struct hda_codec *codec)
343{ 512{
344 struct via_spec *spec = codec->spec; 513 struct via_spec *spec = codec->spec;
345 hda_nid_t pin; 514 hda_nid_t pin;
515 int i;
346 516
347 pin = spec->autocfg.hp_pins[0]; 517 for (i = 0; i < spec->autocfg.hp_outs; i++) {
348 if (pin) /* connect to front */ 518 pin = spec->autocfg.hp_pins[i];
349 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 519 if (pin) /* connect to front */
520 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
521 }
350} 522}
351 523
352static void via_auto_init_analog_input(struct hda_codec *codec) 524static void via_auto_init_analog_input(struct hda_codec *codec)
@@ -364,6 +536,502 @@ static void via_auto_init_analog_input(struct hda_codec *codec)
364 536
365 } 537 }
366} 538}
539
540static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
541
542static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
543 unsigned int *affected_parm)
544{
545 unsigned parm;
546 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
547 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
548 >> AC_DEFCFG_MISC_SHIFT
549 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
550 unsigned present = snd_hda_jack_detect(codec, nid);
551 struct via_spec *spec = codec->spec;
552 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
553 || ((no_presence || present)
554 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
555 *affected_parm = AC_PWRST_D0; /* if it's connected */
556 parm = AC_PWRST_D0;
557 } else
558 parm = AC_PWRST_D3;
559
560 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
561}
562
563static void set_jack_power_state(struct hda_codec *codec)
564{
565 struct via_spec *spec = codec->spec;
566 int imux_is_smixer;
567 unsigned int parm;
568
569 if (spec->codec_type == VT1702) {
570 imux_is_smixer = snd_hda_codec_read(
571 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
572 /* inputs */
573 /* PW 1/2/5 (14h/15h/18h) */
574 parm = AC_PWRST_D3;
575 set_pin_power_state(codec, 0x14, &parm);
576 set_pin_power_state(codec, 0x15, &parm);
577 set_pin_power_state(codec, 0x18, &parm);
578 if (imux_is_smixer)
579 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
580 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
581 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
582 parm);
583 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
584 parm);
585 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
586 parm);
587 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
588 parm);
589
590 /* outputs */
591 /* PW 3/4 (16h/17h) */
592 parm = AC_PWRST_D3;
593 set_pin_power_state(codec, 0x16, &parm);
594 set_pin_power_state(codec, 0x17, &parm);
595 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
596 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
597 imux_is_smixer ? AC_PWRST_D0 : parm);
598 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
599 parm);
600 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
601 parm);
602 } else if (spec->codec_type == VT1708B_8CH
603 || spec->codec_type == VT1708B_4CH
604 || spec->codec_type == VT1708S) {
605 /* SW0 (17h) = stereo mixer */
606 int is_8ch = spec->codec_type != VT1708B_4CH;
607 imux_is_smixer = snd_hda_codec_read(
608 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
609 == ((spec->codec_type == VT1708S) ? 5 : 0);
610 /* inputs */
611 /* PW 1/2/5 (1ah/1bh/1eh) */
612 parm = AC_PWRST_D3;
613 set_pin_power_state(codec, 0x1a, &parm);
614 set_pin_power_state(codec, 0x1b, &parm);
615 set_pin_power_state(codec, 0x1e, &parm);
616 if (imux_is_smixer)
617 parm = AC_PWRST_D0;
618 /* SW0 (17h), AIW 0/1 (13h/14h) */
619 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
620 parm);
621 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
622 parm);
623 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
624 parm);
625
626 /* outputs */
627 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
628 parm = AC_PWRST_D3;
629 set_pin_power_state(codec, 0x19, &parm);
630 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
631 parm);
632 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
633 parm);
634
635 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
636 if (is_8ch) {
637 parm = AC_PWRST_D3;
638 set_pin_power_state(codec, 0x22, &parm);
639 snd_hda_codec_write(codec, 0x26, 0,
640 AC_VERB_SET_POWER_STATE, parm);
641 snd_hda_codec_write(codec, 0x24, 0,
642 AC_VERB_SET_POWER_STATE, parm);
643 }
644
645 /* PW 3/4/7 (1ch/1dh/23h) */
646 parm = AC_PWRST_D3;
647 /* force to D0 for internal Speaker */
648 set_pin_power_state(codec, 0x1c, &parm);
649 set_pin_power_state(codec, 0x1d, &parm);
650 if (is_8ch)
651 set_pin_power_state(codec, 0x23, &parm);
652 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
653 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
654 imux_is_smixer ? AC_PWRST_D0 : parm);
655 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
656 parm);
657 if (is_8ch) {
658 snd_hda_codec_write(codec, 0x25, 0,
659 AC_VERB_SET_POWER_STATE, parm);
660 snd_hda_codec_write(codec, 0x27, 0,
661 AC_VERB_SET_POWER_STATE, parm);
662 }
663 } else if (spec->codec_type == VT1718S) {
664 /* MUX6 (1eh) = stereo mixer */
665 imux_is_smixer = snd_hda_codec_read(
666 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
667 /* inputs */
668 /* PW 5/6/7 (29h/2ah/2bh) */
669 parm = AC_PWRST_D3;
670 set_pin_power_state(codec, 0x29, &parm);
671 set_pin_power_state(codec, 0x2a, &parm);
672 set_pin_power_state(codec, 0x2b, &parm);
673 if (imux_is_smixer)
674 parm = AC_PWRST_D0;
675 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
676 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
677 parm);
678 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
679 parm);
680 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
681 parm);
682 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
683 parm);
684
685 /* outputs */
686 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
687 parm = AC_PWRST_D3;
688 set_pin_power_state(codec, 0x27, &parm);
689 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
690 parm);
691 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
692 parm);
693
694 /* PW2 (26h), AOW2 (ah) */
695 parm = AC_PWRST_D3;
696 set_pin_power_state(codec, 0x26, &parm);
697 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
698 parm);
699
700 /* PW0/1 (24h/25h) */
701 parm = AC_PWRST_D3;
702 set_pin_power_state(codec, 0x24, &parm);
703 set_pin_power_state(codec, 0x25, &parm);
704 if (!spec->hp_independent_mode) /* check for redirected HP */
705 set_pin_power_state(codec, 0x28, &parm);
706 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
707 parm);
708 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
709 parm);
710 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
711 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
712 imux_is_smixer ? AC_PWRST_D0 : parm);
713 if (spec->hp_independent_mode) {
714 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
715 parm = AC_PWRST_D3;
716 set_pin_power_state(codec, 0x28, &parm);
717 snd_hda_codec_write(codec, 0x1b, 0,
718 AC_VERB_SET_POWER_STATE, parm);
719 snd_hda_codec_write(codec, 0x34, 0,
720 AC_VERB_SET_POWER_STATE, parm);
721 snd_hda_codec_write(codec, 0xc, 0,
722 AC_VERB_SET_POWER_STATE, parm);
723 }
724 } else if (spec->codec_type == VT1716S) {
725 unsigned int mono_out, present;
726 /* SW0 (17h) = stereo mixer */
727 imux_is_smixer = snd_hda_codec_read(
728 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
729 /* inputs */
730 /* PW 1/2/5 (1ah/1bh/1eh) */
731 parm = AC_PWRST_D3;
732 set_pin_power_state(codec, 0x1a, &parm);
733 set_pin_power_state(codec, 0x1b, &parm);
734 set_pin_power_state(codec, 0x1e, &parm);
735 if (imux_is_smixer)
736 parm = AC_PWRST_D0;
737 /* SW0 (17h), AIW0(13h) */
738 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
739 parm);
740 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
741 parm);
742
743 parm = AC_PWRST_D3;
744 set_pin_power_state(codec, 0x1e, &parm);
745 /* PW11 (22h) */
746 if (spec->dmic_enabled)
747 set_pin_power_state(codec, 0x22, &parm);
748 else
749 snd_hda_codec_write(
750 codec, 0x22, 0,
751 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
752
753 /* SW2(26h), AIW1(14h) */
754 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
755 parm);
756 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
757 parm);
758
759 /* outputs */
760 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
761 parm = AC_PWRST_D3;
762 set_pin_power_state(codec, 0x19, &parm);
763 /* Smart 5.1 PW2(1bh) */
764 if (spec->smart51_enabled)
765 set_pin_power_state(codec, 0x1b, &parm);
766 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
767 parm);
768 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
769 parm);
770
771 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
772 parm = AC_PWRST_D3;
773 set_pin_power_state(codec, 0x23, &parm);
774 /* Smart 5.1 PW1(1ah) */
775 if (spec->smart51_enabled)
776 set_pin_power_state(codec, 0x1a, &parm);
777 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
778 parm);
779
780 /* Smart 5.1 PW5(1eh) */
781 if (spec->smart51_enabled)
782 set_pin_power_state(codec, 0x1e, &parm);
783 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
784 parm);
785
786 /* Mono out */
787 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
788 present = snd_hda_jack_detect(codec, 0x1c);
789 if (present)
790 mono_out = 0;
791 else {
792 present = snd_hda_jack_detect(codec, 0x1d);
793 if (!spec->hp_independent_mode && present)
794 mono_out = 0;
795 else
796 mono_out = 1;
797 }
798 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
799 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
800 parm);
801 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
802 parm);
803 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
804 parm);
805
806 /* PW 3/4 (1ch/1dh) */
807 parm = AC_PWRST_D3;
808 set_pin_power_state(codec, 0x1c, &parm);
809 set_pin_power_state(codec, 0x1d, &parm);
810 /* HP Independent Mode, power on AOW3 */
811 if (spec->hp_independent_mode)
812 snd_hda_codec_write(codec, 0x25, 0,
813 AC_VERB_SET_POWER_STATE, parm);
814
815 /* force to D0 for internal Speaker */
816 /* MW0 (16h), AOW0 (10h) */
817 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
818 imux_is_smixer ? AC_PWRST_D0 : parm);
819 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
820 mono_out ? AC_PWRST_D0 : parm);
821 } else if (spec->codec_type == VT2002P) {
822 unsigned int present;
823 /* MUX9 (1eh) = stereo mixer */
824 imux_is_smixer = snd_hda_codec_read(
825 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
826 /* inputs */
827 /* PW 5/6/7 (29h/2ah/2bh) */
828 parm = AC_PWRST_D3;
829 set_pin_power_state(codec, 0x29, &parm);
830 set_pin_power_state(codec, 0x2a, &parm);
831 set_pin_power_state(codec, 0x2b, &parm);
832 if (imux_is_smixer)
833 parm = AC_PWRST_D0;
834 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
835 snd_hda_codec_write(codec, 0x1e, 0,
836 AC_VERB_SET_POWER_STATE, parm);
837 snd_hda_codec_write(codec, 0x1f, 0,
838 AC_VERB_SET_POWER_STATE, parm);
839 snd_hda_codec_write(codec, 0x10, 0,
840 AC_VERB_SET_POWER_STATE, parm);
841 snd_hda_codec_write(codec, 0x11, 0,
842 AC_VERB_SET_POWER_STATE, parm);
843
844 /* outputs */
845 /* AOW0 (8h)*/
846 snd_hda_codec_write(codec, 0x8, 0,
847 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
848
849 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
850 parm = AC_PWRST_D3;
851 set_pin_power_state(codec, 0x26, &parm);
852 snd_hda_codec_write(codec, 0x1c, 0,
853 AC_VERB_SET_POWER_STATE, parm);
854 snd_hda_codec_write(codec, 0x37,
855 0, AC_VERB_SET_POWER_STATE, parm);
856
857 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
858 parm = AC_PWRST_D3;
859 set_pin_power_state(codec, 0x25, &parm);
860 snd_hda_codec_write(codec, 0x19, 0,
861 AC_VERB_SET_POWER_STATE, parm);
862 snd_hda_codec_write(codec, 0x35, 0,
863 AC_VERB_SET_POWER_STATE, parm);
864 if (spec->hp_independent_mode) {
865 snd_hda_codec_write(codec, 0x9, 0,
866 AC_VERB_SET_POWER_STATE, parm);
867 }
868
869 /* Class-D */
870 /* PW0 (24h), MW0(18h), MUX0(34h) */
871 present = snd_hda_jack_detect(codec, 0x25);
872 parm = AC_PWRST_D3;
873 set_pin_power_state(codec, 0x24, &parm);
874 if (present) {
875 snd_hda_codec_write(
876 codec, 0x18, 0,
877 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
878 snd_hda_codec_write(
879 codec, 0x34, 0,
880 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
881 } else {
882 snd_hda_codec_write(
883 codec, 0x18, 0,
884 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
885 snd_hda_codec_write(
886 codec, 0x34, 0,
887 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
888 }
889
890 /* Mono Out */
891 /* PW15 (31h), MW8(17h), MUX8(3bh) */
892 present = snd_hda_jack_detect(codec, 0x26);
893 parm = AC_PWRST_D3;
894 set_pin_power_state(codec, 0x31, &parm);
895 if (present) {
896 snd_hda_codec_write(
897 codec, 0x17, 0,
898 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
899 snd_hda_codec_write(
900 codec, 0x3b, 0,
901 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
902 } else {
903 snd_hda_codec_write(
904 codec, 0x17, 0,
905 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
906 snd_hda_codec_write(
907 codec, 0x3b, 0,
908 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
909 }
910
911 /* MW9 (21h) */
912 if (imux_is_smixer || !is_aa_path_mute(codec))
913 snd_hda_codec_write(
914 codec, 0x21, 0,
915 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
916 else
917 snd_hda_codec_write(
918 codec, 0x21, 0,
919 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
920 } else if (spec->codec_type == VT1812) {
921 unsigned int present;
922 /* MUX10 (1eh) = stereo mixer */
923 imux_is_smixer = snd_hda_codec_read(
924 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
925 /* inputs */
926 /* PW 5/6/7 (29h/2ah/2bh) */
927 parm = AC_PWRST_D3;
928 set_pin_power_state(codec, 0x29, &parm);
929 set_pin_power_state(codec, 0x2a, &parm);
930 set_pin_power_state(codec, 0x2b, &parm);
931 if (imux_is_smixer)
932 parm = AC_PWRST_D0;
933 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
934 snd_hda_codec_write(codec, 0x1e, 0,
935 AC_VERB_SET_POWER_STATE, parm);
936 snd_hda_codec_write(codec, 0x1f, 0,
937 AC_VERB_SET_POWER_STATE, parm);
938 snd_hda_codec_write(codec, 0x10, 0,
939 AC_VERB_SET_POWER_STATE, parm);
940 snd_hda_codec_write(codec, 0x11, 0,
941 AC_VERB_SET_POWER_STATE, parm);
942
943 /* outputs */
944 /* AOW0 (8h)*/
945 snd_hda_codec_write(codec, 0x8, 0,
946 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
947
948 /* PW4 (28h), MW4 (18h), MUX4(38h) */
949 parm = AC_PWRST_D3;
950 set_pin_power_state(codec, 0x28, &parm);
951 snd_hda_codec_write(codec, 0x18, 0,
952 AC_VERB_SET_POWER_STATE, parm);
953 snd_hda_codec_write(codec, 0x38, 0,
954 AC_VERB_SET_POWER_STATE, parm);
955
956 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
957 parm = AC_PWRST_D3;
958 set_pin_power_state(codec, 0x25, &parm);
959 snd_hda_codec_write(codec, 0x15, 0,
960 AC_VERB_SET_POWER_STATE, parm);
961 snd_hda_codec_write(codec, 0x35, 0,
962 AC_VERB_SET_POWER_STATE, parm);
963 if (spec->hp_independent_mode) {
964 snd_hda_codec_write(codec, 0x9, 0,
965 AC_VERB_SET_POWER_STATE, parm);
966 }
967
968 /* Internal Speaker */
969 /* PW0 (24h), MW0(14h), MUX0(34h) */
970 present = snd_hda_jack_detect(codec, 0x25);
971 parm = AC_PWRST_D3;
972 set_pin_power_state(codec, 0x24, &parm);
973 if (present) {
974 snd_hda_codec_write(codec, 0x14, 0,
975 AC_VERB_SET_POWER_STATE,
976 AC_PWRST_D3);
977 snd_hda_codec_write(codec, 0x34, 0,
978 AC_VERB_SET_POWER_STATE,
979 AC_PWRST_D3);
980 } else {
981 snd_hda_codec_write(codec, 0x14, 0,
982 AC_VERB_SET_POWER_STATE,
983 AC_PWRST_D0);
984 snd_hda_codec_write(codec, 0x34, 0,
985 AC_VERB_SET_POWER_STATE,
986 AC_PWRST_D0);
987 }
988 /* Mono Out */
989 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
990 present = snd_hda_jack_detect(codec, 0x28);
991 parm = AC_PWRST_D3;
992 set_pin_power_state(codec, 0x31, &parm);
993 if (present) {
994 snd_hda_codec_write(codec, 0x1c, 0,
995 AC_VERB_SET_POWER_STATE,
996 AC_PWRST_D3);
997 snd_hda_codec_write(codec, 0x3c, 0,
998 AC_VERB_SET_POWER_STATE,
999 AC_PWRST_D3);
1000 snd_hda_codec_write(codec, 0x3e, 0,
1001 AC_VERB_SET_POWER_STATE,
1002 AC_PWRST_D3);
1003 } else {
1004 snd_hda_codec_write(codec, 0x1c, 0,
1005 AC_VERB_SET_POWER_STATE,
1006 AC_PWRST_D0);
1007 snd_hda_codec_write(codec, 0x3c, 0,
1008 AC_VERB_SET_POWER_STATE,
1009 AC_PWRST_D0);
1010 snd_hda_codec_write(codec, 0x3e, 0,
1011 AC_VERB_SET_POWER_STATE,
1012 AC_PWRST_D0);
1013 }
1014
1015 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1016 parm = AC_PWRST_D3;
1017 set_pin_power_state(codec, 0x33, &parm);
1018 snd_hda_codec_write(codec, 0x1d, 0,
1019 AC_VERB_SET_POWER_STATE, parm);
1020 snd_hda_codec_write(codec, 0x3d, 0,
1021 AC_VERB_SET_POWER_STATE, parm);
1022
1023 /* MW9 (21h) */
1024 if (imux_is_smixer || !is_aa_path_mute(codec))
1025 snd_hda_codec_write(
1026 codec, 0x21, 0,
1027 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1028 else
1029 snd_hda_codec_write(
1030 codec, 0x21, 0,
1031 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1032 }
1033}
1034
367/* 1035/*
368 * input MUX handling 1036 * input MUX handling
369 */ 1037 */
@@ -395,6 +1063,14 @@ static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
395 1063
396 if (!spec->mux_nids[adc_idx]) 1064 if (!spec->mux_nids[adc_idx])
397 return -EINVAL; 1065 return -EINVAL;
1066 /* switch to D0 beofre change index */
1067 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1068 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1069 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1070 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1071 /* update jack power state */
1072 set_jack_power_state(codec);
1073
398 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 1074 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
399 spec->mux_nids[adc_idx], 1075 spec->mux_nids[adc_idx],
400 &spec->cur_mux[adc_idx]); 1076 &spec->cur_mux[adc_idx]);
@@ -413,16 +1089,74 @@ static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
413{ 1089{
414 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1090 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
415 struct via_spec *spec = codec->spec; 1091 struct via_spec *spec = codec->spec;
416 hda_nid_t nid = spec->autocfg.hp_pins[0]; 1092 hda_nid_t nid;
417 unsigned int pinsel = snd_hda_codec_read(codec, nid, 0, 1093 unsigned int pinsel;
418 AC_VERB_GET_CONNECT_SEL, 1094
419 0x00); 1095 switch (spec->codec_type) {
420 1096 case VT1718S:
1097 nid = 0x34;
1098 break;
1099 case VT2002P:
1100 nid = 0x35;
1101 break;
1102 case VT1812:
1103 nid = 0x3d;
1104 break;
1105 default:
1106 nid = spec->autocfg.hp_pins[0];
1107 break;
1108 }
1109 /* use !! to translate conn sel 2 for VT1718S */
1110 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1111 AC_VERB_GET_CONNECT_SEL,
1112 0x00);
421 ucontrol->value.enumerated.item[0] = pinsel; 1113 ucontrol->value.enumerated.item[0] = pinsel;
422 1114
423 return 0; 1115 return 0;
424} 1116}
425 1117
1118static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1119{
1120 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1121 if (ctl) {
1122 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1123 ctl->vd[0].access |= active
1124 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1125 snd_ctl_notify(codec->bus->card,
1126 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1127 }
1128}
1129
1130static int update_side_mute_status(struct hda_codec *codec)
1131{
1132 /* mute side channel */
1133 struct via_spec *spec = codec->spec;
1134 unsigned int parm = spec->hp_independent_mode
1135 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1136 hda_nid_t sw3;
1137
1138 switch (spec->codec_type) {
1139 case VT1708:
1140 sw3 = 0x1b;
1141 break;
1142 case VT1709_10CH:
1143 sw3 = 0x29;
1144 break;
1145 case VT1708B_8CH:
1146 case VT1708S:
1147 sw3 = 0x27;
1148 break;
1149 default:
1150 sw3 = 0;
1151 break;
1152 }
1153
1154 if (sw3)
1155 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1156 parm);
1157 return 0;
1158}
1159
426static int via_independent_hp_put(struct snd_kcontrol *kcontrol, 1160static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
427 struct snd_ctl_elem_value *ucontrol) 1161 struct snd_ctl_elem_value *ucontrol)
428{ 1162{
@@ -430,47 +1164,46 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
430 struct via_spec *spec = codec->spec; 1164 struct via_spec *spec = codec->spec;
431 hda_nid_t nid = spec->autocfg.hp_pins[0]; 1165 hda_nid_t nid = spec->autocfg.hp_pins[0];
432 unsigned int pinsel = ucontrol->value.enumerated.item[0]; 1166 unsigned int pinsel = ucontrol->value.enumerated.item[0];
433 unsigned int con_nid = snd_hda_codec_read(codec, nid, 0, 1167 /* Get Independent Mode index of headphone pin widget */
434 AC_VERB_GET_CONNECT_LIST, 0) & 0xff; 1168 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
435 1169 ? 1 : 0;
436 if (con_nid == spec->multiout.hp_nid) { 1170
437 if (pinsel == 0) { 1171 switch (spec->codec_type) {
438 if (!spec->hp_independent_mode) { 1172 case VT1718S:
439 if (spec->multiout.num_dacs > 1) 1173 nid = 0x34;
440 spec->multiout.num_dacs -= 1; 1174 pinsel = pinsel ? 2 : 0; /* indep HP use AOW4 (index 2) */
441 spec->hp_independent_mode = 1; 1175 spec->multiout.num_dacs = 4;
442 } 1176 break;
443 } else if (pinsel == 1) { 1177 case VT2002P:
444 if (spec->hp_independent_mode) { 1178 nid = 0x35;
445 if (spec->multiout.num_dacs > 1) 1179 break;
446 spec->multiout.num_dacs += 1; 1180 case VT1812:
447 spec->hp_independent_mode = 0; 1181 nid = 0x3d;
448 } 1182 break;
449 } 1183 default:
450 } else { 1184 nid = spec->autocfg.hp_pins[0];
451 if (pinsel == 0) { 1185 break;
452 if (spec->hp_independent_mode) { 1186 }
453 if (spec->multiout.num_dacs > 1) 1187 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
454 spec->multiout.num_dacs += 1; 1188
455 spec->hp_independent_mode = 0; 1189 if (spec->multiout.hp_nid && spec->multiout.hp_nid
456 } 1190 != spec->multiout.dac_nids[HDA_FRONT])
457 } else if (pinsel == 1) { 1191 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
458 if (!spec->hp_independent_mode) { 1192 0, 0, 0);
459 if (spec->multiout.num_dacs > 1) 1193
460 spec->multiout.num_dacs -= 1; 1194 update_side_mute_status(codec);
461 spec->hp_independent_mode = 1; 1195 /* update HP volume/swtich active state */
462 } 1196 if (spec->codec_type == VT1708S
463 } 1197 || spec->codec_type == VT1702
1198 || spec->codec_type == VT1718S
1199 || spec->codec_type == VT1716S
1200 || spec->codec_type == VT2002P
1201 || spec->codec_type == VT1812) {
1202 activate_ctl(codec, "Headphone Playback Volume",
1203 spec->hp_independent_mode);
1204 activate_ctl(codec, "Headphone Playback Switch",
1205 spec->hp_independent_mode);
464 } 1206 }
465 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
466 pinsel);
467
468 if (spec->multiout.hp_nid &&
469 spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
470 snd_hda_codec_setup_stream(codec,
471 spec->multiout.hp_nid,
472 0, 0, 0);
473
474 return 0; 1207 return 0;
475} 1208}
476 1209
@@ -486,6 +1219,175 @@ static struct snd_kcontrol_new via_hp_mixer[] = {
486 { } /* end */ 1219 { } /* end */
487}; 1220};
488 1221
1222static void notify_aa_path_ctls(struct hda_codec *codec)
1223{
1224 int i;
1225 struct snd_ctl_elem_id id;
1226 const char *labels[] = {"Mic", "Front Mic", "Line"};
1227
1228 memset(&id, 0, sizeof(id));
1229 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1230 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1231 sprintf(id.name, "%s Playback Volume", labels[i]);
1232 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1233 &id);
1234 }
1235}
1236
1237static void mute_aa_path(struct hda_codec *codec, int mute)
1238{
1239 struct via_spec *spec = codec->spec;
1240 hda_nid_t nid_mixer;
1241 int start_idx;
1242 int end_idx;
1243 int i;
1244 /* get nid of MW0 and start & end index */
1245 switch (spec->codec_type) {
1246 case VT1708:
1247 nid_mixer = 0x17;
1248 start_idx = 2;
1249 end_idx = 4;
1250 break;
1251 case VT1709_10CH:
1252 case VT1709_6CH:
1253 nid_mixer = 0x18;
1254 start_idx = 2;
1255 end_idx = 4;
1256 break;
1257 case VT1708B_8CH:
1258 case VT1708B_4CH:
1259 case VT1708S:
1260 case VT1716S:
1261 nid_mixer = 0x16;
1262 start_idx = 2;
1263 end_idx = 4;
1264 break;
1265 default:
1266 return;
1267 }
1268 /* check AA path's mute status */
1269 for (i = start_idx; i <= end_idx; i++) {
1270 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1271 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1272 HDA_AMP_MUTE, val);
1273 }
1274}
1275static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1276{
1277 int res = 0;
1278 int index;
1279 for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
1280 if (pin == spec->autocfg.input_pins[index]) {
1281 res = 1;
1282 break;
1283 }
1284 }
1285 return res;
1286}
1287
1288static int via_smart51_info(struct snd_kcontrol *kcontrol,
1289 struct snd_ctl_elem_info *uinfo)
1290{
1291 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1292 uinfo->count = 1;
1293 uinfo->value.integer.min = 0;
1294 uinfo->value.integer.max = 1;
1295 return 0;
1296}
1297
1298static int via_smart51_get(struct snd_kcontrol *kcontrol,
1299 struct snd_ctl_elem_value *ucontrol)
1300{
1301 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1302 struct via_spec *spec = codec->spec;
1303 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1304 int on = 1;
1305 int i;
1306
1307 for (i = 0; i < ARRAY_SIZE(index); i++) {
1308 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1309 if (nid) {
1310 int ctl =
1311 snd_hda_codec_read(codec, nid, 0,
1312 AC_VERB_GET_PIN_WIDGET_CONTROL,
1313 0);
1314 if (i == AUTO_PIN_FRONT_MIC
1315 && spec->hp_independent_mode
1316 && spec->codec_type != VT1718S)
1317 continue; /* ignore FMic for independent HP */
1318 if (ctl & AC_PINCTL_IN_EN
1319 && !(ctl & AC_PINCTL_OUT_EN))
1320 on = 0;
1321 }
1322 }
1323 *ucontrol->value.integer.value = on;
1324 return 0;
1325}
1326
1327static int via_smart51_put(struct snd_kcontrol *kcontrol,
1328 struct snd_ctl_elem_value *ucontrol)
1329{
1330 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1331 struct via_spec *spec = codec->spec;
1332 int out_in = *ucontrol->value.integer.value
1333 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1334 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1335 int i;
1336
1337 for (i = 0; i < ARRAY_SIZE(index); i++) {
1338 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1339 if (i == AUTO_PIN_FRONT_MIC
1340 && spec->hp_independent_mode
1341 && spec->codec_type != VT1718S)
1342 continue; /* don't retask FMic for independent HP */
1343 if (nid) {
1344 unsigned int parm = snd_hda_codec_read(
1345 codec, nid, 0,
1346 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1347 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1348 parm |= out_in;
1349 snd_hda_codec_write(codec, nid, 0,
1350 AC_VERB_SET_PIN_WIDGET_CONTROL,
1351 parm);
1352 if (out_in == AC_PINCTL_OUT_EN) {
1353 mute_aa_path(codec, 1);
1354 notify_aa_path_ctls(codec);
1355 }
1356 if (spec->codec_type == VT1718S)
1357 snd_hda_codec_amp_stereo(
1358 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1359 HDA_AMP_UNMUTE);
1360 }
1361 if (i == AUTO_PIN_FRONT_MIC) {
1362 if (spec->codec_type == VT1708S
1363 || spec->codec_type == VT1716S) {
1364 /* input = index 1 (AOW3) */
1365 snd_hda_codec_write(
1366 codec, nid, 0,
1367 AC_VERB_SET_CONNECT_SEL, 1);
1368 snd_hda_codec_amp_stereo(
1369 codec, nid, HDA_OUTPUT,
1370 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1371 }
1372 }
1373 }
1374 spec->smart51_enabled = *ucontrol->value.integer.value;
1375 set_jack_power_state(codec);
1376 return 1;
1377}
1378
1379static struct snd_kcontrol_new via_smart51_mixer[] = {
1380 {
1381 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1382 .name = "Smart 5.1",
1383 .count = 1,
1384 .info = via_smart51_info,
1385 .get = via_smart51_get,
1386 .put = via_smart51_put,
1387 },
1388 {} /* end */
1389};
1390
489/* capture mixer elements */ 1391/* capture mixer elements */
490static struct snd_kcontrol_new vt1708_capture_mixer[] = { 1392static struct snd_kcontrol_new vt1708_capture_mixer[] = {
491 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), 1393 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
@@ -506,6 +1408,112 @@ static struct snd_kcontrol_new vt1708_capture_mixer[] = {
506 }, 1408 },
507 { } /* end */ 1409 { } /* end */
508}; 1410};
1411
1412/* check AA path's mute statue */
1413static int is_aa_path_mute(struct hda_codec *codec)
1414{
1415 int mute = 1;
1416 hda_nid_t nid_mixer;
1417 int start_idx;
1418 int end_idx;
1419 int i;
1420 struct via_spec *spec = codec->spec;
1421 /* get nid of MW0 and start & end index */
1422 switch (spec->codec_type) {
1423 case VT1708B_8CH:
1424 case VT1708B_4CH:
1425 case VT1708S:
1426 case VT1716S:
1427 nid_mixer = 0x16;
1428 start_idx = 2;
1429 end_idx = 4;
1430 break;
1431 case VT1702:
1432 nid_mixer = 0x1a;
1433 start_idx = 1;
1434 end_idx = 3;
1435 break;
1436 case VT1718S:
1437 nid_mixer = 0x21;
1438 start_idx = 1;
1439 end_idx = 3;
1440 break;
1441 case VT2002P:
1442 case VT1812:
1443 nid_mixer = 0x21;
1444 start_idx = 0;
1445 end_idx = 2;
1446 break;
1447 default:
1448 return 0;
1449 }
1450 /* check AA path's mute status */
1451 for (i = start_idx; i <= end_idx; i++) {
1452 unsigned int con_list = snd_hda_codec_read(
1453 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1454 int shift = 8 * (i % 4);
1455 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1456 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1457 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1458 /* check mute status while the pin is connected */
1459 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1460 HDA_INPUT, i) >> 7;
1461 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1462 HDA_INPUT, i) >> 7;
1463 if (!mute_l || !mute_r) {
1464 mute = 0;
1465 break;
1466 }
1467 }
1468 }
1469 return mute;
1470}
1471
1472/* enter/exit analog low-current mode */
1473static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1474{
1475 struct via_spec *spec = codec->spec;
1476 static int saved_stream_idle = 1; /* saved stream idle status */
1477 int enable = is_aa_path_mute(codec);
1478 unsigned int verb = 0;
1479 unsigned int parm = 0;
1480
1481 if (stream_idle == -1) /* stream status did not change */
1482 enable = enable && saved_stream_idle;
1483 else {
1484 enable = enable && stream_idle;
1485 saved_stream_idle = stream_idle;
1486 }
1487
1488 /* decide low current mode's verb & parameter */
1489 switch (spec->codec_type) {
1490 case VT1708B_8CH:
1491 case VT1708B_4CH:
1492 verb = 0xf70;
1493 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1494 break;
1495 case VT1708S:
1496 case VT1718S:
1497 case VT1716S:
1498 verb = 0xf73;
1499 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1500 break;
1501 case VT1702:
1502 verb = 0xf73;
1503 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1504 break;
1505 case VT2002P:
1506 case VT1812:
1507 verb = 0xf93;
1508 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1509 break;
1510 default:
1511 return; /* other codecs are not supported */
1512 }
1513 /* send verb */
1514 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1515}
1516
509/* 1517/*
510 * generic initialization of ADC, input mixers and output mixers 1518 * generic initialization of ADC, input mixers and output mixers
511 */ 1519 */
@@ -534,9 +1542,9 @@ static struct hda_verb vt1708_volume_init_verbs[] = {
534 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 1542 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
535 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 1543 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
536 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 1544 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
537 1545
538 /* Setup default input to PW4 */ 1546 /* Setup default input MW0 to PW4 */
539 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1}, 1547 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
540 /* PW9 Output enable */ 1548 /* PW9 Output enable */
541 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 1549 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
542 { } 1550 { }
@@ -547,30 +1555,13 @@ static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
547 struct snd_pcm_substream *substream) 1555 struct snd_pcm_substream *substream)
548{ 1556{
549 struct via_spec *spec = codec->spec; 1557 struct via_spec *spec = codec->spec;
1558 int idle = substream->pstr->substream_opened == 1
1559 && substream->ref_count == 0;
1560 analog_low_current_mode(codec, idle);
550 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1561 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
551 hinfo); 1562 hinfo);
552} 1563}
553 1564
554static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
555 struct hda_codec *codec,
556 unsigned int stream_tag,
557 unsigned int format,
558 struct snd_pcm_substream *substream)
559{
560 struct via_spec *spec = codec->spec;
561 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
562 stream_tag, format, substream);
563}
564
565static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
566 struct hda_codec *codec,
567 struct snd_pcm_substream *substream)
568{
569 struct via_spec *spec = codec->spec;
570 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
571}
572
573
574static void playback_multi_pcm_prep_0(struct hda_codec *codec, 1565static void playback_multi_pcm_prep_0(struct hda_codec *codec,
575 unsigned int stream_tag, 1566 unsigned int stream_tag,
576 unsigned int format, 1567 unsigned int format,
@@ -615,8 +1606,8 @@ static void playback_multi_pcm_prep_0(struct hda_codec *codec,
615 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, 1606 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
616 0, format); 1607 0, format);
617 1608
618 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && 1609 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
619 !spec->hp_independent_mode) 1610 && !spec->hp_independent_mode)
620 /* headphone out will just decode front left/right (stereo) */ 1611 /* headphone out will just decode front left/right (stereo) */
621 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 1612 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
622 0, format); 1613 0, format);
@@ -658,7 +1649,7 @@ static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
658 snd_hda_codec_setup_stream(codec, mout->hp_nid, 1649 snd_hda_codec_setup_stream(codec, mout->hp_nid,
659 stream_tag, 0, format); 1650 stream_tag, 0, format);
660 } 1651 }
661 1652 vt1708_start_hp_work(spec);
662 return 0; 1653 return 0;
663} 1654}
664 1655
@@ -698,7 +1689,7 @@ static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
698 snd_hda_codec_setup_stream(codec, mout->hp_nid, 1689 snd_hda_codec_setup_stream(codec, mout->hp_nid,
699 0, 0, 0); 1690 0, 0, 0);
700 } 1691 }
701 1692 vt1708_stop_hp_work(spec);
702 return 0; 1693 return 0;
703} 1694}
704 1695
@@ -779,7 +1770,7 @@ static struct hda_pcm_stream vt1708_pcm_analog_playback = {
779}; 1770};
780 1771
781static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { 1772static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
782 .substreams = 1, 1773 .substreams = 2,
783 .channels_min = 2, 1774 .channels_min = 2,
784 .channels_max = 8, 1775 .channels_max = 8,
785 .nid = 0x10, /* NID to query formats and rates */ 1776 .nid = 0x10, /* NID to query formats and rates */
@@ -790,8 +1781,8 @@ static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
790 .formats = SNDRV_PCM_FMTBIT_S16_LE, 1781 .formats = SNDRV_PCM_FMTBIT_S16_LE,
791 .ops = { 1782 .ops = {
792 .open = via_playback_pcm_open, 1783 .open = via_playback_pcm_open,
793 .prepare = via_playback_pcm_prepare, 1784 .prepare = via_playback_multi_pcm_prepare,
794 .cleanup = via_playback_pcm_cleanup 1785 .cleanup = via_playback_multi_pcm_cleanup
795 }, 1786 },
796}; 1787};
797 1788
@@ -853,6 +1844,11 @@ static int via_build_controls(struct hda_codec *codec)
853 if (err < 0) 1844 if (err < 0)
854 return err; 1845 return err;
855 } 1846 }
1847
1848 /* init power states */
1849 set_jack_power_state(codec);
1850 analog_low_current_mode(codec, 1);
1851
856 via_free_kctls(codec); /* no longer needed */ 1852 via_free_kctls(codec); /* no longer needed */
857 return 0; 1853 return 0;
858} 1854}
@@ -866,8 +1862,10 @@ static int via_build_pcms(struct hda_codec *codec)
866 codec->pcm_info = info; 1862 codec->pcm_info = info;
867 1863
868 info->name = spec->stream_name_analog; 1864 info->name = spec->stream_name_analog;
869 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback); 1865 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
870 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; 1866 *(spec->stream_analog_playback);
1867 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1868 spec->multiout.dac_nids[0];
871 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); 1869 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
872 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 1870 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
873 1871
@@ -904,20 +1902,58 @@ static void via_free(struct hda_codec *codec)
904 return; 1902 return;
905 1903
906 via_free_kctls(codec); 1904 via_free_kctls(codec);
1905 vt1708_stop_hp_work(spec);
907 kfree(codec->spec); 1906 kfree(codec->spec);
908} 1907}
909 1908
910/* mute internal speaker if HP is plugged */ 1909/* mute internal speaker if HP is plugged */
911static void via_hp_automute(struct hda_codec *codec) 1910static void via_hp_automute(struct hda_codec *codec)
912{ 1911{
913 unsigned int present; 1912 unsigned int present = 0;
914 struct via_spec *spec = codec->spec; 1913 struct via_spec *spec = codec->spec;
915 1914
916 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0, 1915 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
917 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1916
918 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0], 1917 if (!spec->hp_independent_mode) {
919 HDA_OUTPUT, 0, HDA_AMP_MUTE, 1918 struct snd_ctl_elem_id id;
920 present ? HDA_AMP_MUTE : 0); 1919 /* auto mute */
1920 snd_hda_codec_amp_stereo(
1921 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1922 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1923 /* notify change */
1924 memset(&id, 0, sizeof(id));
1925 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1926 strcpy(id.name, "Front Playback Switch");
1927 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1928 &id);
1929 }
1930}
1931
1932/* mute mono out if HP or Line out is plugged */
1933static void via_mono_automute(struct hda_codec *codec)
1934{
1935 unsigned int hp_present, lineout_present;
1936 struct via_spec *spec = codec->spec;
1937
1938 if (spec->codec_type != VT1716S)
1939 return;
1940
1941 lineout_present = snd_hda_jack_detect(codec,
1942 spec->autocfg.line_out_pins[0]);
1943
1944 /* Mute Mono Out if Line Out is plugged */
1945 if (lineout_present) {
1946 snd_hda_codec_amp_stereo(
1947 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1948 return;
1949 }
1950
1951 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1952
1953 if (!spec->hp_independent_mode)
1954 snd_hda_codec_amp_stereo(
1955 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1956 hp_present ? HDA_AMP_MUTE : 0);
921} 1957}
922 1958
923static void via_gpio_control(struct hda_codec *codec) 1959static void via_gpio_control(struct hda_codec *codec)
@@ -968,15 +2004,83 @@ static void via_gpio_control(struct hda_codec *codec)
968 } 2004 }
969} 2005}
970 2006
2007/* mute Internal-Speaker if HP is plugged */
2008static void via_speaker_automute(struct hda_codec *codec)
2009{
2010 unsigned int hp_present;
2011 struct via_spec *spec = codec->spec;
2012
2013 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2014 return;
2015
2016 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2017
2018 if (!spec->hp_independent_mode) {
2019 struct snd_ctl_elem_id id;
2020 snd_hda_codec_amp_stereo(
2021 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2022 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2023 /* notify change */
2024 memset(&id, 0, sizeof(id));
2025 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2026 strcpy(id.name, "Speaker Playback Switch");
2027 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2028 &id);
2029 }
2030}
2031
2032/* mute line-out and internal speaker if HP is plugged */
2033static void via_hp_bind_automute(struct hda_codec *codec)
2034{
2035 /* use long instead of int below just to avoid an internal compiler
2036 * error with gcc 4.0.x
2037 */
2038 unsigned long hp_present, present = 0;
2039 struct via_spec *spec = codec->spec;
2040 int i;
2041
2042 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2043 return;
2044
2045 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2046
2047 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2048
2049 if (!spec->hp_independent_mode) {
2050 /* Mute Line-Outs */
2051 for (i = 0; i < spec->autocfg.line_outs; i++)
2052 snd_hda_codec_amp_stereo(
2053 codec, spec->autocfg.line_out_pins[i],
2054 HDA_OUTPUT, 0,
2055 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2056 if (hp_present)
2057 present = hp_present;
2058 }
2059 /* Speakers */
2060 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2061 snd_hda_codec_amp_stereo(
2062 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2063 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2064}
2065
2066
971/* unsolicited event for jack sensing */ 2067/* unsolicited event for jack sensing */
972static void via_unsol_event(struct hda_codec *codec, 2068static void via_unsol_event(struct hda_codec *codec,
973 unsigned int res) 2069 unsigned int res)
974{ 2070{
975 res >>= 26; 2071 res >>= 26;
976 if (res == VIA_HP_EVENT) 2072 if (res & VIA_HP_EVENT)
977 via_hp_automute(codec); 2073 via_hp_automute(codec);
978 else if (res == VIA_GPIO_EVENT) 2074 if (res & VIA_GPIO_EVENT)
979 via_gpio_control(codec); 2075 via_gpio_control(codec);
2076 if (res & VIA_JACK_EVENT)
2077 set_jack_power_state(codec);
2078 if (res & VIA_MONO_EVENT)
2079 via_mono_automute(codec);
2080 if (res & VIA_SPEAKER_EVENT)
2081 via_speaker_automute(codec);
2082 if (res & VIA_BIND_HP_EVENT)
2083 via_hp_bind_automute(codec);
980} 2084}
981 2085
982static int via_init(struct hda_codec *codec) 2086static int via_init(struct hda_codec *codec)
@@ -986,6 +2090,10 @@ static int via_init(struct hda_codec *codec)
986 for (i = 0; i < spec->num_iverbs; i++) 2090 for (i = 0; i < spec->num_iverbs; i++)
987 snd_hda_sequence_write(codec, spec->init_verbs[i]); 2091 snd_hda_sequence_write(codec, spec->init_verbs[i]);
988 2092
2093 spec->codec_type = get_codec_type(codec);
2094 if (spec->codec_type == VT1708BCE)
2095 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2096 same */
989 /* Lydia Add for EAPD enable */ 2097 /* Lydia Add for EAPD enable */
990 if (!spec->dig_in_nid) { /* No Digital In connection */ 2098 if (!spec->dig_in_nid) { /* No Digital In connection */
991 if (spec->dig_in_pin) { 2099 if (spec->dig_in_pin) {
@@ -1003,8 +2111,17 @@ static int via_init(struct hda_codec *codec)
1003 if (spec->slave_dig_outs[0]) 2111 if (spec->slave_dig_outs[0])
1004 codec->slave_dig_outs = spec->slave_dig_outs; 2112 codec->slave_dig_outs = spec->slave_dig_outs;
1005 2113
1006 return 0; 2114 return 0;
2115}
2116
2117#ifdef SND_HDA_NEEDS_RESUME
2118static int via_suspend(struct hda_codec *codec, pm_message_t state)
2119{
2120 struct via_spec *spec = codec->spec;
2121 vt1708_stop_hp_work(spec);
2122 return 0;
1007} 2123}
2124#endif
1008 2125
1009#ifdef CONFIG_SND_HDA_POWER_SAVE 2126#ifdef CONFIG_SND_HDA_POWER_SAVE
1010static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) 2127static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
@@ -1021,6 +2138,9 @@ static struct hda_codec_ops via_patch_ops = {
1021 .build_pcms = via_build_pcms, 2138 .build_pcms = via_build_pcms,
1022 .init = via_init, 2139 .init = via_init,
1023 .free = via_free, 2140 .free = via_free,
2141#ifdef SND_HDA_NEEDS_RESUME
2142 .suspend = via_suspend,
2143#endif
1024#ifdef CONFIG_SND_HDA_POWER_SAVE 2144#ifdef CONFIG_SND_HDA_POWER_SAVE
1025 .check_power_status = via_check_power_status, 2145 .check_power_status = via_check_power_status,
1026#endif 2146#endif
@@ -1036,8 +2156,8 @@ static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1036 spec->multiout.num_dacs = cfg->line_outs; 2156 spec->multiout.num_dacs = cfg->line_outs;
1037 2157
1038 spec->multiout.dac_nids = spec->private_dac_nids; 2158 spec->multiout.dac_nids = spec->private_dac_nids;
1039 2159
1040 for(i = 0; i < 4; i++) { 2160 for (i = 0; i < 4; i++) {
1041 nid = cfg->line_out_pins[i]; 2161 nid = cfg->line_out_pins[i];
1042 if (nid) { 2162 if (nid) {
1043 /* config dac list */ 2163 /* config dac list */
@@ -1067,7 +2187,7 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1067{ 2187{
1068 char name[32]; 2188 char name[32];
1069 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; 2189 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1070 hda_nid_t nid, nid_vol = 0; 2190 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
1071 int i, err; 2191 int i, err;
1072 2192
1073 for (i = 0; i <= AUTO_SEQ_SIDE; i++) { 2193 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
@@ -1075,9 +2195,8 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1075 2195
1076 if (!nid) 2196 if (!nid)
1077 continue; 2197 continue;
1078 2198
1079 if (i != AUTO_SEQ_FRONT) 2199 nid_vol = nid_vols[i];
1080 nid_vol = 0x18 + i;
1081 2200
1082 if (i == AUTO_SEQ_CENLFE) { 2201 if (i == AUTO_SEQ_CENLFE) {
1083 /* Center/LFE */ 2202 /* Center/LFE */
@@ -1105,21 +2224,21 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1105 HDA_OUTPUT)); 2224 HDA_OUTPUT));
1106 if (err < 0) 2225 if (err < 0)
1107 return err; 2226 return err;
1108 } else if (i == AUTO_SEQ_FRONT){ 2227 } else if (i == AUTO_SEQ_FRONT) {
1109 /* add control to mixer index 0 */ 2228 /* add control to mixer index 0 */
1110 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2229 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1111 "Master Front Playback Volume", 2230 "Master Front Playback Volume",
1112 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, 2231 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1113 HDA_INPUT)); 2232 HDA_INPUT));
1114 if (err < 0) 2233 if (err < 0)
1115 return err; 2234 return err;
1116 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2235 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1117 "Master Front Playback Switch", 2236 "Master Front Playback Switch",
1118 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, 2237 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1119 HDA_INPUT)); 2238 HDA_INPUT));
1120 if (err < 0) 2239 if (err < 0)
1121 return err; 2240 return err;
1122 2241
1123 /* add control to PW3 */ 2242 /* add control to PW3 */
1124 sprintf(name, "%s Playback Volume", chname[i]); 2243 sprintf(name, "%s Playback Volume", chname[i]);
1125 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2244 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
@@ -1178,6 +2297,7 @@ static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1178 return 0; 2297 return 0;
1179 2298
1180 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */ 2299 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2300 spec->hp_independent_mode_index = 1;
1181 2301
1182 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2302 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1183 "Headphone Playback Volume", 2303 "Headphone Playback Volume",
@@ -1218,7 +2338,7 @@ static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1218 case 0x1d: /* Mic */ 2338 case 0x1d: /* Mic */
1219 idx = 2; 2339 idx = 2;
1220 break; 2340 break;
1221 2341
1222 case 0x1e: /* Line In */ 2342 case 0x1e: /* Line In */
1223 idx = 3; 2343 idx = 3;
1224 break; 2344 break;
@@ -1231,8 +2351,7 @@ static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1231 idx = 1; 2351 idx = 1;
1232 break; 2352 break;
1233 } 2353 }
1234 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 2354 err = via_new_analog_input(spec, labels[i], idx, 0x17);
1235 idx, 0x17);
1236 if (err < 0) 2355 if (err < 0)
1237 return err; 2356 return err;
1238 imux->items[imux->num_items].label = labels[i]; 2357 imux->items[imux->num_items].label = labels[i];
@@ -1260,16 +2379,60 @@ static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1260 def_conf = snd_hda_codec_get_pincfg(codec, nid); 2379 def_conf = snd_hda_codec_get_pincfg(codec, nid);
1261 seqassoc = (unsigned char) get_defcfg_association(def_conf); 2380 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1262 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); 2381 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1263 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) { 2382 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
1264 if (seqassoc == 0xff) { 2383 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
1265 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); 2384 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1266 snd_hda_codec_set_pincfg(codec, nid, def_conf); 2385 snd_hda_codec_set_pincfg(codec, nid, def_conf);
1267 }
1268 } 2386 }
1269 2387
1270 return; 2388 return;
1271} 2389}
1272 2390
2391static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2392 struct snd_ctl_elem_value *ucontrol)
2393{
2394 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2395 struct via_spec *spec = codec->spec;
2396
2397 if (spec->codec_type != VT1708)
2398 return 0;
2399 spec->vt1708_jack_detectect =
2400 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2401 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2402 return 0;
2403}
2404
2405static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2406 struct snd_ctl_elem_value *ucontrol)
2407{
2408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2409 struct via_spec *spec = codec->spec;
2410 int change;
2411
2412 if (spec->codec_type != VT1708)
2413 return 0;
2414 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2415 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2416 == !spec->vt1708_jack_detectect;
2417 if (spec->vt1708_jack_detectect) {
2418 mute_aa_path(codec, 1);
2419 notify_aa_path_ctls(codec);
2420 }
2421 return change;
2422}
2423
2424static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2425 {
2426 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2427 .name = "Jack Detect",
2428 .count = 1,
2429 .info = snd_ctl_boolean_mono_info,
2430 .get = vt1708_jack_detectect_get,
2431 .put = vt1708_jack_detectect_put,
2432 },
2433 {} /* end */
2434};
2435
1273static int vt1708_parse_auto_config(struct hda_codec *codec) 2436static int vt1708_parse_auto_config(struct hda_codec *codec)
1274{ 2437{
1275 struct via_spec *spec = codec->spec; 2438 struct via_spec *spec = codec->spec;
@@ -1297,6 +2460,10 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
1297 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg); 2460 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1298 if (err < 0) 2461 if (err < 0)
1299 return err; 2462 return err;
2463 /* add jack detect on/off control */
2464 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2465 if (err < 0)
2466 return err;
1300 2467
1301 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 2468 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1302 2469
@@ -1316,19 +2483,44 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
1316 if (spec->hp_mux) 2483 if (spec->hp_mux)
1317 spec->mixers[spec->num_mixers++] = via_hp_mixer; 2484 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1318 2485
2486 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
1319 return 1; 2487 return 1;
1320} 2488}
1321 2489
1322/* init callback for auto-configuration model -- overriding the default init */ 2490/* init callback for auto-configuration model -- overriding the default init */
1323static int via_auto_init(struct hda_codec *codec) 2491static int via_auto_init(struct hda_codec *codec)
1324{ 2492{
2493 struct via_spec *spec = codec->spec;
2494
1325 via_init(codec); 2495 via_init(codec);
1326 via_auto_init_multi_out(codec); 2496 via_auto_init_multi_out(codec);
1327 via_auto_init_hp_out(codec); 2497 via_auto_init_hp_out(codec);
1328 via_auto_init_analog_input(codec); 2498 via_auto_init_analog_input(codec);
2499 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2500 via_hp_bind_automute(codec);
2501 } else {
2502 via_hp_automute(codec);
2503 via_speaker_automute(codec);
2504 }
2505
1329 return 0; 2506 return 0;
1330} 2507}
1331 2508
2509static void vt1708_update_hp_jack_state(struct work_struct *work)
2510{
2511 struct via_spec *spec = container_of(work, struct via_spec,
2512 vt1708_hp_work.work);
2513 if (spec->codec_type != VT1708)
2514 return;
2515 /* if jack state toggled */
2516 if (spec->vt1708_hp_present
2517 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2518 spec->vt1708_hp_present ^= 1;
2519 via_hp_automute(spec->codec);
2520 }
2521 vt1708_start_hp_work(spec);
2522}
2523
1332static int get_mux_nids(struct hda_codec *codec) 2524static int get_mux_nids(struct hda_codec *codec)
1333{ 2525{
1334 struct via_spec *spec = codec->spec; 2526 struct via_spec *spec = codec->spec;
@@ -1378,7 +2570,7 @@ static int patch_vt1708(struct hda_codec *codec)
1378 "from BIOS. Using genenic mode...\n"); 2570 "from BIOS. Using genenic mode...\n");
1379 } 2571 }
1380 2572
1381 2573
1382 spec->stream_name_analog = "VT1708 Analog"; 2574 spec->stream_name_analog = "VT1708 Analog";
1383 spec->stream_analog_playback = &vt1708_pcm_analog_playback; 2575 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
1384 /* disable 32bit format on VT1708 */ 2576 /* disable 32bit format on VT1708 */
@@ -1390,7 +2582,7 @@ static int patch_vt1708(struct hda_codec *codec)
1390 spec->stream_digital_playback = &vt1708_pcm_digital_playback; 2582 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1391 spec->stream_digital_capture = &vt1708_pcm_digital_capture; 2583 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1392 2584
1393 2585
1394 if (!spec->adc_nids && spec->input_mux) { 2586 if (!spec->adc_nids && spec->input_mux) {
1395 spec->adc_nids = vt1708_adc_nids; 2587 spec->adc_nids = vt1708_adc_nids;
1396 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids); 2588 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
@@ -1405,7 +2597,8 @@ static int patch_vt1708(struct hda_codec *codec)
1405#ifdef CONFIG_SND_HDA_POWER_SAVE 2597#ifdef CONFIG_SND_HDA_POWER_SAVE
1406 spec->loopback.amplist = vt1708_loopbacks; 2598 spec->loopback.amplist = vt1708_loopbacks;
1407#endif 2599#endif
1408 2600 spec->codec = codec;
2601 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
1409 return 0; 2602 return 0;
1410} 2603}
1411 2604
@@ -1433,7 +2626,8 @@ static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1433}; 2626};
1434 2627
1435static struct hda_verb vt1709_uniwill_init_verbs[] = { 2628static struct hda_verb vt1709_uniwill_init_verbs[] = {
1436 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 2629 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2630 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
1437 { } 2631 { }
1438}; 2632};
1439 2633
@@ -1473,8 +2667,8 @@ static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1473 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 2667 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1474 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 2668 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1475 2669
1476 /* Set input of PW4 as AOW4 */ 2670 /* Set input of PW4 as MW0 */
1477 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1}, 2671 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1478 /* PW9 Output enable */ 2672 /* PW9 Output enable */
1479 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 2673 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1480 { } 2674 { }
@@ -1487,8 +2681,8 @@ static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1487 .nid = 0x10, /* NID to query formats and rates */ 2681 .nid = 0x10, /* NID to query formats and rates */
1488 .ops = { 2682 .ops = {
1489 .open = via_playback_pcm_open, 2683 .open = via_playback_pcm_open,
1490 .prepare = via_playback_pcm_prepare, 2684 .prepare = via_playback_multi_pcm_prepare,
1491 .cleanup = via_playback_pcm_cleanup 2685 .cleanup = via_playback_multi_pcm_cleanup,
1492 }, 2686 },
1493}; 2687};
1494 2688
@@ -1499,8 +2693,8 @@ static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1499 .nid = 0x10, /* NID to query formats and rates */ 2693 .nid = 0x10, /* NID to query formats and rates */
1500 .ops = { 2694 .ops = {
1501 .open = via_playback_pcm_open, 2695 .open = via_playback_pcm_open,
1502 .prepare = via_playback_pcm_prepare, 2696 .prepare = via_playback_multi_pcm_prepare,
1503 .cleanup = via_playback_pcm_cleanup 2697 .cleanup = via_playback_multi_pcm_cleanup,
1504 }, 2698 },
1505}; 2699};
1506 2700
@@ -1575,11 +2769,11 @@ static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1575 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */ 2769 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1576 2770
1577 } else if (cfg->line_outs == 3) { /* 6 channels */ 2771 } else if (cfg->line_outs == 3) { /* 6 channels */
1578 for(i = 0; i < cfg->line_outs; i++) { 2772 for (i = 0; i < cfg->line_outs; i++) {
1579 nid = cfg->line_out_pins[i]; 2773 nid = cfg->line_out_pins[i];
1580 if (nid) { 2774 if (nid) {
1581 /* config dac list */ 2775 /* config dac list */
1582 switch(i) { 2776 switch (i) {
1583 case AUTO_SEQ_FRONT: 2777 case AUTO_SEQ_FRONT:
1584 /* AOW0 */ 2778 /* AOW0 */
1585 spec->multiout.dac_nids[i] = 0x10; 2779 spec->multiout.dac_nids[i] = 0x10;
@@ -1608,56 +2802,58 @@ static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1608{ 2802{
1609 char name[32]; 2803 char name[32];
1610 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; 2804 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1611 hda_nid_t nid = 0; 2805 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
1612 int i, err; 2806 int i, err;
1613 2807
1614 for (i = 0; i <= AUTO_SEQ_SIDE; i++) { 2808 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1615 nid = cfg->line_out_pins[i]; 2809 nid = cfg->line_out_pins[i];
1616 2810
1617 if (!nid) 2811 if (!nid)
1618 continue; 2812 continue;
1619 2813
2814 nid_vol = nid_vols[i];
2815
1620 if (i == AUTO_SEQ_CENLFE) { 2816 if (i == AUTO_SEQ_CENLFE) {
1621 /* Center/LFE */ 2817 /* Center/LFE */
1622 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2818 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1623 "Center Playback Volume", 2819 "Center Playback Volume",
1624 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, 2820 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1625 HDA_OUTPUT)); 2821 HDA_OUTPUT));
1626 if (err < 0) 2822 if (err < 0)
1627 return err; 2823 return err;
1628 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2824 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1629 "LFE Playback Volume", 2825 "LFE Playback Volume",
1630 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, 2826 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1631 HDA_OUTPUT)); 2827 HDA_OUTPUT));
1632 if (err < 0) 2828 if (err < 0)
1633 return err; 2829 return err;
1634 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2830 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1635 "Center Playback Switch", 2831 "Center Playback Switch",
1636 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, 2832 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1637 HDA_OUTPUT)); 2833 HDA_OUTPUT));
1638 if (err < 0) 2834 if (err < 0)
1639 return err; 2835 return err;
1640 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2836 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1641 "LFE Playback Switch", 2837 "LFE Playback Switch",
1642 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, 2838 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1643 HDA_OUTPUT)); 2839 HDA_OUTPUT));
1644 if (err < 0) 2840 if (err < 0)
1645 return err; 2841 return err;
1646 } else if (i == AUTO_SEQ_FRONT){ 2842 } else if (i == AUTO_SEQ_FRONT) {
1647 /* add control to mixer index 0 */ 2843 /* ADD control to mixer index 0 */
1648 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2844 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1649 "Master Front Playback Volume", 2845 "Master Front Playback Volume",
1650 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, 2846 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1651 HDA_INPUT)); 2847 HDA_INPUT));
1652 if (err < 0) 2848 if (err < 0)
1653 return err; 2849 return err;
1654 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, 2850 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1655 "Master Front Playback Switch", 2851 "Master Front Playback Switch",
1656 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, 2852 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1657 HDA_INPUT)); 2853 HDA_INPUT));
1658 if (err < 0) 2854 if (err < 0)
1659 return err; 2855 return err;
1660 2856
1661 /* add control to PW3 */ 2857 /* add control to PW3 */
1662 sprintf(name, "%s Playback Volume", chname[i]); 2858 sprintf(name, "%s Playback Volume", chname[i]);
1663 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2859 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
@@ -1674,26 +2870,26 @@ static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1674 } else if (i == AUTO_SEQ_SURROUND) { 2870 } else if (i == AUTO_SEQ_SURROUND) {
1675 sprintf(name, "%s Playback Volume", chname[i]); 2871 sprintf(name, "%s Playback Volume", chname[i]);
1676 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2872 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1677 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, 2873 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1678 HDA_OUTPUT)); 2874 HDA_OUTPUT));
1679 if (err < 0) 2875 if (err < 0)
1680 return err; 2876 return err;
1681 sprintf(name, "%s Playback Switch", chname[i]); 2877 sprintf(name, "%s Playback Switch", chname[i]);
1682 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 2878 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1683 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, 2879 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1684 HDA_OUTPUT)); 2880 HDA_OUTPUT));
1685 if (err < 0) 2881 if (err < 0)
1686 return err; 2882 return err;
1687 } else if (i == AUTO_SEQ_SIDE) { 2883 } else if (i == AUTO_SEQ_SIDE) {
1688 sprintf(name, "%s Playback Volume", chname[i]); 2884 sprintf(name, "%s Playback Volume", chname[i]);
1689 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, 2885 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1690 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, 2886 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1691 HDA_OUTPUT)); 2887 HDA_OUTPUT));
1692 if (err < 0) 2888 if (err < 0)
1693 return err; 2889 return err;
1694 sprintf(name, "%s Playback Switch", chname[i]); 2890 sprintf(name, "%s Playback Switch", chname[i]);
1695 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, 2891 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1696 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, 2892 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1697 HDA_OUTPUT)); 2893 HDA_OUTPUT));
1698 if (err < 0) 2894 if (err < 0)
1699 return err; 2895 return err;
@@ -1714,6 +2910,7 @@ static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1714 spec->multiout.hp_nid = VT1709_HP_DAC_NID; 2910 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1715 else if (spec->multiout.num_dacs == 3) /* 6 channels */ 2911 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1716 spec->multiout.hp_nid = 0; 2912 spec->multiout.hp_nid = 0;
2913 spec->hp_independent_mode_index = 1;
1717 2914
1718 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 2915 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1719 "Headphone Playback Volume", 2916 "Headphone Playback Volume",
@@ -1752,7 +2949,7 @@ static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1752 case 0x1d: /* Mic */ 2949 case 0x1d: /* Mic */
1753 idx = 2; 2950 idx = 2;
1754 break; 2951 break;
1755 2952
1756 case 0x1e: /* Line In */ 2953 case 0x1e: /* Line In */
1757 idx = 3; 2954 idx = 3;
1758 break; 2955 break;
@@ -1765,8 +2962,7 @@ static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1765 idx = 1; 2962 idx = 1;
1766 break; 2963 break;
1767 } 2964 }
1768 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 2965 err = via_new_analog_input(spec, labels[i], idx, 0x18);
1769 idx, 0x18);
1770 if (err < 0) 2966 if (err < 0)
1771 return err; 2967 return err;
1772 imux->items[imux->num_items].label = labels[i]; 2968 imux->items[imux->num_items].label = labels[i];
@@ -1816,6 +3012,7 @@ static int vt1709_parse_auto_config(struct hda_codec *codec)
1816 if (spec->hp_mux) 3012 if (spec->hp_mux)
1817 spec->mixers[spec->num_mixers++] = via_hp_mixer; 3013 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1818 3014
3015 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
1819 return 1; 3016 return 1;
1820} 3017}
1821 3018
@@ -1861,7 +3058,7 @@ static int patch_vt1709_10ch(struct hda_codec *codec)
1861 spec->stream_digital_playback = &vt1709_pcm_digital_playback; 3058 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1862 spec->stream_digital_capture = &vt1709_pcm_digital_capture; 3059 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1863 3060
1864 3061
1865 if (!spec->adc_nids && spec->input_mux) { 3062 if (!spec->adc_nids && spec->input_mux) {
1866 spec->adc_nids = vt1709_adc_nids; 3063 spec->adc_nids = vt1709_adc_nids;
1867 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); 3064 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
@@ -1955,7 +3152,7 @@ static int patch_vt1709_6ch(struct hda_codec *codec)
1955 spec->stream_digital_playback = &vt1709_pcm_digital_playback; 3152 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1956 spec->stream_digital_capture = &vt1709_pcm_digital_capture; 3153 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1957 3154
1958 3155
1959 if (!spec->adc_nids && spec->input_mux) { 3156 if (!spec->adc_nids && spec->input_mux) {
1960 spec->adc_nids = vt1709_adc_nids; 3157 spec->adc_nids = vt1709_adc_nids;
1961 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); 3158 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
@@ -2024,7 +3221,7 @@ static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2024 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 3221 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2025 3222
2026 /* Setup default input to PW4 */ 3223 /* Setup default input to PW4 */
2027 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, 3224 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2028 /* PW9 Output enable */ 3225 /* PW9 Output enable */
2029 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 3226 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2030 /* PW10 Input enable */ 3227 /* PW10 Input enable */
@@ -2068,10 +3265,29 @@ static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2068}; 3265};
2069 3266
2070static struct hda_verb vt1708B_uniwill_init_verbs[] = { 3267static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2071 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 3268 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3269 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3270 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3271 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3272 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3273 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3274 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3275 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3276 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2072 { } 3277 { }
2073}; 3278};
2074 3279
3280static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3281 struct hda_codec *codec,
3282 struct snd_pcm_substream *substream)
3283{
3284 int idle = substream->pstr->substream_opened == 1
3285 && substream->ref_count == 0;
3286
3287 analog_low_current_mode(codec, idle);
3288 return 0;
3289}
3290
2075static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { 3291static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2076 .substreams = 2, 3292 .substreams = 2,
2077 .channels_min = 2, 3293 .channels_min = 2,
@@ -2080,7 +3296,8 @@ static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2080 .ops = { 3296 .ops = {
2081 .open = via_playback_pcm_open, 3297 .open = via_playback_pcm_open,
2082 .prepare = via_playback_multi_pcm_prepare, 3298 .prepare = via_playback_multi_pcm_prepare,
2083 .cleanup = via_playback_multi_pcm_cleanup 3299 .cleanup = via_playback_multi_pcm_cleanup,
3300 .close = via_pcm_open_close
2084 }, 3301 },
2085}; 3302};
2086 3303
@@ -2102,8 +3319,10 @@ static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2102 .channels_max = 2, 3319 .channels_max = 2,
2103 .nid = 0x13, /* NID to query formats and rates */ 3320 .nid = 0x13, /* NID to query formats and rates */
2104 .ops = { 3321 .ops = {
3322 .open = via_pcm_open_close,
2105 .prepare = via_capture_pcm_prepare, 3323 .prepare = via_capture_pcm_prepare,
2106 .cleanup = via_capture_pcm_cleanup 3324 .cleanup = via_capture_pcm_cleanup,
3325 .close = via_pcm_open_close
2107 }, 3326 },
2108}; 3327};
2109 3328
@@ -2260,6 +3479,7 @@ static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2260 return 0; 3479 return 0;
2261 3480
2262 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */ 3481 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3482 spec->hp_independent_mode_index = 1;
2263 3483
2264 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 3484 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2265 "Headphone Playback Volume", 3485 "Headphone Playback Volume",
@@ -2313,8 +3533,7 @@ static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2313 idx = 1; 3533 idx = 1;
2314 break; 3534 break;
2315 } 3535 }
2316 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 3536 err = via_new_analog_input(spec, labels[i], idx, 0x16);
2317 idx, 0x16);
2318 if (err < 0) 3537 if (err < 0)
2319 return err; 3538 return err;
2320 imux->items[imux->num_items].label = labels[i]; 3539 imux->items[imux->num_items].label = labels[i];
@@ -2364,6 +3583,7 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec)
2364 if (spec->hp_mux) 3583 if (spec->hp_mux)
2365 spec->mixers[spec->num_mixers++] = via_hp_mixer; 3584 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2366 3585
3586 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2367 return 1; 3587 return 1;
2368} 3588}
2369 3589
@@ -2376,12 +3596,14 @@ static struct hda_amp_list vt1708B_loopbacks[] = {
2376 { } /* end */ 3596 { } /* end */
2377}; 3597};
2378#endif 3598#endif
2379 3599static int patch_vt1708S(struct hda_codec *codec);
2380static int patch_vt1708B_8ch(struct hda_codec *codec) 3600static int patch_vt1708B_8ch(struct hda_codec *codec)
2381{ 3601{
2382 struct via_spec *spec; 3602 struct via_spec *spec;
2383 int err; 3603 int err;
2384 3604
3605 if (get_codec_type(codec) == VT1708BCE)
3606 return patch_vt1708S(codec);
2385 /* create a codec specific record */ 3607 /* create a codec specific record */
2386 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3608 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2387 if (spec == NULL) 3609 if (spec == NULL)
@@ -2483,29 +3705,15 @@ static int patch_vt1708B_4ch(struct hda_codec *codec)
2483 3705
2484/* Patch for VT1708S */ 3706/* Patch for VT1708S */
2485 3707
2486/* VT1708S software backdoor based override for buggy hardware micboost
2487 * setting */
2488#define MIC_BOOST_VOLUME(xname, nid) { \
2489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2490 .name = xname, \
2491 .index = 0, \
2492 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2493 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2494 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2495 .info = mic_boost_volume_info, \
2496 .get = snd_hda_mixer_amp_volume_get, \
2497 .put = snd_hda_mixer_amp_volume_put, \
2498 .tlv = { .c = mic_boost_tlv }, \
2499 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2500
2501/* capture mixer elements */ 3708/* capture mixer elements */
2502static struct snd_kcontrol_new vt1708S_capture_mixer[] = { 3709static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2503 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), 3710 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2504 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), 3711 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2505 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), 3712 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2506 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), 3713 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2507 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A), 3714 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
2508 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E), 3715 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3716 HDA_INPUT),
2509 { 3717 {
2510 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3718 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2511 /* The multiple "Capture Source" controls confuse alsamixer 3719 /* The multiple "Capture Source" controls confuse alsamixer
@@ -2542,11 +3750,21 @@ static struct hda_verb vt1708S_volume_init_verbs[] = {
2542 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 3750 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2543 /* Enable Mic Boost Volume backdoor */ 3751 /* Enable Mic Boost Volume backdoor */
2544 {0x1, 0xf98, 0x1}, 3752 {0x1, 0xf98, 0x1},
3753 /* don't bybass mixer */
3754 {0x1, 0xf88, 0xc0},
2545 { } 3755 { }
2546}; 3756};
2547 3757
2548static struct hda_verb vt1708S_uniwill_init_verbs[] = { 3758static struct hda_verb vt1708S_uniwill_init_verbs[] = {
2549 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 3759 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3760 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3761 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3762 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3763 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3764 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3765 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3766 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3767 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2550 { } 3768 { }
2551}; 3769};
2552 3770
@@ -2557,8 +3775,9 @@ static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2557 .nid = 0x10, /* NID to query formats and rates */ 3775 .nid = 0x10, /* NID to query formats and rates */
2558 .ops = { 3776 .ops = {
2559 .open = via_playback_pcm_open, 3777 .open = via_playback_pcm_open,
2560 .prepare = via_playback_pcm_prepare, 3778 .prepare = via_playback_multi_pcm_prepare,
2561 .cleanup = via_playback_pcm_cleanup 3779 .cleanup = via_playback_multi_pcm_cleanup,
3780 .close = via_pcm_open_close
2562 }, 3781 },
2563}; 3782};
2564 3783
@@ -2568,8 +3787,10 @@ static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2568 .channels_max = 2, 3787 .channels_max = 2,
2569 .nid = 0x13, /* NID to query formats and rates */ 3788 .nid = 0x13, /* NID to query formats and rates */
2570 .ops = { 3789 .ops = {
3790 .open = via_pcm_open_close,
2571 .prepare = via_capture_pcm_prepare, 3791 .prepare = via_capture_pcm_prepare,
2572 .cleanup = via_capture_pcm_cleanup 3792 .cleanup = via_capture_pcm_cleanup,
3793 .close = via_pcm_open_close
2573 }, 3794 },
2574}; 3795};
2575 3796
@@ -2726,6 +3947,7 @@ static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2726 return 0; 3947 return 0;
2727 3948
2728 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */ 3949 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3950 spec->hp_independent_mode_index = 1;
2729 3951
2730 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 3952 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2731 "Headphone Playback Volume", 3953 "Headphone Playback Volume",
@@ -2780,8 +4002,7 @@ static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2780 idx = 1; 4002 idx = 1;
2781 break; 4003 break;
2782 } 4004 }
2783 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], 4005 err = via_new_analog_input(spec, labels[i], idx, 0x16);
2784 idx, 0x16);
2785 if (err < 0) 4006 if (err < 0)
2786 return err; 4007 return err;
2787 imux->items[imux->num_items].label = labels[i]; 4008 imux->items[imux->num_items].label = labels[i];
@@ -2852,6 +4073,7 @@ static int vt1708S_parse_auto_config(struct hda_codec *codec)
2852 if (spec->hp_mux) 4073 if (spec->hp_mux)
2853 spec->mixers[spec->num_mixers++] = via_hp_mixer; 4074 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2854 4075
4076 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2855 return 1; 4077 return 1;
2856} 4078}
2857 4079
@@ -2865,6 +4087,16 @@ static struct hda_amp_list vt1708S_loopbacks[] = {
2865}; 4087};
2866#endif 4088#endif
2867 4089
4090static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4091 int offset, int num_steps, int step_size)
4092{
4093 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4094 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4095 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4096 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4097 (0 << AC_AMPCAP_MUTE_SHIFT));
4098}
4099
2868static int patch_vt1708S(struct hda_codec *codec) 4100static int patch_vt1708S(struct hda_codec *codec)
2869{ 4101{
2870 struct via_spec *spec; 4102 struct via_spec *spec;
@@ -2890,17 +4122,25 @@ static int patch_vt1708S(struct hda_codec *codec)
2890 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; 4122 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
2891 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs; 4123 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
2892 4124
2893 spec->stream_name_analog = "VT1708S Analog"; 4125 if (codec->vendor_id == 0x11060440)
4126 spec->stream_name_analog = "VT1818S Analog";
4127 else
4128 spec->stream_name_analog = "VT1708S Analog";
2894 spec->stream_analog_playback = &vt1708S_pcm_analog_playback; 4129 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2895 spec->stream_analog_capture = &vt1708S_pcm_analog_capture; 4130 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2896 4131
2897 spec->stream_name_digital = "VT1708S Digital"; 4132 if (codec->vendor_id == 0x11060440)
4133 spec->stream_name_digital = "VT1818S Digital";
4134 else
4135 spec->stream_name_digital = "VT1708S Digital";
2898 spec->stream_digital_playback = &vt1708S_pcm_digital_playback; 4136 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
2899 4137
2900 if (!spec->adc_nids && spec->input_mux) { 4138 if (!spec->adc_nids && spec->input_mux) {
2901 spec->adc_nids = vt1708S_adc_nids; 4139 spec->adc_nids = vt1708S_adc_nids;
2902 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids); 4140 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2903 get_mux_nids(codec); 4141 get_mux_nids(codec);
4142 override_mic_boost(codec, 0x1a, 0, 3, 40);
4143 override_mic_boost(codec, 0x1e, 0, 3, 40);
2904 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; 4144 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2905 spec->num_mixers++; 4145 spec->num_mixers++;
2906 } 4146 }
@@ -2913,6 +4153,16 @@ static int patch_vt1708S(struct hda_codec *codec)
2913 spec->loopback.amplist = vt1708S_loopbacks; 4153 spec->loopback.amplist = vt1708S_loopbacks;
2914#endif 4154#endif
2915 4155
4156 /* correct names for VT1708BCE */
4157 if (get_codec_type(codec) == VT1708BCE) {
4158 kfree(codec->chip_name);
4159 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4160 snprintf(codec->bus->card->mixername,
4161 sizeof(codec->bus->card->mixername),
4162 "%s %s", codec->vendor_name, codec->chip_name);
4163 spec->stream_name_analog = "VT1708BCE Analog";
4164 spec->stream_name_digital = "VT1708BCE Digital";
4165 }
2916 return 0; 4166 return 0;
2917} 4167}
2918 4168
@@ -2967,12 +4217,20 @@ static struct hda_verb vt1702_volume_init_verbs[] = {
2967 /* PW6 PW7 Output enable */ 4217 /* PW6 PW7 Output enable */
2968 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 4218 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2969 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 4219 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4220 /* mixer enable */
4221 {0x1, 0xF88, 0x3},
4222 /* GPIO 0~2 */
4223 {0x1, 0xF82, 0x3F},
2970 { } 4224 { }
2971}; 4225};
2972 4226
2973static struct hda_verb vt1702_uniwill_init_verbs[] = { 4227static struct hda_verb vt1702_uniwill_init_verbs[] = {
2974 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT}, 4228 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
2975 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, 4229 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4230 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4231 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4232 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4233 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2976 { } 4234 { }
2977}; 4235};
2978 4236
@@ -2984,7 +4242,8 @@ static struct hda_pcm_stream vt1702_pcm_analog_playback = {
2984 .ops = { 4242 .ops = {
2985 .open = via_playback_pcm_open, 4243 .open = via_playback_pcm_open,
2986 .prepare = via_playback_multi_pcm_prepare, 4244 .prepare = via_playback_multi_pcm_prepare,
2987 .cleanup = via_playback_multi_pcm_cleanup 4245 .cleanup = via_playback_multi_pcm_cleanup,
4246 .close = via_pcm_open_close
2988 }, 4247 },
2989}; 4248};
2990 4249
@@ -2994,8 +4253,10 @@ static struct hda_pcm_stream vt1702_pcm_analog_capture = {
2994 .channels_max = 2, 4253 .channels_max = 2,
2995 .nid = 0x12, /* NID to query formats and rates */ 4254 .nid = 0x12, /* NID to query formats and rates */
2996 .ops = { 4255 .ops = {
4256 .open = via_pcm_open_close,
2997 .prepare = via_capture_pcm_prepare, 4257 .prepare = via_capture_pcm_prepare,
2998 .cleanup = via_capture_pcm_cleanup 4258 .cleanup = via_capture_pcm_cleanup,
4259 .close = via_pcm_open_close
2999 }, 4260 },
3000}; 4261};
3001 4262
@@ -3065,12 +4326,13 @@ static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
3065 4326
3066static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) 4327static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3067{ 4328{
3068 int err; 4329 int err, i;
3069 4330 struct hda_input_mux *imux;
4331 static const char *texts[] = { "ON", "OFF", NULL};
3070 if (!pin) 4332 if (!pin)
3071 return 0; 4333 return 0;
3072
3073 spec->multiout.hp_nid = 0x1D; 4334 spec->multiout.hp_nid = 0x1D;
4335 spec->hp_independent_mode_index = 0;
3074 4336
3075 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, 4337 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3076 "Headphone Playback Volume", 4338 "Headphone Playback Volume",
@@ -3084,8 +4346,18 @@ static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3084 if (err < 0) 4346 if (err < 0)
3085 return err; 4347 return err;
3086 4348
3087 create_hp_imux(spec); 4349 imux = &spec->private_imux[1];
3088 4350
4351 /* for hp mode select */
4352 i = 0;
4353 while (texts[i] != NULL) {
4354 imux->items[imux->num_items].label = texts[i];
4355 imux->items[imux->num_items].index = i;
4356 imux->num_items++;
4357 i++;
4358 }
4359
4360 spec->hp_mux = &spec->private_imux[1];
3089 return 0; 4361 return 0;
3090} 4362}
3091 4363
@@ -3121,8 +4393,7 @@ static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3121 idx = 3; 4393 idx = 3;
3122 break; 4394 break;
3123 } 4395 }
3124 err = via_new_analog_input(spec, cfg->input_pins[i], 4396 err = via_new_analog_input(spec, labels[i], idx, 0x1A);
3125 labels[i], idx, 0x1A);
3126 if (err < 0) 4397 if (err < 0)
3127 return err; 4398 return err;
3128 imux->items[imux->num_items].label = labels[i]; 4399 imux->items[imux->num_items].label = labels[i];
@@ -3152,6 +4423,12 @@ static int vt1702_parse_auto_config(struct hda_codec *codec)
3152 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); 4423 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3153 if (err < 0) 4424 if (err < 0)
3154 return err; 4425 return err;
4426 /* limit AA path volume to 0 dB */
4427 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4428 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4429 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4430 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4431 (1 << AC_AMPCAP_MUTE_SHIFT));
3155 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg); 4432 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3156 if (err < 0) 4433 if (err < 0)
3157 return err; 4434 return err;
@@ -3185,8 +4462,6 @@ static int patch_vt1702(struct hda_codec *codec)
3185{ 4462{
3186 struct via_spec *spec; 4463 struct via_spec *spec;
3187 int err; 4464 int err;
3188 unsigned int response;
3189 unsigned char control;
3190 4465
3191 /* create a codec specific record */ 4466 /* create a codec specific record */
3192 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4467 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
@@ -3231,17 +4506,1638 @@ static int patch_vt1702(struct hda_codec *codec)
3231 spec->loopback.amplist = vt1702_loopbacks; 4506 spec->loopback.amplist = vt1702_loopbacks;
3232#endif 4507#endif
3233 4508
3234 /* Open backdoor */ 4509 return 0;
3235 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0); 4510}
3236 control = (unsigned char)(response & 0xff); 4511
3237 control |= 0x3; 4512/* Patch for VT1718S */
3238 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control); 4513
4514/* capture mixer elements */
4515static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4516 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4517 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4518 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4519 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4520 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4521 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4522 HDA_INPUT),
4523 {
4524 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4525 /* The multiple "Capture Source" controls confuse alsamixer
4526 * So call somewhat different..
4527 */
4528 .name = "Input Source",
4529 .count = 2,
4530 .info = via_mux_enum_info,
4531 .get = via_mux_enum_get,
4532 .put = via_mux_enum_put,
4533 },
4534 { } /* end */
4535};
4536
4537static struct hda_verb vt1718S_volume_init_verbs[] = {
4538 /*
4539 * Unmute ADC0-1 and set the default input to mic-in
4540 */
4541 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4542 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4543
4544
4545 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4546 * mixer widget
4547 */
4548 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4549 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4550 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4551 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4552 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4553 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4554
4555 /* Setup default input of Front HP to MW9 */
4556 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4557 /* PW9 PW10 Output enable */
4558 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4559 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4560 /* PW11 Input enable */
4561 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4562 /* Enable Boost Volume backdoor */
4563 {0x1, 0xf88, 0x8},
4564 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4565 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4566 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4567 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4568 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4569 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4570 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4571 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4572 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4573 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4574 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4575 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4576 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4577 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4578 /* Unmute MW4's index 0 */
4579 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4580 { }
4581};
4582
4583
4584static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4585 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4586 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4587 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4588 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4589 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4590 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4591 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4592 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4593 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4594 { }
4595};
4596
4597static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4598 .substreams = 2,
4599 .channels_min = 2,
4600 .channels_max = 10,
4601 .nid = 0x8, /* NID to query formats and rates */
4602 .ops = {
4603 .open = via_playback_pcm_open,
4604 .prepare = via_playback_multi_pcm_prepare,
4605 .cleanup = via_playback_multi_pcm_cleanup,
4606 .close = via_pcm_open_close,
4607 },
4608};
4609
4610static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4611 .substreams = 2,
4612 .channels_min = 2,
4613 .channels_max = 2,
4614 .nid = 0x10, /* NID to query formats and rates */
4615 .ops = {
4616 .open = via_pcm_open_close,
4617 .prepare = via_capture_pcm_prepare,
4618 .cleanup = via_capture_pcm_cleanup,
4619 .close = via_pcm_open_close,
4620 },
4621};
4622
4623static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4624 .substreams = 2,
4625 .channels_min = 2,
4626 .channels_max = 2,
4627 /* NID is set in via_build_pcms */
4628 .ops = {
4629 .open = via_dig_playback_pcm_open,
4630 .close = via_dig_playback_pcm_close,
4631 .prepare = via_dig_playback_pcm_prepare,
4632 .cleanup = via_dig_playback_pcm_cleanup
4633 },
4634};
4635
4636static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4637 .substreams = 1,
4638 .channels_min = 2,
4639 .channels_max = 2,
4640};
4641
4642/* fill in the dac_nids table from the parsed pin configuration */
4643static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4644 const struct auto_pin_cfg *cfg)
4645{
4646 int i;
4647 hda_nid_t nid;
4648
4649 spec->multiout.num_dacs = cfg->line_outs;
4650
4651 spec->multiout.dac_nids = spec->private_dac_nids;
4652
4653 for (i = 0; i < 4; i++) {
4654 nid = cfg->line_out_pins[i];
4655 if (nid) {
4656 /* config dac list */
4657 switch (i) {
4658 case AUTO_SEQ_FRONT:
4659 spec->multiout.dac_nids[i] = 0x8;
4660 break;
4661 case AUTO_SEQ_CENLFE:
4662 spec->multiout.dac_nids[i] = 0xa;
4663 break;
4664 case AUTO_SEQ_SURROUND:
4665 spec->multiout.dac_nids[i] = 0x9;
4666 break;
4667 case AUTO_SEQ_SIDE:
4668 spec->multiout.dac_nids[i] = 0xb;
4669 break;
4670 }
4671 }
4672 }
4673
4674 return 0;
4675}
4676
4677/* add playback controls from the parsed DAC table */
4678static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4679 const struct auto_pin_cfg *cfg)
4680{
4681 char name[32];
4682 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4683 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4684 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4685 hda_nid_t nid, nid_vol, nid_mute = 0;
4686 int i, err;
4687
4688 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4689 nid = cfg->line_out_pins[i];
4690
4691 if (!nid)
4692 continue;
4693 nid_vol = nid_vols[i];
4694 nid_mute = nid_mutes[i];
4695
4696 if (i == AUTO_SEQ_CENLFE) {
4697 /* Center/LFE */
4698 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4699 "Center Playback Volume",
4700 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4701 HDA_OUTPUT));
4702 if (err < 0)
4703 return err;
4704 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4705 "LFE Playback Volume",
4706 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4707 HDA_OUTPUT));
4708 if (err < 0)
4709 return err;
4710 err = via_add_control(
4711 spec, VIA_CTL_WIDGET_MUTE,
4712 "Center Playback Switch",
4713 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4714 HDA_OUTPUT));
4715 if (err < 0)
4716 return err;
4717 err = via_add_control(
4718 spec, VIA_CTL_WIDGET_MUTE,
4719 "LFE Playback Switch",
4720 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4721 HDA_OUTPUT));
4722 if (err < 0)
4723 return err;
4724 } else if (i == AUTO_SEQ_FRONT) {
4725 /* Front */
4726 sprintf(name, "%s Playback Volume", chname[i]);
4727 err = via_add_control(
4728 spec, VIA_CTL_WIDGET_VOL, name,
4729 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4730 if (err < 0)
4731 return err;
4732 sprintf(name, "%s Playback Switch", chname[i]);
4733 err = via_add_control(
4734 spec, VIA_CTL_WIDGET_MUTE, name,
4735 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4736 HDA_OUTPUT));
4737 if (err < 0)
4738 return err;
4739 } else {
4740 sprintf(name, "%s Playback Volume", chname[i]);
4741 err = via_add_control(
4742 spec, VIA_CTL_WIDGET_VOL, name,
4743 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4744 if (err < 0)
4745 return err;
4746 sprintf(name, "%s Playback Switch", chname[i]);
4747 err = via_add_control(
4748 spec, VIA_CTL_WIDGET_MUTE, name,
4749 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4750 HDA_OUTPUT));
4751 if (err < 0)
4752 return err;
4753 }
4754 }
4755 return 0;
4756}
4757
4758static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4759{
4760 int err;
4761
4762 if (!pin)
4763 return 0;
4764
4765 spec->multiout.hp_nid = 0xc; /* AOW4 */
4766 spec->hp_independent_mode_index = 1;
4767
4768 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4769 "Headphone Playback Volume",
4770 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4771 if (err < 0)
4772 return err;
4773
4774 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4775 "Headphone Playback Switch",
4776 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4777 if (err < 0)
4778 return err;
4779
4780 create_hp_imux(spec);
4781 return 0;
4782}
4783
4784/* create playback/capture controls for input pins */
4785static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4786 const struct auto_pin_cfg *cfg)
4787{
4788 static char *labels[] = {
4789 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4790 };
4791 struct hda_input_mux *imux = &spec->private_imux[0];
4792 int i, err, idx = 0;
4793
4794 /* for internal loopback recording select */
4795 imux->items[imux->num_items].label = "Stereo Mixer";
4796 imux->items[imux->num_items].index = 5;
4797 imux->num_items++;
4798
4799 for (i = 0; i < AUTO_PIN_LAST; i++) {
4800 if (!cfg->input_pins[i])
4801 continue;
4802
4803 switch (cfg->input_pins[i]) {
4804 case 0x2b: /* Mic */
4805 idx = 1;
4806 break;
4807
4808 case 0x2a: /* Line In */
4809 idx = 2;
4810 break;
4811
4812 case 0x29: /* Front Mic */
4813 idx = 3;
4814 break;
4815
4816 case 0x2c: /* CD */
4817 idx = 0;
4818 break;
4819 }
4820 err = via_new_analog_input(spec, labels[i], idx, 0x21);
4821 if (err < 0)
4822 return err;
4823 imux->items[imux->num_items].label = labels[i];
4824 imux->items[imux->num_items].index = idx;
4825 imux->num_items++;
4826 }
4827 return 0;
4828}
4829
4830static int vt1718S_parse_auto_config(struct hda_codec *codec)
4831{
4832 struct via_spec *spec = codec->spec;
4833 int err;
4834
4835 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4836
4837 if (err < 0)
4838 return err;
4839 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4840 if (err < 0)
4841 return err;
4842 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4843 return 0; /* can't find valid BIOS pin config */
4844
4845 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4846 if (err < 0)
4847 return err;
4848 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4849 if (err < 0)
4850 return err;
4851 err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4852 if (err < 0)
4853 return err;
4854
4855 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4856
4857 fill_dig_outs(codec);
4858
4859 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4860 spec->dig_in_nid = 0x13;
4861
4862 if (spec->kctls.list)
4863 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4864
4865 spec->input_mux = &spec->private_imux[0];
4866
4867 if (spec->hp_mux)
4868 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4869
4870 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4871
4872 return 1;
4873}
4874
4875#ifdef CONFIG_SND_HDA_POWER_SAVE
4876static struct hda_amp_list vt1718S_loopbacks[] = {
4877 { 0x21, HDA_INPUT, 1 },
4878 { 0x21, HDA_INPUT, 2 },
4879 { 0x21, HDA_INPUT, 3 },
4880 { 0x21, HDA_INPUT, 4 },
4881 { } /* end */
4882};
4883#endif
4884
4885static int patch_vt1718S(struct hda_codec *codec)
4886{
4887 struct via_spec *spec;
4888 int err;
3239 4889
3240 /* Enable GPIO 0&1 for volume&mute control */ 4890 /* create a codec specific record */
3241 /* Enable GPIO 2 for DMIC-DATA */ 4891 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3242 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0); 4892 if (spec == NULL)
3243 control = (unsigned char)((response >> 16) & 0x3f); 4893 return -ENOMEM;
3244 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control); 4894
4895 codec->spec = spec;
4896
4897 /* automatic parse from the BIOS config */
4898 err = vt1718S_parse_auto_config(codec);
4899 if (err < 0) {
4900 via_free(codec);
4901 return err;
4902 } else if (!err) {
4903 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4904 "from BIOS. Using genenic mode...\n");
4905 }
4906
4907 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4908 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4909
4910 if (codec->vendor_id == 0x11060441)
4911 spec->stream_name_analog = "VT2020 Analog";
4912 else if (codec->vendor_id == 0x11064441)
4913 spec->stream_name_analog = "VT1828S Analog";
4914 else
4915 spec->stream_name_analog = "VT1718S Analog";
4916 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4917 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4918
4919 if (codec->vendor_id == 0x11060441)
4920 spec->stream_name_digital = "VT2020 Digital";
4921 else if (codec->vendor_id == 0x11064441)
4922 spec->stream_name_digital = "VT1828S Digital";
4923 else
4924 spec->stream_name_digital = "VT1718S Digital";
4925 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4926 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4927 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4928
4929 if (!spec->adc_nids && spec->input_mux) {
4930 spec->adc_nids = vt1718S_adc_nids;
4931 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4932 get_mux_nids(codec);
4933 override_mic_boost(codec, 0x2b, 0, 3, 40);
4934 override_mic_boost(codec, 0x29, 0, 3, 40);
4935 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4936 spec->num_mixers++;
4937 }
4938
4939 codec->patch_ops = via_patch_ops;
4940
4941 codec->patch_ops.init = via_auto_init;
4942 codec->patch_ops.unsol_event = via_unsol_event;
4943
4944#ifdef CONFIG_SND_HDA_POWER_SAVE
4945 spec->loopback.amplist = vt1718S_loopbacks;
4946#endif
4947
4948 return 0;
4949}
4950
4951/* Patch for VT1716S */
4952
4953static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4954 struct snd_ctl_elem_info *uinfo)
4955{
4956 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4957 uinfo->count = 1;
4958 uinfo->value.integer.min = 0;
4959 uinfo->value.integer.max = 1;
4960 return 0;
4961}
4962
4963static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4964 struct snd_ctl_elem_value *ucontrol)
4965{
4966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4967 int index = 0;
4968
4969 index = snd_hda_codec_read(codec, 0x26, 0,
4970 AC_VERB_GET_CONNECT_SEL, 0);
4971 if (index != -1)
4972 *ucontrol->value.integer.value = index;
4973
4974 return 0;
4975}
4976
4977static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4978 struct snd_ctl_elem_value *ucontrol)
4979{
4980 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4981 struct via_spec *spec = codec->spec;
4982 int index = *ucontrol->value.integer.value;
4983
4984 snd_hda_codec_write(codec, 0x26, 0,
4985 AC_VERB_SET_CONNECT_SEL, index);
4986 spec->dmic_enabled = index;
4987 set_jack_power_state(codec);
4988
4989 return 1;
4990}
4991
4992/* capture mixer elements */
4993static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4994 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4995 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4996 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4997 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4998 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4999 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5000 HDA_INPUT),
5001 {
5002 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5003 .name = "Input Source",
5004 .count = 1,
5005 .info = via_mux_enum_info,
5006 .get = via_mux_enum_get,
5007 .put = via_mux_enum_put,
5008 },
5009 { } /* end */
5010};
5011
5012static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
5013 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
5014 {
5015 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5016 .name = "Digital Mic Capture Switch",
5017 .count = 1,
5018 .info = vt1716s_dmic_info,
5019 .get = vt1716s_dmic_get,
5020 .put = vt1716s_dmic_put,
5021 },
5022 {} /* end */
5023};
5024
5025
5026/* mono-out mixer elements */
5027static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
5028 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
5029 { } /* end */
5030};
5031
5032static struct hda_verb vt1716S_volume_init_verbs[] = {
5033 /*
5034 * Unmute ADC0-1 and set the default input to mic-in
5035 */
5036 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5037 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5038
5039
5040 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5041 * mixer widget
5042 */
5043 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5044 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5045 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5046 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5047 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5048 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5049
5050 /* MUX Indices: Stereo Mixer = 5 */
5051 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
5052
5053 /* Setup default input of PW4 to MW0 */
5054 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
5055
5056 /* Setup default input of SW1 as MW0 */
5057 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5058
5059 /* Setup default input of SW4 as AOW0 */
5060 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5061
5062 /* PW9 PW10 Output enable */
5063 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5064 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5065
5066 /* Unmute SW1, PW12 */
5067 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5068 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5069 /* PW12 Output enable */
5070 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5071 /* Enable Boost Volume backdoor */
5072 {0x1, 0xf8a, 0x80},
5073 /* don't bybass mixer */
5074 {0x1, 0xf88, 0xc0},
5075 /* Enable mono output */
5076 {0x1, 0xf90, 0x08},
5077 { }
5078};
5079
5080
5081static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5082 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5083 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5084 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5085 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5086 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5087 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5088 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5089 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5090 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5091 { }
5092};
5093
5094static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5095 .substreams = 2,
5096 .channels_min = 2,
5097 .channels_max = 6,
5098 .nid = 0x10, /* NID to query formats and rates */
5099 .ops = {
5100 .open = via_playback_pcm_open,
5101 .prepare = via_playback_multi_pcm_prepare,
5102 .cleanup = via_playback_multi_pcm_cleanup,
5103 .close = via_pcm_open_close,
5104 },
5105};
5106
5107static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5108 .substreams = 2,
5109 .channels_min = 2,
5110 .channels_max = 2,
5111 .nid = 0x13, /* NID to query formats and rates */
5112 .ops = {
5113 .open = via_pcm_open_close,
5114 .prepare = via_capture_pcm_prepare,
5115 .cleanup = via_capture_pcm_cleanup,
5116 .close = via_pcm_open_close,
5117 },
5118};
5119
5120static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5121 .substreams = 2,
5122 .channels_min = 2,
5123 .channels_max = 2,
5124 /* NID is set in via_build_pcms */
5125 .ops = {
5126 .open = via_dig_playback_pcm_open,
5127 .close = via_dig_playback_pcm_close,
5128 .prepare = via_dig_playback_pcm_prepare,
5129 .cleanup = via_dig_playback_pcm_cleanup
5130 },
5131};
5132
5133/* fill in the dac_nids table from the parsed pin configuration */
5134static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5135 const struct auto_pin_cfg *cfg)
5136{ int i;
5137 hda_nid_t nid;
5138
5139 spec->multiout.num_dacs = cfg->line_outs;
5140
5141 spec->multiout.dac_nids = spec->private_dac_nids;
5142
5143 for (i = 0; i < 3; i++) {
5144 nid = cfg->line_out_pins[i];
5145 if (nid) {
5146 /* config dac list */
5147 switch (i) {
5148 case AUTO_SEQ_FRONT:
5149 spec->multiout.dac_nids[i] = 0x10;
5150 break;
5151 case AUTO_SEQ_CENLFE:
5152 spec->multiout.dac_nids[i] = 0x25;
5153 break;
5154 case AUTO_SEQ_SURROUND:
5155 spec->multiout.dac_nids[i] = 0x11;
5156 break;
5157 }
5158 }
5159 }
5160
5161 return 0;
5162}
5163
5164/* add playback controls from the parsed DAC table */
5165static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5166 const struct auto_pin_cfg *cfg)
5167{
5168 char name[32];
5169 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5170 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5171 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5172 hda_nid_t nid, nid_vol, nid_mute;
5173 int i, err;
5174
5175 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5176 nid = cfg->line_out_pins[i];
5177
5178 if (!nid)
5179 continue;
5180
5181 nid_vol = nid_vols[i];
5182 nid_mute = nid_mutes[i];
5183
5184 if (i == AUTO_SEQ_CENLFE) {
5185 err = via_add_control(
5186 spec, VIA_CTL_WIDGET_VOL,
5187 "Center Playback Volume",
5188 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5189 if (err < 0)
5190 return err;
5191 err = via_add_control(
5192 spec, VIA_CTL_WIDGET_VOL,
5193 "LFE Playback Volume",
5194 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5195 if (err < 0)
5196 return err;
5197 err = via_add_control(
5198 spec, VIA_CTL_WIDGET_MUTE,
5199 "Center Playback Switch",
5200 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5201 HDA_OUTPUT));
5202 if (err < 0)
5203 return err;
5204 err = via_add_control(
5205 spec, VIA_CTL_WIDGET_MUTE,
5206 "LFE Playback Switch",
5207 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5208 HDA_OUTPUT));
5209 if (err < 0)
5210 return err;
5211 } else if (i == AUTO_SEQ_FRONT) {
5212
5213 err = via_add_control(
5214 spec, VIA_CTL_WIDGET_VOL,
5215 "Master Front Playback Volume",
5216 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5217 if (err < 0)
5218 return err;
5219 err = via_add_control(
5220 spec, VIA_CTL_WIDGET_MUTE,
5221 "Master Front Playback Switch",
5222 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5223 if (err < 0)
5224 return err;
5225
5226 sprintf(name, "%s Playback Volume", chname[i]);
5227 err = via_add_control(
5228 spec, VIA_CTL_WIDGET_VOL, name,
5229 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5230 if (err < 0)
5231 return err;
5232 sprintf(name, "%s Playback Switch", chname[i]);
5233 err = via_add_control(
5234 spec, VIA_CTL_WIDGET_MUTE, name,
5235 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5236 HDA_OUTPUT));
5237 if (err < 0)
5238 return err;
5239 } else {
5240 sprintf(name, "%s Playback Volume", chname[i]);
5241 err = via_add_control(
5242 spec, VIA_CTL_WIDGET_VOL, name,
5243 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5244 if (err < 0)
5245 return err;
5246 sprintf(name, "%s Playback Switch", chname[i]);
5247 err = via_add_control(
5248 spec, VIA_CTL_WIDGET_MUTE, name,
5249 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5250 HDA_OUTPUT));
5251 if (err < 0)
5252 return err;
5253 }
5254 }
5255 return 0;
5256}
5257
5258static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5259{
5260 int err;
5261
5262 if (!pin)
5263 return 0;
5264
5265 spec->multiout.hp_nid = 0x25; /* AOW3 */
5266 spec->hp_independent_mode_index = 1;
5267
5268 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5269 "Headphone Playback Volume",
5270 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5271 if (err < 0)
5272 return err;
5273
5274 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5275 "Headphone Playback Switch",
5276 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5277 if (err < 0)
5278 return err;
5279
5280 create_hp_imux(spec);
5281 return 0;
5282}
5283
5284/* create playback/capture controls for input pins */
5285static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5286 const struct auto_pin_cfg *cfg)
5287{
5288 static char *labels[] = {
5289 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5290 };
5291 struct hda_input_mux *imux = &spec->private_imux[0];
5292 int i, err, idx = 0;
5293
5294 /* for internal loopback recording select */
5295 imux->items[imux->num_items].label = "Stereo Mixer";
5296 imux->items[imux->num_items].index = 5;
5297 imux->num_items++;
5298
5299 for (i = 0; i < AUTO_PIN_LAST; i++) {
5300 if (!cfg->input_pins[i])
5301 continue;
5302
5303 switch (cfg->input_pins[i]) {
5304 case 0x1a: /* Mic */
5305 idx = 2;
5306 break;
5307
5308 case 0x1b: /* Line In */
5309 idx = 3;
5310 break;
5311
5312 case 0x1e: /* Front Mic */
5313 idx = 4;
5314 break;
5315
5316 case 0x1f: /* CD */
5317 idx = 1;
5318 break;
5319 }
5320 err = via_new_analog_input(spec, labels[i], idx, 0x16);
5321 if (err < 0)
5322 return err;
5323 imux->items[imux->num_items].label = labels[i];
5324 imux->items[imux->num_items].index = idx-1;
5325 imux->num_items++;
5326 }
5327 return 0;
5328}
5329
5330static int vt1716S_parse_auto_config(struct hda_codec *codec)
5331{
5332 struct via_spec *spec = codec->spec;
5333 int err;
5334
5335 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5336 if (err < 0)
5337 return err;
5338 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5339 if (err < 0)
5340 return err;
5341 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5342 return 0; /* can't find valid BIOS pin config */
5343
5344 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5345 if (err < 0)
5346 return err;
5347 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5348 if (err < 0)
5349 return err;
5350 err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
5351 if (err < 0)
5352 return err;
5353
5354 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5355
5356 fill_dig_outs(codec);
5357
5358 if (spec->kctls.list)
5359 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5360
5361 spec->input_mux = &spec->private_imux[0];
5362
5363 if (spec->hp_mux)
5364 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5365
5366 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
5367
5368 return 1;
5369}
5370
5371#ifdef CONFIG_SND_HDA_POWER_SAVE
5372static struct hda_amp_list vt1716S_loopbacks[] = {
5373 { 0x16, HDA_INPUT, 1 },
5374 { 0x16, HDA_INPUT, 2 },
5375 { 0x16, HDA_INPUT, 3 },
5376 { 0x16, HDA_INPUT, 4 },
5377 { } /* end */
5378};
5379#endif
5380
5381static int patch_vt1716S(struct hda_codec *codec)
5382{
5383 struct via_spec *spec;
5384 int err;
5385
5386 /* create a codec specific record */
5387 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5388 if (spec == NULL)
5389 return -ENOMEM;
5390
5391 codec->spec = spec;
5392
5393 /* automatic parse from the BIOS config */
5394 err = vt1716S_parse_auto_config(codec);
5395 if (err < 0) {
5396 via_free(codec);
5397 return err;
5398 } else if (!err) {
5399 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5400 "from BIOS. Using genenic mode...\n");
5401 }
5402
5403 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5404 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5405
5406 spec->stream_name_analog = "VT1716S Analog";
5407 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5408 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5409
5410 spec->stream_name_digital = "VT1716S Digital";
5411 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5412
5413 if (!spec->adc_nids && spec->input_mux) {
5414 spec->adc_nids = vt1716S_adc_nids;
5415 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5416 get_mux_nids(codec);
5417 override_mic_boost(codec, 0x1a, 0, 3, 40);
5418 override_mic_boost(codec, 0x1e, 0, 3, 40);
5419 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5420 spec->num_mixers++;
5421 }
5422
5423 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5424 spec->num_mixers++;
5425
5426 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5427
5428 codec->patch_ops = via_patch_ops;
5429
5430 codec->patch_ops.init = via_auto_init;
5431 codec->patch_ops.unsol_event = via_unsol_event;
5432
5433#ifdef CONFIG_SND_HDA_POWER_SAVE
5434 spec->loopback.amplist = vt1716S_loopbacks;
5435#endif
5436
5437 return 0;
5438}
5439
5440/* for vt2002P */
5441
5442/* capture mixer elements */
5443static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5444 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5445 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5446 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5447 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5448 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5449 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5450 HDA_INPUT),
5451 {
5452 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5453 /* The multiple "Capture Source" controls confuse alsamixer
5454 * So call somewhat different..
5455 */
5456 /* .name = "Capture Source", */
5457 .name = "Input Source",
5458 .count = 2,
5459 .info = via_mux_enum_info,
5460 .get = via_mux_enum_get,
5461 .put = via_mux_enum_put,
5462 },
5463 { } /* end */
5464};
5465
5466static struct hda_verb vt2002P_volume_init_verbs[] = {
5467 /*
5468 * Unmute ADC0-1 and set the default input to mic-in
5469 */
5470 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5471 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5472
5473
5474 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5475 * mixer widget
5476 */
5477 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5478 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5479 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5480 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5481 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5482 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5483
5484 /* MUX Indices: Mic = 0 */
5485 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5486 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5487
5488 /* PW9 Output enable */
5489 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5490
5491 /* Enable Boost Volume backdoor */
5492 {0x1, 0xfb9, 0x24},
5493
5494 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5495 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5496 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5497 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5498 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5499 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5500 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5501 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5502 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5503
5504 /* set MUX0/1/4/8 = 0 (AOW0) */
5505 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5506 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5507 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5508 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5509
5510 /* set PW0 index=0 (MW0) */
5511 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5512
5513 /* Enable AOW0 to MW9 */
5514 {0x1, 0xfb8, 0x88},
5515 { }
5516};
5517
5518
5519static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5520 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5521 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5522 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5523 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5524 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5525 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5526 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5527 { }
5528};
5529
5530static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5531 .substreams = 2,
5532 .channels_min = 2,
5533 .channels_max = 2,
5534 .nid = 0x8, /* NID to query formats and rates */
5535 .ops = {
5536 .open = via_playback_pcm_open,
5537 .prepare = via_playback_multi_pcm_prepare,
5538 .cleanup = via_playback_multi_pcm_cleanup,
5539 .close = via_pcm_open_close,
5540 },
5541};
5542
5543static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5544 .substreams = 2,
5545 .channels_min = 2,
5546 .channels_max = 2,
5547 .nid = 0x10, /* NID to query formats and rates */
5548 .ops = {
5549 .open = via_pcm_open_close,
5550 .prepare = via_capture_pcm_prepare,
5551 .cleanup = via_capture_pcm_cleanup,
5552 .close = via_pcm_open_close,
5553 },
5554};
5555
5556static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5557 .substreams = 1,
5558 .channels_min = 2,
5559 .channels_max = 2,
5560 /* NID is set in via_build_pcms */
5561 .ops = {
5562 .open = via_dig_playback_pcm_open,
5563 .close = via_dig_playback_pcm_close,
5564 .prepare = via_dig_playback_pcm_prepare,
5565 .cleanup = via_dig_playback_pcm_cleanup
5566 },
5567};
5568
5569/* fill in the dac_nids table from the parsed pin configuration */
5570static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5571 const struct auto_pin_cfg *cfg)
5572{
5573 spec->multiout.num_dacs = 1;
5574 spec->multiout.dac_nids = spec->private_dac_nids;
5575 if (cfg->line_out_pins[0])
5576 spec->multiout.dac_nids[0] = 0x8;
5577 return 0;
5578}
5579
5580/* add playback controls from the parsed DAC table */
5581static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5582 const struct auto_pin_cfg *cfg)
5583{
5584 int err;
5585
5586 if (!cfg->line_out_pins[0])
5587 return -1;
5588
5589
5590 /* Line-Out: PortE */
5591 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5592 "Master Front Playback Volume",
5593 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5594 if (err < 0)
5595 return err;
5596 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5597 "Master Front Playback Switch",
5598 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5599 if (err < 0)
5600 return err;
5601
5602 return 0;
5603}
5604
5605static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5606{
5607 int err;
5608
5609 if (!pin)
5610 return 0;
5611
5612 spec->multiout.hp_nid = 0x9;
5613 spec->hp_independent_mode_index = 1;
5614
5615 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5616 "Headphone Playback Volume",
5617 HDA_COMPOSE_AMP_VAL(
5618 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5619 if (err < 0)
5620 return err;
5621
5622 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5623 "Headphone Playback Switch",
5624 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5625 if (err < 0)
5626 return err;
5627
5628 create_hp_imux(spec);
5629 return 0;
5630}
5631
5632/* create playback/capture controls for input pins */
5633static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
5634 const struct auto_pin_cfg *cfg)
5635{
5636 static char *labels[] = {
5637 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5638 };
5639 struct hda_input_mux *imux = &spec->private_imux[0];
5640 int i, err, idx = 0;
5641
5642 for (i = 0; i < AUTO_PIN_LAST; i++) {
5643 if (!cfg->input_pins[i])
5644 continue;
5645
5646 switch (cfg->input_pins[i]) {
5647 case 0x2b: /* Mic */
5648 idx = 0;
5649 break;
5650
5651 case 0x2a: /* Line In */
5652 idx = 1;
5653 break;
5654
5655 case 0x29: /* Front Mic */
5656 idx = 2;
5657 break;
5658 }
5659 err = via_new_analog_input(spec, labels[i], idx, 0x21);
5660 if (err < 0)
5661 return err;
5662 imux->items[imux->num_items].label = labels[i];
5663 imux->items[imux->num_items].index = idx;
5664 imux->num_items++;
5665 }
5666
5667 /* build volume/mute control of loopback */
5668 err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
5669 if (err < 0)
5670 return err;
5671
5672 /* for internal loopback recording select */
5673 imux->items[imux->num_items].label = "Stereo Mixer";
5674 imux->items[imux->num_items].index = 3;
5675 imux->num_items++;
5676
5677 /* for digital mic select */
5678 imux->items[imux->num_items].label = "Digital Mic";
5679 imux->items[imux->num_items].index = 4;
5680 imux->num_items++;
5681
5682 return 0;
5683}
5684
5685static int vt2002P_parse_auto_config(struct hda_codec *codec)
5686{
5687 struct via_spec *spec = codec->spec;
5688 int err;
5689
5690
5691 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5692 if (err < 0)
5693 return err;
5694
5695 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5696 if (err < 0)
5697 return err;
5698
5699 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5700 return 0; /* can't find valid BIOS pin config */
5701
5702 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5703 if (err < 0)
5704 return err;
5705 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5706 if (err < 0)
5707 return err;
5708 err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
5709 if (err < 0)
5710 return err;
5711
5712 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5713
5714 fill_dig_outs(codec);
5715
5716 if (spec->kctls.list)
5717 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5718
5719 spec->input_mux = &spec->private_imux[0];
5720
5721 if (spec->hp_mux)
5722 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5723
5724 return 1;
5725}
5726
5727#ifdef CONFIG_SND_HDA_POWER_SAVE
5728static struct hda_amp_list vt2002P_loopbacks[] = {
5729 { 0x21, HDA_INPUT, 0 },
5730 { 0x21, HDA_INPUT, 1 },
5731 { 0x21, HDA_INPUT, 2 },
5732 { } /* end */
5733};
5734#endif
5735
5736
5737/* patch for vt2002P */
5738static int patch_vt2002P(struct hda_codec *codec)
5739{
5740 struct via_spec *spec;
5741 int err;
5742
5743 /* create a codec specific record */
5744 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5745 if (spec == NULL)
5746 return -ENOMEM;
5747
5748 codec->spec = spec;
5749
5750 /* automatic parse from the BIOS config */
5751 err = vt2002P_parse_auto_config(codec);
5752 if (err < 0) {
5753 via_free(codec);
5754 return err;
5755 } else if (!err) {
5756 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5757 "from BIOS. Using genenic mode...\n");
5758 }
5759
5760 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5761 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5762
5763 spec->stream_name_analog = "VT2002P Analog";
5764 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5765 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5766
5767 spec->stream_name_digital = "VT2002P Digital";
5768 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5769
5770 if (!spec->adc_nids && spec->input_mux) {
5771 spec->adc_nids = vt2002P_adc_nids;
5772 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5773 get_mux_nids(codec);
5774 override_mic_boost(codec, 0x2b, 0, 3, 40);
5775 override_mic_boost(codec, 0x29, 0, 3, 40);
5776 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5777 spec->num_mixers++;
5778 }
5779
5780 codec->patch_ops = via_patch_ops;
5781
5782 codec->patch_ops.init = via_auto_init;
5783 codec->patch_ops.unsol_event = via_unsol_event;
5784
5785#ifdef CONFIG_SND_HDA_POWER_SAVE
5786 spec->loopback.amplist = vt2002P_loopbacks;
5787#endif
5788
5789 return 0;
5790}
5791
5792/* for vt1812 */
5793
5794/* capture mixer elements */
5795static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5796 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5797 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5798 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5799 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5800 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5801 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5802 HDA_INPUT),
5803 {
5804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5805 /* The multiple "Capture Source" controls confuse alsamixer
5806 * So call somewhat different..
5807 */
5808 .name = "Input Source",
5809 .count = 2,
5810 .info = via_mux_enum_info,
5811 .get = via_mux_enum_get,
5812 .put = via_mux_enum_put,
5813 },
5814 { } /* end */
5815};
5816
5817static struct hda_verb vt1812_volume_init_verbs[] = {
5818 /*
5819 * Unmute ADC0-1 and set the default input to mic-in
5820 */
5821 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5822 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5823
5824
5825 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5826 * mixer widget
5827 */
5828 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5829 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5830 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5831 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5832 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5833 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5834
5835 /* MUX Indices: Mic = 0 */
5836 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5837 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5838
5839 /* PW9 Output enable */
5840 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5841
5842 /* Enable Boost Volume backdoor */
5843 {0x1, 0xfb9, 0x24},
5844
5845 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5846 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5847 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5848 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5849 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5850 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5851 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5852 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5853 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5854 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5855 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5856
5857 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5858 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5859 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5860 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5861 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5862 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5863
5864 /* Enable AOW0 to MW9 */
5865 {0x1, 0xfb8, 0xa8},
5866 { }
5867};
5868
5869
5870static struct hda_verb vt1812_uniwill_init_verbs[] = {
5871 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5872 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5873 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5874 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5875 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5876 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5877 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5878 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5879 { }
5880};
5881
5882static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5883 .substreams = 2,
5884 .channels_min = 2,
5885 .channels_max = 2,
5886 .nid = 0x8, /* NID to query formats and rates */
5887 .ops = {
5888 .open = via_playback_pcm_open,
5889 .prepare = via_playback_multi_pcm_prepare,
5890 .cleanup = via_playback_multi_pcm_cleanup,
5891 .close = via_pcm_open_close,
5892 },
5893};
5894
5895static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5896 .substreams = 2,
5897 .channels_min = 2,
5898 .channels_max = 2,
5899 .nid = 0x10, /* NID to query formats and rates */
5900 .ops = {
5901 .open = via_pcm_open_close,
5902 .prepare = via_capture_pcm_prepare,
5903 .cleanup = via_capture_pcm_cleanup,
5904 .close = via_pcm_open_close,
5905 },
5906};
5907
5908static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5909 .substreams = 1,
5910 .channels_min = 2,
5911 .channels_max = 2,
5912 /* NID is set in via_build_pcms */
5913 .ops = {
5914 .open = via_dig_playback_pcm_open,
5915 .close = via_dig_playback_pcm_close,
5916 .prepare = via_dig_playback_pcm_prepare,
5917 .cleanup = via_dig_playback_pcm_cleanup
5918 },
5919};
5920/* fill in the dac_nids table from the parsed pin configuration */
5921static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5922 const struct auto_pin_cfg *cfg)
5923{
5924 spec->multiout.num_dacs = 1;
5925 spec->multiout.dac_nids = spec->private_dac_nids;
5926 if (cfg->line_out_pins[0])
5927 spec->multiout.dac_nids[0] = 0x8;
5928 return 0;
5929}
5930
5931
5932/* add playback controls from the parsed DAC table */
5933static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5934 const struct auto_pin_cfg *cfg)
5935{
5936 int err;
5937
5938 if (!cfg->line_out_pins[0])
5939 return -1;
5940
5941 /* Line-Out: PortE */
5942 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5943 "Master Front Playback Volume",
5944 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5945 if (err < 0)
5946 return err;
5947 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5948 "Master Front Playback Switch",
5949 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5950 if (err < 0)
5951 return err;
5952
5953 return 0;
5954}
5955
5956static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5957{
5958 int err;
5959
5960 if (!pin)
5961 return 0;
5962
5963 spec->multiout.hp_nid = 0x9;
5964 spec->hp_independent_mode_index = 1;
5965
5966
5967 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5968 "Headphone Playback Volume",
5969 HDA_COMPOSE_AMP_VAL(
5970 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5971 if (err < 0)
5972 return err;
5973
5974 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5975 "Headphone Playback Switch",
5976 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5977 if (err < 0)
5978 return err;
5979
5980 create_hp_imux(spec);
5981 return 0;
5982}
5983
5984/* create playback/capture controls for input pins */
5985static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
5986 const struct auto_pin_cfg *cfg)
5987{
5988 static char *labels[] = {
5989 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5990 };
5991 struct hda_input_mux *imux = &spec->private_imux[0];
5992 int i, err, idx = 0;
5993
5994 for (i = 0; i < AUTO_PIN_LAST; i++) {
5995 if (!cfg->input_pins[i])
5996 continue;
5997
5998 switch (cfg->input_pins[i]) {
5999 case 0x2b: /* Mic */
6000 idx = 0;
6001 break;
6002
6003 case 0x2a: /* Line In */
6004 idx = 1;
6005 break;
6006
6007 case 0x29: /* Front Mic */
6008 idx = 2;
6009 break;
6010 }
6011 err = via_new_analog_input(spec, labels[i], idx, 0x21);
6012 if (err < 0)
6013 return err;
6014 imux->items[imux->num_items].label = labels[i];
6015 imux->items[imux->num_items].index = idx;
6016 imux->num_items++;
6017 }
6018 /* build volume/mute control of loopback */
6019 err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
6020 if (err < 0)
6021 return err;
6022
6023 /* for internal loopback recording select */
6024 imux->items[imux->num_items].label = "Stereo Mixer";
6025 imux->items[imux->num_items].index = 5;
6026 imux->num_items++;
6027
6028 /* for digital mic select */
6029 imux->items[imux->num_items].label = "Digital Mic";
6030 imux->items[imux->num_items].index = 6;
6031 imux->num_items++;
6032
6033 return 0;
6034}
6035
6036static int vt1812_parse_auto_config(struct hda_codec *codec)
6037{
6038 struct via_spec *spec = codec->spec;
6039 int err;
6040
6041
6042 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6043 if (err < 0)
6044 return err;
6045 fill_dig_outs(codec);
6046 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6047 if (err < 0)
6048 return err;
6049
6050 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6051 return 0; /* can't find valid BIOS pin config */
6052
6053 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6054 if (err < 0)
6055 return err;
6056 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6057 if (err < 0)
6058 return err;
6059 err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
6060 if (err < 0)
6061 return err;
6062
6063 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6064
6065 fill_dig_outs(codec);
6066
6067 if (spec->kctls.list)
6068 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6069
6070 spec->input_mux = &spec->private_imux[0];
6071
6072 if (spec->hp_mux)
6073 spec->mixers[spec->num_mixers++] = via_hp_mixer;
6074
6075 return 1;
6076}
6077
6078#ifdef CONFIG_SND_HDA_POWER_SAVE
6079static struct hda_amp_list vt1812_loopbacks[] = {
6080 { 0x21, HDA_INPUT, 0 },
6081 { 0x21, HDA_INPUT, 1 },
6082 { 0x21, HDA_INPUT, 2 },
6083 { } /* end */
6084};
6085#endif
6086
6087
6088/* patch for vt1812 */
6089static int patch_vt1812(struct hda_codec *codec)
6090{
6091 struct via_spec *spec;
6092 int err;
6093
6094 /* create a codec specific record */
6095 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6096 if (spec == NULL)
6097 return -ENOMEM;
6098
6099 codec->spec = spec;
6100
6101 /* automatic parse from the BIOS config */
6102 err = vt1812_parse_auto_config(codec);
6103 if (err < 0) {
6104 via_free(codec);
6105 return err;
6106 } else if (!err) {
6107 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6108 "from BIOS. Using genenic mode...\n");
6109 }
6110
6111
6112 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6113 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6114
6115 spec->stream_name_analog = "VT1812 Analog";
6116 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6117 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6118
6119 spec->stream_name_digital = "VT1812 Digital";
6120 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6121
6122
6123 if (!spec->adc_nids && spec->input_mux) {
6124 spec->adc_nids = vt1812_adc_nids;
6125 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6126 get_mux_nids(codec);
6127 override_mic_boost(codec, 0x2b, 0, 3, 40);
6128 override_mic_boost(codec, 0x29, 0, 3, 40);
6129 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6130 spec->num_mixers++;
6131 }
6132
6133 codec->patch_ops = via_patch_ops;
6134
6135 codec->patch_ops.init = via_auto_init;
6136 codec->patch_ops.unsol_event = via_unsol_event;
6137
6138#ifdef CONFIG_SND_HDA_POWER_SAVE
6139 spec->loopback.amplist = vt1812_loopbacks;
6140#endif
3245 6141
3246 return 0; 6142 return 0;
3247} 6143}
@@ -3318,6 +6214,23 @@ static struct hda_codec_preset snd_hda_preset_via[] = {
3318 .patch = patch_vt1702}, 6214 .patch = patch_vt1702},
3319 { .id = 0x11067398, .name = "VT1702", 6215 { .id = 0x11067398, .name = "VT1702",
3320 .patch = patch_vt1702}, 6216 .patch = patch_vt1702},
6217 { .id = 0x11060428, .name = "VT1718S",
6218 .patch = patch_vt1718S},
6219 { .id = 0x11064428, .name = "VT1718S",
6220 .patch = patch_vt1718S},
6221 { .id = 0x11060441, .name = "VT2020",
6222 .patch = patch_vt1718S},
6223 { .id = 0x11064441, .name = "VT1828S",
6224 .patch = patch_vt1718S},
6225 { .id = 0x11060433, .name = "VT1716S",
6226 .patch = patch_vt1716S},
6227 { .id = 0x1106a721, .name = "VT1716S",
6228 .patch = patch_vt1716S},
6229 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6230 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6231 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6232 { .id = 0x11060440, .name = "VT1818S",
6233 .patch = patch_vt1708S},
3321 {} /* terminator */ 6234 {} /* terminator */
3322}; 6235};
3323 6236