blob: d1c3f8defc48d059f42124542d4e09b1fda000cf [file] [log] [blame]
Joseph Chanc577b8a2006-11-29 15:29:40 +01001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Lydia Wang8e865972009-10-10 19:08:52 +08004 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
Joseph Chanc577b8a2006-11-29 15:29:40 +01005 *
Lydia Wang8e865972009-10-10 19:08:52 +08006 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
Joseph Chanc577b8a2006-11-29 15:29:40 +01008 *
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24/* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
Lydia Wang377ff312009-10-10 19:08:55 +080025/* */
Joseph Chanc577b8a2006-11-29 15:29:40 +010026/* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
Lydia Wang377ff312009-10-10 19:08:55 +080027/* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28/* 2006-08-02 Lydia Wang Add support to VT1709 codec */
Joseph Chanc577b8a2006-11-29 15:29:40 +010029/* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
Lydia Wang377ff312009-10-10 19:08:55 +080030/* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31/* 2007-09-17 Lydia Wang Add VT1708B codec support */
Harald Welte76d9b0d2008-09-09 15:50:37 +080032/* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
Harald Weltefb4cb772008-09-09 15:53:36 +080033/* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
Lydia Wang377ff312009-10-10 19:08:55 +080034/* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35/* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36/* 2008-04-09 Lydia Wang Add Independent HP feature */
Harald Welte98aa34c2008-09-09 16:02:09 +080037/* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
Lydia Wang377ff312009-10-10 19:08:55 +080038/* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
Lydia Wang8e865972009-10-10 19:08:52 +080039/* 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 */
Lydia Wang36dd5c42009-10-20 13:18:04 +080044/* 2009-09-19 Lydia Wang Add support for VT1818S */
Lydia Wang377ff312009-10-10 19:08:55 +080045/* */
Joseph Chanc577b8a2006-11-29 15:29:40 +010046/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
47
48
Joseph Chanc577b8a2006-11-29 15:29:40 +010049#include <linux/init.h>
50#include <linux/delay.h>
51#include <linux/slab.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010052#include <sound/core.h>
Harald Welte0aa62ae2008-09-09 15:58:27 +080053#include <sound/asoundef.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010054#include "hda_codec.h"
55#include "hda_local.h"
Joseph Chanc577b8a2006-11-29 15:29:40 +010056
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010057#define NID_MAPPING (-1)
58
Joseph Chanc577b8a2006-11-29 15:29:40 +010059/* amp values */
60#define AMP_VAL_IDX_SHIFT 19
61#define AMP_VAL_IDX_MASK (0x0f<<19)
62
Joseph Chanc577b8a2006-11-29 15:29:40 +010063/* Pin Widget NID */
64#define VT1708_HP_NID 0x13
65#define VT1708_DIGOUT_NID 0x14
66#define VT1708_DIGIN_NID 0x16
Josepch Chanf7278fd2007-12-13 16:40:40 +010067#define VT1708_DIGIN_PIN 0x26
Harald Welted949cac2008-09-09 15:56:01 +080068#define VT1708_HP_PIN_NID 0x20
69#define VT1708_CD_PIN_NID 0x24
Joseph Chanc577b8a2006-11-29 15:29:40 +010070
71#define VT1709_HP_DAC_NID 0x28
72#define VT1709_DIGOUT_NID 0x13
73#define VT1709_DIGIN_NID 0x17
Josepch Chanf7278fd2007-12-13 16:40:40 +010074#define VT1709_DIGIN_PIN 0x25
75
76#define VT1708B_HP_NID 0x25
77#define VT1708B_DIGOUT_NID 0x12
78#define VT1708B_DIGIN_NID 0x15
79#define VT1708B_DIGIN_PIN 0x21
Joseph Chanc577b8a2006-11-29 15:29:40 +010080
Harald Welted949cac2008-09-09 15:56:01 +080081#define VT1708S_HP_NID 0x25
82#define VT1708S_DIGOUT_NID 0x12
83
84#define VT1702_HP_NID 0x17
85#define VT1702_DIGOUT_NID 0x11
86
Harald Welted7426322008-09-15 22:43:23 +080087enum VIA_HDA_CODEC {
88 UNKNOWN = -1,
89 VT1708,
90 VT1709_10CH,
91 VT1709_6CH,
92 VT1708B_8CH,
93 VT1708B_4CH,
94 VT1708S,
Lydia Wang518bf3b2009-10-10 19:07:29 +080095 VT1708BCE,
Harald Welted7426322008-09-15 22:43:23 +080096 VT1702,
Lydia Wangeb7188c2009-10-10 19:08:34 +080097 VT1718S,
Lydia Wangf3db4232009-10-10 19:08:41 +080098 VT1716S,
Lydia Wang25eaba22009-10-10 19:08:43 +080099 VT2002P,
Lydia Wangab6734e2009-10-10 19:08:46 +0800100 VT1812,
Harald Welted7426322008-09-15 22:43:23 +0800101 CODEC_TYPES,
102};
103
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800104struct via_spec {
105 /* codec parameterization */
Lydia Wangf3db4232009-10-10 19:08:41 +0800106 struct snd_kcontrol_new *mixers[6];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800107 unsigned int num_mixers;
108
109 struct hda_verb *init_verbs[5];
110 unsigned int num_iverbs;
111
112 char *stream_name_analog;
113 struct hda_pcm_stream *stream_analog_playback;
114 struct hda_pcm_stream *stream_analog_capture;
115
116 char *stream_name_digital;
117 struct hda_pcm_stream *stream_digital_playback;
118 struct hda_pcm_stream *stream_digital_capture;
119
120 /* playback */
121 struct hda_multi_out multiout;
122 hda_nid_t slave_dig_outs[2];
123
124 /* capture */
125 unsigned int num_adc_nids;
126 hda_nid_t *adc_nids;
127 hda_nid_t mux_nids[3];
128 hda_nid_t dig_in_nid;
129 hda_nid_t dig_in_pin;
130
131 /* capture source */
132 const struct hda_input_mux *input_mux;
133 unsigned int cur_mux[3];
134
135 /* PCM information */
136 struct hda_pcm pcm_rec[3];
137
138 /* dynamic controls, init_verbs and input_mux */
139 struct auto_pin_cfg autocfg;
140 struct snd_array kctls;
141 struct hda_input_mux private_imux[2];
142 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
143
144 /* HP mode source */
145 const struct hda_input_mux *hp_mux;
146 unsigned int hp_independent_mode;
147 unsigned int hp_independent_mode_index;
148 unsigned int smart51_enabled;
Lydia Wangf3db4232009-10-10 19:08:41 +0800149 unsigned int dmic_enabled;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800150 enum VIA_HDA_CODEC codec_type;
151
152 /* work to check hp jack state */
153 struct hda_codec *codec;
154 struct delayed_work vt1708_hp_work;
155 int vt1708_jack_detectect;
156 int vt1708_hp_present;
157#ifdef CONFIG_SND_HDA_POWER_SAVE
158 struct hda_loopback_check loopback;
159#endif
160};
161
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100162static struct via_spec * via_new_spec(struct hda_codec *codec)
163{
164 struct via_spec *spec;
165
166 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
167 if (spec == NULL)
168 return NULL;
169
170 codec->spec = spec;
171 spec->codec = codec;
172 return spec;
173}
174
Lydia Wang744ff5f2009-10-10 19:07:26 +0800175static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800176{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800177 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800178 u16 ven_id = vendor_id >> 16;
179 u16 dev_id = vendor_id & 0xffff;
180 enum VIA_HDA_CODEC codec_type;
181
182 /* get codec type */
183 if (ven_id != 0x1106)
184 codec_type = UNKNOWN;
185 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
186 codec_type = VT1708;
187 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
188 codec_type = VT1709_10CH;
189 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
190 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800191 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800192 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800193 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
194 codec_type = VT1708BCE;
195 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800196 codec_type = VT1708B_4CH;
197 else if ((dev_id & 0xfff) == 0x397
198 && (dev_id >> 12) < 8)
199 codec_type = VT1708S;
200 else if ((dev_id & 0xfff) == 0x398
201 && (dev_id >> 12) < 8)
202 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800203 else if ((dev_id & 0xfff) == 0x428
204 && (dev_id >> 12) < 8)
205 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800206 else if (dev_id == 0x0433 || dev_id == 0xa721)
207 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800208 else if (dev_id == 0x0441 || dev_id == 0x4441)
209 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800210 else if (dev_id == 0x0438 || dev_id == 0x4438)
211 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800212 else if (dev_id == 0x0448)
213 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800214 else if (dev_id == 0x0440)
215 codec_type = VT1708S;
Harald Welted7426322008-09-15 22:43:23 +0800216 else
217 codec_type = UNKNOWN;
218 return codec_type;
219};
220
Harald Welte69e52a82008-09-09 15:57:32 +0800221#define VIA_HP_EVENT 0x01
222#define VIA_GPIO_EVENT 0x02
Lydia Wanga34df192009-10-10 19:08:01 +0800223#define VIA_JACK_EVENT 0x04
Lydia Wangf3db4232009-10-10 19:08:41 +0800224#define VIA_MONO_EVENT 0x08
Lydia Wang25eaba22009-10-10 19:08:43 +0800225#define VIA_SPEAKER_EVENT 0x10
226#define VIA_BIND_HP_EVENT 0x20
Harald Welte69e52a82008-09-09 15:57:32 +0800227
Joseph Chanc577b8a2006-11-29 15:29:40 +0100228enum {
229 VIA_CTL_WIDGET_VOL,
230 VIA_CTL_WIDGET_MUTE,
Lydia Wangf5271102009-10-10 19:07:35 +0800231 VIA_CTL_WIDGET_ANALOG_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800232 VIA_CTL_WIDGET_BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100233};
234
235enum {
Harald Welteeb14a462008-09-09 15:40:38 +0800236 AUTO_SEQ_FRONT = 0,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100237 AUTO_SEQ_SURROUND,
238 AUTO_SEQ_CENLFE,
239 AUTO_SEQ_SIDE
240};
241
Lydia Wangf5271102009-10-10 19:07:35 +0800242static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
243static void set_jack_power_state(struct hda_codec *codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800244static int is_aa_path_mute(struct hda_codec *codec);
245
246static void vt1708_start_hp_work(struct via_spec *spec)
247{
248 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
249 return;
250 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
251 !spec->vt1708_jack_detectect);
252 if (!delayed_work_pending(&spec->vt1708_hp_work))
253 schedule_delayed_work(&spec->vt1708_hp_work,
254 msecs_to_jiffies(100));
255}
256
257static void vt1708_stop_hp_work(struct via_spec *spec)
258{
259 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
260 return;
261 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
262 && !is_aa_path_mute(spec->codec))
263 return;
264 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
265 !spec->vt1708_jack_detectect);
266 cancel_delayed_work(&spec->vt1708_hp_work);
267 flush_scheduled_work();
268}
Lydia Wangf5271102009-10-10 19:07:35 +0800269
Lydia Wang25eaba22009-10-10 19:08:43 +0800270
Lydia Wangf5271102009-10-10 19:07:35 +0800271static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
272 struct snd_ctl_elem_value *ucontrol)
273{
274 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
275 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
276
277 set_jack_power_state(codec);
278 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800279 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
280 if (is_aa_path_mute(codec))
281 vt1708_start_hp_work(codec->spec);
282 else
283 vt1708_stop_hp_work(codec->spec);
284 }
Lydia Wangf5271102009-10-10 19:07:35 +0800285 return change;
286}
287
288/* modify .put = snd_hda_mixer_amp_switch_put */
289#define ANALOG_INPUT_MUTE \
290 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
291 .name = NULL, \
292 .index = 0, \
293 .info = snd_hda_mixer_amp_switch_info, \
294 .get = snd_hda_mixer_amp_switch_get, \
295 .put = analog_input_switch_put, \
296 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
297
Lydia Wang25eaba22009-10-10 19:08:43 +0800298static void via_hp_bind_automute(struct hda_codec *codec);
299
300static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
301 struct snd_ctl_elem_value *ucontrol)
302{
303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
304 struct via_spec *spec = codec->spec;
305 int i;
306 int change = 0;
307
308 long *valp = ucontrol->value.integer.value;
309 int lmute, rmute;
310 if (strstr(kcontrol->id.name, "Switch") == NULL) {
311 snd_printd("Invalid control!\n");
312 return change;
313 }
314 change = snd_hda_mixer_amp_switch_put(kcontrol,
315 ucontrol);
316 /* Get mute value */
317 lmute = *valp ? 0 : HDA_AMP_MUTE;
318 valp++;
319 rmute = *valp ? 0 : HDA_AMP_MUTE;
320
321 /* Set hp pins */
322 if (!spec->hp_independent_mode) {
323 for (i = 0; i < spec->autocfg.hp_outs; i++) {
324 snd_hda_codec_amp_update(
325 codec, spec->autocfg.hp_pins[i],
326 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
327 lmute);
328 snd_hda_codec_amp_update(
329 codec, spec->autocfg.hp_pins[i],
330 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
331 rmute);
332 }
333 }
334
335 if (!lmute && !rmute) {
336 /* Line Outs */
337 for (i = 0; i < spec->autocfg.line_outs; i++)
338 snd_hda_codec_amp_stereo(
339 codec, spec->autocfg.line_out_pins[i],
340 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
341 /* Speakers */
342 for (i = 0; i < spec->autocfg.speaker_outs; i++)
343 snd_hda_codec_amp_stereo(
344 codec, spec->autocfg.speaker_pins[i],
345 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
346 /* unmute */
347 via_hp_bind_automute(codec);
348
349 } else {
350 if (lmute) {
351 /* Mute all left channels */
352 for (i = 1; i < spec->autocfg.line_outs; i++)
353 snd_hda_codec_amp_update(
354 codec,
355 spec->autocfg.line_out_pins[i],
356 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
357 lmute);
358 for (i = 0; i < spec->autocfg.speaker_outs; i++)
359 snd_hda_codec_amp_update(
360 codec,
361 spec->autocfg.speaker_pins[i],
362 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
363 lmute);
364 }
365 if (rmute) {
366 /* mute all right channels */
367 for (i = 1; i < spec->autocfg.line_outs; i++)
368 snd_hda_codec_amp_update(
369 codec,
370 spec->autocfg.line_out_pins[i],
371 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
372 rmute);
373 for (i = 0; i < spec->autocfg.speaker_outs; i++)
374 snd_hda_codec_amp_update(
375 codec,
376 spec->autocfg.speaker_pins[i],
377 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
378 rmute);
379 }
380 }
381 return change;
382}
383
384#define BIND_PIN_MUTE \
385 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
386 .name = NULL, \
387 .index = 0, \
388 .info = snd_hda_mixer_amp_switch_info, \
389 .get = snd_hda_mixer_amp_switch_get, \
390 .put = bind_pin_switch_put, \
391 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
392
Lydia Wang71eb7dc2009-10-10 19:08:49 +0800393static struct snd_kcontrol_new via_control_templates[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100394 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
395 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Lydia Wangf5271102009-10-10 19:07:35 +0800396 ANALOG_INPUT_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800397 BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100398};
399
Joseph Chanc577b8a2006-11-29 15:29:40 +0100400static hda_nid_t vt1708_adc_nids[2] = {
401 /* ADC1-2 */
402 0x15, 0x27
403};
404
405static hda_nid_t vt1709_adc_nids[3] = {
406 /* ADC1-2 */
407 0x14, 0x15, 0x16
408};
409
Josepch Chanf7278fd2007-12-13 16:40:40 +0100410static hda_nid_t vt1708B_adc_nids[2] = {
411 /* ADC1-2 */
412 0x13, 0x14
413};
414
Harald Welted949cac2008-09-09 15:56:01 +0800415static hda_nid_t vt1708S_adc_nids[2] = {
416 /* ADC1-2 */
417 0x13, 0x14
418};
419
420static hda_nid_t vt1702_adc_nids[3] = {
421 /* ADC1-2 */
422 0x12, 0x20, 0x1F
423};
424
Lydia Wangeb7188c2009-10-10 19:08:34 +0800425static hda_nid_t vt1718S_adc_nids[2] = {
426 /* ADC1-2 */
427 0x10, 0x11
428};
429
Lydia Wangf3db4232009-10-10 19:08:41 +0800430static hda_nid_t vt1716S_adc_nids[2] = {
431 /* ADC1-2 */
432 0x13, 0x14
433};
434
Lydia Wang25eaba22009-10-10 19:08:43 +0800435static hda_nid_t vt2002P_adc_nids[2] = {
436 /* ADC1-2 */
437 0x10, 0x11
438};
439
Lydia Wangab6734e2009-10-10 19:08:46 +0800440static hda_nid_t vt1812_adc_nids[2] = {
441 /* ADC1-2 */
442 0x10, 0x11
443};
444
445
Joseph Chanc577b8a2006-11-29 15:29:40 +0100446/* add dynamic controls */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200447static int __via_add_control(struct via_spec *spec, int type, const char *name,
448 int idx, unsigned long val)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100449{
450 struct snd_kcontrol_new *knew;
451
Takashi Iwai603c4012008-07-30 15:01:44 +0200452 snd_array_init(&spec->kctls, sizeof(*knew), 32);
453 knew = snd_array_new(&spec->kctls);
454 if (!knew)
455 return -ENOMEM;
Lydia Wang71eb7dc2009-10-10 19:08:49 +0800456 *knew = via_control_templates[type];
Joseph Chanc577b8a2006-11-29 15:29:40 +0100457 knew->name = kstrdup(name, GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100458 if (!knew->name)
459 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100460 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100461 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100462 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100463 return 0;
464}
465
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200466#define via_add_control(spec, type, name, val) \
467 __via_add_control(spec, type, name, 0, val)
468
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100469static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
470 struct snd_kcontrol_new *tmpl)
471{
472 struct snd_kcontrol_new *knew;
473
474 snd_array_init(&spec->kctls, sizeof(*knew), 32);
475 knew = snd_array_new(&spec->kctls);
476 if (!knew)
477 return NULL;
478 *knew = *tmpl;
479 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
480 if (!knew->name)
481 return NULL;
Takashi Iwaib3314392010-04-14 14:33:57 +0200482 return knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100483}
484
Takashi Iwai603c4012008-07-30 15:01:44 +0200485static void via_free_kctls(struct hda_codec *codec)
486{
487 struct via_spec *spec = codec->spec;
488
489 if (spec->kctls.list) {
490 struct snd_kcontrol_new *kctl = spec->kctls.list;
491 int i;
492 for (i = 0; i < spec->kctls.used; i++)
493 kfree(kctl[i].name);
494 }
495 snd_array_free(&spec->kctls);
496}
497
Joseph Chanc577b8a2006-11-29 15:29:40 +0100498/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800499static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200500 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100501{
502 char name[32];
503 int err;
504
505 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200506 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100507 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
508 if (err < 0)
509 return err;
510 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200511 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100512 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
513 if (err < 0)
514 return err;
515 return 0;
516}
517
518static void via_auto_set_output_and_unmute(struct hda_codec *codec,
519 hda_nid_t nid, int pin_type,
520 int dac_idx)
521{
522 /* set as output */
523 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
524 pin_type);
525 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
526 AMP_OUT_UNMUTE);
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200527 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
Lydia Wang377ff312009-10-10 19:08:55 +0800528 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200529 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100530}
531
532
533static void via_auto_init_multi_out(struct hda_codec *codec)
534{
535 struct via_spec *spec = codec->spec;
536 int i;
537
538 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
539 hda_nid_t nid = spec->autocfg.line_out_pins[i];
540 if (nid)
541 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
542 }
543}
544
545static void via_auto_init_hp_out(struct hda_codec *codec)
546{
547 struct via_spec *spec = codec->spec;
548 hda_nid_t pin;
Lydia Wang25eaba22009-10-10 19:08:43 +0800549 int i;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100550
Lydia Wang25eaba22009-10-10 19:08:43 +0800551 for (i = 0; i < spec->autocfg.hp_outs; i++) {
552 pin = spec->autocfg.hp_pins[i];
553 if (pin) /* connect to front */
554 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
555 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100556}
557
Clemens Ladisch32e01912010-07-12 16:28:50 +0200558static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
559
Joseph Chanc577b8a2006-11-29 15:29:40 +0100560static void via_auto_init_analog_input(struct hda_codec *codec)
561{
562 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200563 const struct auto_pin_cfg *cfg = &spec->autocfg;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200564 unsigned int ctl;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100565 int i;
566
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200567 for (i = 0; i < cfg->num_inputs; i++) {
568 hda_nid_t nid = cfg->inputs[i].pin;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200569 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
570 ctl = PIN_OUT;
Takashi Iwai86e29592010-09-09 14:50:17 +0200571 else if (i == AUTO_PIN_MIC)
Clemens Ladisch32e01912010-07-12 16:28:50 +0200572 ctl = PIN_VREF50;
573 else
574 ctl = PIN_IN;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100575 snd_hda_codec_write(codec, nid, 0,
Clemens Ladisch32e01912010-07-12 16:28:50 +0200576 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100577 }
578}
Lydia Wangf5271102009-10-10 19:07:35 +0800579
580static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
581 unsigned int *affected_parm)
582{
583 unsigned parm;
584 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
585 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
586 >> AC_DEFCFG_MISC_SHIFT
587 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Takashi Iwaid56757a2009-11-18 08:00:14 +0100588 unsigned present = snd_hda_jack_detect(codec, nid);
Lydia Wang1564b282009-10-10 19:07:52 +0800589 struct via_spec *spec = codec->spec;
590 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
591 || ((no_presence || present)
592 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800593 *affected_parm = AC_PWRST_D0; /* if it's connected */
594 parm = AC_PWRST_D0;
595 } else
596 parm = AC_PWRST_D3;
597
598 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
599}
600
601static void set_jack_power_state(struct hda_codec *codec)
602{
603 struct via_spec *spec = codec->spec;
604 int imux_is_smixer;
605 unsigned int parm;
606
607 if (spec->codec_type == VT1702) {
608 imux_is_smixer = snd_hda_codec_read(
609 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
610 /* inputs */
611 /* PW 1/2/5 (14h/15h/18h) */
612 parm = AC_PWRST_D3;
613 set_pin_power_state(codec, 0x14, &parm);
614 set_pin_power_state(codec, 0x15, &parm);
615 set_pin_power_state(codec, 0x18, &parm);
616 if (imux_is_smixer)
617 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
618 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
619 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
620 parm);
621 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
622 parm);
623 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
624 parm);
625 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
626 parm);
627
628 /* outputs */
629 /* PW 3/4 (16h/17h) */
630 parm = AC_PWRST_D3;
631 set_pin_power_state(codec, 0x16, &parm);
632 set_pin_power_state(codec, 0x17, &parm);
633 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
634 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
635 imux_is_smixer ? AC_PWRST_D0 : parm);
636 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
637 parm);
638 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
639 parm);
640 } else if (spec->codec_type == VT1708B_8CH
641 || spec->codec_type == VT1708B_4CH
642 || spec->codec_type == VT1708S) {
643 /* SW0 (17h) = stereo mixer */
644 int is_8ch = spec->codec_type != VT1708B_4CH;
645 imux_is_smixer = snd_hda_codec_read(
646 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
647 == ((spec->codec_type == VT1708S) ? 5 : 0);
648 /* inputs */
649 /* PW 1/2/5 (1ah/1bh/1eh) */
650 parm = AC_PWRST_D3;
651 set_pin_power_state(codec, 0x1a, &parm);
652 set_pin_power_state(codec, 0x1b, &parm);
653 set_pin_power_state(codec, 0x1e, &parm);
654 if (imux_is_smixer)
655 parm = AC_PWRST_D0;
656 /* SW0 (17h), AIW 0/1 (13h/14h) */
657 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
658 parm);
659 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
660 parm);
661 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
662 parm);
663
664 /* outputs */
665 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
666 parm = AC_PWRST_D3;
667 set_pin_power_state(codec, 0x19, &parm);
Clemens Ladisch32e01912010-07-12 16:28:50 +0200668 if (spec->smart51_enabled)
669 parm = AC_PWRST_D0;
Lydia Wangf5271102009-10-10 19:07:35 +0800670 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
671 parm);
672 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
673 parm);
674
675 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
676 if (is_8ch) {
677 parm = AC_PWRST_D3;
678 set_pin_power_state(codec, 0x22, &parm);
Clemens Ladisch32e01912010-07-12 16:28:50 +0200679 if (spec->smart51_enabled)
680 parm = AC_PWRST_D0;
Lydia Wangf5271102009-10-10 19:07:35 +0800681 snd_hda_codec_write(codec, 0x26, 0,
682 AC_VERB_SET_POWER_STATE, parm);
683 snd_hda_codec_write(codec, 0x24, 0,
684 AC_VERB_SET_POWER_STATE, parm);
685 }
686
687 /* PW 3/4/7 (1ch/1dh/23h) */
688 parm = AC_PWRST_D3;
689 /* force to D0 for internal Speaker */
690 set_pin_power_state(codec, 0x1c, &parm);
691 set_pin_power_state(codec, 0x1d, &parm);
692 if (is_8ch)
693 set_pin_power_state(codec, 0x23, &parm);
694 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
695 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
696 imux_is_smixer ? AC_PWRST_D0 : parm);
697 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
698 parm);
699 if (is_8ch) {
700 snd_hda_codec_write(codec, 0x25, 0,
701 AC_VERB_SET_POWER_STATE, parm);
702 snd_hda_codec_write(codec, 0x27, 0,
703 AC_VERB_SET_POWER_STATE, parm);
704 }
Lydia Wangeb7188c2009-10-10 19:08:34 +0800705 } else if (spec->codec_type == VT1718S) {
706 /* MUX6 (1eh) = stereo mixer */
707 imux_is_smixer = snd_hda_codec_read(
708 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
709 /* inputs */
710 /* PW 5/6/7 (29h/2ah/2bh) */
711 parm = AC_PWRST_D3;
712 set_pin_power_state(codec, 0x29, &parm);
713 set_pin_power_state(codec, 0x2a, &parm);
714 set_pin_power_state(codec, 0x2b, &parm);
715 if (imux_is_smixer)
716 parm = AC_PWRST_D0;
717 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
718 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
719 parm);
720 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
721 parm);
722 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
723 parm);
724 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
725 parm);
726
727 /* outputs */
728 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
729 parm = AC_PWRST_D3;
730 set_pin_power_state(codec, 0x27, &parm);
731 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
732 parm);
733 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
734 parm);
735
736 /* PW2 (26h), AOW2 (ah) */
737 parm = AC_PWRST_D3;
738 set_pin_power_state(codec, 0x26, &parm);
739 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
740 parm);
741
742 /* PW0/1 (24h/25h) */
743 parm = AC_PWRST_D3;
744 set_pin_power_state(codec, 0x24, &parm);
745 set_pin_power_state(codec, 0x25, &parm);
746 if (!spec->hp_independent_mode) /* check for redirected HP */
747 set_pin_power_state(codec, 0x28, &parm);
748 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
749 parm);
750 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
751 parm);
752 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
753 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
754 imux_is_smixer ? AC_PWRST_D0 : parm);
755 if (spec->hp_independent_mode) {
756 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
757 parm = AC_PWRST_D3;
758 set_pin_power_state(codec, 0x28, &parm);
759 snd_hda_codec_write(codec, 0x1b, 0,
760 AC_VERB_SET_POWER_STATE, parm);
761 snd_hda_codec_write(codec, 0x34, 0,
762 AC_VERB_SET_POWER_STATE, parm);
763 snd_hda_codec_write(codec, 0xc, 0,
764 AC_VERB_SET_POWER_STATE, parm);
765 }
Lydia Wangf3db4232009-10-10 19:08:41 +0800766 } else if (spec->codec_type == VT1716S) {
767 unsigned int mono_out, present;
768 /* SW0 (17h) = stereo mixer */
769 imux_is_smixer = snd_hda_codec_read(
770 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
771 /* inputs */
772 /* PW 1/2/5 (1ah/1bh/1eh) */
773 parm = AC_PWRST_D3;
774 set_pin_power_state(codec, 0x1a, &parm);
775 set_pin_power_state(codec, 0x1b, &parm);
776 set_pin_power_state(codec, 0x1e, &parm);
777 if (imux_is_smixer)
778 parm = AC_PWRST_D0;
779 /* SW0 (17h), AIW0(13h) */
780 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
781 parm);
782 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
783 parm);
784
785 parm = AC_PWRST_D3;
786 set_pin_power_state(codec, 0x1e, &parm);
787 /* PW11 (22h) */
788 if (spec->dmic_enabled)
789 set_pin_power_state(codec, 0x22, &parm);
790 else
791 snd_hda_codec_write(
792 codec, 0x22, 0,
793 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
794
795 /* SW2(26h), AIW1(14h) */
796 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
797 parm);
798 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
799 parm);
800
801 /* outputs */
802 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
803 parm = AC_PWRST_D3;
804 set_pin_power_state(codec, 0x19, &parm);
805 /* Smart 5.1 PW2(1bh) */
806 if (spec->smart51_enabled)
807 set_pin_power_state(codec, 0x1b, &parm);
808 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
809 parm);
810 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
811 parm);
812
813 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
814 parm = AC_PWRST_D3;
815 set_pin_power_state(codec, 0x23, &parm);
816 /* Smart 5.1 PW1(1ah) */
817 if (spec->smart51_enabled)
818 set_pin_power_state(codec, 0x1a, &parm);
819 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
820 parm);
821
822 /* Smart 5.1 PW5(1eh) */
823 if (spec->smart51_enabled)
824 set_pin_power_state(codec, 0x1e, &parm);
825 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
826 parm);
827
828 /* Mono out */
829 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
Takashi Iwaid56757a2009-11-18 08:00:14 +0100830 present = snd_hda_jack_detect(codec, 0x1c);
Lydia Wangf3db4232009-10-10 19:08:41 +0800831 if (present)
832 mono_out = 0;
833 else {
Takashi Iwaid56757a2009-11-18 08:00:14 +0100834 present = snd_hda_jack_detect(codec, 0x1d);
Lydia Wangf3db4232009-10-10 19:08:41 +0800835 if (!spec->hp_independent_mode && present)
836 mono_out = 0;
837 else
838 mono_out = 1;
839 }
840 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
841 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
842 parm);
843 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
844 parm);
845 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
846 parm);
847
848 /* PW 3/4 (1ch/1dh) */
849 parm = AC_PWRST_D3;
850 set_pin_power_state(codec, 0x1c, &parm);
851 set_pin_power_state(codec, 0x1d, &parm);
852 /* HP Independent Mode, power on AOW3 */
853 if (spec->hp_independent_mode)
854 snd_hda_codec_write(codec, 0x25, 0,
855 AC_VERB_SET_POWER_STATE, parm);
856
857 /* force to D0 for internal Speaker */
858 /* MW0 (16h), AOW0 (10h) */
859 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
860 imux_is_smixer ? AC_PWRST_D0 : parm);
861 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
862 mono_out ? AC_PWRST_D0 : parm);
Lydia Wang25eaba22009-10-10 19:08:43 +0800863 } else if (spec->codec_type == VT2002P) {
864 unsigned int present;
865 /* MUX9 (1eh) = stereo mixer */
866 imux_is_smixer = snd_hda_codec_read(
867 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
868 /* inputs */
869 /* PW 5/6/7 (29h/2ah/2bh) */
870 parm = AC_PWRST_D3;
871 set_pin_power_state(codec, 0x29, &parm);
872 set_pin_power_state(codec, 0x2a, &parm);
873 set_pin_power_state(codec, 0x2b, &parm);
874 if (imux_is_smixer)
875 parm = AC_PWRST_D0;
876 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
877 snd_hda_codec_write(codec, 0x1e, 0,
878 AC_VERB_SET_POWER_STATE, parm);
879 snd_hda_codec_write(codec, 0x1f, 0,
880 AC_VERB_SET_POWER_STATE, parm);
881 snd_hda_codec_write(codec, 0x10, 0,
882 AC_VERB_SET_POWER_STATE, parm);
883 snd_hda_codec_write(codec, 0x11, 0,
884 AC_VERB_SET_POWER_STATE, parm);
885
886 /* outputs */
887 /* AOW0 (8h)*/
888 snd_hda_codec_write(codec, 0x8, 0,
889 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
890
891 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
892 parm = AC_PWRST_D3;
893 set_pin_power_state(codec, 0x26, &parm);
894 snd_hda_codec_write(codec, 0x1c, 0,
895 AC_VERB_SET_POWER_STATE, parm);
896 snd_hda_codec_write(codec, 0x37,
897 0, AC_VERB_SET_POWER_STATE, parm);
898
899 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
900 parm = AC_PWRST_D3;
901 set_pin_power_state(codec, 0x25, &parm);
902 snd_hda_codec_write(codec, 0x19, 0,
903 AC_VERB_SET_POWER_STATE, parm);
904 snd_hda_codec_write(codec, 0x35, 0,
905 AC_VERB_SET_POWER_STATE, parm);
906 if (spec->hp_independent_mode) {
907 snd_hda_codec_write(codec, 0x9, 0,
908 AC_VERB_SET_POWER_STATE, parm);
909 }
910
911 /* Class-D */
912 /* PW0 (24h), MW0(18h), MUX0(34h) */
Takashi Iwaid56757a2009-11-18 08:00:14 +0100913 present = snd_hda_jack_detect(codec, 0x25);
Lydia Wang25eaba22009-10-10 19:08:43 +0800914 parm = AC_PWRST_D3;
915 set_pin_power_state(codec, 0x24, &parm);
916 if (present) {
917 snd_hda_codec_write(
918 codec, 0x18, 0,
919 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
920 snd_hda_codec_write(
921 codec, 0x34, 0,
922 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
923 } else {
924 snd_hda_codec_write(
925 codec, 0x18, 0,
926 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
927 snd_hda_codec_write(
928 codec, 0x34, 0,
929 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
930 }
931
932 /* Mono Out */
933 /* PW15 (31h), MW8(17h), MUX8(3bh) */
Takashi Iwaid56757a2009-11-18 08:00:14 +0100934 present = snd_hda_jack_detect(codec, 0x26);
Lydia Wang25eaba22009-10-10 19:08:43 +0800935 parm = AC_PWRST_D3;
936 set_pin_power_state(codec, 0x31, &parm);
937 if (present) {
938 snd_hda_codec_write(
939 codec, 0x17, 0,
940 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
941 snd_hda_codec_write(
942 codec, 0x3b, 0,
943 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
944 } else {
945 snd_hda_codec_write(
946 codec, 0x17, 0,
947 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
948 snd_hda_codec_write(
949 codec, 0x3b, 0,
950 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
951 }
952
953 /* MW9 (21h) */
954 if (imux_is_smixer || !is_aa_path_mute(codec))
955 snd_hda_codec_write(
956 codec, 0x21, 0,
957 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
958 else
959 snd_hda_codec_write(
960 codec, 0x21, 0,
961 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Lydia Wangab6734e2009-10-10 19:08:46 +0800962 } else if (spec->codec_type == VT1812) {
963 unsigned int present;
964 /* MUX10 (1eh) = stereo mixer */
965 imux_is_smixer = snd_hda_codec_read(
966 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
967 /* inputs */
968 /* PW 5/6/7 (29h/2ah/2bh) */
969 parm = AC_PWRST_D3;
970 set_pin_power_state(codec, 0x29, &parm);
971 set_pin_power_state(codec, 0x2a, &parm);
972 set_pin_power_state(codec, 0x2b, &parm);
973 if (imux_is_smixer)
974 parm = AC_PWRST_D0;
975 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
976 snd_hda_codec_write(codec, 0x1e, 0,
977 AC_VERB_SET_POWER_STATE, parm);
978 snd_hda_codec_write(codec, 0x1f, 0,
979 AC_VERB_SET_POWER_STATE, parm);
980 snd_hda_codec_write(codec, 0x10, 0,
981 AC_VERB_SET_POWER_STATE, parm);
982 snd_hda_codec_write(codec, 0x11, 0,
983 AC_VERB_SET_POWER_STATE, parm);
984
985 /* outputs */
986 /* AOW0 (8h)*/
987 snd_hda_codec_write(codec, 0x8, 0,
988 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
989
990 /* PW4 (28h), MW4 (18h), MUX4(38h) */
991 parm = AC_PWRST_D3;
992 set_pin_power_state(codec, 0x28, &parm);
993 snd_hda_codec_write(codec, 0x18, 0,
994 AC_VERB_SET_POWER_STATE, parm);
995 snd_hda_codec_write(codec, 0x38, 0,
996 AC_VERB_SET_POWER_STATE, parm);
997
998 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
999 parm = AC_PWRST_D3;
1000 set_pin_power_state(codec, 0x25, &parm);
1001 snd_hda_codec_write(codec, 0x15, 0,
1002 AC_VERB_SET_POWER_STATE, parm);
1003 snd_hda_codec_write(codec, 0x35, 0,
1004 AC_VERB_SET_POWER_STATE, parm);
1005 if (spec->hp_independent_mode) {
1006 snd_hda_codec_write(codec, 0x9, 0,
1007 AC_VERB_SET_POWER_STATE, parm);
1008 }
1009
1010 /* Internal Speaker */
1011 /* PW0 (24h), MW0(14h), MUX0(34h) */
Takashi Iwaid56757a2009-11-18 08:00:14 +01001012 present = snd_hda_jack_detect(codec, 0x25);
Lydia Wangab6734e2009-10-10 19:08:46 +08001013 parm = AC_PWRST_D3;
1014 set_pin_power_state(codec, 0x24, &parm);
1015 if (present) {
1016 snd_hda_codec_write(codec, 0x14, 0,
1017 AC_VERB_SET_POWER_STATE,
1018 AC_PWRST_D3);
1019 snd_hda_codec_write(codec, 0x34, 0,
1020 AC_VERB_SET_POWER_STATE,
1021 AC_PWRST_D3);
1022 } else {
1023 snd_hda_codec_write(codec, 0x14, 0,
1024 AC_VERB_SET_POWER_STATE,
1025 AC_PWRST_D0);
1026 snd_hda_codec_write(codec, 0x34, 0,
1027 AC_VERB_SET_POWER_STATE,
1028 AC_PWRST_D0);
1029 }
1030 /* Mono Out */
1031 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
Takashi Iwaid56757a2009-11-18 08:00:14 +01001032 present = snd_hda_jack_detect(codec, 0x28);
Lydia Wangab6734e2009-10-10 19:08:46 +08001033 parm = AC_PWRST_D3;
1034 set_pin_power_state(codec, 0x31, &parm);
1035 if (present) {
1036 snd_hda_codec_write(codec, 0x1c, 0,
1037 AC_VERB_SET_POWER_STATE,
1038 AC_PWRST_D3);
1039 snd_hda_codec_write(codec, 0x3c, 0,
1040 AC_VERB_SET_POWER_STATE,
1041 AC_PWRST_D3);
1042 snd_hda_codec_write(codec, 0x3e, 0,
1043 AC_VERB_SET_POWER_STATE,
1044 AC_PWRST_D3);
1045 } else {
1046 snd_hda_codec_write(codec, 0x1c, 0,
1047 AC_VERB_SET_POWER_STATE,
1048 AC_PWRST_D0);
1049 snd_hda_codec_write(codec, 0x3c, 0,
1050 AC_VERB_SET_POWER_STATE,
1051 AC_PWRST_D0);
1052 snd_hda_codec_write(codec, 0x3e, 0,
1053 AC_VERB_SET_POWER_STATE,
1054 AC_PWRST_D0);
1055 }
1056
1057 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1058 parm = AC_PWRST_D3;
1059 set_pin_power_state(codec, 0x33, &parm);
1060 snd_hda_codec_write(codec, 0x1d, 0,
1061 AC_VERB_SET_POWER_STATE, parm);
1062 snd_hda_codec_write(codec, 0x3d, 0,
1063 AC_VERB_SET_POWER_STATE, parm);
1064
1065 /* MW9 (21h) */
1066 if (imux_is_smixer || !is_aa_path_mute(codec))
1067 snd_hda_codec_write(
1068 codec, 0x21, 0,
1069 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1070 else
1071 snd_hda_codec_write(
1072 codec, 0x21, 0,
1073 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Lydia Wangf5271102009-10-10 19:07:35 +08001074 }
1075}
1076
Joseph Chanc577b8a2006-11-29 15:29:40 +01001077/*
1078 * input MUX handling
1079 */
1080static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1081 struct snd_ctl_elem_info *uinfo)
1082{
1083 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1084 struct via_spec *spec = codec->spec;
1085 return snd_hda_input_mux_info(spec->input_mux, uinfo);
1086}
1087
1088static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1089 struct snd_ctl_elem_value *ucontrol)
1090{
1091 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1092 struct via_spec *spec = codec->spec;
1093 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1094
1095 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
1096 return 0;
1097}
1098
1099static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1100 struct snd_ctl_elem_value *ucontrol)
1101{
1102 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1103 struct via_spec *spec = codec->spec;
1104 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001105
Takashi Iwai337b9d02009-07-07 18:18:59 +02001106 if (!spec->mux_nids[adc_idx])
1107 return -EINVAL;
Lydia Wanga80e6e32009-10-10 19:07:55 +08001108 /* switch to D0 beofre change index */
1109 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1110 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1111 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1112 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1113 /* update jack power state */
1114 set_jack_power_state(codec);
1115
Takashi Iwai337b9d02009-07-07 18:18:59 +02001116 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1117 spec->mux_nids[adc_idx],
1118 &spec->cur_mux[adc_idx]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001119}
1120
Harald Welte0aa62ae2008-09-09 15:58:27 +08001121static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
1122 struct snd_ctl_elem_info *uinfo)
1123{
1124 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1125 struct via_spec *spec = codec->spec;
1126 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
1127}
1128
1129static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
1130 struct snd_ctl_elem_value *ucontrol)
1131{
1132 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001133 hda_nid_t nid = kcontrol->private_value;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001134 unsigned int pinsel;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001135
Lydia Wangeb7188c2009-10-10 19:08:34 +08001136 /* use !! to translate conn sel 2 for VT1718S */
1137 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1138 AC_VERB_GET_CONNECT_SEL,
1139 0x00);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001140 ucontrol->value.enumerated.item[0] = pinsel;
1141
1142 return 0;
1143}
1144
Lydia Wang0713efe2009-10-10 19:07:43 +08001145static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1146{
1147 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1148 if (ctl) {
1149 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1150 ctl->vd[0].access |= active
1151 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1152 snd_ctl_notify(codec->bus->card,
1153 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1154 }
1155}
1156
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001157static hda_nid_t side_mute_channel(struct via_spec *spec)
1158{
1159 switch (spec->codec_type) {
1160 case VT1708: return 0x1b;
1161 case VT1709_10CH: return 0x29;
1162 case VT1708B_8CH: /* fall thru */
1163 case VT1708S: return 0x27;
1164 default: return 0;
1165 }
1166}
1167
Lydia Wangcdc17842009-10-10 19:07:47 +08001168static int update_side_mute_status(struct hda_codec *codec)
1169{
1170 /* mute side channel */
1171 struct via_spec *spec = codec->spec;
1172 unsigned int parm = spec->hp_independent_mode
1173 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001174 hda_nid_t sw3 = side_mute_channel(spec);
Lydia Wangcdc17842009-10-10 19:07:47 +08001175
1176 if (sw3)
1177 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1178 parm);
1179 return 0;
1180}
1181
Harald Welte0aa62ae2008-09-09 15:58:27 +08001182static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
1183 struct snd_ctl_elem_value *ucontrol)
1184{
1185 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1186 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001187 hda_nid_t nid = kcontrol->private_value;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001188 unsigned int pinsel = ucontrol->value.enumerated.item[0];
Lydia Wangcdc17842009-10-10 19:07:47 +08001189 /* Get Independent Mode index of headphone pin widget */
1190 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1191 ? 1 : 0;
Lydia Wangcdc17842009-10-10 19:07:47 +08001192 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001193
Lydia Wangcdc17842009-10-10 19:07:47 +08001194 if (spec->multiout.hp_nid && spec->multiout.hp_nid
1195 != spec->multiout.dac_nids[HDA_FRONT])
1196 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
1197 0, 0, 0);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001198
Lydia Wangcdc17842009-10-10 19:07:47 +08001199 update_side_mute_status(codec);
Lydia Wang0713efe2009-10-10 19:07:43 +08001200 /* update HP volume/swtich active state */
1201 if (spec->codec_type == VT1708S
Lydia Wangeb7188c2009-10-10 19:08:34 +08001202 || spec->codec_type == VT1702
Lydia Wangf3db4232009-10-10 19:08:41 +08001203 || spec->codec_type == VT1718S
Lydia Wang25eaba22009-10-10 19:08:43 +08001204 || spec->codec_type == VT1716S
Lydia Wangab6734e2009-10-10 19:08:46 +08001205 || spec->codec_type == VT2002P
1206 || spec->codec_type == VT1812) {
Lydia Wang0713efe2009-10-10 19:07:43 +08001207 activate_ctl(codec, "Headphone Playback Volume",
1208 spec->hp_independent_mode);
1209 activate_ctl(codec, "Headphone Playback Switch",
1210 spec->hp_independent_mode);
1211 }
Harald Welte0aa62ae2008-09-09 15:58:27 +08001212 return 0;
1213}
1214
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001215static struct snd_kcontrol_new via_hp_mixer[2] = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001216 {
1217 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1218 .name = "Independent HP",
Harald Welte0aa62ae2008-09-09 15:58:27 +08001219 .info = via_independent_hp_info,
1220 .get = via_independent_hp_get,
1221 .put = via_independent_hp_put,
1222 },
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001223 {
1224 .iface = NID_MAPPING,
1225 .name = "Independent HP",
1226 },
Harald Welte0aa62ae2008-09-09 15:58:27 +08001227};
1228
Takashi Iwai3d83e572010-04-14 14:36:23 +02001229static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001230{
Takashi Iwai3d83e572010-04-14 14:36:23 +02001231 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001232 struct snd_kcontrol_new *knew;
1233 hda_nid_t nid;
Takashi Iwai3d83e572010-04-14 14:36:23 +02001234 int nums;
1235 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001236
1237 switch (spec->codec_type) {
1238 case VT1718S:
1239 nid = 0x34;
1240 break;
1241 case VT2002P:
1242 nid = 0x35;
1243 break;
1244 case VT1812:
1245 nid = 0x3d;
1246 break;
1247 default:
1248 nid = spec->autocfg.hp_pins[0];
1249 break;
1250 }
1251
Takashi Iwai3d83e572010-04-14 14:36:23 +02001252 nums = snd_hda_get_connections(codec, nid, conn, HDA_MAX_CONNECTIONS);
1253 if (nums <= 1)
1254 return 0;
1255
1256 knew = via_clone_control(spec, &via_hp_mixer[0]);
1257 if (knew == NULL)
1258 return -ENOMEM;
1259
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001260 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
1261 knew->private_value = nid;
1262
1263 knew = via_clone_control(spec, &via_hp_mixer[1]);
1264 if (knew == NULL)
1265 return -ENOMEM;
1266 knew->subdevice = side_mute_channel(spec);
1267
1268 return 0;
1269}
1270
Lydia Wang1564b282009-10-10 19:07:52 +08001271static void notify_aa_path_ctls(struct hda_codec *codec)
1272{
1273 int i;
1274 struct snd_ctl_elem_id id;
1275 const char *labels[] = {"Mic", "Front Mic", "Line"};
1276
1277 memset(&id, 0, sizeof(id));
1278 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1279 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1280 sprintf(id.name, "%s Playback Volume", labels[i]);
1281 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1282 &id);
1283 }
1284}
1285
1286static void mute_aa_path(struct hda_codec *codec, int mute)
1287{
1288 struct via_spec *spec = codec->spec;
1289 hda_nid_t nid_mixer;
1290 int start_idx;
1291 int end_idx;
1292 int i;
1293 /* get nid of MW0 and start & end index */
1294 switch (spec->codec_type) {
1295 case VT1708:
1296 nid_mixer = 0x17;
1297 start_idx = 2;
1298 end_idx = 4;
1299 break;
1300 case VT1709_10CH:
1301 case VT1709_6CH:
1302 nid_mixer = 0x18;
1303 start_idx = 2;
1304 end_idx = 4;
1305 break;
1306 case VT1708B_8CH:
1307 case VT1708B_4CH:
1308 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001309 case VT1716S:
Lydia Wang1564b282009-10-10 19:07:52 +08001310 nid_mixer = 0x16;
1311 start_idx = 2;
1312 end_idx = 4;
1313 break;
1314 default:
1315 return;
1316 }
1317 /* check AA path's mute status */
1318 for (i = start_idx; i <= end_idx; i++) {
1319 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1320 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1321 HDA_AMP_MUTE, val);
1322 }
1323}
1324static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1325{
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001326 const struct auto_pin_cfg *cfg = &spec->autocfg;
1327 int i;
1328
1329 for (i = 0; i < cfg->num_inputs; i++) {
1330 if (pin == cfg->inputs[i].pin)
Takashi Iwai86e29592010-09-09 14:50:17 +02001331 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
Lydia Wang1564b282009-10-10 19:07:52 +08001332 }
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001333 return 0;
Lydia Wang1564b282009-10-10 19:07:52 +08001334}
1335
1336static int via_smart51_info(struct snd_kcontrol *kcontrol,
1337 struct snd_ctl_elem_info *uinfo)
1338{
1339 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1340 uinfo->count = 1;
1341 uinfo->value.integer.min = 0;
1342 uinfo->value.integer.max = 1;
1343 return 0;
1344}
1345
1346static int via_smart51_get(struct snd_kcontrol *kcontrol,
1347 struct snd_ctl_elem_value *ucontrol)
1348{
1349 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1350 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001351 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +08001352 int on = 1;
1353 int i;
1354
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001355 for (i = 0; i < cfg->num_inputs; i++) {
1356 hda_nid_t nid = cfg->inputs[i].pin;
1357 int ctl = snd_hda_codec_read(codec, nid, 0,
1358 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai86e29592010-09-09 14:50:17 +02001359 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001360 continue;
Takashi Iwai86e29592010-09-09 14:50:17 +02001361 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001362 spec->hp_independent_mode && spec->codec_type != VT1718S)
1363 continue; /* ignore FMic for independent HP */
1364 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
1365 on = 0;
Lydia Wang1564b282009-10-10 19:07:52 +08001366 }
1367 *ucontrol->value.integer.value = on;
1368 return 0;
1369}
1370
1371static int via_smart51_put(struct snd_kcontrol *kcontrol,
1372 struct snd_ctl_elem_value *ucontrol)
1373{
1374 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1375 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001376 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +08001377 int out_in = *ucontrol->value.integer.value
1378 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +08001379 int i;
1380
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001381 for (i = 0; i < cfg->num_inputs; i++) {
1382 hda_nid_t nid = cfg->inputs[i].pin;
1383 unsigned int parm;
1384
Takashi Iwai86e29592010-09-09 14:50:17 +02001385 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001386 continue;
Takashi Iwai86e29592010-09-09 14:50:17 +02001387 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001388 spec->hp_independent_mode && spec->codec_type != VT1718S)
Lydia Wang1564b282009-10-10 19:07:52 +08001389 continue; /* don't retask FMic for independent HP */
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001390
1391 parm = snd_hda_codec_read(codec, nid, 0,
1392 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1393 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1394 parm |= out_in;
1395 snd_hda_codec_write(codec, nid, 0,
1396 AC_VERB_SET_PIN_WIDGET_CONTROL,
1397 parm);
1398 if (out_in == AC_PINCTL_OUT_EN) {
1399 mute_aa_path(codec, 1);
1400 notify_aa_path_ctls(codec);
1401 }
1402 if (spec->codec_type == VT1718S) {
1403 snd_hda_codec_amp_stereo(
Lydia Wangeb7188c2009-10-10 19:08:34 +08001404 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1405 HDA_AMP_UNMUTE);
Lydia Wang1564b282009-10-10 19:07:52 +08001406 }
Takashi Iwai86e29592010-09-09 14:50:17 +02001407 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
Lydia Wangf3db4232009-10-10 19:08:41 +08001408 if (spec->codec_type == VT1708S
1409 || spec->codec_type == VT1716S) {
Lydia Wang1564b282009-10-10 19:07:52 +08001410 /* input = index 1 (AOW3) */
1411 snd_hda_codec_write(
1412 codec, nid, 0,
1413 AC_VERB_SET_CONNECT_SEL, 1);
1414 snd_hda_codec_amp_stereo(
1415 codec, nid, HDA_OUTPUT,
1416 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1417 }
1418 }
1419 }
1420 spec->smart51_enabled = *ucontrol->value.integer.value;
1421 set_jack_power_state(codec);
1422 return 1;
1423}
1424
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001425static struct snd_kcontrol_new via_smart51_mixer[2] = {
Lydia Wang1564b282009-10-10 19:07:52 +08001426 {
1427 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1428 .name = "Smart 5.1",
1429 .count = 1,
1430 .info = via_smart51_info,
1431 .get = via_smart51_get,
1432 .put = via_smart51_put,
1433 },
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001434 {
1435 .iface = NID_MAPPING,
1436 .name = "Smart 5.1",
1437 }
Lydia Wang1564b282009-10-10 19:07:52 +08001438};
1439
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001440static int via_smart51_build(struct via_spec *spec)
1441{
1442 struct snd_kcontrol_new *knew;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001443 const struct auto_pin_cfg *cfg = &spec->autocfg;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001444 hda_nid_t nid;
1445 int i;
1446
1447 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1448 if (knew == NULL)
1449 return -ENOMEM;
1450
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001451 for (i = 0; i < cfg->num_inputs; i++) {
1452 nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02001453 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001454 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1455 if (knew == NULL)
1456 return -ENOMEM;
1457 knew->subdevice = nid;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001458 break;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001459 }
1460 }
1461
1462 return 0;
1463}
1464
Joseph Chanc577b8a2006-11-29 15:29:40 +01001465/* capture mixer elements */
1466static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1467 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1468 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1469 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1470 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1471 {
1472 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1473 /* The multiple "Capture Source" controls confuse alsamixer
1474 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01001475 */
1476 /* .name = "Capture Source", */
1477 .name = "Input Source",
1478 .count = 1,
1479 .info = via_mux_enum_info,
1480 .get = via_mux_enum_get,
1481 .put = via_mux_enum_put,
1482 },
1483 { } /* end */
1484};
Lydia Wangf5271102009-10-10 19:07:35 +08001485
1486/* check AA path's mute statue */
1487static int is_aa_path_mute(struct hda_codec *codec)
1488{
1489 int mute = 1;
1490 hda_nid_t nid_mixer;
1491 int start_idx;
1492 int end_idx;
1493 int i;
1494 struct via_spec *spec = codec->spec;
1495 /* get nid of MW0 and start & end index */
1496 switch (spec->codec_type) {
1497 case VT1708B_8CH:
1498 case VT1708B_4CH:
1499 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001500 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001501 nid_mixer = 0x16;
1502 start_idx = 2;
1503 end_idx = 4;
1504 break;
1505 case VT1702:
1506 nid_mixer = 0x1a;
1507 start_idx = 1;
1508 end_idx = 3;
1509 break;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001510 case VT1718S:
1511 nid_mixer = 0x21;
1512 start_idx = 1;
1513 end_idx = 3;
1514 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001515 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001516 case VT1812:
Lydia Wang25eaba22009-10-10 19:08:43 +08001517 nid_mixer = 0x21;
1518 start_idx = 0;
1519 end_idx = 2;
1520 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001521 default:
1522 return 0;
1523 }
1524 /* check AA path's mute status */
1525 for (i = start_idx; i <= end_idx; i++) {
1526 unsigned int con_list = snd_hda_codec_read(
1527 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1528 int shift = 8 * (i % 4);
1529 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1530 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1531 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1532 /* check mute status while the pin is connected */
1533 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1534 HDA_INPUT, i) >> 7;
1535 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1536 HDA_INPUT, i) >> 7;
1537 if (!mute_l || !mute_r) {
1538 mute = 0;
1539 break;
1540 }
1541 }
1542 }
1543 return mute;
1544}
1545
1546/* enter/exit analog low-current mode */
1547static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1548{
1549 struct via_spec *spec = codec->spec;
1550 static int saved_stream_idle = 1; /* saved stream idle status */
1551 int enable = is_aa_path_mute(codec);
1552 unsigned int verb = 0;
1553 unsigned int parm = 0;
1554
1555 if (stream_idle == -1) /* stream status did not change */
1556 enable = enable && saved_stream_idle;
1557 else {
1558 enable = enable && stream_idle;
1559 saved_stream_idle = stream_idle;
1560 }
1561
1562 /* decide low current mode's verb & parameter */
1563 switch (spec->codec_type) {
1564 case VT1708B_8CH:
1565 case VT1708B_4CH:
1566 verb = 0xf70;
1567 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1568 break;
1569 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001570 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001571 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001572 verb = 0xf73;
1573 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1574 break;
1575 case VT1702:
1576 verb = 0xf73;
1577 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1578 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001579 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001580 case VT1812:
Lydia Wang25eaba22009-10-10 19:08:43 +08001581 verb = 0xf93;
1582 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1583 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001584 default:
1585 return; /* other codecs are not supported */
1586 }
1587 /* send verb */
1588 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1589}
1590
Joseph Chanc577b8a2006-11-29 15:29:40 +01001591/*
1592 * generic initialization of ADC, input mixers and output mixers
1593 */
1594static struct hda_verb vt1708_volume_init_verbs[] = {
1595 /*
1596 * Unmute ADC0-1 and set the default input to mic-in
1597 */
1598 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1599 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1600
1601
Josepch Chanf7278fd2007-12-13 16:40:40 +01001602 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01001603 * mixer widget
1604 */
1605 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01001606 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1607 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1608 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1609 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1610 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001611
1612 /*
1613 * Set up output mixers (0x19 - 0x1b)
1614 */
1615 /* set vol=0 to output mixers */
1616 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1617 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1618 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Lydia Wang377ff312009-10-10 19:08:55 +08001619
Lydia Wangbfdc6752009-10-10 19:08:50 +08001620 /* Setup default input MW0 to PW4 */
1621 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001622 /* PW9 Output enable */
1623 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001624 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001625};
1626
1627static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1628 struct hda_codec *codec,
1629 struct snd_pcm_substream *substream)
1630{
1631 struct via_spec *spec = codec->spec;
Lydia Wang17314372009-10-10 19:07:37 +08001632 int idle = substream->pstr->substream_opened == 1
1633 && substream->ref_count == 0;
Lydia Wang17314372009-10-10 19:07:37 +08001634 analog_low_current_mode(codec, idle);
Takashi Iwai9a081602008-02-12 18:37:26 +01001635 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1636 hinfo);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001637}
1638
Harald Welte0aa62ae2008-09-09 15:58:27 +08001639static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1640 unsigned int stream_tag,
1641 unsigned int format,
1642 struct snd_pcm_substream *substream)
1643{
1644 struct via_spec *spec = codec->spec;
1645 struct hda_multi_out *mout = &spec->multiout;
1646 hda_nid_t *nids = mout->dac_nids;
1647 int chs = substream->runtime->channels;
1648 int i;
1649
1650 mutex_lock(&codec->spdif_mutex);
1651 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1652 if (chs == 2 &&
1653 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1654 format) &&
1655 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1656 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1657 /* turn off SPDIF once; otherwise the IEC958 bits won't
1658 * be updated */
1659 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1660 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1661 AC_VERB_SET_DIGI_CONVERT_1,
1662 codec->spdif_ctls &
1663 ~AC_DIG1_ENABLE & 0xff);
1664 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1665 stream_tag, 0, format);
1666 /* turn on again (if needed) */
1667 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1668 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1669 AC_VERB_SET_DIGI_CONVERT_1,
1670 codec->spdif_ctls & 0xff);
1671 } else {
1672 mout->dig_out_used = 0;
1673 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1674 0, 0, 0);
1675 }
1676 }
1677 mutex_unlock(&codec->spdif_mutex);
1678
1679 /* front */
1680 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1681 0, format);
1682
Lydia Wangeb7188c2009-10-10 19:08:34 +08001683 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1684 && !spec->hp_independent_mode)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001685 /* headphone out will just decode front left/right (stereo) */
1686 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1687 0, format);
1688
1689 /* extra outputs copied from front */
1690 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1691 if (mout->extra_out_nid[i])
1692 snd_hda_codec_setup_stream(codec,
1693 mout->extra_out_nid[i],
1694 stream_tag, 0, format);
1695
1696 /* surrounds */
1697 for (i = 1; i < mout->num_dacs; i++) {
1698 if (chs >= (i + 1) * 2) /* independent out */
1699 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1700 i * 2, format);
1701 else /* copy front */
1702 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1703 0, format);
1704 }
1705}
1706
1707static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1708 struct hda_codec *codec,
1709 unsigned int stream_tag,
1710 unsigned int format,
1711 struct snd_pcm_substream *substream)
1712{
1713 struct via_spec *spec = codec->spec;
1714 struct hda_multi_out *mout = &spec->multiout;
1715 hda_nid_t *nids = mout->dac_nids;
1716
1717 if (substream->number == 0)
1718 playback_multi_pcm_prep_0(codec, stream_tag, format,
1719 substream);
1720 else {
1721 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1722 spec->hp_independent_mode)
1723 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1724 stream_tag, 0, format);
1725 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001726 vt1708_start_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001727 return 0;
1728}
1729
1730static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1731 struct hda_codec *codec,
1732 struct snd_pcm_substream *substream)
1733{
1734 struct via_spec *spec = codec->spec;
1735 struct hda_multi_out *mout = &spec->multiout;
1736 hda_nid_t *nids = mout->dac_nids;
1737 int i;
1738
1739 if (substream->number == 0) {
1740 for (i = 0; i < mout->num_dacs; i++)
1741 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1742
1743 if (mout->hp_nid && !spec->hp_independent_mode)
1744 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1745 0, 0, 0);
1746
1747 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1748 if (mout->extra_out_nid[i])
1749 snd_hda_codec_setup_stream(codec,
1750 mout->extra_out_nid[i],
1751 0, 0, 0);
1752 mutex_lock(&codec->spdif_mutex);
1753 if (mout->dig_out_nid &&
1754 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1755 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1756 0, 0, 0);
1757 mout->dig_out_used = 0;
1758 }
1759 mutex_unlock(&codec->spdif_mutex);
1760 } else {
1761 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1762 spec->hp_independent_mode)
1763 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1764 0, 0, 0);
1765 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001766 vt1708_stop_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001767 return 0;
1768}
1769
Joseph Chanc577b8a2006-11-29 15:29:40 +01001770/*
1771 * Digital out
1772 */
1773static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1774 struct hda_codec *codec,
1775 struct snd_pcm_substream *substream)
1776{
1777 struct via_spec *spec = codec->spec;
1778 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1779}
1780
1781static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1782 struct hda_codec *codec,
1783 struct snd_pcm_substream *substream)
1784{
1785 struct via_spec *spec = codec->spec;
1786 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1787}
1788
Harald Welte5691ec72008-09-15 22:42:26 +08001789static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001790 struct hda_codec *codec,
1791 unsigned int stream_tag,
1792 unsigned int format,
1793 struct snd_pcm_substream *substream)
1794{
1795 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001796 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1797 stream_tag, format, substream);
1798}
Harald Welte5691ec72008-09-15 22:42:26 +08001799
Takashi Iwai9da29272009-05-07 16:31:14 +02001800static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1801 struct hda_codec *codec,
1802 struct snd_pcm_substream *substream)
1803{
1804 struct via_spec *spec = codec->spec;
1805 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001806 return 0;
1807}
1808
Joseph Chanc577b8a2006-11-29 15:29:40 +01001809/*
1810 * Analog capture
1811 */
1812static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1813 struct hda_codec *codec,
1814 unsigned int stream_tag,
1815 unsigned int format,
1816 struct snd_pcm_substream *substream)
1817{
1818 struct via_spec *spec = codec->spec;
1819
1820 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1821 stream_tag, 0, format);
1822 return 0;
1823}
1824
1825static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1826 struct hda_codec *codec,
1827 struct snd_pcm_substream *substream)
1828{
1829 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001830 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001831 return 0;
1832}
1833
1834static struct hda_pcm_stream vt1708_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001835 .substreams = 2,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001836 .channels_min = 2,
1837 .channels_max = 8,
1838 .nid = 0x10, /* NID to query formats and rates */
1839 .ops = {
1840 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001841 .prepare = via_playback_multi_pcm_prepare,
1842 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001843 },
1844};
1845
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001846static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Lydia Wangc873cc22009-10-10 19:08:21 +08001847 .substreams = 2,
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001848 .channels_min = 2,
1849 .channels_max = 8,
1850 .nid = 0x10, /* NID to query formats and rates */
1851 /* We got noisy outputs on the right channel on VT1708 when
1852 * 24bit samples are used. Until any workaround is found,
1853 * disable the 24bit format, so far.
1854 */
1855 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1856 .ops = {
1857 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08001858 .prepare = via_playback_multi_pcm_prepare,
1859 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001860 },
1861};
1862
Joseph Chanc577b8a2006-11-29 15:29:40 +01001863static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1864 .substreams = 2,
1865 .channels_min = 2,
1866 .channels_max = 2,
1867 .nid = 0x15, /* NID to query formats and rates */
1868 .ops = {
1869 .prepare = via_capture_pcm_prepare,
1870 .cleanup = via_capture_pcm_cleanup
1871 },
1872};
1873
1874static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1875 .substreams = 1,
1876 .channels_min = 2,
1877 .channels_max = 2,
1878 /* NID is set in via_build_pcms */
1879 .ops = {
1880 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001881 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001882 .prepare = via_dig_playback_pcm_prepare,
1883 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001884 },
1885};
1886
1887static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1888 .substreams = 1,
1889 .channels_min = 2,
1890 .channels_max = 2,
1891};
1892
1893static int via_build_controls(struct hda_codec *codec)
1894{
1895 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001896 struct snd_kcontrol *kctl;
1897 struct snd_kcontrol_new *knew;
1898 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001899
1900 for (i = 0; i < spec->num_mixers; i++) {
1901 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1902 if (err < 0)
1903 return err;
1904 }
1905
1906 if (spec->multiout.dig_out_nid) {
1907 err = snd_hda_create_spdif_out_ctls(codec,
1908 spec->multiout.dig_out_nid);
1909 if (err < 0)
1910 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001911 err = snd_hda_create_spdif_share_sw(codec,
1912 &spec->multiout);
1913 if (err < 0)
1914 return err;
1915 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001916 }
1917 if (spec->dig_in_nid) {
1918 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1919 if (err < 0)
1920 return err;
1921 }
Lydia Wang17314372009-10-10 19:07:37 +08001922
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001923 /* assign Capture Source enums to NID */
1924 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1925 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +01001926 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001927 if (err < 0)
1928 return err;
1929 }
1930
1931 /* other nid->control mapping */
1932 for (i = 0; i < spec->num_mixers; i++) {
1933 for (knew = spec->mixers[i]; knew->name; knew++) {
1934 if (knew->iface != NID_MAPPING)
1935 continue;
1936 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1937 if (kctl == NULL)
1938 continue;
1939 err = snd_hda_add_nid(codec, kctl, 0,
1940 knew->subdevice);
1941 }
1942 }
1943
Lydia Wang17314372009-10-10 19:07:37 +08001944 /* init power states */
1945 set_jack_power_state(codec);
1946 analog_low_current_mode(codec, 1);
1947
Takashi Iwai603c4012008-07-30 15:01:44 +02001948 via_free_kctls(codec); /* no longer needed */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001949 return 0;
1950}
1951
1952static int via_build_pcms(struct hda_codec *codec)
1953{
1954 struct via_spec *spec = codec->spec;
1955 struct hda_pcm *info = spec->pcm_rec;
1956
1957 codec->num_pcms = 1;
1958 codec->pcm_info = info;
1959
1960 info->name = spec->stream_name_analog;
Lydia Wang377ff312009-10-10 19:08:55 +08001961 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1962 *(spec->stream_analog_playback);
1963 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1964 spec->multiout.dac_nids[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001965 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1966 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1967
1968 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1969 spec->multiout.max_channels;
1970
1971 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1972 codec->num_pcms++;
1973 info++;
1974 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001975 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001976 if (spec->multiout.dig_out_nid) {
1977 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1978 *(spec->stream_digital_playback);
1979 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1980 spec->multiout.dig_out_nid;
1981 }
1982 if (spec->dig_in_nid) {
1983 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1984 *(spec->stream_digital_capture);
1985 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1986 spec->dig_in_nid;
1987 }
1988 }
1989
1990 return 0;
1991}
1992
1993static void via_free(struct hda_codec *codec)
1994{
1995 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001996
1997 if (!spec)
1998 return;
1999
Takashi Iwai603c4012008-07-30 15:01:44 +02002000 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002001 vt1708_stop_hp_work(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002002 kfree(codec->spec);
2003}
2004
Harald Welte69e52a82008-09-09 15:57:32 +08002005/* mute internal speaker if HP is plugged */
2006static void via_hp_automute(struct hda_codec *codec)
2007{
Lydia Wangdcf34c82009-10-10 19:08:15 +08002008 unsigned int present = 0;
Harald Welte69e52a82008-09-09 15:57:32 +08002009 struct via_spec *spec = codec->spec;
2010
Takashi Iwaid56757a2009-11-18 08:00:14 +01002011 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangdcf34c82009-10-10 19:08:15 +08002012
2013 if (!spec->hp_independent_mode) {
2014 struct snd_ctl_elem_id id;
2015 /* auto mute */
2016 snd_hda_codec_amp_stereo(
2017 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
2018 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2019 /* notify change */
2020 memset(&id, 0, sizeof(id));
2021 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2022 strcpy(id.name, "Front Playback Switch");
2023 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2024 &id);
2025 }
Harald Welte69e52a82008-09-09 15:57:32 +08002026}
2027
Lydia Wangf3db4232009-10-10 19:08:41 +08002028/* mute mono out if HP or Line out is plugged */
2029static void via_mono_automute(struct hda_codec *codec)
2030{
2031 unsigned int hp_present, lineout_present;
2032 struct via_spec *spec = codec->spec;
2033
2034 if (spec->codec_type != VT1716S)
2035 return;
2036
Takashi Iwaid56757a2009-11-18 08:00:14 +01002037 lineout_present = snd_hda_jack_detect(codec,
2038 spec->autocfg.line_out_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08002039
2040 /* Mute Mono Out if Line Out is plugged */
2041 if (lineout_present) {
2042 snd_hda_codec_amp_stereo(
2043 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
2044 return;
2045 }
2046
Takashi Iwaid56757a2009-11-18 08:00:14 +01002047 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08002048
2049 if (!spec->hp_independent_mode)
2050 snd_hda_codec_amp_stereo(
2051 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
2052 hp_present ? HDA_AMP_MUTE : 0);
2053}
2054
Harald Welte69e52a82008-09-09 15:57:32 +08002055static void via_gpio_control(struct hda_codec *codec)
2056{
2057 unsigned int gpio_data;
2058 unsigned int vol_counter;
2059 unsigned int vol;
2060 unsigned int master_vol;
2061
2062 struct via_spec *spec = codec->spec;
2063
2064 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
2065 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
2066
2067 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
2068 0xF84, 0) & 0x3F0000) >> 16;
2069
2070 vol = vol_counter & 0x1F;
2071 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
2072 AC_VERB_GET_AMP_GAIN_MUTE,
2073 AC_AMP_GET_INPUT);
2074
2075 if (gpio_data == 0x02) {
2076 /* unmute line out */
2077 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
2078 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
2079
2080 if (vol_counter & 0x20) {
2081 /* decrease volume */
2082 if (vol > master_vol)
2083 vol = master_vol;
2084 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
2085 0, HDA_AMP_VOLMASK,
2086 master_vol-vol);
2087 } else {
2088 /* increase volume */
2089 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
2090 HDA_AMP_VOLMASK,
2091 ((master_vol+vol) > 0x2A) ? 0x2A :
2092 (master_vol+vol));
2093 }
2094 } else if (!(gpio_data & 0x02)) {
2095 /* mute line out */
2096 snd_hda_codec_amp_stereo(codec,
2097 spec->autocfg.line_out_pins[0],
2098 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2099 HDA_AMP_MUTE);
2100 }
2101}
2102
Lydia Wang25eaba22009-10-10 19:08:43 +08002103/* mute Internal-Speaker if HP is plugged */
2104static void via_speaker_automute(struct hda_codec *codec)
2105{
2106 unsigned int hp_present;
2107 struct via_spec *spec = codec->spec;
2108
Lydia Wangab6734e2009-10-10 19:08:46 +08002109 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
Lydia Wang25eaba22009-10-10 19:08:43 +08002110 return;
2111
Takashi Iwaid56757a2009-11-18 08:00:14 +01002112 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08002113
2114 if (!spec->hp_independent_mode) {
2115 struct snd_ctl_elem_id id;
2116 snd_hda_codec_amp_stereo(
2117 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2118 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2119 /* notify change */
2120 memset(&id, 0, sizeof(id));
2121 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2122 strcpy(id.name, "Speaker Playback Switch");
2123 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2124 &id);
2125 }
2126}
2127
2128/* mute line-out and internal speaker if HP is plugged */
2129static void via_hp_bind_automute(struct hda_codec *codec)
2130{
akpm@linux-foundation.org01a17962009-11-13 16:47:10 -08002131 /* use long instead of int below just to avoid an internal compiler
2132 * error with gcc 4.0.x
2133 */
2134 unsigned long hp_present, present = 0;
Lydia Wang25eaba22009-10-10 19:08:43 +08002135 struct via_spec *spec = codec->spec;
2136 int i;
2137
2138 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2139 return;
2140
Takashi Iwaid56757a2009-11-18 08:00:14 +01002141 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08002142
Takashi Iwaid56757a2009-11-18 08:00:14 +01002143 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08002144
2145 if (!spec->hp_independent_mode) {
2146 /* Mute Line-Outs */
2147 for (i = 0; i < spec->autocfg.line_outs; i++)
2148 snd_hda_codec_amp_stereo(
2149 codec, spec->autocfg.line_out_pins[i],
2150 HDA_OUTPUT, 0,
2151 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2152 if (hp_present)
2153 present = hp_present;
2154 }
2155 /* Speakers */
2156 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2157 snd_hda_codec_amp_stereo(
2158 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2159 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2160}
2161
2162
Harald Welte69e52a82008-09-09 15:57:32 +08002163/* unsolicited event for jack sensing */
2164static void via_unsol_event(struct hda_codec *codec,
2165 unsigned int res)
2166{
2167 res >>= 26;
Lydia Wanga34df192009-10-10 19:08:01 +08002168 if (res & VIA_HP_EVENT)
Harald Welte69e52a82008-09-09 15:57:32 +08002169 via_hp_automute(codec);
Lydia Wanga34df192009-10-10 19:08:01 +08002170 if (res & VIA_GPIO_EVENT)
Harald Welte69e52a82008-09-09 15:57:32 +08002171 via_gpio_control(codec);
Lydia Wanga34df192009-10-10 19:08:01 +08002172 if (res & VIA_JACK_EVENT)
2173 set_jack_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08002174 if (res & VIA_MONO_EVENT)
2175 via_mono_automute(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08002176 if (res & VIA_SPEAKER_EVENT)
2177 via_speaker_automute(codec);
2178 if (res & VIA_BIND_HP_EVENT)
2179 via_hp_bind_automute(codec);
Harald Welte69e52a82008-09-09 15:57:32 +08002180}
2181
Joseph Chanc577b8a2006-11-29 15:29:40 +01002182static int via_init(struct hda_codec *codec)
2183{
2184 struct via_spec *spec = codec->spec;
Harald Welte69e52a82008-09-09 15:57:32 +08002185 int i;
2186 for (i = 0; i < spec->num_iverbs; i++)
2187 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2188
Lydia Wang518bf3b2009-10-10 19:07:29 +08002189 spec->codec_type = get_codec_type(codec);
2190 if (spec->codec_type == VT1708BCE)
2191 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2192 same */
Josepch Chanf7278fd2007-12-13 16:40:40 +01002193 /* Lydia Add for EAPD enable */
2194 if (!spec->dig_in_nid) { /* No Digital In connection */
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002195 if (spec->dig_in_pin) {
2196 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002197 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +01002198 PIN_OUT);
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002199 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002200 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2201 }
Takashi Iwai12b74c82008-01-15 12:39:38 +01002202 } else /* enable SPDIF-input pin */
2203 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2204 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002205
Takashi Iwai9da29272009-05-07 16:31:14 +02002206 /* assign slave outs */
2207 if (spec->slave_dig_outs[0])
2208 codec->slave_dig_outs = spec->slave_dig_outs;
Harald Welte5691ec72008-09-15 22:42:26 +08002209
Lydia Wang377ff312009-10-10 19:08:55 +08002210 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002211}
2212
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002213#ifdef SND_HDA_NEEDS_RESUME
2214static int via_suspend(struct hda_codec *codec, pm_message_t state)
2215{
2216 struct via_spec *spec = codec->spec;
2217 vt1708_stop_hp_work(spec);
2218 return 0;
2219}
2220#endif
2221
Takashi Iwaicb53c622007-08-10 17:21:45 +02002222#ifdef CONFIG_SND_HDA_POWER_SAVE
2223static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2224{
2225 struct via_spec *spec = codec->spec;
2226 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2227}
2228#endif
2229
Joseph Chanc577b8a2006-11-29 15:29:40 +01002230/*
2231 */
2232static struct hda_codec_ops via_patch_ops = {
2233 .build_controls = via_build_controls,
2234 .build_pcms = via_build_pcms,
2235 .init = via_init,
2236 .free = via_free,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002237#ifdef SND_HDA_NEEDS_RESUME
2238 .suspend = via_suspend,
2239#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002240#ifdef CONFIG_SND_HDA_POWER_SAVE
2241 .check_power_status = via_check_power_status,
2242#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002243};
2244
2245/* fill in the dac_nids table from the parsed pin configuration */
2246static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2247 const struct auto_pin_cfg *cfg)
2248{
2249 int i;
2250 hda_nid_t nid;
2251
2252 spec->multiout.num_dacs = cfg->line_outs;
2253
2254 spec->multiout.dac_nids = spec->private_dac_nids;
Lydia Wang377ff312009-10-10 19:08:55 +08002255
2256 for (i = 0; i < 4; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002257 nid = cfg->line_out_pins[i];
2258 if (nid) {
2259 /* config dac list */
2260 switch (i) {
2261 case AUTO_SEQ_FRONT:
2262 spec->multiout.dac_nids[i] = 0x10;
2263 break;
2264 case AUTO_SEQ_CENLFE:
2265 spec->multiout.dac_nids[i] = 0x12;
2266 break;
2267 case AUTO_SEQ_SURROUND:
Harald Weltefb4cb772008-09-09 15:53:36 +08002268 spec->multiout.dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002269 break;
2270 case AUTO_SEQ_SIDE:
Harald Weltefb4cb772008-09-09 15:53:36 +08002271 spec->multiout.dac_nids[i] = 0x13;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002272 break;
2273 }
2274 }
2275 }
2276
2277 return 0;
2278}
2279
2280/* add playback controls from the parsed DAC table */
2281static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2282 const struct auto_pin_cfg *cfg)
2283{
2284 char name[32];
2285 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
Lydia Wang9645c202009-10-10 19:08:27 +08002286 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
Joseph Chanc577b8a2006-11-29 15:29:40 +01002287 int i, err;
2288
2289 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2290 nid = cfg->line_out_pins[i];
2291
2292 if (!nid)
2293 continue;
Lydia Wang377ff312009-10-10 19:08:55 +08002294
Lydia Wang9645c202009-10-10 19:08:27 +08002295 nid_vol = nid_vols[i];
Joseph Chanc577b8a2006-11-29 15:29:40 +01002296
2297 if (i == AUTO_SEQ_CENLFE) {
2298 /* Center/LFE */
2299 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002300 "Center Playback Volume",
2301 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2302 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002303 if (err < 0)
2304 return err;
2305 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2306 "LFE Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01002307 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2308 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002309 if (err < 0)
2310 return err;
2311 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2312 "Center Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01002313 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2314 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002315 if (err < 0)
2316 return err;
2317 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2318 "LFE Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01002319 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2320 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002321 if (err < 0)
2322 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002323 } else if (i == AUTO_SEQ_FRONT) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002324 /* add control to mixer index 0 */
2325 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2326 "Master Front Playback Volume",
Lydia Wang9645c202009-10-10 19:08:27 +08002327 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002328 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002329 if (err < 0)
2330 return err;
2331 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2332 "Master Front Playback Switch",
Lydia Wang9645c202009-10-10 19:08:27 +08002333 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002334 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002335 if (err < 0)
2336 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002337
Joseph Chanc577b8a2006-11-29 15:29:40 +01002338 /* add control to PW3 */
2339 sprintf(name, "%s Playback Volume", chname[i]);
2340 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002341 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2342 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002343 if (err < 0)
2344 return err;
2345 sprintf(name, "%s Playback Switch", chname[i]);
2346 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002347 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2348 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002349 if (err < 0)
2350 return err;
2351 } else {
2352 sprintf(name, "%s Playback Volume", chname[i]);
2353 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002354 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2355 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002356 if (err < 0)
2357 return err;
2358 sprintf(name, "%s Playback Switch", chname[i]);
2359 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002360 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2361 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002362 if (err < 0)
2363 return err;
2364 }
2365 }
2366
2367 return 0;
2368}
2369
Harald Welte0aa62ae2008-09-09 15:58:27 +08002370static void create_hp_imux(struct via_spec *spec)
2371{
2372 int i;
2373 struct hda_input_mux *imux = &spec->private_imux[1];
2374 static const char *texts[] = { "OFF", "ON", NULL};
2375
2376 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002377 for (i = 0; texts[i]; i++)
2378 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Harald Welte0aa62ae2008-09-09 15:58:27 +08002379
2380 spec->hp_mux = &spec->private_imux[1];
2381}
2382
Joseph Chanc577b8a2006-11-29 15:29:40 +01002383static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2384{
2385 int err;
2386
2387 if (!pin)
2388 return 0;
2389
2390 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08002391 spec->hp_independent_mode_index = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002392
2393 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2394 "Headphone Playback Volume",
2395 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2396 if (err < 0)
2397 return err;
2398 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2399 "Headphone Playback Switch",
2400 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2401 if (err < 0)
2402 return err;
2403
Harald Welte0aa62ae2008-09-09 15:58:27 +08002404 create_hp_imux(spec);
2405
Joseph Chanc577b8a2006-11-29 15:29:40 +01002406 return 0;
2407}
2408
2409/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002410static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaif3268512010-08-30 11:00:19 +02002411 const struct auto_pin_cfg *cfg,
2412 hda_nid_t cap_nid,
2413 hda_nid_t pin_idxs[], int num_idxs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002414{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002415 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08002416 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002417 int i, err, idx, type, type_idx = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002418
2419 /* for internal loopback recording select */
Takashi Iwaif3268512010-08-30 11:00:19 +02002420 for (idx = 0; idx < num_idxs; idx++) {
2421 if (pin_idxs[idx] == 0xff) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002422 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
Takashi Iwaif3268512010-08-30 11:00:19 +02002423 break;
2424 }
2425 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002426
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002427 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002428 const char *label;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002429 type = cfg->inputs[i].type;
Takashi Iwaif3268512010-08-30 11:00:19 +02002430 for (idx = 0; idx < num_idxs; idx++)
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002431 if (pin_idxs[idx] == cfg->inputs[i].pin)
Takashi Iwaif3268512010-08-30 11:00:19 +02002432 break;
2433 if (idx >= num_idxs)
2434 continue;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002435 if (i > 0 && type == cfg->inputs[i - 1].type)
2436 type_idx++;
2437 else
2438 type_idx = 0;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002439 label = hda_get_autocfg_input_label(codec, cfg, i);
2440 err = via_new_analog_input(spec, label, type_idx, idx, cap_nid);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002441 if (err < 0)
2442 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002443 snd_hda_add_imux_item(imux, label, idx, NULL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002444 }
2445 return 0;
2446}
2447
Takashi Iwaif3268512010-08-30 11:00:19 +02002448/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002449static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaif3268512010-08-30 11:00:19 +02002450 const struct auto_pin_cfg *cfg)
2451{
2452 static hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
Takashi Iwai10a20af2010-09-09 16:28:02 +02002453 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02002454 ARRAY_SIZE(pin_idxs));
2455}
2456
Takashi Iwaicb53c622007-08-10 17:21:45 +02002457#ifdef CONFIG_SND_HDA_POWER_SAVE
2458static struct hda_amp_list vt1708_loopbacks[] = {
2459 { 0x17, HDA_INPUT, 1 },
2460 { 0x17, HDA_INPUT, 2 },
2461 { 0x17, HDA_INPUT, 3 },
2462 { 0x17, HDA_INPUT, 4 },
2463 { } /* end */
2464};
2465#endif
2466
Harald Welte76d9b0d2008-09-09 15:50:37 +08002467static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2468{
2469 unsigned int def_conf;
2470 unsigned char seqassoc;
2471
Takashi Iwai2f334f92009-02-20 14:37:42 +01002472 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002473 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2474 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002475 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2476 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2477 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2478 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002479 }
2480
2481 return;
2482}
2483
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002484static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2485 struct snd_ctl_elem_value *ucontrol)
2486{
2487 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2488 struct via_spec *spec = codec->spec;
2489
2490 if (spec->codec_type != VT1708)
2491 return 0;
2492 spec->vt1708_jack_detectect =
2493 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2494 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2495 return 0;
2496}
2497
2498static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2499 struct snd_ctl_elem_value *ucontrol)
2500{
2501 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2502 struct via_spec *spec = codec->spec;
2503 int change;
2504
2505 if (spec->codec_type != VT1708)
2506 return 0;
2507 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2508 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2509 == !spec->vt1708_jack_detectect;
2510 if (spec->vt1708_jack_detectect) {
2511 mute_aa_path(codec, 1);
2512 notify_aa_path_ctls(codec);
2513 }
2514 return change;
2515}
2516
2517static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2518 {
2519 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2520 .name = "Jack Detect",
2521 .count = 1,
2522 .info = snd_ctl_boolean_mono_info,
2523 .get = vt1708_jack_detectect_get,
2524 .put = vt1708_jack_detectect_put,
2525 },
2526 {} /* end */
2527};
2528
Joseph Chanc577b8a2006-11-29 15:29:40 +01002529static int vt1708_parse_auto_config(struct hda_codec *codec)
2530{
2531 struct via_spec *spec = codec->spec;
2532 int err;
2533
Harald Welte76d9b0d2008-09-09 15:50:37 +08002534 /* Add HP and CD pin config connect bit re-config action */
2535 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2536 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2537
Joseph Chanc577b8a2006-11-29 15:29:40 +01002538 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2539 if (err < 0)
2540 return err;
2541 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2542 if (err < 0)
2543 return err;
2544 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2545 return 0; /* can't find valid BIOS pin config */
2546
2547 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2548 if (err < 0)
2549 return err;
2550 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2551 if (err < 0)
2552 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002553 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002554 if (err < 0)
2555 return err;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002556 /* add jack detect on/off control */
2557 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2558 if (err < 0)
2559 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002560
2561 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2562
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002563 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002564 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002565 spec->dig_in_pin = VT1708_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002566 if (spec->autocfg.dig_in_pin)
2567 spec->dig_in_nid = VT1708_DIGIN_NID;
2568
Takashi Iwai603c4012008-07-30 15:01:44 +02002569 if (spec->kctls.list)
2570 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002571
Harald Welte69e52a82008-09-09 15:57:32 +08002572 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002573
Harald Welte0aa62ae2008-09-09 15:58:27 +08002574 spec->input_mux = &spec->private_imux[0];
2575
Harald Weltef8fdd492008-09-15 22:41:31 +08002576 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002577 via_hp_build(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002578
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002579 via_smart51_build(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002580 return 1;
2581}
2582
2583/* init callback for auto-configuration model -- overriding the default init */
2584static int via_auto_init(struct hda_codec *codec)
2585{
Lydia Wang25eaba22009-10-10 19:08:43 +08002586 struct via_spec *spec = codec->spec;
2587
Joseph Chanc577b8a2006-11-29 15:29:40 +01002588 via_init(codec);
2589 via_auto_init_multi_out(codec);
2590 via_auto_init_hp_out(codec);
2591 via_auto_init_analog_input(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08002592 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
Lydia Wang25eaba22009-10-10 19:08:43 +08002593 via_hp_bind_automute(codec);
2594 } else {
2595 via_hp_automute(codec);
2596 via_speaker_automute(codec);
2597 }
2598
Joseph Chanc577b8a2006-11-29 15:29:40 +01002599 return 0;
2600}
2601
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002602static void vt1708_update_hp_jack_state(struct work_struct *work)
2603{
2604 struct via_spec *spec = container_of(work, struct via_spec,
2605 vt1708_hp_work.work);
2606 if (spec->codec_type != VT1708)
2607 return;
2608 /* if jack state toggled */
2609 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002610 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002611 spec->vt1708_hp_present ^= 1;
2612 via_hp_automute(spec->codec);
2613 }
2614 vt1708_start_hp_work(spec);
2615}
2616
Takashi Iwai337b9d02009-07-07 18:18:59 +02002617static int get_mux_nids(struct hda_codec *codec)
2618{
2619 struct via_spec *spec = codec->spec;
2620 hda_nid_t nid, conn[8];
2621 unsigned int type;
2622 int i, n;
2623
2624 for (i = 0; i < spec->num_adc_nids; i++) {
2625 nid = spec->adc_nids[i];
2626 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002627 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002628 if (type == AC_WID_PIN)
2629 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002630 n = snd_hda_get_connections(codec, nid, conn,
2631 ARRAY_SIZE(conn));
2632 if (n <= 0)
2633 break;
2634 if (n > 1) {
2635 spec->mux_nids[i] = nid;
2636 break;
2637 }
2638 nid = conn[0];
2639 }
2640 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002641 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002642}
2643
Joseph Chanc577b8a2006-11-29 15:29:40 +01002644static int patch_vt1708(struct hda_codec *codec)
2645{
2646 struct via_spec *spec;
2647 int err;
2648
2649 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002650 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002651 if (spec == NULL)
2652 return -ENOMEM;
2653
Joseph Chanc577b8a2006-11-29 15:29:40 +01002654 /* automatic parse from the BIOS config */
2655 err = vt1708_parse_auto_config(codec);
2656 if (err < 0) {
2657 via_free(codec);
2658 return err;
2659 } else if (!err) {
2660 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2661 "from BIOS. Using genenic mode...\n");
2662 }
2663
Lydia Wang377ff312009-10-10 19:08:55 +08002664
Joseph Chanc577b8a2006-11-29 15:29:40 +01002665 spec->stream_name_analog = "VT1708 Analog";
2666 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
Takashi Iwaibc9b562382008-05-23 17:50:27 +02002667 /* disable 32bit format on VT1708 */
2668 if (codec->vendor_id == 0x11061708)
2669 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002670 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2671
2672 spec->stream_name_digital = "VT1708 Digital";
2673 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2674 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2675
Lydia Wang377ff312009-10-10 19:08:55 +08002676
Joseph Chanc577b8a2006-11-29 15:29:40 +01002677 if (!spec->adc_nids && spec->input_mux) {
2678 spec->adc_nids = vt1708_adc_nids;
2679 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
Takashi Iwai0f67a612009-08-31 08:12:29 +02002680 get_mux_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002681 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2682 spec->num_mixers++;
2683 }
2684
2685 codec->patch_ops = via_patch_ops;
2686
2687 codec->patch_ops.init = via_auto_init;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002688#ifdef CONFIG_SND_HDA_POWER_SAVE
2689 spec->loopback.amplist = vt1708_loopbacks;
2690#endif
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002691 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002692 return 0;
2693}
2694
2695/* capture mixer elements */
2696static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2697 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2698 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2699 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2700 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2701 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2702 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2703 {
2704 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2705 /* The multiple "Capture Source" controls confuse alsamixer
2706 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01002707 */
2708 /* .name = "Capture Source", */
2709 .name = "Input Source",
2710 .count = 1,
2711 .info = via_mux_enum_info,
2712 .get = via_mux_enum_get,
2713 .put = via_mux_enum_put,
2714 },
2715 { } /* end */
2716};
2717
Harald Welte69e52a82008-09-09 15:57:32 +08002718static struct hda_verb vt1709_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002719 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2720 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002721 { }
2722};
2723
Joseph Chanc577b8a2006-11-29 15:29:40 +01002724/*
2725 * generic initialization of ADC, input mixers and output mixers
2726 */
2727static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2728 /*
2729 * Unmute ADC0-2 and set the default input to mic-in
2730 */
2731 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2732 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2733 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2734
2735
Josepch Chanf7278fd2007-12-13 16:40:40 +01002736 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01002737 * mixer widget
2738 */
2739 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01002740 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2741 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2742 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2743 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2744 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002745
2746 /*
2747 * Set up output selector (0x1a, 0x1b, 0x29)
2748 */
2749 /* set vol=0 to output mixers */
2750 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2751 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2752 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2753
2754 /*
2755 * Unmute PW3 and PW4
2756 */
2757 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2758 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2759
Lydia Wangbfdc6752009-10-10 19:08:50 +08002760 /* Set input of PW4 as MW0 */
2761 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002762 /* PW9 Output enable */
2763 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2764 { }
2765};
2766
2767static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2768 .substreams = 1,
2769 .channels_min = 2,
2770 .channels_max = 10,
2771 .nid = 0x10, /* NID to query formats and rates */
2772 .ops = {
2773 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002774 .prepare = via_playback_multi_pcm_prepare,
2775 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002776 },
2777};
2778
2779static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2780 .substreams = 1,
2781 .channels_min = 2,
2782 .channels_max = 6,
2783 .nid = 0x10, /* NID to query formats and rates */
2784 .ops = {
2785 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002786 .prepare = via_playback_multi_pcm_prepare,
2787 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002788 },
2789};
2790
2791static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2792 .substreams = 2,
2793 .channels_min = 2,
2794 .channels_max = 2,
2795 .nid = 0x14, /* NID to query formats and rates */
2796 .ops = {
2797 .prepare = via_capture_pcm_prepare,
2798 .cleanup = via_capture_pcm_cleanup
2799 },
2800};
2801
2802static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2803 .substreams = 1,
2804 .channels_min = 2,
2805 .channels_max = 2,
2806 /* NID is set in via_build_pcms */
2807 .ops = {
2808 .open = via_dig_playback_pcm_open,
2809 .close = via_dig_playback_pcm_close
2810 },
2811};
2812
2813static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2814 .substreams = 1,
2815 .channels_min = 2,
2816 .channels_max = 2,
2817};
2818
2819static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2820 const struct auto_pin_cfg *cfg)
2821{
2822 int i;
2823 hda_nid_t nid;
2824
2825 if (cfg->line_outs == 4) /* 10 channels */
2826 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2827 else if (cfg->line_outs == 3) /* 6 channels */
2828 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2829
2830 spec->multiout.dac_nids = spec->private_dac_nids;
2831
2832 if (cfg->line_outs == 4) { /* 10 channels */
2833 for (i = 0; i < cfg->line_outs; i++) {
2834 nid = cfg->line_out_pins[i];
2835 if (nid) {
2836 /* config dac list */
2837 switch (i) {
2838 case AUTO_SEQ_FRONT:
2839 /* AOW0 */
2840 spec->multiout.dac_nids[i] = 0x10;
2841 break;
2842 case AUTO_SEQ_CENLFE:
2843 /* AOW2 */
2844 spec->multiout.dac_nids[i] = 0x12;
2845 break;
2846 case AUTO_SEQ_SURROUND:
2847 /* AOW3 */
Harald Weltefb4cb772008-09-09 15:53:36 +08002848 spec->multiout.dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002849 break;
2850 case AUTO_SEQ_SIDE:
2851 /* AOW1 */
Harald Weltefb4cb772008-09-09 15:53:36 +08002852 spec->multiout.dac_nids[i] = 0x27;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002853 break;
2854 default:
2855 break;
2856 }
2857 }
2858 }
2859 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2860
2861 } else if (cfg->line_outs == 3) { /* 6 channels */
Lydia Wang377ff312009-10-10 19:08:55 +08002862 for (i = 0; i < cfg->line_outs; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002863 nid = cfg->line_out_pins[i];
2864 if (nid) {
2865 /* config dac list */
Lydia Wang377ff312009-10-10 19:08:55 +08002866 switch (i) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002867 case AUTO_SEQ_FRONT:
2868 /* AOW0 */
2869 spec->multiout.dac_nids[i] = 0x10;
2870 break;
2871 case AUTO_SEQ_CENLFE:
2872 /* AOW2 */
2873 spec->multiout.dac_nids[i] = 0x12;
2874 break;
2875 case AUTO_SEQ_SURROUND:
2876 /* AOW1 */
2877 spec->multiout.dac_nids[i] = 0x11;
2878 break;
2879 default:
2880 break;
2881 }
2882 }
2883 }
2884 }
2885
2886 return 0;
2887}
2888
2889/* add playback controls from the parsed DAC table */
2890static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2891 const struct auto_pin_cfg *cfg)
2892{
2893 char name[32];
2894 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
Lydia Wang4483a2f2009-10-10 19:08:29 +08002895 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
Joseph Chanc577b8a2006-11-29 15:29:40 +01002896 int i, err;
2897
2898 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2899 nid = cfg->line_out_pins[i];
2900
Lydia Wang377ff312009-10-10 19:08:55 +08002901 if (!nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002902 continue;
2903
Lydia Wang4483a2f2009-10-10 19:08:29 +08002904 nid_vol = nid_vols[i];
2905
Joseph Chanc577b8a2006-11-29 15:29:40 +01002906 if (i == AUTO_SEQ_CENLFE) {
2907 /* Center/LFE */
2908 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2909 "Center Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002910 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002911 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002912 if (err < 0)
2913 return err;
2914 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2915 "LFE Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002916 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002917 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002918 if (err < 0)
2919 return err;
2920 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2921 "Center Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002922 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002923 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002924 if (err < 0)
2925 return err;
2926 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2927 "LFE Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002928 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002929 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002930 if (err < 0)
2931 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002932 } else if (i == AUTO_SEQ_FRONT) {
Lydia Wang4483a2f2009-10-10 19:08:29 +08002933 /* ADD control to mixer index 0 */
Joseph Chanc577b8a2006-11-29 15:29:40 +01002934 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2935 "Master Front Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002936 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002937 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002938 if (err < 0)
2939 return err;
2940 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2941 "Master Front Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002942 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002943 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002944 if (err < 0)
2945 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002946
Joseph Chanc577b8a2006-11-29 15:29:40 +01002947 /* add control to PW3 */
2948 sprintf(name, "%s Playback Volume", chname[i]);
2949 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002950 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2951 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002952 if (err < 0)
2953 return err;
2954 sprintf(name, "%s Playback Switch", chname[i]);
2955 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002956 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2957 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002958 if (err < 0)
2959 return err;
2960 } else if (i == AUTO_SEQ_SURROUND) {
2961 sprintf(name, "%s Playback Volume", chname[i]);
2962 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002963 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002964 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002965 if (err < 0)
2966 return err;
2967 sprintf(name, "%s Playback Switch", chname[i]);
2968 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002969 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002970 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002971 if (err < 0)
2972 return err;
2973 } else if (i == AUTO_SEQ_SIDE) {
2974 sprintf(name, "%s Playback Volume", chname[i]);
2975 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002976 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002977 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002978 if (err < 0)
2979 return err;
2980 sprintf(name, "%s Playback Switch", chname[i]);
2981 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002982 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002983 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002984 if (err < 0)
2985 return err;
2986 }
2987 }
2988
2989 return 0;
2990}
2991
2992static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2993{
2994 int err;
2995
2996 if (!pin)
2997 return 0;
2998
2999 if (spec->multiout.num_dacs == 5) /* 10 channels */
3000 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
3001 else if (spec->multiout.num_dacs == 3) /* 6 channels */
3002 spec->multiout.hp_nid = 0;
Lydia Wangcdc17842009-10-10 19:07:47 +08003003 spec->hp_independent_mode_index = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01003004
3005 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3006 "Headphone Playback Volume",
3007 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3008 if (err < 0)
3009 return err;
3010 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3011 "Headphone Playback Switch",
3012 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3013 if (err < 0)
3014 return err;
3015
3016 return 0;
3017}
3018
3019/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003020static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
Joseph Chanc577b8a2006-11-29 15:29:40 +01003021 const struct auto_pin_cfg *cfg)
3022{
Takashi Iwaif3268512010-08-30 11:00:19 +02003023 static hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
Takashi Iwai10a20af2010-09-09 16:28:02 +02003024 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02003025 ARRAY_SIZE(pin_idxs));
Joseph Chanc577b8a2006-11-29 15:29:40 +01003026}
3027
3028static int vt1709_parse_auto_config(struct hda_codec *codec)
3029{
3030 struct via_spec *spec = codec->spec;
3031 int err;
3032
3033 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3034 if (err < 0)
3035 return err;
3036 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
3037 if (err < 0)
3038 return err;
3039 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3040 return 0; /* can't find valid BIOS pin config */
3041
3042 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
3043 if (err < 0)
3044 return err;
3045 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3046 if (err < 0)
3047 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003048 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01003049 if (err < 0)
3050 return err;
3051
3052 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3053
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003054 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01003055 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02003056 spec->dig_in_pin = VT1709_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01003057 if (spec->autocfg.dig_in_pin)
3058 spec->dig_in_nid = VT1709_DIGIN_NID;
3059
Takashi Iwai603c4012008-07-30 15:01:44 +02003060 if (spec->kctls.list)
3061 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01003062
Harald Welte0aa62ae2008-09-09 15:58:27 +08003063 spec->input_mux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01003064
Harald Weltef8fdd492008-09-15 22:41:31 +08003065 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003066 via_hp_build(codec);
Harald Weltef8fdd492008-09-15 22:41:31 +08003067
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003068 via_smart51_build(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01003069 return 1;
3070}
3071
Takashi Iwaicb53c622007-08-10 17:21:45 +02003072#ifdef CONFIG_SND_HDA_POWER_SAVE
3073static struct hda_amp_list vt1709_loopbacks[] = {
3074 { 0x18, HDA_INPUT, 1 },
3075 { 0x18, HDA_INPUT, 2 },
3076 { 0x18, HDA_INPUT, 3 },
3077 { 0x18, HDA_INPUT, 4 },
3078 { } /* end */
3079};
3080#endif
3081
Joseph Chanc577b8a2006-11-29 15:29:40 +01003082static int patch_vt1709_10ch(struct hda_codec *codec)
3083{
3084 struct via_spec *spec;
3085 int err;
3086
3087 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003088 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01003089 if (spec == NULL)
3090 return -ENOMEM;
3091
Joseph Chanc577b8a2006-11-29 15:29:40 +01003092 err = vt1709_parse_auto_config(codec);
3093 if (err < 0) {
3094 via_free(codec);
3095 return err;
3096 } else if (!err) {
3097 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3098 "Using genenic mode...\n");
3099 }
3100
Harald Welte69e52a82008-09-09 15:57:32 +08003101 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3102 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01003103
3104 spec->stream_name_analog = "VT1709 Analog";
3105 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3106 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3107
3108 spec->stream_name_digital = "VT1709 Digital";
3109 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3110 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3111
Lydia Wang377ff312009-10-10 19:08:55 +08003112
Joseph Chanc577b8a2006-11-29 15:29:40 +01003113 if (!spec->adc_nids && spec->input_mux) {
3114 spec->adc_nids = vt1709_adc_nids;
3115 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02003116 get_mux_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01003117 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3118 spec->num_mixers++;
3119 }
3120
3121 codec->patch_ops = via_patch_ops;
3122
3123 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003124 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02003125#ifdef CONFIG_SND_HDA_POWER_SAVE
3126 spec->loopback.amplist = vt1709_loopbacks;
3127#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01003128
3129 return 0;
3130}
3131/*
3132 * generic initialization of ADC, input mixers and output mixers
3133 */
3134static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3135 /*
3136 * Unmute ADC0-2 and set the default input to mic-in
3137 */
3138 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3139 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3140 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3141
3142
3143 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3144 * mixer widget
3145 */
3146 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3147 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3148 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3149 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3150 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3151 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3152
3153 /*
3154 * Set up output selector (0x1a, 0x1b, 0x29)
3155 */
3156 /* set vol=0 to output mixers */
3157 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3158 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3159 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3160
3161 /*
3162 * Unmute PW3 and PW4
3163 */
3164 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3165 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3166
3167 /* Set input of PW4 as MW0 */
3168 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01003169 /* PW9 Output enable */
3170 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3171 { }
3172};
3173
3174static int patch_vt1709_6ch(struct hda_codec *codec)
3175{
3176 struct via_spec *spec;
3177 int err;
3178
3179 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003180 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01003181 if (spec == NULL)
3182 return -ENOMEM;
3183
Joseph Chanc577b8a2006-11-29 15:29:40 +01003184 err = vt1709_parse_auto_config(codec);
3185 if (err < 0) {
3186 via_free(codec);
3187 return err;
3188 } else if (!err) {
3189 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3190 "Using genenic mode...\n");
3191 }
3192
Harald Welte69e52a82008-09-09 15:57:32 +08003193 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3194 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01003195
3196 spec->stream_name_analog = "VT1709 Analog";
3197 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3198 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3199
3200 spec->stream_name_digital = "VT1709 Digital";
3201 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3202 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3203
Lydia Wang377ff312009-10-10 19:08:55 +08003204
Joseph Chanc577b8a2006-11-29 15:29:40 +01003205 if (!spec->adc_nids && spec->input_mux) {
3206 spec->adc_nids = vt1709_adc_nids;
3207 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02003208 get_mux_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01003209 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3210 spec->num_mixers++;
3211 }
3212
3213 codec->patch_ops = via_patch_ops;
3214
3215 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003216 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02003217#ifdef CONFIG_SND_HDA_POWER_SAVE
3218 spec->loopback.amplist = vt1709_loopbacks;
3219#endif
Josepch Chanf7278fd2007-12-13 16:40:40 +01003220 return 0;
3221}
3222
3223/* capture mixer elements */
3224static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3225 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3226 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3227 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3228 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3229 {
3230 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3231 /* The multiple "Capture Source" controls confuse alsamixer
3232 * So call somewhat different..
Josepch Chanf7278fd2007-12-13 16:40:40 +01003233 */
3234 /* .name = "Capture Source", */
3235 .name = "Input Source",
3236 .count = 1,
3237 .info = via_mux_enum_info,
3238 .get = via_mux_enum_get,
3239 .put = via_mux_enum_put,
3240 },
3241 { } /* end */
3242};
3243/*
3244 * generic initialization of ADC, input mixers and output mixers
3245 */
3246static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3247 /*
3248 * Unmute ADC0-1 and set the default input to mic-in
3249 */
3250 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3251 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3252
3253
3254 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3255 * mixer widget
3256 */
3257 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3258 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3259 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3260 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3261 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3262 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3263
3264 /*
3265 * Set up output mixers
3266 */
3267 /* set vol=0 to output mixers */
3268 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3269 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3270 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3271
3272 /* Setup default input to PW4 */
Lydia Wangbfdc6752009-10-10 19:08:50 +08003273 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
Josepch Chanf7278fd2007-12-13 16:40:40 +01003274 /* PW9 Output enable */
3275 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3276 /* PW10 Input enable */
3277 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3278 { }
3279};
3280
3281static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3282 /*
3283 * Unmute ADC0-1 and set the default input to mic-in
3284 */
3285 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3286 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3287
3288
3289 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3290 * mixer widget
3291 */
3292 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3293 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3294 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3295 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3296 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3297 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3298
3299 /*
3300 * Set up output mixers
3301 */
3302 /* set vol=0 to output mixers */
3303 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3304 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3305 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3306
3307 /* Setup default input of PW4 to MW0 */
3308 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3309 /* PW9 Output enable */
3310 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3311 /* PW10 Input enable */
3312 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3313 { }
3314};
3315
Harald Welte69e52a82008-09-09 15:57:32 +08003316static struct hda_verb vt1708B_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003317 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3318 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3319 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3320 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3321 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3322 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3323 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3324 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3325 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003326 { }
3327};
3328
Lydia Wang17314372009-10-10 19:07:37 +08003329static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3330 struct hda_codec *codec,
3331 struct snd_pcm_substream *substream)
3332{
3333 int idle = substream->pstr->substream_opened == 1
3334 && substream->ref_count == 0;
3335
3336 analog_low_current_mode(codec, idle);
3337 return 0;
3338}
3339
Josepch Chanf7278fd2007-12-13 16:40:40 +01003340static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08003341 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003342 .channels_min = 2,
3343 .channels_max = 8,
3344 .nid = 0x10, /* NID to query formats and rates */
3345 .ops = {
3346 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08003347 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003348 .cleanup = via_playback_multi_pcm_cleanup,
3349 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01003350 },
3351};
3352
3353static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08003354 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003355 .channels_min = 2,
3356 .channels_max = 4,
3357 .nid = 0x10, /* NID to query formats and rates */
3358 .ops = {
3359 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08003360 .prepare = via_playback_multi_pcm_prepare,
3361 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01003362 },
3363};
3364
3365static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3366 .substreams = 2,
3367 .channels_min = 2,
3368 .channels_max = 2,
3369 .nid = 0x13, /* NID to query formats and rates */
3370 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003371 .open = via_pcm_open_close,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003372 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003373 .cleanup = via_capture_pcm_cleanup,
3374 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01003375 },
3376};
3377
3378static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3379 .substreams = 1,
3380 .channels_min = 2,
3381 .channels_max = 2,
3382 /* NID is set in via_build_pcms */
3383 .ops = {
3384 .open = via_dig_playback_pcm_open,
3385 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003386 .prepare = via_dig_playback_pcm_prepare,
3387 .cleanup = via_dig_playback_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01003388 },
3389};
3390
3391static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3392 .substreams = 1,
3393 .channels_min = 2,
3394 .channels_max = 2,
3395};
3396
3397/* fill in the dac_nids table from the parsed pin configuration */
3398static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3399 const struct auto_pin_cfg *cfg)
3400{
3401 int i;
3402 hda_nid_t nid;
3403
3404 spec->multiout.num_dacs = cfg->line_outs;
3405
3406 spec->multiout.dac_nids = spec->private_dac_nids;
3407
3408 for (i = 0; i < 4; i++) {
3409 nid = cfg->line_out_pins[i];
3410 if (nid) {
3411 /* config dac list */
3412 switch (i) {
3413 case AUTO_SEQ_FRONT:
3414 spec->multiout.dac_nids[i] = 0x10;
3415 break;
3416 case AUTO_SEQ_CENLFE:
3417 spec->multiout.dac_nids[i] = 0x24;
3418 break;
3419 case AUTO_SEQ_SURROUND:
Harald Weltefb4cb772008-09-09 15:53:36 +08003420 spec->multiout.dac_nids[i] = 0x11;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003421 break;
3422 case AUTO_SEQ_SIDE:
Harald Weltefb4cb772008-09-09 15:53:36 +08003423 spec->multiout.dac_nids[i] = 0x25;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003424 break;
3425 }
3426 }
3427 }
3428
3429 return 0;
3430}
3431
3432/* add playback controls from the parsed DAC table */
3433static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3434 const struct auto_pin_cfg *cfg)
3435{
3436 char name[32];
3437 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
Harald Weltefb4cb772008-09-09 15:53:36 +08003438 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
Josepch Chanf7278fd2007-12-13 16:40:40 +01003439 hda_nid_t nid, nid_vol = 0;
3440 int i, err;
3441
3442 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3443 nid = cfg->line_out_pins[i];
3444
3445 if (!nid)
3446 continue;
3447
3448 nid_vol = nid_vols[i];
3449
3450 if (i == AUTO_SEQ_CENLFE) {
3451 /* Center/LFE */
3452 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3453 "Center Playback Volume",
3454 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3455 HDA_OUTPUT));
3456 if (err < 0)
3457 return err;
3458 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3459 "LFE Playback Volume",
3460 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3461 HDA_OUTPUT));
3462 if (err < 0)
3463 return err;
3464 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3465 "Center Playback Switch",
3466 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3467 HDA_OUTPUT));
3468 if (err < 0)
3469 return err;
3470 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3471 "LFE Playback Switch",
3472 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3473 HDA_OUTPUT));
3474 if (err < 0)
3475 return err;
3476 } else if (i == AUTO_SEQ_FRONT) {
3477 /* add control to mixer index 0 */
3478 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3479 "Master Front Playback Volume",
3480 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3481 HDA_INPUT));
3482 if (err < 0)
3483 return err;
3484 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3485 "Master Front Playback Switch",
3486 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3487 HDA_INPUT));
3488 if (err < 0)
3489 return err;
3490
3491 /* add control to PW3 */
3492 sprintf(name, "%s Playback Volume", chname[i]);
3493 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3494 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3495 HDA_OUTPUT));
3496 if (err < 0)
3497 return err;
3498 sprintf(name, "%s Playback Switch", chname[i]);
3499 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3500 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3501 HDA_OUTPUT));
3502 if (err < 0)
3503 return err;
3504 } else {
3505 sprintf(name, "%s Playback Volume", chname[i]);
3506 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3507 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3508 HDA_OUTPUT));
3509 if (err < 0)
3510 return err;
3511 sprintf(name, "%s Playback Switch", chname[i]);
3512 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3513 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3514 HDA_OUTPUT));
3515 if (err < 0)
3516 return err;
3517 }
3518 }
3519
3520 return 0;
3521}
3522
3523static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3524{
3525 int err;
3526
3527 if (!pin)
3528 return 0;
3529
3530 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08003531 spec->hp_independent_mode_index = 1;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003532
3533 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3534 "Headphone Playback Volume",
3535 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3536 if (err < 0)
3537 return err;
3538 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3539 "Headphone Playback Switch",
3540 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3541 if (err < 0)
3542 return err;
3543
Harald Welte0aa62ae2008-09-09 15:58:27 +08003544 create_hp_imux(spec);
3545
Josepch Chanf7278fd2007-12-13 16:40:40 +01003546 return 0;
3547}
3548
3549/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003550static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003551 const struct auto_pin_cfg *cfg)
3552{
Takashi Iwaif3268512010-08-30 11:00:19 +02003553 static hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
Takashi Iwai10a20af2010-09-09 16:28:02 +02003554 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02003555 ARRAY_SIZE(pin_idxs));
Josepch Chanf7278fd2007-12-13 16:40:40 +01003556}
3557
3558static int vt1708B_parse_auto_config(struct hda_codec *codec)
3559{
3560 struct via_spec *spec = codec->spec;
3561 int err;
3562
3563 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3564 if (err < 0)
3565 return err;
3566 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3567 if (err < 0)
3568 return err;
3569 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3570 return 0; /* can't find valid BIOS pin config */
3571
3572 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3573 if (err < 0)
3574 return err;
3575 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3576 if (err < 0)
3577 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003578 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003579 if (err < 0)
3580 return err;
3581
3582 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3583
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003584 if (spec->autocfg.dig_outs)
Josepch Chanf7278fd2007-12-13 16:40:40 +01003585 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02003586 spec->dig_in_pin = VT1708B_DIGIN_PIN;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003587 if (spec->autocfg.dig_in_pin)
3588 spec->dig_in_nid = VT1708B_DIGIN_NID;
3589
Takashi Iwai603c4012008-07-30 15:01:44 +02003590 if (spec->kctls.list)
3591 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003592
Harald Welte0aa62ae2008-09-09 15:58:27 +08003593 spec->input_mux = &spec->private_imux[0];
3594
Harald Weltef8fdd492008-09-15 22:41:31 +08003595 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003596 via_hp_build(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003597
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003598 via_smart51_build(spec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003599 return 1;
3600}
3601
3602#ifdef CONFIG_SND_HDA_POWER_SAVE
3603static struct hda_amp_list vt1708B_loopbacks[] = {
3604 { 0x16, HDA_INPUT, 1 },
3605 { 0x16, HDA_INPUT, 2 },
3606 { 0x16, HDA_INPUT, 3 },
3607 { 0x16, HDA_INPUT, 4 },
3608 { } /* end */
3609};
3610#endif
Lydia Wang518bf3b2009-10-10 19:07:29 +08003611static int patch_vt1708S(struct hda_codec *codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003612static int patch_vt1708B_8ch(struct hda_codec *codec)
3613{
3614 struct via_spec *spec;
3615 int err;
3616
Lydia Wang518bf3b2009-10-10 19:07:29 +08003617 if (get_codec_type(codec) == VT1708BCE)
3618 return patch_vt1708S(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003619 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003620 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003621 if (spec == NULL)
3622 return -ENOMEM;
3623
Josepch Chanf7278fd2007-12-13 16:40:40 +01003624 /* automatic parse from the BIOS config */
3625 err = vt1708B_parse_auto_config(codec);
3626 if (err < 0) {
3627 via_free(codec);
3628 return err;
3629 } else if (!err) {
3630 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3631 "from BIOS. Using genenic mode...\n");
3632 }
3633
Harald Welte69e52a82008-09-09 15:57:32 +08003634 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3635 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003636
3637 spec->stream_name_analog = "VT1708B Analog";
3638 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3639 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3640
3641 spec->stream_name_digital = "VT1708B Digital";
3642 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3643 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3644
3645 if (!spec->adc_nids && spec->input_mux) {
3646 spec->adc_nids = vt1708B_adc_nids;
3647 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02003648 get_mux_nids(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003649 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3650 spec->num_mixers++;
3651 }
3652
3653 codec->patch_ops = via_patch_ops;
3654
3655 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003656 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003657#ifdef CONFIG_SND_HDA_POWER_SAVE
3658 spec->loopback.amplist = vt1708B_loopbacks;
3659#endif
3660
3661 return 0;
3662}
3663
3664static int patch_vt1708B_4ch(struct hda_codec *codec)
3665{
3666 struct via_spec *spec;
3667 int err;
3668
3669 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003670 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003671 if (spec == NULL)
3672 return -ENOMEM;
3673
Josepch Chanf7278fd2007-12-13 16:40:40 +01003674 /* automatic parse from the BIOS config */
3675 err = vt1708B_parse_auto_config(codec);
3676 if (err < 0) {
3677 via_free(codec);
3678 return err;
3679 } else if (!err) {
3680 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3681 "from BIOS. Using genenic mode...\n");
3682 }
3683
Harald Welte69e52a82008-09-09 15:57:32 +08003684 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3685 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003686
3687 spec->stream_name_analog = "VT1708B Analog";
3688 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3689 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3690
3691 spec->stream_name_digital = "VT1708B Digital";
3692 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3693 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3694
3695 if (!spec->adc_nids && spec->input_mux) {
3696 spec->adc_nids = vt1708B_adc_nids;
3697 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02003698 get_mux_nids(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003699 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3700 spec->num_mixers++;
3701 }
3702
3703 codec->patch_ops = via_patch_ops;
3704
3705 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003706 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003707#ifdef CONFIG_SND_HDA_POWER_SAVE
3708 spec->loopback.amplist = vt1708B_loopbacks;
3709#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01003710
3711 return 0;
3712}
3713
Harald Welted949cac2008-09-09 15:56:01 +08003714/* Patch for VT1708S */
3715
3716/* capture mixer elements */
3717static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3718 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3719 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3720 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3721 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
Lydia Wang6369bcf2009-10-10 19:08:31 +08003722 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3723 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3724 HDA_INPUT),
Harald Welted949cac2008-09-09 15:56:01 +08003725 {
3726 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3727 /* The multiple "Capture Source" controls confuse alsamixer
3728 * So call somewhat different..
3729 */
3730 /* .name = "Capture Source", */
3731 .name = "Input Source",
3732 .count = 1,
3733 .info = via_mux_enum_info,
3734 .get = via_mux_enum_get,
3735 .put = via_mux_enum_put,
3736 },
3737 { } /* end */
3738};
3739
3740static struct hda_verb vt1708S_volume_init_verbs[] = {
3741 /* Unmute ADC0-1 and set the default input to mic-in */
3742 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3743 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3744
3745 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3746 * analog-loopback mixer widget */
3747 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3748 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3749 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3750 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3751 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3752 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3753
3754 /* Setup default input of PW4 to MW0 */
3755 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
Harald Welte5691ec72008-09-15 22:42:26 +08003756 /* PW9, PW10 Output enable */
Harald Welted949cac2008-09-09 15:56:01 +08003757 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welte5691ec72008-09-15 22:42:26 +08003758 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welted7426322008-09-15 22:43:23 +08003759 /* Enable Mic Boost Volume backdoor */
3760 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003761 /* don't bybass mixer */
3762 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08003763 { }
3764};
3765
Harald Welte69e52a82008-09-09 15:57:32 +08003766static struct hda_verb vt1708S_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003767 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3768 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3769 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3770 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3771 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3772 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3773 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3774 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3775 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003776 { }
3777};
3778
Harald Welted949cac2008-09-09 15:56:01 +08003779static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3780 .substreams = 2,
3781 .channels_min = 2,
3782 .channels_max = 8,
3783 .nid = 0x10, /* NID to query formats and rates */
3784 .ops = {
3785 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08003786 .prepare = via_playback_multi_pcm_prepare,
3787 .cleanup = via_playback_multi_pcm_cleanup,
Lydia Wang17314372009-10-10 19:07:37 +08003788 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003789 },
3790};
3791
3792static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3793 .substreams = 2,
3794 .channels_min = 2,
3795 .channels_max = 2,
3796 .nid = 0x13, /* NID to query formats and rates */
3797 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003798 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08003799 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003800 .cleanup = via_capture_pcm_cleanup,
3801 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003802 },
3803};
3804
3805static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
Takashi Iwai9da29272009-05-07 16:31:14 +02003806 .substreams = 1,
Harald Welted949cac2008-09-09 15:56:01 +08003807 .channels_min = 2,
3808 .channels_max = 2,
3809 /* NID is set in via_build_pcms */
3810 .ops = {
3811 .open = via_dig_playback_pcm_open,
3812 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003813 .prepare = via_dig_playback_pcm_prepare,
3814 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08003815 },
3816};
3817
3818/* fill in the dac_nids table from the parsed pin configuration */
3819static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3820 const struct auto_pin_cfg *cfg)
3821{
3822 int i;
3823 hda_nid_t nid;
3824
3825 spec->multiout.num_dacs = cfg->line_outs;
3826
3827 spec->multiout.dac_nids = spec->private_dac_nids;
3828
3829 for (i = 0; i < 4; i++) {
3830 nid = cfg->line_out_pins[i];
3831 if (nid) {
3832 /* config dac list */
3833 switch (i) {
3834 case AUTO_SEQ_FRONT:
3835 spec->multiout.dac_nids[i] = 0x10;
3836 break;
3837 case AUTO_SEQ_CENLFE:
3838 spec->multiout.dac_nids[i] = 0x24;
3839 break;
3840 case AUTO_SEQ_SURROUND:
3841 spec->multiout.dac_nids[i] = 0x11;
3842 break;
3843 case AUTO_SEQ_SIDE:
3844 spec->multiout.dac_nids[i] = 0x25;
3845 break;
3846 }
3847 }
3848 }
3849
Clemens Ladisch32e01912010-07-12 16:28:50 +02003850 /* for Smart 5.1, line/mic inputs double as output pins */
3851 if (cfg->line_outs == 1) {
3852 spec->multiout.num_dacs = 3;
3853 spec->multiout.dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3854 spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3855 }
3856
Harald Welted949cac2008-09-09 15:56:01 +08003857 return 0;
3858}
3859
3860/* add playback controls from the parsed DAC table */
3861static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3862 const struct auto_pin_cfg *cfg)
3863{
3864 char name[32];
3865 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3866 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3867 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3868 hda_nid_t nid, nid_vol, nid_mute;
3869 int i, err;
3870
3871 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3872 nid = cfg->line_out_pins[i];
3873
Clemens Ladisch32e01912010-07-12 16:28:50 +02003874 /* for Smart 5.1, there are always at least six channels */
3875 if (!nid && i > AUTO_SEQ_CENLFE)
Harald Welted949cac2008-09-09 15:56:01 +08003876 continue;
3877
3878 nid_vol = nid_vols[i];
3879 nid_mute = nid_mutes[i];
3880
3881 if (i == AUTO_SEQ_CENLFE) {
3882 /* Center/LFE */
3883 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3884 "Center Playback Volume",
3885 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3886 HDA_OUTPUT));
3887 if (err < 0)
3888 return err;
3889 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3890 "LFE Playback Volume",
3891 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3892 HDA_OUTPUT));
3893 if (err < 0)
3894 return err;
3895 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3896 "Center Playback Switch",
3897 HDA_COMPOSE_AMP_VAL(nid_mute,
3898 1, 0,
3899 HDA_OUTPUT));
3900 if (err < 0)
3901 return err;
3902 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3903 "LFE Playback Switch",
3904 HDA_COMPOSE_AMP_VAL(nid_mute,
3905 2, 0,
3906 HDA_OUTPUT));
3907 if (err < 0)
3908 return err;
3909 } else if (i == AUTO_SEQ_FRONT) {
3910 /* add control to mixer index 0 */
3911 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3912 "Master Front Playback Volume",
3913 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3914 HDA_INPUT));
3915 if (err < 0)
3916 return err;
3917 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3918 "Master Front Playback Switch",
3919 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3920 HDA_INPUT));
3921 if (err < 0)
3922 return err;
3923
3924 /* Front */
3925 sprintf(name, "%s Playback Volume", chname[i]);
3926 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3927 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3928 HDA_OUTPUT));
3929 if (err < 0)
3930 return err;
3931 sprintf(name, "%s Playback Switch", chname[i]);
3932 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3933 HDA_COMPOSE_AMP_VAL(nid_mute,
3934 3, 0,
3935 HDA_OUTPUT));
3936 if (err < 0)
3937 return err;
3938 } else {
3939 sprintf(name, "%s Playback Volume", chname[i]);
3940 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3941 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3942 HDA_OUTPUT));
3943 if (err < 0)
3944 return err;
3945 sprintf(name, "%s Playback Switch", chname[i]);
3946 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3947 HDA_COMPOSE_AMP_VAL(nid_mute,
3948 3, 0,
3949 HDA_OUTPUT));
3950 if (err < 0)
3951 return err;
3952 }
3953 }
3954
3955 return 0;
3956}
3957
3958static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3959{
3960 int err;
3961
3962 if (!pin)
3963 return 0;
3964
3965 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08003966 spec->hp_independent_mode_index = 1;
Harald Welted949cac2008-09-09 15:56:01 +08003967
3968 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3969 "Headphone Playback Volume",
3970 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3971 if (err < 0)
3972 return err;
3973
3974 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3975 "Headphone Playback Switch",
3976 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3977 if (err < 0)
3978 return err;
3979
Harald Welte0aa62ae2008-09-09 15:58:27 +08003980 create_hp_imux(spec);
3981
Harald Welted949cac2008-09-09 15:56:01 +08003982 return 0;
3983}
3984
3985/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003986static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08003987 const struct auto_pin_cfg *cfg)
3988{
Takashi Iwaif3268512010-08-30 11:00:19 +02003989 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
Takashi Iwai10a20af2010-09-09 16:28:02 +02003990 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02003991 ARRAY_SIZE(pin_idxs));
Harald Welted949cac2008-09-09 15:56:01 +08003992}
3993
Takashi Iwai9da29272009-05-07 16:31:14 +02003994/* fill out digital output widgets; one for master and one for slave outputs */
3995static void fill_dig_outs(struct hda_codec *codec)
3996{
3997 struct via_spec *spec = codec->spec;
3998 int i;
3999
4000 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4001 hda_nid_t nid;
4002 int conn;
4003
4004 nid = spec->autocfg.dig_out_pins[i];
4005 if (!nid)
4006 continue;
4007 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4008 if (conn < 1)
4009 continue;
4010 if (!spec->multiout.dig_out_nid)
4011 spec->multiout.dig_out_nid = nid;
4012 else {
4013 spec->slave_dig_outs[0] = nid;
4014 break; /* at most two dig outs */
4015 }
4016 }
4017}
4018
Harald Welted949cac2008-09-09 15:56:01 +08004019static int vt1708S_parse_auto_config(struct hda_codec *codec)
4020{
4021 struct via_spec *spec = codec->spec;
4022 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004023
Takashi Iwai9da29272009-05-07 16:31:14 +02004024 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08004025 if (err < 0)
4026 return err;
4027 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4028 if (err < 0)
4029 return err;
4030 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4031 return 0; /* can't find valid BIOS pin config */
4032
4033 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4034 if (err < 0)
4035 return err;
4036 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4037 if (err < 0)
4038 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02004039 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08004040 if (err < 0)
4041 return err;
4042
4043 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4044
Takashi Iwai9da29272009-05-07 16:31:14 +02004045 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08004046
Takashi Iwai603c4012008-07-30 15:01:44 +02004047 if (spec->kctls.list)
4048 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08004049
Harald Welte0aa62ae2008-09-09 15:58:27 +08004050 spec->input_mux = &spec->private_imux[0];
4051
Harald Weltef8fdd492008-09-15 22:41:31 +08004052 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004053 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004054
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004055 via_smart51_build(spec);
Harald Welted949cac2008-09-09 15:56:01 +08004056 return 1;
4057}
4058
4059#ifdef CONFIG_SND_HDA_POWER_SAVE
4060static struct hda_amp_list vt1708S_loopbacks[] = {
4061 { 0x16, HDA_INPUT, 1 },
4062 { 0x16, HDA_INPUT, 2 },
4063 { 0x16, HDA_INPUT, 3 },
4064 { 0x16, HDA_INPUT, 4 },
4065 { } /* end */
4066};
4067#endif
4068
Lydia Wang6369bcf2009-10-10 19:08:31 +08004069static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4070 int offset, int num_steps, int step_size)
4071{
4072 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4073 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4074 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4075 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4076 (0 << AC_AMPCAP_MUTE_SHIFT));
4077}
4078
Harald Welted949cac2008-09-09 15:56:01 +08004079static int patch_vt1708S(struct hda_codec *codec)
4080{
4081 struct via_spec *spec;
4082 int err;
4083
4084 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004085 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004086 if (spec == NULL)
4087 return -ENOMEM;
4088
Harald Welted949cac2008-09-09 15:56:01 +08004089 /* automatic parse from the BIOS config */
4090 err = vt1708S_parse_auto_config(codec);
4091 if (err < 0) {
4092 via_free(codec);
4093 return err;
4094 } else if (!err) {
4095 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4096 "from BIOS. Using genenic mode...\n");
4097 }
4098
Harald Welte69e52a82008-09-09 15:57:32 +08004099 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4100 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08004101
Lydia Wang36dd5c42009-10-20 13:18:04 +08004102 if (codec->vendor_id == 0x11060440)
4103 spec->stream_name_analog = "VT1818S Analog";
4104 else
4105 spec->stream_name_analog = "VT1708S Analog";
Harald Welted949cac2008-09-09 15:56:01 +08004106 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4107 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4108
Lydia Wang36dd5c42009-10-20 13:18:04 +08004109 if (codec->vendor_id == 0x11060440)
4110 spec->stream_name_digital = "VT1818S Digital";
4111 else
4112 spec->stream_name_digital = "VT1708S Digital";
Harald Welted949cac2008-09-09 15:56:01 +08004113 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4114
4115 if (!spec->adc_nids && spec->input_mux) {
4116 spec->adc_nids = vt1708S_adc_nids;
4117 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02004118 get_mux_nids(codec);
Lydia Wang6369bcf2009-10-10 19:08:31 +08004119 override_mic_boost(codec, 0x1a, 0, 3, 40);
4120 override_mic_boost(codec, 0x1e, 0, 3, 40);
Harald Welted949cac2008-09-09 15:56:01 +08004121 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4122 spec->num_mixers++;
4123 }
4124
4125 codec->patch_ops = via_patch_ops;
4126
4127 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08004128 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08004129#ifdef CONFIG_SND_HDA_POWER_SAVE
4130 spec->loopback.amplist = vt1708S_loopbacks;
4131#endif
4132
Lydia Wang518bf3b2009-10-10 19:07:29 +08004133 /* correct names for VT1708BCE */
4134 if (get_codec_type(codec) == VT1708BCE) {
4135 kfree(codec->chip_name);
4136 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4137 snprintf(codec->bus->card->mixername,
4138 sizeof(codec->bus->card->mixername),
4139 "%s %s", codec->vendor_name, codec->chip_name);
4140 spec->stream_name_analog = "VT1708BCE Analog";
4141 spec->stream_name_digital = "VT1708BCE Digital";
4142 }
Harald Welted949cac2008-09-09 15:56:01 +08004143 return 0;
4144}
4145
4146/* Patch for VT1702 */
4147
4148/* capture mixer elements */
4149static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4150 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4151 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4152 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4153 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4154 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4155 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4156 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4157 HDA_INPUT),
4158 {
4159 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4160 /* The multiple "Capture Source" controls confuse alsamixer
4161 * So call somewhat different..
4162 */
4163 /* .name = "Capture Source", */
4164 .name = "Input Source",
4165 .count = 1,
4166 .info = via_mux_enum_info,
4167 .get = via_mux_enum_get,
4168 .put = via_mux_enum_put,
4169 },
4170 { } /* end */
4171};
4172
4173static struct hda_verb vt1702_volume_init_verbs[] = {
4174 /*
4175 * Unmute ADC0-1 and set the default input to mic-in
4176 */
4177 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4178 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4179 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4180
4181
4182 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4183 * mixer widget
4184 */
4185 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4186 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4187 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4188 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4189 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4190 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4191
4192 /* Setup default input of PW4 to MW0 */
4193 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4194 /* PW6 PW7 Output enable */
4195 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4196 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08004197 /* mixer enable */
4198 {0x1, 0xF88, 0x3},
4199 /* GPIO 0~2 */
4200 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08004201 { }
4202};
4203
Harald Welte69e52a82008-09-09 15:57:32 +08004204static struct hda_verb vt1702_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08004205 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4206 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4207 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4208 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4209 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4210 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08004211 { }
4212};
4213
Harald Welted949cac2008-09-09 15:56:01 +08004214static struct hda_pcm_stream vt1702_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08004215 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08004216 .channels_min = 2,
4217 .channels_max = 2,
4218 .nid = 0x10, /* NID to query formats and rates */
4219 .ops = {
4220 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08004221 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08004222 .cleanup = via_playback_multi_pcm_cleanup,
4223 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08004224 },
4225};
4226
4227static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4228 .substreams = 3,
4229 .channels_min = 2,
4230 .channels_max = 2,
4231 .nid = 0x12, /* NID to query formats and rates */
4232 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08004233 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08004234 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08004235 .cleanup = via_capture_pcm_cleanup,
4236 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08004237 },
4238};
4239
4240static struct hda_pcm_stream vt1702_pcm_digital_playback = {
Harald Welte5691ec72008-09-15 22:42:26 +08004241 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08004242 .channels_min = 2,
4243 .channels_max = 2,
4244 /* NID is set in via_build_pcms */
4245 .ops = {
4246 .open = via_dig_playback_pcm_open,
4247 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02004248 .prepare = via_dig_playback_pcm_prepare,
4249 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08004250 },
4251};
4252
4253/* fill in the dac_nids table from the parsed pin configuration */
4254static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4255 const struct auto_pin_cfg *cfg)
4256{
4257 spec->multiout.num_dacs = 1;
4258 spec->multiout.dac_nids = spec->private_dac_nids;
4259
4260 if (cfg->line_out_pins[0]) {
4261 /* config dac list */
4262 spec->multiout.dac_nids[0] = 0x10;
4263 }
4264
4265 return 0;
4266}
4267
4268/* add playback controls from the parsed DAC table */
4269static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4270 const struct auto_pin_cfg *cfg)
4271{
4272 int err;
4273
4274 if (!cfg->line_out_pins[0])
4275 return -1;
4276
4277 /* add control to mixer index 0 */
4278 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4279 "Master Front Playback Volume",
4280 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4281 if (err < 0)
4282 return err;
4283 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4284 "Master Front Playback Switch",
4285 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4286 if (err < 0)
4287 return err;
4288
4289 /* Front */
4290 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4291 "Front Playback Volume",
4292 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4293 if (err < 0)
4294 return err;
4295 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4296 "Front Playback Switch",
4297 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4298 if (err < 0)
4299 return err;
4300
4301 return 0;
4302}
4303
4304static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4305{
Lydia Wang0713efe2009-10-10 19:07:43 +08004306 int err, i;
4307 struct hda_input_mux *imux;
4308 static const char *texts[] = { "ON", "OFF", NULL};
Harald Welted949cac2008-09-09 15:56:01 +08004309 if (!pin)
4310 return 0;
Harald Welted949cac2008-09-09 15:56:01 +08004311 spec->multiout.hp_nid = 0x1D;
Lydia Wangcdc17842009-10-10 19:07:47 +08004312 spec->hp_independent_mode_index = 0;
Harald Welted949cac2008-09-09 15:56:01 +08004313
4314 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4315 "Headphone Playback Volume",
4316 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4317 if (err < 0)
4318 return err;
4319
4320 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4321 "Headphone Playback Switch",
4322 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4323 if (err < 0)
4324 return err;
4325
Lydia Wang0713efe2009-10-10 19:07:43 +08004326 imux = &spec->private_imux[1];
Harald Welte0aa62ae2008-09-09 15:58:27 +08004327
Lydia Wang0713efe2009-10-10 19:07:43 +08004328 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004329 for (i = 0; texts[i]; i++)
4330 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Lydia Wang0713efe2009-10-10 19:07:43 +08004331
4332 spec->hp_mux = &spec->private_imux[1];
Harald Welted949cac2008-09-09 15:56:01 +08004333 return 0;
4334}
4335
4336/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004337static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08004338 const struct auto_pin_cfg *cfg)
4339{
Takashi Iwaif3268512010-08-30 11:00:19 +02004340 static hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
Takashi Iwai10a20af2010-09-09 16:28:02 +02004341 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02004342 ARRAY_SIZE(pin_idxs));
Harald Welted949cac2008-09-09 15:56:01 +08004343}
4344
4345static int vt1702_parse_auto_config(struct hda_codec *codec)
4346{
4347 struct via_spec *spec = codec->spec;
4348 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004349
Takashi Iwai9da29272009-05-07 16:31:14 +02004350 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08004351 if (err < 0)
4352 return err;
4353 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4354 if (err < 0)
4355 return err;
4356 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4357 return 0; /* can't find valid BIOS pin config */
4358
4359 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4360 if (err < 0)
4361 return err;
4362 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4363 if (err < 0)
4364 return err;
Lydia Wangc2c02ea2009-10-10 19:07:32 +08004365 /* limit AA path volume to 0 dB */
4366 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4367 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4368 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4369 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4370 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai10a20af2010-09-09 16:28:02 +02004371 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08004372 if (err < 0)
4373 return err;
4374
4375 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4376
Takashi Iwai9da29272009-05-07 16:31:14 +02004377 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08004378
Takashi Iwai603c4012008-07-30 15:01:44 +02004379 if (spec->kctls.list)
4380 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08004381
Harald Welte0aa62ae2008-09-09 15:58:27 +08004382 spec->input_mux = &spec->private_imux[0];
4383
Harald Weltef8fdd492008-09-15 22:41:31 +08004384 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004385 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004386
4387 return 1;
4388}
4389
4390#ifdef CONFIG_SND_HDA_POWER_SAVE
4391static struct hda_amp_list vt1702_loopbacks[] = {
4392 { 0x1A, HDA_INPUT, 1 },
4393 { 0x1A, HDA_INPUT, 2 },
4394 { 0x1A, HDA_INPUT, 3 },
4395 { 0x1A, HDA_INPUT, 4 },
4396 { } /* end */
4397};
4398#endif
4399
4400static int patch_vt1702(struct hda_codec *codec)
4401{
4402 struct via_spec *spec;
4403 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004404
4405 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004406 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004407 if (spec == NULL)
4408 return -ENOMEM;
4409
Harald Welted949cac2008-09-09 15:56:01 +08004410 /* automatic parse from the BIOS config */
4411 err = vt1702_parse_auto_config(codec);
4412 if (err < 0) {
4413 via_free(codec);
4414 return err;
4415 } else if (!err) {
4416 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4417 "from BIOS. Using genenic mode...\n");
4418 }
4419
Harald Welte69e52a82008-09-09 15:57:32 +08004420 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4421 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08004422
4423 spec->stream_name_analog = "VT1702 Analog";
4424 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4425 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4426
4427 spec->stream_name_digital = "VT1702 Digital";
4428 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4429
4430 if (!spec->adc_nids && spec->input_mux) {
4431 spec->adc_nids = vt1702_adc_nids;
4432 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02004433 get_mux_nids(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004434 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4435 spec->num_mixers++;
4436 }
4437
4438 codec->patch_ops = via_patch_ops;
4439
4440 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08004441 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08004442#ifdef CONFIG_SND_HDA_POWER_SAVE
4443 spec->loopback.amplist = vt1702_loopbacks;
4444#endif
4445
Harald Welted949cac2008-09-09 15:56:01 +08004446 return 0;
4447}
4448
Lydia Wangeb7188c2009-10-10 19:08:34 +08004449/* Patch for VT1718S */
4450
4451/* capture mixer elements */
4452static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4453 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4454 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4455 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4456 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4457 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4458 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4459 HDA_INPUT),
4460 {
4461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4462 /* The multiple "Capture Source" controls confuse alsamixer
4463 * So call somewhat different..
4464 */
4465 .name = "Input Source",
4466 .count = 2,
4467 .info = via_mux_enum_info,
4468 .get = via_mux_enum_get,
4469 .put = via_mux_enum_put,
4470 },
4471 { } /* end */
4472};
4473
4474static struct hda_verb vt1718S_volume_init_verbs[] = {
4475 /*
4476 * Unmute ADC0-1 and set the default input to mic-in
4477 */
4478 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4479 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4480
4481
4482 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4483 * mixer widget
4484 */
4485 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4486 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4487 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4488 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4489 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4490 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4491
4492 /* Setup default input of Front HP to MW9 */
4493 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4494 /* PW9 PW10 Output enable */
4495 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4496 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4497 /* PW11 Input enable */
4498 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4499 /* Enable Boost Volume backdoor */
4500 {0x1, 0xf88, 0x8},
4501 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4502 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4503 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4504 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4505 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4506 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4507 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4508 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4509 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4510 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4511 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4512 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4513 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4514 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4515 /* Unmute MW4's index 0 */
4516 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4517 { }
4518};
4519
4520
4521static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4522 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4523 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4524 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4525 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4526 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4527 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4528 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4529 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4530 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4531 { }
4532};
4533
4534static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4535 .substreams = 2,
4536 .channels_min = 2,
4537 .channels_max = 10,
4538 .nid = 0x8, /* NID to query formats and rates */
4539 .ops = {
4540 .open = via_playback_pcm_open,
4541 .prepare = via_playback_multi_pcm_prepare,
4542 .cleanup = via_playback_multi_pcm_cleanup,
4543 .close = via_pcm_open_close,
4544 },
4545};
4546
4547static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4548 .substreams = 2,
4549 .channels_min = 2,
4550 .channels_max = 2,
4551 .nid = 0x10, /* NID to query formats and rates */
4552 .ops = {
4553 .open = via_pcm_open_close,
4554 .prepare = via_capture_pcm_prepare,
4555 .cleanup = via_capture_pcm_cleanup,
4556 .close = via_pcm_open_close,
4557 },
4558};
4559
4560static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4561 .substreams = 2,
4562 .channels_min = 2,
4563 .channels_max = 2,
Lydia Wangeb7188c2009-10-10 19:08:34 +08004564 /* NID is set in via_build_pcms */
4565 .ops = {
4566 .open = via_dig_playback_pcm_open,
4567 .close = via_dig_playback_pcm_close,
4568 .prepare = via_dig_playback_pcm_prepare,
4569 .cleanup = via_dig_playback_pcm_cleanup
4570 },
4571};
4572
4573static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4574 .substreams = 1,
4575 .channels_min = 2,
4576 .channels_max = 2,
4577};
4578
4579/* fill in the dac_nids table from the parsed pin configuration */
4580static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4581 const struct auto_pin_cfg *cfg)
4582{
4583 int i;
4584 hda_nid_t nid;
4585
4586 spec->multiout.num_dacs = cfg->line_outs;
4587
4588 spec->multiout.dac_nids = spec->private_dac_nids;
4589
4590 for (i = 0; i < 4; i++) {
4591 nid = cfg->line_out_pins[i];
4592 if (nid) {
4593 /* config dac list */
4594 switch (i) {
4595 case AUTO_SEQ_FRONT:
4596 spec->multiout.dac_nids[i] = 0x8;
4597 break;
4598 case AUTO_SEQ_CENLFE:
4599 spec->multiout.dac_nids[i] = 0xa;
4600 break;
4601 case AUTO_SEQ_SURROUND:
4602 spec->multiout.dac_nids[i] = 0x9;
4603 break;
4604 case AUTO_SEQ_SIDE:
4605 spec->multiout.dac_nids[i] = 0xb;
4606 break;
4607 }
4608 }
4609 }
4610
4611 return 0;
4612}
4613
4614/* add playback controls from the parsed DAC table */
4615static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4616 const struct auto_pin_cfg *cfg)
4617{
4618 char name[32];
4619 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4620 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4621 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4622 hda_nid_t nid, nid_vol, nid_mute = 0;
4623 int i, err;
4624
4625 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4626 nid = cfg->line_out_pins[i];
4627
4628 if (!nid)
4629 continue;
4630 nid_vol = nid_vols[i];
4631 nid_mute = nid_mutes[i];
4632
4633 if (i == AUTO_SEQ_CENLFE) {
4634 /* Center/LFE */
4635 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4636 "Center Playback Volume",
4637 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4638 HDA_OUTPUT));
4639 if (err < 0)
4640 return err;
4641 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4642 "LFE Playback Volume",
4643 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4644 HDA_OUTPUT));
4645 if (err < 0)
4646 return err;
4647 err = via_add_control(
4648 spec, VIA_CTL_WIDGET_MUTE,
4649 "Center Playback Switch",
4650 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4651 HDA_OUTPUT));
4652 if (err < 0)
4653 return err;
4654 err = via_add_control(
4655 spec, VIA_CTL_WIDGET_MUTE,
4656 "LFE Playback Switch",
4657 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4658 HDA_OUTPUT));
4659 if (err < 0)
4660 return err;
4661 } else if (i == AUTO_SEQ_FRONT) {
4662 /* Front */
4663 sprintf(name, "%s Playback Volume", chname[i]);
4664 err = via_add_control(
4665 spec, VIA_CTL_WIDGET_VOL, name,
4666 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4667 if (err < 0)
4668 return err;
4669 sprintf(name, "%s Playback Switch", chname[i]);
4670 err = via_add_control(
4671 spec, VIA_CTL_WIDGET_MUTE, name,
4672 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4673 HDA_OUTPUT));
4674 if (err < 0)
4675 return err;
4676 } else {
4677 sprintf(name, "%s Playback Volume", chname[i]);
4678 err = via_add_control(
4679 spec, VIA_CTL_WIDGET_VOL, name,
4680 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4681 if (err < 0)
4682 return err;
4683 sprintf(name, "%s Playback Switch", chname[i]);
4684 err = via_add_control(
4685 spec, VIA_CTL_WIDGET_MUTE, name,
4686 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4687 HDA_OUTPUT));
4688 if (err < 0)
4689 return err;
4690 }
4691 }
4692 return 0;
4693}
4694
4695static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4696{
4697 int err;
4698
4699 if (!pin)
4700 return 0;
4701
4702 spec->multiout.hp_nid = 0xc; /* AOW4 */
4703 spec->hp_independent_mode_index = 1;
4704
4705 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4706 "Headphone Playback Volume",
4707 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4708 if (err < 0)
4709 return err;
4710
4711 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4712 "Headphone Playback Switch",
4713 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4714 if (err < 0)
4715 return err;
4716
4717 create_hp_imux(spec);
4718 return 0;
4719}
4720
4721/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004722static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangeb7188c2009-10-10 19:08:34 +08004723 const struct auto_pin_cfg *cfg)
4724{
Takashi Iwaif3268512010-08-30 11:00:19 +02004725 static hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
Takashi Iwai10a20af2010-09-09 16:28:02 +02004726 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02004727 ARRAY_SIZE(pin_idxs));
Lydia Wangeb7188c2009-10-10 19:08:34 +08004728}
4729
4730static int vt1718S_parse_auto_config(struct hda_codec *codec)
4731{
4732 struct via_spec *spec = codec->spec;
4733 int err;
4734
4735 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4736
4737 if (err < 0)
4738 return err;
4739 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4740 if (err < 0)
4741 return err;
4742 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4743 return 0; /* can't find valid BIOS pin config */
4744
4745 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4746 if (err < 0)
4747 return err;
4748 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4749 if (err < 0)
4750 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02004751 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004752 if (err < 0)
4753 return err;
4754
4755 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4756
4757 fill_dig_outs(codec);
4758
4759 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4760 spec->dig_in_nid = 0x13;
4761
4762 if (spec->kctls.list)
4763 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4764
4765 spec->input_mux = &spec->private_imux[0];
4766
4767 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004768 via_hp_build(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004769
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004770 via_smart51_build(spec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004771
4772 return 1;
4773}
4774
4775#ifdef CONFIG_SND_HDA_POWER_SAVE
4776static struct hda_amp_list vt1718S_loopbacks[] = {
4777 { 0x21, HDA_INPUT, 1 },
4778 { 0x21, HDA_INPUT, 2 },
4779 { 0x21, HDA_INPUT, 3 },
4780 { 0x21, HDA_INPUT, 4 },
4781 { } /* end */
4782};
4783#endif
4784
4785static int patch_vt1718S(struct hda_codec *codec)
4786{
4787 struct via_spec *spec;
4788 int err;
4789
4790 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004791 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004792 if (spec == NULL)
4793 return -ENOMEM;
4794
Lydia Wangeb7188c2009-10-10 19:08:34 +08004795 /* automatic parse from the BIOS config */
4796 err = vt1718S_parse_auto_config(codec);
4797 if (err < 0) {
4798 via_free(codec);
4799 return err;
4800 } else if (!err) {
4801 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4802 "from BIOS. Using genenic mode...\n");
4803 }
4804
4805 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4806 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4807
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004808 if (codec->vendor_id == 0x11060441)
4809 spec->stream_name_analog = "VT2020 Analog";
4810 else if (codec->vendor_id == 0x11064441)
4811 spec->stream_name_analog = "VT1828S Analog";
4812 else
4813 spec->stream_name_analog = "VT1718S Analog";
Lydia Wangeb7188c2009-10-10 19:08:34 +08004814 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4815 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4816
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004817 if (codec->vendor_id == 0x11060441)
4818 spec->stream_name_digital = "VT2020 Digital";
4819 else if (codec->vendor_id == 0x11064441)
4820 spec->stream_name_digital = "VT1828S Digital";
4821 else
4822 spec->stream_name_digital = "VT1718S Digital";
Lydia Wangeb7188c2009-10-10 19:08:34 +08004823 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004824 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
Lydia Wangeb7188c2009-10-10 19:08:34 +08004825 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4826
4827 if (!spec->adc_nids && spec->input_mux) {
4828 spec->adc_nids = vt1718S_adc_nids;
4829 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4830 get_mux_nids(codec);
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004831 override_mic_boost(codec, 0x2b, 0, 3, 40);
4832 override_mic_boost(codec, 0x29, 0, 3, 40);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004833 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4834 spec->num_mixers++;
4835 }
4836
4837 codec->patch_ops = via_patch_ops;
4838
4839 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11004840 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004841
4842#ifdef CONFIG_SND_HDA_POWER_SAVE
4843 spec->loopback.amplist = vt1718S_loopbacks;
4844#endif
4845
4846 return 0;
4847}
Lydia Wangf3db4232009-10-10 19:08:41 +08004848
4849/* Patch for VT1716S */
4850
4851static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4852 struct snd_ctl_elem_info *uinfo)
4853{
4854 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4855 uinfo->count = 1;
4856 uinfo->value.integer.min = 0;
4857 uinfo->value.integer.max = 1;
4858 return 0;
4859}
4860
4861static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4862 struct snd_ctl_elem_value *ucontrol)
4863{
4864 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4865 int index = 0;
4866
4867 index = snd_hda_codec_read(codec, 0x26, 0,
4868 AC_VERB_GET_CONNECT_SEL, 0);
4869 if (index != -1)
4870 *ucontrol->value.integer.value = index;
4871
4872 return 0;
4873}
4874
4875static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4876 struct snd_ctl_elem_value *ucontrol)
4877{
4878 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4879 struct via_spec *spec = codec->spec;
4880 int index = *ucontrol->value.integer.value;
4881
4882 snd_hda_codec_write(codec, 0x26, 0,
4883 AC_VERB_SET_CONNECT_SEL, index);
4884 spec->dmic_enabled = index;
4885 set_jack_power_state(codec);
4886
4887 return 1;
4888}
4889
4890/* capture mixer elements */
4891static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4892 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4893 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4894 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4895 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4896 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4897 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4898 HDA_INPUT),
4899 {
4900 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4901 .name = "Input Source",
4902 .count = 1,
4903 .info = via_mux_enum_info,
4904 .get = via_mux_enum_get,
4905 .put = via_mux_enum_put,
4906 },
4907 { } /* end */
4908};
4909
4910static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4911 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4912 {
4913 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4914 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004915 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08004916 .count = 1,
4917 .info = vt1716s_dmic_info,
4918 .get = vt1716s_dmic_get,
4919 .put = vt1716s_dmic_put,
4920 },
4921 {} /* end */
4922};
4923
4924
4925/* mono-out mixer elements */
4926static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4927 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4928 { } /* end */
4929};
4930
4931static struct hda_verb vt1716S_volume_init_verbs[] = {
4932 /*
4933 * Unmute ADC0-1 and set the default input to mic-in
4934 */
4935 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4936 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4937
4938
4939 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4940 * mixer widget
4941 */
4942 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4943 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4944 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4945 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4946 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4947 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4948
4949 /* MUX Indices: Stereo Mixer = 5 */
4950 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4951
4952 /* Setup default input of PW4 to MW0 */
4953 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4954
4955 /* Setup default input of SW1 as MW0 */
4956 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4957
4958 /* Setup default input of SW4 as AOW0 */
4959 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4960
4961 /* PW9 PW10 Output enable */
4962 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4963 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4964
4965 /* Unmute SW1, PW12 */
4966 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4967 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4968 /* PW12 Output enable */
4969 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4970 /* Enable Boost Volume backdoor */
4971 {0x1, 0xf8a, 0x80},
4972 /* don't bybass mixer */
4973 {0x1, 0xf88, 0xc0},
4974 /* Enable mono output */
4975 {0x1, 0xf90, 0x08},
4976 { }
4977};
4978
4979
4980static struct hda_verb vt1716S_uniwill_init_verbs[] = {
4981 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4982 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4983 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4984 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4985 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4986 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4987 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4988 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4989 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4990 { }
4991};
4992
4993static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
4994 .substreams = 2,
4995 .channels_min = 2,
4996 .channels_max = 6,
4997 .nid = 0x10, /* NID to query formats and rates */
4998 .ops = {
4999 .open = via_playback_pcm_open,
5000 .prepare = via_playback_multi_pcm_prepare,
5001 .cleanup = via_playback_multi_pcm_cleanup,
5002 .close = via_pcm_open_close,
5003 },
5004};
5005
5006static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5007 .substreams = 2,
5008 .channels_min = 2,
5009 .channels_max = 2,
5010 .nid = 0x13, /* NID to query formats and rates */
5011 .ops = {
5012 .open = via_pcm_open_close,
5013 .prepare = via_capture_pcm_prepare,
5014 .cleanup = via_capture_pcm_cleanup,
5015 .close = via_pcm_open_close,
5016 },
5017};
5018
5019static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5020 .substreams = 2,
5021 .channels_min = 2,
5022 .channels_max = 2,
Lydia Wangf3db4232009-10-10 19:08:41 +08005023 /* NID is set in via_build_pcms */
5024 .ops = {
5025 .open = via_dig_playback_pcm_open,
5026 .close = via_dig_playback_pcm_close,
5027 .prepare = via_dig_playback_pcm_prepare,
5028 .cleanup = via_dig_playback_pcm_cleanup
5029 },
5030};
5031
5032/* fill in the dac_nids table from the parsed pin configuration */
5033static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5034 const struct auto_pin_cfg *cfg)
5035{ int i;
5036 hda_nid_t nid;
5037
5038 spec->multiout.num_dacs = cfg->line_outs;
5039
5040 spec->multiout.dac_nids = spec->private_dac_nids;
5041
5042 for (i = 0; i < 3; i++) {
5043 nid = cfg->line_out_pins[i];
5044 if (nid) {
5045 /* config dac list */
5046 switch (i) {
5047 case AUTO_SEQ_FRONT:
5048 spec->multiout.dac_nids[i] = 0x10;
5049 break;
5050 case AUTO_SEQ_CENLFE:
5051 spec->multiout.dac_nids[i] = 0x25;
5052 break;
5053 case AUTO_SEQ_SURROUND:
5054 spec->multiout.dac_nids[i] = 0x11;
5055 break;
5056 }
5057 }
5058 }
5059
5060 return 0;
5061}
5062
5063/* add playback controls from the parsed DAC table */
5064static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5065 const struct auto_pin_cfg *cfg)
5066{
5067 char name[32];
5068 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5069 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5070 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5071 hda_nid_t nid, nid_vol, nid_mute;
5072 int i, err;
5073
5074 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5075 nid = cfg->line_out_pins[i];
5076
5077 if (!nid)
5078 continue;
5079
5080 nid_vol = nid_vols[i];
5081 nid_mute = nid_mutes[i];
5082
5083 if (i == AUTO_SEQ_CENLFE) {
5084 err = via_add_control(
5085 spec, VIA_CTL_WIDGET_VOL,
5086 "Center Playback Volume",
5087 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5088 if (err < 0)
5089 return err;
5090 err = via_add_control(
5091 spec, VIA_CTL_WIDGET_VOL,
5092 "LFE Playback Volume",
5093 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5094 if (err < 0)
5095 return err;
5096 err = via_add_control(
5097 spec, VIA_CTL_WIDGET_MUTE,
5098 "Center Playback Switch",
5099 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5100 HDA_OUTPUT));
5101 if (err < 0)
5102 return err;
5103 err = via_add_control(
5104 spec, VIA_CTL_WIDGET_MUTE,
5105 "LFE Playback Switch",
5106 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5107 HDA_OUTPUT));
5108 if (err < 0)
5109 return err;
5110 } else if (i == AUTO_SEQ_FRONT) {
5111
5112 err = via_add_control(
5113 spec, VIA_CTL_WIDGET_VOL,
5114 "Master Front Playback Volume",
5115 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5116 if (err < 0)
5117 return err;
5118 err = via_add_control(
5119 spec, VIA_CTL_WIDGET_MUTE,
5120 "Master Front Playback Switch",
5121 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5122 if (err < 0)
5123 return err;
5124
5125 sprintf(name, "%s Playback Volume", chname[i]);
5126 err = via_add_control(
5127 spec, VIA_CTL_WIDGET_VOL, name,
5128 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5129 if (err < 0)
5130 return err;
5131 sprintf(name, "%s Playback Switch", chname[i]);
5132 err = via_add_control(
5133 spec, VIA_CTL_WIDGET_MUTE, name,
5134 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5135 HDA_OUTPUT));
5136 if (err < 0)
5137 return err;
5138 } else {
5139 sprintf(name, "%s Playback Volume", chname[i]);
5140 err = via_add_control(
5141 spec, VIA_CTL_WIDGET_VOL, name,
5142 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5143 if (err < 0)
5144 return err;
5145 sprintf(name, "%s Playback Switch", chname[i]);
5146 err = via_add_control(
5147 spec, VIA_CTL_WIDGET_MUTE, name,
5148 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5149 HDA_OUTPUT));
5150 if (err < 0)
5151 return err;
5152 }
5153 }
5154 return 0;
5155}
5156
5157static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5158{
5159 int err;
5160
5161 if (!pin)
5162 return 0;
5163
5164 spec->multiout.hp_nid = 0x25; /* AOW3 */
5165 spec->hp_independent_mode_index = 1;
5166
5167 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5168 "Headphone Playback Volume",
5169 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5170 if (err < 0)
5171 return err;
5172
5173 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5174 "Headphone Playback Switch",
5175 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5176 if (err < 0)
5177 return err;
5178
5179 create_hp_imux(spec);
5180 return 0;
5181}
5182
5183/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005184static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangf3db4232009-10-10 19:08:41 +08005185 const struct auto_pin_cfg *cfg)
5186{
Takashi Iwaif3268512010-08-30 11:00:19 +02005187 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
Takashi Iwai10a20af2010-09-09 16:28:02 +02005188 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02005189 ARRAY_SIZE(pin_idxs));
Lydia Wangf3db4232009-10-10 19:08:41 +08005190}
5191
5192static int vt1716S_parse_auto_config(struct hda_codec *codec)
5193{
5194 struct via_spec *spec = codec->spec;
5195 int err;
5196
5197 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5198 if (err < 0)
5199 return err;
5200 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5201 if (err < 0)
5202 return err;
5203 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5204 return 0; /* can't find valid BIOS pin config */
5205
5206 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5207 if (err < 0)
5208 return err;
5209 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5210 if (err < 0)
5211 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005212 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangf3db4232009-10-10 19:08:41 +08005213 if (err < 0)
5214 return err;
5215
5216 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5217
5218 fill_dig_outs(codec);
5219
5220 if (spec->kctls.list)
5221 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5222
5223 spec->input_mux = &spec->private_imux[0];
5224
5225 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005226 via_hp_build(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005227
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005228 via_smart51_build(spec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005229
5230 return 1;
5231}
5232
5233#ifdef CONFIG_SND_HDA_POWER_SAVE
5234static struct hda_amp_list vt1716S_loopbacks[] = {
5235 { 0x16, HDA_INPUT, 1 },
5236 { 0x16, HDA_INPUT, 2 },
5237 { 0x16, HDA_INPUT, 3 },
5238 { 0x16, HDA_INPUT, 4 },
5239 { } /* end */
5240};
5241#endif
5242
5243static int patch_vt1716S(struct hda_codec *codec)
5244{
5245 struct via_spec *spec;
5246 int err;
5247
5248 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005249 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005250 if (spec == NULL)
5251 return -ENOMEM;
5252
Lydia Wangf3db4232009-10-10 19:08:41 +08005253 /* automatic parse from the BIOS config */
5254 err = vt1716S_parse_auto_config(codec);
5255 if (err < 0) {
5256 via_free(codec);
5257 return err;
5258 } else if (!err) {
5259 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5260 "from BIOS. Using genenic mode...\n");
5261 }
5262
5263 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5264 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5265
5266 spec->stream_name_analog = "VT1716S Analog";
5267 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5268 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5269
5270 spec->stream_name_digital = "VT1716S Digital";
5271 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5272
5273 if (!spec->adc_nids && spec->input_mux) {
5274 spec->adc_nids = vt1716S_adc_nids;
5275 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5276 get_mux_nids(codec);
5277 override_mic_boost(codec, 0x1a, 0, 3, 40);
5278 override_mic_boost(codec, 0x1e, 0, 3, 40);
5279 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5280 spec->num_mixers++;
5281 }
5282
5283 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5284 spec->num_mixers++;
5285
5286 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5287
5288 codec->patch_ops = via_patch_ops;
5289
5290 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005291 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangf3db4232009-10-10 19:08:41 +08005292
5293#ifdef CONFIG_SND_HDA_POWER_SAVE
5294 spec->loopback.amplist = vt1716S_loopbacks;
5295#endif
5296
5297 return 0;
5298}
Lydia Wang25eaba22009-10-10 19:08:43 +08005299
5300/* for vt2002P */
5301
5302/* capture mixer elements */
5303static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5304 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5305 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5306 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5307 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5308 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5309 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5310 HDA_INPUT),
5311 {
5312 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5313 /* The multiple "Capture Source" controls confuse alsamixer
5314 * So call somewhat different..
5315 */
5316 /* .name = "Capture Source", */
5317 .name = "Input Source",
5318 .count = 2,
5319 .info = via_mux_enum_info,
5320 .get = via_mux_enum_get,
5321 .put = via_mux_enum_put,
5322 },
5323 { } /* end */
5324};
5325
5326static struct hda_verb vt2002P_volume_init_verbs[] = {
5327 /*
5328 * Unmute ADC0-1 and set the default input to mic-in
5329 */
5330 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5331 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5332
5333
5334 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5335 * mixer widget
5336 */
5337 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5338 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5339 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5340 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5341 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5342 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5343
5344 /* MUX Indices: Mic = 0 */
5345 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5346 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5347
5348 /* PW9 Output enable */
5349 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5350
5351 /* Enable Boost Volume backdoor */
5352 {0x1, 0xfb9, 0x24},
5353
5354 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5355 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5356 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5357 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5358 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5359 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5360 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5361 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5362 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5363
5364 /* set MUX0/1/4/8 = 0 (AOW0) */
5365 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5366 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5367 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5368 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5369
5370 /* set PW0 index=0 (MW0) */
5371 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5372
5373 /* Enable AOW0 to MW9 */
5374 {0x1, 0xfb8, 0x88},
5375 { }
5376};
5377
5378
5379static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5380 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5381 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5382 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5383 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5384 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5385 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5386 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5387 { }
5388};
5389
5390static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5391 .substreams = 2,
5392 .channels_min = 2,
5393 .channels_max = 2,
5394 .nid = 0x8, /* NID to query formats and rates */
5395 .ops = {
5396 .open = via_playback_pcm_open,
5397 .prepare = via_playback_multi_pcm_prepare,
5398 .cleanup = via_playback_multi_pcm_cleanup,
5399 .close = via_pcm_open_close,
5400 },
5401};
5402
5403static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5404 .substreams = 2,
5405 .channels_min = 2,
5406 .channels_max = 2,
5407 .nid = 0x10, /* NID to query formats and rates */
5408 .ops = {
5409 .open = via_pcm_open_close,
5410 .prepare = via_capture_pcm_prepare,
5411 .cleanup = via_capture_pcm_cleanup,
5412 .close = via_pcm_open_close,
5413 },
5414};
5415
5416static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5417 .substreams = 1,
5418 .channels_min = 2,
5419 .channels_max = 2,
Lydia Wang25eaba22009-10-10 19:08:43 +08005420 /* NID is set in via_build_pcms */
5421 .ops = {
5422 .open = via_dig_playback_pcm_open,
5423 .close = via_dig_playback_pcm_close,
5424 .prepare = via_dig_playback_pcm_prepare,
5425 .cleanup = via_dig_playback_pcm_cleanup
5426 },
5427};
5428
5429/* fill in the dac_nids table from the parsed pin configuration */
5430static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5431 const struct auto_pin_cfg *cfg)
5432{
5433 spec->multiout.num_dacs = 1;
5434 spec->multiout.dac_nids = spec->private_dac_nids;
5435 if (cfg->line_out_pins[0])
5436 spec->multiout.dac_nids[0] = 0x8;
5437 return 0;
5438}
5439
5440/* add playback controls from the parsed DAC table */
5441static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5442 const struct auto_pin_cfg *cfg)
5443{
5444 int err;
5445
5446 if (!cfg->line_out_pins[0])
5447 return -1;
5448
5449
5450 /* Line-Out: PortE */
5451 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5452 "Master Front Playback Volume",
5453 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5454 if (err < 0)
5455 return err;
5456 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5457 "Master Front Playback Switch",
5458 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5459 if (err < 0)
5460 return err;
5461
5462 return 0;
5463}
5464
5465static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5466{
5467 int err;
5468
5469 if (!pin)
5470 return 0;
5471
5472 spec->multiout.hp_nid = 0x9;
5473 spec->hp_independent_mode_index = 1;
5474
5475 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5476 "Headphone Playback Volume",
5477 HDA_COMPOSE_AMP_VAL(
5478 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5479 if (err < 0)
5480 return err;
5481
5482 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5483 "Headphone Playback Switch",
5484 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5485 if (err < 0)
5486 return err;
5487
5488 create_hp_imux(spec);
5489 return 0;
5490}
5491
5492/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005493static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wang25eaba22009-10-10 19:08:43 +08005494 const struct auto_pin_cfg *cfg)
5495{
Takashi Iwai10a20af2010-09-09 16:28:02 +02005496 struct via_spec *spec = codec->spec;
Lydia Wang25eaba22009-10-10 19:08:43 +08005497 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaif3268512010-08-30 11:00:19 +02005498 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5499 int err;
Lydia Wang25eaba22009-10-10 19:08:43 +08005500
Takashi Iwai10a20af2010-09-09 16:28:02 +02005501 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02005502 ARRAY_SIZE(pin_idxs));
5503 if (err < 0)
5504 return err;
Lydia Wang25eaba22009-10-10 19:08:43 +08005505 /* build volume/mute control of loopback */
Takashi Iwai7b315bb2010-08-30 13:06:30 +02005506 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
Lydia Wang25eaba22009-10-10 19:08:43 +08005507 if (err < 0)
5508 return err;
5509
Lydia Wang25eaba22009-10-10 19:08:43 +08005510 /* for digital mic select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005511 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
Lydia Wang25eaba22009-10-10 19:08:43 +08005512
5513 return 0;
5514}
5515
5516static int vt2002P_parse_auto_config(struct hda_codec *codec)
5517{
5518 struct via_spec *spec = codec->spec;
5519 int err;
5520
5521
5522 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5523 if (err < 0)
5524 return err;
5525
5526 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5527 if (err < 0)
5528 return err;
5529
5530 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5531 return 0; /* can't find valid BIOS pin config */
5532
5533 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5534 if (err < 0)
5535 return err;
5536 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5537 if (err < 0)
5538 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005539 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wang25eaba22009-10-10 19:08:43 +08005540 if (err < 0)
5541 return err;
5542
5543 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5544
5545 fill_dig_outs(codec);
5546
5547 if (spec->kctls.list)
5548 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5549
5550 spec->input_mux = &spec->private_imux[0];
5551
5552 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005553 via_hp_build(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08005554
5555 return 1;
5556}
5557
5558#ifdef CONFIG_SND_HDA_POWER_SAVE
5559static struct hda_amp_list vt2002P_loopbacks[] = {
5560 { 0x21, HDA_INPUT, 0 },
5561 { 0x21, HDA_INPUT, 1 },
5562 { 0x21, HDA_INPUT, 2 },
5563 { } /* end */
5564};
5565#endif
5566
5567
5568/* patch for vt2002P */
5569static int patch_vt2002P(struct hda_codec *codec)
5570{
5571 struct via_spec *spec;
5572 int err;
5573
5574 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005575 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08005576 if (spec == NULL)
5577 return -ENOMEM;
5578
Lydia Wang25eaba22009-10-10 19:08:43 +08005579 /* automatic parse from the BIOS config */
5580 err = vt2002P_parse_auto_config(codec);
5581 if (err < 0) {
5582 via_free(codec);
5583 return err;
5584 } else if (!err) {
5585 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5586 "from BIOS. Using genenic mode...\n");
5587 }
5588
5589 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5590 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5591
5592 spec->stream_name_analog = "VT2002P Analog";
5593 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5594 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5595
5596 spec->stream_name_digital = "VT2002P Digital";
5597 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5598
5599 if (!spec->adc_nids && spec->input_mux) {
5600 spec->adc_nids = vt2002P_adc_nids;
5601 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5602 get_mux_nids(codec);
5603 override_mic_boost(codec, 0x2b, 0, 3, 40);
5604 override_mic_boost(codec, 0x29, 0, 3, 40);
5605 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5606 spec->num_mixers++;
5607 }
5608
5609 codec->patch_ops = via_patch_ops;
5610
5611 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005612 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wang25eaba22009-10-10 19:08:43 +08005613
5614#ifdef CONFIG_SND_HDA_POWER_SAVE
5615 spec->loopback.amplist = vt2002P_loopbacks;
5616#endif
5617
5618 return 0;
5619}
Lydia Wangab6734e2009-10-10 19:08:46 +08005620
5621/* for vt1812 */
5622
5623/* capture mixer elements */
5624static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5625 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5626 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5627 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5628 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5629 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5630 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5631 HDA_INPUT),
5632 {
5633 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5634 /* The multiple "Capture Source" controls confuse alsamixer
5635 * So call somewhat different..
5636 */
5637 .name = "Input Source",
5638 .count = 2,
5639 .info = via_mux_enum_info,
5640 .get = via_mux_enum_get,
5641 .put = via_mux_enum_put,
5642 },
5643 { } /* end */
5644};
5645
5646static struct hda_verb vt1812_volume_init_verbs[] = {
5647 /*
5648 * Unmute ADC0-1 and set the default input to mic-in
5649 */
5650 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5651 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5652
5653
5654 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5655 * mixer widget
5656 */
5657 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5658 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5659 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5660 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5661 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5662 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5663
5664 /* MUX Indices: Mic = 0 */
5665 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5666 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5667
5668 /* PW9 Output enable */
5669 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5670
5671 /* Enable Boost Volume backdoor */
5672 {0x1, 0xfb9, 0x24},
5673
5674 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5675 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5676 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5677 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5678 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5679 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5680 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5681 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5682 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5683 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5684 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5685
5686 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5687 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5688 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5689 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5690 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5691 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5692
5693 /* Enable AOW0 to MW9 */
5694 {0x1, 0xfb8, 0xa8},
5695 { }
5696};
5697
5698
5699static struct hda_verb vt1812_uniwill_init_verbs[] = {
5700 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5701 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5702 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5703 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5704 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5705 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5706 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5707 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5708 { }
5709};
5710
5711static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5712 .substreams = 2,
5713 .channels_min = 2,
5714 .channels_max = 2,
5715 .nid = 0x8, /* NID to query formats and rates */
5716 .ops = {
5717 .open = via_playback_pcm_open,
5718 .prepare = via_playback_multi_pcm_prepare,
5719 .cleanup = via_playback_multi_pcm_cleanup,
5720 .close = via_pcm_open_close,
5721 },
5722};
5723
5724static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5725 .substreams = 2,
5726 .channels_min = 2,
5727 .channels_max = 2,
5728 .nid = 0x10, /* NID to query formats and rates */
5729 .ops = {
5730 .open = via_pcm_open_close,
5731 .prepare = via_capture_pcm_prepare,
5732 .cleanup = via_capture_pcm_cleanup,
5733 .close = via_pcm_open_close,
5734 },
5735};
5736
5737static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5738 .substreams = 1,
5739 .channels_min = 2,
5740 .channels_max = 2,
Lydia Wangab6734e2009-10-10 19:08:46 +08005741 /* NID is set in via_build_pcms */
5742 .ops = {
5743 .open = via_dig_playback_pcm_open,
5744 .close = via_dig_playback_pcm_close,
5745 .prepare = via_dig_playback_pcm_prepare,
5746 .cleanup = via_dig_playback_pcm_cleanup
5747 },
5748};
5749/* fill in the dac_nids table from the parsed pin configuration */
5750static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5751 const struct auto_pin_cfg *cfg)
5752{
5753 spec->multiout.num_dacs = 1;
5754 spec->multiout.dac_nids = spec->private_dac_nids;
5755 if (cfg->line_out_pins[0])
5756 spec->multiout.dac_nids[0] = 0x8;
5757 return 0;
5758}
5759
5760
5761/* add playback controls from the parsed DAC table */
5762static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5763 const struct auto_pin_cfg *cfg)
5764{
5765 int err;
5766
5767 if (!cfg->line_out_pins[0])
5768 return -1;
5769
5770 /* Line-Out: PortE */
5771 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Takashi Iwai3d83e572010-04-14 14:36:23 +02005772 "Front Playback Volume",
Lydia Wangab6734e2009-10-10 19:08:46 +08005773 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5774 if (err < 0)
5775 return err;
5776 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
Takashi Iwai3d83e572010-04-14 14:36:23 +02005777 "Front Playback Switch",
Lydia Wangab6734e2009-10-10 19:08:46 +08005778 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5779 if (err < 0)
5780 return err;
5781
5782 return 0;
5783}
5784
5785static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5786{
5787 int err;
5788
5789 if (!pin)
5790 return 0;
5791
5792 spec->multiout.hp_nid = 0x9;
5793 spec->hp_independent_mode_index = 1;
5794
5795
5796 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5797 "Headphone Playback Volume",
5798 HDA_COMPOSE_AMP_VAL(
5799 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5800 if (err < 0)
5801 return err;
5802
5803 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5804 "Headphone Playback Switch",
5805 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5806 if (err < 0)
5807 return err;
5808
5809 create_hp_imux(spec);
5810 return 0;
5811}
5812
5813/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005814static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangab6734e2009-10-10 19:08:46 +08005815 const struct auto_pin_cfg *cfg)
5816{
Takashi Iwai10a20af2010-09-09 16:28:02 +02005817 struct via_spec *spec = codec->spec;
Lydia Wangab6734e2009-10-10 19:08:46 +08005818 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaif3268512010-08-30 11:00:19 +02005819 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5820 int err;
Lydia Wangab6734e2009-10-10 19:08:46 +08005821
Takashi Iwai10a20af2010-09-09 16:28:02 +02005822 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02005823 ARRAY_SIZE(pin_idxs));
5824 if (err < 0)
5825 return err;
Lydia Wangab6734e2009-10-10 19:08:46 +08005826
Lydia Wangab6734e2009-10-10 19:08:46 +08005827 /* build volume/mute control of loopback */
Takashi Iwai7b315bb2010-08-30 13:06:30 +02005828 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
Lydia Wangab6734e2009-10-10 19:08:46 +08005829 if (err < 0)
5830 return err;
5831
Lydia Wangab6734e2009-10-10 19:08:46 +08005832 /* for digital mic select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005833 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
Lydia Wangab6734e2009-10-10 19:08:46 +08005834
5835 return 0;
5836}
5837
5838static int vt1812_parse_auto_config(struct hda_codec *codec)
5839{
5840 struct via_spec *spec = codec->spec;
5841 int err;
5842
5843
5844 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5845 if (err < 0)
5846 return err;
5847 fill_dig_outs(codec);
5848 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5849 if (err < 0)
5850 return err;
5851
5852 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5853 return 0; /* can't find valid BIOS pin config */
5854
5855 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5856 if (err < 0)
5857 return err;
5858 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5859 if (err < 0)
5860 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005861 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangab6734e2009-10-10 19:08:46 +08005862 if (err < 0)
5863 return err;
5864
5865 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5866
5867 fill_dig_outs(codec);
5868
5869 if (spec->kctls.list)
5870 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5871
5872 spec->input_mux = &spec->private_imux[0];
5873
5874 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005875 via_hp_build(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08005876
5877 return 1;
5878}
5879
5880#ifdef CONFIG_SND_HDA_POWER_SAVE
5881static struct hda_amp_list vt1812_loopbacks[] = {
5882 { 0x21, HDA_INPUT, 0 },
5883 { 0x21, HDA_INPUT, 1 },
5884 { 0x21, HDA_INPUT, 2 },
5885 { } /* end */
5886};
5887#endif
5888
5889
5890/* patch for vt1812 */
5891static int patch_vt1812(struct hda_codec *codec)
5892{
5893 struct via_spec *spec;
5894 int err;
5895
5896 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005897 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08005898 if (spec == NULL)
5899 return -ENOMEM;
5900
Lydia Wangab6734e2009-10-10 19:08:46 +08005901 /* automatic parse from the BIOS config */
5902 err = vt1812_parse_auto_config(codec);
5903 if (err < 0) {
5904 via_free(codec);
5905 return err;
5906 } else if (!err) {
5907 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5908 "from BIOS. Using genenic mode...\n");
5909 }
5910
5911
5912 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
5913 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
5914
5915 spec->stream_name_analog = "VT1812 Analog";
5916 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
5917 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
5918
5919 spec->stream_name_digital = "VT1812 Digital";
5920 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
5921
5922
5923 if (!spec->adc_nids && spec->input_mux) {
5924 spec->adc_nids = vt1812_adc_nids;
5925 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
5926 get_mux_nids(codec);
5927 override_mic_boost(codec, 0x2b, 0, 3, 40);
5928 override_mic_boost(codec, 0x29, 0, 3, 40);
5929 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
5930 spec->num_mixers++;
5931 }
5932
5933 codec->patch_ops = via_patch_ops;
5934
5935 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005936 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangab6734e2009-10-10 19:08:46 +08005937
5938#ifdef CONFIG_SND_HDA_POWER_SAVE
5939 spec->loopback.amplist = vt1812_loopbacks;
5940#endif
5941
5942 return 0;
5943}
5944
Joseph Chanc577b8a2006-11-29 15:29:40 +01005945/*
5946 * patch entries
5947 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005948static struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01005949 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
5950 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
5951 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
5952 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
5953 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005954 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005955 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005956 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005957 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005958 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005959 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005960 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005961 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005962 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005963 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005964 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005965 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005966 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005967 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005968 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005969 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005970 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005971 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005972 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005973 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005974 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005975 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005976 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005977 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005978 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005979 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005980 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005981 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005982 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005983 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005984 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005985 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005986 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005987 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005988 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005989 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005990 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005991 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005992 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005993 { .id = 0x11064397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005994 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005995 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005996 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005997 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005998 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005999 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006000 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006001 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006002 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006003 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006004 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006005 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006006 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006007 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006008 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006009 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006010 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006011 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006012 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006013 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006014 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006015 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006016 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08006017 { .id = 0x11060428, .name = "VT1718S",
6018 .patch = patch_vt1718S},
6019 { .id = 0x11064428, .name = "VT1718S",
6020 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08006021 { .id = 0x11060441, .name = "VT2020",
6022 .patch = patch_vt1718S},
6023 { .id = 0x11064441, .name = "VT1828S",
6024 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08006025 { .id = 0x11060433, .name = "VT1716S",
6026 .patch = patch_vt1716S},
6027 { .id = 0x1106a721, .name = "VT1716S",
6028 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08006029 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6030 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08006031 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08006032 { .id = 0x11060440, .name = "VT1818S",
6033 .patch = patch_vt1708S},
Joseph Chanc577b8a2006-11-29 15:29:40 +01006034 {} /* terminator */
6035};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006036
6037MODULE_ALIAS("snd-hda-codec-id:1106*");
6038
6039static struct hda_codec_preset_list via_list = {
6040 .preset = snd_hda_preset_via,
6041 .owner = THIS_MODULE,
6042};
6043
6044MODULE_LICENSE("GPL");
6045MODULE_DESCRIPTION("VIA HD-audio codec");
6046
6047static int __init patch_via_init(void)
6048{
6049 return snd_hda_add_codec_preset(&via_list);
6050}
6051
6052static void __exit patch_via_exit(void)
6053{
6054 snd_hda_delete_codec_preset(&via_list);
6055}
6056
6057module_init(patch_via_init)
6058module_exit(patch_via_exit)