blob: 995974d0b120ddd84d1d665ee23ebe3d75756347 [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,
Lydia Wang118909562011-03-23 17:57:34 +0800101 VT1802,
Harald Welted7426322008-09-15 22:43:23 +0800102 CODEC_TYPES,
103};
104
Lydia Wang118909562011-03-23 17:57:34 +0800105#define VT2002P_COMPATIBLE(spec) \
106 ((spec)->codec_type == VT2002P ||\
107 (spec)->codec_type == VT1812 ||\
108 (spec)->codec_type == VT1802)
109
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800110struct via_spec {
111 /* codec parameterization */
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200112 const struct snd_kcontrol_new *mixers[6];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800113 unsigned int num_mixers;
114
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200115 const struct hda_verb *init_verbs[5];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800116 unsigned int num_iverbs;
117
118 char *stream_name_analog;
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200119 const struct hda_pcm_stream *stream_analog_playback;
120 const struct hda_pcm_stream *stream_analog_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800121
122 char *stream_name_digital;
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200123 const struct hda_pcm_stream *stream_digital_playback;
124 const struct hda_pcm_stream *stream_digital_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800125
126 /* playback */
127 struct hda_multi_out multiout;
128 hda_nid_t slave_dig_outs[2];
129
130 /* capture */
131 unsigned int num_adc_nids;
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200132 const hda_nid_t *adc_nids;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800133 hda_nid_t mux_nids[3];
134 hda_nid_t dig_in_nid;
135 hda_nid_t dig_in_pin;
136
137 /* capture source */
138 const struct hda_input_mux *input_mux;
139 unsigned int cur_mux[3];
140
141 /* PCM information */
142 struct hda_pcm pcm_rec[3];
143
144 /* dynamic controls, init_verbs and input_mux */
145 struct auto_pin_cfg autocfg;
146 struct snd_array kctls;
147 struct hda_input_mux private_imux[2];
148 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
149
150 /* HP mode source */
151 const struct hda_input_mux *hp_mux;
152 unsigned int hp_independent_mode;
153 unsigned int hp_independent_mode_index;
154 unsigned int smart51_enabled;
Lydia Wangf3db4232009-10-10 19:08:41 +0800155 unsigned int dmic_enabled;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800156 enum VIA_HDA_CODEC codec_type;
157
158 /* work to check hp jack state */
159 struct hda_codec *codec;
160 struct delayed_work vt1708_hp_work;
161 int vt1708_jack_detectect;
162 int vt1708_hp_present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800163
164 void (*set_widgets_power_state)(struct hda_codec *codec);
165
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800166#ifdef CONFIG_SND_HDA_POWER_SAVE
167 struct hda_loopback_check loopback;
168#endif
169};
170
Lydia Wang0341ccd2011-03-22 16:25:03 +0800171static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100172static struct via_spec * via_new_spec(struct hda_codec *codec)
173{
174 struct via_spec *spec;
175
176 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
177 if (spec == NULL)
178 return NULL;
179
180 codec->spec = spec;
181 spec->codec = codec;
Lydia Wang0341ccd2011-03-22 16:25:03 +0800182 spec->codec_type = get_codec_type(codec);
183 /* VT1708BCE & VT1708S are almost same */
184 if (spec->codec_type == VT1708BCE)
185 spec->codec_type = VT1708S;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100186 return spec;
187}
188
Lydia Wang744ff5f2009-10-10 19:07:26 +0800189static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800190{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800191 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800192 u16 ven_id = vendor_id >> 16;
193 u16 dev_id = vendor_id & 0xffff;
194 enum VIA_HDA_CODEC codec_type;
195
196 /* get codec type */
197 if (ven_id != 0x1106)
198 codec_type = UNKNOWN;
199 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
200 codec_type = VT1708;
201 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
202 codec_type = VT1709_10CH;
203 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
204 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800205 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800206 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800207 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
208 codec_type = VT1708BCE;
209 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800210 codec_type = VT1708B_4CH;
211 else if ((dev_id & 0xfff) == 0x397
212 && (dev_id >> 12) < 8)
213 codec_type = VT1708S;
214 else if ((dev_id & 0xfff) == 0x398
215 && (dev_id >> 12) < 8)
216 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800217 else if ((dev_id & 0xfff) == 0x428
218 && (dev_id >> 12) < 8)
219 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800220 else if (dev_id == 0x0433 || dev_id == 0xa721)
221 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800222 else if (dev_id == 0x0441 || dev_id == 0x4441)
223 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800224 else if (dev_id == 0x0438 || dev_id == 0x4438)
225 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800226 else if (dev_id == 0x0448)
227 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800228 else if (dev_id == 0x0440)
229 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800230 else if ((dev_id & 0xfff) == 0x446)
231 codec_type = VT1802;
Harald Welted7426322008-09-15 22:43:23 +0800232 else
233 codec_type = UNKNOWN;
234 return codec_type;
235};
236
Lydia Wangec7e7e42011-03-24 12:43:44 +0800237#define VIA_JACK_EVENT 0x20
Harald Welte69e52a82008-09-09 15:57:32 +0800238#define VIA_HP_EVENT 0x01
239#define VIA_GPIO_EVENT 0x02
Lydia Wangec7e7e42011-03-24 12:43:44 +0800240#define VIA_MONO_EVENT 0x03
241#define VIA_SPEAKER_EVENT 0x04
242#define VIA_BIND_HP_EVENT 0x05
Harald Welte69e52a82008-09-09 15:57:32 +0800243
Joseph Chanc577b8a2006-11-29 15:29:40 +0100244enum {
245 VIA_CTL_WIDGET_VOL,
246 VIA_CTL_WIDGET_MUTE,
Lydia Wangf5271102009-10-10 19:07:35 +0800247 VIA_CTL_WIDGET_ANALOG_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800248 VIA_CTL_WIDGET_BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100249};
250
251enum {
Harald Welteeb14a462008-09-09 15:40:38 +0800252 AUTO_SEQ_FRONT = 0,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100253 AUTO_SEQ_SURROUND,
254 AUTO_SEQ_CENLFE,
255 AUTO_SEQ_SIDE
256};
257
Lydia Wangf5271102009-10-10 19:07:35 +0800258static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800259static int is_aa_path_mute(struct hda_codec *codec);
260
261static void vt1708_start_hp_work(struct via_spec *spec)
262{
263 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
264 return;
265 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
266 !spec->vt1708_jack_detectect);
267 if (!delayed_work_pending(&spec->vt1708_hp_work))
268 schedule_delayed_work(&spec->vt1708_hp_work,
269 msecs_to_jiffies(100));
270}
271
272static void vt1708_stop_hp_work(struct via_spec *spec)
273{
274 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
275 return;
276 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
277 && !is_aa_path_mute(spec->codec))
278 return;
279 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
280 !spec->vt1708_jack_detectect);
Tejun Heo5b84ba22010-12-11 17:51:26 +0100281 cancel_delayed_work_sync(&spec->vt1708_hp_work);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800282}
Lydia Wangf5271102009-10-10 19:07:35 +0800283
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800284static void set_widgets_power_state(struct hda_codec *codec)
285{
286 struct via_spec *spec = codec->spec;
287 if (spec->set_widgets_power_state)
288 spec->set_widgets_power_state(codec);
289}
Lydia Wang25eaba22009-10-10 19:08:43 +0800290
Lydia Wangf5271102009-10-10 19:07:35 +0800291static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
292 struct snd_ctl_elem_value *ucontrol)
293{
294 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
295 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
296
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800297 set_widgets_power_state(codec);
Lydia Wangf5271102009-10-10 19:07:35 +0800298 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800299 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
300 if (is_aa_path_mute(codec))
301 vt1708_start_hp_work(codec->spec);
302 else
303 vt1708_stop_hp_work(codec->spec);
304 }
Lydia Wangf5271102009-10-10 19:07:35 +0800305 return change;
306}
307
308/* modify .put = snd_hda_mixer_amp_switch_put */
309#define ANALOG_INPUT_MUTE \
310 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
311 .name = NULL, \
312 .index = 0, \
313 .info = snd_hda_mixer_amp_switch_info, \
314 .get = snd_hda_mixer_amp_switch_get, \
315 .put = analog_input_switch_put, \
316 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
317
Lydia Wang25eaba22009-10-10 19:08:43 +0800318static void via_hp_bind_automute(struct hda_codec *codec);
319
320static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
321 struct snd_ctl_elem_value *ucontrol)
322{
323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
324 struct via_spec *spec = codec->spec;
325 int i;
326 int change = 0;
327
328 long *valp = ucontrol->value.integer.value;
329 int lmute, rmute;
330 if (strstr(kcontrol->id.name, "Switch") == NULL) {
331 snd_printd("Invalid control!\n");
332 return change;
333 }
334 change = snd_hda_mixer_amp_switch_put(kcontrol,
335 ucontrol);
336 /* Get mute value */
337 lmute = *valp ? 0 : HDA_AMP_MUTE;
338 valp++;
339 rmute = *valp ? 0 : HDA_AMP_MUTE;
340
341 /* Set hp pins */
342 if (!spec->hp_independent_mode) {
343 for (i = 0; i < spec->autocfg.hp_outs; i++) {
344 snd_hda_codec_amp_update(
345 codec, spec->autocfg.hp_pins[i],
346 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
347 lmute);
348 snd_hda_codec_amp_update(
349 codec, spec->autocfg.hp_pins[i],
350 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
351 rmute);
352 }
353 }
354
355 if (!lmute && !rmute) {
356 /* Line Outs */
357 for (i = 0; i < spec->autocfg.line_outs; i++)
358 snd_hda_codec_amp_stereo(
359 codec, spec->autocfg.line_out_pins[i],
360 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
361 /* Speakers */
362 for (i = 0; i < spec->autocfg.speaker_outs; i++)
363 snd_hda_codec_amp_stereo(
364 codec, spec->autocfg.speaker_pins[i],
365 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
366 /* unmute */
367 via_hp_bind_automute(codec);
368
369 } else {
370 if (lmute) {
371 /* Mute all left channels */
372 for (i = 1; i < spec->autocfg.line_outs; i++)
373 snd_hda_codec_amp_update(
374 codec,
375 spec->autocfg.line_out_pins[i],
376 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
377 lmute);
378 for (i = 0; i < spec->autocfg.speaker_outs; i++)
379 snd_hda_codec_amp_update(
380 codec,
381 spec->autocfg.speaker_pins[i],
382 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
383 lmute);
384 }
385 if (rmute) {
386 /* mute all right channels */
387 for (i = 1; i < spec->autocfg.line_outs; i++)
388 snd_hda_codec_amp_update(
389 codec,
390 spec->autocfg.line_out_pins[i],
391 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
392 rmute);
393 for (i = 0; i < spec->autocfg.speaker_outs; i++)
394 snd_hda_codec_amp_update(
395 codec,
396 spec->autocfg.speaker_pins[i],
397 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
398 rmute);
399 }
400 }
401 return change;
402}
403
404#define BIND_PIN_MUTE \
405 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
406 .name = NULL, \
407 .index = 0, \
408 .info = snd_hda_mixer_amp_switch_info, \
409 .get = snd_hda_mixer_amp_switch_get, \
410 .put = bind_pin_switch_put, \
411 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
412
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200413static const struct snd_kcontrol_new via_control_templates[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100414 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
415 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Lydia Wangf5271102009-10-10 19:07:35 +0800416 ANALOG_INPUT_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800417 BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100418};
419
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200420static const hda_nid_t vt1708_adc_nids[2] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100421 /* ADC1-2 */
422 0x15, 0x27
423};
424
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200425static const hda_nid_t vt1709_adc_nids[3] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100426 /* ADC1-2 */
427 0x14, 0x15, 0x16
428};
429
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200430static const hda_nid_t vt1708B_adc_nids[2] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +0100431 /* ADC1-2 */
432 0x13, 0x14
433};
434
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200435static const hda_nid_t vt1708S_adc_nids[2] = {
Harald Welted949cac2008-09-09 15:56:01 +0800436 /* ADC1-2 */
437 0x13, 0x14
438};
439
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200440static const hda_nid_t vt1702_adc_nids[3] = {
Harald Welted949cac2008-09-09 15:56:01 +0800441 /* ADC1-2 */
442 0x12, 0x20, 0x1F
443};
444
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200445static const hda_nid_t vt1718S_adc_nids[2] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +0800446 /* ADC1-2 */
447 0x10, 0x11
448};
449
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200450static const hda_nid_t vt1716S_adc_nids[2] = {
Lydia Wangf3db4232009-10-10 19:08:41 +0800451 /* ADC1-2 */
452 0x13, 0x14
453};
454
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200455static const hda_nid_t vt2002P_adc_nids[2] = {
Lydia Wang25eaba22009-10-10 19:08:43 +0800456 /* ADC1-2 */
457 0x10, 0x11
458};
459
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200460static const hda_nid_t vt1812_adc_nids[2] = {
Lydia Wangab6734e2009-10-10 19:08:46 +0800461 /* ADC1-2 */
462 0x10, 0x11
463};
464
465
Joseph Chanc577b8a2006-11-29 15:29:40 +0100466/* add dynamic controls */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200467static int __via_add_control(struct via_spec *spec, int type, const char *name,
468 int idx, unsigned long val)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100469{
470 struct snd_kcontrol_new *knew;
471
Takashi Iwai603c4012008-07-30 15:01:44 +0200472 snd_array_init(&spec->kctls, sizeof(*knew), 32);
473 knew = snd_array_new(&spec->kctls);
474 if (!knew)
475 return -ENOMEM;
Lydia Wang71eb7dc2009-10-10 19:08:49 +0800476 *knew = via_control_templates[type];
Joseph Chanc577b8a2006-11-29 15:29:40 +0100477 knew->name = kstrdup(name, GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100478 if (!knew->name)
479 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100480 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100481 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100482 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100483 return 0;
484}
485
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200486#define via_add_control(spec, type, name, val) \
487 __via_add_control(spec, type, name, 0, val)
488
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100489static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200490 const struct snd_kcontrol_new *tmpl)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100491{
492 struct snd_kcontrol_new *knew;
493
494 snd_array_init(&spec->kctls, sizeof(*knew), 32);
495 knew = snd_array_new(&spec->kctls);
496 if (!knew)
497 return NULL;
498 *knew = *tmpl;
499 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
500 if (!knew->name)
501 return NULL;
Takashi Iwaib3314392010-04-14 14:33:57 +0200502 return knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100503}
504
Takashi Iwai603c4012008-07-30 15:01:44 +0200505static void via_free_kctls(struct hda_codec *codec)
506{
507 struct via_spec *spec = codec->spec;
508
509 if (spec->kctls.list) {
510 struct snd_kcontrol_new *kctl = spec->kctls.list;
511 int i;
512 for (i = 0; i < spec->kctls.used; i++)
513 kfree(kctl[i].name);
514 }
515 snd_array_free(&spec->kctls);
516}
517
Joseph Chanc577b8a2006-11-29 15:29:40 +0100518/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800519static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200520 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100521{
522 char name[32];
523 int err;
524
525 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200526 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100527 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
528 if (err < 0)
529 return err;
530 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200531 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100532 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
533 if (err < 0)
534 return err;
535 return 0;
536}
537
538static void via_auto_set_output_and_unmute(struct hda_codec *codec,
539 hda_nid_t nid, int pin_type,
540 int dac_idx)
541{
542 /* set as output */
543 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
544 pin_type);
545 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
546 AMP_OUT_UNMUTE);
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200547 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
Lydia Wang377ff312009-10-10 19:08:55 +0800548 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200549 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100550}
551
552
553static void via_auto_init_multi_out(struct hda_codec *codec)
554{
555 struct via_spec *spec = codec->spec;
556 int i;
557
558 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
559 hda_nid_t nid = spec->autocfg.line_out_pins[i];
560 if (nid)
561 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
562 }
563}
564
565static void via_auto_init_hp_out(struct hda_codec *codec)
566{
567 struct via_spec *spec = codec->spec;
568 hda_nid_t pin;
Lydia Wang25eaba22009-10-10 19:08:43 +0800569 int i;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100570
Lydia Wang25eaba22009-10-10 19:08:43 +0800571 for (i = 0; i < spec->autocfg.hp_outs; i++) {
572 pin = spec->autocfg.hp_pins[i];
573 if (pin) /* connect to front */
574 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
575 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100576}
577
Clemens Ladisch32e01912010-07-12 16:28:50 +0200578static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
579
Joseph Chanc577b8a2006-11-29 15:29:40 +0100580static void via_auto_init_analog_input(struct hda_codec *codec)
581{
582 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200583 const struct auto_pin_cfg *cfg = &spec->autocfg;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200584 unsigned int ctl;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100585 int i;
586
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200587 for (i = 0; i < cfg->num_inputs; i++) {
588 hda_nid_t nid = cfg->inputs[i].pin;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200589 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
590 ctl = PIN_OUT;
David Henningsson30649672011-02-21 10:23:18 +0100591 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
Clemens Ladisch32e01912010-07-12 16:28:50 +0200592 ctl = PIN_VREF50;
593 else
594 ctl = PIN_IN;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100595 snd_hda_codec_write(codec, nid, 0,
Clemens Ladisch32e01912010-07-12 16:28:50 +0200596 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100597 }
598}
Lydia Wangf5271102009-10-10 19:07:35 +0800599
600static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
601 unsigned int *affected_parm)
602{
603 unsigned parm;
604 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
605 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
606 >> AC_DEFCFG_MISC_SHIFT
607 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Takashi Iwaid56757a2009-11-18 08:00:14 +0100608 unsigned present = snd_hda_jack_detect(codec, nid);
Lydia Wang1564b282009-10-10 19:07:52 +0800609 struct via_spec *spec = codec->spec;
610 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
611 || ((no_presence || present)
612 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800613 *affected_parm = AC_PWRST_D0; /* if it's connected */
614 parm = AC_PWRST_D0;
615 } else
616 parm = AC_PWRST_D3;
617
618 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
619}
620
Joseph Chanc577b8a2006-11-29 15:29:40 +0100621/*
622 * input MUX handling
623 */
624static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
625 struct snd_ctl_elem_info *uinfo)
626{
627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
628 struct via_spec *spec = codec->spec;
629 return snd_hda_input_mux_info(spec->input_mux, uinfo);
630}
631
632static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_value *ucontrol)
634{
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct via_spec *spec = codec->spec;
637 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
638
639 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
640 return 0;
641}
642
643static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_value *ucontrol)
645{
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct via_spec *spec = codec->spec;
648 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800649 int ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100650
Takashi Iwai337b9d02009-07-07 18:18:59 +0200651 if (!spec->mux_nids[adc_idx])
652 return -EINVAL;
Lydia Wanga80e6e32009-10-10 19:07:55 +0800653 /* switch to D0 beofre change index */
654 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
655 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
656 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
657 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800658
659 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
660 spec->mux_nids[adc_idx],
661 &spec->cur_mux[adc_idx]);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800662 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800663 set_widgets_power_state(codec);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800664
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800665 return ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100666}
667
Harald Welte0aa62ae2008-09-09 15:58:27 +0800668static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
669 struct snd_ctl_elem_info *uinfo)
670{
671 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
672 struct via_spec *spec = codec->spec;
673 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
674}
675
676static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
677 struct snd_ctl_elem_value *ucontrol)
678{
679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100680 hda_nid_t nid = kcontrol->private_value;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800681 unsigned int pinsel;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800682
Lydia Wangeb7188c2009-10-10 19:08:34 +0800683 /* use !! to translate conn sel 2 for VT1718S */
684 pinsel = !!snd_hda_codec_read(codec, nid, 0,
685 AC_VERB_GET_CONNECT_SEL,
686 0x00);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800687 ucontrol->value.enumerated.item[0] = pinsel;
688
689 return 0;
690}
691
Lydia Wang0713efe2009-10-10 19:07:43 +0800692static void activate_ctl(struct hda_codec *codec, const char *name, int active)
693{
694 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
695 if (ctl) {
696 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
697 ctl->vd[0].access |= active
698 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
699 snd_ctl_notify(codec->bus->card,
700 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
701 }
702}
703
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100704static hda_nid_t side_mute_channel(struct via_spec *spec)
705{
706 switch (spec->codec_type) {
707 case VT1708: return 0x1b;
708 case VT1709_10CH: return 0x29;
709 case VT1708B_8CH: /* fall thru */
710 case VT1708S: return 0x27;
Lydia Wange87885f2011-03-24 12:39:05 +0800711 case VT2002P: return 0x19;
712 case VT1802: return 0x15;
713 case VT1812: return 0x15;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100714 default: return 0;
715 }
716}
717
Lydia Wangcdc17842009-10-10 19:07:47 +0800718static int update_side_mute_status(struct hda_codec *codec)
719{
720 /* mute side channel */
721 struct via_spec *spec = codec->spec;
Lydia Wange87885f2011-03-24 12:39:05 +0800722 unsigned int parm;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100723 hda_nid_t sw3 = side_mute_channel(spec);
Lydia Wangcdc17842009-10-10 19:07:47 +0800724
Lydia Wange87885f2011-03-24 12:39:05 +0800725 if (sw3) {
726 if (VT2002P_COMPATIBLE(spec))
727 parm = spec->hp_independent_mode ?
728 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
729 else
730 parm = spec->hp_independent_mode ?
731 AMP_OUT_MUTE : AMP_OUT_UNMUTE;
732 snd_hda_codec_write(codec, sw3, 0,
733 AC_VERB_SET_AMP_GAIN_MUTE, parm);
734 if (spec->codec_type == VT1812)
735 snd_hda_codec_write(codec, 0x1d, 0,
736 AC_VERB_SET_AMP_GAIN_MUTE, parm);
737 }
Lydia Wangcdc17842009-10-10 19:07:47 +0800738 return 0;
739}
740
Harald Welte0aa62ae2008-09-09 15:58:27 +0800741static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
742 struct snd_ctl_elem_value *ucontrol)
743{
744 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
745 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100746 hda_nid_t nid = kcontrol->private_value;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800747 unsigned int pinsel = ucontrol->value.enumerated.item[0];
Lydia Wangcdc17842009-10-10 19:07:47 +0800748 /* Get Independent Mode index of headphone pin widget */
749 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
750 ? 1 : 0;
Lydia Wangce0e5a92011-03-22 16:22:37 +0800751 if (spec->codec_type == VT1718S)
752 snd_hda_codec_write(codec, nid, 0,
753 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
754 else
755 snd_hda_codec_write(codec, nid, 0,
756 AC_VERB_SET_CONNECT_SEL, pinsel);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800757
Lydia Wangce0e5a92011-03-22 16:22:37 +0800758 if (spec->codec_type == VT1812)
759 snd_hda_codec_write(codec, 0x35, 0,
760 AC_VERB_SET_CONNECT_SEL, pinsel);
Lydia Wangcdc17842009-10-10 19:07:47 +0800761 if (spec->multiout.hp_nid && spec->multiout.hp_nid
762 != spec->multiout.dac_nids[HDA_FRONT])
763 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
764 0, 0, 0);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800765
Lydia Wangcdc17842009-10-10 19:07:47 +0800766 update_side_mute_status(codec);
Lydia Wang0713efe2009-10-10 19:07:43 +0800767 /* update HP volume/swtich active state */
768 if (spec->codec_type == VT1708S
Lydia Wangeb7188c2009-10-10 19:08:34 +0800769 || spec->codec_type == VT1702
Lydia Wangf3db4232009-10-10 19:08:41 +0800770 || spec->codec_type == VT1718S
Lydia Wang25eaba22009-10-10 19:08:43 +0800771 || spec->codec_type == VT1716S
Lydia Wang118909562011-03-23 17:57:34 +0800772 || VT2002P_COMPATIBLE(spec)) {
Lydia Wang0713efe2009-10-10 19:07:43 +0800773 activate_ctl(codec, "Headphone Playback Volume",
774 spec->hp_independent_mode);
775 activate_ctl(codec, "Headphone Playback Switch",
776 spec->hp_independent_mode);
777 }
Lydia Wangce0e5a92011-03-22 16:22:37 +0800778 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800779 set_widgets_power_state(codec);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800780 return 0;
781}
782
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200783static const struct snd_kcontrol_new via_hp_mixer[2] = {
Harald Welte0aa62ae2008-09-09 15:58:27 +0800784 {
785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
786 .name = "Independent HP",
Harald Welte0aa62ae2008-09-09 15:58:27 +0800787 .info = via_independent_hp_info,
788 .get = via_independent_hp_get,
789 .put = via_independent_hp_put,
790 },
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100791 {
792 .iface = NID_MAPPING,
793 .name = "Independent HP",
794 },
Harald Welte0aa62ae2008-09-09 15:58:27 +0800795};
796
Takashi Iwai3d83e572010-04-14 14:36:23 +0200797static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100798{
Takashi Iwai3d83e572010-04-14 14:36:23 +0200799 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100800 struct snd_kcontrol_new *knew;
801 hda_nid_t nid;
Takashi Iwai3d83e572010-04-14 14:36:23 +0200802 int nums;
803 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100804
805 switch (spec->codec_type) {
806 case VT1718S:
807 nid = 0x34;
808 break;
809 case VT2002P:
Lydia Wang118909562011-03-23 17:57:34 +0800810 case VT1802:
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100811 nid = 0x35;
812 break;
813 case VT1812:
814 nid = 0x3d;
815 break;
816 default:
817 nid = spec->autocfg.hp_pins[0];
818 break;
819 }
820
Lydia Wangee3c35c2011-03-22 16:26:36 +0800821 if (spec->codec_type != VT1708) {
822 nums = snd_hda_get_connections(codec, nid,
823 conn, HDA_MAX_CONNECTIONS);
824 if (nums <= 1)
825 return 0;
826 }
Takashi Iwai3d83e572010-04-14 14:36:23 +0200827
828 knew = via_clone_control(spec, &via_hp_mixer[0]);
829 if (knew == NULL)
830 return -ENOMEM;
831
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100832 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
833 knew->private_value = nid;
834
835 knew = via_clone_control(spec, &via_hp_mixer[1]);
836 if (knew == NULL)
837 return -ENOMEM;
838 knew->subdevice = side_mute_channel(spec);
839
840 return 0;
841}
842
Lydia Wang1564b282009-10-10 19:07:52 +0800843static void notify_aa_path_ctls(struct hda_codec *codec)
844{
845 int i;
846 struct snd_ctl_elem_id id;
Lydia Wang525566c2011-04-28 16:03:39 +0800847 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
848 struct snd_kcontrol *ctl;
Lydia Wang1564b282009-10-10 19:07:52 +0800849
850 memset(&id, 0, sizeof(id));
851 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
852 for (i = 0; i < ARRAY_SIZE(labels); i++) {
853 sprintf(id.name, "%s Playback Volume", labels[i]);
Lydia Wang525566c2011-04-28 16:03:39 +0800854 ctl = snd_hda_find_mixer_ctl(codec, id.name);
855 if (ctl)
856 snd_ctl_notify(codec->bus->card,
857 SNDRV_CTL_EVENT_MASK_VALUE,
858 &ctl->id);
Lydia Wang1564b282009-10-10 19:07:52 +0800859 }
860}
861
862static void mute_aa_path(struct hda_codec *codec, int mute)
863{
864 struct via_spec *spec = codec->spec;
865 hda_nid_t nid_mixer;
866 int start_idx;
867 int end_idx;
868 int i;
869 /* get nid of MW0 and start & end index */
870 switch (spec->codec_type) {
871 case VT1708:
872 nid_mixer = 0x17;
873 start_idx = 2;
874 end_idx = 4;
875 break;
876 case VT1709_10CH:
877 case VT1709_6CH:
878 nid_mixer = 0x18;
879 start_idx = 2;
880 end_idx = 4;
881 break;
882 case VT1708B_8CH:
883 case VT1708B_4CH:
884 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +0800885 case VT1716S:
Lydia Wang1564b282009-10-10 19:07:52 +0800886 nid_mixer = 0x16;
887 start_idx = 2;
888 end_idx = 4;
889 break;
Lydia Wangab657e02011-03-22 16:23:23 +0800890 case VT1718S:
891 nid_mixer = 0x21;
892 start_idx = 1;
893 end_idx = 3;
894 break;
Lydia Wang1564b282009-10-10 19:07:52 +0800895 default:
896 return;
897 }
898 /* check AA path's mute status */
899 for (i = start_idx; i <= end_idx; i++) {
900 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
901 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
902 HDA_AMP_MUTE, val);
903 }
904}
905static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
906{
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200907 const struct auto_pin_cfg *cfg = &spec->autocfg;
908 int i;
909
910 for (i = 0; i < cfg->num_inputs; i++) {
911 if (pin == cfg->inputs[i].pin)
Takashi Iwai86e29592010-09-09 14:50:17 +0200912 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
Lydia Wang1564b282009-10-10 19:07:52 +0800913 }
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200914 return 0;
Lydia Wang1564b282009-10-10 19:07:52 +0800915}
916
917static int via_smart51_info(struct snd_kcontrol *kcontrol,
918 struct snd_ctl_elem_info *uinfo)
919{
920 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
921 uinfo->count = 1;
922 uinfo->value.integer.min = 0;
923 uinfo->value.integer.max = 1;
924 return 0;
925}
926
927static int via_smart51_get(struct snd_kcontrol *kcontrol,
928 struct snd_ctl_elem_value *ucontrol)
929{
930 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
931 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200932 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800933 int on = 1;
934 int i;
935
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200936 for (i = 0; i < cfg->num_inputs; i++) {
937 hda_nid_t nid = cfg->inputs[i].pin;
938 int ctl = snd_hda_codec_read(codec, nid, 0,
939 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai86e29592010-09-09 14:50:17 +0200940 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200941 continue;
Takashi Iwai86e29592010-09-09 14:50:17 +0200942 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200943 spec->hp_independent_mode && spec->codec_type != VT1718S)
944 continue; /* ignore FMic for independent HP */
945 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
946 on = 0;
Lydia Wang1564b282009-10-10 19:07:52 +0800947 }
948 *ucontrol->value.integer.value = on;
949 return 0;
950}
951
952static int via_smart51_put(struct snd_kcontrol *kcontrol,
953 struct snd_ctl_elem_value *ucontrol)
954{
955 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
956 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200957 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800958 int out_in = *ucontrol->value.integer.value
959 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +0800960 int i;
961
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200962 for (i = 0; i < cfg->num_inputs; i++) {
963 hda_nid_t nid = cfg->inputs[i].pin;
964 unsigned int parm;
965
Takashi Iwai86e29592010-09-09 14:50:17 +0200966 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200967 continue;
Takashi Iwai86e29592010-09-09 14:50:17 +0200968 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200969 spec->hp_independent_mode && spec->codec_type != VT1718S)
Lydia Wang1564b282009-10-10 19:07:52 +0800970 continue; /* don't retask FMic for independent HP */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200971
972 parm = snd_hda_codec_read(codec, nid, 0,
973 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
974 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
975 parm |= out_in;
976 snd_hda_codec_write(codec, nid, 0,
977 AC_VERB_SET_PIN_WIDGET_CONTROL,
978 parm);
979 if (out_in == AC_PINCTL_OUT_EN) {
980 mute_aa_path(codec, 1);
981 notify_aa_path_ctls(codec);
982 }
983 if (spec->codec_type == VT1718S) {
984 snd_hda_codec_amp_stereo(
Lydia Wangeb7188c2009-10-10 19:08:34 +0800985 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
986 HDA_AMP_UNMUTE);
Lydia Wang1564b282009-10-10 19:07:52 +0800987 }
Takashi Iwai86e29592010-09-09 14:50:17 +0200988 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
Lydia Wangf3db4232009-10-10 19:08:41 +0800989 if (spec->codec_type == VT1708S
990 || spec->codec_type == VT1716S) {
Lydia Wang1564b282009-10-10 19:07:52 +0800991 /* input = index 1 (AOW3) */
992 snd_hda_codec_write(
993 codec, nid, 0,
994 AC_VERB_SET_CONNECT_SEL, 1);
995 snd_hda_codec_amp_stereo(
996 codec, nid, HDA_OUTPUT,
997 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
998 }
999 }
1000 }
1001 spec->smart51_enabled = *ucontrol->value.integer.value;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001002 set_widgets_power_state(codec);
Lydia Wang1564b282009-10-10 19:07:52 +08001003 return 1;
1004}
1005
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001006static const struct snd_kcontrol_new via_smart51_mixer = {
1007 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1008 .name = "Smart 5.1",
1009 .count = 1,
1010 .info = via_smart51_info,
1011 .get = via_smart51_get,
1012 .put = via_smart51_put,
Lydia Wang1564b282009-10-10 19:07:52 +08001013};
1014
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001015static int via_smart51_build(struct via_spec *spec)
1016{
1017 struct snd_kcontrol_new *knew;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001018 const struct auto_pin_cfg *cfg = &spec->autocfg;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001019 hda_nid_t nid;
1020 int i;
1021
Lydia Wangcb34c202011-04-27 17:44:16 +08001022 if (!cfg)
1023 return 0;
1024 if (cfg->line_outs > 2)
1025 return 0;
1026
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001027 knew = via_clone_control(spec, &via_smart51_mixer);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001028 if (knew == NULL)
1029 return -ENOMEM;
1030
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001031 for (i = 0; i < cfg->num_inputs; i++) {
1032 nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02001033 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001034 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001035 break;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001036 }
1037 }
1038
1039 return 0;
1040}
1041
Joseph Chanc577b8a2006-11-29 15:29:40 +01001042/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001043static const struct snd_kcontrol_new vt1708_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001044 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1045 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1046 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1047 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1048 {
1049 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1050 /* The multiple "Capture Source" controls confuse alsamixer
1051 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01001052 */
1053 /* .name = "Capture Source", */
1054 .name = "Input Source",
1055 .count = 1,
1056 .info = via_mux_enum_info,
1057 .get = via_mux_enum_get,
1058 .put = via_mux_enum_put,
1059 },
1060 { } /* end */
1061};
Lydia Wangf5271102009-10-10 19:07:35 +08001062
1063/* check AA path's mute statue */
1064static int is_aa_path_mute(struct hda_codec *codec)
1065{
1066 int mute = 1;
1067 hda_nid_t nid_mixer;
1068 int start_idx;
1069 int end_idx;
1070 int i;
1071 struct via_spec *spec = codec->spec;
1072 /* get nid of MW0 and start & end index */
1073 switch (spec->codec_type) {
1074 case VT1708B_8CH:
1075 case VT1708B_4CH:
1076 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001077 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001078 nid_mixer = 0x16;
1079 start_idx = 2;
1080 end_idx = 4;
1081 break;
1082 case VT1702:
1083 nid_mixer = 0x1a;
1084 start_idx = 1;
1085 end_idx = 3;
1086 break;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001087 case VT1718S:
1088 nid_mixer = 0x21;
1089 start_idx = 1;
1090 end_idx = 3;
1091 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001092 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001093 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001094 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001095 nid_mixer = 0x21;
1096 start_idx = 0;
1097 end_idx = 2;
1098 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001099 default:
1100 return 0;
1101 }
1102 /* check AA path's mute status */
1103 for (i = start_idx; i <= end_idx; i++) {
1104 unsigned int con_list = snd_hda_codec_read(
1105 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1106 int shift = 8 * (i % 4);
1107 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1108 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1109 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1110 /* check mute status while the pin is connected */
1111 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1112 HDA_INPUT, i) >> 7;
1113 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1114 HDA_INPUT, i) >> 7;
1115 if (!mute_l || !mute_r) {
1116 mute = 0;
1117 break;
1118 }
1119 }
1120 }
1121 return mute;
1122}
1123
1124/* enter/exit analog low-current mode */
1125static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1126{
1127 struct via_spec *spec = codec->spec;
1128 static int saved_stream_idle = 1; /* saved stream idle status */
1129 int enable = is_aa_path_mute(codec);
1130 unsigned int verb = 0;
1131 unsigned int parm = 0;
1132
1133 if (stream_idle == -1) /* stream status did not change */
1134 enable = enable && saved_stream_idle;
1135 else {
1136 enable = enable && stream_idle;
1137 saved_stream_idle = stream_idle;
1138 }
1139
1140 /* decide low current mode's verb & parameter */
1141 switch (spec->codec_type) {
1142 case VT1708B_8CH:
1143 case VT1708B_4CH:
1144 verb = 0xf70;
1145 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1146 break;
1147 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001148 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001149 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001150 verb = 0xf73;
1151 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1152 break;
1153 case VT1702:
1154 verb = 0xf73;
1155 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1156 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001157 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001158 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001159 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001160 verb = 0xf93;
1161 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1162 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001163 default:
1164 return; /* other codecs are not supported */
1165 }
1166 /* send verb */
1167 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1168}
1169
Joseph Chanc577b8a2006-11-29 15:29:40 +01001170/*
1171 * generic initialization of ADC, input mixers and output mixers
1172 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001173static const struct hda_verb vt1708_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001174 /*
1175 * Unmute ADC0-1 and set the default input to mic-in
1176 */
1177 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1178 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1179
1180
Josepch Chanf7278fd2007-12-13 16:40:40 +01001181 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01001182 * mixer widget
1183 */
1184 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01001185 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1186 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1187 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1188 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1189 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001190
1191 /*
1192 * Set up output mixers (0x19 - 0x1b)
1193 */
1194 /* set vol=0 to output mixers */
1195 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1196 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1197 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Lydia Wang377ff312009-10-10 19:08:55 +08001198
Lydia Wangbfdc6752009-10-10 19:08:50 +08001199 /* Setup default input MW0 to PW4 */
1200 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001201 /* PW9 Output enable */
1202 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangaa266fc2011-03-24 12:41:01 +08001203 /* power down jack detect function */
1204 {0x1, 0xf81, 0x1},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001205 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001206};
1207
1208static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1209 struct hda_codec *codec,
1210 struct snd_pcm_substream *substream)
1211{
1212 struct via_spec *spec = codec->spec;
Lydia Wang17314372009-10-10 19:07:37 +08001213 int idle = substream->pstr->substream_opened == 1
1214 && substream->ref_count == 0;
Lydia Wang17314372009-10-10 19:07:37 +08001215 analog_low_current_mode(codec, idle);
Takashi Iwai9a081602008-02-12 18:37:26 +01001216 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1217 hinfo);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001218}
1219
Harald Welte0aa62ae2008-09-09 15:58:27 +08001220static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1221 unsigned int stream_tag,
1222 unsigned int format,
1223 struct snd_pcm_substream *substream)
1224{
1225 struct via_spec *spec = codec->spec;
1226 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001227 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001228 int chs = substream->runtime->channels;
1229 int i;
Stephen Warren7c935972011-06-01 11:14:17 -06001230 struct hda_spdif_out *spdif =
1231 snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001232
1233 mutex_lock(&codec->spdif_mutex);
1234 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1235 if (chs == 2 &&
1236 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1237 format) &&
Stephen Warren7c935972011-06-01 11:14:17 -06001238 !(spdif->status & IEC958_AES0_NONAUDIO)) {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001239 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1240 /* turn off SPDIF once; otherwise the IEC958 bits won't
1241 * be updated */
Stephen Warren7c935972011-06-01 11:14:17 -06001242 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001243 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1244 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001245 spdif->ctls &
Harald Welte0aa62ae2008-09-09 15:58:27 +08001246 ~AC_DIG1_ENABLE & 0xff);
1247 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1248 stream_tag, 0, format);
1249 /* turn on again (if needed) */
Stephen Warren7c935972011-06-01 11:14:17 -06001250 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001251 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1252 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001253 spdif->ctls & 0xff);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001254 } else {
1255 mout->dig_out_used = 0;
1256 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1257 0, 0, 0);
1258 }
1259 }
1260 mutex_unlock(&codec->spdif_mutex);
1261
1262 /* front */
1263 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1264 0, format);
1265
Lydia Wangeb7188c2009-10-10 19:08:34 +08001266 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1267 && !spec->hp_independent_mode)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001268 /* headphone out will just decode front left/right (stereo) */
1269 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1270 0, format);
1271
1272 /* extra outputs copied from front */
1273 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1274 if (mout->extra_out_nid[i])
1275 snd_hda_codec_setup_stream(codec,
1276 mout->extra_out_nid[i],
1277 stream_tag, 0, format);
1278
1279 /* surrounds */
1280 for (i = 1; i < mout->num_dacs; i++) {
1281 if (chs >= (i + 1) * 2) /* independent out */
1282 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1283 i * 2, format);
1284 else /* copy front */
1285 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1286 0, format);
1287 }
1288}
1289
1290static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1291 struct hda_codec *codec,
1292 unsigned int stream_tag,
1293 unsigned int format,
1294 struct snd_pcm_substream *substream)
1295{
1296 struct via_spec *spec = codec->spec;
1297 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001298 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001299
1300 if (substream->number == 0)
1301 playback_multi_pcm_prep_0(codec, stream_tag, format,
1302 substream);
1303 else {
1304 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1305 spec->hp_independent_mode)
1306 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1307 stream_tag, 0, format);
1308 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001309 vt1708_start_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001310 return 0;
1311}
1312
1313static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1314 struct hda_codec *codec,
1315 struct snd_pcm_substream *substream)
1316{
1317 struct via_spec *spec = codec->spec;
1318 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001319 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001320 int i;
1321
1322 if (substream->number == 0) {
1323 for (i = 0; i < mout->num_dacs; i++)
1324 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1325
1326 if (mout->hp_nid && !spec->hp_independent_mode)
1327 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1328 0, 0, 0);
1329
1330 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1331 if (mout->extra_out_nid[i])
1332 snd_hda_codec_setup_stream(codec,
1333 mout->extra_out_nid[i],
1334 0, 0, 0);
1335 mutex_lock(&codec->spdif_mutex);
1336 if (mout->dig_out_nid &&
1337 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1338 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1339 0, 0, 0);
1340 mout->dig_out_used = 0;
1341 }
1342 mutex_unlock(&codec->spdif_mutex);
1343 } else {
1344 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1345 spec->hp_independent_mode)
1346 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1347 0, 0, 0);
1348 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001349 vt1708_stop_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001350 return 0;
1351}
1352
Joseph Chanc577b8a2006-11-29 15:29:40 +01001353/*
1354 * Digital out
1355 */
1356static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1357 struct hda_codec *codec,
1358 struct snd_pcm_substream *substream)
1359{
1360 struct via_spec *spec = codec->spec;
1361 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1362}
1363
1364static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1365 struct hda_codec *codec,
1366 struct snd_pcm_substream *substream)
1367{
1368 struct via_spec *spec = codec->spec;
1369 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1370}
1371
Harald Welte5691ec72008-09-15 22:42:26 +08001372static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001373 struct hda_codec *codec,
1374 unsigned int stream_tag,
1375 unsigned int format,
1376 struct snd_pcm_substream *substream)
1377{
1378 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001379 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1380 stream_tag, format, substream);
1381}
Harald Welte5691ec72008-09-15 22:42:26 +08001382
Takashi Iwai9da29272009-05-07 16:31:14 +02001383static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1384 struct hda_codec *codec,
1385 struct snd_pcm_substream *substream)
1386{
1387 struct via_spec *spec = codec->spec;
1388 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001389 return 0;
1390}
1391
Joseph Chanc577b8a2006-11-29 15:29:40 +01001392/*
1393 * Analog capture
1394 */
1395static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1396 struct hda_codec *codec,
1397 unsigned int stream_tag,
1398 unsigned int format,
1399 struct snd_pcm_substream *substream)
1400{
1401 struct via_spec *spec = codec->spec;
1402
1403 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1404 stream_tag, 0, format);
1405 return 0;
1406}
1407
1408static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1409 struct hda_codec *codec,
1410 struct snd_pcm_substream *substream)
1411{
1412 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001413 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001414 return 0;
1415}
1416
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001417static const struct hda_pcm_stream vt1708_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001418 .substreams = 2,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001419 .channels_min = 2,
1420 .channels_max = 8,
1421 .nid = 0x10, /* NID to query formats and rates */
1422 .ops = {
1423 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001424 .prepare = via_playback_multi_pcm_prepare,
1425 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001426 },
1427};
1428
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001429static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Lydia Wangc873cc22009-10-10 19:08:21 +08001430 .substreams = 2,
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001431 .channels_min = 2,
1432 .channels_max = 8,
1433 .nid = 0x10, /* NID to query formats and rates */
1434 /* We got noisy outputs on the right channel on VT1708 when
1435 * 24bit samples are used. Until any workaround is found,
1436 * disable the 24bit format, so far.
1437 */
1438 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1439 .ops = {
1440 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08001441 .prepare = via_playback_multi_pcm_prepare,
1442 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001443 },
1444};
1445
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001446static const struct hda_pcm_stream vt1708_pcm_analog_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001447 .substreams = 2,
1448 .channels_min = 2,
1449 .channels_max = 2,
1450 .nid = 0x15, /* NID to query formats and rates */
1451 .ops = {
1452 .prepare = via_capture_pcm_prepare,
1453 .cleanup = via_capture_pcm_cleanup
1454 },
1455};
1456
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001457static const struct hda_pcm_stream vt1708_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001458 .substreams = 1,
1459 .channels_min = 2,
1460 .channels_max = 2,
1461 /* NID is set in via_build_pcms */
1462 .ops = {
1463 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001464 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001465 .prepare = via_dig_playback_pcm_prepare,
1466 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001467 },
1468};
1469
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001470static const struct hda_pcm_stream vt1708_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001471 .substreams = 1,
1472 .channels_min = 2,
1473 .channels_max = 2,
1474};
1475
1476static int via_build_controls(struct hda_codec *codec)
1477{
1478 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001479 struct snd_kcontrol *kctl;
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001480 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001481 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001482
1483 for (i = 0; i < spec->num_mixers; i++) {
1484 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1485 if (err < 0)
1486 return err;
1487 }
1488
1489 if (spec->multiout.dig_out_nid) {
1490 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001491 spec->multiout.dig_out_nid,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001492 spec->multiout.dig_out_nid);
1493 if (err < 0)
1494 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001495 err = snd_hda_create_spdif_share_sw(codec,
1496 &spec->multiout);
1497 if (err < 0)
1498 return err;
1499 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001500 }
1501 if (spec->dig_in_nid) {
1502 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1503 if (err < 0)
1504 return err;
1505 }
Lydia Wang17314372009-10-10 19:07:37 +08001506
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001507 /* assign Capture Source enums to NID */
1508 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1509 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +01001510 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001511 if (err < 0)
1512 return err;
1513 }
1514
1515 /* other nid->control mapping */
1516 for (i = 0; i < spec->num_mixers; i++) {
1517 for (knew = spec->mixers[i]; knew->name; knew++) {
1518 if (knew->iface != NID_MAPPING)
1519 continue;
1520 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1521 if (kctl == NULL)
1522 continue;
1523 err = snd_hda_add_nid(codec, kctl, 0,
1524 knew->subdevice);
1525 }
1526 }
1527
Lydia Wang17314372009-10-10 19:07:37 +08001528 /* init power states */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001529 set_widgets_power_state(codec);
Lydia Wang17314372009-10-10 19:07:37 +08001530 analog_low_current_mode(codec, 1);
1531
Takashi Iwai603c4012008-07-30 15:01:44 +02001532 via_free_kctls(codec); /* no longer needed */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001533 return 0;
1534}
1535
1536static int via_build_pcms(struct hda_codec *codec)
1537{
1538 struct via_spec *spec = codec->spec;
1539 struct hda_pcm *info = spec->pcm_rec;
1540
1541 codec->num_pcms = 1;
1542 codec->pcm_info = info;
1543
1544 info->name = spec->stream_name_analog;
Lydia Wang377ff312009-10-10 19:08:55 +08001545 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1546 *(spec->stream_analog_playback);
1547 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1548 spec->multiout.dac_nids[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001549 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1550 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1551
1552 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1553 spec->multiout.max_channels;
1554
1555 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1556 codec->num_pcms++;
1557 info++;
1558 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001559 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001560 if (spec->multiout.dig_out_nid) {
1561 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1562 *(spec->stream_digital_playback);
1563 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1564 spec->multiout.dig_out_nid;
1565 }
1566 if (spec->dig_in_nid) {
1567 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1568 *(spec->stream_digital_capture);
1569 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1570 spec->dig_in_nid;
1571 }
1572 }
1573
1574 return 0;
1575}
1576
1577static void via_free(struct hda_codec *codec)
1578{
1579 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001580
1581 if (!spec)
1582 return;
1583
Takashi Iwai603c4012008-07-30 15:01:44 +02001584 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001585 vt1708_stop_hp_work(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001586 kfree(codec->spec);
1587}
1588
Harald Welte69e52a82008-09-09 15:57:32 +08001589/* mute internal speaker if HP is plugged */
1590static void via_hp_automute(struct hda_codec *codec)
1591{
Lydia Wangdcf34c82009-10-10 19:08:15 +08001592 unsigned int present = 0;
Harald Welte69e52a82008-09-09 15:57:32 +08001593 struct via_spec *spec = codec->spec;
1594
Takashi Iwaid56757a2009-11-18 08:00:14 +01001595 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangdcf34c82009-10-10 19:08:15 +08001596
1597 if (!spec->hp_independent_mode) {
1598 struct snd_ctl_elem_id id;
1599 /* auto mute */
1600 snd_hda_codec_amp_stereo(
1601 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1602 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1603 /* notify change */
1604 memset(&id, 0, sizeof(id));
1605 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1606 strcpy(id.name, "Front Playback Switch");
1607 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1608 &id);
1609 }
Harald Welte69e52a82008-09-09 15:57:32 +08001610}
1611
Lydia Wangf3db4232009-10-10 19:08:41 +08001612/* mute mono out if HP or Line out is plugged */
1613static void via_mono_automute(struct hda_codec *codec)
1614{
1615 unsigned int hp_present, lineout_present;
1616 struct via_spec *spec = codec->spec;
1617
1618 if (spec->codec_type != VT1716S)
1619 return;
1620
Takashi Iwaid56757a2009-11-18 08:00:14 +01001621 lineout_present = snd_hda_jack_detect(codec,
1622 spec->autocfg.line_out_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001623
1624 /* Mute Mono Out if Line Out is plugged */
1625 if (lineout_present) {
1626 snd_hda_codec_amp_stereo(
1627 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1628 return;
1629 }
1630
Takashi Iwaid56757a2009-11-18 08:00:14 +01001631 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001632
1633 if (!spec->hp_independent_mode)
1634 snd_hda_codec_amp_stereo(
1635 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1636 hp_present ? HDA_AMP_MUTE : 0);
1637}
1638
Harald Welte69e52a82008-09-09 15:57:32 +08001639static void via_gpio_control(struct hda_codec *codec)
1640{
1641 unsigned int gpio_data;
1642 unsigned int vol_counter;
1643 unsigned int vol;
1644 unsigned int master_vol;
1645
1646 struct via_spec *spec = codec->spec;
1647
1648 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1649 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1650
1651 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1652 0xF84, 0) & 0x3F0000) >> 16;
1653
1654 vol = vol_counter & 0x1F;
1655 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1656 AC_VERB_GET_AMP_GAIN_MUTE,
1657 AC_AMP_GET_INPUT);
1658
1659 if (gpio_data == 0x02) {
1660 /* unmute line out */
1661 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1662 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1663
1664 if (vol_counter & 0x20) {
1665 /* decrease volume */
1666 if (vol > master_vol)
1667 vol = master_vol;
1668 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1669 0, HDA_AMP_VOLMASK,
1670 master_vol-vol);
1671 } else {
1672 /* increase volume */
1673 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1674 HDA_AMP_VOLMASK,
1675 ((master_vol+vol) > 0x2A) ? 0x2A :
1676 (master_vol+vol));
1677 }
1678 } else if (!(gpio_data & 0x02)) {
1679 /* mute line out */
1680 snd_hda_codec_amp_stereo(codec,
1681 spec->autocfg.line_out_pins[0],
1682 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1683 HDA_AMP_MUTE);
1684 }
1685}
1686
Lydia Wang25eaba22009-10-10 19:08:43 +08001687/* mute Internal-Speaker if HP is plugged */
1688static void via_speaker_automute(struct hda_codec *codec)
1689{
1690 unsigned int hp_present;
1691 struct via_spec *spec = codec->spec;
1692
Lydia Wang27439ce2011-03-24 12:40:10 +08001693 if (!VT2002P_COMPATIBLE(spec))
Lydia Wang25eaba22009-10-10 19:08:43 +08001694 return;
1695
Takashi Iwaid56757a2009-11-18 08:00:14 +01001696 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001697
1698 if (!spec->hp_independent_mode) {
1699 struct snd_ctl_elem_id id;
1700 snd_hda_codec_amp_stereo(
1701 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
1702 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1703 /* notify change */
1704 memset(&id, 0, sizeof(id));
1705 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1706 strcpy(id.name, "Speaker Playback Switch");
1707 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1708 &id);
1709 }
1710}
1711
1712/* mute line-out and internal speaker if HP is plugged */
1713static void via_hp_bind_automute(struct hda_codec *codec)
1714{
akpm@linux-foundation.org01a17962009-11-13 16:47:10 -08001715 /* use long instead of int below just to avoid an internal compiler
1716 * error with gcc 4.0.x
1717 */
1718 unsigned long hp_present, present = 0;
Lydia Wang25eaba22009-10-10 19:08:43 +08001719 struct via_spec *spec = codec->spec;
1720 int i;
1721
1722 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1723 return;
1724
Takashi Iwaid56757a2009-11-18 08:00:14 +01001725 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001726
Takashi Iwaid56757a2009-11-18 08:00:14 +01001727 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001728
1729 if (!spec->hp_independent_mode) {
1730 /* Mute Line-Outs */
1731 for (i = 0; i < spec->autocfg.line_outs; i++)
1732 snd_hda_codec_amp_stereo(
1733 codec, spec->autocfg.line_out_pins[i],
1734 HDA_OUTPUT, 0,
1735 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1736 if (hp_present)
1737 present = hp_present;
1738 }
1739 /* Speakers */
1740 for (i = 0; i < spec->autocfg.speaker_outs; i++)
1741 snd_hda_codec_amp_stereo(
1742 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
1743 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1744}
1745
1746
Harald Welte69e52a82008-09-09 15:57:32 +08001747/* unsolicited event for jack sensing */
1748static void via_unsol_event(struct hda_codec *codec,
1749 unsigned int res)
1750{
1751 res >>= 26;
Lydia Wangec7e7e42011-03-24 12:43:44 +08001752
Lydia Wanga34df192009-10-10 19:08:01 +08001753 if (res & VIA_JACK_EVENT)
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001754 set_widgets_power_state(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001755
1756 res &= ~VIA_JACK_EVENT;
1757
1758 if (res == VIA_HP_EVENT)
1759 via_hp_automute(codec);
1760 else if (res == VIA_GPIO_EVENT)
1761 via_gpio_control(codec);
1762 else if (res == VIA_MONO_EVENT)
Lydia Wangf3db4232009-10-10 19:08:41 +08001763 via_mono_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001764 else if (res == VIA_SPEAKER_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001765 via_speaker_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001766 else if (res == VIA_BIND_HP_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001767 via_hp_bind_automute(codec);
Harald Welte69e52a82008-09-09 15:57:32 +08001768}
1769
Joseph Chanc577b8a2006-11-29 15:29:40 +01001770static int via_init(struct hda_codec *codec)
1771{
1772 struct via_spec *spec = codec->spec;
Harald Welte69e52a82008-09-09 15:57:32 +08001773 int i;
1774 for (i = 0; i < spec->num_iverbs; i++)
1775 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1776
Josepch Chanf7278fd2007-12-13 16:40:40 +01001777 /* Lydia Add for EAPD enable */
1778 if (!spec->dig_in_nid) { /* No Digital In connection */
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001779 if (spec->dig_in_pin) {
1780 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001781 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +01001782 PIN_OUT);
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001783 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001784 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1785 }
Takashi Iwai12b74c82008-01-15 12:39:38 +01001786 } else /* enable SPDIF-input pin */
1787 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1788 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
Josepch Chanf7278fd2007-12-13 16:40:40 +01001789
Takashi Iwai9da29272009-05-07 16:31:14 +02001790 /* assign slave outs */
1791 if (spec->slave_dig_outs[0])
1792 codec->slave_dig_outs = spec->slave_dig_outs;
Harald Welte5691ec72008-09-15 22:42:26 +08001793
Lydia Wang377ff312009-10-10 19:08:55 +08001794 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001795}
1796
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001797#ifdef SND_HDA_NEEDS_RESUME
1798static int via_suspend(struct hda_codec *codec, pm_message_t state)
1799{
1800 struct via_spec *spec = codec->spec;
1801 vt1708_stop_hp_work(spec);
1802 return 0;
1803}
1804#endif
1805
Takashi Iwaicb53c622007-08-10 17:21:45 +02001806#ifdef CONFIG_SND_HDA_POWER_SAVE
1807static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1808{
1809 struct via_spec *spec = codec->spec;
1810 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1811}
1812#endif
1813
Joseph Chanc577b8a2006-11-29 15:29:40 +01001814/*
1815 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001816static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001817 .build_controls = via_build_controls,
1818 .build_pcms = via_build_pcms,
1819 .init = via_init,
1820 .free = via_free,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001821#ifdef SND_HDA_NEEDS_RESUME
1822 .suspend = via_suspend,
1823#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02001824#ifdef CONFIG_SND_HDA_POWER_SAVE
1825 .check_power_status = via_check_power_status,
1826#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001827};
1828
1829/* fill in the dac_nids table from the parsed pin configuration */
1830static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1831 const struct auto_pin_cfg *cfg)
1832{
1833 int i;
1834 hda_nid_t nid;
1835
1836 spec->multiout.num_dacs = cfg->line_outs;
1837
1838 spec->multiout.dac_nids = spec->private_dac_nids;
Lydia Wang377ff312009-10-10 19:08:55 +08001839
1840 for (i = 0; i < 4; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001841 nid = cfg->line_out_pins[i];
1842 if (nid) {
1843 /* config dac list */
1844 switch (i) {
1845 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02001846 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001847 break;
1848 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02001849 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001850 break;
1851 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02001852 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001853 break;
1854 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02001855 spec->private_dac_nids[i] = 0x13;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001856 break;
1857 }
1858 }
1859 }
1860
1861 return 0;
1862}
1863
1864/* add playback controls from the parsed DAC table */
1865static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1866 const struct auto_pin_cfg *cfg)
1867{
1868 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01001869 static const char * const chname[4] = {
1870 "Front", "Surround", "C/LFE", "Side"
1871 };
Lydia Wang9645c202009-10-10 19:08:27 +08001872 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
Joseph Chanc577b8a2006-11-29 15:29:40 +01001873 int i, err;
1874
1875 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1876 nid = cfg->line_out_pins[i];
1877
1878 if (!nid)
1879 continue;
Lydia Wang377ff312009-10-10 19:08:55 +08001880
Lydia Wang9645c202009-10-10 19:08:27 +08001881 nid_vol = nid_vols[i];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001882
1883 if (i == AUTO_SEQ_CENLFE) {
1884 /* Center/LFE */
1885 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001886 "Center Playback Volume",
1887 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1888 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001889 if (err < 0)
1890 return err;
1891 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1892 "LFE Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001893 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1894 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001895 if (err < 0)
1896 return err;
1897 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1898 "Center Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001899 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1900 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001901 if (err < 0)
1902 return err;
1903 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1904 "LFE Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001905 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1906 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001907 if (err < 0)
1908 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08001909 } else if (i == AUTO_SEQ_FRONT) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001910 /* add control to mixer index 0 */
1911 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1912 "Master Front Playback Volume",
Lydia Wang9645c202009-10-10 19:08:27 +08001913 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001914 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001915 if (err < 0)
1916 return err;
1917 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1918 "Master Front Playback Switch",
Lydia Wang9645c202009-10-10 19:08:27 +08001919 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001920 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001921 if (err < 0)
1922 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08001923
Joseph Chanc577b8a2006-11-29 15:29:40 +01001924 /* add control to PW3 */
1925 sprintf(name, "%s Playback Volume", chname[i]);
1926 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001927 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1928 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001929 if (err < 0)
1930 return err;
1931 sprintf(name, "%s Playback Switch", chname[i]);
1932 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001933 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1934 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001935 if (err < 0)
1936 return err;
1937 } else {
1938 sprintf(name, "%s Playback Volume", chname[i]);
1939 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001940 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1941 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001942 if (err < 0)
1943 return err;
1944 sprintf(name, "%s Playback Switch", chname[i]);
1945 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001946 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1947 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001948 if (err < 0)
1949 return err;
1950 }
1951 }
1952
1953 return 0;
1954}
1955
Harald Welte0aa62ae2008-09-09 15:58:27 +08001956static void create_hp_imux(struct via_spec *spec)
1957{
1958 int i;
1959 struct hda_input_mux *imux = &spec->private_imux[1];
Takashi Iwaiea734962011-01-17 11:29:34 +01001960 static const char * const texts[] = { "OFF", "ON", NULL};
Harald Welte0aa62ae2008-09-09 15:58:27 +08001961
1962 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02001963 for (i = 0; texts[i]; i++)
1964 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001965
1966 spec->hp_mux = &spec->private_imux[1];
1967}
1968
Joseph Chanc577b8a2006-11-29 15:29:40 +01001969static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1970{
1971 int err;
1972
1973 if (!pin)
1974 return 0;
1975
1976 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08001977 spec->hp_independent_mode_index = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001978
1979 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1980 "Headphone Playback Volume",
1981 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1982 if (err < 0)
1983 return err;
1984 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1985 "Headphone Playback Switch",
1986 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1987 if (err < 0)
1988 return err;
1989
Harald Welte0aa62ae2008-09-09 15:58:27 +08001990 create_hp_imux(spec);
1991
Joseph Chanc577b8a2006-11-29 15:29:40 +01001992 return 0;
1993}
1994
1995/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02001996static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaif3268512010-08-30 11:00:19 +02001997 const struct auto_pin_cfg *cfg,
1998 hda_nid_t cap_nid,
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001999 const hda_nid_t pin_idxs[],
2000 int num_idxs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002001{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002002 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08002003 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002004 int i, err, idx, type, type_idx = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002005
2006 /* for internal loopback recording select */
Takashi Iwaif3268512010-08-30 11:00:19 +02002007 for (idx = 0; idx < num_idxs; idx++) {
2008 if (pin_idxs[idx] == 0xff) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002009 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
Takashi Iwaif3268512010-08-30 11:00:19 +02002010 break;
2011 }
2012 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002013
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002014 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002015 const char *label;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002016 type = cfg->inputs[i].type;
Takashi Iwaif3268512010-08-30 11:00:19 +02002017 for (idx = 0; idx < num_idxs; idx++)
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002018 if (pin_idxs[idx] == cfg->inputs[i].pin)
Takashi Iwaif3268512010-08-30 11:00:19 +02002019 break;
2020 if (idx >= num_idxs)
2021 continue;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002022 if (i > 0 && type == cfg->inputs[i - 1].type)
2023 type_idx++;
2024 else
2025 type_idx = 0;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002026 label = hda_get_autocfg_input_label(codec, cfg, i);
Lydia Wang16922282011-03-22 16:24:10 +08002027 if (spec->codec_type == VT1708S ||
2028 spec->codec_type == VT1702 ||
2029 spec->codec_type == VT1716S)
2030 err = via_new_analog_input(spec, label, type_idx,
2031 idx+1, cap_nid);
2032 else
2033 err = via_new_analog_input(spec, label, type_idx,
2034 idx, cap_nid);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002035 if (err < 0)
2036 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002037 snd_hda_add_imux_item(imux, label, idx, NULL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002038 }
2039 return 0;
2040}
2041
Takashi Iwaif3268512010-08-30 11:00:19 +02002042/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002043static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaif3268512010-08-30 11:00:19 +02002044 const struct auto_pin_cfg *cfg)
2045{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002046 static const hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
Takashi Iwai10a20af2010-09-09 16:28:02 +02002047 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02002048 ARRAY_SIZE(pin_idxs));
2049}
2050
Takashi Iwaicb53c622007-08-10 17:21:45 +02002051#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002052static const struct hda_amp_list vt1708_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002053 { 0x17, HDA_INPUT, 1 },
2054 { 0x17, HDA_INPUT, 2 },
2055 { 0x17, HDA_INPUT, 3 },
2056 { 0x17, HDA_INPUT, 4 },
2057 { } /* end */
2058};
2059#endif
2060
Harald Welte76d9b0d2008-09-09 15:50:37 +08002061static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2062{
2063 unsigned int def_conf;
2064 unsigned char seqassoc;
2065
Takashi Iwai2f334f92009-02-20 14:37:42 +01002066 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002067 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2068 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002069 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2070 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2071 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2072 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002073 }
2074
2075 return;
2076}
2077
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002078static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2079 struct snd_ctl_elem_value *ucontrol)
2080{
2081 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2082 struct via_spec *spec = codec->spec;
2083
2084 if (spec->codec_type != VT1708)
2085 return 0;
2086 spec->vt1708_jack_detectect =
2087 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2088 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2089 return 0;
2090}
2091
2092static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2093 struct snd_ctl_elem_value *ucontrol)
2094{
2095 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2096 struct via_spec *spec = codec->spec;
2097 int change;
2098
2099 if (spec->codec_type != VT1708)
2100 return 0;
2101 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2102 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2103 == !spec->vt1708_jack_detectect;
2104 if (spec->vt1708_jack_detectect) {
2105 mute_aa_path(codec, 1);
2106 notify_aa_path_ctls(codec);
2107 }
2108 return change;
2109}
2110
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002111static const struct snd_kcontrol_new vt1708_jack_detectect[] = {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002112 {
2113 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2114 .name = "Jack Detect",
2115 .count = 1,
2116 .info = snd_ctl_boolean_mono_info,
2117 .get = vt1708_jack_detectect_get,
2118 .put = vt1708_jack_detectect_put,
2119 },
2120 {} /* end */
2121};
2122
Joseph Chanc577b8a2006-11-29 15:29:40 +01002123static int vt1708_parse_auto_config(struct hda_codec *codec)
2124{
2125 struct via_spec *spec = codec->spec;
2126 int err;
2127
Harald Welte76d9b0d2008-09-09 15:50:37 +08002128 /* Add HP and CD pin config connect bit re-config action */
2129 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2130 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2131
Joseph Chanc577b8a2006-11-29 15:29:40 +01002132 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2133 if (err < 0)
2134 return err;
2135 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2136 if (err < 0)
2137 return err;
2138 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2139 return 0; /* can't find valid BIOS pin config */
2140
2141 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2142 if (err < 0)
2143 return err;
2144 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2145 if (err < 0)
2146 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002147 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002148 if (err < 0)
2149 return err;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002150 /* add jack detect on/off control */
2151 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2152 if (err < 0)
2153 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002154
2155 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2156
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002157 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002158 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002159 spec->dig_in_pin = VT1708_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002160 if (spec->autocfg.dig_in_pin)
2161 spec->dig_in_nid = VT1708_DIGIN_NID;
2162
Takashi Iwai603c4012008-07-30 15:01:44 +02002163 if (spec->kctls.list)
2164 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002165
Harald Welte69e52a82008-09-09 15:57:32 +08002166 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002167
Harald Welte0aa62ae2008-09-09 15:58:27 +08002168 spec->input_mux = &spec->private_imux[0];
2169
Harald Weltef8fdd492008-09-15 22:41:31 +08002170 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002171 via_hp_build(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002172
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002173 via_smart51_build(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002174 return 1;
2175}
2176
2177/* init callback for auto-configuration model -- overriding the default init */
2178static int via_auto_init(struct hda_codec *codec)
2179{
Lydia Wang25eaba22009-10-10 19:08:43 +08002180 struct via_spec *spec = codec->spec;
2181
Joseph Chanc577b8a2006-11-29 15:29:40 +01002182 via_init(codec);
2183 via_auto_init_multi_out(codec);
2184 via_auto_init_hp_out(codec);
2185 via_auto_init_analog_input(codec);
Lydia Wang118909562011-03-23 17:57:34 +08002186
2187 if (VT2002P_COMPATIBLE(spec)) {
Lydia Wang25eaba22009-10-10 19:08:43 +08002188 via_hp_bind_automute(codec);
2189 } else {
2190 via_hp_automute(codec);
2191 via_speaker_automute(codec);
2192 }
2193
Joseph Chanc577b8a2006-11-29 15:29:40 +01002194 return 0;
2195}
2196
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002197static void vt1708_update_hp_jack_state(struct work_struct *work)
2198{
2199 struct via_spec *spec = container_of(work, struct via_spec,
2200 vt1708_hp_work.work);
2201 if (spec->codec_type != VT1708)
2202 return;
2203 /* if jack state toggled */
2204 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002205 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002206 spec->vt1708_hp_present ^= 1;
2207 via_hp_automute(spec->codec);
2208 }
2209 vt1708_start_hp_work(spec);
2210}
2211
Takashi Iwai337b9d02009-07-07 18:18:59 +02002212static int get_mux_nids(struct hda_codec *codec)
2213{
2214 struct via_spec *spec = codec->spec;
2215 hda_nid_t nid, conn[8];
2216 unsigned int type;
2217 int i, n;
2218
2219 for (i = 0; i < spec->num_adc_nids; i++) {
2220 nid = spec->adc_nids[i];
2221 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002222 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002223 if (type == AC_WID_PIN)
2224 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002225 n = snd_hda_get_connections(codec, nid, conn,
2226 ARRAY_SIZE(conn));
2227 if (n <= 0)
2228 break;
2229 if (n > 1) {
2230 spec->mux_nids[i] = nid;
2231 break;
2232 }
2233 nid = conn[0];
2234 }
2235 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002236 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002237}
2238
Joseph Chanc577b8a2006-11-29 15:29:40 +01002239static int patch_vt1708(struct hda_codec *codec)
2240{
2241 struct via_spec *spec;
2242 int err;
2243
2244 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002245 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002246 if (spec == NULL)
2247 return -ENOMEM;
2248
Joseph Chanc577b8a2006-11-29 15:29:40 +01002249 /* automatic parse from the BIOS config */
2250 err = vt1708_parse_auto_config(codec);
2251 if (err < 0) {
2252 via_free(codec);
2253 return err;
2254 } else if (!err) {
2255 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2256 "from BIOS. Using genenic mode...\n");
2257 }
2258
Lydia Wang377ff312009-10-10 19:08:55 +08002259
Joseph Chanc577b8a2006-11-29 15:29:40 +01002260 spec->stream_name_analog = "VT1708 Analog";
2261 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
Takashi Iwaibc9b562382008-05-23 17:50:27 +02002262 /* disable 32bit format on VT1708 */
2263 if (codec->vendor_id == 0x11061708)
2264 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002265 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2266
2267 spec->stream_name_digital = "VT1708 Digital";
2268 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2269 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2270
Lydia Wang377ff312009-10-10 19:08:55 +08002271
Joseph Chanc577b8a2006-11-29 15:29:40 +01002272 if (!spec->adc_nids && spec->input_mux) {
2273 spec->adc_nids = vt1708_adc_nids;
2274 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
Takashi Iwai0f67a612009-08-31 08:12:29 +02002275 get_mux_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002276 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2277 spec->num_mixers++;
2278 }
2279
2280 codec->patch_ops = via_patch_ops;
2281
2282 codec->patch_ops.init = via_auto_init;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002283#ifdef CONFIG_SND_HDA_POWER_SAVE
2284 spec->loopback.amplist = vt1708_loopbacks;
2285#endif
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002286 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002287 return 0;
2288}
2289
2290/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002291static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002292 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2293 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2294 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2295 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2296 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2297 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2298 {
2299 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2300 /* The multiple "Capture Source" controls confuse alsamixer
2301 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01002302 */
2303 /* .name = "Capture Source", */
2304 .name = "Input Source",
2305 .count = 1,
2306 .info = via_mux_enum_info,
2307 .get = via_mux_enum_get,
2308 .put = via_mux_enum_put,
2309 },
2310 { } /* end */
2311};
2312
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002313static const struct hda_verb vt1709_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002314 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2315 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002316 { }
2317};
2318
Joseph Chanc577b8a2006-11-29 15:29:40 +01002319/*
2320 * generic initialization of ADC, input mixers and output mixers
2321 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002322static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002323 /*
2324 * Unmute ADC0-2 and set the default input to mic-in
2325 */
2326 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2327 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2328 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2329
2330
Josepch Chanf7278fd2007-12-13 16:40:40 +01002331 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01002332 * mixer widget
2333 */
2334 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01002335 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2336 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2337 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2338 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2339 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002340
2341 /*
2342 * Set up output selector (0x1a, 0x1b, 0x29)
2343 */
2344 /* set vol=0 to output mixers */
2345 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2346 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2347 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2348
2349 /*
2350 * Unmute PW3 and PW4
2351 */
2352 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2353 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2354
Lydia Wangbfdc6752009-10-10 19:08:50 +08002355 /* Set input of PW4 as MW0 */
2356 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002357 /* PW9 Output enable */
2358 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2359 { }
2360};
2361
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002362static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002363 .substreams = 1,
2364 .channels_min = 2,
2365 .channels_max = 10,
2366 .nid = 0x10, /* NID to query formats and rates */
2367 .ops = {
2368 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002369 .prepare = via_playback_multi_pcm_prepare,
2370 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002371 },
2372};
2373
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002374static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002375 .substreams = 1,
2376 .channels_min = 2,
2377 .channels_max = 6,
2378 .nid = 0x10, /* NID to query formats and rates */
2379 .ops = {
2380 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002381 .prepare = via_playback_multi_pcm_prepare,
2382 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002383 },
2384};
2385
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002386static const struct hda_pcm_stream vt1709_pcm_analog_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002387 .substreams = 2,
2388 .channels_min = 2,
2389 .channels_max = 2,
2390 .nid = 0x14, /* NID to query formats and rates */
2391 .ops = {
2392 .prepare = via_capture_pcm_prepare,
2393 .cleanup = via_capture_pcm_cleanup
2394 },
2395};
2396
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002397static const struct hda_pcm_stream vt1709_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002398 .substreams = 1,
2399 .channels_min = 2,
2400 .channels_max = 2,
2401 /* NID is set in via_build_pcms */
2402 .ops = {
2403 .open = via_dig_playback_pcm_open,
2404 .close = via_dig_playback_pcm_close
2405 },
2406};
2407
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002408static const struct hda_pcm_stream vt1709_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002409 .substreams = 1,
2410 .channels_min = 2,
2411 .channels_max = 2,
2412};
2413
2414static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2415 const struct auto_pin_cfg *cfg)
2416{
2417 int i;
2418 hda_nid_t nid;
2419
2420 if (cfg->line_outs == 4) /* 10 channels */
2421 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2422 else if (cfg->line_outs == 3) /* 6 channels */
2423 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2424
2425 spec->multiout.dac_nids = spec->private_dac_nids;
2426
2427 if (cfg->line_outs == 4) { /* 10 channels */
2428 for (i = 0; i < cfg->line_outs; i++) {
2429 nid = cfg->line_out_pins[i];
2430 if (nid) {
2431 /* config dac list */
2432 switch (i) {
2433 case AUTO_SEQ_FRONT:
2434 /* AOW0 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002435 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002436 break;
2437 case AUTO_SEQ_CENLFE:
2438 /* AOW2 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002439 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002440 break;
2441 case AUTO_SEQ_SURROUND:
2442 /* AOW3 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002443 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002444 break;
2445 case AUTO_SEQ_SIDE:
2446 /* AOW1 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002447 spec->private_dac_nids[i] = 0x27;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002448 break;
2449 default:
2450 break;
2451 }
2452 }
2453 }
Takashi Iwaidda14412011-05-02 11:29:30 +02002454 spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
Joseph Chanc577b8a2006-11-29 15:29:40 +01002455
2456 } else if (cfg->line_outs == 3) { /* 6 channels */
Lydia Wang377ff312009-10-10 19:08:55 +08002457 for (i = 0; i < cfg->line_outs; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002458 nid = cfg->line_out_pins[i];
2459 if (nid) {
2460 /* config dac list */
Lydia Wang377ff312009-10-10 19:08:55 +08002461 switch (i) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002462 case AUTO_SEQ_FRONT:
2463 /* AOW0 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002464 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002465 break;
2466 case AUTO_SEQ_CENLFE:
2467 /* AOW2 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002468 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002469 break;
2470 case AUTO_SEQ_SURROUND:
2471 /* AOW1 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002472 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002473 break;
2474 default:
2475 break;
2476 }
2477 }
2478 }
2479 }
2480
2481 return 0;
2482}
2483
2484/* add playback controls from the parsed DAC table */
2485static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2486 const struct auto_pin_cfg *cfg)
2487{
2488 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01002489 static const char * const chname[4] = {
2490 "Front", "Surround", "C/LFE", "Side"
2491 };
Lydia Wang4483a2f2009-10-10 19:08:29 +08002492 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
Joseph Chanc577b8a2006-11-29 15:29:40 +01002493 int i, err;
2494
2495 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2496 nid = cfg->line_out_pins[i];
2497
Lydia Wang377ff312009-10-10 19:08:55 +08002498 if (!nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002499 continue;
2500
Lydia Wang4483a2f2009-10-10 19:08:29 +08002501 nid_vol = nid_vols[i];
2502
Joseph Chanc577b8a2006-11-29 15:29:40 +01002503 if (i == AUTO_SEQ_CENLFE) {
2504 /* Center/LFE */
2505 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2506 "Center Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002507 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002508 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002509 if (err < 0)
2510 return err;
2511 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2512 "LFE Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002513 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002514 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002515 if (err < 0)
2516 return err;
2517 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2518 "Center Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002519 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002520 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002521 if (err < 0)
2522 return err;
2523 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2524 "LFE Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002525 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002526 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002527 if (err < 0)
2528 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002529 } else if (i == AUTO_SEQ_FRONT) {
Lydia Wang4483a2f2009-10-10 19:08:29 +08002530 /* ADD control to mixer index 0 */
Joseph Chanc577b8a2006-11-29 15:29:40 +01002531 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2532 "Master Front Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002533 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002534 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002535 if (err < 0)
2536 return err;
2537 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2538 "Master Front Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002539 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002540 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002541 if (err < 0)
2542 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002543
Joseph Chanc577b8a2006-11-29 15:29:40 +01002544 /* add control to PW3 */
2545 sprintf(name, "%s Playback Volume", chname[i]);
2546 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002547 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2548 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002549 if (err < 0)
2550 return err;
2551 sprintf(name, "%s Playback Switch", chname[i]);
2552 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002553 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2554 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002555 if (err < 0)
2556 return err;
2557 } else if (i == AUTO_SEQ_SURROUND) {
2558 sprintf(name, "%s Playback Volume", chname[i]);
2559 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002560 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002561 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002562 if (err < 0)
2563 return err;
2564 sprintf(name, "%s Playback Switch", chname[i]);
2565 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002566 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002567 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002568 if (err < 0)
2569 return err;
2570 } else if (i == AUTO_SEQ_SIDE) {
2571 sprintf(name, "%s Playback Volume", chname[i]);
2572 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002573 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002574 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002575 if (err < 0)
2576 return err;
2577 sprintf(name, "%s Playback Switch", chname[i]);
2578 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002579 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002580 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002581 if (err < 0)
2582 return err;
2583 }
2584 }
2585
2586 return 0;
2587}
2588
2589static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2590{
2591 int err;
2592
2593 if (!pin)
2594 return 0;
2595
2596 if (spec->multiout.num_dacs == 5) /* 10 channels */
2597 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2598 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2599 spec->multiout.hp_nid = 0;
Lydia Wangcdc17842009-10-10 19:07:47 +08002600 spec->hp_independent_mode_index = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002601
2602 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2603 "Headphone Playback Volume",
2604 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2605 if (err < 0)
2606 return err;
2607 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2608 "Headphone Playback Switch",
2609 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2610 if (err < 0)
2611 return err;
2612
2613 return 0;
2614}
2615
2616/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002617static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002618 const struct auto_pin_cfg *cfg)
2619{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002620 static const hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
Takashi Iwai10a20af2010-09-09 16:28:02 +02002621 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02002622 ARRAY_SIZE(pin_idxs));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002623}
2624
2625static int vt1709_parse_auto_config(struct hda_codec *codec)
2626{
2627 struct via_spec *spec = codec->spec;
2628 int err;
2629
2630 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2631 if (err < 0)
2632 return err;
2633 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2634 if (err < 0)
2635 return err;
2636 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2637 return 0; /* can't find valid BIOS pin config */
2638
2639 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2640 if (err < 0)
2641 return err;
2642 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2643 if (err < 0)
2644 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002645 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002646 if (err < 0)
2647 return err;
2648
2649 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2650
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002651 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002652 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002653 spec->dig_in_pin = VT1709_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002654 if (spec->autocfg.dig_in_pin)
2655 spec->dig_in_nid = VT1709_DIGIN_NID;
2656
Takashi Iwai603c4012008-07-30 15:01:44 +02002657 if (spec->kctls.list)
2658 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002659
Harald Welte0aa62ae2008-09-09 15:58:27 +08002660 spec->input_mux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01002661
Harald Weltef8fdd492008-09-15 22:41:31 +08002662 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002663 via_hp_build(codec);
Harald Weltef8fdd492008-09-15 22:41:31 +08002664
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002665 via_smart51_build(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002666 return 1;
2667}
2668
Takashi Iwaicb53c622007-08-10 17:21:45 +02002669#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002670static const struct hda_amp_list vt1709_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002671 { 0x18, HDA_INPUT, 1 },
2672 { 0x18, HDA_INPUT, 2 },
2673 { 0x18, HDA_INPUT, 3 },
2674 { 0x18, HDA_INPUT, 4 },
2675 { } /* end */
2676};
2677#endif
2678
Joseph Chanc577b8a2006-11-29 15:29:40 +01002679static int patch_vt1709_10ch(struct hda_codec *codec)
2680{
2681 struct via_spec *spec;
2682 int err;
2683
2684 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002685 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002686 if (spec == NULL)
2687 return -ENOMEM;
2688
Joseph Chanc577b8a2006-11-29 15:29:40 +01002689 err = vt1709_parse_auto_config(codec);
2690 if (err < 0) {
2691 via_free(codec);
2692 return err;
2693 } else if (!err) {
2694 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2695 "Using genenic mode...\n");
2696 }
2697
Harald Welte69e52a82008-09-09 15:57:32 +08002698 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2699 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002700
2701 spec->stream_name_analog = "VT1709 Analog";
2702 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2703 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2704
2705 spec->stream_name_digital = "VT1709 Digital";
2706 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2707 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2708
Lydia Wang377ff312009-10-10 19:08:55 +08002709
Joseph Chanc577b8a2006-11-29 15:29:40 +01002710 if (!spec->adc_nids && spec->input_mux) {
2711 spec->adc_nids = vt1709_adc_nids;
2712 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02002713 get_mux_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002714 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2715 spec->num_mixers++;
2716 }
2717
2718 codec->patch_ops = via_patch_ops;
2719
2720 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002721 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002722#ifdef CONFIG_SND_HDA_POWER_SAVE
2723 spec->loopback.amplist = vt1709_loopbacks;
2724#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002725
2726 return 0;
2727}
2728/*
2729 * generic initialization of ADC, input mixers and output mixers
2730 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002731static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002732 /*
2733 * Unmute ADC0-2 and set the default input to mic-in
2734 */
2735 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2736 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2737 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2738
2739
2740 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2741 * mixer widget
2742 */
2743 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2744 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2745 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2746 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2747 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2748 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2749
2750 /*
2751 * Set up output selector (0x1a, 0x1b, 0x29)
2752 */
2753 /* set vol=0 to output mixers */
2754 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2755 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2756 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2757
2758 /*
2759 * Unmute PW3 and PW4
2760 */
2761 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2762 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2763
2764 /* Set input of PW4 as MW0 */
2765 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002766 /* PW9 Output enable */
2767 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2768 { }
2769};
2770
2771static int patch_vt1709_6ch(struct hda_codec *codec)
2772{
2773 struct via_spec *spec;
2774 int err;
2775
2776 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002777 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002778 if (spec == NULL)
2779 return -ENOMEM;
2780
Joseph Chanc577b8a2006-11-29 15:29:40 +01002781 err = vt1709_parse_auto_config(codec);
2782 if (err < 0) {
2783 via_free(codec);
2784 return err;
2785 } else if (!err) {
2786 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2787 "Using genenic mode...\n");
2788 }
2789
Harald Welte69e52a82008-09-09 15:57:32 +08002790 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2791 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002792
2793 spec->stream_name_analog = "VT1709 Analog";
2794 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2795 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2796
2797 spec->stream_name_digital = "VT1709 Digital";
2798 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2799 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2800
Lydia Wang377ff312009-10-10 19:08:55 +08002801
Joseph Chanc577b8a2006-11-29 15:29:40 +01002802 if (!spec->adc_nids && spec->input_mux) {
2803 spec->adc_nids = vt1709_adc_nids;
2804 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02002805 get_mux_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002806 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2807 spec->num_mixers++;
2808 }
2809
2810 codec->patch_ops = via_patch_ops;
2811
2812 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002813 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002814#ifdef CONFIG_SND_HDA_POWER_SAVE
2815 spec->loopback.amplist = vt1709_loopbacks;
2816#endif
Josepch Chanf7278fd2007-12-13 16:40:40 +01002817 return 0;
2818}
2819
2820/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002821static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002822 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2823 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2824 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2825 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2826 {
2827 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2828 /* The multiple "Capture Source" controls confuse alsamixer
2829 * So call somewhat different..
Josepch Chanf7278fd2007-12-13 16:40:40 +01002830 */
2831 /* .name = "Capture Source", */
2832 .name = "Input Source",
2833 .count = 1,
2834 .info = via_mux_enum_info,
2835 .get = via_mux_enum_get,
2836 .put = via_mux_enum_put,
2837 },
2838 { } /* end */
2839};
2840/*
2841 * generic initialization of ADC, input mixers and output mixers
2842 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002843static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002844 /*
2845 * Unmute ADC0-1 and set the default input to mic-in
2846 */
2847 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2848 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2849
2850
2851 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2852 * mixer widget
2853 */
2854 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2855 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2856 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2857 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2858 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2859 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2860
2861 /*
2862 * Set up output mixers
2863 */
2864 /* set vol=0 to output mixers */
2865 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2866 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2867 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2868
2869 /* Setup default input to PW4 */
Lydia Wangbfdc6752009-10-10 19:08:50 +08002870 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
Josepch Chanf7278fd2007-12-13 16:40:40 +01002871 /* PW9 Output enable */
2872 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2873 /* PW10 Input enable */
2874 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2875 { }
2876};
2877
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002878static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002879 /*
2880 * Unmute ADC0-1 and set the default input to mic-in
2881 */
2882 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2883 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2884
2885
2886 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2887 * mixer widget
2888 */
2889 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2890 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2891 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2892 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2893 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2894 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2895
2896 /*
2897 * Set up output mixers
2898 */
2899 /* set vol=0 to output mixers */
2900 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2901 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2902 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2903
2904 /* Setup default input of PW4 to MW0 */
2905 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2906 /* PW9 Output enable */
2907 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2908 /* PW10 Input enable */
2909 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2910 { }
2911};
2912
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002913static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002914 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2915 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2916 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2917 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2918 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2919 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2920 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2921 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2922 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002923 { }
2924};
2925
Lydia Wang17314372009-10-10 19:07:37 +08002926static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2927 struct hda_codec *codec,
2928 struct snd_pcm_substream *substream)
2929{
2930 int idle = substream->pstr->substream_opened == 1
2931 && substream->ref_count == 0;
2932
2933 analog_low_current_mode(codec, idle);
2934 return 0;
2935}
2936
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002937static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002938 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002939 .channels_min = 2,
2940 .channels_max = 8,
2941 .nid = 0x10, /* NID to query formats and rates */
2942 .ops = {
2943 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002944 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08002945 .cleanup = via_playback_multi_pcm_cleanup,
2946 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01002947 },
2948};
2949
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002950static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002951 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002952 .channels_min = 2,
2953 .channels_max = 4,
2954 .nid = 0x10, /* NID to query formats and rates */
2955 .ops = {
2956 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002957 .prepare = via_playback_multi_pcm_prepare,
2958 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002959 },
2960};
2961
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002962static const struct hda_pcm_stream vt1708B_pcm_analog_capture = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002963 .substreams = 2,
2964 .channels_min = 2,
2965 .channels_max = 2,
2966 .nid = 0x13, /* NID to query formats and rates */
2967 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08002968 .open = via_pcm_open_close,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002969 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08002970 .cleanup = via_capture_pcm_cleanup,
2971 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01002972 },
2973};
2974
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002975static const struct hda_pcm_stream vt1708B_pcm_digital_playback = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002976 .substreams = 1,
2977 .channels_min = 2,
2978 .channels_max = 2,
2979 /* NID is set in via_build_pcms */
2980 .ops = {
2981 .open = via_dig_playback_pcm_open,
2982 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02002983 .prepare = via_dig_playback_pcm_prepare,
2984 .cleanup = via_dig_playback_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002985 },
2986};
2987
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002988static const struct hda_pcm_stream vt1708B_pcm_digital_capture = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002989 .substreams = 1,
2990 .channels_min = 2,
2991 .channels_max = 2,
2992};
2993
2994/* fill in the dac_nids table from the parsed pin configuration */
2995static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
2996 const struct auto_pin_cfg *cfg)
2997{
2998 int i;
2999 hda_nid_t nid;
3000
3001 spec->multiout.num_dacs = cfg->line_outs;
3002
3003 spec->multiout.dac_nids = spec->private_dac_nids;
3004
3005 for (i = 0; i < 4; i++) {
3006 nid = cfg->line_out_pins[i];
3007 if (nid) {
3008 /* config dac list */
3009 switch (i) {
3010 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02003011 spec->private_dac_nids[i] = 0x10;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003012 break;
3013 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003014 spec->private_dac_nids[i] = 0x24;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003015 break;
3016 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02003017 spec->private_dac_nids[i] = 0x11;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003018 break;
3019 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003020 spec->private_dac_nids[i] = 0x25;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003021 break;
3022 }
3023 }
3024 }
3025
3026 return 0;
3027}
3028
3029/* add playback controls from the parsed DAC table */
3030static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3031 const struct auto_pin_cfg *cfg)
3032{
3033 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01003034 static const char * const chname[4] = {
3035 "Front", "Surround", "C/LFE", "Side"
3036 };
Harald Weltefb4cb772008-09-09 15:53:36 +08003037 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
Josepch Chanf7278fd2007-12-13 16:40:40 +01003038 hda_nid_t nid, nid_vol = 0;
3039 int i, err;
3040
3041 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3042 nid = cfg->line_out_pins[i];
3043
3044 if (!nid)
3045 continue;
3046
3047 nid_vol = nid_vols[i];
3048
3049 if (i == AUTO_SEQ_CENLFE) {
3050 /* Center/LFE */
3051 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3052 "Center Playback Volume",
3053 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3054 HDA_OUTPUT));
3055 if (err < 0)
3056 return err;
3057 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3058 "LFE Playback Volume",
3059 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3060 HDA_OUTPUT));
3061 if (err < 0)
3062 return err;
3063 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3064 "Center Playback Switch",
3065 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3066 HDA_OUTPUT));
3067 if (err < 0)
3068 return err;
3069 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3070 "LFE Playback Switch",
3071 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3072 HDA_OUTPUT));
3073 if (err < 0)
3074 return err;
3075 } else if (i == AUTO_SEQ_FRONT) {
3076 /* add control to mixer index 0 */
3077 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3078 "Master Front Playback Volume",
3079 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3080 HDA_INPUT));
3081 if (err < 0)
3082 return err;
3083 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3084 "Master Front Playback Switch",
3085 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3086 HDA_INPUT));
3087 if (err < 0)
3088 return err;
3089
3090 /* add control to PW3 */
3091 sprintf(name, "%s Playback Volume", chname[i]);
3092 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3093 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3094 HDA_OUTPUT));
3095 if (err < 0)
3096 return err;
3097 sprintf(name, "%s Playback Switch", chname[i]);
3098 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3099 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3100 HDA_OUTPUT));
3101 if (err < 0)
3102 return err;
3103 } else {
3104 sprintf(name, "%s Playback Volume", chname[i]);
3105 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3106 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3107 HDA_OUTPUT));
3108 if (err < 0)
3109 return err;
3110 sprintf(name, "%s Playback Switch", chname[i]);
3111 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3112 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3113 HDA_OUTPUT));
3114 if (err < 0)
3115 return err;
3116 }
3117 }
3118
3119 return 0;
3120}
3121
3122static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3123{
3124 int err;
3125
3126 if (!pin)
3127 return 0;
3128
3129 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08003130 spec->hp_independent_mode_index = 1;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003131
3132 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3133 "Headphone Playback Volume",
3134 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3135 if (err < 0)
3136 return err;
3137 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3138 "Headphone Playback Switch",
3139 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3140 if (err < 0)
3141 return err;
3142
Harald Welte0aa62ae2008-09-09 15:58:27 +08003143 create_hp_imux(spec);
3144
Josepch Chanf7278fd2007-12-13 16:40:40 +01003145 return 0;
3146}
3147
3148/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003149static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003150 const struct auto_pin_cfg *cfg)
3151{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003152 static const hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
Takashi Iwai10a20af2010-09-09 16:28:02 +02003153 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02003154 ARRAY_SIZE(pin_idxs));
Josepch Chanf7278fd2007-12-13 16:40:40 +01003155}
3156
3157static int vt1708B_parse_auto_config(struct hda_codec *codec)
3158{
3159 struct via_spec *spec = codec->spec;
3160 int err;
3161
3162 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3163 if (err < 0)
3164 return err;
3165 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3166 if (err < 0)
3167 return err;
3168 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3169 return 0; /* can't find valid BIOS pin config */
3170
3171 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3172 if (err < 0)
3173 return err;
3174 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3175 if (err < 0)
3176 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003177 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003178 if (err < 0)
3179 return err;
3180
3181 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3182
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003183 if (spec->autocfg.dig_outs)
Josepch Chanf7278fd2007-12-13 16:40:40 +01003184 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02003185 spec->dig_in_pin = VT1708B_DIGIN_PIN;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003186 if (spec->autocfg.dig_in_pin)
3187 spec->dig_in_nid = VT1708B_DIGIN_NID;
3188
Takashi Iwai603c4012008-07-30 15:01:44 +02003189 if (spec->kctls.list)
3190 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003191
Harald Welte0aa62ae2008-09-09 15:58:27 +08003192 spec->input_mux = &spec->private_imux[0];
3193
Harald Weltef8fdd492008-09-15 22:41:31 +08003194 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003195 via_hp_build(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003196
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003197 via_smart51_build(spec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003198 return 1;
3199}
3200
3201#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003202static const struct hda_amp_list vt1708B_loopbacks[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003203 { 0x16, HDA_INPUT, 1 },
3204 { 0x16, HDA_INPUT, 2 },
3205 { 0x16, HDA_INPUT, 3 },
3206 { 0x16, HDA_INPUT, 4 },
3207 { } /* end */
3208};
3209#endif
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003210
3211static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3212{
3213 struct via_spec *spec = codec->spec;
3214 int imux_is_smixer;
3215 unsigned int parm;
3216 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +08003217 if ((spec->codec_type != VT1708B_4CH) &&
3218 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003219 is_8ch = 1;
3220
3221 /* SW0 (17h) = stereo mixer */
3222 imux_is_smixer =
3223 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3224 == ((spec->codec_type == VT1708S) ? 5 : 0));
3225 /* inputs */
3226 /* PW 1/2/5 (1ah/1bh/1eh) */
3227 parm = AC_PWRST_D3;
3228 set_pin_power_state(codec, 0x1a, &parm);
3229 set_pin_power_state(codec, 0x1b, &parm);
3230 set_pin_power_state(codec, 0x1e, &parm);
3231 if (imux_is_smixer)
3232 parm = AC_PWRST_D0;
3233 /* SW0 (17h), AIW 0/1 (13h/14h) */
3234 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3235 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3236 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3237
3238 /* outputs */
3239 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3240 parm = AC_PWRST_D3;
3241 set_pin_power_state(codec, 0x19, &parm);
3242 if (spec->smart51_enabled)
3243 set_pin_power_state(codec, 0x1b, &parm);
3244 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3245 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3246
3247 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3248 if (is_8ch) {
3249 parm = AC_PWRST_D3;
3250 set_pin_power_state(codec, 0x22, &parm);
3251 if (spec->smart51_enabled)
3252 set_pin_power_state(codec, 0x1a, &parm);
3253 snd_hda_codec_write(codec, 0x26, 0,
3254 AC_VERB_SET_POWER_STATE, parm);
3255 snd_hda_codec_write(codec, 0x24, 0,
3256 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08003257 } else if (codec->vendor_id == 0x11064397) {
3258 /* PW7(23h), SW2(27h), AOW2(25h) */
3259 parm = AC_PWRST_D3;
3260 set_pin_power_state(codec, 0x23, &parm);
3261 if (spec->smart51_enabled)
3262 set_pin_power_state(codec, 0x1a, &parm);
3263 snd_hda_codec_write(codec, 0x27, 0,
3264 AC_VERB_SET_POWER_STATE, parm);
3265 snd_hda_codec_write(codec, 0x25, 0,
3266 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003267 }
3268
3269 /* PW 3/4/7 (1ch/1dh/23h) */
3270 parm = AC_PWRST_D3;
3271 /* force to D0 for internal Speaker */
3272 set_pin_power_state(codec, 0x1c, &parm);
3273 set_pin_power_state(codec, 0x1d, &parm);
3274 if (is_8ch)
3275 set_pin_power_state(codec, 0x23, &parm);
3276
3277 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3278 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3279 imux_is_smixer ? AC_PWRST_D0 : parm);
3280 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3281 if (is_8ch) {
3282 snd_hda_codec_write(codec, 0x25, 0,
3283 AC_VERB_SET_POWER_STATE, parm);
3284 snd_hda_codec_write(codec, 0x27, 0,
3285 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08003286 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3287 snd_hda_codec_write(codec, 0x25, 0,
3288 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003289}
3290
Lydia Wang518bf3b2009-10-10 19:07:29 +08003291static int patch_vt1708S(struct hda_codec *codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003292static int patch_vt1708B_8ch(struct hda_codec *codec)
3293{
3294 struct via_spec *spec;
3295 int err;
3296
Lydia Wang518bf3b2009-10-10 19:07:29 +08003297 if (get_codec_type(codec) == VT1708BCE)
3298 return patch_vt1708S(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003299 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003300 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003301 if (spec == NULL)
3302 return -ENOMEM;
3303
Josepch Chanf7278fd2007-12-13 16:40:40 +01003304 /* automatic parse from the BIOS config */
3305 err = vt1708B_parse_auto_config(codec);
3306 if (err < 0) {
3307 via_free(codec);
3308 return err;
3309 } else if (!err) {
3310 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3311 "from BIOS. Using genenic mode...\n");
3312 }
3313
Harald Welte69e52a82008-09-09 15:57:32 +08003314 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3315 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003316
3317 spec->stream_name_analog = "VT1708B Analog";
3318 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3319 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3320
3321 spec->stream_name_digital = "VT1708B Digital";
3322 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3323 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3324
3325 if (!spec->adc_nids && spec->input_mux) {
3326 spec->adc_nids = vt1708B_adc_nids;
3327 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02003328 get_mux_nids(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003329 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3330 spec->num_mixers++;
3331 }
3332
3333 codec->patch_ops = via_patch_ops;
3334
3335 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003336 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003337#ifdef CONFIG_SND_HDA_POWER_SAVE
3338 spec->loopback.amplist = vt1708B_loopbacks;
3339#endif
3340
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003341 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3342
Josepch Chanf7278fd2007-12-13 16:40:40 +01003343 return 0;
3344}
3345
3346static int patch_vt1708B_4ch(struct hda_codec *codec)
3347{
3348 struct via_spec *spec;
3349 int err;
3350
3351 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003352 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003353 if (spec == NULL)
3354 return -ENOMEM;
3355
Josepch Chanf7278fd2007-12-13 16:40:40 +01003356 /* automatic parse from the BIOS config */
3357 err = vt1708B_parse_auto_config(codec);
3358 if (err < 0) {
3359 via_free(codec);
3360 return err;
3361 } else if (!err) {
3362 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3363 "from BIOS. Using genenic mode...\n");
3364 }
3365
Harald Welte69e52a82008-09-09 15:57:32 +08003366 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3367 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003368
3369 spec->stream_name_analog = "VT1708B Analog";
3370 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3371 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3372
3373 spec->stream_name_digital = "VT1708B Digital";
3374 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3375 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3376
3377 if (!spec->adc_nids && spec->input_mux) {
3378 spec->adc_nids = vt1708B_adc_nids;
3379 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02003380 get_mux_nids(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003381 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3382 spec->num_mixers++;
3383 }
3384
3385 codec->patch_ops = via_patch_ops;
3386
3387 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003388 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003389#ifdef CONFIG_SND_HDA_POWER_SAVE
3390 spec->loopback.amplist = vt1708B_loopbacks;
3391#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01003392
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003393 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3394
Joseph Chanc577b8a2006-11-29 15:29:40 +01003395 return 0;
3396}
3397
Harald Welted949cac2008-09-09 15:56:01 +08003398/* Patch for VT1708S */
3399
3400/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003401static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003402 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3403 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3404 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3405 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
Lydia Wang6369bcf2009-10-10 19:08:31 +08003406 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3407 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3408 HDA_INPUT),
Harald Welted949cac2008-09-09 15:56:01 +08003409 {
3410 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3411 /* The multiple "Capture Source" controls confuse alsamixer
3412 * So call somewhat different..
3413 */
3414 /* .name = "Capture Source", */
3415 .name = "Input Source",
3416 .count = 1,
3417 .info = via_mux_enum_info,
3418 .get = via_mux_enum_get,
3419 .put = via_mux_enum_put,
3420 },
3421 { } /* end */
3422};
3423
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003424static const struct hda_verb vt1708S_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003425 /* Unmute ADC0-1 and set the default input to mic-in */
3426 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3427 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3428
3429 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3430 * analog-loopback mixer widget */
3431 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3432 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3433 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3434 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3435 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3436 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3437
3438 /* Setup default input of PW4 to MW0 */
3439 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
Harald Welte5691ec72008-09-15 22:42:26 +08003440 /* PW9, PW10 Output enable */
Harald Welted949cac2008-09-09 15:56:01 +08003441 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welte5691ec72008-09-15 22:42:26 +08003442 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welted7426322008-09-15 22:43:23 +08003443 /* Enable Mic Boost Volume backdoor */
3444 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003445 /* don't bybass mixer */
3446 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08003447 { }
3448};
3449
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003450static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003451 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3452 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3453 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3454 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3455 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3456 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3457 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3458 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3459 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003460 { }
3461};
3462
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003463static const struct hda_verb vt1705_uniwill_init_verbs[] = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003464 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3465 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3466 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3467 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3468 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3469 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3470 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3471 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3472 { }
3473};
3474
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003475static const struct hda_pcm_stream vt1708S_pcm_analog_playback = {
Harald Welted949cac2008-09-09 15:56:01 +08003476 .substreams = 2,
3477 .channels_min = 2,
3478 .channels_max = 8,
3479 .nid = 0x10, /* NID to query formats and rates */
3480 .ops = {
3481 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08003482 .prepare = via_playback_multi_pcm_prepare,
3483 .cleanup = via_playback_multi_pcm_cleanup,
Lydia Wang17314372009-10-10 19:07:37 +08003484 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003485 },
3486};
3487
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003488static const struct hda_pcm_stream vt1705_pcm_analog_playback = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003489 .substreams = 2,
3490 .channels_min = 2,
3491 .channels_max = 6,
3492 .nid = 0x10, /* NID to query formats and rates */
3493 .ops = {
3494 .open = via_playback_pcm_open,
3495 .prepare = via_playback_multi_pcm_prepare,
3496 .cleanup = via_playback_multi_pcm_cleanup,
3497 .close = via_pcm_open_close
3498 },
3499};
3500
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003501static const struct hda_pcm_stream vt1708S_pcm_analog_capture = {
Harald Welted949cac2008-09-09 15:56:01 +08003502 .substreams = 2,
3503 .channels_min = 2,
3504 .channels_max = 2,
3505 .nid = 0x13, /* NID to query formats and rates */
3506 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003507 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08003508 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003509 .cleanup = via_capture_pcm_cleanup,
3510 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003511 },
3512};
3513
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003514static const struct hda_pcm_stream vt1708S_pcm_digital_playback = {
Takashi Iwai9da29272009-05-07 16:31:14 +02003515 .substreams = 1,
Harald Welted949cac2008-09-09 15:56:01 +08003516 .channels_min = 2,
3517 .channels_max = 2,
3518 /* NID is set in via_build_pcms */
3519 .ops = {
3520 .open = via_dig_playback_pcm_open,
3521 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003522 .prepare = via_dig_playback_pcm_prepare,
3523 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08003524 },
3525};
3526
3527/* fill in the dac_nids table from the parsed pin configuration */
3528static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3529 const struct auto_pin_cfg *cfg)
3530{
3531 int i;
3532 hda_nid_t nid;
3533
3534 spec->multiout.num_dacs = cfg->line_outs;
3535
3536 spec->multiout.dac_nids = spec->private_dac_nids;
3537
3538 for (i = 0; i < 4; i++) {
3539 nid = cfg->line_out_pins[i];
3540 if (nid) {
3541 /* config dac list */
3542 switch (i) {
3543 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02003544 spec->private_dac_nids[i] = 0x10;
Harald Welted949cac2008-09-09 15:56:01 +08003545 break;
3546 case AUTO_SEQ_CENLFE:
Lydia Wangbc92df72011-03-23 17:56:05 +08003547 if (spec->codec->vendor_id == 0x11064397)
Takashi Iwaidda14412011-05-02 11:29:30 +02003548 spec->private_dac_nids[i] = 0x25;
Lydia Wangbc92df72011-03-23 17:56:05 +08003549 else
Takashi Iwaidda14412011-05-02 11:29:30 +02003550 spec->private_dac_nids[i] = 0x24;
Harald Welted949cac2008-09-09 15:56:01 +08003551 break;
3552 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02003553 spec->private_dac_nids[i] = 0x11;
Harald Welted949cac2008-09-09 15:56:01 +08003554 break;
3555 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003556 spec->private_dac_nids[i] = 0x25;
Harald Welted949cac2008-09-09 15:56:01 +08003557 break;
3558 }
3559 }
3560 }
3561
Clemens Ladisch32e01912010-07-12 16:28:50 +02003562 /* for Smart 5.1, line/mic inputs double as output pins */
3563 if (cfg->line_outs == 1) {
3564 spec->multiout.num_dacs = 3;
Takashi Iwaidda14412011-05-02 11:29:30 +02003565 spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11;
Lydia Wangbc92df72011-03-23 17:56:05 +08003566 if (spec->codec->vendor_id == 0x11064397)
Takashi Iwaidda14412011-05-02 11:29:30 +02003567 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25;
Lydia Wangbc92df72011-03-23 17:56:05 +08003568 else
Takashi Iwaidda14412011-05-02 11:29:30 +02003569 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24;
Clemens Ladisch32e01912010-07-12 16:28:50 +02003570 }
3571
Harald Welted949cac2008-09-09 15:56:01 +08003572 return 0;
3573}
3574
3575/* add playback controls from the parsed DAC table */
Lydia Wangbc92df72011-03-23 17:56:05 +08003576static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08003577 const struct auto_pin_cfg *cfg)
3578{
Lydia Wangbc92df72011-03-23 17:56:05 +08003579 struct via_spec *spec = codec->spec;
Harald Welted949cac2008-09-09 15:56:01 +08003580 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01003581 static const char * const chname[4] = {
3582 "Front", "Surround", "C/LFE", "Side"
3583 };
Lydia Wangbc92df72011-03-23 17:56:05 +08003584 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3585 {0x10, 0x11, 0x25, 0} };
3586 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3587 {0x1C, 0x18, 0x27, 0} };
Harald Welted949cac2008-09-09 15:56:01 +08003588 hda_nid_t nid, nid_vol, nid_mute;
3589 int i, err;
3590
3591 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3592 nid = cfg->line_out_pins[i];
3593
Clemens Ladisch32e01912010-07-12 16:28:50 +02003594 /* for Smart 5.1, there are always at least six channels */
3595 if (!nid && i > AUTO_SEQ_CENLFE)
Harald Welted949cac2008-09-09 15:56:01 +08003596 continue;
3597
Lydia Wangbc92df72011-03-23 17:56:05 +08003598 if (codec->vendor_id == 0x11064397) {
3599 nid_vol = nid_vols[1][i];
3600 nid_mute = nid_mutes[1][i];
3601 } else {
3602 nid_vol = nid_vols[0][i];
3603 nid_mute = nid_mutes[0][i];
3604 }
3605 if (!nid_vol && !nid_mute)
3606 continue;
Harald Welted949cac2008-09-09 15:56:01 +08003607
3608 if (i == AUTO_SEQ_CENLFE) {
3609 /* Center/LFE */
3610 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3611 "Center Playback Volume",
3612 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3613 HDA_OUTPUT));
3614 if (err < 0)
3615 return err;
3616 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3617 "LFE Playback Volume",
3618 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3619 HDA_OUTPUT));
3620 if (err < 0)
3621 return err;
3622 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3623 "Center Playback Switch",
3624 HDA_COMPOSE_AMP_VAL(nid_mute,
3625 1, 0,
3626 HDA_OUTPUT));
3627 if (err < 0)
3628 return err;
3629 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3630 "LFE Playback Switch",
3631 HDA_COMPOSE_AMP_VAL(nid_mute,
3632 2, 0,
3633 HDA_OUTPUT));
3634 if (err < 0)
3635 return err;
3636 } else if (i == AUTO_SEQ_FRONT) {
3637 /* add control to mixer index 0 */
3638 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3639 "Master Front Playback Volume",
3640 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3641 HDA_INPUT));
3642 if (err < 0)
3643 return err;
3644 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3645 "Master Front Playback Switch",
3646 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3647 HDA_INPUT));
3648 if (err < 0)
3649 return err;
3650
3651 /* Front */
3652 sprintf(name, "%s Playback Volume", chname[i]);
3653 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3654 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3655 HDA_OUTPUT));
3656 if (err < 0)
3657 return err;
3658 sprintf(name, "%s Playback Switch", chname[i]);
3659 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3660 HDA_COMPOSE_AMP_VAL(nid_mute,
3661 3, 0,
3662 HDA_OUTPUT));
3663 if (err < 0)
3664 return err;
3665 } else {
3666 sprintf(name, "%s Playback Volume", chname[i]);
3667 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3668 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3669 HDA_OUTPUT));
3670 if (err < 0)
3671 return err;
3672 sprintf(name, "%s Playback Switch", chname[i]);
3673 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3674 HDA_COMPOSE_AMP_VAL(nid_mute,
3675 3, 0,
3676 HDA_OUTPUT));
3677 if (err < 0)
3678 return err;
3679 }
3680 }
3681
3682 return 0;
3683}
3684
3685static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3686{
3687 int err;
3688
3689 if (!pin)
3690 return 0;
3691
3692 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08003693 spec->hp_independent_mode_index = 1;
Harald Welted949cac2008-09-09 15:56:01 +08003694
3695 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3696 "Headphone Playback Volume",
3697 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3698 if (err < 0)
3699 return err;
3700
3701 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3702 "Headphone Playback Switch",
3703 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3704 if (err < 0)
3705 return err;
3706
Harald Welte0aa62ae2008-09-09 15:58:27 +08003707 create_hp_imux(spec);
3708
Harald Welted949cac2008-09-09 15:56:01 +08003709 return 0;
3710}
3711
3712/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003713static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08003714 const struct auto_pin_cfg *cfg)
3715{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003716 static const hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
Takashi Iwai10a20af2010-09-09 16:28:02 +02003717 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02003718 ARRAY_SIZE(pin_idxs));
Harald Welted949cac2008-09-09 15:56:01 +08003719}
3720
Takashi Iwai9da29272009-05-07 16:31:14 +02003721/* fill out digital output widgets; one for master and one for slave outputs */
3722static void fill_dig_outs(struct hda_codec *codec)
3723{
3724 struct via_spec *spec = codec->spec;
3725 int i;
3726
3727 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3728 hda_nid_t nid;
3729 int conn;
3730
3731 nid = spec->autocfg.dig_out_pins[i];
3732 if (!nid)
3733 continue;
3734 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3735 if (conn < 1)
3736 continue;
3737 if (!spec->multiout.dig_out_nid)
3738 spec->multiout.dig_out_nid = nid;
3739 else {
3740 spec->slave_dig_outs[0] = nid;
3741 break; /* at most two dig outs */
3742 }
3743 }
3744}
3745
Harald Welted949cac2008-09-09 15:56:01 +08003746static int vt1708S_parse_auto_config(struct hda_codec *codec)
3747{
3748 struct via_spec *spec = codec->spec;
3749 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003750
Takashi Iwai9da29272009-05-07 16:31:14 +02003751 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08003752 if (err < 0)
3753 return err;
3754 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3755 if (err < 0)
3756 return err;
3757 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3758 return 0; /* can't find valid BIOS pin config */
3759
Lydia Wangbc92df72011-03-23 17:56:05 +08003760 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003761 if (err < 0)
3762 return err;
3763 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3764 if (err < 0)
3765 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003766 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003767 if (err < 0)
3768 return err;
3769
3770 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3771
Takashi Iwai9da29272009-05-07 16:31:14 +02003772 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08003773
Takashi Iwai603c4012008-07-30 15:01:44 +02003774 if (spec->kctls.list)
3775 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08003776
Harald Welte0aa62ae2008-09-09 15:58:27 +08003777 spec->input_mux = &spec->private_imux[0];
3778
Harald Weltef8fdd492008-09-15 22:41:31 +08003779 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003780 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003781
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003782 via_smart51_build(spec);
Harald Welted949cac2008-09-09 15:56:01 +08003783 return 1;
3784}
3785
3786#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003787static const struct hda_amp_list vt1708S_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003788 { 0x16, HDA_INPUT, 1 },
3789 { 0x16, HDA_INPUT, 2 },
3790 { 0x16, HDA_INPUT, 3 },
3791 { 0x16, HDA_INPUT, 4 },
3792 { } /* end */
3793};
3794#endif
3795
Lydia Wang6369bcf2009-10-10 19:08:31 +08003796static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3797 int offset, int num_steps, int step_size)
3798{
3799 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3800 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3801 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3802 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3803 (0 << AC_AMPCAP_MUTE_SHIFT));
3804}
3805
Harald Welted949cac2008-09-09 15:56:01 +08003806static int patch_vt1708S(struct hda_codec *codec)
3807{
3808 struct via_spec *spec;
3809 int err;
3810
3811 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003812 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003813 if (spec == NULL)
3814 return -ENOMEM;
3815
Harald Welted949cac2008-09-09 15:56:01 +08003816 /* automatic parse from the BIOS config */
3817 err = vt1708S_parse_auto_config(codec);
3818 if (err < 0) {
3819 via_free(codec);
3820 return err;
3821 } else if (!err) {
3822 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3823 "from BIOS. Using genenic mode...\n");
3824 }
3825
Harald Welte69e52a82008-09-09 15:57:32 +08003826 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
Lydia Wangbc92df72011-03-23 17:56:05 +08003827 if (codec->vendor_id == 0x11064397)
3828 spec->init_verbs[spec->num_iverbs++] =
3829 vt1705_uniwill_init_verbs;
3830 else
3831 spec->init_verbs[spec->num_iverbs++] =
3832 vt1708S_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003833
Lydia Wang36dd5c42009-10-20 13:18:04 +08003834 if (codec->vendor_id == 0x11060440)
3835 spec->stream_name_analog = "VT1818S Analog";
Lydia Wangbc92df72011-03-23 17:56:05 +08003836 else if (codec->vendor_id == 0x11064397)
3837 spec->stream_name_analog = "VT1705 Analog";
Lydia Wang36dd5c42009-10-20 13:18:04 +08003838 else
3839 spec->stream_name_analog = "VT1708S Analog";
Lydia Wangbc92df72011-03-23 17:56:05 +08003840 if (codec->vendor_id == 0x11064397)
3841 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3842 else
3843 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
Harald Welted949cac2008-09-09 15:56:01 +08003844 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3845
Lydia Wang36dd5c42009-10-20 13:18:04 +08003846 if (codec->vendor_id == 0x11060440)
3847 spec->stream_name_digital = "VT1818S Digital";
Lydia Wangbc92df72011-03-23 17:56:05 +08003848 else if (codec->vendor_id == 0x11064397)
3849 spec->stream_name_digital = "VT1705 Digital";
Lydia Wang36dd5c42009-10-20 13:18:04 +08003850 else
3851 spec->stream_name_digital = "VT1708S Digital";
Harald Welted949cac2008-09-09 15:56:01 +08003852 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3853
3854 if (!spec->adc_nids && spec->input_mux) {
3855 spec->adc_nids = vt1708S_adc_nids;
3856 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02003857 get_mux_nids(codec);
Lydia Wang6369bcf2009-10-10 19:08:31 +08003858 override_mic_boost(codec, 0x1a, 0, 3, 40);
3859 override_mic_boost(codec, 0x1e, 0, 3, 40);
Harald Welted949cac2008-09-09 15:56:01 +08003860 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3861 spec->num_mixers++;
3862 }
3863
3864 codec->patch_ops = via_patch_ops;
3865
3866 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003867 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08003868#ifdef CONFIG_SND_HDA_POWER_SAVE
3869 spec->loopback.amplist = vt1708S_loopbacks;
3870#endif
3871
Lydia Wang518bf3b2009-10-10 19:07:29 +08003872 /* correct names for VT1708BCE */
3873 if (get_codec_type(codec) == VT1708BCE) {
3874 kfree(codec->chip_name);
3875 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3876 snprintf(codec->bus->card->mixername,
3877 sizeof(codec->bus->card->mixername),
3878 "%s %s", codec->vendor_name, codec->chip_name);
3879 spec->stream_name_analog = "VT1708BCE Analog";
3880 spec->stream_name_digital = "VT1708BCE Digital";
3881 }
Lydia Wang970f630f2011-03-22 16:25:56 +08003882 /* correct names for VT1818S */
3883 if (codec->vendor_id == 0x11060440) {
3884 spec->stream_name_analog = "VT1818S Analog";
3885 spec->stream_name_digital = "VT1818S Digital";
3886 }
Lydia Wangbc92df72011-03-23 17:56:05 +08003887 /* correct names for VT1705 */
3888 if (codec->vendor_id == 0x11064397) {
3889 kfree(codec->chip_name);
3890 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3891 snprintf(codec->bus->card->mixername,
3892 sizeof(codec->bus->card->mixername),
3893 "%s %s", codec->vendor_name, codec->chip_name);
3894 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003895 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +08003896 return 0;
3897}
3898
3899/* Patch for VT1702 */
3900
3901/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003902static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003903 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3904 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3905 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3906 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3907 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3908 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3909 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3910 HDA_INPUT),
3911 {
3912 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3913 /* The multiple "Capture Source" controls confuse alsamixer
3914 * So call somewhat different..
3915 */
3916 /* .name = "Capture Source", */
3917 .name = "Input Source",
3918 .count = 1,
3919 .info = via_mux_enum_info,
3920 .get = via_mux_enum_get,
3921 .put = via_mux_enum_put,
3922 },
3923 { } /* end */
3924};
3925
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003926static const struct hda_verb vt1702_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003927 /*
3928 * Unmute ADC0-1 and set the default input to mic-in
3929 */
3930 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3931 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3932 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3933
3934
3935 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3936 * mixer widget
3937 */
3938 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3939 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3940 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3941 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3942 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3943 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3944
3945 /* Setup default input of PW4 to MW0 */
3946 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3947 /* PW6 PW7 Output enable */
3948 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3949 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003950 /* mixer enable */
3951 {0x1, 0xF88, 0x3},
3952 /* GPIO 0~2 */
3953 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08003954 { }
3955};
3956
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003957static const struct hda_verb vt1702_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003958 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3959 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3960 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3961 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3962 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3963 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003964 { }
3965};
3966
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003967static const struct hda_pcm_stream vt1702_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08003968 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08003969 .channels_min = 2,
3970 .channels_max = 2,
3971 .nid = 0x10, /* NID to query formats and rates */
3972 .ops = {
3973 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08003974 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003975 .cleanup = via_playback_multi_pcm_cleanup,
3976 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003977 },
3978};
3979
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003980static const struct hda_pcm_stream vt1702_pcm_analog_capture = {
Harald Welted949cac2008-09-09 15:56:01 +08003981 .substreams = 3,
3982 .channels_min = 2,
3983 .channels_max = 2,
3984 .nid = 0x12, /* NID to query formats and rates */
3985 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003986 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08003987 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003988 .cleanup = via_capture_pcm_cleanup,
3989 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003990 },
3991};
3992
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003993static const struct hda_pcm_stream vt1702_pcm_digital_playback = {
Harald Welte5691ec72008-09-15 22:42:26 +08003994 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08003995 .channels_min = 2,
3996 .channels_max = 2,
3997 /* NID is set in via_build_pcms */
3998 .ops = {
3999 .open = via_dig_playback_pcm_open,
4000 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02004001 .prepare = via_dig_playback_pcm_prepare,
4002 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08004003 },
4004};
4005
4006/* fill in the dac_nids table from the parsed pin configuration */
4007static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4008 const struct auto_pin_cfg *cfg)
4009{
4010 spec->multiout.num_dacs = 1;
4011 spec->multiout.dac_nids = spec->private_dac_nids;
4012
4013 if (cfg->line_out_pins[0]) {
4014 /* config dac list */
Takashi Iwaidda14412011-05-02 11:29:30 +02004015 spec->private_dac_nids[0] = 0x10;
Harald Welted949cac2008-09-09 15:56:01 +08004016 }
4017
4018 return 0;
4019}
4020
4021/* add playback controls from the parsed DAC table */
4022static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4023 const struct auto_pin_cfg *cfg)
4024{
4025 int err;
4026
4027 if (!cfg->line_out_pins[0])
4028 return -1;
4029
4030 /* add control to mixer index 0 */
4031 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4032 "Master Front Playback Volume",
4033 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4034 if (err < 0)
4035 return err;
4036 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4037 "Master Front Playback Switch",
4038 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4039 if (err < 0)
4040 return err;
4041
4042 /* Front */
4043 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4044 "Front Playback Volume",
4045 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4046 if (err < 0)
4047 return err;
4048 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4049 "Front Playback Switch",
4050 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4051 if (err < 0)
4052 return err;
4053
4054 return 0;
4055}
4056
4057static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4058{
Lydia Wang0713efe2009-10-10 19:07:43 +08004059 int err, i;
4060 struct hda_input_mux *imux;
Takashi Iwaiea734962011-01-17 11:29:34 +01004061 static const char * const texts[] = { "ON", "OFF", NULL};
Harald Welted949cac2008-09-09 15:56:01 +08004062 if (!pin)
4063 return 0;
Harald Welted949cac2008-09-09 15:56:01 +08004064 spec->multiout.hp_nid = 0x1D;
Lydia Wangcdc17842009-10-10 19:07:47 +08004065 spec->hp_independent_mode_index = 0;
Harald Welted949cac2008-09-09 15:56:01 +08004066
4067 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4068 "Headphone Playback Volume",
4069 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4070 if (err < 0)
4071 return err;
4072
4073 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4074 "Headphone Playback Switch",
4075 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4076 if (err < 0)
4077 return err;
4078
Lydia Wang0713efe2009-10-10 19:07:43 +08004079 imux = &spec->private_imux[1];
Harald Welte0aa62ae2008-09-09 15:58:27 +08004080
Lydia Wang0713efe2009-10-10 19:07:43 +08004081 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004082 for (i = 0; texts[i]; i++)
4083 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Lydia Wang0713efe2009-10-10 19:07:43 +08004084
4085 spec->hp_mux = &spec->private_imux[1];
Harald Welted949cac2008-09-09 15:56:01 +08004086 return 0;
4087}
4088
4089/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004090static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08004091 const struct auto_pin_cfg *cfg)
4092{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004093 static const hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
Takashi Iwai10a20af2010-09-09 16:28:02 +02004094 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02004095 ARRAY_SIZE(pin_idxs));
Harald Welted949cac2008-09-09 15:56:01 +08004096}
4097
4098static int vt1702_parse_auto_config(struct hda_codec *codec)
4099{
4100 struct via_spec *spec = codec->spec;
4101 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004102
Takashi Iwai9da29272009-05-07 16:31:14 +02004103 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08004104 if (err < 0)
4105 return err;
4106 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4107 if (err < 0)
4108 return err;
4109 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4110 return 0; /* can't find valid BIOS pin config */
4111
4112 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4113 if (err < 0)
4114 return err;
4115 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4116 if (err < 0)
4117 return err;
Lydia Wangc2c02ea2009-10-10 19:07:32 +08004118 /* limit AA path volume to 0 dB */
4119 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4120 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4121 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4122 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4123 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai10a20af2010-09-09 16:28:02 +02004124 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08004125 if (err < 0)
4126 return err;
4127
4128 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4129
Takashi Iwai9da29272009-05-07 16:31:14 +02004130 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08004131
Takashi Iwai603c4012008-07-30 15:01:44 +02004132 if (spec->kctls.list)
4133 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08004134
Harald Welte0aa62ae2008-09-09 15:58:27 +08004135 spec->input_mux = &spec->private_imux[0];
4136
Harald Weltef8fdd492008-09-15 22:41:31 +08004137 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004138 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004139
4140 return 1;
4141}
4142
4143#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004144static const struct hda_amp_list vt1702_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08004145 { 0x1A, HDA_INPUT, 1 },
4146 { 0x1A, HDA_INPUT, 2 },
4147 { 0x1A, HDA_INPUT, 3 },
4148 { 0x1A, HDA_INPUT, 4 },
4149 { } /* end */
4150};
4151#endif
4152
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004153static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4154{
4155 int imux_is_smixer =
4156 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4157 unsigned int parm;
4158 /* inputs */
4159 /* PW 1/2/5 (14h/15h/18h) */
4160 parm = AC_PWRST_D3;
4161 set_pin_power_state(codec, 0x14, &parm);
4162 set_pin_power_state(codec, 0x15, &parm);
4163 set_pin_power_state(codec, 0x18, &parm);
4164 if (imux_is_smixer)
4165 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4166 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4167 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4168 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4169 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4170 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4171
4172 /* outputs */
4173 /* PW 3/4 (16h/17h) */
4174 parm = AC_PWRST_D3;
4175 set_pin_power_state(codec, 0x17, &parm);
4176 set_pin_power_state(codec, 0x16, &parm);
4177 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4178 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4179 imux_is_smixer ? AC_PWRST_D0 : parm);
4180 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4181 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4182}
4183
Harald Welted949cac2008-09-09 15:56:01 +08004184static int patch_vt1702(struct hda_codec *codec)
4185{
4186 struct via_spec *spec;
4187 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004188
4189 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004190 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004191 if (spec == NULL)
4192 return -ENOMEM;
4193
Harald Welted949cac2008-09-09 15:56:01 +08004194 /* automatic parse from the BIOS config */
4195 err = vt1702_parse_auto_config(codec);
4196 if (err < 0) {
4197 via_free(codec);
4198 return err;
4199 } else if (!err) {
4200 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4201 "from BIOS. Using genenic mode...\n");
4202 }
4203
Harald Welte69e52a82008-09-09 15:57:32 +08004204 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4205 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08004206
4207 spec->stream_name_analog = "VT1702 Analog";
4208 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4209 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4210
4211 spec->stream_name_digital = "VT1702 Digital";
4212 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4213
4214 if (!spec->adc_nids && spec->input_mux) {
4215 spec->adc_nids = vt1702_adc_nids;
4216 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02004217 get_mux_nids(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004218 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4219 spec->num_mixers++;
4220 }
4221
4222 codec->patch_ops = via_patch_ops;
4223
4224 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08004225 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08004226#ifdef CONFIG_SND_HDA_POWER_SAVE
4227 spec->loopback.amplist = vt1702_loopbacks;
4228#endif
4229
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004230 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08004231 return 0;
4232}
4233
Lydia Wangeb7188c2009-10-10 19:08:34 +08004234/* Patch for VT1718S */
4235
4236/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004237static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004238 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4239 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4240 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4241 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4242 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4243 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4244 HDA_INPUT),
4245 {
4246 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4247 /* The multiple "Capture Source" controls confuse alsamixer
4248 * So call somewhat different..
4249 */
4250 .name = "Input Source",
4251 .count = 2,
4252 .info = via_mux_enum_info,
4253 .get = via_mux_enum_get,
4254 .put = via_mux_enum_put,
4255 },
4256 { } /* end */
4257};
4258
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004259static const struct hda_verb vt1718S_volume_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004260 /*
4261 * Unmute ADC0-1 and set the default input to mic-in
4262 */
4263 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4264 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4265
Lydia Wang4ab2d532011-03-24 12:42:03 +08004266 /* Enable MW0 adjust Gain 5 */
4267 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08004268 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4269 * mixer widget
4270 */
4271 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4272 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4273 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4274 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4275 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
Lydia Wang4ab2d532011-03-24 12:42:03 +08004276 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
Lydia Wangeb7188c2009-10-10 19:08:34 +08004277
4278 /* Setup default input of Front HP to MW9 */
4279 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4280 /* PW9 PW10 Output enable */
4281 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4282 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4283 /* PW11 Input enable */
4284 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4285 /* Enable Boost Volume backdoor */
4286 {0x1, 0xf88, 0x8},
4287 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4288 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4289 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4290 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4291 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4292 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4293 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4294 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4295 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4296 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4297 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4298 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4299 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4300 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4301 /* Unmute MW4's index 0 */
4302 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4303 { }
4304};
4305
4306
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004307static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004308 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4309 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4310 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4311 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4312 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4313 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4314 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4315 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4316 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4317 { }
4318};
4319
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004320static const struct hda_pcm_stream vt1718S_pcm_analog_playback = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004321 .substreams = 2,
4322 .channels_min = 2,
4323 .channels_max = 10,
4324 .nid = 0x8, /* NID to query formats and rates */
4325 .ops = {
4326 .open = via_playback_pcm_open,
4327 .prepare = via_playback_multi_pcm_prepare,
4328 .cleanup = via_playback_multi_pcm_cleanup,
4329 .close = via_pcm_open_close,
4330 },
4331};
4332
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004333static const struct hda_pcm_stream vt1718S_pcm_analog_capture = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004334 .substreams = 2,
4335 .channels_min = 2,
4336 .channels_max = 2,
4337 .nid = 0x10, /* NID to query formats and rates */
4338 .ops = {
4339 .open = via_pcm_open_close,
4340 .prepare = via_capture_pcm_prepare,
4341 .cleanup = via_capture_pcm_cleanup,
4342 .close = via_pcm_open_close,
4343 },
4344};
4345
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004346static const struct hda_pcm_stream vt1718S_pcm_digital_playback = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004347 .substreams = 2,
4348 .channels_min = 2,
4349 .channels_max = 2,
Lydia Wangeb7188c2009-10-10 19:08:34 +08004350 /* NID is set in via_build_pcms */
4351 .ops = {
4352 .open = via_dig_playback_pcm_open,
4353 .close = via_dig_playback_pcm_close,
4354 .prepare = via_dig_playback_pcm_prepare,
4355 .cleanup = via_dig_playback_pcm_cleanup
4356 },
4357};
4358
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004359static const struct hda_pcm_stream vt1718S_pcm_digital_capture = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004360 .substreams = 1,
4361 .channels_min = 2,
4362 .channels_max = 2,
4363};
4364
4365/* fill in the dac_nids table from the parsed pin configuration */
4366static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4367 const struct auto_pin_cfg *cfg)
4368{
4369 int i;
4370 hda_nid_t nid;
4371
4372 spec->multiout.num_dacs = cfg->line_outs;
4373
4374 spec->multiout.dac_nids = spec->private_dac_nids;
4375
4376 for (i = 0; i < 4; i++) {
4377 nid = cfg->line_out_pins[i];
4378 if (nid) {
4379 /* config dac list */
4380 switch (i) {
4381 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02004382 spec->private_dac_nids[i] = 0x8;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004383 break;
4384 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004385 spec->private_dac_nids[i] = 0xa;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004386 break;
4387 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02004388 spec->private_dac_nids[i] = 0x9;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004389 break;
4390 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004391 spec->private_dac_nids[i] = 0xb;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004392 break;
4393 }
4394 }
4395 }
4396
4397 return 0;
4398}
4399
4400/* add playback controls from the parsed DAC table */
4401static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4402 const struct auto_pin_cfg *cfg)
4403{
4404 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01004405 static const char * const chname[4] = {
4406 "Front", "Surround", "C/LFE", "Side"
4407 };
Lydia Wangeb7188c2009-10-10 19:08:34 +08004408 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4409 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4410 hda_nid_t nid, nid_vol, nid_mute = 0;
4411 int i, err;
4412
4413 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4414 nid = cfg->line_out_pins[i];
4415
4416 if (!nid)
4417 continue;
4418 nid_vol = nid_vols[i];
4419 nid_mute = nid_mutes[i];
4420
4421 if (i == AUTO_SEQ_CENLFE) {
4422 /* Center/LFE */
4423 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4424 "Center Playback Volume",
4425 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4426 HDA_OUTPUT));
4427 if (err < 0)
4428 return err;
4429 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4430 "LFE Playback Volume",
4431 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4432 HDA_OUTPUT));
4433 if (err < 0)
4434 return err;
4435 err = via_add_control(
4436 spec, VIA_CTL_WIDGET_MUTE,
4437 "Center Playback Switch",
4438 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4439 HDA_OUTPUT));
4440 if (err < 0)
4441 return err;
4442 err = via_add_control(
4443 spec, VIA_CTL_WIDGET_MUTE,
4444 "LFE Playback Switch",
4445 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4446 HDA_OUTPUT));
4447 if (err < 0)
4448 return err;
4449 } else if (i == AUTO_SEQ_FRONT) {
4450 /* Front */
4451 sprintf(name, "%s Playback Volume", chname[i]);
4452 err = via_add_control(
4453 spec, VIA_CTL_WIDGET_VOL, name,
4454 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4455 if (err < 0)
4456 return err;
4457 sprintf(name, "%s Playback Switch", chname[i]);
4458 err = via_add_control(
4459 spec, VIA_CTL_WIDGET_MUTE, name,
4460 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4461 HDA_OUTPUT));
4462 if (err < 0)
4463 return err;
4464 } else {
4465 sprintf(name, "%s Playback Volume", chname[i]);
4466 err = via_add_control(
4467 spec, VIA_CTL_WIDGET_VOL, name,
4468 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4469 if (err < 0)
4470 return err;
4471 sprintf(name, "%s Playback Switch", chname[i]);
4472 err = via_add_control(
4473 spec, VIA_CTL_WIDGET_MUTE, name,
4474 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4475 HDA_OUTPUT));
4476 if (err < 0)
4477 return err;
4478 }
4479 }
4480 return 0;
4481}
4482
4483static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4484{
4485 int err;
4486
4487 if (!pin)
4488 return 0;
4489
4490 spec->multiout.hp_nid = 0xc; /* AOW4 */
4491 spec->hp_independent_mode_index = 1;
4492
4493 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4494 "Headphone Playback Volume",
4495 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4496 if (err < 0)
4497 return err;
4498
4499 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4500 "Headphone Playback Switch",
4501 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4502 if (err < 0)
4503 return err;
4504
4505 create_hp_imux(spec);
4506 return 0;
4507}
4508
4509/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004510static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangeb7188c2009-10-10 19:08:34 +08004511 const struct auto_pin_cfg *cfg)
4512{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004513 static const hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
Takashi Iwai10a20af2010-09-09 16:28:02 +02004514 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02004515 ARRAY_SIZE(pin_idxs));
Lydia Wangeb7188c2009-10-10 19:08:34 +08004516}
4517
4518static int vt1718S_parse_auto_config(struct hda_codec *codec)
4519{
4520 struct via_spec *spec = codec->spec;
4521 int err;
4522
4523 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4524
4525 if (err < 0)
4526 return err;
4527 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4528 if (err < 0)
4529 return err;
4530 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4531 return 0; /* can't find valid BIOS pin config */
4532
4533 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4534 if (err < 0)
4535 return err;
4536 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4537 if (err < 0)
4538 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02004539 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004540 if (err < 0)
4541 return err;
4542
4543 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4544
4545 fill_dig_outs(codec);
4546
4547 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4548 spec->dig_in_nid = 0x13;
4549
4550 if (spec->kctls.list)
4551 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4552
4553 spec->input_mux = &spec->private_imux[0];
4554
4555 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004556 via_hp_build(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004557
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004558 via_smart51_build(spec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004559
4560 return 1;
4561}
4562
4563#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004564static const struct hda_amp_list vt1718S_loopbacks[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004565 { 0x21, HDA_INPUT, 1 },
4566 { 0x21, HDA_INPUT, 2 },
4567 { 0x21, HDA_INPUT, 3 },
4568 { 0x21, HDA_INPUT, 4 },
4569 { } /* end */
4570};
4571#endif
4572
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004573static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4574{
4575 struct via_spec *spec = codec->spec;
4576 int imux_is_smixer;
4577 unsigned int parm;
4578 /* MUX6 (1eh) = stereo mixer */
4579 imux_is_smixer =
4580 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4581 /* inputs */
4582 /* PW 5/6/7 (29h/2ah/2bh) */
4583 parm = AC_PWRST_D3;
4584 set_pin_power_state(codec, 0x29, &parm);
4585 set_pin_power_state(codec, 0x2a, &parm);
4586 set_pin_power_state(codec, 0x2b, &parm);
4587 if (imux_is_smixer)
4588 parm = AC_PWRST_D0;
4589 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4590 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4591 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4592 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4593 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4594
4595 /* outputs */
4596 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4597 parm = AC_PWRST_D3;
4598 set_pin_power_state(codec, 0x27, &parm);
4599 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4600 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4601
4602 /* PW2 (26h), AOW2 (ah) */
4603 parm = AC_PWRST_D3;
4604 set_pin_power_state(codec, 0x26, &parm);
4605 if (spec->smart51_enabled)
4606 set_pin_power_state(codec, 0x2b, &parm);
4607 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4608
4609 /* PW0 (24h), AOW0 (8h) */
4610 parm = AC_PWRST_D3;
4611 set_pin_power_state(codec, 0x24, &parm);
4612 if (!spec->hp_independent_mode) /* check for redirected HP */
4613 set_pin_power_state(codec, 0x28, &parm);
4614 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4615 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4616 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4617 imux_is_smixer ? AC_PWRST_D0 : parm);
4618
4619 /* PW1 (25h), AOW1 (9h) */
4620 parm = AC_PWRST_D3;
4621 set_pin_power_state(codec, 0x25, &parm);
4622 if (spec->smart51_enabled)
4623 set_pin_power_state(codec, 0x2a, &parm);
4624 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4625
4626 if (spec->hp_independent_mode) {
4627 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4628 parm = AC_PWRST_D3;
4629 set_pin_power_state(codec, 0x28, &parm);
4630 snd_hda_codec_write(codec, 0x1b, 0,
4631 AC_VERB_SET_POWER_STATE, parm);
4632 snd_hda_codec_write(codec, 0x34, 0,
4633 AC_VERB_SET_POWER_STATE, parm);
4634 snd_hda_codec_write(codec, 0xc, 0,
4635 AC_VERB_SET_POWER_STATE, parm);
4636 }
4637}
4638
Lydia Wangeb7188c2009-10-10 19:08:34 +08004639static int patch_vt1718S(struct hda_codec *codec)
4640{
4641 struct via_spec *spec;
4642 int err;
4643
4644 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004645 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004646 if (spec == NULL)
4647 return -ENOMEM;
4648
Lydia Wangeb7188c2009-10-10 19:08:34 +08004649 /* automatic parse from the BIOS config */
4650 err = vt1718S_parse_auto_config(codec);
4651 if (err < 0) {
4652 via_free(codec);
4653 return err;
4654 } else if (!err) {
4655 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4656 "from BIOS. Using genenic mode...\n");
4657 }
4658
4659 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4660 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4661
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004662 if (codec->vendor_id == 0x11060441)
4663 spec->stream_name_analog = "VT2020 Analog";
4664 else if (codec->vendor_id == 0x11064441)
4665 spec->stream_name_analog = "VT1828S Analog";
4666 else
4667 spec->stream_name_analog = "VT1718S Analog";
Lydia Wangeb7188c2009-10-10 19:08:34 +08004668 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4669 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4670
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004671 if (codec->vendor_id == 0x11060441)
4672 spec->stream_name_digital = "VT2020 Digital";
4673 else if (codec->vendor_id == 0x11064441)
4674 spec->stream_name_digital = "VT1828S Digital";
4675 else
4676 spec->stream_name_digital = "VT1718S Digital";
Lydia Wangeb7188c2009-10-10 19:08:34 +08004677 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004678 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
Lydia Wangeb7188c2009-10-10 19:08:34 +08004679 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4680
4681 if (!spec->adc_nids && spec->input_mux) {
4682 spec->adc_nids = vt1718S_adc_nids;
4683 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4684 get_mux_nids(codec);
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004685 override_mic_boost(codec, 0x2b, 0, 3, 40);
4686 override_mic_boost(codec, 0x29, 0, 3, 40);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004687 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4688 spec->num_mixers++;
4689 }
4690
4691 codec->patch_ops = via_patch_ops;
4692
4693 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11004694 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004695
4696#ifdef CONFIG_SND_HDA_POWER_SAVE
4697 spec->loopback.amplist = vt1718S_loopbacks;
4698#endif
4699
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004700 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4701
Lydia Wangeb7188c2009-10-10 19:08:34 +08004702 return 0;
4703}
Lydia Wangf3db4232009-10-10 19:08:41 +08004704
4705/* Patch for VT1716S */
4706
4707static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4708 struct snd_ctl_elem_info *uinfo)
4709{
4710 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4711 uinfo->count = 1;
4712 uinfo->value.integer.min = 0;
4713 uinfo->value.integer.max = 1;
4714 return 0;
4715}
4716
4717static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4718 struct snd_ctl_elem_value *ucontrol)
4719{
4720 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4721 int index = 0;
4722
4723 index = snd_hda_codec_read(codec, 0x26, 0,
4724 AC_VERB_GET_CONNECT_SEL, 0);
4725 if (index != -1)
4726 *ucontrol->value.integer.value = index;
4727
4728 return 0;
4729}
4730
4731static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4732 struct snd_ctl_elem_value *ucontrol)
4733{
4734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4735 struct via_spec *spec = codec->spec;
4736 int index = *ucontrol->value.integer.value;
4737
4738 snd_hda_codec_write(codec, 0x26, 0,
4739 AC_VERB_SET_CONNECT_SEL, index);
4740 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004741 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08004742 return 1;
4743}
4744
4745/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004746static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004747 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4748 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4749 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4750 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4751 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4752 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4753 HDA_INPUT),
4754 {
4755 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4756 .name = "Input Source",
4757 .count = 1,
4758 .info = via_mux_enum_info,
4759 .get = via_mux_enum_get,
4760 .put = via_mux_enum_put,
4761 },
4762 { } /* end */
4763};
4764
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004765static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004766 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4767 {
4768 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4769 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004770 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08004771 .count = 1,
4772 .info = vt1716s_dmic_info,
4773 .get = vt1716s_dmic_get,
4774 .put = vt1716s_dmic_put,
4775 },
4776 {} /* end */
4777};
4778
4779
4780/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004781static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004782 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4783 { } /* end */
4784};
4785
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004786static const struct hda_verb vt1716S_volume_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004787 /*
4788 * Unmute ADC0-1 and set the default input to mic-in
4789 */
4790 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4791 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4792
4793
4794 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4795 * mixer widget
4796 */
4797 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4798 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4799 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4800 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4801 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4802 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4803
4804 /* MUX Indices: Stereo Mixer = 5 */
4805 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4806
4807 /* Setup default input of PW4 to MW0 */
4808 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4809
4810 /* Setup default input of SW1 as MW0 */
4811 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4812
4813 /* Setup default input of SW4 as AOW0 */
4814 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4815
4816 /* PW9 PW10 Output enable */
4817 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4818 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4819
4820 /* Unmute SW1, PW12 */
4821 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4822 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4823 /* PW12 Output enable */
4824 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4825 /* Enable Boost Volume backdoor */
4826 {0x1, 0xf8a, 0x80},
4827 /* don't bybass mixer */
4828 {0x1, 0xf88, 0xc0},
4829 /* Enable mono output */
4830 {0x1, 0xf90, 0x08},
4831 { }
4832};
4833
4834
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004835static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004836 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4837 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4838 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4839 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4840 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4841 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4842 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4843 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4844 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4845 { }
4846};
4847
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004848static const struct hda_pcm_stream vt1716S_pcm_analog_playback = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004849 .substreams = 2,
4850 .channels_min = 2,
4851 .channels_max = 6,
4852 .nid = 0x10, /* NID to query formats and rates */
4853 .ops = {
4854 .open = via_playback_pcm_open,
4855 .prepare = via_playback_multi_pcm_prepare,
4856 .cleanup = via_playback_multi_pcm_cleanup,
4857 .close = via_pcm_open_close,
4858 },
4859};
4860
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004861static const struct hda_pcm_stream vt1716S_pcm_analog_capture = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004862 .substreams = 2,
4863 .channels_min = 2,
4864 .channels_max = 2,
4865 .nid = 0x13, /* NID to query formats and rates */
4866 .ops = {
4867 .open = via_pcm_open_close,
4868 .prepare = via_capture_pcm_prepare,
4869 .cleanup = via_capture_pcm_cleanup,
4870 .close = via_pcm_open_close,
4871 },
4872};
4873
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004874static const struct hda_pcm_stream vt1716S_pcm_digital_playback = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004875 .substreams = 2,
4876 .channels_min = 2,
4877 .channels_max = 2,
Lydia Wangf3db4232009-10-10 19:08:41 +08004878 /* NID is set in via_build_pcms */
4879 .ops = {
4880 .open = via_dig_playback_pcm_open,
4881 .close = via_dig_playback_pcm_close,
4882 .prepare = via_dig_playback_pcm_prepare,
4883 .cleanup = via_dig_playback_pcm_cleanup
4884 },
4885};
4886
4887/* fill in the dac_nids table from the parsed pin configuration */
4888static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4889 const struct auto_pin_cfg *cfg)
4890{ int i;
4891 hda_nid_t nid;
4892
4893 spec->multiout.num_dacs = cfg->line_outs;
4894
4895 spec->multiout.dac_nids = spec->private_dac_nids;
4896
4897 for (i = 0; i < 3; i++) {
4898 nid = cfg->line_out_pins[i];
4899 if (nid) {
4900 /* config dac list */
4901 switch (i) {
4902 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02004903 spec->private_dac_nids[i] = 0x10;
Lydia Wangf3db4232009-10-10 19:08:41 +08004904 break;
4905 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004906 spec->private_dac_nids[i] = 0x25;
Lydia Wangf3db4232009-10-10 19:08:41 +08004907 break;
4908 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02004909 spec->private_dac_nids[i] = 0x11;
Lydia Wangf3db4232009-10-10 19:08:41 +08004910 break;
4911 }
4912 }
4913 }
4914
4915 return 0;
4916}
4917
4918/* add playback controls from the parsed DAC table */
4919static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4920 const struct auto_pin_cfg *cfg)
4921{
4922 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01004923 static const char * const chname[3] = {
4924 "Front", "Surround", "C/LFE"
4925 };
Lydia Wangf3db4232009-10-10 19:08:41 +08004926 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4927 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4928 hda_nid_t nid, nid_vol, nid_mute;
4929 int i, err;
4930
4931 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4932 nid = cfg->line_out_pins[i];
4933
4934 if (!nid)
4935 continue;
4936
4937 nid_vol = nid_vols[i];
4938 nid_mute = nid_mutes[i];
4939
4940 if (i == AUTO_SEQ_CENLFE) {
4941 err = via_add_control(
4942 spec, VIA_CTL_WIDGET_VOL,
4943 "Center Playback Volume",
4944 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
4945 if (err < 0)
4946 return err;
4947 err = via_add_control(
4948 spec, VIA_CTL_WIDGET_VOL,
4949 "LFE Playback Volume",
4950 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
4951 if (err < 0)
4952 return err;
4953 err = via_add_control(
4954 spec, VIA_CTL_WIDGET_MUTE,
4955 "Center Playback Switch",
4956 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4957 HDA_OUTPUT));
4958 if (err < 0)
4959 return err;
4960 err = via_add_control(
4961 spec, VIA_CTL_WIDGET_MUTE,
4962 "LFE Playback Switch",
4963 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4964 HDA_OUTPUT));
4965 if (err < 0)
4966 return err;
4967 } else if (i == AUTO_SEQ_FRONT) {
4968
4969 err = via_add_control(
4970 spec, VIA_CTL_WIDGET_VOL,
4971 "Master Front Playback Volume",
4972 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4973 if (err < 0)
4974 return err;
4975 err = via_add_control(
4976 spec, VIA_CTL_WIDGET_MUTE,
4977 "Master Front Playback Switch",
4978 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4979 if (err < 0)
4980 return err;
4981
4982 sprintf(name, "%s Playback Volume", chname[i]);
4983 err = via_add_control(
4984 spec, VIA_CTL_WIDGET_VOL, name,
4985 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4986 if (err < 0)
4987 return err;
4988 sprintf(name, "%s Playback Switch", chname[i]);
4989 err = via_add_control(
4990 spec, VIA_CTL_WIDGET_MUTE, name,
4991 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4992 HDA_OUTPUT));
4993 if (err < 0)
4994 return err;
4995 } else {
4996 sprintf(name, "%s Playback Volume", chname[i]);
4997 err = via_add_control(
4998 spec, VIA_CTL_WIDGET_VOL, name,
4999 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5000 if (err < 0)
5001 return err;
5002 sprintf(name, "%s Playback Switch", chname[i]);
5003 err = via_add_control(
5004 spec, VIA_CTL_WIDGET_MUTE, name,
5005 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5006 HDA_OUTPUT));
5007 if (err < 0)
5008 return err;
5009 }
5010 }
5011 return 0;
5012}
5013
5014static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5015{
5016 int err;
5017
5018 if (!pin)
5019 return 0;
5020
5021 spec->multiout.hp_nid = 0x25; /* AOW3 */
5022 spec->hp_independent_mode_index = 1;
5023
5024 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5025 "Headphone Playback Volume",
5026 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5027 if (err < 0)
5028 return err;
5029
5030 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5031 "Headphone Playback Switch",
5032 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5033 if (err < 0)
5034 return err;
5035
5036 create_hp_imux(spec);
5037 return 0;
5038}
5039
5040/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005041static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangf3db4232009-10-10 19:08:41 +08005042 const struct auto_pin_cfg *cfg)
5043{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005044 static const hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
Takashi Iwai10a20af2010-09-09 16:28:02 +02005045 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02005046 ARRAY_SIZE(pin_idxs));
Lydia Wangf3db4232009-10-10 19:08:41 +08005047}
5048
5049static int vt1716S_parse_auto_config(struct hda_codec *codec)
5050{
5051 struct via_spec *spec = codec->spec;
5052 int err;
5053
5054 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5055 if (err < 0)
5056 return err;
5057 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5058 if (err < 0)
5059 return err;
5060 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5061 return 0; /* can't find valid BIOS pin config */
5062
5063 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5064 if (err < 0)
5065 return err;
5066 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5067 if (err < 0)
5068 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005069 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangf3db4232009-10-10 19:08:41 +08005070 if (err < 0)
5071 return err;
5072
5073 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5074
5075 fill_dig_outs(codec);
5076
5077 if (spec->kctls.list)
5078 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5079
5080 spec->input_mux = &spec->private_imux[0];
5081
5082 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005083 via_hp_build(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005084
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005085 via_smart51_build(spec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005086
5087 return 1;
5088}
5089
5090#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005091static const struct hda_amp_list vt1716S_loopbacks[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08005092 { 0x16, HDA_INPUT, 1 },
5093 { 0x16, HDA_INPUT, 2 },
5094 { 0x16, HDA_INPUT, 3 },
5095 { 0x16, HDA_INPUT, 4 },
5096 { } /* end */
5097};
5098#endif
5099
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005100static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5101{
5102 struct via_spec *spec = codec->spec;
5103 int imux_is_smixer;
5104 unsigned int parm;
5105 unsigned int mono_out, present;
5106 /* SW0 (17h) = stereo mixer */
5107 imux_is_smixer =
5108 (snd_hda_codec_read(codec, 0x17, 0,
5109 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5110 /* inputs */
5111 /* PW 1/2/5 (1ah/1bh/1eh) */
5112 parm = AC_PWRST_D3;
5113 set_pin_power_state(codec, 0x1a, &parm);
5114 set_pin_power_state(codec, 0x1b, &parm);
5115 set_pin_power_state(codec, 0x1e, &parm);
5116 if (imux_is_smixer)
5117 parm = AC_PWRST_D0;
5118 /* SW0 (17h), AIW0(13h) */
5119 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5120 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5121
5122 parm = AC_PWRST_D3;
5123 set_pin_power_state(codec, 0x1e, &parm);
5124 /* PW11 (22h) */
5125 if (spec->dmic_enabled)
5126 set_pin_power_state(codec, 0x22, &parm);
5127 else
5128 snd_hda_codec_write(codec, 0x22, 0,
5129 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5130
5131 /* SW2(26h), AIW1(14h) */
5132 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5133 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5134
5135 /* outputs */
5136 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5137 parm = AC_PWRST_D3;
5138 set_pin_power_state(codec, 0x19, &parm);
5139 /* Smart 5.1 PW2(1bh) */
5140 if (spec->smart51_enabled)
5141 set_pin_power_state(codec, 0x1b, &parm);
5142 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5143 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5144
5145 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5146 parm = AC_PWRST_D3;
5147 set_pin_power_state(codec, 0x23, &parm);
5148 /* Smart 5.1 PW1(1ah) */
5149 if (spec->smart51_enabled)
5150 set_pin_power_state(codec, 0x1a, &parm);
5151 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5152
5153 /* Smart 5.1 PW5(1eh) */
5154 if (spec->smart51_enabled)
5155 set_pin_power_state(codec, 0x1e, &parm);
5156 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5157
5158 /* Mono out */
5159 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5160 present = snd_hda_jack_detect(codec, 0x1c);
5161
5162 if (present)
5163 mono_out = 0;
5164 else {
5165 present = snd_hda_jack_detect(codec, 0x1d);
5166 if (!spec->hp_independent_mode && present)
5167 mono_out = 0;
5168 else
5169 mono_out = 1;
5170 }
5171 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5172 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5173 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5174 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5175
5176 /* PW 3/4 (1ch/1dh) */
5177 parm = AC_PWRST_D3;
5178 set_pin_power_state(codec, 0x1c, &parm);
5179 set_pin_power_state(codec, 0x1d, &parm);
5180 /* HP Independent Mode, power on AOW3 */
5181 if (spec->hp_independent_mode)
5182 snd_hda_codec_write(codec, 0x25, 0,
5183 AC_VERB_SET_POWER_STATE, parm);
5184
5185 /* force to D0 for internal Speaker */
5186 /* MW0 (16h), AOW0 (10h) */
5187 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5188 imux_is_smixer ? AC_PWRST_D0 : parm);
5189 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5190 mono_out ? AC_PWRST_D0 : parm);
5191}
5192
Lydia Wangf3db4232009-10-10 19:08:41 +08005193static int patch_vt1716S(struct hda_codec *codec)
5194{
5195 struct via_spec *spec;
5196 int err;
5197
5198 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005199 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005200 if (spec == NULL)
5201 return -ENOMEM;
5202
Lydia Wangf3db4232009-10-10 19:08:41 +08005203 /* automatic parse from the BIOS config */
5204 err = vt1716S_parse_auto_config(codec);
5205 if (err < 0) {
5206 via_free(codec);
5207 return err;
5208 } else if (!err) {
5209 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5210 "from BIOS. Using genenic mode...\n");
5211 }
5212
5213 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5214 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5215
5216 spec->stream_name_analog = "VT1716S Analog";
5217 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5218 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5219
5220 spec->stream_name_digital = "VT1716S Digital";
5221 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5222
5223 if (!spec->adc_nids && spec->input_mux) {
5224 spec->adc_nids = vt1716S_adc_nids;
5225 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5226 get_mux_nids(codec);
5227 override_mic_boost(codec, 0x1a, 0, 3, 40);
5228 override_mic_boost(codec, 0x1e, 0, 3, 40);
5229 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5230 spec->num_mixers++;
5231 }
5232
5233 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5234 spec->num_mixers++;
5235
5236 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5237
5238 codec->patch_ops = via_patch_ops;
5239
5240 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005241 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangf3db4232009-10-10 19:08:41 +08005242
5243#ifdef CONFIG_SND_HDA_POWER_SAVE
5244 spec->loopback.amplist = vt1716S_loopbacks;
5245#endif
5246
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005247 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08005248 return 0;
5249}
Lydia Wang25eaba22009-10-10 19:08:43 +08005250
5251/* for vt2002P */
5252
5253/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005254static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005255 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5256 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5257 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5258 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5259 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5260 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5261 HDA_INPUT),
5262 {
5263 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5264 /* The multiple "Capture Source" controls confuse alsamixer
5265 * So call somewhat different..
5266 */
5267 /* .name = "Capture Source", */
5268 .name = "Input Source",
5269 .count = 2,
5270 .info = via_mux_enum_info,
5271 .get = via_mux_enum_get,
5272 .put = via_mux_enum_put,
5273 },
5274 { } /* end */
5275};
5276
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005277static const struct hda_verb vt2002P_volume_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08005278 /* Class-D speaker related verbs */
5279 {0x1, 0xfe0, 0x4},
5280 {0x1, 0xfe9, 0x80},
5281 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08005282 /*
5283 * Unmute ADC0-1 and set the default input to mic-in
5284 */
5285 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5286 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5287
5288
5289 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5290 * mixer widget
5291 */
5292 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5293 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5294 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5295 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5296 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5297 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5298
5299 /* MUX Indices: Mic = 0 */
5300 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5301 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5302
5303 /* PW9 Output enable */
5304 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5305
5306 /* Enable Boost Volume backdoor */
5307 {0x1, 0xfb9, 0x24},
5308
5309 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5310 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5311 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5312 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5313 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5314 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5315 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5316 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5317 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5318
5319 /* set MUX0/1/4/8 = 0 (AOW0) */
5320 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5321 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5322 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5323 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5324
5325 /* set PW0 index=0 (MW0) */
5326 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5327
5328 /* Enable AOW0 to MW9 */
5329 {0x1, 0xfb8, 0x88},
5330 { }
5331};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005332static const struct hda_verb vt1802_volume_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08005333 /*
5334 * Unmute ADC0-1 and set the default input to mic-in
5335 */
5336 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5337 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5338
5339
5340 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5341 * mixer widget
5342 */
5343 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5344 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5345 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5346 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5347 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5348 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5349
5350 /* MUX Indices: Mic = 0 */
5351 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5352 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5353
5354 /* PW9 Output enable */
5355 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5356
5357 /* Enable Boost Volume backdoor */
5358 {0x1, 0xfb9, 0x24},
5359
5360 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5361 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5362 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5363 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5364 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5365 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5366 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5367 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5368 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5369
5370 /* set MUX0/1/4/8 = 0 (AOW0) */
5371 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5372 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5373 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5374 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5375
5376 /* set PW0 index=0 (MW0) */
5377 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5378
5379 /* Enable AOW0 to MW9 */
5380 {0x1, 0xfb8, 0x88},
5381 { }
5382};
Lydia Wang25eaba22009-10-10 19:08:43 +08005383
5384
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005385static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005386 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5387 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5388 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5389 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5390 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5391 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5392 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5393 { }
5394};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005395static const struct hda_verb vt1802_uniwill_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08005396 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5397 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5398 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5399 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5400 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5401 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5402 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5403 { }
5404};
Lydia Wang25eaba22009-10-10 19:08:43 +08005405
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005406static const struct hda_pcm_stream vt2002P_pcm_analog_playback = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005407 .substreams = 2,
5408 .channels_min = 2,
5409 .channels_max = 2,
5410 .nid = 0x8, /* NID to query formats and rates */
5411 .ops = {
5412 .open = via_playback_pcm_open,
5413 .prepare = via_playback_multi_pcm_prepare,
5414 .cleanup = via_playback_multi_pcm_cleanup,
5415 .close = via_pcm_open_close,
5416 },
5417};
5418
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005419static const struct hda_pcm_stream vt2002P_pcm_analog_capture = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005420 .substreams = 2,
5421 .channels_min = 2,
5422 .channels_max = 2,
5423 .nid = 0x10, /* NID to query formats and rates */
5424 .ops = {
5425 .open = via_pcm_open_close,
5426 .prepare = via_capture_pcm_prepare,
5427 .cleanup = via_capture_pcm_cleanup,
5428 .close = via_pcm_open_close,
5429 },
5430};
5431
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005432static const struct hda_pcm_stream vt2002P_pcm_digital_playback = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005433 .substreams = 1,
5434 .channels_min = 2,
5435 .channels_max = 2,
Lydia Wang25eaba22009-10-10 19:08:43 +08005436 /* NID is set in via_build_pcms */
5437 .ops = {
5438 .open = via_dig_playback_pcm_open,
5439 .close = via_dig_playback_pcm_close,
5440 .prepare = via_dig_playback_pcm_prepare,
5441 .cleanup = via_dig_playback_pcm_cleanup
5442 },
5443};
5444
5445/* fill in the dac_nids table from the parsed pin configuration */
5446static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5447 const struct auto_pin_cfg *cfg)
5448{
5449 spec->multiout.num_dacs = 1;
5450 spec->multiout.dac_nids = spec->private_dac_nids;
5451 if (cfg->line_out_pins[0])
Takashi Iwaidda14412011-05-02 11:29:30 +02005452 spec->private_dac_nids[0] = 0x8;
Lydia Wang25eaba22009-10-10 19:08:43 +08005453 return 0;
5454}
5455
5456/* add playback controls from the parsed DAC table */
5457static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5458 const struct auto_pin_cfg *cfg)
5459{
5460 int err;
Lydia Wang118909562011-03-23 17:57:34 +08005461 hda_nid_t sw_nid;
Lydia Wang25eaba22009-10-10 19:08:43 +08005462
5463 if (!cfg->line_out_pins[0])
5464 return -1;
5465
Lydia Wang118909562011-03-23 17:57:34 +08005466 if (spec->codec_type == VT1802)
5467 sw_nid = 0x28;
5468 else
5469 sw_nid = 0x26;
Lydia Wang25eaba22009-10-10 19:08:43 +08005470
5471 /* Line-Out: PortE */
5472 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5473 "Master Front Playback Volume",
5474 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5475 if (err < 0)
5476 return err;
5477 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5478 "Master Front Playback Switch",
Lydia Wang118909562011-03-23 17:57:34 +08005479 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
Lydia Wang25eaba22009-10-10 19:08:43 +08005480 if (err < 0)
5481 return err;
5482
5483 return 0;
5484}
5485
5486static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5487{
5488 int err;
5489
5490 if (!pin)
5491 return 0;
5492
5493 spec->multiout.hp_nid = 0x9;
5494 spec->hp_independent_mode_index = 1;
5495
5496 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5497 "Headphone Playback Volume",
5498 HDA_COMPOSE_AMP_VAL(
5499 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5500 if (err < 0)
5501 return err;
5502
5503 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5504 "Headphone Playback Switch",
5505 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5506 if (err < 0)
5507 return err;
5508
5509 create_hp_imux(spec);
5510 return 0;
5511}
5512
5513/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005514static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wang25eaba22009-10-10 19:08:43 +08005515 const struct auto_pin_cfg *cfg)
5516{
Takashi Iwai10a20af2010-09-09 16:28:02 +02005517 struct via_spec *spec = codec->spec;
Lydia Wang25eaba22009-10-10 19:08:43 +08005518 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005519 static const hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
Takashi Iwaif3268512010-08-30 11:00:19 +02005520 int err;
Lydia Wang25eaba22009-10-10 19:08:43 +08005521
Takashi Iwai10a20af2010-09-09 16:28:02 +02005522 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02005523 ARRAY_SIZE(pin_idxs));
5524 if (err < 0)
5525 return err;
Lydia Wang25eaba22009-10-10 19:08:43 +08005526 /* build volume/mute control of loopback */
Takashi Iwai7b315bb2010-08-30 13:06:30 +02005527 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
Lydia Wang25eaba22009-10-10 19:08:43 +08005528 if (err < 0)
5529 return err;
5530
Lydia Wang25eaba22009-10-10 19:08:43 +08005531 /* for digital mic select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005532 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
Lydia Wang25eaba22009-10-10 19:08:43 +08005533
5534 return 0;
5535}
5536
5537static int vt2002P_parse_auto_config(struct hda_codec *codec)
5538{
5539 struct via_spec *spec = codec->spec;
5540 int err;
5541
5542
5543 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5544 if (err < 0)
5545 return err;
5546
5547 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5548 if (err < 0)
5549 return err;
5550
5551 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5552 return 0; /* can't find valid BIOS pin config */
5553
5554 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5555 if (err < 0)
5556 return err;
5557 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5558 if (err < 0)
5559 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005560 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wang25eaba22009-10-10 19:08:43 +08005561 if (err < 0)
5562 return err;
5563
5564 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5565
5566 fill_dig_outs(codec);
5567
5568 if (spec->kctls.list)
5569 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5570
5571 spec->input_mux = &spec->private_imux[0];
5572
5573 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005574 via_hp_build(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08005575
5576 return 1;
5577}
5578
5579#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005580static const struct hda_amp_list vt2002P_loopbacks[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005581 { 0x21, HDA_INPUT, 0 },
5582 { 0x21, HDA_INPUT, 1 },
5583 { 0x21, HDA_INPUT, 2 },
5584 { } /* end */
5585};
5586#endif
5587
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005588static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5589{
5590 struct via_spec *spec = codec->spec;
5591 int imux_is_smixer;
5592 unsigned int parm;
5593 unsigned int present;
5594 /* MUX9 (1eh) = stereo mixer */
5595 imux_is_smixer =
5596 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5597 /* inputs */
5598 /* PW 5/6/7 (29h/2ah/2bh) */
5599 parm = AC_PWRST_D3;
5600 set_pin_power_state(codec, 0x29, &parm);
5601 set_pin_power_state(codec, 0x2a, &parm);
5602 set_pin_power_state(codec, 0x2b, &parm);
5603 parm = AC_PWRST_D0;
5604 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5605 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5606 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5607 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5608 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5609
5610 /* outputs */
5611 /* AOW0 (8h)*/
5612 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5613
Lydia Wang118909562011-03-23 17:57:34 +08005614 if (spec->codec_type == VT1802) {
5615 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5616 parm = AC_PWRST_D3;
5617 set_pin_power_state(codec, 0x28, &parm);
5618 snd_hda_codec_write(codec, 0x18, 0,
5619 AC_VERB_SET_POWER_STATE, parm);
5620 snd_hda_codec_write(codec, 0x38, 0,
5621 AC_VERB_SET_POWER_STATE, parm);
5622 } else {
5623 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5624 parm = AC_PWRST_D3;
5625 set_pin_power_state(codec, 0x26, &parm);
5626 snd_hda_codec_write(codec, 0x1c, 0,
5627 AC_VERB_SET_POWER_STATE, parm);
5628 snd_hda_codec_write(codec, 0x37, 0,
5629 AC_VERB_SET_POWER_STATE, parm);
5630 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005631
Lydia Wang118909562011-03-23 17:57:34 +08005632 if (spec->codec_type == VT1802) {
5633 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5634 parm = AC_PWRST_D3;
5635 set_pin_power_state(codec, 0x25, &parm);
5636 snd_hda_codec_write(codec, 0x15, 0,
5637 AC_VERB_SET_POWER_STATE, parm);
5638 snd_hda_codec_write(codec, 0x35, 0,
5639 AC_VERB_SET_POWER_STATE, parm);
5640 } else {
5641 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5642 parm = AC_PWRST_D3;
5643 set_pin_power_state(codec, 0x25, &parm);
5644 snd_hda_codec_write(codec, 0x19, 0,
5645 AC_VERB_SET_POWER_STATE, parm);
5646 snd_hda_codec_write(codec, 0x35, 0,
5647 AC_VERB_SET_POWER_STATE, parm);
5648 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005649
5650 if (spec->hp_independent_mode)
5651 snd_hda_codec_write(codec, 0x9, 0,
5652 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5653
5654 /* Class-D */
5655 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5656 present = snd_hda_jack_detect(codec, 0x25);
5657
5658 parm = AC_PWRST_D3;
5659 set_pin_power_state(codec, 0x24, &parm);
5660 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08005661 if (spec->codec_type == VT1802)
5662 snd_hda_codec_write(codec, 0x14, 0,
5663 AC_VERB_SET_POWER_STATE, parm);
5664 else
5665 snd_hda_codec_write(codec, 0x18, 0,
5666 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005667 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5668
5669 /* Mono Out */
5670 present = snd_hda_jack_detect(codec, 0x26);
5671
5672 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08005673 if (spec->codec_type == VT1802) {
5674 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5675 snd_hda_codec_write(codec, 0x33, 0,
5676 AC_VERB_SET_POWER_STATE, parm);
5677 snd_hda_codec_write(codec, 0x1c, 0,
5678 AC_VERB_SET_POWER_STATE, parm);
5679 snd_hda_codec_write(codec, 0x3c, 0,
5680 AC_VERB_SET_POWER_STATE, parm);
5681 } else {
5682 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5683 snd_hda_codec_write(codec, 0x31, 0,
5684 AC_VERB_SET_POWER_STATE, parm);
5685 snd_hda_codec_write(codec, 0x17, 0,
5686 AC_VERB_SET_POWER_STATE, parm);
5687 snd_hda_codec_write(codec, 0x3b, 0,
5688 AC_VERB_SET_POWER_STATE, parm);
5689 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005690 /* MW9 (21h) */
5691 if (imux_is_smixer || !is_aa_path_mute(codec))
5692 snd_hda_codec_write(codec, 0x21, 0,
5693 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5694 else
5695 snd_hda_codec_write(codec, 0x21, 0,
5696 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5697}
Lydia Wang25eaba22009-10-10 19:08:43 +08005698
5699/* patch for vt2002P */
5700static int patch_vt2002P(struct hda_codec *codec)
5701{
5702 struct via_spec *spec;
5703 int err;
5704
5705 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005706 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08005707 if (spec == NULL)
5708 return -ENOMEM;
5709
Lydia Wang25eaba22009-10-10 19:08:43 +08005710 /* automatic parse from the BIOS config */
5711 err = vt2002P_parse_auto_config(codec);
5712 if (err < 0) {
5713 via_free(codec);
5714 return err;
5715 } else if (!err) {
5716 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5717 "from BIOS. Using genenic mode...\n");
5718 }
5719
Lydia Wang118909562011-03-23 17:57:34 +08005720 if (spec->codec_type == VT1802)
5721 spec->init_verbs[spec->num_iverbs++] =
5722 vt1802_volume_init_verbs;
5723 else
5724 spec->init_verbs[spec->num_iverbs++] =
5725 vt2002P_volume_init_verbs;
Lydia Wang25eaba22009-10-10 19:08:43 +08005726
Lydia Wang118909562011-03-23 17:57:34 +08005727 if (spec->codec_type == VT1802)
5728 spec->init_verbs[spec->num_iverbs++] =
5729 vt1802_uniwill_init_verbs;
5730 else
5731 spec->init_verbs[spec->num_iverbs++] =
5732 vt2002P_uniwill_init_verbs;
5733
5734 if (spec->codec_type == VT1802)
5735 spec->stream_name_analog = "VT1802 Analog";
5736 else
5737 spec->stream_name_analog = "VT2002P Analog";
Lydia Wang25eaba22009-10-10 19:08:43 +08005738 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5739 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5740
Lydia Wang118909562011-03-23 17:57:34 +08005741 if (spec->codec_type == VT1802)
5742 spec->stream_name_digital = "VT1802 Digital";
5743 else
5744 spec->stream_name_digital = "VT2002P Digital";
Lydia Wang25eaba22009-10-10 19:08:43 +08005745 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5746
5747 if (!spec->adc_nids && spec->input_mux) {
5748 spec->adc_nids = vt2002P_adc_nids;
5749 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5750 get_mux_nids(codec);
5751 override_mic_boost(codec, 0x2b, 0, 3, 40);
5752 override_mic_boost(codec, 0x29, 0, 3, 40);
5753 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5754 spec->num_mixers++;
5755 }
5756
5757 codec->patch_ops = via_patch_ops;
5758
5759 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005760 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wang25eaba22009-10-10 19:08:43 +08005761
5762#ifdef CONFIG_SND_HDA_POWER_SAVE
5763 spec->loopback.amplist = vt2002P_loopbacks;
5764#endif
5765
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005766 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08005767 return 0;
5768}
Lydia Wangab6734e2009-10-10 19:08:46 +08005769
5770/* for vt1812 */
5771
5772/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005773static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005774 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5775 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5776 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5777 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5778 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5779 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5780 HDA_INPUT),
5781 {
5782 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5783 /* The multiple "Capture Source" controls confuse alsamixer
5784 * So call somewhat different..
5785 */
5786 .name = "Input Source",
5787 .count = 2,
5788 .info = via_mux_enum_info,
5789 .get = via_mux_enum_get,
5790 .put = via_mux_enum_put,
5791 },
5792 { } /* end */
5793};
5794
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005795static const struct hda_verb vt1812_volume_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005796 /*
5797 * Unmute ADC0-1 and set the default input to mic-in
5798 */
5799 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5800 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5801
5802
5803 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5804 * mixer widget
5805 */
5806 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5807 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5808 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5809 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5810 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5811 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5812
5813 /* MUX Indices: Mic = 0 */
5814 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5815 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5816
5817 /* PW9 Output enable */
5818 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5819
5820 /* Enable Boost Volume backdoor */
5821 {0x1, 0xfb9, 0x24},
5822
5823 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5824 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5825 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5826 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5827 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5828 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5829 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5830 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5831 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5832 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5833 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5834
5835 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5836 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5837 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5838 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5839 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5840 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5841
5842 /* Enable AOW0 to MW9 */
5843 {0x1, 0xfb8, 0xa8},
5844 { }
5845};
5846
5847
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005848static const struct hda_verb vt1812_uniwill_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005849 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5850 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5851 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5852 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5853 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5854 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5855 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5856 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5857 { }
5858};
5859
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005860static const struct hda_pcm_stream vt1812_pcm_analog_playback = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005861 .substreams = 2,
5862 .channels_min = 2,
5863 .channels_max = 2,
5864 .nid = 0x8, /* NID to query formats and rates */
5865 .ops = {
5866 .open = via_playback_pcm_open,
5867 .prepare = via_playback_multi_pcm_prepare,
5868 .cleanup = via_playback_multi_pcm_cleanup,
5869 .close = via_pcm_open_close,
5870 },
5871};
5872
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005873static const struct hda_pcm_stream vt1812_pcm_analog_capture = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005874 .substreams = 2,
5875 .channels_min = 2,
5876 .channels_max = 2,
5877 .nid = 0x10, /* NID to query formats and rates */
5878 .ops = {
5879 .open = via_pcm_open_close,
5880 .prepare = via_capture_pcm_prepare,
5881 .cleanup = via_capture_pcm_cleanup,
5882 .close = via_pcm_open_close,
5883 },
5884};
5885
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005886static const struct hda_pcm_stream vt1812_pcm_digital_playback = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005887 .substreams = 1,
5888 .channels_min = 2,
5889 .channels_max = 2,
Lydia Wangab6734e2009-10-10 19:08:46 +08005890 /* NID is set in via_build_pcms */
5891 .ops = {
5892 .open = via_dig_playback_pcm_open,
5893 .close = via_dig_playback_pcm_close,
5894 .prepare = via_dig_playback_pcm_prepare,
5895 .cleanup = via_dig_playback_pcm_cleanup
5896 },
5897};
5898/* fill in the dac_nids table from the parsed pin configuration */
5899static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5900 const struct auto_pin_cfg *cfg)
5901{
5902 spec->multiout.num_dacs = 1;
5903 spec->multiout.dac_nids = spec->private_dac_nids;
5904 if (cfg->line_out_pins[0])
Takashi Iwaidda14412011-05-02 11:29:30 +02005905 spec->private_dac_nids[0] = 0x8;
Lydia Wangab6734e2009-10-10 19:08:46 +08005906 return 0;
5907}
5908
5909
5910/* add playback controls from the parsed DAC table */
5911static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5912 const struct auto_pin_cfg *cfg)
5913{
5914 int err;
5915
5916 if (!cfg->line_out_pins[0])
5917 return -1;
5918
5919 /* Line-Out: PortE */
5920 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Takashi Iwai3d83e572010-04-14 14:36:23 +02005921 "Front Playback Volume",
Lydia Wangab6734e2009-10-10 19:08:46 +08005922 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5923 if (err < 0)
5924 return err;
5925 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
Takashi Iwai3d83e572010-04-14 14:36:23 +02005926 "Front Playback Switch",
Lydia Wangab6734e2009-10-10 19:08:46 +08005927 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5928 if (err < 0)
5929 return err;
5930
5931 return 0;
5932}
5933
5934static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5935{
5936 int err;
5937
5938 if (!pin)
5939 return 0;
5940
5941 spec->multiout.hp_nid = 0x9;
5942 spec->hp_independent_mode_index = 1;
5943
5944
5945 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5946 "Headphone Playback Volume",
5947 HDA_COMPOSE_AMP_VAL(
5948 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5949 if (err < 0)
5950 return err;
5951
5952 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5953 "Headphone Playback Switch",
5954 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5955 if (err < 0)
5956 return err;
5957
5958 create_hp_imux(spec);
5959 return 0;
5960}
5961
5962/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005963static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangab6734e2009-10-10 19:08:46 +08005964 const struct auto_pin_cfg *cfg)
5965{
Takashi Iwai10a20af2010-09-09 16:28:02 +02005966 struct via_spec *spec = codec->spec;
Lydia Wangab6734e2009-10-10 19:08:46 +08005967 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005968 static const hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
Takashi Iwaif3268512010-08-30 11:00:19 +02005969 int err;
Lydia Wangab6734e2009-10-10 19:08:46 +08005970
Takashi Iwai10a20af2010-09-09 16:28:02 +02005971 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02005972 ARRAY_SIZE(pin_idxs));
5973 if (err < 0)
5974 return err;
Lydia Wangab6734e2009-10-10 19:08:46 +08005975
Lydia Wangab6734e2009-10-10 19:08:46 +08005976 /* build volume/mute control of loopback */
Takashi Iwai7b315bb2010-08-30 13:06:30 +02005977 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
Lydia Wangab6734e2009-10-10 19:08:46 +08005978 if (err < 0)
5979 return err;
5980
Lydia Wangab6734e2009-10-10 19:08:46 +08005981 /* for digital mic select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005982 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
Lydia Wangab6734e2009-10-10 19:08:46 +08005983
5984 return 0;
5985}
5986
5987static int vt1812_parse_auto_config(struct hda_codec *codec)
5988{
5989 struct via_spec *spec = codec->spec;
5990 int err;
5991
5992
5993 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5994 if (err < 0)
5995 return err;
5996 fill_dig_outs(codec);
5997 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5998 if (err < 0)
5999 return err;
6000
6001 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6002 return 0; /* can't find valid BIOS pin config */
6003
6004 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6005 if (err < 0)
6006 return err;
6007 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6008 if (err < 0)
6009 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02006010 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangab6734e2009-10-10 19:08:46 +08006011 if (err < 0)
6012 return err;
6013
6014 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6015
6016 fill_dig_outs(codec);
6017
6018 if (spec->kctls.list)
6019 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6020
6021 spec->input_mux = &spec->private_imux[0];
6022
6023 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02006024 via_hp_build(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08006025
6026 return 1;
6027}
6028
6029#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02006030static const struct hda_amp_list vt1812_loopbacks[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08006031 { 0x21, HDA_INPUT, 0 },
6032 { 0x21, HDA_INPUT, 1 },
6033 { 0x21, HDA_INPUT, 2 },
6034 { } /* end */
6035};
6036#endif
6037
Lydia Wang3e95b9a2011-03-23 15:13:28 +08006038static void set_widgets_power_state_vt1812(struct hda_codec *codec)
6039{
6040 struct via_spec *spec = codec->spec;
6041 int imux_is_smixer =
6042 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
6043 unsigned int parm;
6044 unsigned int present;
6045 /* MUX10 (1eh) = stereo mixer */
6046 imux_is_smixer =
6047 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
6048 /* inputs */
6049 /* PW 5/6/7 (29h/2ah/2bh) */
6050 parm = AC_PWRST_D3;
6051 set_pin_power_state(codec, 0x29, &parm);
6052 set_pin_power_state(codec, 0x2a, &parm);
6053 set_pin_power_state(codec, 0x2b, &parm);
6054 parm = AC_PWRST_D0;
6055 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
6056 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
6057 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
6058 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
6059 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
6060
6061 /* outputs */
6062 /* AOW0 (8h)*/
6063 snd_hda_codec_write(codec, 0x8, 0,
6064 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6065
6066 /* PW4 (28h), MW4 (18h), MUX4(38h) */
6067 parm = AC_PWRST_D3;
6068 set_pin_power_state(codec, 0x28, &parm);
6069 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
6070 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
6071
6072 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
6073 parm = AC_PWRST_D3;
6074 set_pin_power_state(codec, 0x25, &parm);
6075 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
6076 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
6077 if (spec->hp_independent_mode)
6078 snd_hda_codec_write(codec, 0x9, 0,
6079 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6080
6081 /* Internal Speaker */
6082 /* PW0 (24h), MW0(14h), MUX0(34h) */
6083 present = snd_hda_jack_detect(codec, 0x25);
6084
6085 parm = AC_PWRST_D3;
6086 set_pin_power_state(codec, 0x24, &parm);
6087 if (present) {
6088 snd_hda_codec_write(codec, 0x14, 0,
6089 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6090 snd_hda_codec_write(codec, 0x34, 0,
6091 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6092 } else {
6093 snd_hda_codec_write(codec, 0x14, 0,
6094 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6095 snd_hda_codec_write(codec, 0x34, 0,
6096 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6097 }
6098
6099
6100 /* Mono Out */
6101 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6102 present = snd_hda_jack_detect(codec, 0x28);
6103
6104 parm = AC_PWRST_D3;
6105 set_pin_power_state(codec, 0x31, &parm);
6106 if (present) {
6107 snd_hda_codec_write(codec, 0x1c, 0,
6108 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6109 snd_hda_codec_write(codec, 0x3c, 0,
6110 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6111 snd_hda_codec_write(codec, 0x3e, 0,
6112 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6113 } else {
6114 snd_hda_codec_write(codec, 0x1c, 0,
6115 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6116 snd_hda_codec_write(codec, 0x3c, 0,
6117 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6118 snd_hda_codec_write(codec, 0x3e, 0,
6119 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6120 }
6121
6122 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6123 parm = AC_PWRST_D3;
6124 set_pin_power_state(codec, 0x33, &parm);
6125 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6126 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6127
6128}
Lydia Wangab6734e2009-10-10 19:08:46 +08006129
6130/* patch for vt1812 */
6131static int patch_vt1812(struct hda_codec *codec)
6132{
6133 struct via_spec *spec;
6134 int err;
6135
6136 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01006137 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08006138 if (spec == NULL)
6139 return -ENOMEM;
6140
Lydia Wangab6734e2009-10-10 19:08:46 +08006141 /* automatic parse from the BIOS config */
6142 err = vt1812_parse_auto_config(codec);
6143 if (err < 0) {
6144 via_free(codec);
6145 return err;
6146 } else if (!err) {
6147 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6148 "from BIOS. Using genenic mode...\n");
6149 }
6150
6151
6152 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6153 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6154
6155 spec->stream_name_analog = "VT1812 Analog";
6156 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6157 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6158
6159 spec->stream_name_digital = "VT1812 Digital";
6160 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6161
6162
6163 if (!spec->adc_nids && spec->input_mux) {
6164 spec->adc_nids = vt1812_adc_nids;
6165 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6166 get_mux_nids(codec);
6167 override_mic_boost(codec, 0x2b, 0, 3, 40);
6168 override_mic_boost(codec, 0x29, 0, 3, 40);
6169 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6170 spec->num_mixers++;
6171 }
6172
6173 codec->patch_ops = via_patch_ops;
6174
6175 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11006176 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangab6734e2009-10-10 19:08:46 +08006177
6178#ifdef CONFIG_SND_HDA_POWER_SAVE
6179 spec->loopback.amplist = vt1812_loopbacks;
6180#endif
6181
Lydia Wang3e95b9a2011-03-23 15:13:28 +08006182 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08006183 return 0;
6184}
6185
Joseph Chanc577b8a2006-11-29 15:29:40 +01006186/*
6187 * patch entries
6188 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02006189static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01006190 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6191 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6192 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6193 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6194 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006195 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006196 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006197 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006198 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006199 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006200 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006201 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006202 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006203 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006204 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006205 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006206 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006207 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006208 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006209 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006210 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006211 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006212 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006213 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006214 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006215 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006216 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006217 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006218 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006219 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006220 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006221 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006222 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006223 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006224 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006225 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006226 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006227 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006228 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006229 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006230 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006231 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006232 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006233 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08006234 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08006235 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006236 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006237 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006238 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006239 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006240 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006241 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006242 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006243 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006244 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006245 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006246 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006247 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006248 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006249 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006250 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006251 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006252 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006253 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006254 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006255 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006256 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006257 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08006258 { .id = 0x11060428, .name = "VT1718S",
6259 .patch = patch_vt1718S},
6260 { .id = 0x11064428, .name = "VT1718S",
6261 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08006262 { .id = 0x11060441, .name = "VT2020",
6263 .patch = patch_vt1718S},
6264 { .id = 0x11064441, .name = "VT1828S",
6265 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08006266 { .id = 0x11060433, .name = "VT1716S",
6267 .patch = patch_vt1716S},
6268 { .id = 0x1106a721, .name = "VT1716S",
6269 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08006270 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6271 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08006272 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08006273 { .id = 0x11060440, .name = "VT1818S",
6274 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08006275 { .id = 0x11060446, .name = "VT1802",
6276 .patch = patch_vt2002P},
6277 { .id = 0x11068446, .name = "VT1802",
6278 .patch = patch_vt2002P},
Joseph Chanc577b8a2006-11-29 15:29:40 +01006279 {} /* terminator */
6280};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006281
6282MODULE_ALIAS("snd-hda-codec-id:1106*");
6283
6284static struct hda_codec_preset_list via_list = {
6285 .preset = snd_hda_preset_via,
6286 .owner = THIS_MODULE,
6287};
6288
6289MODULE_LICENSE("GPL");
6290MODULE_DESCRIPTION("VIA HD-audio codec");
6291
6292static int __init patch_via_init(void)
6293{
6294 return snd_hda_add_codec_preset(&via_list);
6295}
6296
6297static void __exit patch_via_exit(void)
6298{
6299 snd_hda_delete_codec_preset(&via_list);
6300}
6301
6302module_init(patch_via_init)
6303module_exit(patch_via_exit)