blob: 8a9791ab43c0340815577a3706fe38ccfb58eeda [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;
Takashi Iwai24088a52011-06-17 16:59:21 +0200156 unsigned int no_pin_power_ctl;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800157 enum VIA_HDA_CODEC codec_type;
158
159 /* work to check hp jack state */
160 struct hda_codec *codec;
161 struct delayed_work vt1708_hp_work;
162 int vt1708_jack_detectect;
163 int vt1708_hp_present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800164
165 void (*set_widgets_power_state)(struct hda_codec *codec);
166
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800167#ifdef CONFIG_SND_HDA_POWER_SAVE
168 struct hda_loopback_check loopback;
169#endif
170};
171
Lydia Wang0341ccd2011-03-22 16:25:03 +0800172static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100173static struct via_spec * via_new_spec(struct hda_codec *codec)
174{
175 struct via_spec *spec;
176
177 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
178 if (spec == NULL)
179 return NULL;
180
181 codec->spec = spec;
182 spec->codec = codec;
Lydia Wang0341ccd2011-03-22 16:25:03 +0800183 spec->codec_type = get_codec_type(codec);
184 /* VT1708BCE & VT1708S are almost same */
185 if (spec->codec_type == VT1708BCE)
186 spec->codec_type = VT1708S;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100187 return spec;
188}
189
Lydia Wang744ff5f2009-10-10 19:07:26 +0800190static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800191{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800192 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800193 u16 ven_id = vendor_id >> 16;
194 u16 dev_id = vendor_id & 0xffff;
195 enum VIA_HDA_CODEC codec_type;
196
197 /* get codec type */
198 if (ven_id != 0x1106)
199 codec_type = UNKNOWN;
200 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
201 codec_type = VT1708;
202 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
203 codec_type = VT1709_10CH;
204 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
205 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800206 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800207 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800208 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
209 codec_type = VT1708BCE;
210 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800211 codec_type = VT1708B_4CH;
212 else if ((dev_id & 0xfff) == 0x397
213 && (dev_id >> 12) < 8)
214 codec_type = VT1708S;
215 else if ((dev_id & 0xfff) == 0x398
216 && (dev_id >> 12) < 8)
217 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800218 else if ((dev_id & 0xfff) == 0x428
219 && (dev_id >> 12) < 8)
220 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800221 else if (dev_id == 0x0433 || dev_id == 0xa721)
222 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800223 else if (dev_id == 0x0441 || dev_id == 0x4441)
224 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800225 else if (dev_id == 0x0438 || dev_id == 0x4438)
226 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800227 else if (dev_id == 0x0448)
228 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800229 else if (dev_id == 0x0440)
230 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800231 else if ((dev_id & 0xfff) == 0x446)
232 codec_type = VT1802;
Harald Welted7426322008-09-15 22:43:23 +0800233 else
234 codec_type = UNKNOWN;
235 return codec_type;
236};
237
Lydia Wangec7e7e42011-03-24 12:43:44 +0800238#define VIA_JACK_EVENT 0x20
Harald Welte69e52a82008-09-09 15:57:32 +0800239#define VIA_HP_EVENT 0x01
240#define VIA_GPIO_EVENT 0x02
Lydia Wangec7e7e42011-03-24 12:43:44 +0800241#define VIA_MONO_EVENT 0x03
242#define VIA_SPEAKER_EVENT 0x04
243#define VIA_BIND_HP_EVENT 0x05
Harald Welte69e52a82008-09-09 15:57:32 +0800244
Joseph Chanc577b8a2006-11-29 15:29:40 +0100245enum {
246 VIA_CTL_WIDGET_VOL,
247 VIA_CTL_WIDGET_MUTE,
Lydia Wangf5271102009-10-10 19:07:35 +0800248 VIA_CTL_WIDGET_ANALOG_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800249 VIA_CTL_WIDGET_BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100250};
251
252enum {
Harald Welteeb14a462008-09-09 15:40:38 +0800253 AUTO_SEQ_FRONT = 0,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100254 AUTO_SEQ_SURROUND,
255 AUTO_SEQ_CENLFE,
256 AUTO_SEQ_SIDE
257};
258
Lydia Wangf5271102009-10-10 19:07:35 +0800259static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800260static int is_aa_path_mute(struct hda_codec *codec);
261
262static void vt1708_start_hp_work(struct via_spec *spec)
263{
264 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
265 return;
266 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
267 !spec->vt1708_jack_detectect);
268 if (!delayed_work_pending(&spec->vt1708_hp_work))
269 schedule_delayed_work(&spec->vt1708_hp_work,
270 msecs_to_jiffies(100));
271}
272
273static void vt1708_stop_hp_work(struct via_spec *spec)
274{
275 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
276 return;
277 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
278 && !is_aa_path_mute(spec->codec))
279 return;
280 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
281 !spec->vt1708_jack_detectect);
Tejun Heo5b84ba22010-12-11 17:51:26 +0100282 cancel_delayed_work_sync(&spec->vt1708_hp_work);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800283}
Lydia Wangf5271102009-10-10 19:07:35 +0800284
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800285static void set_widgets_power_state(struct hda_codec *codec)
286{
287 struct via_spec *spec = codec->spec;
288 if (spec->set_widgets_power_state)
289 spec->set_widgets_power_state(codec);
290}
Lydia Wang25eaba22009-10-10 19:08:43 +0800291
Lydia Wangf5271102009-10-10 19:07:35 +0800292static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_value *ucontrol)
294{
295 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
296 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
297
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800298 set_widgets_power_state(codec);
Lydia Wangf5271102009-10-10 19:07:35 +0800299 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800300 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
301 if (is_aa_path_mute(codec))
302 vt1708_start_hp_work(codec->spec);
303 else
304 vt1708_stop_hp_work(codec->spec);
305 }
Lydia Wangf5271102009-10-10 19:07:35 +0800306 return change;
307}
308
309/* modify .put = snd_hda_mixer_amp_switch_put */
310#define ANALOG_INPUT_MUTE \
311 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
312 .name = NULL, \
313 .index = 0, \
314 .info = snd_hda_mixer_amp_switch_info, \
315 .get = snd_hda_mixer_amp_switch_get, \
316 .put = analog_input_switch_put, \
317 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
318
Lydia Wang25eaba22009-10-10 19:08:43 +0800319static void via_hp_bind_automute(struct hda_codec *codec);
320
321static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
322 struct snd_ctl_elem_value *ucontrol)
323{
324 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
325 struct via_spec *spec = codec->spec;
326 int i;
327 int change = 0;
328
329 long *valp = ucontrol->value.integer.value;
330 int lmute, rmute;
331 if (strstr(kcontrol->id.name, "Switch") == NULL) {
332 snd_printd("Invalid control!\n");
333 return change;
334 }
335 change = snd_hda_mixer_amp_switch_put(kcontrol,
336 ucontrol);
337 /* Get mute value */
338 lmute = *valp ? 0 : HDA_AMP_MUTE;
339 valp++;
340 rmute = *valp ? 0 : HDA_AMP_MUTE;
341
342 /* Set hp pins */
343 if (!spec->hp_independent_mode) {
344 for (i = 0; i < spec->autocfg.hp_outs; i++) {
345 snd_hda_codec_amp_update(
346 codec, spec->autocfg.hp_pins[i],
347 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
348 lmute);
349 snd_hda_codec_amp_update(
350 codec, spec->autocfg.hp_pins[i],
351 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
352 rmute);
353 }
354 }
355
356 if (!lmute && !rmute) {
357 /* Line Outs */
358 for (i = 0; i < spec->autocfg.line_outs; i++)
359 snd_hda_codec_amp_stereo(
360 codec, spec->autocfg.line_out_pins[i],
361 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
362 /* Speakers */
363 for (i = 0; i < spec->autocfg.speaker_outs; i++)
364 snd_hda_codec_amp_stereo(
365 codec, spec->autocfg.speaker_pins[i],
366 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
367 /* unmute */
368 via_hp_bind_automute(codec);
369
370 } else {
371 if (lmute) {
372 /* Mute all left channels */
373 for (i = 1; i < spec->autocfg.line_outs; i++)
374 snd_hda_codec_amp_update(
375 codec,
376 spec->autocfg.line_out_pins[i],
377 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
378 lmute);
379 for (i = 0; i < spec->autocfg.speaker_outs; i++)
380 snd_hda_codec_amp_update(
381 codec,
382 spec->autocfg.speaker_pins[i],
383 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
384 lmute);
385 }
386 if (rmute) {
387 /* mute all right channels */
388 for (i = 1; i < spec->autocfg.line_outs; i++)
389 snd_hda_codec_amp_update(
390 codec,
391 spec->autocfg.line_out_pins[i],
392 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
393 rmute);
394 for (i = 0; i < spec->autocfg.speaker_outs; i++)
395 snd_hda_codec_amp_update(
396 codec,
397 spec->autocfg.speaker_pins[i],
398 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
399 rmute);
400 }
401 }
402 return change;
403}
404
405#define BIND_PIN_MUTE \
406 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
407 .name = NULL, \
408 .index = 0, \
409 .info = snd_hda_mixer_amp_switch_info, \
410 .get = snd_hda_mixer_amp_switch_get, \
411 .put = bind_pin_switch_put, \
412 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
413
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200414static const struct snd_kcontrol_new via_control_templates[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100415 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
416 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Lydia Wangf5271102009-10-10 19:07:35 +0800417 ANALOG_INPUT_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800418 BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100419};
420
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200421static const hda_nid_t vt1708_adc_nids[2] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100422 /* ADC1-2 */
423 0x15, 0x27
424};
425
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200426static const hda_nid_t vt1709_adc_nids[3] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100427 /* ADC1-2 */
428 0x14, 0x15, 0x16
429};
430
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200431static const hda_nid_t vt1708B_adc_nids[2] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +0100432 /* ADC1-2 */
433 0x13, 0x14
434};
435
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200436static const hda_nid_t vt1708S_adc_nids[2] = {
Harald Welted949cac2008-09-09 15:56:01 +0800437 /* ADC1-2 */
438 0x13, 0x14
439};
440
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200441static const hda_nid_t vt1702_adc_nids[3] = {
Harald Welted949cac2008-09-09 15:56:01 +0800442 /* ADC1-2 */
443 0x12, 0x20, 0x1F
444};
445
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200446static const hda_nid_t vt1718S_adc_nids[2] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +0800447 /* ADC1-2 */
448 0x10, 0x11
449};
450
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200451static const hda_nid_t vt1716S_adc_nids[2] = {
Lydia Wangf3db4232009-10-10 19:08:41 +0800452 /* ADC1-2 */
453 0x13, 0x14
454};
455
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200456static const hda_nid_t vt2002P_adc_nids[2] = {
Lydia Wang25eaba22009-10-10 19:08:43 +0800457 /* ADC1-2 */
458 0x10, 0x11
459};
460
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200461static const hda_nid_t vt1812_adc_nids[2] = {
Lydia Wangab6734e2009-10-10 19:08:46 +0800462 /* ADC1-2 */
463 0x10, 0x11
464};
465
466
Joseph Chanc577b8a2006-11-29 15:29:40 +0100467/* add dynamic controls */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200468static int __via_add_control(struct via_spec *spec, int type, const char *name,
469 int idx, unsigned long val)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100470{
471 struct snd_kcontrol_new *knew;
472
Takashi Iwai603c4012008-07-30 15:01:44 +0200473 snd_array_init(&spec->kctls, sizeof(*knew), 32);
474 knew = snd_array_new(&spec->kctls);
475 if (!knew)
476 return -ENOMEM;
Lydia Wang71eb7dc2009-10-10 19:08:49 +0800477 *knew = via_control_templates[type];
Joseph Chanc577b8a2006-11-29 15:29:40 +0100478 knew->name = kstrdup(name, GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100479 if (!knew->name)
480 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100481 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100482 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100483 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100484 return 0;
485}
486
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200487#define via_add_control(spec, type, name, val) \
488 __via_add_control(spec, type, name, 0, val)
489
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100490static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200491 const struct snd_kcontrol_new *tmpl)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100492{
493 struct snd_kcontrol_new *knew;
494
495 snd_array_init(&spec->kctls, sizeof(*knew), 32);
496 knew = snd_array_new(&spec->kctls);
497 if (!knew)
498 return NULL;
499 *knew = *tmpl;
500 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
501 if (!knew->name)
502 return NULL;
Takashi Iwaib3314392010-04-14 14:33:57 +0200503 return knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100504}
505
Takashi Iwai603c4012008-07-30 15:01:44 +0200506static void via_free_kctls(struct hda_codec *codec)
507{
508 struct via_spec *spec = codec->spec;
509
510 if (spec->kctls.list) {
511 struct snd_kcontrol_new *kctl = spec->kctls.list;
512 int i;
513 for (i = 0; i < spec->kctls.used; i++)
514 kfree(kctl[i].name);
515 }
516 snd_array_free(&spec->kctls);
517}
518
Joseph Chanc577b8a2006-11-29 15:29:40 +0100519/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800520static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200521 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100522{
523 char name[32];
524 int err;
525
526 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200527 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100528 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
529 if (err < 0)
530 return err;
531 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200532 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100533 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
534 if (err < 0)
535 return err;
536 return 0;
537}
538
539static void via_auto_set_output_and_unmute(struct hda_codec *codec,
540 hda_nid_t nid, int pin_type,
541 int dac_idx)
542{
543 /* set as output */
544 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
545 pin_type);
546 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
547 AMP_OUT_UNMUTE);
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200548 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
Lydia Wang377ff312009-10-10 19:08:55 +0800549 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200550 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100551}
552
553
554static void via_auto_init_multi_out(struct hda_codec *codec)
555{
556 struct via_spec *spec = codec->spec;
557 int i;
558
559 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
560 hda_nid_t nid = spec->autocfg.line_out_pins[i];
561 if (nid)
562 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
563 }
564}
565
566static void via_auto_init_hp_out(struct hda_codec *codec)
567{
568 struct via_spec *spec = codec->spec;
569 hda_nid_t pin;
Lydia Wang25eaba22009-10-10 19:08:43 +0800570 int i;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100571
Lydia Wang25eaba22009-10-10 19:08:43 +0800572 for (i = 0; i < spec->autocfg.hp_outs; i++) {
573 pin = spec->autocfg.hp_pins[i];
574 if (pin) /* connect to front */
575 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
576 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100577}
578
Clemens Ladisch32e01912010-07-12 16:28:50 +0200579static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
580
Joseph Chanc577b8a2006-11-29 15:29:40 +0100581static void via_auto_init_analog_input(struct hda_codec *codec)
582{
583 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200584 const struct auto_pin_cfg *cfg = &spec->autocfg;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200585 unsigned int ctl;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100586 int i;
587
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200588 for (i = 0; i < cfg->num_inputs; i++) {
589 hda_nid_t nid = cfg->inputs[i].pin;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200590 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
591 ctl = PIN_OUT;
David Henningsson30649672011-02-21 10:23:18 +0100592 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
Clemens Ladisch32e01912010-07-12 16:28:50 +0200593 ctl = PIN_VREF50;
594 else
595 ctl = PIN_IN;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100596 snd_hda_codec_write(codec, nid, 0,
Clemens Ladisch32e01912010-07-12 16:28:50 +0200597 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100598 }
599}
Lydia Wangf5271102009-10-10 19:07:35 +0800600
601static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
602 unsigned int *affected_parm)
603{
604 unsigned parm;
605 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
606 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
607 >> AC_DEFCFG_MISC_SHIFT
608 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800609 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200610 unsigned present = 0;
611
612 no_presence |= spec->no_pin_power_ctl;
613 if (!no_presence)
614 present = snd_hda_jack_detect(codec, nid);
Lydia Wang1564b282009-10-10 19:07:52 +0800615 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
616 || ((no_presence || present)
617 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800618 *affected_parm = AC_PWRST_D0; /* if it's connected */
619 parm = AC_PWRST_D0;
620 } else
621 parm = AC_PWRST_D3;
622
623 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
624}
625
Takashi Iwai24088a52011-06-17 16:59:21 +0200626static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
627 struct snd_ctl_elem_info *uinfo)
628{
629 static const char * const texts[] = {
630 "Disabled", "Enabled"
631 };
632
633 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
634 uinfo->count = 1;
635 uinfo->value.enumerated.items = 2;
636 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
637 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
638 strcpy(uinfo->value.enumerated.name,
639 texts[uinfo->value.enumerated.item]);
640 return 0;
641}
642
643static int via_pin_power_ctl_get(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 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
649 return 0;
650}
651
652static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
653 struct snd_ctl_elem_value *ucontrol)
654{
655 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
656 struct via_spec *spec = codec->spec;
657 unsigned int val = !ucontrol->value.enumerated.item[0];
658
659 if (val == spec->no_pin_power_ctl)
660 return 0;
661 spec->no_pin_power_ctl = val;
662 set_widgets_power_state(codec);
663 return 1;
664}
665
666static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
667 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
668 .name = "Dynamic Power-Control",
669 .info = via_pin_power_ctl_info,
670 .get = via_pin_power_ctl_get,
671 .put = via_pin_power_ctl_put,
672};
673
674
Joseph Chanc577b8a2006-11-29 15:29:40 +0100675/*
676 * input MUX handling
677 */
678static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
679 struct snd_ctl_elem_info *uinfo)
680{
681 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
682 struct via_spec *spec = codec->spec;
683 return snd_hda_input_mux_info(spec->input_mux, uinfo);
684}
685
686static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
687 struct snd_ctl_elem_value *ucontrol)
688{
689 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
690 struct via_spec *spec = codec->spec;
691 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
692
693 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
694 return 0;
695}
696
697static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
698 struct snd_ctl_elem_value *ucontrol)
699{
700 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
701 struct via_spec *spec = codec->spec;
702 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800703 int ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100704
Takashi Iwai337b9d02009-07-07 18:18:59 +0200705 if (!spec->mux_nids[adc_idx])
706 return -EINVAL;
Lydia Wanga80e6e32009-10-10 19:07:55 +0800707 /* switch to D0 beofre change index */
708 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
709 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
710 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
711 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800712
713 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
714 spec->mux_nids[adc_idx],
715 &spec->cur_mux[adc_idx]);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800716 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800717 set_widgets_power_state(codec);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800718
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800719 return ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100720}
721
Harald Welte0aa62ae2008-09-09 15:58:27 +0800722static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
723 struct snd_ctl_elem_info *uinfo)
724{
725 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
726 struct via_spec *spec = codec->spec;
727 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
728}
729
730static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
731 struct snd_ctl_elem_value *ucontrol)
732{
733 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100734 hda_nid_t nid = kcontrol->private_value;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800735 unsigned int pinsel;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800736
Lydia Wangeb7188c2009-10-10 19:08:34 +0800737 /* use !! to translate conn sel 2 for VT1718S */
738 pinsel = !!snd_hda_codec_read(codec, nid, 0,
739 AC_VERB_GET_CONNECT_SEL,
740 0x00);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800741 ucontrol->value.enumerated.item[0] = pinsel;
742
743 return 0;
744}
745
Lydia Wang0713efe2009-10-10 19:07:43 +0800746static void activate_ctl(struct hda_codec *codec, const char *name, int active)
747{
748 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
749 if (ctl) {
750 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
751 ctl->vd[0].access |= active
752 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
753 snd_ctl_notify(codec->bus->card,
754 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
755 }
756}
757
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100758static hda_nid_t side_mute_channel(struct via_spec *spec)
759{
760 switch (spec->codec_type) {
761 case VT1708: return 0x1b;
762 case VT1709_10CH: return 0x29;
763 case VT1708B_8CH: /* fall thru */
764 case VT1708S: return 0x27;
Lydia Wange87885f2011-03-24 12:39:05 +0800765 case VT2002P: return 0x19;
766 case VT1802: return 0x15;
767 case VT1812: return 0x15;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100768 default: return 0;
769 }
770}
771
Lydia Wangcdc17842009-10-10 19:07:47 +0800772static int update_side_mute_status(struct hda_codec *codec)
773{
774 /* mute side channel */
775 struct via_spec *spec = codec->spec;
Lydia Wange87885f2011-03-24 12:39:05 +0800776 unsigned int parm;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100777 hda_nid_t sw3 = side_mute_channel(spec);
Lydia Wangcdc17842009-10-10 19:07:47 +0800778
Lydia Wange87885f2011-03-24 12:39:05 +0800779 if (sw3) {
780 if (VT2002P_COMPATIBLE(spec))
781 parm = spec->hp_independent_mode ?
782 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
783 else
784 parm = spec->hp_independent_mode ?
785 AMP_OUT_MUTE : AMP_OUT_UNMUTE;
786 snd_hda_codec_write(codec, sw3, 0,
787 AC_VERB_SET_AMP_GAIN_MUTE, parm);
788 if (spec->codec_type == VT1812)
789 snd_hda_codec_write(codec, 0x1d, 0,
790 AC_VERB_SET_AMP_GAIN_MUTE, parm);
791 }
Lydia Wangcdc17842009-10-10 19:07:47 +0800792 return 0;
793}
794
Harald Welte0aa62ae2008-09-09 15:58:27 +0800795static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
796 struct snd_ctl_elem_value *ucontrol)
797{
798 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
799 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100800 hda_nid_t nid = kcontrol->private_value;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800801 unsigned int pinsel = ucontrol->value.enumerated.item[0];
Lydia Wangcdc17842009-10-10 19:07:47 +0800802 /* Get Independent Mode index of headphone pin widget */
803 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
804 ? 1 : 0;
Lydia Wangce0e5a92011-03-22 16:22:37 +0800805 if (spec->codec_type == VT1718S)
806 snd_hda_codec_write(codec, nid, 0,
807 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
808 else
809 snd_hda_codec_write(codec, nid, 0,
810 AC_VERB_SET_CONNECT_SEL, pinsel);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800811
Lydia Wangce0e5a92011-03-22 16:22:37 +0800812 if (spec->codec_type == VT1812)
813 snd_hda_codec_write(codec, 0x35, 0,
814 AC_VERB_SET_CONNECT_SEL, pinsel);
Lydia Wangcdc17842009-10-10 19:07:47 +0800815 if (spec->multiout.hp_nid && spec->multiout.hp_nid
816 != spec->multiout.dac_nids[HDA_FRONT])
817 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
818 0, 0, 0);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800819
Lydia Wangcdc17842009-10-10 19:07:47 +0800820 update_side_mute_status(codec);
Lydia Wang0713efe2009-10-10 19:07:43 +0800821 /* update HP volume/swtich active state */
822 if (spec->codec_type == VT1708S
Lydia Wangeb7188c2009-10-10 19:08:34 +0800823 || spec->codec_type == VT1702
Lydia Wangf3db4232009-10-10 19:08:41 +0800824 || spec->codec_type == VT1718S
Lydia Wang25eaba22009-10-10 19:08:43 +0800825 || spec->codec_type == VT1716S
Lydia Wang118909562011-03-23 17:57:34 +0800826 || VT2002P_COMPATIBLE(spec)) {
Lydia Wang0713efe2009-10-10 19:07:43 +0800827 activate_ctl(codec, "Headphone Playback Volume",
828 spec->hp_independent_mode);
829 activate_ctl(codec, "Headphone Playback Switch",
830 spec->hp_independent_mode);
831 }
Lydia Wangce0e5a92011-03-22 16:22:37 +0800832 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800833 set_widgets_power_state(codec);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800834 return 0;
835}
836
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200837static const struct snd_kcontrol_new via_hp_mixer[2] = {
Harald Welte0aa62ae2008-09-09 15:58:27 +0800838 {
839 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
840 .name = "Independent HP",
Harald Welte0aa62ae2008-09-09 15:58:27 +0800841 .info = via_independent_hp_info,
842 .get = via_independent_hp_get,
843 .put = via_independent_hp_put,
844 },
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100845 {
846 .iface = NID_MAPPING,
847 .name = "Independent HP",
848 },
Harald Welte0aa62ae2008-09-09 15:58:27 +0800849};
850
Takashi Iwai3d83e572010-04-14 14:36:23 +0200851static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100852{
Takashi Iwai3d83e572010-04-14 14:36:23 +0200853 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100854 struct snd_kcontrol_new *knew;
855 hda_nid_t nid;
Takashi Iwai3d83e572010-04-14 14:36:23 +0200856 int nums;
857 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100858
859 switch (spec->codec_type) {
860 case VT1718S:
861 nid = 0x34;
862 break;
863 case VT2002P:
Lydia Wang118909562011-03-23 17:57:34 +0800864 case VT1802:
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100865 nid = 0x35;
866 break;
867 case VT1812:
868 nid = 0x3d;
869 break;
870 default:
871 nid = spec->autocfg.hp_pins[0];
872 break;
873 }
874
Lydia Wangee3c35c2011-03-22 16:26:36 +0800875 if (spec->codec_type != VT1708) {
876 nums = snd_hda_get_connections(codec, nid,
877 conn, HDA_MAX_CONNECTIONS);
878 if (nums <= 1)
879 return 0;
880 }
Takashi Iwai3d83e572010-04-14 14:36:23 +0200881
882 knew = via_clone_control(spec, &via_hp_mixer[0]);
883 if (knew == NULL)
884 return -ENOMEM;
885
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100886 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
887 knew->private_value = nid;
888
889 knew = via_clone_control(spec, &via_hp_mixer[1]);
890 if (knew == NULL)
891 return -ENOMEM;
892 knew->subdevice = side_mute_channel(spec);
893
894 return 0;
895}
896
Lydia Wang1564b282009-10-10 19:07:52 +0800897static void notify_aa_path_ctls(struct hda_codec *codec)
898{
899 int i;
900 struct snd_ctl_elem_id id;
Lydia Wang525566c2011-04-28 16:03:39 +0800901 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
902 struct snd_kcontrol *ctl;
Lydia Wang1564b282009-10-10 19:07:52 +0800903
904 memset(&id, 0, sizeof(id));
905 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
906 for (i = 0; i < ARRAY_SIZE(labels); i++) {
907 sprintf(id.name, "%s Playback Volume", labels[i]);
Lydia Wang525566c2011-04-28 16:03:39 +0800908 ctl = snd_hda_find_mixer_ctl(codec, id.name);
909 if (ctl)
910 snd_ctl_notify(codec->bus->card,
911 SNDRV_CTL_EVENT_MASK_VALUE,
912 &ctl->id);
Lydia Wang1564b282009-10-10 19:07:52 +0800913 }
914}
915
916static void mute_aa_path(struct hda_codec *codec, int mute)
917{
918 struct via_spec *spec = codec->spec;
919 hda_nid_t nid_mixer;
920 int start_idx;
921 int end_idx;
922 int i;
923 /* get nid of MW0 and start & end index */
924 switch (spec->codec_type) {
925 case VT1708:
926 nid_mixer = 0x17;
927 start_idx = 2;
928 end_idx = 4;
929 break;
930 case VT1709_10CH:
931 case VT1709_6CH:
932 nid_mixer = 0x18;
933 start_idx = 2;
934 end_idx = 4;
935 break;
936 case VT1708B_8CH:
937 case VT1708B_4CH:
938 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +0800939 case VT1716S:
Lydia Wang1564b282009-10-10 19:07:52 +0800940 nid_mixer = 0x16;
941 start_idx = 2;
942 end_idx = 4;
943 break;
Lydia Wangab657e02011-03-22 16:23:23 +0800944 case VT1718S:
945 nid_mixer = 0x21;
946 start_idx = 1;
947 end_idx = 3;
948 break;
Lydia Wang1564b282009-10-10 19:07:52 +0800949 default:
950 return;
951 }
952 /* check AA path's mute status */
953 for (i = start_idx; i <= end_idx; i++) {
954 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
955 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
956 HDA_AMP_MUTE, val);
957 }
958}
959static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
960{
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200961 const struct auto_pin_cfg *cfg = &spec->autocfg;
962 int i;
963
964 for (i = 0; i < cfg->num_inputs; i++) {
965 if (pin == cfg->inputs[i].pin)
Takashi Iwai86e29592010-09-09 14:50:17 +0200966 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
Lydia Wang1564b282009-10-10 19:07:52 +0800967 }
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200968 return 0;
Lydia Wang1564b282009-10-10 19:07:52 +0800969}
970
971static int via_smart51_info(struct snd_kcontrol *kcontrol,
972 struct snd_ctl_elem_info *uinfo)
973{
974 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
975 uinfo->count = 1;
976 uinfo->value.integer.min = 0;
977 uinfo->value.integer.max = 1;
978 return 0;
979}
980
981static int via_smart51_get(struct snd_kcontrol *kcontrol,
982 struct snd_ctl_elem_value *ucontrol)
983{
984 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
985 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200986 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800987 int on = 1;
988 int i;
989
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200990 for (i = 0; i < cfg->num_inputs; i++) {
991 hda_nid_t nid = cfg->inputs[i].pin;
992 int ctl = snd_hda_codec_read(codec, nid, 0,
993 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai86e29592010-09-09 14:50:17 +0200994 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200995 continue;
Takashi Iwai86e29592010-09-09 14:50:17 +0200996 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200997 spec->hp_independent_mode && spec->codec_type != VT1718S)
998 continue; /* ignore FMic for independent HP */
999 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
1000 on = 0;
Lydia Wang1564b282009-10-10 19:07:52 +08001001 }
1002 *ucontrol->value.integer.value = on;
1003 return 0;
1004}
1005
1006static int via_smart51_put(struct snd_kcontrol *kcontrol,
1007 struct snd_ctl_elem_value *ucontrol)
1008{
1009 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1010 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001011 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +08001012 int out_in = *ucontrol->value.integer.value
1013 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +08001014 int i;
1015
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001016 for (i = 0; i < cfg->num_inputs; i++) {
1017 hda_nid_t nid = cfg->inputs[i].pin;
1018 unsigned int parm;
1019
Takashi Iwai86e29592010-09-09 14:50:17 +02001020 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001021 continue;
Takashi Iwai86e29592010-09-09 14:50:17 +02001022 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001023 spec->hp_independent_mode && spec->codec_type != VT1718S)
Lydia Wang1564b282009-10-10 19:07:52 +08001024 continue; /* don't retask FMic for independent HP */
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001025
1026 parm = snd_hda_codec_read(codec, nid, 0,
1027 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1028 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1029 parm |= out_in;
1030 snd_hda_codec_write(codec, nid, 0,
1031 AC_VERB_SET_PIN_WIDGET_CONTROL,
1032 parm);
1033 if (out_in == AC_PINCTL_OUT_EN) {
1034 mute_aa_path(codec, 1);
1035 notify_aa_path_ctls(codec);
1036 }
1037 if (spec->codec_type == VT1718S) {
1038 snd_hda_codec_amp_stereo(
Lydia Wangeb7188c2009-10-10 19:08:34 +08001039 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1040 HDA_AMP_UNMUTE);
Lydia Wang1564b282009-10-10 19:07:52 +08001041 }
Takashi Iwai86e29592010-09-09 14:50:17 +02001042 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
Lydia Wangf3db4232009-10-10 19:08:41 +08001043 if (spec->codec_type == VT1708S
1044 || spec->codec_type == VT1716S) {
Lydia Wang1564b282009-10-10 19:07:52 +08001045 /* input = index 1 (AOW3) */
1046 snd_hda_codec_write(
1047 codec, nid, 0,
1048 AC_VERB_SET_CONNECT_SEL, 1);
1049 snd_hda_codec_amp_stereo(
1050 codec, nid, HDA_OUTPUT,
1051 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1052 }
1053 }
1054 }
1055 spec->smart51_enabled = *ucontrol->value.integer.value;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001056 set_widgets_power_state(codec);
Lydia Wang1564b282009-10-10 19:07:52 +08001057 return 1;
1058}
1059
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001060static const struct snd_kcontrol_new via_smart51_mixer = {
1061 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1062 .name = "Smart 5.1",
1063 .count = 1,
1064 .info = via_smart51_info,
1065 .get = via_smart51_get,
1066 .put = via_smart51_put,
Lydia Wang1564b282009-10-10 19:07:52 +08001067};
1068
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001069static int via_smart51_build(struct via_spec *spec)
1070{
1071 struct snd_kcontrol_new *knew;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001072 const struct auto_pin_cfg *cfg = &spec->autocfg;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001073 hda_nid_t nid;
1074 int i;
1075
Lydia Wangcb34c202011-04-27 17:44:16 +08001076 if (!cfg)
1077 return 0;
1078 if (cfg->line_outs > 2)
1079 return 0;
1080
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001081 knew = via_clone_control(spec, &via_smart51_mixer);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001082 if (knew == NULL)
1083 return -ENOMEM;
1084
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001085 for (i = 0; i < cfg->num_inputs; i++) {
1086 nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02001087 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001088 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001089 break;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001090 }
1091 }
1092
1093 return 0;
1094}
1095
Joseph Chanc577b8a2006-11-29 15:29:40 +01001096/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001097static const struct snd_kcontrol_new vt1708_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001098 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1099 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1100 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1101 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1102 {
1103 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1104 /* The multiple "Capture Source" controls confuse alsamixer
1105 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01001106 */
1107 /* .name = "Capture Source", */
1108 .name = "Input Source",
1109 .count = 1,
1110 .info = via_mux_enum_info,
1111 .get = via_mux_enum_get,
1112 .put = via_mux_enum_put,
1113 },
1114 { } /* end */
1115};
Lydia Wangf5271102009-10-10 19:07:35 +08001116
1117/* check AA path's mute statue */
1118static int is_aa_path_mute(struct hda_codec *codec)
1119{
1120 int mute = 1;
1121 hda_nid_t nid_mixer;
1122 int start_idx;
1123 int end_idx;
1124 int i;
1125 struct via_spec *spec = codec->spec;
1126 /* get nid of MW0 and start & end index */
1127 switch (spec->codec_type) {
1128 case VT1708B_8CH:
1129 case VT1708B_4CH:
1130 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001131 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001132 nid_mixer = 0x16;
1133 start_idx = 2;
1134 end_idx = 4;
1135 break;
1136 case VT1702:
1137 nid_mixer = 0x1a;
1138 start_idx = 1;
1139 end_idx = 3;
1140 break;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001141 case VT1718S:
1142 nid_mixer = 0x21;
1143 start_idx = 1;
1144 end_idx = 3;
1145 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001146 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001147 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001148 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001149 nid_mixer = 0x21;
1150 start_idx = 0;
1151 end_idx = 2;
1152 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001153 default:
1154 return 0;
1155 }
1156 /* check AA path's mute status */
1157 for (i = start_idx; i <= end_idx; i++) {
1158 unsigned int con_list = snd_hda_codec_read(
1159 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1160 int shift = 8 * (i % 4);
1161 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1162 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1163 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1164 /* check mute status while the pin is connected */
1165 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1166 HDA_INPUT, i) >> 7;
1167 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1168 HDA_INPUT, i) >> 7;
1169 if (!mute_l || !mute_r) {
1170 mute = 0;
1171 break;
1172 }
1173 }
1174 }
1175 return mute;
1176}
1177
1178/* enter/exit analog low-current mode */
1179static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1180{
1181 struct via_spec *spec = codec->spec;
1182 static int saved_stream_idle = 1; /* saved stream idle status */
1183 int enable = is_aa_path_mute(codec);
1184 unsigned int verb = 0;
1185 unsigned int parm = 0;
1186
1187 if (stream_idle == -1) /* stream status did not change */
1188 enable = enable && saved_stream_idle;
1189 else {
1190 enable = enable && stream_idle;
1191 saved_stream_idle = stream_idle;
1192 }
1193
1194 /* decide low current mode's verb & parameter */
1195 switch (spec->codec_type) {
1196 case VT1708B_8CH:
1197 case VT1708B_4CH:
1198 verb = 0xf70;
1199 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1200 break;
1201 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001202 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001203 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001204 verb = 0xf73;
1205 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1206 break;
1207 case VT1702:
1208 verb = 0xf73;
1209 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1210 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001211 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001212 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001213 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001214 verb = 0xf93;
1215 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1216 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001217 default:
1218 return; /* other codecs are not supported */
1219 }
1220 /* send verb */
1221 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1222}
1223
Joseph Chanc577b8a2006-11-29 15:29:40 +01001224/*
1225 * generic initialization of ADC, input mixers and output mixers
1226 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001227static const struct hda_verb vt1708_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001228 /*
1229 * Unmute ADC0-1 and set the default input to mic-in
1230 */
1231 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1232 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1233
1234
Josepch Chanf7278fd2007-12-13 16:40:40 +01001235 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01001236 * mixer widget
1237 */
1238 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01001239 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1240 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1241 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1242 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1243 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001244
1245 /*
1246 * Set up output mixers (0x19 - 0x1b)
1247 */
1248 /* set vol=0 to output mixers */
1249 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1250 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1251 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Lydia Wang377ff312009-10-10 19:08:55 +08001252
Lydia Wangbfdc6752009-10-10 19:08:50 +08001253 /* Setup default input MW0 to PW4 */
1254 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001255 /* PW9 Output enable */
1256 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangaa266fc2011-03-24 12:41:01 +08001257 /* power down jack detect function */
1258 {0x1, 0xf81, 0x1},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001259 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001260};
1261
1262static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1263 struct hda_codec *codec,
1264 struct snd_pcm_substream *substream)
1265{
1266 struct via_spec *spec = codec->spec;
Lydia Wang17314372009-10-10 19:07:37 +08001267 int idle = substream->pstr->substream_opened == 1
1268 && substream->ref_count == 0;
Lydia Wang17314372009-10-10 19:07:37 +08001269 analog_low_current_mode(codec, idle);
Takashi Iwai9a081602008-02-12 18:37:26 +01001270 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1271 hinfo);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001272}
1273
Harald Welte0aa62ae2008-09-09 15:58:27 +08001274static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1275 unsigned int stream_tag,
1276 unsigned int format,
1277 struct snd_pcm_substream *substream)
1278{
1279 struct via_spec *spec = codec->spec;
1280 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001281 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001282 int chs = substream->runtime->channels;
1283 int i;
Stephen Warren7c935972011-06-01 11:14:17 -06001284 struct hda_spdif_out *spdif =
1285 snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001286
1287 mutex_lock(&codec->spdif_mutex);
1288 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1289 if (chs == 2 &&
1290 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1291 format) &&
Stephen Warren7c935972011-06-01 11:14:17 -06001292 !(spdif->status & IEC958_AES0_NONAUDIO)) {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001293 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1294 /* turn off SPDIF once; otherwise the IEC958 bits won't
1295 * be updated */
Stephen Warren7c935972011-06-01 11:14:17 -06001296 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001297 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1298 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001299 spdif->ctls &
Harald Welte0aa62ae2008-09-09 15:58:27 +08001300 ~AC_DIG1_ENABLE & 0xff);
1301 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1302 stream_tag, 0, format);
1303 /* turn on again (if needed) */
Stephen Warren7c935972011-06-01 11:14:17 -06001304 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001305 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1306 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001307 spdif->ctls & 0xff);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001308 } else {
1309 mout->dig_out_used = 0;
1310 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1311 0, 0, 0);
1312 }
1313 }
1314 mutex_unlock(&codec->spdif_mutex);
1315
1316 /* front */
1317 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1318 0, format);
1319
Lydia Wangeb7188c2009-10-10 19:08:34 +08001320 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1321 && !spec->hp_independent_mode)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001322 /* headphone out will just decode front left/right (stereo) */
1323 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1324 0, format);
1325
1326 /* extra outputs copied from front */
1327 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1328 if (mout->extra_out_nid[i])
1329 snd_hda_codec_setup_stream(codec,
1330 mout->extra_out_nid[i],
1331 stream_tag, 0, format);
1332
1333 /* surrounds */
1334 for (i = 1; i < mout->num_dacs; i++) {
1335 if (chs >= (i + 1) * 2) /* independent out */
1336 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1337 i * 2, format);
1338 else /* copy front */
1339 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1340 0, format);
1341 }
1342}
1343
1344static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1345 struct hda_codec *codec,
1346 unsigned int stream_tag,
1347 unsigned int format,
1348 struct snd_pcm_substream *substream)
1349{
1350 struct via_spec *spec = codec->spec;
1351 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001352 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001353
1354 if (substream->number == 0)
1355 playback_multi_pcm_prep_0(codec, stream_tag, format,
1356 substream);
1357 else {
1358 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1359 spec->hp_independent_mode)
1360 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1361 stream_tag, 0, format);
1362 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001363 vt1708_start_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001364 return 0;
1365}
1366
1367static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1368 struct hda_codec *codec,
1369 struct snd_pcm_substream *substream)
1370{
1371 struct via_spec *spec = codec->spec;
1372 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001373 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001374 int i;
1375
1376 if (substream->number == 0) {
1377 for (i = 0; i < mout->num_dacs; i++)
1378 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1379
1380 if (mout->hp_nid && !spec->hp_independent_mode)
1381 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1382 0, 0, 0);
1383
1384 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1385 if (mout->extra_out_nid[i])
1386 snd_hda_codec_setup_stream(codec,
1387 mout->extra_out_nid[i],
1388 0, 0, 0);
1389 mutex_lock(&codec->spdif_mutex);
1390 if (mout->dig_out_nid &&
1391 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1392 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1393 0, 0, 0);
1394 mout->dig_out_used = 0;
1395 }
1396 mutex_unlock(&codec->spdif_mutex);
1397 } else {
1398 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1399 spec->hp_independent_mode)
1400 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1401 0, 0, 0);
1402 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001403 vt1708_stop_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001404 return 0;
1405}
1406
Joseph Chanc577b8a2006-11-29 15:29:40 +01001407/*
1408 * Digital out
1409 */
1410static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1411 struct hda_codec *codec,
1412 struct snd_pcm_substream *substream)
1413{
1414 struct via_spec *spec = codec->spec;
1415 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1416}
1417
1418static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1419 struct hda_codec *codec,
1420 struct snd_pcm_substream *substream)
1421{
1422 struct via_spec *spec = codec->spec;
1423 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1424}
1425
Harald Welte5691ec72008-09-15 22:42:26 +08001426static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001427 struct hda_codec *codec,
1428 unsigned int stream_tag,
1429 unsigned int format,
1430 struct snd_pcm_substream *substream)
1431{
1432 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001433 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1434 stream_tag, format, substream);
1435}
Harald Welte5691ec72008-09-15 22:42:26 +08001436
Takashi Iwai9da29272009-05-07 16:31:14 +02001437static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1438 struct hda_codec *codec,
1439 struct snd_pcm_substream *substream)
1440{
1441 struct via_spec *spec = codec->spec;
1442 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001443 return 0;
1444}
1445
Joseph Chanc577b8a2006-11-29 15:29:40 +01001446/*
1447 * Analog capture
1448 */
1449static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1450 struct hda_codec *codec,
1451 unsigned int stream_tag,
1452 unsigned int format,
1453 struct snd_pcm_substream *substream)
1454{
1455 struct via_spec *spec = codec->spec;
1456
1457 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1458 stream_tag, 0, format);
1459 return 0;
1460}
1461
1462static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1463 struct hda_codec *codec,
1464 struct snd_pcm_substream *substream)
1465{
1466 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001467 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001468 return 0;
1469}
1470
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001471static const struct hda_pcm_stream vt1708_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001472 .substreams = 2,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001473 .channels_min = 2,
1474 .channels_max = 8,
1475 .nid = 0x10, /* NID to query formats and rates */
1476 .ops = {
1477 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001478 .prepare = via_playback_multi_pcm_prepare,
1479 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001480 },
1481};
1482
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001483static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Lydia Wangc873cc22009-10-10 19:08:21 +08001484 .substreams = 2,
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001485 .channels_min = 2,
1486 .channels_max = 8,
1487 .nid = 0x10, /* NID to query formats and rates */
1488 /* We got noisy outputs on the right channel on VT1708 when
1489 * 24bit samples are used. Until any workaround is found,
1490 * disable the 24bit format, so far.
1491 */
1492 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1493 .ops = {
1494 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08001495 .prepare = via_playback_multi_pcm_prepare,
1496 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001497 },
1498};
1499
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001500static const struct hda_pcm_stream vt1708_pcm_analog_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001501 .substreams = 2,
1502 .channels_min = 2,
1503 .channels_max = 2,
1504 .nid = 0x15, /* NID to query formats and rates */
1505 .ops = {
1506 .prepare = via_capture_pcm_prepare,
1507 .cleanup = via_capture_pcm_cleanup
1508 },
1509};
1510
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001511static const struct hda_pcm_stream vt1708_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001512 .substreams = 1,
1513 .channels_min = 2,
1514 .channels_max = 2,
1515 /* NID is set in via_build_pcms */
1516 .ops = {
1517 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001518 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001519 .prepare = via_dig_playback_pcm_prepare,
1520 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001521 },
1522};
1523
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001524static const struct hda_pcm_stream vt1708_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001525 .substreams = 1,
1526 .channels_min = 2,
1527 .channels_max = 2,
1528};
1529
1530static int via_build_controls(struct hda_codec *codec)
1531{
1532 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001533 struct snd_kcontrol *kctl;
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001534 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001535 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001536
Takashi Iwai24088a52011-06-17 16:59:21 +02001537 if (spec->set_widgets_power_state)
1538 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1539 return -ENOMEM;
1540
Joseph Chanc577b8a2006-11-29 15:29:40 +01001541 for (i = 0; i < spec->num_mixers; i++) {
1542 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1543 if (err < 0)
1544 return err;
1545 }
1546
1547 if (spec->multiout.dig_out_nid) {
1548 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001549 spec->multiout.dig_out_nid,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001550 spec->multiout.dig_out_nid);
1551 if (err < 0)
1552 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001553 err = snd_hda_create_spdif_share_sw(codec,
1554 &spec->multiout);
1555 if (err < 0)
1556 return err;
1557 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001558 }
1559 if (spec->dig_in_nid) {
1560 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1561 if (err < 0)
1562 return err;
1563 }
Lydia Wang17314372009-10-10 19:07:37 +08001564
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001565 /* assign Capture Source enums to NID */
1566 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1567 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +01001568 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001569 if (err < 0)
1570 return err;
1571 }
1572
1573 /* other nid->control mapping */
1574 for (i = 0; i < spec->num_mixers; i++) {
1575 for (knew = spec->mixers[i]; knew->name; knew++) {
1576 if (knew->iface != NID_MAPPING)
1577 continue;
1578 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1579 if (kctl == NULL)
1580 continue;
1581 err = snd_hda_add_nid(codec, kctl, 0,
1582 knew->subdevice);
1583 }
1584 }
1585
Lydia Wang17314372009-10-10 19:07:37 +08001586 /* init power states */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001587 set_widgets_power_state(codec);
Lydia Wang17314372009-10-10 19:07:37 +08001588 analog_low_current_mode(codec, 1);
1589
Takashi Iwai603c4012008-07-30 15:01:44 +02001590 via_free_kctls(codec); /* no longer needed */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001591 return 0;
1592}
1593
1594static int via_build_pcms(struct hda_codec *codec)
1595{
1596 struct via_spec *spec = codec->spec;
1597 struct hda_pcm *info = spec->pcm_rec;
1598
1599 codec->num_pcms = 1;
1600 codec->pcm_info = info;
1601
1602 info->name = spec->stream_name_analog;
Lydia Wang377ff312009-10-10 19:08:55 +08001603 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1604 *(spec->stream_analog_playback);
1605 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1606 spec->multiout.dac_nids[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001607 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1608 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1609
1610 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1611 spec->multiout.max_channels;
1612
1613 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1614 codec->num_pcms++;
1615 info++;
1616 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001617 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001618 if (spec->multiout.dig_out_nid) {
1619 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1620 *(spec->stream_digital_playback);
1621 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1622 spec->multiout.dig_out_nid;
1623 }
1624 if (spec->dig_in_nid) {
1625 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1626 *(spec->stream_digital_capture);
1627 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1628 spec->dig_in_nid;
1629 }
1630 }
1631
1632 return 0;
1633}
1634
1635static void via_free(struct hda_codec *codec)
1636{
1637 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001638
1639 if (!spec)
1640 return;
1641
Takashi Iwai603c4012008-07-30 15:01:44 +02001642 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001643 vt1708_stop_hp_work(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001644 kfree(codec->spec);
1645}
1646
Harald Welte69e52a82008-09-09 15:57:32 +08001647/* mute internal speaker if HP is plugged */
1648static void via_hp_automute(struct hda_codec *codec)
1649{
Lydia Wangdcf34c82009-10-10 19:08:15 +08001650 unsigned int present = 0;
Harald Welte69e52a82008-09-09 15:57:32 +08001651 struct via_spec *spec = codec->spec;
1652
Takashi Iwaid56757a2009-11-18 08:00:14 +01001653 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangdcf34c82009-10-10 19:08:15 +08001654
1655 if (!spec->hp_independent_mode) {
1656 struct snd_ctl_elem_id id;
1657 /* auto mute */
1658 snd_hda_codec_amp_stereo(
1659 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1660 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1661 /* notify change */
1662 memset(&id, 0, sizeof(id));
1663 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1664 strcpy(id.name, "Front Playback Switch");
1665 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1666 &id);
1667 }
Harald Welte69e52a82008-09-09 15:57:32 +08001668}
1669
Lydia Wangf3db4232009-10-10 19:08:41 +08001670/* mute mono out if HP or Line out is plugged */
1671static void via_mono_automute(struct hda_codec *codec)
1672{
1673 unsigned int hp_present, lineout_present;
1674 struct via_spec *spec = codec->spec;
1675
1676 if (spec->codec_type != VT1716S)
1677 return;
1678
Takashi Iwaid56757a2009-11-18 08:00:14 +01001679 lineout_present = snd_hda_jack_detect(codec,
1680 spec->autocfg.line_out_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001681
1682 /* Mute Mono Out if Line Out is plugged */
1683 if (lineout_present) {
1684 snd_hda_codec_amp_stereo(
1685 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1686 return;
1687 }
1688
Takashi Iwaid56757a2009-11-18 08:00:14 +01001689 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001690
1691 if (!spec->hp_independent_mode)
1692 snd_hda_codec_amp_stereo(
1693 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1694 hp_present ? HDA_AMP_MUTE : 0);
1695}
1696
Harald Welte69e52a82008-09-09 15:57:32 +08001697static void via_gpio_control(struct hda_codec *codec)
1698{
1699 unsigned int gpio_data;
1700 unsigned int vol_counter;
1701 unsigned int vol;
1702 unsigned int master_vol;
1703
1704 struct via_spec *spec = codec->spec;
1705
1706 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1707 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1708
1709 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1710 0xF84, 0) & 0x3F0000) >> 16;
1711
1712 vol = vol_counter & 0x1F;
1713 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1714 AC_VERB_GET_AMP_GAIN_MUTE,
1715 AC_AMP_GET_INPUT);
1716
1717 if (gpio_data == 0x02) {
1718 /* unmute line out */
1719 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1720 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1721
1722 if (vol_counter & 0x20) {
1723 /* decrease volume */
1724 if (vol > master_vol)
1725 vol = master_vol;
1726 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1727 0, HDA_AMP_VOLMASK,
1728 master_vol-vol);
1729 } else {
1730 /* increase volume */
1731 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1732 HDA_AMP_VOLMASK,
1733 ((master_vol+vol) > 0x2A) ? 0x2A :
1734 (master_vol+vol));
1735 }
1736 } else if (!(gpio_data & 0x02)) {
1737 /* mute line out */
1738 snd_hda_codec_amp_stereo(codec,
1739 spec->autocfg.line_out_pins[0],
1740 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1741 HDA_AMP_MUTE);
1742 }
1743}
1744
Lydia Wang25eaba22009-10-10 19:08:43 +08001745/* mute Internal-Speaker if HP is plugged */
1746static void via_speaker_automute(struct hda_codec *codec)
1747{
1748 unsigned int hp_present;
1749 struct via_spec *spec = codec->spec;
1750
Lydia Wang27439ce2011-03-24 12:40:10 +08001751 if (!VT2002P_COMPATIBLE(spec))
Lydia Wang25eaba22009-10-10 19:08:43 +08001752 return;
1753
Takashi Iwaid56757a2009-11-18 08:00:14 +01001754 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001755
1756 if (!spec->hp_independent_mode) {
1757 struct snd_ctl_elem_id id;
1758 snd_hda_codec_amp_stereo(
1759 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
1760 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1761 /* notify change */
1762 memset(&id, 0, sizeof(id));
1763 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1764 strcpy(id.name, "Speaker Playback Switch");
1765 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1766 &id);
1767 }
1768}
1769
1770/* mute line-out and internal speaker if HP is plugged */
1771static void via_hp_bind_automute(struct hda_codec *codec)
1772{
akpm@linux-foundation.org01a17962009-11-13 16:47:10 -08001773 /* use long instead of int below just to avoid an internal compiler
1774 * error with gcc 4.0.x
1775 */
1776 unsigned long hp_present, present = 0;
Lydia Wang25eaba22009-10-10 19:08:43 +08001777 struct via_spec *spec = codec->spec;
1778 int i;
1779
1780 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1781 return;
1782
Takashi Iwaid56757a2009-11-18 08:00:14 +01001783 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001784
Takashi Iwaid56757a2009-11-18 08:00:14 +01001785 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001786
1787 if (!spec->hp_independent_mode) {
1788 /* Mute Line-Outs */
1789 for (i = 0; i < spec->autocfg.line_outs; i++)
1790 snd_hda_codec_amp_stereo(
1791 codec, spec->autocfg.line_out_pins[i],
1792 HDA_OUTPUT, 0,
1793 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1794 if (hp_present)
1795 present = hp_present;
1796 }
1797 /* Speakers */
1798 for (i = 0; i < spec->autocfg.speaker_outs; i++)
1799 snd_hda_codec_amp_stereo(
1800 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
1801 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1802}
1803
1804
Harald Welte69e52a82008-09-09 15:57:32 +08001805/* unsolicited event for jack sensing */
1806static void via_unsol_event(struct hda_codec *codec,
1807 unsigned int res)
1808{
1809 res >>= 26;
Lydia Wangec7e7e42011-03-24 12:43:44 +08001810
Lydia Wanga34df192009-10-10 19:08:01 +08001811 if (res & VIA_JACK_EVENT)
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001812 set_widgets_power_state(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001813
1814 res &= ~VIA_JACK_EVENT;
1815
1816 if (res == VIA_HP_EVENT)
1817 via_hp_automute(codec);
1818 else if (res == VIA_GPIO_EVENT)
1819 via_gpio_control(codec);
1820 else if (res == VIA_MONO_EVENT)
Lydia Wangf3db4232009-10-10 19:08:41 +08001821 via_mono_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001822 else if (res == VIA_SPEAKER_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001823 via_speaker_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001824 else if (res == VIA_BIND_HP_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001825 via_hp_bind_automute(codec);
Harald Welte69e52a82008-09-09 15:57:32 +08001826}
1827
Joseph Chanc577b8a2006-11-29 15:29:40 +01001828static int via_init(struct hda_codec *codec)
1829{
1830 struct via_spec *spec = codec->spec;
Harald Welte69e52a82008-09-09 15:57:32 +08001831 int i;
1832 for (i = 0; i < spec->num_iverbs; i++)
1833 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1834
Josepch Chanf7278fd2007-12-13 16:40:40 +01001835 /* Lydia Add for EAPD enable */
1836 if (!spec->dig_in_nid) { /* No Digital In connection */
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001837 if (spec->dig_in_pin) {
1838 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001839 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +01001840 PIN_OUT);
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001841 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001842 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1843 }
Takashi Iwai12b74c82008-01-15 12:39:38 +01001844 } else /* enable SPDIF-input pin */
1845 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1846 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
Josepch Chanf7278fd2007-12-13 16:40:40 +01001847
Takashi Iwai9da29272009-05-07 16:31:14 +02001848 /* assign slave outs */
1849 if (spec->slave_dig_outs[0])
1850 codec->slave_dig_outs = spec->slave_dig_outs;
Harald Welte5691ec72008-09-15 22:42:26 +08001851
Lydia Wang377ff312009-10-10 19:08:55 +08001852 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001853}
1854
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001855#ifdef SND_HDA_NEEDS_RESUME
1856static int via_suspend(struct hda_codec *codec, pm_message_t state)
1857{
1858 struct via_spec *spec = codec->spec;
1859 vt1708_stop_hp_work(spec);
1860 return 0;
1861}
1862#endif
1863
Takashi Iwaicb53c622007-08-10 17:21:45 +02001864#ifdef CONFIG_SND_HDA_POWER_SAVE
1865static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1866{
1867 struct via_spec *spec = codec->spec;
1868 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1869}
1870#endif
1871
Joseph Chanc577b8a2006-11-29 15:29:40 +01001872/*
1873 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001874static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001875 .build_controls = via_build_controls,
1876 .build_pcms = via_build_pcms,
1877 .init = via_init,
1878 .free = via_free,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001879#ifdef SND_HDA_NEEDS_RESUME
1880 .suspend = via_suspend,
1881#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02001882#ifdef CONFIG_SND_HDA_POWER_SAVE
1883 .check_power_status = via_check_power_status,
1884#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001885};
1886
1887/* fill in the dac_nids table from the parsed pin configuration */
1888static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1889 const struct auto_pin_cfg *cfg)
1890{
1891 int i;
1892 hda_nid_t nid;
1893
1894 spec->multiout.num_dacs = cfg->line_outs;
1895
1896 spec->multiout.dac_nids = spec->private_dac_nids;
Lydia Wang377ff312009-10-10 19:08:55 +08001897
1898 for (i = 0; i < 4; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001899 nid = cfg->line_out_pins[i];
1900 if (nid) {
1901 /* config dac list */
1902 switch (i) {
1903 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02001904 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001905 break;
1906 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02001907 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001908 break;
1909 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02001910 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001911 break;
1912 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02001913 spec->private_dac_nids[i] = 0x13;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001914 break;
1915 }
1916 }
1917 }
1918
1919 return 0;
1920}
1921
1922/* add playback controls from the parsed DAC table */
1923static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1924 const struct auto_pin_cfg *cfg)
1925{
1926 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01001927 static const char * const chname[4] = {
1928 "Front", "Surround", "C/LFE", "Side"
1929 };
Lydia Wang9645c202009-10-10 19:08:27 +08001930 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
Joseph Chanc577b8a2006-11-29 15:29:40 +01001931 int i, err;
1932
1933 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1934 nid = cfg->line_out_pins[i];
1935
1936 if (!nid)
1937 continue;
Lydia Wang377ff312009-10-10 19:08:55 +08001938
Lydia Wang9645c202009-10-10 19:08:27 +08001939 nid_vol = nid_vols[i];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001940
1941 if (i == AUTO_SEQ_CENLFE) {
1942 /* Center/LFE */
1943 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001944 "Center Playback Volume",
1945 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1946 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001947 if (err < 0)
1948 return err;
1949 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1950 "LFE Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001951 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1952 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001953 if (err < 0)
1954 return err;
1955 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1956 "Center Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001957 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1958 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001959 if (err < 0)
1960 return err;
1961 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1962 "LFE Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001963 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1964 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001965 if (err < 0)
1966 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08001967 } else if (i == AUTO_SEQ_FRONT) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001968 /* add control to mixer index 0 */
1969 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1970 "Master Front Playback Volume",
Lydia Wang9645c202009-10-10 19:08:27 +08001971 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001972 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001973 if (err < 0)
1974 return err;
1975 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1976 "Master Front Playback Switch",
Lydia Wang9645c202009-10-10 19:08:27 +08001977 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001978 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001979 if (err < 0)
1980 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08001981
Joseph Chanc577b8a2006-11-29 15:29:40 +01001982 /* add control to PW3 */
1983 sprintf(name, "%s Playback Volume", chname[i]);
1984 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001985 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1986 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001987 if (err < 0)
1988 return err;
1989 sprintf(name, "%s Playback Switch", chname[i]);
1990 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001991 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1992 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001993 if (err < 0)
1994 return err;
1995 } else {
1996 sprintf(name, "%s Playback Volume", chname[i]);
1997 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001998 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1999 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002000 if (err < 0)
2001 return err;
2002 sprintf(name, "%s Playback Switch", chname[i]);
2003 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002004 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2005 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002006 if (err < 0)
2007 return err;
2008 }
2009 }
2010
2011 return 0;
2012}
2013
Harald Welte0aa62ae2008-09-09 15:58:27 +08002014static void create_hp_imux(struct via_spec *spec)
2015{
2016 int i;
2017 struct hda_input_mux *imux = &spec->private_imux[1];
Takashi Iwaiea734962011-01-17 11:29:34 +01002018 static const char * const texts[] = { "OFF", "ON", NULL};
Harald Welte0aa62ae2008-09-09 15:58:27 +08002019
2020 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002021 for (i = 0; texts[i]; i++)
2022 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Harald Welte0aa62ae2008-09-09 15:58:27 +08002023
2024 spec->hp_mux = &spec->private_imux[1];
2025}
2026
Joseph Chanc577b8a2006-11-29 15:29:40 +01002027static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2028{
2029 int err;
2030
2031 if (!pin)
2032 return 0;
2033
2034 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08002035 spec->hp_independent_mode_index = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002036
2037 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2038 "Headphone Playback Volume",
2039 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2040 if (err < 0)
2041 return err;
2042 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2043 "Headphone Playback Switch",
2044 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2045 if (err < 0)
2046 return err;
2047
Harald Welte0aa62ae2008-09-09 15:58:27 +08002048 create_hp_imux(spec);
2049
Joseph Chanc577b8a2006-11-29 15:29:40 +01002050 return 0;
2051}
2052
2053/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002054static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaif3268512010-08-30 11:00:19 +02002055 const struct auto_pin_cfg *cfg,
2056 hda_nid_t cap_nid,
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002057 const hda_nid_t pin_idxs[],
2058 int num_idxs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002059{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002060 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08002061 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002062 int i, err, idx, type, type_idx = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002063
2064 /* for internal loopback recording select */
Takashi Iwaif3268512010-08-30 11:00:19 +02002065 for (idx = 0; idx < num_idxs; idx++) {
2066 if (pin_idxs[idx] == 0xff) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002067 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
Takashi Iwaif3268512010-08-30 11:00:19 +02002068 break;
2069 }
2070 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002071
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002072 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002073 const char *label;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002074 type = cfg->inputs[i].type;
Takashi Iwaif3268512010-08-30 11:00:19 +02002075 for (idx = 0; idx < num_idxs; idx++)
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002076 if (pin_idxs[idx] == cfg->inputs[i].pin)
Takashi Iwaif3268512010-08-30 11:00:19 +02002077 break;
2078 if (idx >= num_idxs)
2079 continue;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002080 if (i > 0 && type == cfg->inputs[i - 1].type)
2081 type_idx++;
2082 else
2083 type_idx = 0;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002084 label = hda_get_autocfg_input_label(codec, cfg, i);
Lydia Wang16922282011-03-22 16:24:10 +08002085 if (spec->codec_type == VT1708S ||
2086 spec->codec_type == VT1702 ||
2087 spec->codec_type == VT1716S)
2088 err = via_new_analog_input(spec, label, type_idx,
2089 idx+1, cap_nid);
2090 else
2091 err = via_new_analog_input(spec, label, type_idx,
2092 idx, cap_nid);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002093 if (err < 0)
2094 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002095 snd_hda_add_imux_item(imux, label, idx, NULL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002096 }
2097 return 0;
2098}
2099
Takashi Iwaif3268512010-08-30 11:00:19 +02002100/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002101static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaif3268512010-08-30 11:00:19 +02002102 const struct auto_pin_cfg *cfg)
2103{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002104 static const hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
Takashi Iwai10a20af2010-09-09 16:28:02 +02002105 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02002106 ARRAY_SIZE(pin_idxs));
2107}
2108
Takashi Iwaicb53c622007-08-10 17:21:45 +02002109#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002110static const struct hda_amp_list vt1708_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002111 { 0x17, HDA_INPUT, 1 },
2112 { 0x17, HDA_INPUT, 2 },
2113 { 0x17, HDA_INPUT, 3 },
2114 { 0x17, HDA_INPUT, 4 },
2115 { } /* end */
2116};
2117#endif
2118
Harald Welte76d9b0d2008-09-09 15:50:37 +08002119static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2120{
2121 unsigned int def_conf;
2122 unsigned char seqassoc;
2123
Takashi Iwai2f334f92009-02-20 14:37:42 +01002124 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002125 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2126 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002127 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2128 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2129 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2130 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002131 }
2132
2133 return;
2134}
2135
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002136static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2137 struct snd_ctl_elem_value *ucontrol)
2138{
2139 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2140 struct via_spec *spec = codec->spec;
2141
2142 if (spec->codec_type != VT1708)
2143 return 0;
2144 spec->vt1708_jack_detectect =
2145 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2146 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2147 return 0;
2148}
2149
2150static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2151 struct snd_ctl_elem_value *ucontrol)
2152{
2153 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2154 struct via_spec *spec = codec->spec;
2155 int change;
2156
2157 if (spec->codec_type != VT1708)
2158 return 0;
2159 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2160 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2161 == !spec->vt1708_jack_detectect;
2162 if (spec->vt1708_jack_detectect) {
2163 mute_aa_path(codec, 1);
2164 notify_aa_path_ctls(codec);
2165 }
2166 return change;
2167}
2168
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002169static const struct snd_kcontrol_new vt1708_jack_detectect[] = {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002170 {
2171 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2172 .name = "Jack Detect",
2173 .count = 1,
2174 .info = snd_ctl_boolean_mono_info,
2175 .get = vt1708_jack_detectect_get,
2176 .put = vt1708_jack_detectect_put,
2177 },
2178 {} /* end */
2179};
2180
Joseph Chanc577b8a2006-11-29 15:29:40 +01002181static int vt1708_parse_auto_config(struct hda_codec *codec)
2182{
2183 struct via_spec *spec = codec->spec;
2184 int err;
2185
Harald Welte76d9b0d2008-09-09 15:50:37 +08002186 /* Add HP and CD pin config connect bit re-config action */
2187 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2188 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2189
Joseph Chanc577b8a2006-11-29 15:29:40 +01002190 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2191 if (err < 0)
2192 return err;
2193 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2194 if (err < 0)
2195 return err;
2196 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2197 return 0; /* can't find valid BIOS pin config */
2198
2199 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2200 if (err < 0)
2201 return err;
2202 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2203 if (err < 0)
2204 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002205 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002206 if (err < 0)
2207 return err;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002208 /* add jack detect on/off control */
2209 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2210 if (err < 0)
2211 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002212
2213 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2214
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002215 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002216 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002217 spec->dig_in_pin = VT1708_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002218 if (spec->autocfg.dig_in_pin)
2219 spec->dig_in_nid = VT1708_DIGIN_NID;
2220
Takashi Iwai603c4012008-07-30 15:01:44 +02002221 if (spec->kctls.list)
2222 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002223
Harald Welte69e52a82008-09-09 15:57:32 +08002224 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002225
Harald Welte0aa62ae2008-09-09 15:58:27 +08002226 spec->input_mux = &spec->private_imux[0];
2227
Harald Weltef8fdd492008-09-15 22:41:31 +08002228 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002229 via_hp_build(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002230
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002231 via_smart51_build(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002232 return 1;
2233}
2234
2235/* init callback for auto-configuration model -- overriding the default init */
2236static int via_auto_init(struct hda_codec *codec)
2237{
Lydia Wang25eaba22009-10-10 19:08:43 +08002238 struct via_spec *spec = codec->spec;
2239
Joseph Chanc577b8a2006-11-29 15:29:40 +01002240 via_init(codec);
2241 via_auto_init_multi_out(codec);
2242 via_auto_init_hp_out(codec);
2243 via_auto_init_analog_input(codec);
Lydia Wang118909562011-03-23 17:57:34 +08002244
2245 if (VT2002P_COMPATIBLE(spec)) {
Lydia Wang25eaba22009-10-10 19:08:43 +08002246 via_hp_bind_automute(codec);
2247 } else {
2248 via_hp_automute(codec);
2249 via_speaker_automute(codec);
2250 }
2251
Joseph Chanc577b8a2006-11-29 15:29:40 +01002252 return 0;
2253}
2254
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002255static void vt1708_update_hp_jack_state(struct work_struct *work)
2256{
2257 struct via_spec *spec = container_of(work, struct via_spec,
2258 vt1708_hp_work.work);
2259 if (spec->codec_type != VT1708)
2260 return;
2261 /* if jack state toggled */
2262 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002263 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002264 spec->vt1708_hp_present ^= 1;
2265 via_hp_automute(spec->codec);
2266 }
2267 vt1708_start_hp_work(spec);
2268}
2269
Takashi Iwai337b9d02009-07-07 18:18:59 +02002270static int get_mux_nids(struct hda_codec *codec)
2271{
2272 struct via_spec *spec = codec->spec;
2273 hda_nid_t nid, conn[8];
2274 unsigned int type;
2275 int i, n;
2276
2277 for (i = 0; i < spec->num_adc_nids; i++) {
2278 nid = spec->adc_nids[i];
2279 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002280 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002281 if (type == AC_WID_PIN)
2282 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002283 n = snd_hda_get_connections(codec, nid, conn,
2284 ARRAY_SIZE(conn));
2285 if (n <= 0)
2286 break;
2287 if (n > 1) {
2288 spec->mux_nids[i] = nid;
2289 break;
2290 }
2291 nid = conn[0];
2292 }
2293 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002294 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002295}
2296
Joseph Chanc577b8a2006-11-29 15:29:40 +01002297static int patch_vt1708(struct hda_codec *codec)
2298{
2299 struct via_spec *spec;
2300 int err;
2301
2302 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002303 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002304 if (spec == NULL)
2305 return -ENOMEM;
2306
Joseph Chanc577b8a2006-11-29 15:29:40 +01002307 /* automatic parse from the BIOS config */
2308 err = vt1708_parse_auto_config(codec);
2309 if (err < 0) {
2310 via_free(codec);
2311 return err;
2312 } else if (!err) {
2313 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2314 "from BIOS. Using genenic mode...\n");
2315 }
2316
Lydia Wang377ff312009-10-10 19:08:55 +08002317
Joseph Chanc577b8a2006-11-29 15:29:40 +01002318 spec->stream_name_analog = "VT1708 Analog";
2319 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
Takashi Iwaibc9b562382008-05-23 17:50:27 +02002320 /* disable 32bit format on VT1708 */
2321 if (codec->vendor_id == 0x11061708)
2322 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002323 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2324
2325 spec->stream_name_digital = "VT1708 Digital";
2326 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2327 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2328
Lydia Wang377ff312009-10-10 19:08:55 +08002329
Joseph Chanc577b8a2006-11-29 15:29:40 +01002330 if (!spec->adc_nids && spec->input_mux) {
2331 spec->adc_nids = vt1708_adc_nids;
2332 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
Takashi Iwai0f67a612009-08-31 08:12:29 +02002333 get_mux_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002334 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2335 spec->num_mixers++;
2336 }
2337
2338 codec->patch_ops = via_patch_ops;
2339
2340 codec->patch_ops.init = via_auto_init;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002341#ifdef CONFIG_SND_HDA_POWER_SAVE
2342 spec->loopback.amplist = vt1708_loopbacks;
2343#endif
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002344 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002345 return 0;
2346}
2347
2348/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002349static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002350 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2351 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2352 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2353 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2354 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2355 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2356 {
2357 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2358 /* The multiple "Capture Source" controls confuse alsamixer
2359 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01002360 */
2361 /* .name = "Capture Source", */
2362 .name = "Input Source",
2363 .count = 1,
2364 .info = via_mux_enum_info,
2365 .get = via_mux_enum_get,
2366 .put = via_mux_enum_put,
2367 },
2368 { } /* end */
2369};
2370
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002371static const struct hda_verb vt1709_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002372 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2373 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002374 { }
2375};
2376
Joseph Chanc577b8a2006-11-29 15:29:40 +01002377/*
2378 * generic initialization of ADC, input mixers and output mixers
2379 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002380static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002381 /*
2382 * Unmute ADC0-2 and set the default input to mic-in
2383 */
2384 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2385 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2386 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2387
2388
Josepch Chanf7278fd2007-12-13 16:40:40 +01002389 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01002390 * mixer widget
2391 */
2392 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01002393 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2394 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2395 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2396 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2397 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002398
2399 /*
2400 * Set up output selector (0x1a, 0x1b, 0x29)
2401 */
2402 /* set vol=0 to output mixers */
2403 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2404 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2405 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2406
2407 /*
2408 * Unmute PW3 and PW4
2409 */
2410 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2411 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2412
Lydia Wangbfdc6752009-10-10 19:08:50 +08002413 /* Set input of PW4 as MW0 */
2414 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002415 /* PW9 Output enable */
2416 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2417 { }
2418};
2419
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002420static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002421 .substreams = 1,
2422 .channels_min = 2,
2423 .channels_max = 10,
2424 .nid = 0x10, /* NID to query formats and rates */
2425 .ops = {
2426 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002427 .prepare = via_playback_multi_pcm_prepare,
2428 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002429 },
2430};
2431
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002432static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002433 .substreams = 1,
2434 .channels_min = 2,
2435 .channels_max = 6,
2436 .nid = 0x10, /* NID to query formats and rates */
2437 .ops = {
2438 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002439 .prepare = via_playback_multi_pcm_prepare,
2440 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002441 },
2442};
2443
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002444static const struct hda_pcm_stream vt1709_pcm_analog_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002445 .substreams = 2,
2446 .channels_min = 2,
2447 .channels_max = 2,
2448 .nid = 0x14, /* NID to query formats and rates */
2449 .ops = {
2450 .prepare = via_capture_pcm_prepare,
2451 .cleanup = via_capture_pcm_cleanup
2452 },
2453};
2454
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002455static const struct hda_pcm_stream vt1709_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002456 .substreams = 1,
2457 .channels_min = 2,
2458 .channels_max = 2,
2459 /* NID is set in via_build_pcms */
2460 .ops = {
2461 .open = via_dig_playback_pcm_open,
2462 .close = via_dig_playback_pcm_close
2463 },
2464};
2465
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002466static const struct hda_pcm_stream vt1709_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002467 .substreams = 1,
2468 .channels_min = 2,
2469 .channels_max = 2,
2470};
2471
2472static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2473 const struct auto_pin_cfg *cfg)
2474{
2475 int i;
2476 hda_nid_t nid;
2477
2478 if (cfg->line_outs == 4) /* 10 channels */
2479 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2480 else if (cfg->line_outs == 3) /* 6 channels */
2481 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2482
2483 spec->multiout.dac_nids = spec->private_dac_nids;
2484
2485 if (cfg->line_outs == 4) { /* 10 channels */
2486 for (i = 0; i < cfg->line_outs; i++) {
2487 nid = cfg->line_out_pins[i];
2488 if (nid) {
2489 /* config dac list */
2490 switch (i) {
2491 case AUTO_SEQ_FRONT:
2492 /* AOW0 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002493 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002494 break;
2495 case AUTO_SEQ_CENLFE:
2496 /* AOW2 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002497 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002498 break;
2499 case AUTO_SEQ_SURROUND:
2500 /* AOW3 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002501 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002502 break;
2503 case AUTO_SEQ_SIDE:
2504 /* AOW1 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002505 spec->private_dac_nids[i] = 0x27;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002506 break;
2507 default:
2508 break;
2509 }
2510 }
2511 }
Takashi Iwaidda14412011-05-02 11:29:30 +02002512 spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
Joseph Chanc577b8a2006-11-29 15:29:40 +01002513
2514 } else if (cfg->line_outs == 3) { /* 6 channels */
Lydia Wang377ff312009-10-10 19:08:55 +08002515 for (i = 0; i < cfg->line_outs; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002516 nid = cfg->line_out_pins[i];
2517 if (nid) {
2518 /* config dac list */
Lydia Wang377ff312009-10-10 19:08:55 +08002519 switch (i) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002520 case AUTO_SEQ_FRONT:
2521 /* AOW0 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002522 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002523 break;
2524 case AUTO_SEQ_CENLFE:
2525 /* AOW2 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002526 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002527 break;
2528 case AUTO_SEQ_SURROUND:
2529 /* AOW1 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002530 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002531 break;
2532 default:
2533 break;
2534 }
2535 }
2536 }
2537 }
2538
2539 return 0;
2540}
2541
2542/* add playback controls from the parsed DAC table */
2543static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2544 const struct auto_pin_cfg *cfg)
2545{
2546 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01002547 static const char * const chname[4] = {
2548 "Front", "Surround", "C/LFE", "Side"
2549 };
Lydia Wang4483a2f2009-10-10 19:08:29 +08002550 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
Joseph Chanc577b8a2006-11-29 15:29:40 +01002551 int i, err;
2552
2553 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2554 nid = cfg->line_out_pins[i];
2555
Lydia Wang377ff312009-10-10 19:08:55 +08002556 if (!nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002557 continue;
2558
Lydia Wang4483a2f2009-10-10 19:08:29 +08002559 nid_vol = nid_vols[i];
2560
Joseph Chanc577b8a2006-11-29 15:29:40 +01002561 if (i == AUTO_SEQ_CENLFE) {
2562 /* Center/LFE */
2563 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2564 "Center Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002565 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002566 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002567 if (err < 0)
2568 return err;
2569 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2570 "LFE Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002571 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002572 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002573 if (err < 0)
2574 return err;
2575 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2576 "Center Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002577 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002578 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002579 if (err < 0)
2580 return err;
2581 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2582 "LFE Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002583 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002584 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002585 if (err < 0)
2586 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002587 } else if (i == AUTO_SEQ_FRONT) {
Lydia Wang4483a2f2009-10-10 19:08:29 +08002588 /* ADD control to mixer index 0 */
Joseph Chanc577b8a2006-11-29 15:29:40 +01002589 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2590 "Master Front Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002591 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002592 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002593 if (err < 0)
2594 return err;
2595 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2596 "Master Front Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002597 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002598 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002599 if (err < 0)
2600 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002601
Joseph Chanc577b8a2006-11-29 15:29:40 +01002602 /* add control to PW3 */
2603 sprintf(name, "%s Playback Volume", chname[i]);
2604 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002605 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2606 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002607 if (err < 0)
2608 return err;
2609 sprintf(name, "%s Playback Switch", chname[i]);
2610 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002611 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2612 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002613 if (err < 0)
2614 return err;
2615 } else if (i == AUTO_SEQ_SURROUND) {
2616 sprintf(name, "%s Playback Volume", chname[i]);
2617 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002618 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002619 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002620 if (err < 0)
2621 return err;
2622 sprintf(name, "%s Playback Switch", chname[i]);
2623 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002624 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002625 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002626 if (err < 0)
2627 return err;
2628 } else if (i == AUTO_SEQ_SIDE) {
2629 sprintf(name, "%s Playback Volume", chname[i]);
2630 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002631 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002632 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002633 if (err < 0)
2634 return err;
2635 sprintf(name, "%s Playback Switch", chname[i]);
2636 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002637 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002638 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002639 if (err < 0)
2640 return err;
2641 }
2642 }
2643
2644 return 0;
2645}
2646
2647static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2648{
2649 int err;
2650
2651 if (!pin)
2652 return 0;
2653
2654 if (spec->multiout.num_dacs == 5) /* 10 channels */
2655 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2656 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2657 spec->multiout.hp_nid = 0;
Lydia Wangcdc17842009-10-10 19:07:47 +08002658 spec->hp_independent_mode_index = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002659
2660 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2661 "Headphone Playback Volume",
2662 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2663 if (err < 0)
2664 return err;
2665 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2666 "Headphone Playback Switch",
2667 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2668 if (err < 0)
2669 return err;
2670
2671 return 0;
2672}
2673
2674/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002675static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002676 const struct auto_pin_cfg *cfg)
2677{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002678 static const hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
Takashi Iwai10a20af2010-09-09 16:28:02 +02002679 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02002680 ARRAY_SIZE(pin_idxs));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002681}
2682
2683static int vt1709_parse_auto_config(struct hda_codec *codec)
2684{
2685 struct via_spec *spec = codec->spec;
2686 int err;
2687
2688 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2689 if (err < 0)
2690 return err;
2691 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2692 if (err < 0)
2693 return err;
2694 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2695 return 0; /* can't find valid BIOS pin config */
2696
2697 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2698 if (err < 0)
2699 return err;
2700 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2701 if (err < 0)
2702 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002703 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002704 if (err < 0)
2705 return err;
2706
2707 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2708
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002709 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002710 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002711 spec->dig_in_pin = VT1709_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002712 if (spec->autocfg.dig_in_pin)
2713 spec->dig_in_nid = VT1709_DIGIN_NID;
2714
Takashi Iwai603c4012008-07-30 15:01:44 +02002715 if (spec->kctls.list)
2716 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002717
Harald Welte0aa62ae2008-09-09 15:58:27 +08002718 spec->input_mux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01002719
Harald Weltef8fdd492008-09-15 22:41:31 +08002720 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002721 via_hp_build(codec);
Harald Weltef8fdd492008-09-15 22:41:31 +08002722
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002723 via_smart51_build(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002724 return 1;
2725}
2726
Takashi Iwaicb53c622007-08-10 17:21:45 +02002727#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002728static const struct hda_amp_list vt1709_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002729 { 0x18, HDA_INPUT, 1 },
2730 { 0x18, HDA_INPUT, 2 },
2731 { 0x18, HDA_INPUT, 3 },
2732 { 0x18, HDA_INPUT, 4 },
2733 { } /* end */
2734};
2735#endif
2736
Joseph Chanc577b8a2006-11-29 15:29:40 +01002737static int patch_vt1709_10ch(struct hda_codec *codec)
2738{
2739 struct via_spec *spec;
2740 int err;
2741
2742 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002743 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002744 if (spec == NULL)
2745 return -ENOMEM;
2746
Joseph Chanc577b8a2006-11-29 15:29:40 +01002747 err = vt1709_parse_auto_config(codec);
2748 if (err < 0) {
2749 via_free(codec);
2750 return err;
2751 } else if (!err) {
2752 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2753 "Using genenic mode...\n");
2754 }
2755
Harald Welte69e52a82008-09-09 15:57:32 +08002756 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2757 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002758
2759 spec->stream_name_analog = "VT1709 Analog";
2760 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2761 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2762
2763 spec->stream_name_digital = "VT1709 Digital";
2764 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2765 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2766
Lydia Wang377ff312009-10-10 19:08:55 +08002767
Joseph Chanc577b8a2006-11-29 15:29:40 +01002768 if (!spec->adc_nids && spec->input_mux) {
2769 spec->adc_nids = vt1709_adc_nids;
2770 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02002771 get_mux_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002772 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2773 spec->num_mixers++;
2774 }
2775
2776 codec->patch_ops = via_patch_ops;
2777
2778 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002779 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002780#ifdef CONFIG_SND_HDA_POWER_SAVE
2781 spec->loopback.amplist = vt1709_loopbacks;
2782#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002783
2784 return 0;
2785}
2786/*
2787 * generic initialization of ADC, input mixers and output mixers
2788 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002789static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002790 /*
2791 * Unmute ADC0-2 and set the default input to mic-in
2792 */
2793 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2794 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2795 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2796
2797
2798 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2799 * mixer widget
2800 */
2801 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2802 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2803 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2804 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2805 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2806 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2807
2808 /*
2809 * Set up output selector (0x1a, 0x1b, 0x29)
2810 */
2811 /* set vol=0 to output mixers */
2812 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2813 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2814 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2815
2816 /*
2817 * Unmute PW3 and PW4
2818 */
2819 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2820 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2821
2822 /* Set input of PW4 as MW0 */
2823 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002824 /* PW9 Output enable */
2825 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2826 { }
2827};
2828
2829static int patch_vt1709_6ch(struct hda_codec *codec)
2830{
2831 struct via_spec *spec;
2832 int err;
2833
2834 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002835 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002836 if (spec == NULL)
2837 return -ENOMEM;
2838
Joseph Chanc577b8a2006-11-29 15:29:40 +01002839 err = vt1709_parse_auto_config(codec);
2840 if (err < 0) {
2841 via_free(codec);
2842 return err;
2843 } else if (!err) {
2844 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2845 "Using genenic mode...\n");
2846 }
2847
Harald Welte69e52a82008-09-09 15:57:32 +08002848 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2849 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002850
2851 spec->stream_name_analog = "VT1709 Analog";
2852 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2853 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2854
2855 spec->stream_name_digital = "VT1709 Digital";
2856 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2857 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2858
Lydia Wang377ff312009-10-10 19:08:55 +08002859
Joseph Chanc577b8a2006-11-29 15:29:40 +01002860 if (!spec->adc_nids && spec->input_mux) {
2861 spec->adc_nids = vt1709_adc_nids;
2862 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02002863 get_mux_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002864 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2865 spec->num_mixers++;
2866 }
2867
2868 codec->patch_ops = via_patch_ops;
2869
2870 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002871 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002872#ifdef CONFIG_SND_HDA_POWER_SAVE
2873 spec->loopback.amplist = vt1709_loopbacks;
2874#endif
Josepch Chanf7278fd2007-12-13 16:40:40 +01002875 return 0;
2876}
2877
2878/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002879static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002880 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2881 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2882 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2883 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2884 {
2885 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2886 /* The multiple "Capture Source" controls confuse alsamixer
2887 * So call somewhat different..
Josepch Chanf7278fd2007-12-13 16:40:40 +01002888 */
2889 /* .name = "Capture Source", */
2890 .name = "Input Source",
2891 .count = 1,
2892 .info = via_mux_enum_info,
2893 .get = via_mux_enum_get,
2894 .put = via_mux_enum_put,
2895 },
2896 { } /* end */
2897};
2898/*
2899 * generic initialization of ADC, input mixers and output mixers
2900 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002901static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002902 /*
2903 * Unmute ADC0-1 and set the default input to mic-in
2904 */
2905 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2906 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2907
2908
2909 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2910 * mixer widget
2911 */
2912 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2913 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2914 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2915 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2916 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2917 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2918
2919 /*
2920 * Set up output mixers
2921 */
2922 /* set vol=0 to output mixers */
2923 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2924 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2925 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2926
2927 /* Setup default input to PW4 */
Lydia Wangbfdc6752009-10-10 19:08:50 +08002928 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
Josepch Chanf7278fd2007-12-13 16:40:40 +01002929 /* PW9 Output enable */
2930 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2931 /* PW10 Input enable */
2932 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2933 { }
2934};
2935
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002936static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002937 /*
2938 * Unmute ADC0-1 and set the default input to mic-in
2939 */
2940 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2941 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2942
2943
2944 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2945 * mixer widget
2946 */
2947 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2948 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2949 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2950 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2951 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2952 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2953
2954 /*
2955 * Set up output mixers
2956 */
2957 /* set vol=0 to output mixers */
2958 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2959 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2960 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2961
2962 /* Setup default input of PW4 to MW0 */
2963 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2964 /* PW9 Output enable */
2965 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2966 /* PW10 Input enable */
2967 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2968 { }
2969};
2970
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002971static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002972 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2973 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2974 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2975 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2976 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2977 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2978 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2979 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2980 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002981 { }
2982};
2983
Lydia Wang17314372009-10-10 19:07:37 +08002984static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2985 struct hda_codec *codec,
2986 struct snd_pcm_substream *substream)
2987{
2988 int idle = substream->pstr->substream_opened == 1
2989 && substream->ref_count == 0;
2990
2991 analog_low_current_mode(codec, idle);
2992 return 0;
2993}
2994
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002995static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002996 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002997 .channels_min = 2,
2998 .channels_max = 8,
2999 .nid = 0x10, /* NID to query formats and rates */
3000 .ops = {
3001 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08003002 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003003 .cleanup = via_playback_multi_pcm_cleanup,
3004 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01003005 },
3006};
3007
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003008static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08003009 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003010 .channels_min = 2,
3011 .channels_max = 4,
3012 .nid = 0x10, /* NID to query formats and rates */
3013 .ops = {
3014 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08003015 .prepare = via_playback_multi_pcm_prepare,
3016 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01003017 },
3018};
3019
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003020static const struct hda_pcm_stream vt1708B_pcm_analog_capture = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003021 .substreams = 2,
3022 .channels_min = 2,
3023 .channels_max = 2,
3024 .nid = 0x13, /* NID to query formats and rates */
3025 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003026 .open = via_pcm_open_close,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003027 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003028 .cleanup = via_capture_pcm_cleanup,
3029 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01003030 },
3031};
3032
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003033static const struct hda_pcm_stream vt1708B_pcm_digital_playback = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003034 .substreams = 1,
3035 .channels_min = 2,
3036 .channels_max = 2,
3037 /* NID is set in via_build_pcms */
3038 .ops = {
3039 .open = via_dig_playback_pcm_open,
3040 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003041 .prepare = via_dig_playback_pcm_prepare,
3042 .cleanup = via_dig_playback_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01003043 },
3044};
3045
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003046static const struct hda_pcm_stream vt1708B_pcm_digital_capture = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003047 .substreams = 1,
3048 .channels_min = 2,
3049 .channels_max = 2,
3050};
3051
3052/* fill in the dac_nids table from the parsed pin configuration */
3053static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3054 const struct auto_pin_cfg *cfg)
3055{
3056 int i;
3057 hda_nid_t nid;
3058
3059 spec->multiout.num_dacs = cfg->line_outs;
3060
3061 spec->multiout.dac_nids = spec->private_dac_nids;
3062
3063 for (i = 0; i < 4; i++) {
3064 nid = cfg->line_out_pins[i];
3065 if (nid) {
3066 /* config dac list */
3067 switch (i) {
3068 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02003069 spec->private_dac_nids[i] = 0x10;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003070 break;
3071 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003072 spec->private_dac_nids[i] = 0x24;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003073 break;
3074 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02003075 spec->private_dac_nids[i] = 0x11;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003076 break;
3077 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003078 spec->private_dac_nids[i] = 0x25;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003079 break;
3080 }
3081 }
3082 }
3083
3084 return 0;
3085}
3086
3087/* add playback controls from the parsed DAC table */
3088static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3089 const struct auto_pin_cfg *cfg)
3090{
3091 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01003092 static const char * const chname[4] = {
3093 "Front", "Surround", "C/LFE", "Side"
3094 };
Harald Weltefb4cb772008-09-09 15:53:36 +08003095 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
Josepch Chanf7278fd2007-12-13 16:40:40 +01003096 hda_nid_t nid, nid_vol = 0;
3097 int i, err;
3098
3099 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3100 nid = cfg->line_out_pins[i];
3101
3102 if (!nid)
3103 continue;
3104
3105 nid_vol = nid_vols[i];
3106
3107 if (i == AUTO_SEQ_CENLFE) {
3108 /* Center/LFE */
3109 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3110 "Center Playback Volume",
3111 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3112 HDA_OUTPUT));
3113 if (err < 0)
3114 return err;
3115 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3116 "LFE Playback Volume",
3117 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3118 HDA_OUTPUT));
3119 if (err < 0)
3120 return err;
3121 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3122 "Center Playback Switch",
3123 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3124 HDA_OUTPUT));
3125 if (err < 0)
3126 return err;
3127 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3128 "LFE Playback Switch",
3129 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3130 HDA_OUTPUT));
3131 if (err < 0)
3132 return err;
3133 } else if (i == AUTO_SEQ_FRONT) {
3134 /* add control to mixer index 0 */
3135 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3136 "Master Front Playback Volume",
3137 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3138 HDA_INPUT));
3139 if (err < 0)
3140 return err;
3141 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3142 "Master Front Playback Switch",
3143 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3144 HDA_INPUT));
3145 if (err < 0)
3146 return err;
3147
3148 /* add control to PW3 */
3149 sprintf(name, "%s Playback Volume", chname[i]);
3150 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3151 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3152 HDA_OUTPUT));
3153 if (err < 0)
3154 return err;
3155 sprintf(name, "%s Playback Switch", chname[i]);
3156 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3157 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3158 HDA_OUTPUT));
3159 if (err < 0)
3160 return err;
3161 } else {
3162 sprintf(name, "%s Playback Volume", chname[i]);
3163 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3164 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3165 HDA_OUTPUT));
3166 if (err < 0)
3167 return err;
3168 sprintf(name, "%s Playback Switch", chname[i]);
3169 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3170 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3171 HDA_OUTPUT));
3172 if (err < 0)
3173 return err;
3174 }
3175 }
3176
3177 return 0;
3178}
3179
3180static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3181{
3182 int err;
3183
3184 if (!pin)
3185 return 0;
3186
3187 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08003188 spec->hp_independent_mode_index = 1;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003189
3190 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3191 "Headphone Playback Volume",
3192 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3193 if (err < 0)
3194 return err;
3195 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3196 "Headphone Playback Switch",
3197 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3198 if (err < 0)
3199 return err;
3200
Harald Welte0aa62ae2008-09-09 15:58:27 +08003201 create_hp_imux(spec);
3202
Josepch Chanf7278fd2007-12-13 16:40:40 +01003203 return 0;
3204}
3205
3206/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003207static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003208 const struct auto_pin_cfg *cfg)
3209{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003210 static const hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
Takashi Iwai10a20af2010-09-09 16:28:02 +02003211 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02003212 ARRAY_SIZE(pin_idxs));
Josepch Chanf7278fd2007-12-13 16:40:40 +01003213}
3214
3215static int vt1708B_parse_auto_config(struct hda_codec *codec)
3216{
3217 struct via_spec *spec = codec->spec;
3218 int err;
3219
3220 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3221 if (err < 0)
3222 return err;
3223 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3224 if (err < 0)
3225 return err;
3226 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3227 return 0; /* can't find valid BIOS pin config */
3228
3229 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3230 if (err < 0)
3231 return err;
3232 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3233 if (err < 0)
3234 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003235 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003236 if (err < 0)
3237 return err;
3238
3239 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3240
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003241 if (spec->autocfg.dig_outs)
Josepch Chanf7278fd2007-12-13 16:40:40 +01003242 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02003243 spec->dig_in_pin = VT1708B_DIGIN_PIN;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003244 if (spec->autocfg.dig_in_pin)
3245 spec->dig_in_nid = VT1708B_DIGIN_NID;
3246
Takashi Iwai603c4012008-07-30 15:01:44 +02003247 if (spec->kctls.list)
3248 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003249
Harald Welte0aa62ae2008-09-09 15:58:27 +08003250 spec->input_mux = &spec->private_imux[0];
3251
Harald Weltef8fdd492008-09-15 22:41:31 +08003252 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003253 via_hp_build(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003254
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003255 via_smart51_build(spec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003256 return 1;
3257}
3258
3259#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003260static const struct hda_amp_list vt1708B_loopbacks[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003261 { 0x16, HDA_INPUT, 1 },
3262 { 0x16, HDA_INPUT, 2 },
3263 { 0x16, HDA_INPUT, 3 },
3264 { 0x16, HDA_INPUT, 4 },
3265 { } /* end */
3266};
3267#endif
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003268
3269static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3270{
3271 struct via_spec *spec = codec->spec;
3272 int imux_is_smixer;
3273 unsigned int parm;
3274 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +08003275 if ((spec->codec_type != VT1708B_4CH) &&
3276 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003277 is_8ch = 1;
3278
3279 /* SW0 (17h) = stereo mixer */
3280 imux_is_smixer =
3281 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3282 == ((spec->codec_type == VT1708S) ? 5 : 0));
3283 /* inputs */
3284 /* PW 1/2/5 (1ah/1bh/1eh) */
3285 parm = AC_PWRST_D3;
3286 set_pin_power_state(codec, 0x1a, &parm);
3287 set_pin_power_state(codec, 0x1b, &parm);
3288 set_pin_power_state(codec, 0x1e, &parm);
3289 if (imux_is_smixer)
3290 parm = AC_PWRST_D0;
3291 /* SW0 (17h), AIW 0/1 (13h/14h) */
3292 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3293 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3294 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3295
3296 /* outputs */
3297 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3298 parm = AC_PWRST_D3;
3299 set_pin_power_state(codec, 0x19, &parm);
3300 if (spec->smart51_enabled)
3301 set_pin_power_state(codec, 0x1b, &parm);
3302 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3303 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3304
3305 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3306 if (is_8ch) {
3307 parm = AC_PWRST_D3;
3308 set_pin_power_state(codec, 0x22, &parm);
3309 if (spec->smart51_enabled)
3310 set_pin_power_state(codec, 0x1a, &parm);
3311 snd_hda_codec_write(codec, 0x26, 0,
3312 AC_VERB_SET_POWER_STATE, parm);
3313 snd_hda_codec_write(codec, 0x24, 0,
3314 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08003315 } else if (codec->vendor_id == 0x11064397) {
3316 /* PW7(23h), SW2(27h), AOW2(25h) */
3317 parm = AC_PWRST_D3;
3318 set_pin_power_state(codec, 0x23, &parm);
3319 if (spec->smart51_enabled)
3320 set_pin_power_state(codec, 0x1a, &parm);
3321 snd_hda_codec_write(codec, 0x27, 0,
3322 AC_VERB_SET_POWER_STATE, parm);
3323 snd_hda_codec_write(codec, 0x25, 0,
3324 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003325 }
3326
3327 /* PW 3/4/7 (1ch/1dh/23h) */
3328 parm = AC_PWRST_D3;
3329 /* force to D0 for internal Speaker */
3330 set_pin_power_state(codec, 0x1c, &parm);
3331 set_pin_power_state(codec, 0x1d, &parm);
3332 if (is_8ch)
3333 set_pin_power_state(codec, 0x23, &parm);
3334
3335 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3336 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3337 imux_is_smixer ? AC_PWRST_D0 : parm);
3338 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3339 if (is_8ch) {
3340 snd_hda_codec_write(codec, 0x25, 0,
3341 AC_VERB_SET_POWER_STATE, parm);
3342 snd_hda_codec_write(codec, 0x27, 0,
3343 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08003344 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3345 snd_hda_codec_write(codec, 0x25, 0,
3346 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003347}
3348
Lydia Wang518bf3b2009-10-10 19:07:29 +08003349static int patch_vt1708S(struct hda_codec *codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003350static int patch_vt1708B_8ch(struct hda_codec *codec)
3351{
3352 struct via_spec *spec;
3353 int err;
3354
Lydia Wang518bf3b2009-10-10 19:07:29 +08003355 if (get_codec_type(codec) == VT1708BCE)
3356 return patch_vt1708S(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003357 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003358 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003359 if (spec == NULL)
3360 return -ENOMEM;
3361
Josepch Chanf7278fd2007-12-13 16:40:40 +01003362 /* automatic parse from the BIOS config */
3363 err = vt1708B_parse_auto_config(codec);
3364 if (err < 0) {
3365 via_free(codec);
3366 return err;
3367 } else if (!err) {
3368 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3369 "from BIOS. Using genenic mode...\n");
3370 }
3371
Harald Welte69e52a82008-09-09 15:57:32 +08003372 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3373 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003374
3375 spec->stream_name_analog = "VT1708B Analog";
3376 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3377 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3378
3379 spec->stream_name_digital = "VT1708B Digital";
3380 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3381 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3382
3383 if (!spec->adc_nids && spec->input_mux) {
3384 spec->adc_nids = vt1708B_adc_nids;
3385 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02003386 get_mux_nids(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003387 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3388 spec->num_mixers++;
3389 }
3390
3391 codec->patch_ops = via_patch_ops;
3392
3393 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003394 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003395#ifdef CONFIG_SND_HDA_POWER_SAVE
3396 spec->loopback.amplist = vt1708B_loopbacks;
3397#endif
3398
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003399 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3400
Josepch Chanf7278fd2007-12-13 16:40:40 +01003401 return 0;
3402}
3403
3404static int patch_vt1708B_4ch(struct hda_codec *codec)
3405{
3406 struct via_spec *spec;
3407 int err;
3408
3409 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003410 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003411 if (spec == NULL)
3412 return -ENOMEM;
3413
Josepch Chanf7278fd2007-12-13 16:40:40 +01003414 /* automatic parse from the BIOS config */
3415 err = vt1708B_parse_auto_config(codec);
3416 if (err < 0) {
3417 via_free(codec);
3418 return err;
3419 } else if (!err) {
3420 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3421 "from BIOS. Using genenic mode...\n");
3422 }
3423
Harald Welte69e52a82008-09-09 15:57:32 +08003424 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3425 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003426
3427 spec->stream_name_analog = "VT1708B Analog";
3428 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3429 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3430
3431 spec->stream_name_digital = "VT1708B Digital";
3432 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3433 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3434
3435 if (!spec->adc_nids && spec->input_mux) {
3436 spec->adc_nids = vt1708B_adc_nids;
3437 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02003438 get_mux_nids(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003439 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3440 spec->num_mixers++;
3441 }
3442
3443 codec->patch_ops = via_patch_ops;
3444
3445 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003446 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003447#ifdef CONFIG_SND_HDA_POWER_SAVE
3448 spec->loopback.amplist = vt1708B_loopbacks;
3449#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01003450
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003451 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3452
Joseph Chanc577b8a2006-11-29 15:29:40 +01003453 return 0;
3454}
3455
Harald Welted949cac2008-09-09 15:56:01 +08003456/* Patch for VT1708S */
3457
3458/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003459static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003460 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3461 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3462 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3463 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
Lydia Wang6369bcf2009-10-10 19:08:31 +08003464 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3465 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3466 HDA_INPUT),
Harald Welted949cac2008-09-09 15:56:01 +08003467 {
3468 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3469 /* The multiple "Capture Source" controls confuse alsamixer
3470 * So call somewhat different..
3471 */
3472 /* .name = "Capture Source", */
3473 .name = "Input Source",
3474 .count = 1,
3475 .info = via_mux_enum_info,
3476 .get = via_mux_enum_get,
3477 .put = via_mux_enum_put,
3478 },
3479 { } /* end */
3480};
3481
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003482static const struct hda_verb vt1708S_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003483 /* Unmute ADC0-1 and set the default input to mic-in */
3484 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3485 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3486
3487 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3488 * analog-loopback mixer widget */
3489 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3490 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3491 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3492 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3493 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3494 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3495
3496 /* Setup default input of PW4 to MW0 */
3497 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
Harald Welte5691ec72008-09-15 22:42:26 +08003498 /* PW9, PW10 Output enable */
Harald Welted949cac2008-09-09 15:56:01 +08003499 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welte5691ec72008-09-15 22:42:26 +08003500 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welted7426322008-09-15 22:43:23 +08003501 /* Enable Mic Boost Volume backdoor */
3502 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003503 /* don't bybass mixer */
3504 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08003505 { }
3506};
3507
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003508static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003509 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3510 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3511 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3512 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3513 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3514 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3515 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3516 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3517 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003518 { }
3519};
3520
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003521static const struct hda_verb vt1705_uniwill_init_verbs[] = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003522 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3523 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3524 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3525 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3526 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3527 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3528 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3529 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3530 { }
3531};
3532
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003533static const struct hda_pcm_stream vt1708S_pcm_analog_playback = {
Harald Welted949cac2008-09-09 15:56:01 +08003534 .substreams = 2,
3535 .channels_min = 2,
3536 .channels_max = 8,
3537 .nid = 0x10, /* NID to query formats and rates */
3538 .ops = {
3539 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08003540 .prepare = via_playback_multi_pcm_prepare,
3541 .cleanup = via_playback_multi_pcm_cleanup,
Lydia Wang17314372009-10-10 19:07:37 +08003542 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003543 },
3544};
3545
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003546static const struct hda_pcm_stream vt1705_pcm_analog_playback = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003547 .substreams = 2,
3548 .channels_min = 2,
3549 .channels_max = 6,
3550 .nid = 0x10, /* NID to query formats and rates */
3551 .ops = {
3552 .open = via_playback_pcm_open,
3553 .prepare = via_playback_multi_pcm_prepare,
3554 .cleanup = via_playback_multi_pcm_cleanup,
3555 .close = via_pcm_open_close
3556 },
3557};
3558
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003559static const struct hda_pcm_stream vt1708S_pcm_analog_capture = {
Harald Welted949cac2008-09-09 15:56:01 +08003560 .substreams = 2,
3561 .channels_min = 2,
3562 .channels_max = 2,
3563 .nid = 0x13, /* NID to query formats and rates */
3564 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003565 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08003566 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003567 .cleanup = via_capture_pcm_cleanup,
3568 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003569 },
3570};
3571
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003572static const struct hda_pcm_stream vt1708S_pcm_digital_playback = {
Takashi Iwai9da29272009-05-07 16:31:14 +02003573 .substreams = 1,
Harald Welted949cac2008-09-09 15:56:01 +08003574 .channels_min = 2,
3575 .channels_max = 2,
3576 /* NID is set in via_build_pcms */
3577 .ops = {
3578 .open = via_dig_playback_pcm_open,
3579 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003580 .prepare = via_dig_playback_pcm_prepare,
3581 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08003582 },
3583};
3584
3585/* fill in the dac_nids table from the parsed pin configuration */
3586static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3587 const struct auto_pin_cfg *cfg)
3588{
3589 int i;
3590 hda_nid_t nid;
3591
3592 spec->multiout.num_dacs = cfg->line_outs;
3593
3594 spec->multiout.dac_nids = spec->private_dac_nids;
3595
3596 for (i = 0; i < 4; i++) {
3597 nid = cfg->line_out_pins[i];
3598 if (nid) {
3599 /* config dac list */
3600 switch (i) {
3601 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02003602 spec->private_dac_nids[i] = 0x10;
Harald Welted949cac2008-09-09 15:56:01 +08003603 break;
3604 case AUTO_SEQ_CENLFE:
Lydia Wangbc92df72011-03-23 17:56:05 +08003605 if (spec->codec->vendor_id == 0x11064397)
Takashi Iwaidda14412011-05-02 11:29:30 +02003606 spec->private_dac_nids[i] = 0x25;
Lydia Wangbc92df72011-03-23 17:56:05 +08003607 else
Takashi Iwaidda14412011-05-02 11:29:30 +02003608 spec->private_dac_nids[i] = 0x24;
Harald Welted949cac2008-09-09 15:56:01 +08003609 break;
3610 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02003611 spec->private_dac_nids[i] = 0x11;
Harald Welted949cac2008-09-09 15:56:01 +08003612 break;
3613 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003614 spec->private_dac_nids[i] = 0x25;
Harald Welted949cac2008-09-09 15:56:01 +08003615 break;
3616 }
3617 }
3618 }
3619
Clemens Ladisch32e01912010-07-12 16:28:50 +02003620 /* for Smart 5.1, line/mic inputs double as output pins */
3621 if (cfg->line_outs == 1) {
3622 spec->multiout.num_dacs = 3;
Takashi Iwaidda14412011-05-02 11:29:30 +02003623 spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11;
Lydia Wangbc92df72011-03-23 17:56:05 +08003624 if (spec->codec->vendor_id == 0x11064397)
Takashi Iwaidda14412011-05-02 11:29:30 +02003625 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25;
Lydia Wangbc92df72011-03-23 17:56:05 +08003626 else
Takashi Iwaidda14412011-05-02 11:29:30 +02003627 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24;
Clemens Ladisch32e01912010-07-12 16:28:50 +02003628 }
3629
Harald Welted949cac2008-09-09 15:56:01 +08003630 return 0;
3631}
3632
3633/* add playback controls from the parsed DAC table */
Lydia Wangbc92df72011-03-23 17:56:05 +08003634static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08003635 const struct auto_pin_cfg *cfg)
3636{
Lydia Wangbc92df72011-03-23 17:56:05 +08003637 struct via_spec *spec = codec->spec;
Harald Welted949cac2008-09-09 15:56:01 +08003638 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01003639 static const char * const chname[4] = {
3640 "Front", "Surround", "C/LFE", "Side"
3641 };
Lydia Wangbc92df72011-03-23 17:56:05 +08003642 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3643 {0x10, 0x11, 0x25, 0} };
3644 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3645 {0x1C, 0x18, 0x27, 0} };
Harald Welted949cac2008-09-09 15:56:01 +08003646 hda_nid_t nid, nid_vol, nid_mute;
3647 int i, err;
3648
3649 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3650 nid = cfg->line_out_pins[i];
3651
Clemens Ladisch32e01912010-07-12 16:28:50 +02003652 /* for Smart 5.1, there are always at least six channels */
3653 if (!nid && i > AUTO_SEQ_CENLFE)
Harald Welted949cac2008-09-09 15:56:01 +08003654 continue;
3655
Lydia Wangbc92df72011-03-23 17:56:05 +08003656 if (codec->vendor_id == 0x11064397) {
3657 nid_vol = nid_vols[1][i];
3658 nid_mute = nid_mutes[1][i];
3659 } else {
3660 nid_vol = nid_vols[0][i];
3661 nid_mute = nid_mutes[0][i];
3662 }
3663 if (!nid_vol && !nid_mute)
3664 continue;
Harald Welted949cac2008-09-09 15:56:01 +08003665
3666 if (i == AUTO_SEQ_CENLFE) {
3667 /* Center/LFE */
3668 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3669 "Center Playback Volume",
3670 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3671 HDA_OUTPUT));
3672 if (err < 0)
3673 return err;
3674 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3675 "LFE Playback Volume",
3676 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3677 HDA_OUTPUT));
3678 if (err < 0)
3679 return err;
3680 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3681 "Center Playback Switch",
3682 HDA_COMPOSE_AMP_VAL(nid_mute,
3683 1, 0,
3684 HDA_OUTPUT));
3685 if (err < 0)
3686 return err;
3687 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3688 "LFE Playback Switch",
3689 HDA_COMPOSE_AMP_VAL(nid_mute,
3690 2, 0,
3691 HDA_OUTPUT));
3692 if (err < 0)
3693 return err;
3694 } else if (i == AUTO_SEQ_FRONT) {
3695 /* add control to mixer index 0 */
3696 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3697 "Master Front Playback Volume",
3698 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3699 HDA_INPUT));
3700 if (err < 0)
3701 return err;
3702 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3703 "Master Front Playback Switch",
3704 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3705 HDA_INPUT));
3706 if (err < 0)
3707 return err;
3708
3709 /* Front */
3710 sprintf(name, "%s Playback Volume", chname[i]);
3711 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3712 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3713 HDA_OUTPUT));
3714 if (err < 0)
3715 return err;
3716 sprintf(name, "%s Playback Switch", chname[i]);
3717 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3718 HDA_COMPOSE_AMP_VAL(nid_mute,
3719 3, 0,
3720 HDA_OUTPUT));
3721 if (err < 0)
3722 return err;
3723 } else {
3724 sprintf(name, "%s Playback Volume", chname[i]);
3725 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3726 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3727 HDA_OUTPUT));
3728 if (err < 0)
3729 return err;
3730 sprintf(name, "%s Playback Switch", chname[i]);
3731 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3732 HDA_COMPOSE_AMP_VAL(nid_mute,
3733 3, 0,
3734 HDA_OUTPUT));
3735 if (err < 0)
3736 return err;
3737 }
3738 }
3739
3740 return 0;
3741}
3742
3743static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3744{
3745 int err;
3746
3747 if (!pin)
3748 return 0;
3749
3750 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08003751 spec->hp_independent_mode_index = 1;
Harald Welted949cac2008-09-09 15:56:01 +08003752
3753 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3754 "Headphone Playback Volume",
3755 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3756 if (err < 0)
3757 return err;
3758
3759 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3760 "Headphone Playback Switch",
3761 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3762 if (err < 0)
3763 return err;
3764
Harald Welte0aa62ae2008-09-09 15:58:27 +08003765 create_hp_imux(spec);
3766
Harald Welted949cac2008-09-09 15:56:01 +08003767 return 0;
3768}
3769
3770/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003771static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08003772 const struct auto_pin_cfg *cfg)
3773{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003774 static const hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
Takashi Iwai10a20af2010-09-09 16:28:02 +02003775 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02003776 ARRAY_SIZE(pin_idxs));
Harald Welted949cac2008-09-09 15:56:01 +08003777}
3778
Takashi Iwai9da29272009-05-07 16:31:14 +02003779/* fill out digital output widgets; one for master and one for slave outputs */
3780static void fill_dig_outs(struct hda_codec *codec)
3781{
3782 struct via_spec *spec = codec->spec;
3783 int i;
3784
3785 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3786 hda_nid_t nid;
3787 int conn;
3788
3789 nid = spec->autocfg.dig_out_pins[i];
3790 if (!nid)
3791 continue;
3792 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3793 if (conn < 1)
3794 continue;
3795 if (!spec->multiout.dig_out_nid)
3796 spec->multiout.dig_out_nid = nid;
3797 else {
3798 spec->slave_dig_outs[0] = nid;
3799 break; /* at most two dig outs */
3800 }
3801 }
3802}
3803
Harald Welted949cac2008-09-09 15:56:01 +08003804static int vt1708S_parse_auto_config(struct hda_codec *codec)
3805{
3806 struct via_spec *spec = codec->spec;
3807 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003808
Takashi Iwai9da29272009-05-07 16:31:14 +02003809 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08003810 if (err < 0)
3811 return err;
3812 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3813 if (err < 0)
3814 return err;
3815 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3816 return 0; /* can't find valid BIOS pin config */
3817
Lydia Wangbc92df72011-03-23 17:56:05 +08003818 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003819 if (err < 0)
3820 return err;
3821 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3822 if (err < 0)
3823 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003824 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003825 if (err < 0)
3826 return err;
3827
3828 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3829
Takashi Iwai9da29272009-05-07 16:31:14 +02003830 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08003831
Takashi Iwai603c4012008-07-30 15:01:44 +02003832 if (spec->kctls.list)
3833 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08003834
Harald Welte0aa62ae2008-09-09 15:58:27 +08003835 spec->input_mux = &spec->private_imux[0];
3836
Harald Weltef8fdd492008-09-15 22:41:31 +08003837 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003838 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003839
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003840 via_smart51_build(spec);
Harald Welted949cac2008-09-09 15:56:01 +08003841 return 1;
3842}
3843
3844#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003845static const struct hda_amp_list vt1708S_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003846 { 0x16, HDA_INPUT, 1 },
3847 { 0x16, HDA_INPUT, 2 },
3848 { 0x16, HDA_INPUT, 3 },
3849 { 0x16, HDA_INPUT, 4 },
3850 { } /* end */
3851};
3852#endif
3853
Lydia Wang6369bcf2009-10-10 19:08:31 +08003854static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3855 int offset, int num_steps, int step_size)
3856{
3857 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3858 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3859 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3860 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3861 (0 << AC_AMPCAP_MUTE_SHIFT));
3862}
3863
Harald Welted949cac2008-09-09 15:56:01 +08003864static int patch_vt1708S(struct hda_codec *codec)
3865{
3866 struct via_spec *spec;
3867 int err;
3868
3869 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003870 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003871 if (spec == NULL)
3872 return -ENOMEM;
3873
Harald Welted949cac2008-09-09 15:56:01 +08003874 /* automatic parse from the BIOS config */
3875 err = vt1708S_parse_auto_config(codec);
3876 if (err < 0) {
3877 via_free(codec);
3878 return err;
3879 } else if (!err) {
3880 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3881 "from BIOS. Using genenic mode...\n");
3882 }
3883
Harald Welte69e52a82008-09-09 15:57:32 +08003884 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
Lydia Wangbc92df72011-03-23 17:56:05 +08003885 if (codec->vendor_id == 0x11064397)
3886 spec->init_verbs[spec->num_iverbs++] =
3887 vt1705_uniwill_init_verbs;
3888 else
3889 spec->init_verbs[spec->num_iverbs++] =
3890 vt1708S_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003891
Lydia Wang36dd5c42009-10-20 13:18:04 +08003892 if (codec->vendor_id == 0x11060440)
3893 spec->stream_name_analog = "VT1818S Analog";
Lydia Wangbc92df72011-03-23 17:56:05 +08003894 else if (codec->vendor_id == 0x11064397)
3895 spec->stream_name_analog = "VT1705 Analog";
Lydia Wang36dd5c42009-10-20 13:18:04 +08003896 else
3897 spec->stream_name_analog = "VT1708S Analog";
Lydia Wangbc92df72011-03-23 17:56:05 +08003898 if (codec->vendor_id == 0x11064397)
3899 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3900 else
3901 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
Harald Welted949cac2008-09-09 15:56:01 +08003902 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3903
Lydia Wang36dd5c42009-10-20 13:18:04 +08003904 if (codec->vendor_id == 0x11060440)
3905 spec->stream_name_digital = "VT1818S Digital";
Lydia Wangbc92df72011-03-23 17:56:05 +08003906 else if (codec->vendor_id == 0x11064397)
3907 spec->stream_name_digital = "VT1705 Digital";
Lydia Wang36dd5c42009-10-20 13:18:04 +08003908 else
3909 spec->stream_name_digital = "VT1708S Digital";
Harald Welted949cac2008-09-09 15:56:01 +08003910 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3911
3912 if (!spec->adc_nids && spec->input_mux) {
3913 spec->adc_nids = vt1708S_adc_nids;
3914 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02003915 get_mux_nids(codec);
Lydia Wang6369bcf2009-10-10 19:08:31 +08003916 override_mic_boost(codec, 0x1a, 0, 3, 40);
3917 override_mic_boost(codec, 0x1e, 0, 3, 40);
Harald Welted949cac2008-09-09 15:56:01 +08003918 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3919 spec->num_mixers++;
3920 }
3921
3922 codec->patch_ops = via_patch_ops;
3923
3924 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003925 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08003926#ifdef CONFIG_SND_HDA_POWER_SAVE
3927 spec->loopback.amplist = vt1708S_loopbacks;
3928#endif
3929
Lydia Wang518bf3b2009-10-10 19:07:29 +08003930 /* correct names for VT1708BCE */
3931 if (get_codec_type(codec) == VT1708BCE) {
3932 kfree(codec->chip_name);
3933 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3934 snprintf(codec->bus->card->mixername,
3935 sizeof(codec->bus->card->mixername),
3936 "%s %s", codec->vendor_name, codec->chip_name);
3937 spec->stream_name_analog = "VT1708BCE Analog";
3938 spec->stream_name_digital = "VT1708BCE Digital";
3939 }
Lydia Wang970f630f2011-03-22 16:25:56 +08003940 /* correct names for VT1818S */
3941 if (codec->vendor_id == 0x11060440) {
3942 spec->stream_name_analog = "VT1818S Analog";
3943 spec->stream_name_digital = "VT1818S Digital";
3944 }
Lydia Wangbc92df72011-03-23 17:56:05 +08003945 /* correct names for VT1705 */
3946 if (codec->vendor_id == 0x11064397) {
3947 kfree(codec->chip_name);
3948 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3949 snprintf(codec->bus->card->mixername,
3950 sizeof(codec->bus->card->mixername),
3951 "%s %s", codec->vendor_name, codec->chip_name);
3952 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003953 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +08003954 return 0;
3955}
3956
3957/* Patch for VT1702 */
3958
3959/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003960static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003961 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3962 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3963 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3964 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3965 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3966 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3967 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3968 HDA_INPUT),
3969 {
3970 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3971 /* The multiple "Capture Source" controls confuse alsamixer
3972 * So call somewhat different..
3973 */
3974 /* .name = "Capture Source", */
3975 .name = "Input Source",
3976 .count = 1,
3977 .info = via_mux_enum_info,
3978 .get = via_mux_enum_get,
3979 .put = via_mux_enum_put,
3980 },
3981 { } /* end */
3982};
3983
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003984static const struct hda_verb vt1702_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003985 /*
3986 * Unmute ADC0-1 and set the default input to mic-in
3987 */
3988 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3989 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3990 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3991
3992
3993 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3994 * mixer widget
3995 */
3996 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3997 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3998 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3999 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4000 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4001 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4002
4003 /* Setup default input of PW4 to MW0 */
4004 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4005 /* PW6 PW7 Output enable */
4006 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4007 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08004008 /* mixer enable */
4009 {0x1, 0xF88, 0x3},
4010 /* GPIO 0~2 */
4011 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08004012 { }
4013};
4014
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004015static const struct hda_verb vt1702_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08004016 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4017 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4018 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4019 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4020 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4021 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08004022 { }
4023};
4024
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004025static const struct hda_pcm_stream vt1702_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08004026 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08004027 .channels_min = 2,
4028 .channels_max = 2,
4029 .nid = 0x10, /* NID to query formats and rates */
4030 .ops = {
4031 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08004032 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08004033 .cleanup = via_playback_multi_pcm_cleanup,
4034 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08004035 },
4036};
4037
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004038static const struct hda_pcm_stream vt1702_pcm_analog_capture = {
Harald Welted949cac2008-09-09 15:56:01 +08004039 .substreams = 3,
4040 .channels_min = 2,
4041 .channels_max = 2,
4042 .nid = 0x12, /* NID to query formats and rates */
4043 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08004044 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08004045 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08004046 .cleanup = via_capture_pcm_cleanup,
4047 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08004048 },
4049};
4050
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004051static const struct hda_pcm_stream vt1702_pcm_digital_playback = {
Harald Welte5691ec72008-09-15 22:42:26 +08004052 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08004053 .channels_min = 2,
4054 .channels_max = 2,
4055 /* NID is set in via_build_pcms */
4056 .ops = {
4057 .open = via_dig_playback_pcm_open,
4058 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02004059 .prepare = via_dig_playback_pcm_prepare,
4060 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08004061 },
4062};
4063
4064/* fill in the dac_nids table from the parsed pin configuration */
4065static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4066 const struct auto_pin_cfg *cfg)
4067{
4068 spec->multiout.num_dacs = 1;
4069 spec->multiout.dac_nids = spec->private_dac_nids;
4070
4071 if (cfg->line_out_pins[0]) {
4072 /* config dac list */
Takashi Iwaidda14412011-05-02 11:29:30 +02004073 spec->private_dac_nids[0] = 0x10;
Harald Welted949cac2008-09-09 15:56:01 +08004074 }
4075
4076 return 0;
4077}
4078
4079/* add playback controls from the parsed DAC table */
4080static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4081 const struct auto_pin_cfg *cfg)
4082{
4083 int err;
4084
4085 if (!cfg->line_out_pins[0])
4086 return -1;
4087
4088 /* add control to mixer index 0 */
4089 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4090 "Master Front Playback Volume",
4091 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4092 if (err < 0)
4093 return err;
4094 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4095 "Master Front Playback Switch",
4096 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4097 if (err < 0)
4098 return err;
4099
4100 /* Front */
4101 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4102 "Front Playback Volume",
4103 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4104 if (err < 0)
4105 return err;
4106 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4107 "Front Playback Switch",
4108 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4109 if (err < 0)
4110 return err;
4111
4112 return 0;
4113}
4114
4115static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4116{
Lydia Wang0713efe2009-10-10 19:07:43 +08004117 int err, i;
4118 struct hda_input_mux *imux;
Takashi Iwaiea734962011-01-17 11:29:34 +01004119 static const char * const texts[] = { "ON", "OFF", NULL};
Harald Welted949cac2008-09-09 15:56:01 +08004120 if (!pin)
4121 return 0;
Harald Welted949cac2008-09-09 15:56:01 +08004122 spec->multiout.hp_nid = 0x1D;
Lydia Wangcdc17842009-10-10 19:07:47 +08004123 spec->hp_independent_mode_index = 0;
Harald Welted949cac2008-09-09 15:56:01 +08004124
4125 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4126 "Headphone Playback Volume",
4127 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4128 if (err < 0)
4129 return err;
4130
4131 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4132 "Headphone Playback Switch",
4133 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4134 if (err < 0)
4135 return err;
4136
Lydia Wang0713efe2009-10-10 19:07:43 +08004137 imux = &spec->private_imux[1];
Harald Welte0aa62ae2008-09-09 15:58:27 +08004138
Lydia Wang0713efe2009-10-10 19:07:43 +08004139 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004140 for (i = 0; texts[i]; i++)
4141 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Lydia Wang0713efe2009-10-10 19:07:43 +08004142
4143 spec->hp_mux = &spec->private_imux[1];
Harald Welted949cac2008-09-09 15:56:01 +08004144 return 0;
4145}
4146
4147/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004148static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08004149 const struct auto_pin_cfg *cfg)
4150{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004151 static const hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
Takashi Iwai10a20af2010-09-09 16:28:02 +02004152 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02004153 ARRAY_SIZE(pin_idxs));
Harald Welted949cac2008-09-09 15:56:01 +08004154}
4155
4156static int vt1702_parse_auto_config(struct hda_codec *codec)
4157{
4158 struct via_spec *spec = codec->spec;
4159 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004160
Takashi Iwai9da29272009-05-07 16:31:14 +02004161 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08004162 if (err < 0)
4163 return err;
4164 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4165 if (err < 0)
4166 return err;
4167 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4168 return 0; /* can't find valid BIOS pin config */
4169
4170 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4171 if (err < 0)
4172 return err;
4173 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4174 if (err < 0)
4175 return err;
Lydia Wangc2c02ea2009-10-10 19:07:32 +08004176 /* limit AA path volume to 0 dB */
4177 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4178 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4179 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4180 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4181 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai10a20af2010-09-09 16:28:02 +02004182 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08004183 if (err < 0)
4184 return err;
4185
4186 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4187
Takashi Iwai9da29272009-05-07 16:31:14 +02004188 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08004189
Takashi Iwai603c4012008-07-30 15:01:44 +02004190 if (spec->kctls.list)
4191 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08004192
Harald Welte0aa62ae2008-09-09 15:58:27 +08004193 spec->input_mux = &spec->private_imux[0];
4194
Harald Weltef8fdd492008-09-15 22:41:31 +08004195 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004196 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004197
4198 return 1;
4199}
4200
4201#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004202static const struct hda_amp_list vt1702_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08004203 { 0x1A, HDA_INPUT, 1 },
4204 { 0x1A, HDA_INPUT, 2 },
4205 { 0x1A, HDA_INPUT, 3 },
4206 { 0x1A, HDA_INPUT, 4 },
4207 { } /* end */
4208};
4209#endif
4210
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004211static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4212{
4213 int imux_is_smixer =
4214 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4215 unsigned int parm;
4216 /* inputs */
4217 /* PW 1/2/5 (14h/15h/18h) */
4218 parm = AC_PWRST_D3;
4219 set_pin_power_state(codec, 0x14, &parm);
4220 set_pin_power_state(codec, 0x15, &parm);
4221 set_pin_power_state(codec, 0x18, &parm);
4222 if (imux_is_smixer)
4223 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4224 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4225 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4226 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4227 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4228 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4229
4230 /* outputs */
4231 /* PW 3/4 (16h/17h) */
4232 parm = AC_PWRST_D3;
4233 set_pin_power_state(codec, 0x17, &parm);
4234 set_pin_power_state(codec, 0x16, &parm);
4235 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4236 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4237 imux_is_smixer ? AC_PWRST_D0 : parm);
4238 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4239 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4240}
4241
Harald Welted949cac2008-09-09 15:56:01 +08004242static int patch_vt1702(struct hda_codec *codec)
4243{
4244 struct via_spec *spec;
4245 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004246
4247 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004248 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004249 if (spec == NULL)
4250 return -ENOMEM;
4251
Harald Welted949cac2008-09-09 15:56:01 +08004252 /* automatic parse from the BIOS config */
4253 err = vt1702_parse_auto_config(codec);
4254 if (err < 0) {
4255 via_free(codec);
4256 return err;
4257 } else if (!err) {
4258 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4259 "from BIOS. Using genenic mode...\n");
4260 }
4261
Harald Welte69e52a82008-09-09 15:57:32 +08004262 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4263 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08004264
4265 spec->stream_name_analog = "VT1702 Analog";
4266 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4267 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4268
4269 spec->stream_name_digital = "VT1702 Digital";
4270 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4271
4272 if (!spec->adc_nids && spec->input_mux) {
4273 spec->adc_nids = vt1702_adc_nids;
4274 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02004275 get_mux_nids(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004276 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4277 spec->num_mixers++;
4278 }
4279
4280 codec->patch_ops = via_patch_ops;
4281
4282 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08004283 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08004284#ifdef CONFIG_SND_HDA_POWER_SAVE
4285 spec->loopback.amplist = vt1702_loopbacks;
4286#endif
4287
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004288 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08004289 return 0;
4290}
4291
Lydia Wangeb7188c2009-10-10 19:08:34 +08004292/* Patch for VT1718S */
4293
4294/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004295static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004296 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4297 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4298 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4299 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4300 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4301 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4302 HDA_INPUT),
4303 {
4304 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4305 /* The multiple "Capture Source" controls confuse alsamixer
4306 * So call somewhat different..
4307 */
4308 .name = "Input Source",
4309 .count = 2,
4310 .info = via_mux_enum_info,
4311 .get = via_mux_enum_get,
4312 .put = via_mux_enum_put,
4313 },
4314 { } /* end */
4315};
4316
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004317static const struct hda_verb vt1718S_volume_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004318 /*
4319 * Unmute ADC0-1 and set the default input to mic-in
4320 */
4321 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4322 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4323
Lydia Wang4ab2d532011-03-24 12:42:03 +08004324 /* Enable MW0 adjust Gain 5 */
4325 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08004326 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4327 * mixer widget
4328 */
4329 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4330 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4331 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4332 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4333 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
Lydia Wang4ab2d532011-03-24 12:42:03 +08004334 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
Lydia Wangeb7188c2009-10-10 19:08:34 +08004335
4336 /* Setup default input of Front HP to MW9 */
4337 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4338 /* PW9 PW10 Output enable */
4339 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4340 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4341 /* PW11 Input enable */
4342 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4343 /* Enable Boost Volume backdoor */
4344 {0x1, 0xf88, 0x8},
4345 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4346 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4347 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4348 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4349 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4350 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4351 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4352 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4353 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4354 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4355 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4356 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4357 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4358 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4359 /* Unmute MW4's index 0 */
4360 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4361 { }
4362};
4363
4364
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004365static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004366 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4367 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4368 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4369 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4370 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4371 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4372 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4373 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4374 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4375 { }
4376};
4377
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004378static const struct hda_pcm_stream vt1718S_pcm_analog_playback = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004379 .substreams = 2,
4380 .channels_min = 2,
4381 .channels_max = 10,
4382 .nid = 0x8, /* NID to query formats and rates */
4383 .ops = {
4384 .open = via_playback_pcm_open,
4385 .prepare = via_playback_multi_pcm_prepare,
4386 .cleanup = via_playback_multi_pcm_cleanup,
4387 .close = via_pcm_open_close,
4388 },
4389};
4390
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004391static const struct hda_pcm_stream vt1718S_pcm_analog_capture = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004392 .substreams = 2,
4393 .channels_min = 2,
4394 .channels_max = 2,
4395 .nid = 0x10, /* NID to query formats and rates */
4396 .ops = {
4397 .open = via_pcm_open_close,
4398 .prepare = via_capture_pcm_prepare,
4399 .cleanup = via_capture_pcm_cleanup,
4400 .close = via_pcm_open_close,
4401 },
4402};
4403
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004404static const struct hda_pcm_stream vt1718S_pcm_digital_playback = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004405 .substreams = 2,
4406 .channels_min = 2,
4407 .channels_max = 2,
Lydia Wangeb7188c2009-10-10 19:08:34 +08004408 /* NID is set in via_build_pcms */
4409 .ops = {
4410 .open = via_dig_playback_pcm_open,
4411 .close = via_dig_playback_pcm_close,
4412 .prepare = via_dig_playback_pcm_prepare,
4413 .cleanup = via_dig_playback_pcm_cleanup
4414 },
4415};
4416
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004417static const struct hda_pcm_stream vt1718S_pcm_digital_capture = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004418 .substreams = 1,
4419 .channels_min = 2,
4420 .channels_max = 2,
4421};
4422
4423/* fill in the dac_nids table from the parsed pin configuration */
4424static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4425 const struct auto_pin_cfg *cfg)
4426{
4427 int i;
4428 hda_nid_t nid;
4429
4430 spec->multiout.num_dacs = cfg->line_outs;
4431
4432 spec->multiout.dac_nids = spec->private_dac_nids;
4433
4434 for (i = 0; i < 4; i++) {
4435 nid = cfg->line_out_pins[i];
4436 if (nid) {
4437 /* config dac list */
4438 switch (i) {
4439 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02004440 spec->private_dac_nids[i] = 0x8;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004441 break;
4442 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004443 spec->private_dac_nids[i] = 0xa;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004444 break;
4445 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02004446 spec->private_dac_nids[i] = 0x9;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004447 break;
4448 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004449 spec->private_dac_nids[i] = 0xb;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004450 break;
4451 }
4452 }
4453 }
4454
4455 return 0;
4456}
4457
4458/* add playback controls from the parsed DAC table */
4459static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4460 const struct auto_pin_cfg *cfg)
4461{
4462 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01004463 static const char * const chname[4] = {
4464 "Front", "Surround", "C/LFE", "Side"
4465 };
Lydia Wangeb7188c2009-10-10 19:08:34 +08004466 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4467 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4468 hda_nid_t nid, nid_vol, nid_mute = 0;
4469 int i, err;
4470
4471 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4472 nid = cfg->line_out_pins[i];
4473
4474 if (!nid)
4475 continue;
4476 nid_vol = nid_vols[i];
4477 nid_mute = nid_mutes[i];
4478
4479 if (i == AUTO_SEQ_CENLFE) {
4480 /* Center/LFE */
4481 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4482 "Center Playback Volume",
4483 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4484 HDA_OUTPUT));
4485 if (err < 0)
4486 return err;
4487 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4488 "LFE Playback Volume",
4489 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4490 HDA_OUTPUT));
4491 if (err < 0)
4492 return err;
4493 err = via_add_control(
4494 spec, VIA_CTL_WIDGET_MUTE,
4495 "Center Playback Switch",
4496 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4497 HDA_OUTPUT));
4498 if (err < 0)
4499 return err;
4500 err = via_add_control(
4501 spec, VIA_CTL_WIDGET_MUTE,
4502 "LFE Playback Switch",
4503 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4504 HDA_OUTPUT));
4505 if (err < 0)
4506 return err;
4507 } else if (i == AUTO_SEQ_FRONT) {
4508 /* Front */
4509 sprintf(name, "%s Playback Volume", chname[i]);
4510 err = via_add_control(
4511 spec, VIA_CTL_WIDGET_VOL, name,
4512 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4513 if (err < 0)
4514 return err;
4515 sprintf(name, "%s Playback Switch", chname[i]);
4516 err = via_add_control(
4517 spec, VIA_CTL_WIDGET_MUTE, name,
4518 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4519 HDA_OUTPUT));
4520 if (err < 0)
4521 return err;
4522 } else {
4523 sprintf(name, "%s Playback Volume", chname[i]);
4524 err = via_add_control(
4525 spec, VIA_CTL_WIDGET_VOL, name,
4526 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4527 if (err < 0)
4528 return err;
4529 sprintf(name, "%s Playback Switch", chname[i]);
4530 err = via_add_control(
4531 spec, VIA_CTL_WIDGET_MUTE, name,
4532 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4533 HDA_OUTPUT));
4534 if (err < 0)
4535 return err;
4536 }
4537 }
4538 return 0;
4539}
4540
4541static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4542{
4543 int err;
4544
4545 if (!pin)
4546 return 0;
4547
4548 spec->multiout.hp_nid = 0xc; /* AOW4 */
4549 spec->hp_independent_mode_index = 1;
4550
4551 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4552 "Headphone Playback Volume",
4553 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4554 if (err < 0)
4555 return err;
4556
4557 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4558 "Headphone Playback Switch",
4559 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4560 if (err < 0)
4561 return err;
4562
4563 create_hp_imux(spec);
4564 return 0;
4565}
4566
4567/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004568static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangeb7188c2009-10-10 19:08:34 +08004569 const struct auto_pin_cfg *cfg)
4570{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004571 static const hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
Takashi Iwai10a20af2010-09-09 16:28:02 +02004572 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02004573 ARRAY_SIZE(pin_idxs));
Lydia Wangeb7188c2009-10-10 19:08:34 +08004574}
4575
4576static int vt1718S_parse_auto_config(struct hda_codec *codec)
4577{
4578 struct via_spec *spec = codec->spec;
4579 int err;
4580
4581 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4582
4583 if (err < 0)
4584 return err;
4585 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4586 if (err < 0)
4587 return err;
4588 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4589 return 0; /* can't find valid BIOS pin config */
4590
4591 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4592 if (err < 0)
4593 return err;
4594 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4595 if (err < 0)
4596 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02004597 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004598 if (err < 0)
4599 return err;
4600
4601 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4602
4603 fill_dig_outs(codec);
4604
4605 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4606 spec->dig_in_nid = 0x13;
4607
4608 if (spec->kctls.list)
4609 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4610
4611 spec->input_mux = &spec->private_imux[0];
4612
4613 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004614 via_hp_build(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004615
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004616 via_smart51_build(spec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004617
4618 return 1;
4619}
4620
4621#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004622static const struct hda_amp_list vt1718S_loopbacks[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004623 { 0x21, HDA_INPUT, 1 },
4624 { 0x21, HDA_INPUT, 2 },
4625 { 0x21, HDA_INPUT, 3 },
4626 { 0x21, HDA_INPUT, 4 },
4627 { } /* end */
4628};
4629#endif
4630
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004631static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4632{
4633 struct via_spec *spec = codec->spec;
4634 int imux_is_smixer;
4635 unsigned int parm;
4636 /* MUX6 (1eh) = stereo mixer */
4637 imux_is_smixer =
4638 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4639 /* inputs */
4640 /* PW 5/6/7 (29h/2ah/2bh) */
4641 parm = AC_PWRST_D3;
4642 set_pin_power_state(codec, 0x29, &parm);
4643 set_pin_power_state(codec, 0x2a, &parm);
4644 set_pin_power_state(codec, 0x2b, &parm);
4645 if (imux_is_smixer)
4646 parm = AC_PWRST_D0;
4647 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4648 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4649 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4650 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4651 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4652
4653 /* outputs */
4654 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4655 parm = AC_PWRST_D3;
4656 set_pin_power_state(codec, 0x27, &parm);
4657 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4658 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4659
4660 /* PW2 (26h), AOW2 (ah) */
4661 parm = AC_PWRST_D3;
4662 set_pin_power_state(codec, 0x26, &parm);
4663 if (spec->smart51_enabled)
4664 set_pin_power_state(codec, 0x2b, &parm);
4665 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4666
4667 /* PW0 (24h), AOW0 (8h) */
4668 parm = AC_PWRST_D3;
4669 set_pin_power_state(codec, 0x24, &parm);
4670 if (!spec->hp_independent_mode) /* check for redirected HP */
4671 set_pin_power_state(codec, 0x28, &parm);
4672 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4673 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4674 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4675 imux_is_smixer ? AC_PWRST_D0 : parm);
4676
4677 /* PW1 (25h), AOW1 (9h) */
4678 parm = AC_PWRST_D3;
4679 set_pin_power_state(codec, 0x25, &parm);
4680 if (spec->smart51_enabled)
4681 set_pin_power_state(codec, 0x2a, &parm);
4682 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4683
4684 if (spec->hp_independent_mode) {
4685 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4686 parm = AC_PWRST_D3;
4687 set_pin_power_state(codec, 0x28, &parm);
4688 snd_hda_codec_write(codec, 0x1b, 0,
4689 AC_VERB_SET_POWER_STATE, parm);
4690 snd_hda_codec_write(codec, 0x34, 0,
4691 AC_VERB_SET_POWER_STATE, parm);
4692 snd_hda_codec_write(codec, 0xc, 0,
4693 AC_VERB_SET_POWER_STATE, parm);
4694 }
4695}
4696
Lydia Wangeb7188c2009-10-10 19:08:34 +08004697static int patch_vt1718S(struct hda_codec *codec)
4698{
4699 struct via_spec *spec;
4700 int err;
4701
4702 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004703 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004704 if (spec == NULL)
4705 return -ENOMEM;
4706
Lydia Wangeb7188c2009-10-10 19:08:34 +08004707 /* automatic parse from the BIOS config */
4708 err = vt1718S_parse_auto_config(codec);
4709 if (err < 0) {
4710 via_free(codec);
4711 return err;
4712 } else if (!err) {
4713 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4714 "from BIOS. Using genenic mode...\n");
4715 }
4716
4717 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4718 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4719
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004720 if (codec->vendor_id == 0x11060441)
4721 spec->stream_name_analog = "VT2020 Analog";
4722 else if (codec->vendor_id == 0x11064441)
4723 spec->stream_name_analog = "VT1828S Analog";
4724 else
4725 spec->stream_name_analog = "VT1718S Analog";
Lydia Wangeb7188c2009-10-10 19:08:34 +08004726 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4727 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4728
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004729 if (codec->vendor_id == 0x11060441)
4730 spec->stream_name_digital = "VT2020 Digital";
4731 else if (codec->vendor_id == 0x11064441)
4732 spec->stream_name_digital = "VT1828S Digital";
4733 else
4734 spec->stream_name_digital = "VT1718S Digital";
Lydia Wangeb7188c2009-10-10 19:08:34 +08004735 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004736 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
Lydia Wangeb7188c2009-10-10 19:08:34 +08004737 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4738
4739 if (!spec->adc_nids && spec->input_mux) {
4740 spec->adc_nids = vt1718S_adc_nids;
4741 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4742 get_mux_nids(codec);
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004743 override_mic_boost(codec, 0x2b, 0, 3, 40);
4744 override_mic_boost(codec, 0x29, 0, 3, 40);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004745 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4746 spec->num_mixers++;
4747 }
4748
4749 codec->patch_ops = via_patch_ops;
4750
4751 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11004752 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004753
4754#ifdef CONFIG_SND_HDA_POWER_SAVE
4755 spec->loopback.amplist = vt1718S_loopbacks;
4756#endif
4757
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004758 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4759
Lydia Wangeb7188c2009-10-10 19:08:34 +08004760 return 0;
4761}
Lydia Wangf3db4232009-10-10 19:08:41 +08004762
4763/* Patch for VT1716S */
4764
4765static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4766 struct snd_ctl_elem_info *uinfo)
4767{
4768 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4769 uinfo->count = 1;
4770 uinfo->value.integer.min = 0;
4771 uinfo->value.integer.max = 1;
4772 return 0;
4773}
4774
4775static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4776 struct snd_ctl_elem_value *ucontrol)
4777{
4778 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4779 int index = 0;
4780
4781 index = snd_hda_codec_read(codec, 0x26, 0,
4782 AC_VERB_GET_CONNECT_SEL, 0);
4783 if (index != -1)
4784 *ucontrol->value.integer.value = index;
4785
4786 return 0;
4787}
4788
4789static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4790 struct snd_ctl_elem_value *ucontrol)
4791{
4792 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4793 struct via_spec *spec = codec->spec;
4794 int index = *ucontrol->value.integer.value;
4795
4796 snd_hda_codec_write(codec, 0x26, 0,
4797 AC_VERB_SET_CONNECT_SEL, index);
4798 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004799 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08004800 return 1;
4801}
4802
4803/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004804static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004805 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4806 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4807 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4808 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4809 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4810 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4811 HDA_INPUT),
4812 {
4813 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4814 .name = "Input Source",
4815 .count = 1,
4816 .info = via_mux_enum_info,
4817 .get = via_mux_enum_get,
4818 .put = via_mux_enum_put,
4819 },
4820 { } /* end */
4821};
4822
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004823static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004824 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4825 {
4826 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4827 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004828 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08004829 .count = 1,
4830 .info = vt1716s_dmic_info,
4831 .get = vt1716s_dmic_get,
4832 .put = vt1716s_dmic_put,
4833 },
4834 {} /* end */
4835};
4836
4837
4838/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004839static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004840 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4841 { } /* end */
4842};
4843
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004844static const struct hda_verb vt1716S_volume_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004845 /*
4846 * Unmute ADC0-1 and set the default input to mic-in
4847 */
4848 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4849 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4850
4851
4852 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4853 * mixer widget
4854 */
4855 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4856 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4857 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4858 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4859 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4860 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4861
4862 /* MUX Indices: Stereo Mixer = 5 */
4863 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4864
4865 /* Setup default input of PW4 to MW0 */
4866 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4867
4868 /* Setup default input of SW1 as MW0 */
4869 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4870
4871 /* Setup default input of SW4 as AOW0 */
4872 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4873
4874 /* PW9 PW10 Output enable */
4875 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4876 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4877
4878 /* Unmute SW1, PW12 */
4879 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4880 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4881 /* PW12 Output enable */
4882 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4883 /* Enable Boost Volume backdoor */
4884 {0x1, 0xf8a, 0x80},
4885 /* don't bybass mixer */
4886 {0x1, 0xf88, 0xc0},
4887 /* Enable mono output */
4888 {0x1, 0xf90, 0x08},
4889 { }
4890};
4891
4892
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004893static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004894 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4895 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4896 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4897 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4898 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4899 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4900 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4901 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4902 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4903 { }
4904};
4905
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004906static const struct hda_pcm_stream vt1716S_pcm_analog_playback = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004907 .substreams = 2,
4908 .channels_min = 2,
4909 .channels_max = 6,
4910 .nid = 0x10, /* NID to query formats and rates */
4911 .ops = {
4912 .open = via_playback_pcm_open,
4913 .prepare = via_playback_multi_pcm_prepare,
4914 .cleanup = via_playback_multi_pcm_cleanup,
4915 .close = via_pcm_open_close,
4916 },
4917};
4918
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004919static const struct hda_pcm_stream vt1716S_pcm_analog_capture = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004920 .substreams = 2,
4921 .channels_min = 2,
4922 .channels_max = 2,
4923 .nid = 0x13, /* NID to query formats and rates */
4924 .ops = {
4925 .open = via_pcm_open_close,
4926 .prepare = via_capture_pcm_prepare,
4927 .cleanup = via_capture_pcm_cleanup,
4928 .close = via_pcm_open_close,
4929 },
4930};
4931
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004932static const struct hda_pcm_stream vt1716S_pcm_digital_playback = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004933 .substreams = 2,
4934 .channels_min = 2,
4935 .channels_max = 2,
Lydia Wangf3db4232009-10-10 19:08:41 +08004936 /* NID is set in via_build_pcms */
4937 .ops = {
4938 .open = via_dig_playback_pcm_open,
4939 .close = via_dig_playback_pcm_close,
4940 .prepare = via_dig_playback_pcm_prepare,
4941 .cleanup = via_dig_playback_pcm_cleanup
4942 },
4943};
4944
4945/* fill in the dac_nids table from the parsed pin configuration */
4946static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4947 const struct auto_pin_cfg *cfg)
4948{ int i;
4949 hda_nid_t nid;
4950
4951 spec->multiout.num_dacs = cfg->line_outs;
4952
4953 spec->multiout.dac_nids = spec->private_dac_nids;
4954
4955 for (i = 0; i < 3; i++) {
4956 nid = cfg->line_out_pins[i];
4957 if (nid) {
4958 /* config dac list */
4959 switch (i) {
4960 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02004961 spec->private_dac_nids[i] = 0x10;
Lydia Wangf3db4232009-10-10 19:08:41 +08004962 break;
4963 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004964 spec->private_dac_nids[i] = 0x25;
Lydia Wangf3db4232009-10-10 19:08:41 +08004965 break;
4966 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02004967 spec->private_dac_nids[i] = 0x11;
Lydia Wangf3db4232009-10-10 19:08:41 +08004968 break;
4969 }
4970 }
4971 }
4972
4973 return 0;
4974}
4975
4976/* add playback controls from the parsed DAC table */
4977static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4978 const struct auto_pin_cfg *cfg)
4979{
4980 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01004981 static const char * const chname[3] = {
4982 "Front", "Surround", "C/LFE"
4983 };
Lydia Wangf3db4232009-10-10 19:08:41 +08004984 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4985 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4986 hda_nid_t nid, nid_vol, nid_mute;
4987 int i, err;
4988
4989 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4990 nid = cfg->line_out_pins[i];
4991
4992 if (!nid)
4993 continue;
4994
4995 nid_vol = nid_vols[i];
4996 nid_mute = nid_mutes[i];
4997
4998 if (i == AUTO_SEQ_CENLFE) {
4999 err = via_add_control(
5000 spec, VIA_CTL_WIDGET_VOL,
5001 "Center Playback Volume",
5002 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5003 if (err < 0)
5004 return err;
5005 err = via_add_control(
5006 spec, VIA_CTL_WIDGET_VOL,
5007 "LFE Playback Volume",
5008 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5009 if (err < 0)
5010 return err;
5011 err = via_add_control(
5012 spec, VIA_CTL_WIDGET_MUTE,
5013 "Center Playback Switch",
5014 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5015 HDA_OUTPUT));
5016 if (err < 0)
5017 return err;
5018 err = via_add_control(
5019 spec, VIA_CTL_WIDGET_MUTE,
5020 "LFE Playback Switch",
5021 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5022 HDA_OUTPUT));
5023 if (err < 0)
5024 return err;
5025 } else if (i == AUTO_SEQ_FRONT) {
5026
5027 err = via_add_control(
5028 spec, VIA_CTL_WIDGET_VOL,
5029 "Master Front Playback Volume",
5030 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5031 if (err < 0)
5032 return err;
5033 err = via_add_control(
5034 spec, VIA_CTL_WIDGET_MUTE,
5035 "Master Front Playback Switch",
5036 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5037 if (err < 0)
5038 return err;
5039
5040 sprintf(name, "%s Playback Volume", chname[i]);
5041 err = via_add_control(
5042 spec, VIA_CTL_WIDGET_VOL, name,
5043 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5044 if (err < 0)
5045 return err;
5046 sprintf(name, "%s Playback Switch", chname[i]);
5047 err = via_add_control(
5048 spec, VIA_CTL_WIDGET_MUTE, name,
5049 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5050 HDA_OUTPUT));
5051 if (err < 0)
5052 return err;
5053 } else {
5054 sprintf(name, "%s Playback Volume", chname[i]);
5055 err = via_add_control(
5056 spec, VIA_CTL_WIDGET_VOL, name,
5057 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5058 if (err < 0)
5059 return err;
5060 sprintf(name, "%s Playback Switch", chname[i]);
5061 err = via_add_control(
5062 spec, VIA_CTL_WIDGET_MUTE, name,
5063 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5064 HDA_OUTPUT));
5065 if (err < 0)
5066 return err;
5067 }
5068 }
5069 return 0;
5070}
5071
5072static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5073{
5074 int err;
5075
5076 if (!pin)
5077 return 0;
5078
5079 spec->multiout.hp_nid = 0x25; /* AOW3 */
5080 spec->hp_independent_mode_index = 1;
5081
5082 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5083 "Headphone Playback Volume",
5084 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5085 if (err < 0)
5086 return err;
5087
5088 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5089 "Headphone Playback Switch",
5090 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5091 if (err < 0)
5092 return err;
5093
5094 create_hp_imux(spec);
5095 return 0;
5096}
5097
5098/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005099static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangf3db4232009-10-10 19:08:41 +08005100 const struct auto_pin_cfg *cfg)
5101{
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005102 static const hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
Takashi Iwai10a20af2010-09-09 16:28:02 +02005103 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02005104 ARRAY_SIZE(pin_idxs));
Lydia Wangf3db4232009-10-10 19:08:41 +08005105}
5106
5107static int vt1716S_parse_auto_config(struct hda_codec *codec)
5108{
5109 struct via_spec *spec = codec->spec;
5110 int err;
5111
5112 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5113 if (err < 0)
5114 return err;
5115 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5116 if (err < 0)
5117 return err;
5118 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5119 return 0; /* can't find valid BIOS pin config */
5120
5121 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5122 if (err < 0)
5123 return err;
5124 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5125 if (err < 0)
5126 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005127 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangf3db4232009-10-10 19:08:41 +08005128 if (err < 0)
5129 return err;
5130
5131 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5132
5133 fill_dig_outs(codec);
5134
5135 if (spec->kctls.list)
5136 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5137
5138 spec->input_mux = &spec->private_imux[0];
5139
5140 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005141 via_hp_build(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005142
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005143 via_smart51_build(spec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005144
5145 return 1;
5146}
5147
5148#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005149static const struct hda_amp_list vt1716S_loopbacks[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08005150 { 0x16, HDA_INPUT, 1 },
5151 { 0x16, HDA_INPUT, 2 },
5152 { 0x16, HDA_INPUT, 3 },
5153 { 0x16, HDA_INPUT, 4 },
5154 { } /* end */
5155};
5156#endif
5157
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005158static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5159{
5160 struct via_spec *spec = codec->spec;
5161 int imux_is_smixer;
5162 unsigned int parm;
5163 unsigned int mono_out, present;
5164 /* SW0 (17h) = stereo mixer */
5165 imux_is_smixer =
5166 (snd_hda_codec_read(codec, 0x17, 0,
5167 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5168 /* inputs */
5169 /* PW 1/2/5 (1ah/1bh/1eh) */
5170 parm = AC_PWRST_D3;
5171 set_pin_power_state(codec, 0x1a, &parm);
5172 set_pin_power_state(codec, 0x1b, &parm);
5173 set_pin_power_state(codec, 0x1e, &parm);
5174 if (imux_is_smixer)
5175 parm = AC_PWRST_D0;
5176 /* SW0 (17h), AIW0(13h) */
5177 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5178 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5179
5180 parm = AC_PWRST_D3;
5181 set_pin_power_state(codec, 0x1e, &parm);
5182 /* PW11 (22h) */
5183 if (spec->dmic_enabled)
5184 set_pin_power_state(codec, 0x22, &parm);
5185 else
5186 snd_hda_codec_write(codec, 0x22, 0,
5187 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5188
5189 /* SW2(26h), AIW1(14h) */
5190 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5191 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5192
5193 /* outputs */
5194 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5195 parm = AC_PWRST_D3;
5196 set_pin_power_state(codec, 0x19, &parm);
5197 /* Smart 5.1 PW2(1bh) */
5198 if (spec->smart51_enabled)
5199 set_pin_power_state(codec, 0x1b, &parm);
5200 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5201 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5202
5203 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5204 parm = AC_PWRST_D3;
5205 set_pin_power_state(codec, 0x23, &parm);
5206 /* Smart 5.1 PW1(1ah) */
5207 if (spec->smart51_enabled)
5208 set_pin_power_state(codec, 0x1a, &parm);
5209 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5210
5211 /* Smart 5.1 PW5(1eh) */
5212 if (spec->smart51_enabled)
5213 set_pin_power_state(codec, 0x1e, &parm);
5214 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5215
5216 /* Mono out */
5217 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5218 present = snd_hda_jack_detect(codec, 0x1c);
5219
5220 if (present)
5221 mono_out = 0;
5222 else {
5223 present = snd_hda_jack_detect(codec, 0x1d);
5224 if (!spec->hp_independent_mode && present)
5225 mono_out = 0;
5226 else
5227 mono_out = 1;
5228 }
5229 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5230 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5231 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5232 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5233
5234 /* PW 3/4 (1ch/1dh) */
5235 parm = AC_PWRST_D3;
5236 set_pin_power_state(codec, 0x1c, &parm);
5237 set_pin_power_state(codec, 0x1d, &parm);
5238 /* HP Independent Mode, power on AOW3 */
5239 if (spec->hp_independent_mode)
5240 snd_hda_codec_write(codec, 0x25, 0,
5241 AC_VERB_SET_POWER_STATE, parm);
5242
5243 /* force to D0 for internal Speaker */
5244 /* MW0 (16h), AOW0 (10h) */
5245 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5246 imux_is_smixer ? AC_PWRST_D0 : parm);
5247 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5248 mono_out ? AC_PWRST_D0 : parm);
5249}
5250
Lydia Wangf3db4232009-10-10 19:08:41 +08005251static int patch_vt1716S(struct hda_codec *codec)
5252{
5253 struct via_spec *spec;
5254 int err;
5255
5256 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005257 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005258 if (spec == NULL)
5259 return -ENOMEM;
5260
Lydia Wangf3db4232009-10-10 19:08:41 +08005261 /* automatic parse from the BIOS config */
5262 err = vt1716S_parse_auto_config(codec);
5263 if (err < 0) {
5264 via_free(codec);
5265 return err;
5266 } else if (!err) {
5267 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5268 "from BIOS. Using genenic mode...\n");
5269 }
5270
5271 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5272 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5273
5274 spec->stream_name_analog = "VT1716S Analog";
5275 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5276 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5277
5278 spec->stream_name_digital = "VT1716S Digital";
5279 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5280
5281 if (!spec->adc_nids && spec->input_mux) {
5282 spec->adc_nids = vt1716S_adc_nids;
5283 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5284 get_mux_nids(codec);
5285 override_mic_boost(codec, 0x1a, 0, 3, 40);
5286 override_mic_boost(codec, 0x1e, 0, 3, 40);
5287 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5288 spec->num_mixers++;
5289 }
5290
5291 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5292 spec->num_mixers++;
5293
5294 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5295
5296 codec->patch_ops = via_patch_ops;
5297
5298 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005299 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangf3db4232009-10-10 19:08:41 +08005300
5301#ifdef CONFIG_SND_HDA_POWER_SAVE
5302 spec->loopback.amplist = vt1716S_loopbacks;
5303#endif
5304
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005305 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08005306 return 0;
5307}
Lydia Wang25eaba22009-10-10 19:08:43 +08005308
5309/* for vt2002P */
5310
5311/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005312static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005313 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5314 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5315 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5316 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5317 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5318 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5319 HDA_INPUT),
5320 {
5321 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5322 /* The multiple "Capture Source" controls confuse alsamixer
5323 * So call somewhat different..
5324 */
5325 /* .name = "Capture Source", */
5326 .name = "Input Source",
5327 .count = 2,
5328 .info = via_mux_enum_info,
5329 .get = via_mux_enum_get,
5330 .put = via_mux_enum_put,
5331 },
5332 { } /* end */
5333};
5334
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005335static const struct hda_verb vt2002P_volume_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08005336 /* Class-D speaker related verbs */
5337 {0x1, 0xfe0, 0x4},
5338 {0x1, 0xfe9, 0x80},
5339 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08005340 /*
5341 * Unmute ADC0-1 and set the default input to mic-in
5342 */
5343 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5344 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5345
5346
5347 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5348 * mixer widget
5349 */
5350 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5351 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5352 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5353 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5354 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5355 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5356
5357 /* MUX Indices: Mic = 0 */
5358 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5359 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5360
5361 /* PW9 Output enable */
5362 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5363
5364 /* Enable Boost Volume backdoor */
5365 {0x1, 0xfb9, 0x24},
5366
5367 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5368 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5369 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5370 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5371 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5372 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5373 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5374 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5375 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5376
5377 /* set MUX0/1/4/8 = 0 (AOW0) */
5378 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5379 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5380 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5381 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5382
5383 /* set PW0 index=0 (MW0) */
5384 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5385
5386 /* Enable AOW0 to MW9 */
5387 {0x1, 0xfb8, 0x88},
5388 { }
5389};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005390static const struct hda_verb vt1802_volume_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08005391 /*
5392 * Unmute ADC0-1 and set the default input to mic-in
5393 */
5394 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5395 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5396
5397
5398 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5399 * mixer widget
5400 */
5401 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5402 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5403 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5404 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5405 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5406 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5407
5408 /* MUX Indices: Mic = 0 */
5409 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5410 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5411
5412 /* PW9 Output enable */
5413 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5414
5415 /* Enable Boost Volume backdoor */
5416 {0x1, 0xfb9, 0x24},
5417
5418 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5419 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5420 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5421 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5422 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5423 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5424 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5425 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5426 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5427
5428 /* set MUX0/1/4/8 = 0 (AOW0) */
5429 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5430 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5431 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5432 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5433
5434 /* set PW0 index=0 (MW0) */
5435 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5436
5437 /* Enable AOW0 to MW9 */
5438 {0x1, 0xfb8, 0x88},
5439 { }
5440};
Lydia Wang25eaba22009-10-10 19:08:43 +08005441
5442
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005443static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005444 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5445 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5446 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5447 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5448 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5449 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5450 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5451 { }
5452};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005453static const struct hda_verb vt1802_uniwill_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08005454 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5455 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5456 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5457 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5458 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5459 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5460 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5461 { }
5462};
Lydia Wang25eaba22009-10-10 19:08:43 +08005463
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005464static const struct hda_pcm_stream vt2002P_pcm_analog_playback = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005465 .substreams = 2,
5466 .channels_min = 2,
5467 .channels_max = 2,
5468 .nid = 0x8, /* NID to query formats and rates */
5469 .ops = {
5470 .open = via_playback_pcm_open,
5471 .prepare = via_playback_multi_pcm_prepare,
5472 .cleanup = via_playback_multi_pcm_cleanup,
5473 .close = via_pcm_open_close,
5474 },
5475};
5476
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005477static const struct hda_pcm_stream vt2002P_pcm_analog_capture = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005478 .substreams = 2,
5479 .channels_min = 2,
5480 .channels_max = 2,
5481 .nid = 0x10, /* NID to query formats and rates */
5482 .ops = {
5483 .open = via_pcm_open_close,
5484 .prepare = via_capture_pcm_prepare,
5485 .cleanup = via_capture_pcm_cleanup,
5486 .close = via_pcm_open_close,
5487 },
5488};
5489
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005490static const struct hda_pcm_stream vt2002P_pcm_digital_playback = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005491 .substreams = 1,
5492 .channels_min = 2,
5493 .channels_max = 2,
Lydia Wang25eaba22009-10-10 19:08:43 +08005494 /* NID is set in via_build_pcms */
5495 .ops = {
5496 .open = via_dig_playback_pcm_open,
5497 .close = via_dig_playback_pcm_close,
5498 .prepare = via_dig_playback_pcm_prepare,
5499 .cleanup = via_dig_playback_pcm_cleanup
5500 },
5501};
5502
5503/* fill in the dac_nids table from the parsed pin configuration */
5504static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5505 const struct auto_pin_cfg *cfg)
5506{
5507 spec->multiout.num_dacs = 1;
5508 spec->multiout.dac_nids = spec->private_dac_nids;
5509 if (cfg->line_out_pins[0])
Takashi Iwaidda14412011-05-02 11:29:30 +02005510 spec->private_dac_nids[0] = 0x8;
Lydia Wang25eaba22009-10-10 19:08:43 +08005511 return 0;
5512}
5513
5514/* add playback controls from the parsed DAC table */
5515static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5516 const struct auto_pin_cfg *cfg)
5517{
5518 int err;
Lydia Wang118909562011-03-23 17:57:34 +08005519 hda_nid_t sw_nid;
Lydia Wang25eaba22009-10-10 19:08:43 +08005520
5521 if (!cfg->line_out_pins[0])
5522 return -1;
5523
Lydia Wang118909562011-03-23 17:57:34 +08005524 if (spec->codec_type == VT1802)
5525 sw_nid = 0x28;
5526 else
5527 sw_nid = 0x26;
Lydia Wang25eaba22009-10-10 19:08:43 +08005528
5529 /* Line-Out: PortE */
5530 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5531 "Master Front Playback Volume",
5532 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5533 if (err < 0)
5534 return err;
5535 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5536 "Master Front Playback Switch",
Lydia Wang118909562011-03-23 17:57:34 +08005537 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
Lydia Wang25eaba22009-10-10 19:08:43 +08005538 if (err < 0)
5539 return err;
5540
5541 return 0;
5542}
5543
5544static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5545{
5546 int err;
5547
5548 if (!pin)
5549 return 0;
5550
5551 spec->multiout.hp_nid = 0x9;
5552 spec->hp_independent_mode_index = 1;
5553
5554 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5555 "Headphone Playback Volume",
5556 HDA_COMPOSE_AMP_VAL(
5557 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5558 if (err < 0)
5559 return err;
5560
5561 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5562 "Headphone Playback Switch",
5563 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5564 if (err < 0)
5565 return err;
5566
5567 create_hp_imux(spec);
5568 return 0;
5569}
5570
5571/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005572static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wang25eaba22009-10-10 19:08:43 +08005573 const struct auto_pin_cfg *cfg)
5574{
Takashi Iwai10a20af2010-09-09 16:28:02 +02005575 struct via_spec *spec = codec->spec;
Lydia Wang25eaba22009-10-10 19:08:43 +08005576 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005577 static const hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
Takashi Iwaif3268512010-08-30 11:00:19 +02005578 int err;
Lydia Wang25eaba22009-10-10 19:08:43 +08005579
Takashi Iwai10a20af2010-09-09 16:28:02 +02005580 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02005581 ARRAY_SIZE(pin_idxs));
5582 if (err < 0)
5583 return err;
Lydia Wang25eaba22009-10-10 19:08:43 +08005584 /* build volume/mute control of loopback */
Takashi Iwai7b315bb2010-08-30 13:06:30 +02005585 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
Lydia Wang25eaba22009-10-10 19:08:43 +08005586 if (err < 0)
5587 return err;
5588
Lydia Wang25eaba22009-10-10 19:08:43 +08005589 /* for digital mic select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005590 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
Lydia Wang25eaba22009-10-10 19:08:43 +08005591
5592 return 0;
5593}
5594
5595static int vt2002P_parse_auto_config(struct hda_codec *codec)
5596{
5597 struct via_spec *spec = codec->spec;
5598 int err;
5599
5600
5601 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5602 if (err < 0)
5603 return err;
5604
5605 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5606 if (err < 0)
5607 return err;
5608
5609 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5610 return 0; /* can't find valid BIOS pin config */
5611
5612 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5613 if (err < 0)
5614 return err;
5615 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5616 if (err < 0)
5617 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005618 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wang25eaba22009-10-10 19:08:43 +08005619 if (err < 0)
5620 return err;
5621
5622 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5623
5624 fill_dig_outs(codec);
5625
5626 if (spec->kctls.list)
5627 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5628
5629 spec->input_mux = &spec->private_imux[0];
5630
5631 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005632 via_hp_build(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08005633
5634 return 1;
5635}
5636
5637#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005638static const struct hda_amp_list vt2002P_loopbacks[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005639 { 0x21, HDA_INPUT, 0 },
5640 { 0x21, HDA_INPUT, 1 },
5641 { 0x21, HDA_INPUT, 2 },
5642 { } /* end */
5643};
5644#endif
5645
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005646static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5647{
5648 struct via_spec *spec = codec->spec;
5649 int imux_is_smixer;
5650 unsigned int parm;
5651 unsigned int present;
5652 /* MUX9 (1eh) = stereo mixer */
5653 imux_is_smixer =
5654 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5655 /* inputs */
5656 /* PW 5/6/7 (29h/2ah/2bh) */
5657 parm = AC_PWRST_D3;
5658 set_pin_power_state(codec, 0x29, &parm);
5659 set_pin_power_state(codec, 0x2a, &parm);
5660 set_pin_power_state(codec, 0x2b, &parm);
5661 parm = AC_PWRST_D0;
5662 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5663 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5664 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5665 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5666 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5667
5668 /* outputs */
5669 /* AOW0 (8h)*/
5670 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5671
Lydia Wang118909562011-03-23 17:57:34 +08005672 if (spec->codec_type == VT1802) {
5673 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5674 parm = AC_PWRST_D3;
5675 set_pin_power_state(codec, 0x28, &parm);
5676 snd_hda_codec_write(codec, 0x18, 0,
5677 AC_VERB_SET_POWER_STATE, parm);
5678 snd_hda_codec_write(codec, 0x38, 0,
5679 AC_VERB_SET_POWER_STATE, parm);
5680 } else {
5681 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5682 parm = AC_PWRST_D3;
5683 set_pin_power_state(codec, 0x26, &parm);
5684 snd_hda_codec_write(codec, 0x1c, 0,
5685 AC_VERB_SET_POWER_STATE, parm);
5686 snd_hda_codec_write(codec, 0x37, 0,
5687 AC_VERB_SET_POWER_STATE, parm);
5688 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005689
Lydia Wang118909562011-03-23 17:57:34 +08005690 if (spec->codec_type == VT1802) {
5691 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5692 parm = AC_PWRST_D3;
5693 set_pin_power_state(codec, 0x25, &parm);
5694 snd_hda_codec_write(codec, 0x15, 0,
5695 AC_VERB_SET_POWER_STATE, parm);
5696 snd_hda_codec_write(codec, 0x35, 0,
5697 AC_VERB_SET_POWER_STATE, parm);
5698 } else {
5699 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5700 parm = AC_PWRST_D3;
5701 set_pin_power_state(codec, 0x25, &parm);
5702 snd_hda_codec_write(codec, 0x19, 0,
5703 AC_VERB_SET_POWER_STATE, parm);
5704 snd_hda_codec_write(codec, 0x35, 0,
5705 AC_VERB_SET_POWER_STATE, parm);
5706 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005707
5708 if (spec->hp_independent_mode)
5709 snd_hda_codec_write(codec, 0x9, 0,
5710 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5711
5712 /* Class-D */
5713 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5714 present = snd_hda_jack_detect(codec, 0x25);
5715
5716 parm = AC_PWRST_D3;
5717 set_pin_power_state(codec, 0x24, &parm);
5718 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08005719 if (spec->codec_type == VT1802)
5720 snd_hda_codec_write(codec, 0x14, 0,
5721 AC_VERB_SET_POWER_STATE, parm);
5722 else
5723 snd_hda_codec_write(codec, 0x18, 0,
5724 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005725 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5726
5727 /* Mono Out */
5728 present = snd_hda_jack_detect(codec, 0x26);
5729
5730 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08005731 if (spec->codec_type == VT1802) {
5732 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5733 snd_hda_codec_write(codec, 0x33, 0,
5734 AC_VERB_SET_POWER_STATE, parm);
5735 snd_hda_codec_write(codec, 0x1c, 0,
5736 AC_VERB_SET_POWER_STATE, parm);
5737 snd_hda_codec_write(codec, 0x3c, 0,
5738 AC_VERB_SET_POWER_STATE, parm);
5739 } else {
5740 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5741 snd_hda_codec_write(codec, 0x31, 0,
5742 AC_VERB_SET_POWER_STATE, parm);
5743 snd_hda_codec_write(codec, 0x17, 0,
5744 AC_VERB_SET_POWER_STATE, parm);
5745 snd_hda_codec_write(codec, 0x3b, 0,
5746 AC_VERB_SET_POWER_STATE, parm);
5747 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005748 /* MW9 (21h) */
5749 if (imux_is_smixer || !is_aa_path_mute(codec))
5750 snd_hda_codec_write(codec, 0x21, 0,
5751 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5752 else
5753 snd_hda_codec_write(codec, 0x21, 0,
5754 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5755}
Lydia Wang25eaba22009-10-10 19:08:43 +08005756
5757/* patch for vt2002P */
5758static int patch_vt2002P(struct hda_codec *codec)
5759{
5760 struct via_spec *spec;
5761 int err;
5762
5763 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005764 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08005765 if (spec == NULL)
5766 return -ENOMEM;
5767
Lydia Wang25eaba22009-10-10 19:08:43 +08005768 /* automatic parse from the BIOS config */
5769 err = vt2002P_parse_auto_config(codec);
5770 if (err < 0) {
5771 via_free(codec);
5772 return err;
5773 } else if (!err) {
5774 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5775 "from BIOS. Using genenic mode...\n");
5776 }
5777
Lydia Wang118909562011-03-23 17:57:34 +08005778 if (spec->codec_type == VT1802)
5779 spec->init_verbs[spec->num_iverbs++] =
5780 vt1802_volume_init_verbs;
5781 else
5782 spec->init_verbs[spec->num_iverbs++] =
5783 vt2002P_volume_init_verbs;
Lydia Wang25eaba22009-10-10 19:08:43 +08005784
Lydia Wang118909562011-03-23 17:57:34 +08005785 if (spec->codec_type == VT1802)
5786 spec->init_verbs[spec->num_iverbs++] =
5787 vt1802_uniwill_init_verbs;
5788 else
5789 spec->init_verbs[spec->num_iverbs++] =
5790 vt2002P_uniwill_init_verbs;
5791
5792 if (spec->codec_type == VT1802)
5793 spec->stream_name_analog = "VT1802 Analog";
5794 else
5795 spec->stream_name_analog = "VT2002P Analog";
Lydia Wang25eaba22009-10-10 19:08:43 +08005796 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5797 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5798
Lydia Wang118909562011-03-23 17:57:34 +08005799 if (spec->codec_type == VT1802)
5800 spec->stream_name_digital = "VT1802 Digital";
5801 else
5802 spec->stream_name_digital = "VT2002P Digital";
Lydia Wang25eaba22009-10-10 19:08:43 +08005803 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5804
5805 if (!spec->adc_nids && spec->input_mux) {
5806 spec->adc_nids = vt2002P_adc_nids;
5807 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5808 get_mux_nids(codec);
5809 override_mic_boost(codec, 0x2b, 0, 3, 40);
5810 override_mic_boost(codec, 0x29, 0, 3, 40);
5811 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5812 spec->num_mixers++;
5813 }
5814
5815 codec->patch_ops = via_patch_ops;
5816
5817 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005818 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wang25eaba22009-10-10 19:08:43 +08005819
5820#ifdef CONFIG_SND_HDA_POWER_SAVE
5821 spec->loopback.amplist = vt2002P_loopbacks;
5822#endif
5823
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005824 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08005825 return 0;
5826}
Lydia Wangab6734e2009-10-10 19:08:46 +08005827
5828/* for vt1812 */
5829
5830/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005831static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005832 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5833 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5834 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5835 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5836 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5837 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5838 HDA_INPUT),
5839 {
5840 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5841 /* The multiple "Capture Source" controls confuse alsamixer
5842 * So call somewhat different..
5843 */
5844 .name = "Input Source",
5845 .count = 2,
5846 .info = via_mux_enum_info,
5847 .get = via_mux_enum_get,
5848 .put = via_mux_enum_put,
5849 },
5850 { } /* end */
5851};
5852
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005853static const struct hda_verb vt1812_volume_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005854 /*
5855 * Unmute ADC0-1 and set the default input to mic-in
5856 */
5857 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5858 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5859
5860
5861 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5862 * mixer widget
5863 */
5864 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5865 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5866 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5867 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5868 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5869 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5870
5871 /* MUX Indices: Mic = 0 */
5872 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5873 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5874
5875 /* PW9 Output enable */
5876 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5877
5878 /* Enable Boost Volume backdoor */
5879 {0x1, 0xfb9, 0x24},
5880
5881 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5882 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5883 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5884 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5885 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5886 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5887 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5888 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5889 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5890 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5891 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5892
5893 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5894 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5895 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5896 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5897 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5898 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5899
5900 /* Enable AOW0 to MW9 */
5901 {0x1, 0xfb8, 0xa8},
5902 { }
5903};
5904
5905
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005906static const struct hda_verb vt1812_uniwill_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005907 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5908 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5909 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5910 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5911 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5912 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5913 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5914 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5915 { }
5916};
5917
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005918static const struct hda_pcm_stream vt1812_pcm_analog_playback = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005919 .substreams = 2,
5920 .channels_min = 2,
5921 .channels_max = 2,
5922 .nid = 0x8, /* NID to query formats and rates */
5923 .ops = {
5924 .open = via_playback_pcm_open,
5925 .prepare = via_playback_multi_pcm_prepare,
5926 .cleanup = via_playback_multi_pcm_cleanup,
5927 .close = via_pcm_open_close,
5928 },
5929};
5930
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005931static const struct hda_pcm_stream vt1812_pcm_analog_capture = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005932 .substreams = 2,
5933 .channels_min = 2,
5934 .channels_max = 2,
5935 .nid = 0x10, /* NID to query formats and rates */
5936 .ops = {
5937 .open = via_pcm_open_close,
5938 .prepare = via_capture_pcm_prepare,
5939 .cleanup = via_capture_pcm_cleanup,
5940 .close = via_pcm_open_close,
5941 },
5942};
5943
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005944static const struct hda_pcm_stream vt1812_pcm_digital_playback = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005945 .substreams = 1,
5946 .channels_min = 2,
5947 .channels_max = 2,
Lydia Wangab6734e2009-10-10 19:08:46 +08005948 /* NID is set in via_build_pcms */
5949 .ops = {
5950 .open = via_dig_playback_pcm_open,
5951 .close = via_dig_playback_pcm_close,
5952 .prepare = via_dig_playback_pcm_prepare,
5953 .cleanup = via_dig_playback_pcm_cleanup
5954 },
5955};
5956/* fill in the dac_nids table from the parsed pin configuration */
5957static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5958 const struct auto_pin_cfg *cfg)
5959{
5960 spec->multiout.num_dacs = 1;
5961 spec->multiout.dac_nids = spec->private_dac_nids;
5962 if (cfg->line_out_pins[0])
Takashi Iwaidda14412011-05-02 11:29:30 +02005963 spec->private_dac_nids[0] = 0x8;
Lydia Wangab6734e2009-10-10 19:08:46 +08005964 return 0;
5965}
5966
5967
5968/* add playback controls from the parsed DAC table */
5969static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5970 const struct auto_pin_cfg *cfg)
5971{
5972 int err;
5973
5974 if (!cfg->line_out_pins[0])
5975 return -1;
5976
5977 /* Line-Out: PortE */
5978 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Takashi Iwai3d83e572010-04-14 14:36:23 +02005979 "Front Playback Volume",
Lydia Wangab6734e2009-10-10 19:08:46 +08005980 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5981 if (err < 0)
5982 return err;
5983 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
Takashi Iwai3d83e572010-04-14 14:36:23 +02005984 "Front Playback Switch",
Lydia Wangab6734e2009-10-10 19:08:46 +08005985 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5986 if (err < 0)
5987 return err;
5988
5989 return 0;
5990}
5991
5992static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5993{
5994 int err;
5995
5996 if (!pin)
5997 return 0;
5998
5999 spec->multiout.hp_nid = 0x9;
6000 spec->hp_independent_mode_index = 1;
6001
6002
6003 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
6004 "Headphone Playback Volume",
6005 HDA_COMPOSE_AMP_VAL(
6006 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
6007 if (err < 0)
6008 return err;
6009
6010 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
6011 "Headphone Playback Switch",
6012 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
6013 if (err < 0)
6014 return err;
6015
6016 create_hp_imux(spec);
6017 return 0;
6018}
6019
6020/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02006021static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangab6734e2009-10-10 19:08:46 +08006022 const struct auto_pin_cfg *cfg)
6023{
Takashi Iwai10a20af2010-09-09 16:28:02 +02006024 struct via_spec *spec = codec->spec;
Lydia Wangab6734e2009-10-10 19:08:46 +08006025 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwai90dd48a2011-05-02 12:38:19 +02006026 static const hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
Takashi Iwaif3268512010-08-30 11:00:19 +02006027 int err;
Lydia Wangab6734e2009-10-10 19:08:46 +08006028
Takashi Iwai10a20af2010-09-09 16:28:02 +02006029 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
Takashi Iwaif3268512010-08-30 11:00:19 +02006030 ARRAY_SIZE(pin_idxs));
6031 if (err < 0)
6032 return err;
Lydia Wangab6734e2009-10-10 19:08:46 +08006033
Lydia Wangab6734e2009-10-10 19:08:46 +08006034 /* build volume/mute control of loopback */
Takashi Iwai7b315bb2010-08-30 13:06:30 +02006035 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
Lydia Wangab6734e2009-10-10 19:08:46 +08006036 if (err < 0)
6037 return err;
6038
Lydia Wangab6734e2009-10-10 19:08:46 +08006039 /* for digital mic select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02006040 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
Lydia Wangab6734e2009-10-10 19:08:46 +08006041
6042 return 0;
6043}
6044
6045static int vt1812_parse_auto_config(struct hda_codec *codec)
6046{
6047 struct via_spec *spec = codec->spec;
6048 int err;
6049
6050
6051 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6052 if (err < 0)
6053 return err;
6054 fill_dig_outs(codec);
6055 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6056 if (err < 0)
6057 return err;
6058
6059 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6060 return 0; /* can't find valid BIOS pin config */
6061
6062 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6063 if (err < 0)
6064 return err;
6065 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6066 if (err < 0)
6067 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02006068 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangab6734e2009-10-10 19:08:46 +08006069 if (err < 0)
6070 return err;
6071
6072 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6073
6074 fill_dig_outs(codec);
6075
6076 if (spec->kctls.list)
6077 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6078
6079 spec->input_mux = &spec->private_imux[0];
6080
6081 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02006082 via_hp_build(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08006083
6084 return 1;
6085}
6086
6087#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02006088static const struct hda_amp_list vt1812_loopbacks[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08006089 { 0x21, HDA_INPUT, 0 },
6090 { 0x21, HDA_INPUT, 1 },
6091 { 0x21, HDA_INPUT, 2 },
6092 { } /* end */
6093};
6094#endif
6095
Lydia Wang3e95b9a2011-03-23 15:13:28 +08006096static void set_widgets_power_state_vt1812(struct hda_codec *codec)
6097{
6098 struct via_spec *spec = codec->spec;
6099 int imux_is_smixer =
6100 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
6101 unsigned int parm;
6102 unsigned int present;
6103 /* MUX10 (1eh) = stereo mixer */
6104 imux_is_smixer =
6105 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
6106 /* inputs */
6107 /* PW 5/6/7 (29h/2ah/2bh) */
6108 parm = AC_PWRST_D3;
6109 set_pin_power_state(codec, 0x29, &parm);
6110 set_pin_power_state(codec, 0x2a, &parm);
6111 set_pin_power_state(codec, 0x2b, &parm);
6112 parm = AC_PWRST_D0;
6113 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
6114 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
6115 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
6116 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
6117 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
6118
6119 /* outputs */
6120 /* AOW0 (8h)*/
6121 snd_hda_codec_write(codec, 0x8, 0,
6122 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6123
6124 /* PW4 (28h), MW4 (18h), MUX4(38h) */
6125 parm = AC_PWRST_D3;
6126 set_pin_power_state(codec, 0x28, &parm);
6127 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
6128 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
6129
6130 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
6131 parm = AC_PWRST_D3;
6132 set_pin_power_state(codec, 0x25, &parm);
6133 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
6134 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
6135 if (spec->hp_independent_mode)
6136 snd_hda_codec_write(codec, 0x9, 0,
6137 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6138
6139 /* Internal Speaker */
6140 /* PW0 (24h), MW0(14h), MUX0(34h) */
6141 present = snd_hda_jack_detect(codec, 0x25);
6142
6143 parm = AC_PWRST_D3;
6144 set_pin_power_state(codec, 0x24, &parm);
6145 if (present) {
6146 snd_hda_codec_write(codec, 0x14, 0,
6147 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6148 snd_hda_codec_write(codec, 0x34, 0,
6149 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6150 } else {
6151 snd_hda_codec_write(codec, 0x14, 0,
6152 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6153 snd_hda_codec_write(codec, 0x34, 0,
6154 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6155 }
6156
6157
6158 /* Mono Out */
6159 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6160 present = snd_hda_jack_detect(codec, 0x28);
6161
6162 parm = AC_PWRST_D3;
6163 set_pin_power_state(codec, 0x31, &parm);
6164 if (present) {
6165 snd_hda_codec_write(codec, 0x1c, 0,
6166 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6167 snd_hda_codec_write(codec, 0x3c, 0,
6168 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6169 snd_hda_codec_write(codec, 0x3e, 0,
6170 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6171 } else {
6172 snd_hda_codec_write(codec, 0x1c, 0,
6173 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6174 snd_hda_codec_write(codec, 0x3c, 0,
6175 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6176 snd_hda_codec_write(codec, 0x3e, 0,
6177 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6178 }
6179
6180 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6181 parm = AC_PWRST_D3;
6182 set_pin_power_state(codec, 0x33, &parm);
6183 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6184 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6185
6186}
Lydia Wangab6734e2009-10-10 19:08:46 +08006187
6188/* patch for vt1812 */
6189static int patch_vt1812(struct hda_codec *codec)
6190{
6191 struct via_spec *spec;
6192 int err;
6193
6194 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01006195 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08006196 if (spec == NULL)
6197 return -ENOMEM;
6198
Lydia Wangab6734e2009-10-10 19:08:46 +08006199 /* automatic parse from the BIOS config */
6200 err = vt1812_parse_auto_config(codec);
6201 if (err < 0) {
6202 via_free(codec);
6203 return err;
6204 } else if (!err) {
6205 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6206 "from BIOS. Using genenic mode...\n");
6207 }
6208
6209
6210 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6211 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6212
6213 spec->stream_name_analog = "VT1812 Analog";
6214 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6215 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6216
6217 spec->stream_name_digital = "VT1812 Digital";
6218 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6219
6220
6221 if (!spec->adc_nids && spec->input_mux) {
6222 spec->adc_nids = vt1812_adc_nids;
6223 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6224 get_mux_nids(codec);
6225 override_mic_boost(codec, 0x2b, 0, 3, 40);
6226 override_mic_boost(codec, 0x29, 0, 3, 40);
6227 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6228 spec->num_mixers++;
6229 }
6230
6231 codec->patch_ops = via_patch_ops;
6232
6233 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11006234 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangab6734e2009-10-10 19:08:46 +08006235
6236#ifdef CONFIG_SND_HDA_POWER_SAVE
6237 spec->loopback.amplist = vt1812_loopbacks;
6238#endif
6239
Lydia Wang3e95b9a2011-03-23 15:13:28 +08006240 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08006241 return 0;
6242}
6243
Joseph Chanc577b8a2006-11-29 15:29:40 +01006244/*
6245 * patch entries
6246 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02006247static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01006248 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6249 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6250 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6251 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6252 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006253 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006254 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006255 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006256 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006257 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006258 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006259 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006260 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006261 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006262 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006263 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006264 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006265 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006266 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006267 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006268 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006269 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006270 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006271 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006272 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006273 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006274 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006275 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006276 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006277 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006278 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006279 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006280 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006281 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006282 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006283 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006284 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006285 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006286 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006287 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006288 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006289 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006290 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006291 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08006292 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08006293 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006294 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006295 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006296 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006297 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006298 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006299 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006300 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006301 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006302 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006303 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006304 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006305 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006306 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006307 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006308 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006309 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006310 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006311 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006312 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006313 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006314 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006315 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08006316 { .id = 0x11060428, .name = "VT1718S",
6317 .patch = patch_vt1718S},
6318 { .id = 0x11064428, .name = "VT1718S",
6319 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08006320 { .id = 0x11060441, .name = "VT2020",
6321 .patch = patch_vt1718S},
6322 { .id = 0x11064441, .name = "VT1828S",
6323 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08006324 { .id = 0x11060433, .name = "VT1716S",
6325 .patch = patch_vt1716S},
6326 { .id = 0x1106a721, .name = "VT1716S",
6327 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08006328 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6329 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08006330 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08006331 { .id = 0x11060440, .name = "VT1818S",
6332 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08006333 { .id = 0x11060446, .name = "VT1802",
6334 .patch = patch_vt2002P},
6335 { .id = 0x11068446, .name = "VT1802",
6336 .patch = patch_vt2002P},
Joseph Chanc577b8a2006-11-29 15:29:40 +01006337 {} /* terminator */
6338};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006339
6340MODULE_ALIAS("snd-hda-codec-id:1106*");
6341
6342static struct hda_codec_preset_list via_list = {
6343 .preset = snd_hda_preset_via,
6344 .owner = THIS_MODULE,
6345};
6346
6347MODULE_LICENSE("GPL");
6348MODULE_DESCRIPTION("VIA HD-audio codec");
6349
6350static int __init patch_via_init(void)
6351{
6352 return snd_hda_add_codec_preset(&via_list);
6353}
6354
6355static void __exit patch_via_exit(void)
6356{
6357 snd_hda_delete_codec_preset(&via_list);
6358}
6359
6360module_init(patch_via_init)
6361module_exit(patch_via_exit)