blob: 78e679e76ca82a7fd10a5755c8ef22cf5fc98bad [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
Takashi Iwai4a796162011-06-17 17:53:38 +0200110struct nid_path {
111 int depth;
112 hda_nid_t path[5];
113 short idx[5];
114};
115
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800116struct via_spec {
117 /* codec parameterization */
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200118 const struct snd_kcontrol_new *mixers[6];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800119 unsigned int num_mixers;
120
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200121 const struct hda_verb *init_verbs[5];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800122 unsigned int num_iverbs;
123
Takashi Iwai82673bc2011-06-17 16:24:21 +0200124 char stream_name_analog[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200125 const struct hda_pcm_stream *stream_analog_playback;
126 const struct hda_pcm_stream *stream_analog_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800127
Takashi Iwai82673bc2011-06-17 16:24:21 +0200128 char stream_name_digital[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200129 const struct hda_pcm_stream *stream_digital_playback;
130 const struct hda_pcm_stream *stream_digital_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800131
132 /* playback */
133 struct hda_multi_out multiout;
134 hda_nid_t slave_dig_outs[2];
135
Takashi Iwai4a796162011-06-17 17:53:38 +0200136 struct nid_path out_path[4];
137 struct nid_path hp_path;
138 struct nid_path hp_dep_path;
139
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800140 /* capture */
141 unsigned int num_adc_nids;
Takashi Iwaia766d0d2011-06-17 09:01:29 +0200142 hda_nid_t adc_nids[3];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800143 hda_nid_t mux_nids[3];
Takashi Iwai620e2b22011-06-17 17:19:19 +0200144 hda_nid_t aa_mix_nid;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800145 hda_nid_t dig_in_nid;
146 hda_nid_t dig_in_pin;
147
148 /* capture source */
149 const struct hda_input_mux *input_mux;
150 unsigned int cur_mux[3];
151
152 /* PCM information */
153 struct hda_pcm pcm_rec[3];
154
155 /* dynamic controls, init_verbs and input_mux */
156 struct auto_pin_cfg autocfg;
157 struct snd_array kctls;
158 struct hda_input_mux private_imux[2];
159 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
160
161 /* HP mode source */
162 const struct hda_input_mux *hp_mux;
163 unsigned int hp_independent_mode;
164 unsigned int hp_independent_mode_index;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200165 unsigned int can_smart51;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800166 unsigned int smart51_enabled;
Lydia Wangf3db4232009-10-10 19:08:41 +0800167 unsigned int dmic_enabled;
Takashi Iwai24088a52011-06-17 16:59:21 +0200168 unsigned int no_pin_power_ctl;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800169 enum VIA_HDA_CODEC codec_type;
170
171 /* work to check hp jack state */
172 struct hda_codec *codec;
173 struct delayed_work vt1708_hp_work;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200174 int vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800175 int vt1708_hp_present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800176
177 void (*set_widgets_power_state)(struct hda_codec *codec);
178
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800179#ifdef CONFIG_SND_HDA_POWER_SAVE
180 struct hda_loopback_check loopback;
181#endif
182};
183
Lydia Wang0341ccd2011-03-22 16:25:03 +0800184static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100185static struct via_spec * via_new_spec(struct hda_codec *codec)
186{
187 struct via_spec *spec;
188
189 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
190 if (spec == NULL)
191 return NULL;
192
193 codec->spec = spec;
194 spec->codec = codec;
Lydia Wang0341ccd2011-03-22 16:25:03 +0800195 spec->codec_type = get_codec_type(codec);
196 /* VT1708BCE & VT1708S are almost same */
197 if (spec->codec_type == VT1708BCE)
198 spec->codec_type = VT1708S;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100199 return spec;
200}
201
Lydia Wang744ff5f2009-10-10 19:07:26 +0800202static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800203{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800204 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800205 u16 ven_id = vendor_id >> 16;
206 u16 dev_id = vendor_id & 0xffff;
207 enum VIA_HDA_CODEC codec_type;
208
209 /* get codec type */
210 if (ven_id != 0x1106)
211 codec_type = UNKNOWN;
212 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
213 codec_type = VT1708;
214 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
215 codec_type = VT1709_10CH;
216 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
217 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800218 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800219 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800220 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
221 codec_type = VT1708BCE;
222 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800223 codec_type = VT1708B_4CH;
224 else if ((dev_id & 0xfff) == 0x397
225 && (dev_id >> 12) < 8)
226 codec_type = VT1708S;
227 else if ((dev_id & 0xfff) == 0x398
228 && (dev_id >> 12) < 8)
229 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800230 else if ((dev_id & 0xfff) == 0x428
231 && (dev_id >> 12) < 8)
232 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800233 else if (dev_id == 0x0433 || dev_id == 0xa721)
234 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800235 else if (dev_id == 0x0441 || dev_id == 0x4441)
236 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800237 else if (dev_id == 0x0438 || dev_id == 0x4438)
238 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800239 else if (dev_id == 0x0448)
240 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800241 else if (dev_id == 0x0440)
242 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800243 else if ((dev_id & 0xfff) == 0x446)
244 codec_type = VT1802;
Harald Welted7426322008-09-15 22:43:23 +0800245 else
246 codec_type = UNKNOWN;
247 return codec_type;
248};
249
Lydia Wangec7e7e42011-03-24 12:43:44 +0800250#define VIA_JACK_EVENT 0x20
Harald Welte69e52a82008-09-09 15:57:32 +0800251#define VIA_HP_EVENT 0x01
252#define VIA_GPIO_EVENT 0x02
Lydia Wangec7e7e42011-03-24 12:43:44 +0800253#define VIA_MONO_EVENT 0x03
254#define VIA_SPEAKER_EVENT 0x04
255#define VIA_BIND_HP_EVENT 0x05
Harald Welte69e52a82008-09-09 15:57:32 +0800256
Joseph Chanc577b8a2006-11-29 15:29:40 +0100257enum {
258 VIA_CTL_WIDGET_VOL,
259 VIA_CTL_WIDGET_MUTE,
Lydia Wangf5271102009-10-10 19:07:35 +0800260 VIA_CTL_WIDGET_ANALOG_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800261 VIA_CTL_WIDGET_BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100262};
263
264enum {
Harald Welteeb14a462008-09-09 15:40:38 +0800265 AUTO_SEQ_FRONT = 0,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100266 AUTO_SEQ_SURROUND,
267 AUTO_SEQ_CENLFE,
268 AUTO_SEQ_SIDE
269};
270
Lydia Wangf5271102009-10-10 19:07:35 +0800271static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800272static int is_aa_path_mute(struct hda_codec *codec);
273
274static void vt1708_start_hp_work(struct via_spec *spec)
275{
276 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
277 return;
278 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200279 !spec->vt1708_jack_detect);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800280 if (!delayed_work_pending(&spec->vt1708_hp_work))
281 schedule_delayed_work(&spec->vt1708_hp_work,
282 msecs_to_jiffies(100));
283}
284
285static void vt1708_stop_hp_work(struct via_spec *spec)
286{
287 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
288 return;
289 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
290 && !is_aa_path_mute(spec->codec))
291 return;
292 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200293 !spec->vt1708_jack_detect);
Tejun Heo5b84ba22010-12-11 17:51:26 +0100294 cancel_delayed_work_sync(&spec->vt1708_hp_work);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800295}
Lydia Wangf5271102009-10-10 19:07:35 +0800296
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800297static void set_widgets_power_state(struct hda_codec *codec)
298{
299 struct via_spec *spec = codec->spec;
300 if (spec->set_widgets_power_state)
301 spec->set_widgets_power_state(codec);
302}
Lydia Wang25eaba22009-10-10 19:08:43 +0800303
Lydia Wangf5271102009-10-10 19:07:35 +0800304static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
305 struct snd_ctl_elem_value *ucontrol)
306{
307 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
308 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
309
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800310 set_widgets_power_state(codec);
Lydia Wangf5271102009-10-10 19:07:35 +0800311 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800312 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
313 if (is_aa_path_mute(codec))
314 vt1708_start_hp_work(codec->spec);
315 else
316 vt1708_stop_hp_work(codec->spec);
317 }
Lydia Wangf5271102009-10-10 19:07:35 +0800318 return change;
319}
320
321/* modify .put = snd_hda_mixer_amp_switch_put */
322#define ANALOG_INPUT_MUTE \
323 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
324 .name = NULL, \
325 .index = 0, \
326 .info = snd_hda_mixer_amp_switch_info, \
327 .get = snd_hda_mixer_amp_switch_get, \
328 .put = analog_input_switch_put, \
329 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
330
Lydia Wang25eaba22009-10-10 19:08:43 +0800331static void via_hp_bind_automute(struct hda_codec *codec);
332
333static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
334 struct snd_ctl_elem_value *ucontrol)
335{
336 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
337 struct via_spec *spec = codec->spec;
338 int i;
339 int change = 0;
340
341 long *valp = ucontrol->value.integer.value;
342 int lmute, rmute;
343 if (strstr(kcontrol->id.name, "Switch") == NULL) {
344 snd_printd("Invalid control!\n");
345 return change;
346 }
347 change = snd_hda_mixer_amp_switch_put(kcontrol,
348 ucontrol);
349 /* Get mute value */
350 lmute = *valp ? 0 : HDA_AMP_MUTE;
351 valp++;
352 rmute = *valp ? 0 : HDA_AMP_MUTE;
353
354 /* Set hp pins */
355 if (!spec->hp_independent_mode) {
356 for (i = 0; i < spec->autocfg.hp_outs; i++) {
357 snd_hda_codec_amp_update(
358 codec, spec->autocfg.hp_pins[i],
359 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
360 lmute);
361 snd_hda_codec_amp_update(
362 codec, spec->autocfg.hp_pins[i],
363 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
364 rmute);
365 }
366 }
367
368 if (!lmute && !rmute) {
369 /* Line Outs */
370 for (i = 0; i < spec->autocfg.line_outs; i++)
371 snd_hda_codec_amp_stereo(
372 codec, spec->autocfg.line_out_pins[i],
373 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
374 /* Speakers */
375 for (i = 0; i < spec->autocfg.speaker_outs; i++)
376 snd_hda_codec_amp_stereo(
377 codec, spec->autocfg.speaker_pins[i],
378 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
379 /* unmute */
380 via_hp_bind_automute(codec);
381
382 } else {
383 if (lmute) {
384 /* Mute all left channels */
385 for (i = 1; i < spec->autocfg.line_outs; i++)
386 snd_hda_codec_amp_update(
387 codec,
388 spec->autocfg.line_out_pins[i],
389 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
390 lmute);
391 for (i = 0; i < spec->autocfg.speaker_outs; i++)
392 snd_hda_codec_amp_update(
393 codec,
394 spec->autocfg.speaker_pins[i],
395 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
396 lmute);
397 }
398 if (rmute) {
399 /* mute all right channels */
400 for (i = 1; i < spec->autocfg.line_outs; i++)
401 snd_hda_codec_amp_update(
402 codec,
403 spec->autocfg.line_out_pins[i],
404 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
405 rmute);
406 for (i = 0; i < spec->autocfg.speaker_outs; i++)
407 snd_hda_codec_amp_update(
408 codec,
409 spec->autocfg.speaker_pins[i],
410 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
411 rmute);
412 }
413 }
414 return change;
415}
416
417#define BIND_PIN_MUTE \
418 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
419 .name = NULL, \
420 .index = 0, \
421 .info = snd_hda_mixer_amp_switch_info, \
422 .get = snd_hda_mixer_amp_switch_get, \
423 .put = bind_pin_switch_put, \
424 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
425
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200426static const struct snd_kcontrol_new via_control_templates[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100427 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
428 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Lydia Wangf5271102009-10-10 19:07:35 +0800429 ANALOG_INPUT_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800430 BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100431};
432
Lydia Wangab6734e2009-10-10 19:08:46 +0800433
Joseph Chanc577b8a2006-11-29 15:29:40 +0100434/* add dynamic controls */
Takashi Iwai291c9e32011-06-17 16:15:26 +0200435static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
436 const struct snd_kcontrol_new *tmpl,
437 const char *name)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100438{
439 struct snd_kcontrol_new *knew;
440
Takashi Iwai603c4012008-07-30 15:01:44 +0200441 snd_array_init(&spec->kctls, sizeof(*knew), 32);
442 knew = snd_array_new(&spec->kctls);
443 if (!knew)
Takashi Iwai291c9e32011-06-17 16:15:26 +0200444 return NULL;
445 *knew = *tmpl;
446 if (!name)
447 name = tmpl->name;
448 if (name) {
449 knew->name = kstrdup(name, GFP_KERNEL);
450 if (!knew->name)
451 return NULL;
452 }
453 return knew;
454}
455
456static int __via_add_control(struct via_spec *spec, int type, const char *name,
457 int idx, unsigned long val)
458{
459 struct snd_kcontrol_new *knew;
460
461 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
462 if (!knew)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100463 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100464 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100465 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100466 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100467 return 0;
468}
469
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200470#define via_add_control(spec, type, name, val) \
471 __via_add_control(spec, type, name, 0, val)
472
Takashi Iwai291c9e32011-06-17 16:15:26 +0200473#define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100474
Takashi Iwai603c4012008-07-30 15:01:44 +0200475static void via_free_kctls(struct hda_codec *codec)
476{
477 struct via_spec *spec = codec->spec;
478
479 if (spec->kctls.list) {
480 struct snd_kcontrol_new *kctl = spec->kctls.list;
481 int i;
482 for (i = 0; i < spec->kctls.used; i++)
483 kfree(kctl[i].name);
484 }
485 snd_array_free(&spec->kctls);
486}
487
Joseph Chanc577b8a2006-11-29 15:29:40 +0100488/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800489static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200490 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100491{
492 char name[32];
493 int err;
494
495 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200496 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100497 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
498 if (err < 0)
499 return err;
500 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200501 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100502 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
503 if (err < 0)
504 return err;
505 return 0;
506}
507
508static void via_auto_set_output_and_unmute(struct hda_codec *codec,
509 hda_nid_t nid, int pin_type,
510 int dac_idx)
511{
512 /* set as output */
513 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
514 pin_type);
515 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
516 AMP_OUT_UNMUTE);
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200517 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
Lydia Wang377ff312009-10-10 19:08:55 +0800518 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200519 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100520}
521
522
523static void via_auto_init_multi_out(struct hda_codec *codec)
524{
525 struct via_spec *spec = codec->spec;
526 int i;
527
528 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
529 hda_nid_t nid = spec->autocfg.line_out_pins[i];
530 if (nid)
531 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
532 }
533}
534
535static void via_auto_init_hp_out(struct hda_codec *codec)
536{
537 struct via_spec *spec = codec->spec;
538 hda_nid_t pin;
Lydia Wang25eaba22009-10-10 19:08:43 +0800539 int i;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100540
Lydia Wang25eaba22009-10-10 19:08:43 +0800541 for (i = 0; i < spec->autocfg.hp_outs; i++) {
542 pin = spec->autocfg.hp_pins[i];
543 if (pin) /* connect to front */
544 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
545 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100546}
547
Takashi Iwaif4a78282011-06-17 18:46:48 +0200548static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
Clemens Ladisch32e01912010-07-12 16:28:50 +0200549
Joseph Chanc577b8a2006-11-29 15:29:40 +0100550static void via_auto_init_analog_input(struct hda_codec *codec)
551{
552 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200553 const struct auto_pin_cfg *cfg = &spec->autocfg;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200554 unsigned int ctl;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100555 int i;
556
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200557 for (i = 0; i < cfg->num_inputs; i++) {
558 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200559 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
Clemens Ladisch32e01912010-07-12 16:28:50 +0200560 ctl = PIN_OUT;
David Henningsson30649672011-02-21 10:23:18 +0100561 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
Clemens Ladisch32e01912010-07-12 16:28:50 +0200562 ctl = PIN_VREF50;
563 else
564 ctl = PIN_IN;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100565 snd_hda_codec_write(codec, nid, 0,
Clemens Ladisch32e01912010-07-12 16:28:50 +0200566 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100567 }
568}
Lydia Wangf5271102009-10-10 19:07:35 +0800569
570static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
571 unsigned int *affected_parm)
572{
573 unsigned parm;
574 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
575 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
576 >> AC_DEFCFG_MISC_SHIFT
577 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800578 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200579 unsigned present = 0;
580
581 no_presence |= spec->no_pin_power_ctl;
582 if (!no_presence)
583 present = snd_hda_jack_detect(codec, nid);
Takashi Iwaif4a78282011-06-17 18:46:48 +0200584 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
Lydia Wang1564b282009-10-10 19:07:52 +0800585 || ((no_presence || present)
586 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800587 *affected_parm = AC_PWRST_D0; /* if it's connected */
588 parm = AC_PWRST_D0;
589 } else
590 parm = AC_PWRST_D3;
591
592 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
593}
594
Takashi Iwai24088a52011-06-17 16:59:21 +0200595static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
596 struct snd_ctl_elem_info *uinfo)
597{
598 static const char * const texts[] = {
599 "Disabled", "Enabled"
600 };
601
602 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
603 uinfo->count = 1;
604 uinfo->value.enumerated.items = 2;
605 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
606 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
607 strcpy(uinfo->value.enumerated.name,
608 texts[uinfo->value.enumerated.item]);
609 return 0;
610}
611
612static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
613 struct snd_ctl_elem_value *ucontrol)
614{
615 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
616 struct via_spec *spec = codec->spec;
617 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
618 return 0;
619}
620
621static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
622 struct snd_ctl_elem_value *ucontrol)
623{
624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
625 struct via_spec *spec = codec->spec;
626 unsigned int val = !ucontrol->value.enumerated.item[0];
627
628 if (val == spec->no_pin_power_ctl)
629 return 0;
630 spec->no_pin_power_ctl = val;
631 set_widgets_power_state(codec);
632 return 1;
633}
634
635static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
636 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
637 .name = "Dynamic Power-Control",
638 .info = via_pin_power_ctl_info,
639 .get = via_pin_power_ctl_get,
640 .put = via_pin_power_ctl_put,
641};
642
643
Joseph Chanc577b8a2006-11-29 15:29:40 +0100644/*
645 * input MUX handling
646 */
647static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_info *uinfo)
649{
650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
651 struct via_spec *spec = codec->spec;
652 return snd_hda_input_mux_info(spec->input_mux, uinfo);
653}
654
655static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
656 struct snd_ctl_elem_value *ucontrol)
657{
658 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
659 struct via_spec *spec = codec->spec;
660 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
661
662 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
663 return 0;
664}
665
666static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_value *ucontrol)
668{
669 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670 struct via_spec *spec = codec->spec;
671 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800672 int ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100673
Takashi Iwai337b9d02009-07-07 18:18:59 +0200674 if (!spec->mux_nids[adc_idx])
675 return -EINVAL;
Lydia Wanga80e6e32009-10-10 19:07:55 +0800676 /* switch to D0 beofre change index */
677 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
678 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
679 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
680 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800681
682 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
683 spec->mux_nids[adc_idx],
684 &spec->cur_mux[adc_idx]);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800685 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800686 set_widgets_power_state(codec);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800687
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800688 return ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100689}
690
Harald Welte0aa62ae2008-09-09 15:58:27 +0800691static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_info *uinfo)
693{
694 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
695 struct via_spec *spec = codec->spec;
696 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
697}
698
699static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
700 struct snd_ctl_elem_value *ucontrol)
701{
702 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100703 hda_nid_t nid = kcontrol->private_value;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800704 unsigned int pinsel;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800705
Lydia Wangeb7188c2009-10-10 19:08:34 +0800706 /* use !! to translate conn sel 2 for VT1718S */
707 pinsel = !!snd_hda_codec_read(codec, nid, 0,
708 AC_VERB_GET_CONNECT_SEL,
709 0x00);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800710 ucontrol->value.enumerated.item[0] = pinsel;
711
712 return 0;
713}
714
Lydia Wang0713efe2009-10-10 19:07:43 +0800715static void activate_ctl(struct hda_codec *codec, const char *name, int active)
716{
717 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
718 if (ctl) {
719 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
720 ctl->vd[0].access |= active
721 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
722 snd_ctl_notify(codec->bus->card,
723 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
724 }
725}
726
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100727static hda_nid_t side_mute_channel(struct via_spec *spec)
728{
729 switch (spec->codec_type) {
730 case VT1708: return 0x1b;
731 case VT1709_10CH: return 0x29;
732 case VT1708B_8CH: /* fall thru */
733 case VT1708S: return 0x27;
Lydia Wange87885f2011-03-24 12:39:05 +0800734 case VT2002P: return 0x19;
735 case VT1802: return 0x15;
736 case VT1812: return 0x15;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100737 default: return 0;
738 }
739}
740
Lydia Wangcdc17842009-10-10 19:07:47 +0800741static int update_side_mute_status(struct hda_codec *codec)
742{
743 /* mute side channel */
744 struct via_spec *spec = codec->spec;
Lydia Wange87885f2011-03-24 12:39:05 +0800745 unsigned int parm;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100746 hda_nid_t sw3 = side_mute_channel(spec);
Lydia Wangcdc17842009-10-10 19:07:47 +0800747
Lydia Wange87885f2011-03-24 12:39:05 +0800748 if (sw3) {
749 if (VT2002P_COMPATIBLE(spec))
750 parm = spec->hp_independent_mode ?
751 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
752 else
753 parm = spec->hp_independent_mode ?
754 AMP_OUT_MUTE : AMP_OUT_UNMUTE;
755 snd_hda_codec_write(codec, sw3, 0,
756 AC_VERB_SET_AMP_GAIN_MUTE, parm);
757 if (spec->codec_type == VT1812)
758 snd_hda_codec_write(codec, 0x1d, 0,
759 AC_VERB_SET_AMP_GAIN_MUTE, parm);
760 }
Lydia Wangcdc17842009-10-10 19:07:47 +0800761 return 0;
762}
763
Harald Welte0aa62ae2008-09-09 15:58:27 +0800764static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
765 struct snd_ctl_elem_value *ucontrol)
766{
767 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
768 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100769 hda_nid_t nid = kcontrol->private_value;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800770 unsigned int pinsel = ucontrol->value.enumerated.item[0];
Lydia Wangcdc17842009-10-10 19:07:47 +0800771 /* Get Independent Mode index of headphone pin widget */
772 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
773 ? 1 : 0;
Lydia Wangce0e5a92011-03-22 16:22:37 +0800774 if (spec->codec_type == VT1718S)
775 snd_hda_codec_write(codec, nid, 0,
776 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
777 else
778 snd_hda_codec_write(codec, nid, 0,
779 AC_VERB_SET_CONNECT_SEL, pinsel);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800780
Lydia Wangce0e5a92011-03-22 16:22:37 +0800781 if (spec->codec_type == VT1812)
782 snd_hda_codec_write(codec, 0x35, 0,
783 AC_VERB_SET_CONNECT_SEL, pinsel);
Lydia Wangcdc17842009-10-10 19:07:47 +0800784 if (spec->multiout.hp_nid && spec->multiout.hp_nid
785 != spec->multiout.dac_nids[HDA_FRONT])
786 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
787 0, 0, 0);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800788
Lydia Wangcdc17842009-10-10 19:07:47 +0800789 update_side_mute_status(codec);
Lydia Wang0713efe2009-10-10 19:07:43 +0800790 /* update HP volume/swtich active state */
791 if (spec->codec_type == VT1708S
Lydia Wangeb7188c2009-10-10 19:08:34 +0800792 || spec->codec_type == VT1702
Lydia Wangf3db4232009-10-10 19:08:41 +0800793 || spec->codec_type == VT1718S
Lydia Wang25eaba22009-10-10 19:08:43 +0800794 || spec->codec_type == VT1716S
Lydia Wang118909562011-03-23 17:57:34 +0800795 || VT2002P_COMPATIBLE(spec)) {
Lydia Wang0713efe2009-10-10 19:07:43 +0800796 activate_ctl(codec, "Headphone Playback Volume",
797 spec->hp_independent_mode);
798 activate_ctl(codec, "Headphone Playback Switch",
799 spec->hp_independent_mode);
800 }
Lydia Wangce0e5a92011-03-22 16:22:37 +0800801 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800802 set_widgets_power_state(codec);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800803 return 0;
804}
805
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200806static const struct snd_kcontrol_new via_hp_mixer[2] = {
Harald Welte0aa62ae2008-09-09 15:58:27 +0800807 {
808 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
809 .name = "Independent HP",
Harald Welte0aa62ae2008-09-09 15:58:27 +0800810 .info = via_independent_hp_info,
811 .get = via_independent_hp_get,
812 .put = via_independent_hp_put,
813 },
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100814 {
815 .iface = NID_MAPPING,
816 .name = "Independent HP",
817 },
Harald Welte0aa62ae2008-09-09 15:58:27 +0800818};
819
Takashi Iwai3d83e572010-04-14 14:36:23 +0200820static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100821{
Takashi Iwai3d83e572010-04-14 14:36:23 +0200822 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100823 struct snd_kcontrol_new *knew;
824 hda_nid_t nid;
Takashi Iwai3d83e572010-04-14 14:36:23 +0200825 int nums;
826 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100827
828 switch (spec->codec_type) {
829 case VT1718S:
830 nid = 0x34;
831 break;
832 case VT2002P:
Lydia Wang118909562011-03-23 17:57:34 +0800833 case VT1802:
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100834 nid = 0x35;
835 break;
836 case VT1812:
837 nid = 0x3d;
838 break;
839 default:
840 nid = spec->autocfg.hp_pins[0];
841 break;
842 }
843
Lydia Wangee3c35c2011-03-22 16:26:36 +0800844 if (spec->codec_type != VT1708) {
845 nums = snd_hda_get_connections(codec, nid,
846 conn, HDA_MAX_CONNECTIONS);
847 if (nums <= 1)
848 return 0;
849 }
Takashi Iwai3d83e572010-04-14 14:36:23 +0200850
851 knew = via_clone_control(spec, &via_hp_mixer[0]);
852 if (knew == NULL)
853 return -ENOMEM;
854
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100855 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
856 knew->private_value = nid;
857
858 knew = via_clone_control(spec, &via_hp_mixer[1]);
859 if (knew == NULL)
860 return -ENOMEM;
861 knew->subdevice = side_mute_channel(spec);
862
863 return 0;
864}
865
Lydia Wang1564b282009-10-10 19:07:52 +0800866static void notify_aa_path_ctls(struct hda_codec *codec)
867{
868 int i;
869 struct snd_ctl_elem_id id;
Lydia Wang525566c2011-04-28 16:03:39 +0800870 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
871 struct snd_kcontrol *ctl;
Lydia Wang1564b282009-10-10 19:07:52 +0800872
873 memset(&id, 0, sizeof(id));
874 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
875 for (i = 0; i < ARRAY_SIZE(labels); i++) {
876 sprintf(id.name, "%s Playback Volume", labels[i]);
Lydia Wang525566c2011-04-28 16:03:39 +0800877 ctl = snd_hda_find_mixer_ctl(codec, id.name);
878 if (ctl)
879 snd_ctl_notify(codec->bus->card,
880 SNDRV_CTL_EVENT_MASK_VALUE,
881 &ctl->id);
Lydia Wang1564b282009-10-10 19:07:52 +0800882 }
883}
884
885static void mute_aa_path(struct hda_codec *codec, int mute)
886{
887 struct via_spec *spec = codec->spec;
Lydia Wang1564b282009-10-10 19:07:52 +0800888 int start_idx;
889 int end_idx;
890 int i;
891 /* get nid of MW0 and start & end index */
892 switch (spec->codec_type) {
893 case VT1708:
Lydia Wang1564b282009-10-10 19:07:52 +0800894 start_idx = 2;
895 end_idx = 4;
896 break;
897 case VT1709_10CH:
898 case VT1709_6CH:
Lydia Wang1564b282009-10-10 19:07:52 +0800899 start_idx = 2;
900 end_idx = 4;
901 break;
902 case VT1708B_8CH:
903 case VT1708B_4CH:
904 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +0800905 case VT1716S:
Lydia Wang1564b282009-10-10 19:07:52 +0800906 start_idx = 2;
907 end_idx = 4;
908 break;
Lydia Wangab657e02011-03-22 16:23:23 +0800909 case VT1718S:
Lydia Wangab657e02011-03-22 16:23:23 +0800910 start_idx = 1;
911 end_idx = 3;
912 break;
Lydia Wang1564b282009-10-10 19:07:52 +0800913 default:
914 return;
915 }
916 /* check AA path's mute status */
917 for (i = start_idx; i <= end_idx; i++) {
918 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200919 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid, HDA_INPUT, i,
Lydia Wang1564b282009-10-10 19:07:52 +0800920 HDA_AMP_MUTE, val);
921 }
922}
Takashi Iwaif4a78282011-06-17 18:46:48 +0200923
924static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
Lydia Wang1564b282009-10-10 19:07:52 +0800925{
Takashi Iwaif4a78282011-06-17 18:46:48 +0200926 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200927 const struct auto_pin_cfg *cfg = &spec->autocfg;
928 int i;
929
930 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwaif4a78282011-06-17 18:46:48 +0200931 unsigned int defcfg;
932 if (pin != cfg->inputs[i].pin)
933 continue;
934 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
935 return false;
936 defcfg = snd_hda_codec_get_pincfg(codec, pin);
937 if (snd_hda_get_input_pin_attr(defcfg) < INPUT_PIN_ATTR_NORMAL)
938 return false;
939 return true;
Lydia Wang1564b282009-10-10 19:07:52 +0800940 }
Takashi Iwaif4a78282011-06-17 18:46:48 +0200941 return false;
Lydia Wang1564b282009-10-10 19:07:52 +0800942}
943
944static int via_smart51_info(struct snd_kcontrol *kcontrol,
945 struct snd_ctl_elem_info *uinfo)
946{
947 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
948 uinfo->count = 1;
949 uinfo->value.integer.min = 0;
950 uinfo->value.integer.max = 1;
951 return 0;
952}
953
954static int via_smart51_get(struct snd_kcontrol *kcontrol,
955 struct snd_ctl_elem_value *ucontrol)
956{
957 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
958 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200959 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800960 int on = 1;
961 int i;
962
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200963 for (i = 0; i < cfg->num_inputs; i++) {
964 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200965 unsigned int ctl;
Takashi Iwai86e29592010-09-09 14:50:17 +0200966 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200967 spec->hp_independent_mode && spec->codec_type != VT1718S)
968 continue; /* ignore FMic for independent HP */
Takashi Iwaif4a78282011-06-17 18:46:48 +0200969 if (!is_smart51_pins(codec, nid))
970 continue;
971 ctl = snd_hda_codec_read(codec, nid, 0,
972 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200973 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
974 on = 0;
Lydia Wang1564b282009-10-10 19:07:52 +0800975 }
976 *ucontrol->value.integer.value = on;
977 return 0;
978}
979
980static int via_smart51_put(struct snd_kcontrol *kcontrol,
981 struct snd_ctl_elem_value *ucontrol)
982{
983 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
984 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200985 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800986 int out_in = *ucontrol->value.integer.value
987 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +0800988 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 unsigned int parm;
993
Takashi Iwai86e29592010-09-09 14:50:17 +0200994 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200995 spec->hp_independent_mode && spec->codec_type != VT1718S)
Lydia Wang1564b282009-10-10 19:07:52 +0800996 continue; /* don't retask FMic for independent HP */
Takashi Iwaif4a78282011-06-17 18:46:48 +0200997 if (!is_smart51_pins(codec, nid))
998 continue;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200999
1000 parm = snd_hda_codec_read(codec, nid, 0,
1001 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1002 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1003 parm |= out_in;
1004 snd_hda_codec_write(codec, nid, 0,
1005 AC_VERB_SET_PIN_WIDGET_CONTROL,
1006 parm);
1007 if (out_in == AC_PINCTL_OUT_EN) {
1008 mute_aa_path(codec, 1);
1009 notify_aa_path_ctls(codec);
1010 }
Lydia Wang1564b282009-10-10 19:07:52 +08001011 }
1012 spec->smart51_enabled = *ucontrol->value.integer.value;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001013 set_widgets_power_state(codec);
Lydia Wang1564b282009-10-10 19:07:52 +08001014 return 1;
1015}
1016
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001017static const struct snd_kcontrol_new via_smart51_mixer = {
1018 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1019 .name = "Smart 5.1",
1020 .count = 1,
1021 .info = via_smart51_info,
1022 .get = via_smart51_get,
1023 .put = via_smart51_put,
Lydia Wang1564b282009-10-10 19:07:52 +08001024};
1025
Takashi Iwaif4a78282011-06-17 18:46:48 +02001026static int via_smart51_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001027{
Takashi Iwaif4a78282011-06-17 18:46:48 +02001028 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001029 struct snd_kcontrol_new *knew;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001030 const struct auto_pin_cfg *cfg = &spec->autocfg;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001031 hda_nid_t nid;
1032 int i;
1033
Takashi Iwaif4a78282011-06-17 18:46:48 +02001034 if (!spec->can_smart51)
Lydia Wangcb34c202011-04-27 17:44:16 +08001035 return 0;
1036
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001037 knew = via_clone_control(spec, &via_smart51_mixer);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001038 if (knew == NULL)
1039 return -ENOMEM;
1040
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001041 for (i = 0; i < cfg->num_inputs; i++) {
1042 nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001043 if (is_smart51_pins(codec, nid)) {
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001044 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001045 break;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001046 }
1047 }
1048
1049 return 0;
1050}
1051
Joseph Chanc577b8a2006-11-29 15:29:40 +01001052/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001053static const struct snd_kcontrol_new vt1708_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001054 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1055 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1056 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1057 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1058 {
1059 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1060 /* The multiple "Capture Source" controls confuse alsamixer
1061 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01001062 */
1063 /* .name = "Capture Source", */
1064 .name = "Input Source",
1065 .count = 1,
1066 .info = via_mux_enum_info,
1067 .get = via_mux_enum_get,
1068 .put = via_mux_enum_put,
1069 },
1070 { } /* end */
1071};
Lydia Wangf5271102009-10-10 19:07:35 +08001072
1073/* check AA path's mute statue */
1074static int is_aa_path_mute(struct hda_codec *codec)
1075{
1076 int mute = 1;
Lydia Wangf5271102009-10-10 19:07:35 +08001077 int start_idx;
1078 int end_idx;
1079 int i;
1080 struct via_spec *spec = codec->spec;
1081 /* get nid of MW0 and start & end index */
1082 switch (spec->codec_type) {
1083 case VT1708B_8CH:
1084 case VT1708B_4CH:
1085 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001086 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001087 start_idx = 2;
1088 end_idx = 4;
1089 break;
1090 case VT1702:
Lydia Wangf5271102009-10-10 19:07:35 +08001091 start_idx = 1;
1092 end_idx = 3;
1093 break;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001094 case VT1718S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001095 start_idx = 1;
1096 end_idx = 3;
1097 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001098 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001099 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001100 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001101 start_idx = 0;
1102 end_idx = 2;
1103 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001104 default:
1105 return 0;
1106 }
1107 /* check AA path's mute status */
1108 for (i = start_idx; i <= end_idx; i++) {
1109 unsigned int con_list = snd_hda_codec_read(
Takashi Iwai620e2b22011-06-17 17:19:19 +02001110 codec, spec->aa_mix_nid, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
Lydia Wangf5271102009-10-10 19:07:35 +08001111 int shift = 8 * (i % 4);
1112 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1113 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1114 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1115 /* check mute status while the pin is connected */
Takashi Iwai620e2b22011-06-17 17:19:19 +02001116 int mute_l = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 0,
Lydia Wangf5271102009-10-10 19:07:35 +08001117 HDA_INPUT, i) >> 7;
Takashi Iwai620e2b22011-06-17 17:19:19 +02001118 int mute_r = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 1,
Lydia Wangf5271102009-10-10 19:07:35 +08001119 HDA_INPUT, i) >> 7;
1120 if (!mute_l || !mute_r) {
1121 mute = 0;
1122 break;
1123 }
1124 }
1125 }
1126 return mute;
1127}
1128
1129/* enter/exit analog low-current mode */
1130static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1131{
1132 struct via_spec *spec = codec->spec;
1133 static int saved_stream_idle = 1; /* saved stream idle status */
1134 int enable = is_aa_path_mute(codec);
1135 unsigned int verb = 0;
1136 unsigned int parm = 0;
1137
1138 if (stream_idle == -1) /* stream status did not change */
1139 enable = enable && saved_stream_idle;
1140 else {
1141 enable = enable && stream_idle;
1142 saved_stream_idle = stream_idle;
1143 }
1144
1145 /* decide low current mode's verb & parameter */
1146 switch (spec->codec_type) {
1147 case VT1708B_8CH:
1148 case VT1708B_4CH:
1149 verb = 0xf70;
1150 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1151 break;
1152 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001153 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001154 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001155 verb = 0xf73;
1156 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1157 break;
1158 case VT1702:
1159 verb = 0xf73;
1160 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1161 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001162 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001163 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001164 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001165 verb = 0xf93;
1166 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1167 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001168 default:
1169 return; /* other codecs are not supported */
1170 }
1171 /* send verb */
1172 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1173}
1174
Joseph Chanc577b8a2006-11-29 15:29:40 +01001175/*
1176 * generic initialization of ADC, input mixers and output mixers
1177 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001178static const struct hda_verb vt1708_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001179 /*
1180 * Unmute ADC0-1 and set the default input to mic-in
1181 */
1182 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1183 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1184
1185
Josepch Chanf7278fd2007-12-13 16:40:40 +01001186 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01001187 * mixer widget
1188 */
1189 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01001190 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1191 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1192 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1193 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1194 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001195
1196 /*
1197 * Set up output mixers (0x19 - 0x1b)
1198 */
1199 /* set vol=0 to output mixers */
1200 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1201 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1202 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Lydia Wang377ff312009-10-10 19:08:55 +08001203
Lydia Wangbfdc6752009-10-10 19:08:50 +08001204 /* Setup default input MW0 to PW4 */
1205 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001206 /* PW9 Output enable */
1207 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangaa266fc2011-03-24 12:41:01 +08001208 /* power down jack detect function */
1209 {0x1, 0xf81, 0x1},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001210 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001211};
1212
1213static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1214 struct hda_codec *codec,
1215 struct snd_pcm_substream *substream)
1216{
1217 struct via_spec *spec = codec->spec;
Lydia Wang17314372009-10-10 19:07:37 +08001218 int idle = substream->pstr->substream_opened == 1
1219 && substream->ref_count == 0;
Lydia Wang17314372009-10-10 19:07:37 +08001220 analog_low_current_mode(codec, idle);
Takashi Iwai9a081602008-02-12 18:37:26 +01001221 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1222 hinfo);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001223}
1224
Harald Welte0aa62ae2008-09-09 15:58:27 +08001225static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1226 unsigned int stream_tag,
1227 unsigned int format,
1228 struct snd_pcm_substream *substream)
1229{
1230 struct via_spec *spec = codec->spec;
1231 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001232 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001233 int chs = substream->runtime->channels;
1234 int i;
Stephen Warren7c935972011-06-01 11:14:17 -06001235 struct hda_spdif_out *spdif =
1236 snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001237
1238 mutex_lock(&codec->spdif_mutex);
1239 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1240 if (chs == 2 &&
1241 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1242 format) &&
Stephen Warren7c935972011-06-01 11:14:17 -06001243 !(spdif->status & IEC958_AES0_NONAUDIO)) {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001244 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1245 /* turn off SPDIF once; otherwise the IEC958 bits won't
1246 * be updated */
Stephen Warren7c935972011-06-01 11:14:17 -06001247 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001248 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1249 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001250 spdif->ctls &
Harald Welte0aa62ae2008-09-09 15:58:27 +08001251 ~AC_DIG1_ENABLE & 0xff);
1252 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1253 stream_tag, 0, format);
1254 /* turn on again (if needed) */
Stephen Warren7c935972011-06-01 11:14:17 -06001255 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001256 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1257 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001258 spdif->ctls & 0xff);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001259 } else {
1260 mout->dig_out_used = 0;
1261 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1262 0, 0, 0);
1263 }
1264 }
1265 mutex_unlock(&codec->spdif_mutex);
1266
1267 /* front */
1268 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1269 0, format);
1270
Lydia Wangeb7188c2009-10-10 19:08:34 +08001271 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1272 && !spec->hp_independent_mode)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001273 /* headphone out will just decode front left/right (stereo) */
1274 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1275 0, format);
1276
1277 /* extra outputs copied from front */
1278 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1279 if (mout->extra_out_nid[i])
1280 snd_hda_codec_setup_stream(codec,
1281 mout->extra_out_nid[i],
1282 stream_tag, 0, format);
1283
1284 /* surrounds */
1285 for (i = 1; i < mout->num_dacs; i++) {
1286 if (chs >= (i + 1) * 2) /* independent out */
1287 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1288 i * 2, format);
1289 else /* copy front */
1290 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1291 0, format);
1292 }
1293}
1294
1295static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1296 struct hda_codec *codec,
1297 unsigned int stream_tag,
1298 unsigned int format,
1299 struct snd_pcm_substream *substream)
1300{
1301 struct via_spec *spec = codec->spec;
1302 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001303 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001304
1305 if (substream->number == 0)
1306 playback_multi_pcm_prep_0(codec, stream_tag, format,
1307 substream);
1308 else {
1309 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1310 spec->hp_independent_mode)
1311 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1312 stream_tag, 0, format);
1313 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001314 vt1708_start_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001315 return 0;
1316}
1317
1318static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1319 struct hda_codec *codec,
1320 struct snd_pcm_substream *substream)
1321{
1322 struct via_spec *spec = codec->spec;
1323 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001324 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001325 int i;
1326
1327 if (substream->number == 0) {
1328 for (i = 0; i < mout->num_dacs; i++)
1329 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1330
1331 if (mout->hp_nid && !spec->hp_independent_mode)
1332 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1333 0, 0, 0);
1334
1335 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1336 if (mout->extra_out_nid[i])
1337 snd_hda_codec_setup_stream(codec,
1338 mout->extra_out_nid[i],
1339 0, 0, 0);
1340 mutex_lock(&codec->spdif_mutex);
1341 if (mout->dig_out_nid &&
1342 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1343 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1344 0, 0, 0);
1345 mout->dig_out_used = 0;
1346 }
1347 mutex_unlock(&codec->spdif_mutex);
1348 } else {
1349 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1350 spec->hp_independent_mode)
1351 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1352 0, 0, 0);
1353 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001354 vt1708_stop_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001355 return 0;
1356}
1357
Joseph Chanc577b8a2006-11-29 15:29:40 +01001358/*
1359 * Digital out
1360 */
1361static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1362 struct hda_codec *codec,
1363 struct snd_pcm_substream *substream)
1364{
1365 struct via_spec *spec = codec->spec;
1366 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1367}
1368
1369static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1370 struct hda_codec *codec,
1371 struct snd_pcm_substream *substream)
1372{
1373 struct via_spec *spec = codec->spec;
1374 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1375}
1376
Harald Welte5691ec72008-09-15 22:42:26 +08001377static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001378 struct hda_codec *codec,
1379 unsigned int stream_tag,
1380 unsigned int format,
1381 struct snd_pcm_substream *substream)
1382{
1383 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001384 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1385 stream_tag, format, substream);
1386}
Harald Welte5691ec72008-09-15 22:42:26 +08001387
Takashi Iwai9da29272009-05-07 16:31:14 +02001388static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1389 struct hda_codec *codec,
1390 struct snd_pcm_substream *substream)
1391{
1392 struct via_spec *spec = codec->spec;
1393 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001394 return 0;
1395}
1396
Joseph Chanc577b8a2006-11-29 15:29:40 +01001397/*
1398 * Analog capture
1399 */
1400static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1401 struct hda_codec *codec,
1402 unsigned int stream_tag,
1403 unsigned int format,
1404 struct snd_pcm_substream *substream)
1405{
1406 struct via_spec *spec = codec->spec;
1407
1408 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1409 stream_tag, 0, format);
1410 return 0;
1411}
1412
1413static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1414 struct hda_codec *codec,
1415 struct snd_pcm_substream *substream)
1416{
1417 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001418 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001419 return 0;
1420}
1421
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001422static const struct hda_pcm_stream vt1708_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001423 .substreams = 2,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001424 .channels_min = 2,
1425 .channels_max = 8,
1426 .nid = 0x10, /* NID to query formats and rates */
1427 .ops = {
1428 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001429 .prepare = via_playback_multi_pcm_prepare,
1430 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001431 },
1432};
1433
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001434static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Lydia Wangc873cc22009-10-10 19:08:21 +08001435 .substreams = 2,
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001436 .channels_min = 2,
1437 .channels_max = 8,
1438 .nid = 0x10, /* NID to query formats and rates */
1439 /* We got noisy outputs on the right channel on VT1708 when
1440 * 24bit samples are used. Until any workaround is found,
1441 * disable the 24bit format, so far.
1442 */
1443 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1444 .ops = {
1445 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08001446 .prepare = via_playback_multi_pcm_prepare,
1447 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001448 },
1449};
1450
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001451static const struct hda_pcm_stream vt1708_pcm_analog_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001452 .substreams = 2,
1453 .channels_min = 2,
1454 .channels_max = 2,
1455 .nid = 0x15, /* NID to query formats and rates */
1456 .ops = {
1457 .prepare = via_capture_pcm_prepare,
1458 .cleanup = via_capture_pcm_cleanup
1459 },
1460};
1461
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001462static const struct hda_pcm_stream vt1708_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001463 .substreams = 1,
1464 .channels_min = 2,
1465 .channels_max = 2,
1466 /* NID is set in via_build_pcms */
1467 .ops = {
1468 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001469 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001470 .prepare = via_dig_playback_pcm_prepare,
1471 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001472 },
1473};
1474
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001475static const struct hda_pcm_stream vt1708_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001476 .substreams = 1,
1477 .channels_min = 2,
1478 .channels_max = 2,
1479};
1480
1481static int via_build_controls(struct hda_codec *codec)
1482{
1483 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001484 struct snd_kcontrol *kctl;
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001485 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001486 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001487
Takashi Iwai24088a52011-06-17 16:59:21 +02001488 if (spec->set_widgets_power_state)
1489 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1490 return -ENOMEM;
1491
Joseph Chanc577b8a2006-11-29 15:29:40 +01001492 for (i = 0; i < spec->num_mixers; i++) {
1493 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1494 if (err < 0)
1495 return err;
1496 }
1497
1498 if (spec->multiout.dig_out_nid) {
1499 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001500 spec->multiout.dig_out_nid,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001501 spec->multiout.dig_out_nid);
1502 if (err < 0)
1503 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001504 err = snd_hda_create_spdif_share_sw(codec,
1505 &spec->multiout);
1506 if (err < 0)
1507 return err;
1508 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001509 }
1510 if (spec->dig_in_nid) {
1511 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1512 if (err < 0)
1513 return err;
1514 }
Lydia Wang17314372009-10-10 19:07:37 +08001515
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001516 /* assign Capture Source enums to NID */
1517 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1518 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +01001519 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001520 if (err < 0)
1521 return err;
1522 }
1523
1524 /* other nid->control mapping */
1525 for (i = 0; i < spec->num_mixers; i++) {
1526 for (knew = spec->mixers[i]; knew->name; knew++) {
1527 if (knew->iface != NID_MAPPING)
1528 continue;
1529 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1530 if (kctl == NULL)
1531 continue;
1532 err = snd_hda_add_nid(codec, kctl, 0,
1533 knew->subdevice);
1534 }
1535 }
1536
Lydia Wang17314372009-10-10 19:07:37 +08001537 /* init power states */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001538 set_widgets_power_state(codec);
Lydia Wang17314372009-10-10 19:07:37 +08001539 analog_low_current_mode(codec, 1);
1540
Takashi Iwai603c4012008-07-30 15:01:44 +02001541 via_free_kctls(codec); /* no longer needed */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001542 return 0;
1543}
1544
1545static int via_build_pcms(struct hda_codec *codec)
1546{
1547 struct via_spec *spec = codec->spec;
1548 struct hda_pcm *info = spec->pcm_rec;
1549
1550 codec->num_pcms = 1;
1551 codec->pcm_info = info;
1552
Takashi Iwai82673bc2011-06-17 16:24:21 +02001553 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1554 "%s Analog", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001555 info->name = spec->stream_name_analog;
Lydia Wang377ff312009-10-10 19:08:55 +08001556 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1557 *(spec->stream_analog_playback);
1558 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1559 spec->multiout.dac_nids[0];
Takashi Iwai57307bf2011-06-18 10:58:49 +02001560 if (!spec->multiout.hp_nid)
1561 info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001562 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1563 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1564
1565 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1566 spec->multiout.max_channels;
1567
1568 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1569 codec->num_pcms++;
1570 info++;
Takashi Iwai82673bc2011-06-17 16:24:21 +02001571 snprintf(spec->stream_name_digital,
1572 sizeof(spec->stream_name_digital),
1573 "%s Digital", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001574 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001575 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001576 if (spec->multiout.dig_out_nid) {
1577 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1578 *(spec->stream_digital_playback);
1579 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1580 spec->multiout.dig_out_nid;
1581 }
1582 if (spec->dig_in_nid) {
1583 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1584 *(spec->stream_digital_capture);
1585 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1586 spec->dig_in_nid;
1587 }
1588 }
1589
1590 return 0;
1591}
1592
1593static void via_free(struct hda_codec *codec)
1594{
1595 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001596
1597 if (!spec)
1598 return;
1599
Takashi Iwai603c4012008-07-30 15:01:44 +02001600 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001601 vt1708_stop_hp_work(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001602 kfree(codec->spec);
1603}
1604
Takashi Iwai64be2852011-06-17 16:51:39 +02001605/* mute/unmute outputs */
1606static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1607 hda_nid_t *pins, bool mute)
1608{
1609 int i;
1610 for (i = 0; i < num_pins; i++)
1611 snd_hda_codec_write(codec, pins[i], 0,
1612 AC_VERB_SET_PIN_WIDGET_CONTROL,
1613 mute ? 0 : PIN_OUT);
1614}
1615
Harald Welte69e52a82008-09-09 15:57:32 +08001616/* mute internal speaker if HP is plugged */
1617static void via_hp_automute(struct hda_codec *codec)
1618{
Lydia Wangdcf34c82009-10-10 19:08:15 +08001619 unsigned int present = 0;
Harald Welte69e52a82008-09-09 15:57:32 +08001620 struct via_spec *spec = codec->spec;
1621
Takashi Iwaid56757a2009-11-18 08:00:14 +01001622 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangdcf34c82009-10-10 19:08:15 +08001623
Takashi Iwai64be2852011-06-17 16:51:39 +02001624 if (!spec->hp_independent_mode)
1625 toggle_output_mutes(codec, spec->autocfg.line_outs,
1626 spec->autocfg.line_out_pins,
1627 present);
Harald Welte69e52a82008-09-09 15:57:32 +08001628}
1629
Lydia Wangf3db4232009-10-10 19:08:41 +08001630/* mute mono out if HP or Line out is plugged */
1631static void via_mono_automute(struct hda_codec *codec)
1632{
1633 unsigned int hp_present, lineout_present;
1634 struct via_spec *spec = codec->spec;
1635
1636 if (spec->codec_type != VT1716S)
1637 return;
1638
Takashi Iwaid56757a2009-11-18 08:00:14 +01001639 lineout_present = snd_hda_jack_detect(codec,
1640 spec->autocfg.line_out_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001641
1642 /* Mute Mono Out if Line Out is plugged */
1643 if (lineout_present) {
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001644 snd_hda_codec_write(codec, 0x2A, 0,
1645 AC_VERB_SET_PIN_WIDGET_CONTROL,
1646 lineout_present ? 0 : PIN_OUT);
Lydia Wangf3db4232009-10-10 19:08:41 +08001647 return;
1648 }
1649
Takashi Iwaid56757a2009-11-18 08:00:14 +01001650 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001651
1652 if (!spec->hp_independent_mode)
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001653 snd_hda_codec_write(codec, 0x2A, 0,
1654 AC_VERB_SET_PIN_WIDGET_CONTROL,
1655 hp_present ? 0 : PIN_OUT);
Lydia Wangf3db4232009-10-10 19:08:41 +08001656}
1657
Harald Welte69e52a82008-09-09 15:57:32 +08001658static void via_gpio_control(struct hda_codec *codec)
1659{
1660 unsigned int gpio_data;
1661 unsigned int vol_counter;
1662 unsigned int vol;
1663 unsigned int master_vol;
1664
1665 struct via_spec *spec = codec->spec;
1666
1667 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1668 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1669
1670 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1671 0xF84, 0) & 0x3F0000) >> 16;
1672
1673 vol = vol_counter & 0x1F;
1674 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1675 AC_VERB_GET_AMP_GAIN_MUTE,
1676 AC_AMP_GET_INPUT);
1677
1678 if (gpio_data == 0x02) {
1679 /* unmute line out */
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001680 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1681 AC_VERB_SET_PIN_WIDGET_CONTROL,
1682 PIN_OUT);
Harald Welte69e52a82008-09-09 15:57:32 +08001683 if (vol_counter & 0x20) {
1684 /* decrease volume */
1685 if (vol > master_vol)
1686 vol = master_vol;
1687 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1688 0, HDA_AMP_VOLMASK,
1689 master_vol-vol);
1690 } else {
1691 /* increase volume */
1692 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1693 HDA_AMP_VOLMASK,
1694 ((master_vol+vol) > 0x2A) ? 0x2A :
1695 (master_vol+vol));
1696 }
1697 } else if (!(gpio_data & 0x02)) {
1698 /* mute line out */
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001699 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1700 AC_VERB_SET_PIN_WIDGET_CONTROL,
1701 0);
Harald Welte69e52a82008-09-09 15:57:32 +08001702 }
1703}
1704
Lydia Wang25eaba22009-10-10 19:08:43 +08001705/* mute Internal-Speaker if HP is plugged */
1706static void via_speaker_automute(struct hda_codec *codec)
1707{
1708 unsigned int hp_present;
1709 struct via_spec *spec = codec->spec;
1710
Lydia Wang27439ce2011-03-24 12:40:10 +08001711 if (!VT2002P_COMPATIBLE(spec))
Lydia Wang25eaba22009-10-10 19:08:43 +08001712 return;
1713
Takashi Iwaid56757a2009-11-18 08:00:14 +01001714 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001715
Takashi Iwai64be2852011-06-17 16:51:39 +02001716 if (!spec->hp_independent_mode)
1717 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1718 spec->autocfg.speaker_pins,
1719 hp_present);
Lydia Wang25eaba22009-10-10 19:08:43 +08001720}
1721
1722/* mute line-out and internal speaker if HP is plugged */
1723static void via_hp_bind_automute(struct hda_codec *codec)
1724{
Takashi Iwai64be2852011-06-17 16:51:39 +02001725 int present;
Lydia Wang25eaba22009-10-10 19:08:43 +08001726 struct via_spec *spec = codec->spec;
Lydia Wang25eaba22009-10-10 19:08:43 +08001727
1728 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1729 return;
1730
Takashi Iwai64be2852011-06-17 16:51:39 +02001731 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1732 if (!spec->hp_independent_mode)
1733 toggle_output_mutes(codec, spec->autocfg.line_outs,
1734 spec->autocfg.line_out_pins,
1735 present);
Lydia Wang25eaba22009-10-10 19:08:43 +08001736
Takashi Iwai64be2852011-06-17 16:51:39 +02001737 if (!present)
1738 present = snd_hda_jack_detect(codec,
1739 spec->autocfg.line_out_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001740
Lydia Wang25eaba22009-10-10 19:08:43 +08001741 /* Speakers */
Takashi Iwai64be2852011-06-17 16:51:39 +02001742 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1743 spec->autocfg.speaker_pins,
1744 present);
Lydia Wang25eaba22009-10-10 19:08:43 +08001745}
1746
1747
Harald Welte69e52a82008-09-09 15:57:32 +08001748/* unsolicited event for jack sensing */
1749static void via_unsol_event(struct hda_codec *codec,
1750 unsigned int res)
1751{
1752 res >>= 26;
Lydia Wangec7e7e42011-03-24 12:43:44 +08001753
Lydia Wanga34df192009-10-10 19:08:01 +08001754 if (res & VIA_JACK_EVENT)
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001755 set_widgets_power_state(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001756
1757 res &= ~VIA_JACK_EVENT;
1758
1759 if (res == VIA_HP_EVENT)
1760 via_hp_automute(codec);
1761 else if (res == VIA_GPIO_EVENT)
1762 via_gpio_control(codec);
1763 else if (res == VIA_MONO_EVENT)
Lydia Wangf3db4232009-10-10 19:08:41 +08001764 via_mono_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001765 else if (res == VIA_SPEAKER_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001766 via_speaker_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001767 else if (res == VIA_BIND_HP_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001768 via_hp_bind_automute(codec);
Harald Welte69e52a82008-09-09 15:57:32 +08001769}
1770
Joseph Chanc577b8a2006-11-29 15:29:40 +01001771static int via_init(struct hda_codec *codec)
1772{
1773 struct via_spec *spec = codec->spec;
Harald Welte69e52a82008-09-09 15:57:32 +08001774 int i;
1775 for (i = 0; i < spec->num_iverbs; i++)
1776 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1777
Josepch Chanf7278fd2007-12-13 16:40:40 +01001778 /* Lydia Add for EAPD enable */
1779 if (!spec->dig_in_nid) { /* No Digital In connection */
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001780 if (spec->dig_in_pin) {
1781 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001782 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +01001783 PIN_OUT);
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001784 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001785 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1786 }
Takashi Iwai12b74c82008-01-15 12:39:38 +01001787 } else /* enable SPDIF-input pin */
1788 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1789 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
Josepch Chanf7278fd2007-12-13 16:40:40 +01001790
Takashi Iwai9da29272009-05-07 16:31:14 +02001791 /* assign slave outs */
1792 if (spec->slave_dig_outs[0])
1793 codec->slave_dig_outs = spec->slave_dig_outs;
Harald Welte5691ec72008-09-15 22:42:26 +08001794
Lydia Wang377ff312009-10-10 19:08:55 +08001795 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001796}
1797
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001798#ifdef SND_HDA_NEEDS_RESUME
1799static int via_suspend(struct hda_codec *codec, pm_message_t state)
1800{
1801 struct via_spec *spec = codec->spec;
1802 vt1708_stop_hp_work(spec);
1803 return 0;
1804}
1805#endif
1806
Takashi Iwaicb53c622007-08-10 17:21:45 +02001807#ifdef CONFIG_SND_HDA_POWER_SAVE
1808static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1809{
1810 struct via_spec *spec = codec->spec;
1811 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1812}
1813#endif
1814
Joseph Chanc577b8a2006-11-29 15:29:40 +01001815/*
1816 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001817static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001818 .build_controls = via_build_controls,
1819 .build_pcms = via_build_pcms,
1820 .init = via_init,
1821 .free = via_free,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001822#ifdef SND_HDA_NEEDS_RESUME
1823 .suspend = via_suspend,
1824#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02001825#ifdef CONFIG_SND_HDA_POWER_SAVE
1826 .check_power_status = via_check_power_status,
1827#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001828};
1829
Takashi Iwai4a796162011-06-17 17:53:38 +02001830static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001831{
Takashi Iwai4a796162011-06-17 17:53:38 +02001832 struct via_spec *spec = codec->spec;
1833 int i;
1834
1835 for (i = 0; i < spec->multiout.num_dacs; i++) {
1836 if (spec->multiout.dac_nids[i] == dac)
1837 return false;
1838 }
1839 if (spec->multiout.hp_nid == dac)
1840 return false;
1841 return true;
1842}
1843
1844static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1845 hda_nid_t target_dac, struct nid_path *path,
1846 int depth, int wid_type)
1847{
1848 hda_nid_t conn[8];
1849 int i, nums;
1850
1851 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1852 for (i = 0; i < nums; i++) {
1853 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1854 continue;
1855 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1856 path->path[depth] = conn[i];
1857 path->idx[depth] = i;
1858 path->depth = ++depth;
1859 return true;
1860 }
1861 }
1862 if (depth > 4)
1863 return false;
1864 for (i = 0; i < nums; i++) {
1865 unsigned int type;
1866 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1867 if (type == AC_WID_AUD_OUT ||
1868 (wid_type != -1 && type != wid_type))
1869 continue;
1870 if (parse_output_path(codec, conn[i], target_dac,
1871 path, depth + 1, AC_WID_AUD_SEL)) {
1872 path->path[depth] = conn[i];
1873 path->idx[depth] = i;
1874 return true;
1875 }
1876 }
1877 return false;
1878}
1879
1880static int via_auto_fill_dac_nids(struct hda_codec *codec)
1881{
1882 struct via_spec *spec = codec->spec;
1883 const struct auto_pin_cfg *cfg = &spec->autocfg;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001884 int i;
1885 hda_nid_t nid;
1886
Joseph Chanc577b8a2006-11-29 15:29:40 +01001887 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai4a796162011-06-17 17:53:38 +02001888 spec->multiout.num_dacs = cfg->line_outs;
1889 for (i = 0; i < cfg->line_outs; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001890 nid = cfg->line_out_pins[i];
Takashi Iwai4a796162011-06-17 17:53:38 +02001891 if (!nid)
1892 continue;
1893 if (parse_output_path(codec, nid, 0, &spec->out_path[i], 0, -1))
1894 spec->private_dac_nids[i] =
1895 spec->out_path[i].path[spec->out_path[i].depth - 1];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001896 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001897 return 0;
1898}
1899
Takashi Iwai4a796162011-06-17 17:53:38 +02001900static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1901 hda_nid_t pin, hda_nid_t dac, int chs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001902{
Takashi Iwai4a796162011-06-17 17:53:38 +02001903 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001904 char name[32];
Takashi Iwai4a796162011-06-17 17:53:38 +02001905 hda_nid_t nid;
1906 int err;
1907
1908 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1909 nid = dac;
1910 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1911 nid = pin;
1912 else
1913 nid = 0;
1914 if (nid) {
1915 sprintf(name, "%s Playback Volume", pfx);
1916 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1917 HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT));
1918 if (err < 0)
1919 return err;
1920 }
1921
1922 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1923 nid = dac;
1924 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1925 nid = pin;
1926 else
1927 nid = 0;
1928 if (nid) {
1929 sprintf(name, "%s Playback Switch", pfx);
1930 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1931 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1932 if (err < 0)
1933 return err;
1934 }
1935 return 0;
1936}
1937
1938static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
1939 hda_nid_t nid);
1940
Takashi Iwaif4a78282011-06-17 18:46:48 +02001941static void mangle_smart51(struct hda_codec *codec)
1942{
1943 struct via_spec *spec = codec->spec;
1944 struct auto_pin_cfg *cfg = &spec->autocfg;
1945 int i;
1946
1947 for (i = 0; i < cfg->num_inputs; i++) {
1948 if (!is_smart51_pins(codec, cfg->inputs[i].pin))
1949 continue;
1950 spec->can_smart51 = 1;
1951 cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin;
1952 if (cfg->line_outs == 3)
1953 break;
1954 }
1955}
1956
Takashi Iwai4a796162011-06-17 17:53:38 +02001957/* add playback controls from the parsed DAC table */
1958static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1959{
1960 struct via_spec *spec = codec->spec;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001961 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaiea734962011-01-17 11:29:34 +01001962 static const char * const chname[4] = {
1963 "Front", "Surround", "C/LFE", "Side"
1964 };
Takashi Iwai4a796162011-06-17 17:53:38 +02001965 int i, idx, err;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001966 int old_line_outs;
1967
1968 /* check smart51 */
1969 old_line_outs = cfg->line_outs;
1970 if (cfg->line_outs == 1)
1971 mangle_smart51(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001972
Takashi Iwai4a796162011-06-17 17:53:38 +02001973 for (i = 0; i < cfg->line_outs; i++) {
1974 hda_nid_t pin, dac;
1975 pin = cfg->line_out_pins[i];
1976 dac = spec->multiout.dac_nids[i];
1977 if (!pin || !dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001978 continue;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001979 if (i == AUTO_SEQ_CENLFE) {
Takashi Iwai4a796162011-06-17 17:53:38 +02001980 err = create_ch_ctls(codec, "Center", pin, dac, 1);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001981 if (err < 0)
1982 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02001983 err = create_ch_ctls(codec, "LFE", pin, dac, 2);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001984 if (err < 0)
1985 return err;
1986 } else {
Takashi Iwai4a796162011-06-17 17:53:38 +02001987 err = create_ch_ctls(codec, chname[i], pin, dac, 3);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001988 if (err < 0)
1989 return err;
1990 }
1991 }
1992
Takashi Iwai4a796162011-06-17 17:53:38 +02001993 idx = get_connection_index(codec, spec->aa_mix_nid,
1994 spec->multiout.dac_nids[0]);
1995 if (idx >= 0) {
1996 /* add control to mixer */
1997 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1998 "PCM Playback Volume",
1999 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2000 idx, HDA_INPUT));
2001 if (err < 0)
2002 return err;
2003 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2004 "PCM Playback Switch",
2005 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2006 idx, HDA_INPUT));
2007 if (err < 0)
2008 return err;
2009 }
2010
Takashi Iwaif4a78282011-06-17 18:46:48 +02002011 cfg->line_outs = old_line_outs;
2012
Joseph Chanc577b8a2006-11-29 15:29:40 +01002013 return 0;
2014}
2015
Harald Welte0aa62ae2008-09-09 15:58:27 +08002016static void create_hp_imux(struct via_spec *spec)
2017{
2018 int i;
2019 struct hda_input_mux *imux = &spec->private_imux[1];
Takashi Iwaiea734962011-01-17 11:29:34 +01002020 static const char * const texts[] = { "OFF", "ON", NULL};
Harald Welte0aa62ae2008-09-09 15:58:27 +08002021
2022 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002023 for (i = 0; texts[i]; i++)
2024 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Harald Welte0aa62ae2008-09-09 15:58:27 +08002025
2026 spec->hp_mux = &spec->private_imux[1];
2027}
2028
Takashi Iwai4a796162011-06-17 17:53:38 +02002029static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002030{
Takashi Iwai4a796162011-06-17 17:53:38 +02002031 struct via_spec *spec = codec->spec;
2032 hda_nid_t dac = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002033 int err;
2034
2035 if (!pin)
2036 return 0;
2037
Takashi Iwai4a796162011-06-17 17:53:38 +02002038 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2039 &spec->hp_dep_path, 0, -1))
2040 return 0;
2041 if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) {
2042 dac = spec->hp_path.path[spec->hp_path.depth - 1];
2043 spec->multiout.hp_nid = dac;
2044 spec->hp_independent_mode_index =
2045 spec->hp_path.idx[spec->hp_path.depth - 1];
2046 create_hp_imux(spec);
2047 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002048
Takashi Iwai4a796162011-06-17 17:53:38 +02002049 err = create_ch_ctls(codec, "Headphone", pin, dac, 3);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002050 if (err < 0)
2051 return err;
Harald Welte0aa62ae2008-09-09 15:58:27 +08002052
Joseph Chanc577b8a2006-11-29 15:29:40 +01002053 return 0;
2054}
2055
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002056static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
2057 hda_nid_t nid)
2058{
2059 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
2060 int i, nums;
2061
2062 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
2063 for (i = 0; i < nums; i++)
2064 if (conn[i] == nid)
2065 return i;
2066 return -1;
2067}
2068
2069/* look for ADCs */
2070static int via_fill_adcs(struct hda_codec *codec)
2071{
2072 struct via_spec *spec = codec->spec;
2073 hda_nid_t nid = codec->start_nid;
2074 int i;
2075
2076 for (i = 0; i < codec->num_nodes; i++, nid++) {
2077 unsigned int wcaps = get_wcaps(codec, nid);
2078 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2079 continue;
2080 if (wcaps & AC_WCAP_DIGITAL)
2081 continue;
2082 if (!(wcaps & AC_WCAP_CONN_LIST))
2083 continue;
2084 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2085 return -ENOMEM;
2086 spec->adc_nids[spec->num_adc_nids++] = nid;
2087 }
2088 return 0;
2089}
2090
2091static int get_mux_nids(struct hda_codec *codec);
2092
Joseph Chanc577b8a2006-11-29 15:29:40 +01002093/* create playback/capture controls for input pins */
Takashi Iwai620e2b22011-06-17 17:19:19 +02002094static int via_auto_create_analog_input_ctls(struct hda_codec *codec,
2095 const struct auto_pin_cfg *cfg)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002096{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002097 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08002098 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002099 int i, err, idx, idx2, type, type_idx = 0;
2100 hda_nid_t cap_nid;
2101 hda_nid_t pin_idxs[8];
2102 int num_idxs;
2103
2104 err = via_fill_adcs(codec);
2105 if (err < 0)
2106 return err;
2107 err = get_mux_nids(codec);
2108 if (err < 0)
2109 return err;
2110 cap_nid = spec->mux_nids[0];
2111
2112 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
2113 ARRAY_SIZE(pin_idxs));
2114 if (num_idxs <= 0)
2115 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002116
2117 /* for internal loopback recording select */
Takashi Iwaif3268512010-08-30 11:00:19 +02002118 for (idx = 0; idx < num_idxs; idx++) {
Takashi Iwai620e2b22011-06-17 17:19:19 +02002119 if (pin_idxs[idx] == spec->aa_mix_nid) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002120 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
Takashi Iwaif3268512010-08-30 11:00:19 +02002121 break;
2122 }
2123 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002124
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002125 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002126 const char *label;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002127 type = cfg->inputs[i].type;
Takashi Iwaif3268512010-08-30 11:00:19 +02002128 for (idx = 0; idx < num_idxs; idx++)
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002129 if (pin_idxs[idx] == cfg->inputs[i].pin)
Takashi Iwaif3268512010-08-30 11:00:19 +02002130 break;
2131 if (idx >= num_idxs)
2132 continue;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002133 if (i > 0 && type == cfg->inputs[i - 1].type)
2134 type_idx++;
2135 else
2136 type_idx = 0;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002137 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai620e2b22011-06-17 17:19:19 +02002138 idx2 = get_connection_index(codec, spec->aa_mix_nid,
2139 pin_idxs[idx]);
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002140 if (idx2 >= 0)
Lydia Wang16922282011-03-22 16:24:10 +08002141 err = via_new_analog_input(spec, label, type_idx,
Takashi Iwai620e2b22011-06-17 17:19:19 +02002142 idx2, spec->aa_mix_nid);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002143 if (err < 0)
2144 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002145 snd_hda_add_imux_item(imux, label, idx, NULL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002146 }
2147 return 0;
2148}
2149
Takashi Iwaicb53c622007-08-10 17:21:45 +02002150#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002151static const struct hda_amp_list vt1708_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002152 { 0x17, HDA_INPUT, 1 },
2153 { 0x17, HDA_INPUT, 2 },
2154 { 0x17, HDA_INPUT, 3 },
2155 { 0x17, HDA_INPUT, 4 },
2156 { } /* end */
2157};
2158#endif
2159
Harald Welte76d9b0d2008-09-09 15:50:37 +08002160static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2161{
2162 unsigned int def_conf;
2163 unsigned char seqassoc;
2164
Takashi Iwai2f334f92009-02-20 14:37:42 +01002165 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002166 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2167 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002168 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2169 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2170 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2171 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002172 }
2173
2174 return;
2175}
2176
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002177static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002178 struct snd_ctl_elem_value *ucontrol)
2179{
2180 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2181 struct via_spec *spec = codec->spec;
2182
2183 if (spec->codec_type != VT1708)
2184 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002185 spec->vt1708_jack_detect =
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002186 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002187 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002188 return 0;
2189}
2190
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002191static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002192 struct snd_ctl_elem_value *ucontrol)
2193{
2194 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2195 struct via_spec *spec = codec->spec;
2196 int change;
2197
2198 if (spec->codec_type != VT1708)
2199 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002200 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002201 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002202 == !spec->vt1708_jack_detect;
2203 if (spec->vt1708_jack_detect) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002204 mute_aa_path(codec, 1);
2205 notify_aa_path_ctls(codec);
2206 }
2207 return change;
2208}
2209
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002210static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2211 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2212 .name = "Jack Detect",
2213 .count = 1,
2214 .info = snd_ctl_boolean_mono_info,
2215 .get = vt1708_jack_detect_get,
2216 .put = vt1708_jack_detect_put,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002217};
2218
Joseph Chanc577b8a2006-11-29 15:29:40 +01002219static int vt1708_parse_auto_config(struct hda_codec *codec)
2220{
2221 struct via_spec *spec = codec->spec;
2222 int err;
2223
Harald Welte76d9b0d2008-09-09 15:50:37 +08002224 /* Add HP and CD pin config connect bit re-config action */
2225 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2226 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2227
Joseph Chanc577b8a2006-11-29 15:29:40 +01002228 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2229 if (err < 0)
2230 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002231 err = via_auto_fill_dac_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002232 if (err < 0)
2233 return err;
2234 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2235 return 0; /* can't find valid BIOS pin config */
2236
Takashi Iwai4a796162011-06-17 17:53:38 +02002237 err = via_auto_create_multi_out_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002238 if (err < 0)
2239 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002240 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002241 if (err < 0)
2242 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02002243 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002244 if (err < 0)
2245 return err;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002246 /* add jack detect on/off control */
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002247 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2248 return -ENOMEM;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002249
2250 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2251
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002252 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002253 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002254 spec->dig_in_pin = VT1708_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002255 if (spec->autocfg.dig_in_pin)
2256 spec->dig_in_nid = VT1708_DIGIN_NID;
2257
Takashi Iwai603c4012008-07-30 15:01:44 +02002258 if (spec->kctls.list)
2259 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002260
Harald Welte69e52a82008-09-09 15:57:32 +08002261 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002262
Harald Welte0aa62ae2008-09-09 15:58:27 +08002263 spec->input_mux = &spec->private_imux[0];
2264
Harald Weltef8fdd492008-09-15 22:41:31 +08002265 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002266 via_hp_build(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002267
Takashi Iwaif4a78282011-06-17 18:46:48 +02002268 err = via_smart51_build(codec);
2269 if (err < 0)
2270 return err;
2271
Joseph Chanc577b8a2006-11-29 15:29:40 +01002272 return 1;
2273}
2274
2275/* init callback for auto-configuration model -- overriding the default init */
2276static int via_auto_init(struct hda_codec *codec)
2277{
Lydia Wang25eaba22009-10-10 19:08:43 +08002278 struct via_spec *spec = codec->spec;
2279
Joseph Chanc577b8a2006-11-29 15:29:40 +01002280 via_init(codec);
2281 via_auto_init_multi_out(codec);
2282 via_auto_init_hp_out(codec);
2283 via_auto_init_analog_input(codec);
Lydia Wang118909562011-03-23 17:57:34 +08002284
2285 if (VT2002P_COMPATIBLE(spec)) {
Lydia Wang25eaba22009-10-10 19:08:43 +08002286 via_hp_bind_automute(codec);
2287 } else {
2288 via_hp_automute(codec);
2289 via_speaker_automute(codec);
2290 }
2291
Joseph Chanc577b8a2006-11-29 15:29:40 +01002292 return 0;
2293}
2294
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002295static void vt1708_update_hp_jack_state(struct work_struct *work)
2296{
2297 struct via_spec *spec = container_of(work, struct via_spec,
2298 vt1708_hp_work.work);
2299 if (spec->codec_type != VT1708)
2300 return;
2301 /* if jack state toggled */
2302 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002303 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002304 spec->vt1708_hp_present ^= 1;
2305 via_hp_automute(spec->codec);
2306 }
2307 vt1708_start_hp_work(spec);
2308}
2309
Takashi Iwai337b9d02009-07-07 18:18:59 +02002310static int get_mux_nids(struct hda_codec *codec)
2311{
2312 struct via_spec *spec = codec->spec;
2313 hda_nid_t nid, conn[8];
2314 unsigned int type;
2315 int i, n;
2316
2317 for (i = 0; i < spec->num_adc_nids; i++) {
2318 nid = spec->adc_nids[i];
2319 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002320 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002321 if (type == AC_WID_PIN)
2322 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002323 n = snd_hda_get_connections(codec, nid, conn,
2324 ARRAY_SIZE(conn));
2325 if (n <= 0)
2326 break;
2327 if (n > 1) {
2328 spec->mux_nids[i] = nid;
2329 break;
2330 }
2331 nid = conn[0];
2332 }
2333 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002334 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002335}
2336
Joseph Chanc577b8a2006-11-29 15:29:40 +01002337static int patch_vt1708(struct hda_codec *codec)
2338{
2339 struct via_spec *spec;
2340 int err;
2341
2342 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002343 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002344 if (spec == NULL)
2345 return -ENOMEM;
2346
Takashi Iwai620e2b22011-06-17 17:19:19 +02002347 spec->aa_mix_nid = 0x17;
2348
Joseph Chanc577b8a2006-11-29 15:29:40 +01002349 /* automatic parse from the BIOS config */
2350 err = vt1708_parse_auto_config(codec);
2351 if (err < 0) {
2352 via_free(codec);
2353 return err;
2354 } else if (!err) {
2355 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2356 "from BIOS. Using genenic mode...\n");
2357 }
2358
Lydia Wang377ff312009-10-10 19:08:55 +08002359
Joseph Chanc577b8a2006-11-29 15:29:40 +01002360 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
Takashi Iwaibc9b562382008-05-23 17:50:27 +02002361 /* disable 32bit format on VT1708 */
2362 if (codec->vendor_id == 0x11061708)
2363 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002364 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2365
Joseph Chanc577b8a2006-11-29 15:29:40 +01002366 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2367 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2368
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002369 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002370 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2371 spec->num_mixers++;
2372 }
2373
2374 codec->patch_ops = via_patch_ops;
2375
2376 codec->patch_ops.init = via_auto_init;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002377#ifdef CONFIG_SND_HDA_POWER_SAVE
2378 spec->loopback.amplist = vt1708_loopbacks;
2379#endif
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002380 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002381 return 0;
2382}
2383
2384/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002385static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002386 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2387 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2388 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2389 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2390 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2391 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2392 {
2393 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2394 /* The multiple "Capture Source" controls confuse alsamixer
2395 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01002396 */
2397 /* .name = "Capture Source", */
2398 .name = "Input Source",
2399 .count = 1,
2400 .info = via_mux_enum_info,
2401 .get = via_mux_enum_get,
2402 .put = via_mux_enum_put,
2403 },
2404 { } /* end */
2405};
2406
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002407static const struct hda_verb vt1709_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002408 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2409 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002410 { }
2411};
2412
Joseph Chanc577b8a2006-11-29 15:29:40 +01002413/*
2414 * generic initialization of ADC, input mixers and output mixers
2415 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002416static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002417 /*
2418 * Unmute ADC0-2 and set the default input to mic-in
2419 */
2420 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2421 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2422 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2423
2424
Josepch Chanf7278fd2007-12-13 16:40:40 +01002425 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01002426 * mixer widget
2427 */
2428 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01002429 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2430 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2431 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2432 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2433 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002434
2435 /*
2436 * Set up output selector (0x1a, 0x1b, 0x29)
2437 */
2438 /* set vol=0 to output mixers */
2439 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2440 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2441 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2442
2443 /*
2444 * Unmute PW3 and PW4
2445 */
2446 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2447 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2448
Lydia Wangbfdc6752009-10-10 19:08:50 +08002449 /* Set input of PW4 as MW0 */
2450 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002451 /* PW9 Output enable */
2452 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2453 { }
2454};
2455
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002456static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002457 .substreams = 1,
2458 .channels_min = 2,
2459 .channels_max = 10,
2460 .nid = 0x10, /* NID to query formats and rates */
2461 .ops = {
2462 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002463 .prepare = via_playback_multi_pcm_prepare,
2464 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002465 },
2466};
2467
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002468static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002469 .substreams = 1,
2470 .channels_min = 2,
2471 .channels_max = 6,
2472 .nid = 0x10, /* NID to query formats and rates */
2473 .ops = {
2474 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002475 .prepare = via_playback_multi_pcm_prepare,
2476 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002477 },
2478};
2479
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002480static const struct hda_pcm_stream vt1709_pcm_analog_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002481 .substreams = 2,
2482 .channels_min = 2,
2483 .channels_max = 2,
2484 .nid = 0x14, /* NID to query formats and rates */
2485 .ops = {
2486 .prepare = via_capture_pcm_prepare,
2487 .cleanup = via_capture_pcm_cleanup
2488 },
2489};
2490
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002491static const struct hda_pcm_stream vt1709_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002492 .substreams = 1,
2493 .channels_min = 2,
2494 .channels_max = 2,
2495 /* NID is set in via_build_pcms */
2496 .ops = {
2497 .open = via_dig_playback_pcm_open,
2498 .close = via_dig_playback_pcm_close
2499 },
2500};
2501
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002502static const struct hda_pcm_stream vt1709_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002503 .substreams = 1,
2504 .channels_min = 2,
2505 .channels_max = 2,
2506};
2507
Joseph Chanc577b8a2006-11-29 15:29:40 +01002508static int vt1709_parse_auto_config(struct hda_codec *codec)
2509{
2510 struct via_spec *spec = codec->spec;
2511 int err;
2512
2513 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2514 if (err < 0)
2515 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002516 err = via_auto_fill_dac_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002517 if (err < 0)
2518 return err;
2519 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2520 return 0; /* can't find valid BIOS pin config */
2521
Takashi Iwai4a796162011-06-17 17:53:38 +02002522 err = via_auto_create_multi_out_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002523 if (err < 0)
2524 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002525 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002526 if (err < 0)
2527 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02002528 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002529 if (err < 0)
2530 return err;
2531
2532 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2533
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002534 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002535 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002536 spec->dig_in_pin = VT1709_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002537 if (spec->autocfg.dig_in_pin)
2538 spec->dig_in_nid = VT1709_DIGIN_NID;
2539
Takashi Iwai603c4012008-07-30 15:01:44 +02002540 if (spec->kctls.list)
2541 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002542
Harald Welte0aa62ae2008-09-09 15:58:27 +08002543 spec->input_mux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01002544
Harald Weltef8fdd492008-09-15 22:41:31 +08002545 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002546 via_hp_build(codec);
Harald Weltef8fdd492008-09-15 22:41:31 +08002547
Takashi Iwaif4a78282011-06-17 18:46:48 +02002548 err = via_smart51_build(codec);
2549 if (err < 0)
2550 return err;
2551
Joseph Chanc577b8a2006-11-29 15:29:40 +01002552 return 1;
2553}
2554
Takashi Iwaicb53c622007-08-10 17:21:45 +02002555#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002556static const struct hda_amp_list vt1709_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002557 { 0x18, HDA_INPUT, 1 },
2558 { 0x18, HDA_INPUT, 2 },
2559 { 0x18, HDA_INPUT, 3 },
2560 { 0x18, HDA_INPUT, 4 },
2561 { } /* end */
2562};
2563#endif
2564
Joseph Chanc577b8a2006-11-29 15:29:40 +01002565static int patch_vt1709_10ch(struct hda_codec *codec)
2566{
2567 struct via_spec *spec;
2568 int err;
2569
2570 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002571 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002572 if (spec == NULL)
2573 return -ENOMEM;
2574
Takashi Iwai620e2b22011-06-17 17:19:19 +02002575 spec->aa_mix_nid = 0x18;
2576
Joseph Chanc577b8a2006-11-29 15:29:40 +01002577 err = vt1709_parse_auto_config(codec);
2578 if (err < 0) {
2579 via_free(codec);
2580 return err;
2581 } else if (!err) {
2582 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2583 "Using genenic mode...\n");
2584 }
2585
Harald Welte69e52a82008-09-09 15:57:32 +08002586 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2587 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002588
Joseph Chanc577b8a2006-11-29 15:29:40 +01002589 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2590 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2591
Joseph Chanc577b8a2006-11-29 15:29:40 +01002592 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2593 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2594
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002595 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002596 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2597 spec->num_mixers++;
2598 }
2599
2600 codec->patch_ops = via_patch_ops;
2601
2602 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002603 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002604#ifdef CONFIG_SND_HDA_POWER_SAVE
2605 spec->loopback.amplist = vt1709_loopbacks;
2606#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002607
2608 return 0;
2609}
2610/*
2611 * generic initialization of ADC, input mixers and output mixers
2612 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002613static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002614 /*
2615 * Unmute ADC0-2 and set the default input to mic-in
2616 */
2617 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2618 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2619 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2620
2621
2622 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2623 * mixer widget
2624 */
2625 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2626 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2627 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2628 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2629 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2630 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2631
2632 /*
2633 * Set up output selector (0x1a, 0x1b, 0x29)
2634 */
2635 /* set vol=0 to output mixers */
2636 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2637 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2638 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2639
2640 /*
2641 * Unmute PW3 and PW4
2642 */
2643 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2644 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2645
2646 /* Set input of PW4 as MW0 */
2647 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002648 /* PW9 Output enable */
2649 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2650 { }
2651};
2652
2653static int patch_vt1709_6ch(struct hda_codec *codec)
2654{
2655 struct via_spec *spec;
2656 int err;
2657
2658 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002659 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002660 if (spec == NULL)
2661 return -ENOMEM;
2662
Takashi Iwai620e2b22011-06-17 17:19:19 +02002663 spec->aa_mix_nid = 0x18;
2664
Joseph Chanc577b8a2006-11-29 15:29:40 +01002665 err = vt1709_parse_auto_config(codec);
2666 if (err < 0) {
2667 via_free(codec);
2668 return err;
2669 } else if (!err) {
2670 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2671 "Using genenic mode...\n");
2672 }
2673
Harald Welte69e52a82008-09-09 15:57:32 +08002674 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2675 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002676
Joseph Chanc577b8a2006-11-29 15:29:40 +01002677 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2678 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2679
Joseph Chanc577b8a2006-11-29 15:29:40 +01002680 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2681 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2682
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002683 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002684 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2685 spec->num_mixers++;
2686 }
2687
2688 codec->patch_ops = via_patch_ops;
2689
2690 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002691 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002692#ifdef CONFIG_SND_HDA_POWER_SAVE
2693 spec->loopback.amplist = vt1709_loopbacks;
2694#endif
Josepch Chanf7278fd2007-12-13 16:40:40 +01002695 return 0;
2696}
2697
2698/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002699static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002700 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2701 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2702 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2703 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2704 {
2705 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2706 /* The multiple "Capture Source" controls confuse alsamixer
2707 * So call somewhat different..
Josepch Chanf7278fd2007-12-13 16:40:40 +01002708 */
2709 /* .name = "Capture Source", */
2710 .name = "Input Source",
2711 .count = 1,
2712 .info = via_mux_enum_info,
2713 .get = via_mux_enum_get,
2714 .put = via_mux_enum_put,
2715 },
2716 { } /* end */
2717};
2718/*
2719 * generic initialization of ADC, input mixers and output mixers
2720 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002721static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002722 /*
2723 * Unmute ADC0-1 and set the default input to mic-in
2724 */
2725 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2726 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2727
2728
2729 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2730 * mixer widget
2731 */
2732 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2733 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2734 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2735 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2736 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2737 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2738
2739 /*
2740 * Set up output mixers
2741 */
2742 /* set vol=0 to output mixers */
2743 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2744 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2745 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2746
2747 /* Setup default input to PW4 */
Lydia Wangbfdc6752009-10-10 19:08:50 +08002748 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
Josepch Chanf7278fd2007-12-13 16:40:40 +01002749 /* PW9 Output enable */
2750 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2751 /* PW10 Input enable */
2752 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2753 { }
2754};
2755
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002756static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002757 /*
2758 * Unmute ADC0-1 and set the default input to mic-in
2759 */
2760 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2761 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2762
2763
2764 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2765 * mixer widget
2766 */
2767 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2768 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2769 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2770 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2771 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2772 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2773
2774 /*
2775 * Set up output mixers
2776 */
2777 /* set vol=0 to output mixers */
2778 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2779 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2780 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2781
2782 /* Setup default input of PW4 to MW0 */
2783 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2784 /* PW9 Output enable */
2785 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2786 /* PW10 Input enable */
2787 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2788 { }
2789};
2790
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002791static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002792 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2793 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2794 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2795 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2796 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2797 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2798 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2799 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2800 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002801 { }
2802};
2803
Lydia Wang17314372009-10-10 19:07:37 +08002804static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2805 struct hda_codec *codec,
2806 struct snd_pcm_substream *substream)
2807{
2808 int idle = substream->pstr->substream_opened == 1
2809 && substream->ref_count == 0;
2810
2811 analog_low_current_mode(codec, idle);
2812 return 0;
2813}
2814
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002815static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002816 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002817 .channels_min = 2,
2818 .channels_max = 8,
2819 .nid = 0x10, /* NID to query formats and rates */
2820 .ops = {
2821 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002822 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08002823 .cleanup = via_playback_multi_pcm_cleanup,
2824 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01002825 },
2826};
2827
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002828static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002829 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002830 .channels_min = 2,
2831 .channels_max = 4,
2832 .nid = 0x10, /* NID to query formats and rates */
2833 .ops = {
2834 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002835 .prepare = via_playback_multi_pcm_prepare,
2836 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002837 },
2838};
2839
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002840static const struct hda_pcm_stream vt1708B_pcm_analog_capture = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002841 .substreams = 2,
2842 .channels_min = 2,
2843 .channels_max = 2,
2844 .nid = 0x13, /* NID to query formats and rates */
2845 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08002846 .open = via_pcm_open_close,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002847 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08002848 .cleanup = via_capture_pcm_cleanup,
2849 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01002850 },
2851};
2852
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002853static const struct hda_pcm_stream vt1708B_pcm_digital_playback = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002854 .substreams = 1,
2855 .channels_min = 2,
2856 .channels_max = 2,
2857 /* NID is set in via_build_pcms */
2858 .ops = {
2859 .open = via_dig_playback_pcm_open,
2860 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02002861 .prepare = via_dig_playback_pcm_prepare,
2862 .cleanup = via_dig_playback_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002863 },
2864};
2865
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002866static const struct hda_pcm_stream vt1708B_pcm_digital_capture = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002867 .substreams = 1,
2868 .channels_min = 2,
2869 .channels_max = 2,
2870};
2871
Josepch Chanf7278fd2007-12-13 16:40:40 +01002872static int vt1708B_parse_auto_config(struct hda_codec *codec)
2873{
2874 struct via_spec *spec = codec->spec;
2875 int err;
2876
2877 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2878 if (err < 0)
2879 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002880 err = via_auto_fill_dac_nids(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002881 if (err < 0)
2882 return err;
2883 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2884 return 0; /* can't find valid BIOS pin config */
2885
Takashi Iwai4a796162011-06-17 17:53:38 +02002886 err = via_auto_create_multi_out_ctls(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002887 if (err < 0)
2888 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002889 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002890 if (err < 0)
2891 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02002892 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002893 if (err < 0)
2894 return err;
2895
2896 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2897
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002898 if (spec->autocfg.dig_outs)
Josepch Chanf7278fd2007-12-13 16:40:40 +01002899 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002900 spec->dig_in_pin = VT1708B_DIGIN_PIN;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002901 if (spec->autocfg.dig_in_pin)
2902 spec->dig_in_nid = VT1708B_DIGIN_NID;
2903
Takashi Iwai603c4012008-07-30 15:01:44 +02002904 if (spec->kctls.list)
2905 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002906
Harald Welte0aa62ae2008-09-09 15:58:27 +08002907 spec->input_mux = &spec->private_imux[0];
2908
Harald Weltef8fdd492008-09-15 22:41:31 +08002909 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002910 via_hp_build(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002911
Takashi Iwaif4a78282011-06-17 18:46:48 +02002912 err = via_smart51_build(codec);
2913 if (err < 0)
2914 return err;
2915
Josepch Chanf7278fd2007-12-13 16:40:40 +01002916 return 1;
2917}
2918
2919#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002920static const struct hda_amp_list vt1708B_loopbacks[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002921 { 0x16, HDA_INPUT, 1 },
2922 { 0x16, HDA_INPUT, 2 },
2923 { 0x16, HDA_INPUT, 3 },
2924 { 0x16, HDA_INPUT, 4 },
2925 { } /* end */
2926};
2927#endif
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002928
2929static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2930{
2931 struct via_spec *spec = codec->spec;
2932 int imux_is_smixer;
2933 unsigned int parm;
2934 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +08002935 if ((spec->codec_type != VT1708B_4CH) &&
2936 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002937 is_8ch = 1;
2938
2939 /* SW0 (17h) = stereo mixer */
2940 imux_is_smixer =
2941 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2942 == ((spec->codec_type == VT1708S) ? 5 : 0));
2943 /* inputs */
2944 /* PW 1/2/5 (1ah/1bh/1eh) */
2945 parm = AC_PWRST_D3;
2946 set_pin_power_state(codec, 0x1a, &parm);
2947 set_pin_power_state(codec, 0x1b, &parm);
2948 set_pin_power_state(codec, 0x1e, &parm);
2949 if (imux_is_smixer)
2950 parm = AC_PWRST_D0;
2951 /* SW0 (17h), AIW 0/1 (13h/14h) */
2952 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2953 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2954 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2955
2956 /* outputs */
2957 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2958 parm = AC_PWRST_D3;
2959 set_pin_power_state(codec, 0x19, &parm);
2960 if (spec->smart51_enabled)
2961 set_pin_power_state(codec, 0x1b, &parm);
2962 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2963 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2964
2965 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2966 if (is_8ch) {
2967 parm = AC_PWRST_D3;
2968 set_pin_power_state(codec, 0x22, &parm);
2969 if (spec->smart51_enabled)
2970 set_pin_power_state(codec, 0x1a, &parm);
2971 snd_hda_codec_write(codec, 0x26, 0,
2972 AC_VERB_SET_POWER_STATE, parm);
2973 snd_hda_codec_write(codec, 0x24, 0,
2974 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002975 } else if (codec->vendor_id == 0x11064397) {
2976 /* PW7(23h), SW2(27h), AOW2(25h) */
2977 parm = AC_PWRST_D3;
2978 set_pin_power_state(codec, 0x23, &parm);
2979 if (spec->smart51_enabled)
2980 set_pin_power_state(codec, 0x1a, &parm);
2981 snd_hda_codec_write(codec, 0x27, 0,
2982 AC_VERB_SET_POWER_STATE, parm);
2983 snd_hda_codec_write(codec, 0x25, 0,
2984 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002985 }
2986
2987 /* PW 3/4/7 (1ch/1dh/23h) */
2988 parm = AC_PWRST_D3;
2989 /* force to D0 for internal Speaker */
2990 set_pin_power_state(codec, 0x1c, &parm);
2991 set_pin_power_state(codec, 0x1d, &parm);
2992 if (is_8ch)
2993 set_pin_power_state(codec, 0x23, &parm);
2994
2995 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2996 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2997 imux_is_smixer ? AC_PWRST_D0 : parm);
2998 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2999 if (is_8ch) {
3000 snd_hda_codec_write(codec, 0x25, 0,
3001 AC_VERB_SET_POWER_STATE, parm);
3002 snd_hda_codec_write(codec, 0x27, 0,
3003 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08003004 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3005 snd_hda_codec_write(codec, 0x25, 0,
3006 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003007}
3008
Lydia Wang518bf3b2009-10-10 19:07:29 +08003009static int patch_vt1708S(struct hda_codec *codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003010static int patch_vt1708B_8ch(struct hda_codec *codec)
3011{
3012 struct via_spec *spec;
3013 int err;
3014
Lydia Wang518bf3b2009-10-10 19:07:29 +08003015 if (get_codec_type(codec) == VT1708BCE)
3016 return patch_vt1708S(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003017 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003018 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003019 if (spec == NULL)
3020 return -ENOMEM;
3021
Takashi Iwai620e2b22011-06-17 17:19:19 +02003022 spec->aa_mix_nid = 0x16;
3023
Josepch Chanf7278fd2007-12-13 16:40:40 +01003024 /* automatic parse from the BIOS config */
3025 err = vt1708B_parse_auto_config(codec);
3026 if (err < 0) {
3027 via_free(codec);
3028 return err;
3029 } else if (!err) {
3030 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3031 "from BIOS. Using genenic mode...\n");
3032 }
3033
Harald Welte69e52a82008-09-09 15:57:32 +08003034 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3035 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003036
Josepch Chanf7278fd2007-12-13 16:40:40 +01003037 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3038 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3039
Josepch Chanf7278fd2007-12-13 16:40:40 +01003040 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3041 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3042
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003043 if (spec->adc_nids && spec->input_mux) {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003044 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3045 spec->num_mixers++;
3046 }
3047
3048 codec->patch_ops = via_patch_ops;
3049
3050 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003051 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003052#ifdef CONFIG_SND_HDA_POWER_SAVE
3053 spec->loopback.amplist = vt1708B_loopbacks;
3054#endif
3055
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003056 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3057
Josepch Chanf7278fd2007-12-13 16:40:40 +01003058 return 0;
3059}
3060
3061static int patch_vt1708B_4ch(struct hda_codec *codec)
3062{
3063 struct via_spec *spec;
3064 int err;
3065
3066 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003067 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003068 if (spec == NULL)
3069 return -ENOMEM;
3070
Josepch Chanf7278fd2007-12-13 16:40:40 +01003071 /* automatic parse from the BIOS config */
3072 err = vt1708B_parse_auto_config(codec);
3073 if (err < 0) {
3074 via_free(codec);
3075 return err;
3076 } else if (!err) {
3077 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3078 "from BIOS. Using genenic mode...\n");
3079 }
3080
Harald Welte69e52a82008-09-09 15:57:32 +08003081 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3082 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003083
Josepch Chanf7278fd2007-12-13 16:40:40 +01003084 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3085 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3086
Josepch Chanf7278fd2007-12-13 16:40:40 +01003087 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3088 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3089
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003090 if (spec->adc_nids && spec->input_mux) {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003091 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3092 spec->num_mixers++;
3093 }
3094
3095 codec->patch_ops = via_patch_ops;
3096
3097 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003098 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003099#ifdef CONFIG_SND_HDA_POWER_SAVE
3100 spec->loopback.amplist = vt1708B_loopbacks;
3101#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01003102
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003103 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3104
Joseph Chanc577b8a2006-11-29 15:29:40 +01003105 return 0;
3106}
3107
Harald Welted949cac2008-09-09 15:56:01 +08003108/* Patch for VT1708S */
3109
3110/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003111static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003112 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3113 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3114 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3115 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
Lydia Wang6369bcf2009-10-10 19:08:31 +08003116 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3117 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3118 HDA_INPUT),
Harald Welted949cac2008-09-09 15:56:01 +08003119 {
3120 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3121 /* The multiple "Capture Source" controls confuse alsamixer
3122 * So call somewhat different..
3123 */
3124 /* .name = "Capture Source", */
3125 .name = "Input Source",
3126 .count = 1,
3127 .info = via_mux_enum_info,
3128 .get = via_mux_enum_get,
3129 .put = via_mux_enum_put,
3130 },
3131 { } /* end */
3132};
3133
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003134static const struct hda_verb vt1708S_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003135 /* Unmute ADC0-1 and set the default input to mic-in */
3136 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3137 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3138
3139 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3140 * analog-loopback mixer widget */
3141 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3142 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3143 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3144 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3145 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3146 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3147
3148 /* Setup default input of PW4 to MW0 */
3149 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
Harald Welte5691ec72008-09-15 22:42:26 +08003150 /* PW9, PW10 Output enable */
Harald Welted949cac2008-09-09 15:56:01 +08003151 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welte5691ec72008-09-15 22:42:26 +08003152 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welted7426322008-09-15 22:43:23 +08003153 /* Enable Mic Boost Volume backdoor */
3154 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003155 /* don't bybass mixer */
3156 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08003157 { }
3158};
3159
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003160static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003161 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3162 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3163 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3164 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3165 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3166 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3167 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3168 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3169 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003170 { }
3171};
3172
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003173static const struct hda_verb vt1705_uniwill_init_verbs[] = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003174 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3175 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3176 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3177 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3178 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3179 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3180 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3181 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3182 { }
3183};
3184
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003185static const struct hda_pcm_stream vt1708S_pcm_analog_playback = {
Harald Welted949cac2008-09-09 15:56:01 +08003186 .substreams = 2,
3187 .channels_min = 2,
3188 .channels_max = 8,
3189 .nid = 0x10, /* NID to query formats and rates */
3190 .ops = {
3191 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08003192 .prepare = via_playback_multi_pcm_prepare,
3193 .cleanup = via_playback_multi_pcm_cleanup,
Lydia Wang17314372009-10-10 19:07:37 +08003194 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003195 },
3196};
3197
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003198static const struct hda_pcm_stream vt1705_pcm_analog_playback = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003199 .substreams = 2,
3200 .channels_min = 2,
3201 .channels_max = 6,
3202 .nid = 0x10, /* NID to query formats and rates */
3203 .ops = {
3204 .open = via_playback_pcm_open,
3205 .prepare = via_playback_multi_pcm_prepare,
3206 .cleanup = via_playback_multi_pcm_cleanup,
3207 .close = via_pcm_open_close
3208 },
3209};
3210
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003211static const struct hda_pcm_stream vt1708S_pcm_analog_capture = {
Harald Welted949cac2008-09-09 15:56:01 +08003212 .substreams = 2,
3213 .channels_min = 2,
3214 .channels_max = 2,
3215 .nid = 0x13, /* NID to query formats and rates */
3216 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003217 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08003218 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003219 .cleanup = via_capture_pcm_cleanup,
3220 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003221 },
3222};
3223
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003224static const struct hda_pcm_stream vt1708S_pcm_digital_playback = {
Takashi Iwai9da29272009-05-07 16:31:14 +02003225 .substreams = 1,
Harald Welted949cac2008-09-09 15:56:01 +08003226 .channels_min = 2,
3227 .channels_max = 2,
3228 /* NID is set in via_build_pcms */
3229 .ops = {
3230 .open = via_dig_playback_pcm_open,
3231 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003232 .prepare = via_dig_playback_pcm_prepare,
3233 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08003234 },
3235};
3236
Takashi Iwai9da29272009-05-07 16:31:14 +02003237/* fill out digital output widgets; one for master and one for slave outputs */
3238static void fill_dig_outs(struct hda_codec *codec)
3239{
3240 struct via_spec *spec = codec->spec;
3241 int i;
3242
3243 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3244 hda_nid_t nid;
3245 int conn;
3246
3247 nid = spec->autocfg.dig_out_pins[i];
3248 if (!nid)
3249 continue;
3250 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3251 if (conn < 1)
3252 continue;
3253 if (!spec->multiout.dig_out_nid)
3254 spec->multiout.dig_out_nid = nid;
3255 else {
3256 spec->slave_dig_outs[0] = nid;
3257 break; /* at most two dig outs */
3258 }
3259 }
3260}
3261
Harald Welted949cac2008-09-09 15:56:01 +08003262static int vt1708S_parse_auto_config(struct hda_codec *codec)
3263{
3264 struct via_spec *spec = codec->spec;
3265 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003266
Takashi Iwai9da29272009-05-07 16:31:14 +02003267 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08003268 if (err < 0)
3269 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003270 err = via_auto_fill_dac_nids(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003271 if (err < 0)
3272 return err;
3273 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3274 return 0; /* can't find valid BIOS pin config */
3275
Takashi Iwai4a796162011-06-17 17:53:38 +02003276 err = via_auto_create_multi_out_ctls(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003277 if (err < 0)
3278 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003279 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Harald Welted949cac2008-09-09 15:56:01 +08003280 if (err < 0)
3281 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02003282 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003283 if (err < 0)
3284 return err;
3285
3286 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3287
Takashi Iwai9da29272009-05-07 16:31:14 +02003288 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08003289
Takashi Iwai603c4012008-07-30 15:01:44 +02003290 if (spec->kctls.list)
3291 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08003292
Harald Welte0aa62ae2008-09-09 15:58:27 +08003293 spec->input_mux = &spec->private_imux[0];
3294
Harald Weltef8fdd492008-09-15 22:41:31 +08003295 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003296 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003297
Takashi Iwaif4a78282011-06-17 18:46:48 +02003298 err = via_smart51_build(codec);
3299 if (err < 0)
3300 return err;
3301
Harald Welted949cac2008-09-09 15:56:01 +08003302 return 1;
3303}
3304
3305#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003306static const struct hda_amp_list vt1708S_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003307 { 0x16, HDA_INPUT, 1 },
3308 { 0x16, HDA_INPUT, 2 },
3309 { 0x16, HDA_INPUT, 3 },
3310 { 0x16, HDA_INPUT, 4 },
3311 { } /* end */
3312};
3313#endif
3314
Lydia Wang6369bcf2009-10-10 19:08:31 +08003315static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3316 int offset, int num_steps, int step_size)
3317{
3318 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3319 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3320 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3321 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3322 (0 << AC_AMPCAP_MUTE_SHIFT));
3323}
3324
Harald Welted949cac2008-09-09 15:56:01 +08003325static int patch_vt1708S(struct hda_codec *codec)
3326{
3327 struct via_spec *spec;
3328 int err;
3329
3330 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003331 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003332 if (spec == NULL)
3333 return -ENOMEM;
3334
Takashi Iwai620e2b22011-06-17 17:19:19 +02003335 spec->aa_mix_nid = 0x16;
3336
Harald Welted949cac2008-09-09 15:56:01 +08003337 /* automatic parse from the BIOS config */
3338 err = vt1708S_parse_auto_config(codec);
3339 if (err < 0) {
3340 via_free(codec);
3341 return err;
3342 } else if (!err) {
3343 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3344 "from BIOS. Using genenic mode...\n");
3345 }
3346
Harald Welte69e52a82008-09-09 15:57:32 +08003347 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
Lydia Wangbc92df72011-03-23 17:56:05 +08003348 if (codec->vendor_id == 0x11064397)
3349 spec->init_verbs[spec->num_iverbs++] =
3350 vt1705_uniwill_init_verbs;
3351 else
3352 spec->init_verbs[spec->num_iverbs++] =
3353 vt1708S_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003354
Lydia Wangbc92df72011-03-23 17:56:05 +08003355 if (codec->vendor_id == 0x11064397)
3356 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3357 else
3358 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
Harald Welted949cac2008-09-09 15:56:01 +08003359 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3360
Harald Welted949cac2008-09-09 15:56:01 +08003361 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3362
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003363 if (spec->adc_nids && spec->input_mux) {
Lydia Wang6369bcf2009-10-10 19:08:31 +08003364 override_mic_boost(codec, 0x1a, 0, 3, 40);
3365 override_mic_boost(codec, 0x1e, 0, 3, 40);
Harald Welted949cac2008-09-09 15:56:01 +08003366 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3367 spec->num_mixers++;
3368 }
3369
3370 codec->patch_ops = via_patch_ops;
3371
3372 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003373 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08003374#ifdef CONFIG_SND_HDA_POWER_SAVE
3375 spec->loopback.amplist = vt1708S_loopbacks;
3376#endif
3377
Lydia Wang518bf3b2009-10-10 19:07:29 +08003378 /* correct names for VT1708BCE */
3379 if (get_codec_type(codec) == VT1708BCE) {
3380 kfree(codec->chip_name);
3381 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3382 snprintf(codec->bus->card->mixername,
3383 sizeof(codec->bus->card->mixername),
3384 "%s %s", codec->vendor_name, codec->chip_name);
Lydia Wang970f630f2011-03-22 16:25:56 +08003385 }
Lydia Wangbc92df72011-03-23 17:56:05 +08003386 /* correct names for VT1705 */
3387 if (codec->vendor_id == 0x11064397) {
3388 kfree(codec->chip_name);
3389 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3390 snprintf(codec->bus->card->mixername,
3391 sizeof(codec->bus->card->mixername),
3392 "%s %s", codec->vendor_name, codec->chip_name);
3393 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003394 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +08003395 return 0;
3396}
3397
3398/* Patch for VT1702 */
3399
3400/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003401static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003402 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3403 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3404 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3405 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3406 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3407 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3408 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3409 HDA_INPUT),
3410 {
3411 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3412 /* The multiple "Capture Source" controls confuse alsamixer
3413 * So call somewhat different..
3414 */
3415 /* .name = "Capture Source", */
3416 .name = "Input Source",
3417 .count = 1,
3418 .info = via_mux_enum_info,
3419 .get = via_mux_enum_get,
3420 .put = via_mux_enum_put,
3421 },
3422 { } /* end */
3423};
3424
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003425static const struct hda_verb vt1702_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003426 /*
3427 * Unmute ADC0-1 and set the default input to mic-in
3428 */
3429 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3430 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3431 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3432
3433
3434 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3435 * mixer widget
3436 */
3437 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3438 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3439 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3440 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3441 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3442 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3443
3444 /* Setup default input of PW4 to MW0 */
3445 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3446 /* PW6 PW7 Output enable */
3447 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3448 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003449 /* mixer enable */
3450 {0x1, 0xF88, 0x3},
3451 /* GPIO 0~2 */
3452 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08003453 { }
3454};
3455
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003456static const struct hda_verb vt1702_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003457 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3458 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3459 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3460 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3461 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3462 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003463 { }
3464};
3465
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003466static const struct hda_pcm_stream vt1702_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08003467 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08003468 .channels_min = 2,
3469 .channels_max = 2,
3470 .nid = 0x10, /* NID to query formats and rates */
3471 .ops = {
3472 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08003473 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003474 .cleanup = via_playback_multi_pcm_cleanup,
3475 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003476 },
3477};
3478
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003479static const struct hda_pcm_stream vt1702_pcm_analog_capture = {
Harald Welted949cac2008-09-09 15:56:01 +08003480 .substreams = 3,
3481 .channels_min = 2,
3482 .channels_max = 2,
3483 .nid = 0x12, /* NID to query formats and rates */
3484 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003485 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08003486 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003487 .cleanup = via_capture_pcm_cleanup,
3488 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003489 },
3490};
3491
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003492static const struct hda_pcm_stream vt1702_pcm_digital_playback = {
Harald Welte5691ec72008-09-15 22:42:26 +08003493 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08003494 .channels_min = 2,
3495 .channels_max = 2,
3496 /* NID is set in via_build_pcms */
3497 .ops = {
3498 .open = via_dig_playback_pcm_open,
3499 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003500 .prepare = via_dig_playback_pcm_prepare,
3501 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08003502 },
3503};
3504
Harald Welted949cac2008-09-09 15:56:01 +08003505static int vt1702_parse_auto_config(struct hda_codec *codec)
3506{
3507 struct via_spec *spec = codec->spec;
3508 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003509
Takashi Iwai9da29272009-05-07 16:31:14 +02003510 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08003511 if (err < 0)
3512 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003513 err = via_auto_fill_dac_nids(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003514 if (err < 0)
3515 return err;
3516 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3517 return 0; /* can't find valid BIOS pin config */
3518
Takashi Iwai4a796162011-06-17 17:53:38 +02003519 err = via_auto_create_multi_out_ctls(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003520 if (err < 0)
3521 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003522 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Harald Welted949cac2008-09-09 15:56:01 +08003523 if (err < 0)
3524 return err;
Lydia Wangc2c02ea2009-10-10 19:07:32 +08003525 /* limit AA path volume to 0 dB */
3526 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3527 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3528 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3529 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3530 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai620e2b22011-06-17 17:19:19 +02003531 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003532 if (err < 0)
3533 return err;
3534
3535 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3536
Takashi Iwai9da29272009-05-07 16:31:14 +02003537 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08003538
Takashi Iwai603c4012008-07-30 15:01:44 +02003539 if (spec->kctls.list)
3540 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08003541
Harald Welte0aa62ae2008-09-09 15:58:27 +08003542 spec->input_mux = &spec->private_imux[0];
3543
Harald Weltef8fdd492008-09-15 22:41:31 +08003544 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003545 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003546
3547 return 1;
3548}
3549
3550#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003551static const struct hda_amp_list vt1702_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003552 { 0x1A, HDA_INPUT, 1 },
3553 { 0x1A, HDA_INPUT, 2 },
3554 { 0x1A, HDA_INPUT, 3 },
3555 { 0x1A, HDA_INPUT, 4 },
3556 { } /* end */
3557};
3558#endif
3559
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003560static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3561{
3562 int imux_is_smixer =
3563 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3564 unsigned int parm;
3565 /* inputs */
3566 /* PW 1/2/5 (14h/15h/18h) */
3567 parm = AC_PWRST_D3;
3568 set_pin_power_state(codec, 0x14, &parm);
3569 set_pin_power_state(codec, 0x15, &parm);
3570 set_pin_power_state(codec, 0x18, &parm);
3571 if (imux_is_smixer)
3572 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3573 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3574 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3575 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
3576 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3577 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
3578
3579 /* outputs */
3580 /* PW 3/4 (16h/17h) */
3581 parm = AC_PWRST_D3;
3582 set_pin_power_state(codec, 0x17, &parm);
3583 set_pin_power_state(codec, 0x16, &parm);
3584 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3585 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
3586 imux_is_smixer ? AC_PWRST_D0 : parm);
3587 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3588 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3589}
3590
Harald Welted949cac2008-09-09 15:56:01 +08003591static int patch_vt1702(struct hda_codec *codec)
3592{
3593 struct via_spec *spec;
3594 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003595
3596 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003597 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003598 if (spec == NULL)
3599 return -ENOMEM;
3600
Takashi Iwai620e2b22011-06-17 17:19:19 +02003601 spec->aa_mix_nid = 0x1a;
3602
Harald Welted949cac2008-09-09 15:56:01 +08003603 /* automatic parse from the BIOS config */
3604 err = vt1702_parse_auto_config(codec);
3605 if (err < 0) {
3606 via_free(codec);
3607 return err;
3608 } else if (!err) {
3609 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3610 "from BIOS. Using genenic mode...\n");
3611 }
3612
Harald Welte69e52a82008-09-09 15:57:32 +08003613 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
3614 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003615
Harald Welted949cac2008-09-09 15:56:01 +08003616 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
3617 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
3618
Harald Welted949cac2008-09-09 15:56:01 +08003619 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
3620
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003621 if (spec->adc_nids && spec->input_mux) {
Harald Welted949cac2008-09-09 15:56:01 +08003622 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3623 spec->num_mixers++;
3624 }
3625
3626 codec->patch_ops = via_patch_ops;
3627
3628 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003629 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08003630#ifdef CONFIG_SND_HDA_POWER_SAVE
3631 spec->loopback.amplist = vt1702_loopbacks;
3632#endif
3633
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003634 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08003635 return 0;
3636}
3637
Lydia Wangeb7188c2009-10-10 19:08:34 +08003638/* Patch for VT1718S */
3639
3640/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003641static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08003642 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
3643 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
3644 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
3645 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
3646 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
3647 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
3648 HDA_INPUT),
3649 {
3650 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3651 /* The multiple "Capture Source" controls confuse alsamixer
3652 * So call somewhat different..
3653 */
3654 .name = "Input Source",
3655 .count = 2,
3656 .info = via_mux_enum_info,
3657 .get = via_mux_enum_get,
3658 .put = via_mux_enum_put,
3659 },
3660 { } /* end */
3661};
3662
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003663static const struct hda_verb vt1718S_volume_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08003664 /*
3665 * Unmute ADC0-1 and set the default input to mic-in
3666 */
3667 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3668 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3669
Lydia Wang4ab2d532011-03-24 12:42:03 +08003670 /* Enable MW0 adjust Gain 5 */
3671 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08003672 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3673 * mixer widget
3674 */
3675 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3676 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3677 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3678 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3679 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
Lydia Wang4ab2d532011-03-24 12:42:03 +08003680 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
Lydia Wangeb7188c2009-10-10 19:08:34 +08003681
3682 /* Setup default input of Front HP to MW9 */
3683 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
3684 /* PW9 PW10 Output enable */
3685 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
3686 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
3687 /* PW11 Input enable */
3688 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
3689 /* Enable Boost Volume backdoor */
3690 {0x1, 0xf88, 0x8},
3691 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
3692 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3693 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3694 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3695 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3696 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3697 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3698 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3699 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3700 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3701 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3702 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
3703 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
3704 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
3705 /* Unmute MW4's index 0 */
3706 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3707 { }
3708};
3709
3710
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003711static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08003712 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
3713 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3714 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3715 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3716 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3717 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3718 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3719 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3720 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3721 { }
3722};
3723
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003724static const struct hda_pcm_stream vt1718S_pcm_analog_playback = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08003725 .substreams = 2,
3726 .channels_min = 2,
3727 .channels_max = 10,
3728 .nid = 0x8, /* NID to query formats and rates */
3729 .ops = {
3730 .open = via_playback_pcm_open,
3731 .prepare = via_playback_multi_pcm_prepare,
3732 .cleanup = via_playback_multi_pcm_cleanup,
3733 .close = via_pcm_open_close,
3734 },
3735};
3736
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003737static const struct hda_pcm_stream vt1718S_pcm_analog_capture = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08003738 .substreams = 2,
3739 .channels_min = 2,
3740 .channels_max = 2,
3741 .nid = 0x10, /* NID to query formats and rates */
3742 .ops = {
3743 .open = via_pcm_open_close,
3744 .prepare = via_capture_pcm_prepare,
3745 .cleanup = via_capture_pcm_cleanup,
3746 .close = via_pcm_open_close,
3747 },
3748};
3749
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003750static const struct hda_pcm_stream vt1718S_pcm_digital_playback = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08003751 .substreams = 2,
3752 .channels_min = 2,
3753 .channels_max = 2,
Lydia Wangeb7188c2009-10-10 19:08:34 +08003754 /* NID is set in via_build_pcms */
3755 .ops = {
3756 .open = via_dig_playback_pcm_open,
3757 .close = via_dig_playback_pcm_close,
3758 .prepare = via_dig_playback_pcm_prepare,
3759 .cleanup = via_dig_playback_pcm_cleanup
3760 },
3761};
3762
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003763static const struct hda_pcm_stream vt1718S_pcm_digital_capture = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08003764 .substreams = 1,
3765 .channels_min = 2,
3766 .channels_max = 2,
3767};
3768
Lydia Wangeb7188c2009-10-10 19:08:34 +08003769static int vt1718S_parse_auto_config(struct hda_codec *codec)
3770{
3771 struct via_spec *spec = codec->spec;
3772 int err;
3773
3774 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3775
3776 if (err < 0)
3777 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003778 err = via_auto_fill_dac_nids(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003779 if (err < 0)
3780 return err;
3781 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3782 return 0; /* can't find valid BIOS pin config */
3783
Takashi Iwai4a796162011-06-17 17:53:38 +02003784 err = via_auto_create_multi_out_ctls(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003785 if (err < 0)
3786 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003787 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003788 if (err < 0)
3789 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02003790 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003791 if (err < 0)
3792 return err;
3793
3794 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3795
3796 fill_dig_outs(codec);
3797
3798 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
3799 spec->dig_in_nid = 0x13;
3800
3801 if (spec->kctls.list)
3802 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3803
3804 spec->input_mux = &spec->private_imux[0];
3805
3806 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003807 via_hp_build(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003808
Takashi Iwaif4a78282011-06-17 18:46:48 +02003809 err = via_smart51_build(codec);
3810 if (err < 0)
3811 return err;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003812
3813 return 1;
3814}
3815
3816#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003817static const struct hda_amp_list vt1718S_loopbacks[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08003818 { 0x21, HDA_INPUT, 1 },
3819 { 0x21, HDA_INPUT, 2 },
3820 { 0x21, HDA_INPUT, 3 },
3821 { 0x21, HDA_INPUT, 4 },
3822 { } /* end */
3823};
3824#endif
3825
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003826static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3827{
3828 struct via_spec *spec = codec->spec;
3829 int imux_is_smixer;
3830 unsigned int parm;
3831 /* MUX6 (1eh) = stereo mixer */
3832 imux_is_smixer =
3833 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3834 /* inputs */
3835 /* PW 5/6/7 (29h/2ah/2bh) */
3836 parm = AC_PWRST_D3;
3837 set_pin_power_state(codec, 0x29, &parm);
3838 set_pin_power_state(codec, 0x2a, &parm);
3839 set_pin_power_state(codec, 0x2b, &parm);
3840 if (imux_is_smixer)
3841 parm = AC_PWRST_D0;
3842 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3843 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3844 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3845 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3846 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3847
3848 /* outputs */
3849 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3850 parm = AC_PWRST_D3;
3851 set_pin_power_state(codec, 0x27, &parm);
3852 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
3853 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
3854
3855 /* PW2 (26h), AOW2 (ah) */
3856 parm = AC_PWRST_D3;
3857 set_pin_power_state(codec, 0x26, &parm);
3858 if (spec->smart51_enabled)
3859 set_pin_power_state(codec, 0x2b, &parm);
3860 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
3861
3862 /* PW0 (24h), AOW0 (8h) */
3863 parm = AC_PWRST_D3;
3864 set_pin_power_state(codec, 0x24, &parm);
3865 if (!spec->hp_independent_mode) /* check for redirected HP */
3866 set_pin_power_state(codec, 0x28, &parm);
3867 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3868 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3869 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
3870 imux_is_smixer ? AC_PWRST_D0 : parm);
3871
3872 /* PW1 (25h), AOW1 (9h) */
3873 parm = AC_PWRST_D3;
3874 set_pin_power_state(codec, 0x25, &parm);
3875 if (spec->smart51_enabled)
3876 set_pin_power_state(codec, 0x2a, &parm);
3877 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
3878
3879 if (spec->hp_independent_mode) {
3880 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3881 parm = AC_PWRST_D3;
3882 set_pin_power_state(codec, 0x28, &parm);
3883 snd_hda_codec_write(codec, 0x1b, 0,
3884 AC_VERB_SET_POWER_STATE, parm);
3885 snd_hda_codec_write(codec, 0x34, 0,
3886 AC_VERB_SET_POWER_STATE, parm);
3887 snd_hda_codec_write(codec, 0xc, 0,
3888 AC_VERB_SET_POWER_STATE, parm);
3889 }
3890}
3891
Lydia Wangeb7188c2009-10-10 19:08:34 +08003892static int patch_vt1718S(struct hda_codec *codec)
3893{
3894 struct via_spec *spec;
3895 int err;
3896
3897 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003898 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003899 if (spec == NULL)
3900 return -ENOMEM;
3901
Takashi Iwai620e2b22011-06-17 17:19:19 +02003902 spec->aa_mix_nid = 0x21;
3903
Lydia Wangeb7188c2009-10-10 19:08:34 +08003904 /* automatic parse from the BIOS config */
3905 err = vt1718S_parse_auto_config(codec);
3906 if (err < 0) {
3907 via_free(codec);
3908 return err;
3909 } else if (!err) {
3910 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3911 "from BIOS. Using genenic mode...\n");
3912 }
3913
3914 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
3915 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
3916
Lydia Wangeb7188c2009-10-10 19:08:34 +08003917 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
3918 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
3919
Lydia Wangeb7188c2009-10-10 19:08:34 +08003920 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08003921 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
Lydia Wangeb7188c2009-10-10 19:08:34 +08003922 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
3923
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003924 if (spec->adc_nids && spec->input_mux) {
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08003925 override_mic_boost(codec, 0x2b, 0, 3, 40);
3926 override_mic_boost(codec, 0x29, 0, 3, 40);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003927 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
3928 spec->num_mixers++;
3929 }
3930
3931 codec->patch_ops = via_patch_ops;
3932
3933 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11003934 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003935
3936#ifdef CONFIG_SND_HDA_POWER_SAVE
3937 spec->loopback.amplist = vt1718S_loopbacks;
3938#endif
3939
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003940 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3941
Lydia Wangeb7188c2009-10-10 19:08:34 +08003942 return 0;
3943}
Lydia Wangf3db4232009-10-10 19:08:41 +08003944
3945/* Patch for VT1716S */
3946
3947static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3948 struct snd_ctl_elem_info *uinfo)
3949{
3950 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3951 uinfo->count = 1;
3952 uinfo->value.integer.min = 0;
3953 uinfo->value.integer.max = 1;
3954 return 0;
3955}
3956
3957static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3958 struct snd_ctl_elem_value *ucontrol)
3959{
3960 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3961 int index = 0;
3962
3963 index = snd_hda_codec_read(codec, 0x26, 0,
3964 AC_VERB_GET_CONNECT_SEL, 0);
3965 if (index != -1)
3966 *ucontrol->value.integer.value = index;
3967
3968 return 0;
3969}
3970
3971static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3972 struct snd_ctl_elem_value *ucontrol)
3973{
3974 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3975 struct via_spec *spec = codec->spec;
3976 int index = *ucontrol->value.integer.value;
3977
3978 snd_hda_codec_write(codec, 0x26, 0,
3979 AC_VERB_SET_CONNECT_SEL, index);
3980 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003981 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003982 return 1;
3983}
3984
3985/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003986static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003987 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3988 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3989 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3990 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3991 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3992 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3993 HDA_INPUT),
3994 {
3995 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3996 .name = "Input Source",
3997 .count = 1,
3998 .info = via_mux_enum_info,
3999 .get = via_mux_enum_get,
4000 .put = via_mux_enum_put,
4001 },
4002 { } /* end */
4003};
4004
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004005static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004006 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4007 {
4008 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4009 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004010 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08004011 .count = 1,
4012 .info = vt1716s_dmic_info,
4013 .get = vt1716s_dmic_get,
4014 .put = vt1716s_dmic_put,
4015 },
4016 {} /* end */
4017};
4018
4019
4020/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004021static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004022 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4023 { } /* end */
4024};
4025
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004026static const struct hda_verb vt1716S_volume_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004027 /*
4028 * Unmute ADC0-1 and set the default input to mic-in
4029 */
4030 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4031 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4032
4033
4034 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4035 * mixer widget
4036 */
4037 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4038 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4039 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4040 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4041 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4042 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4043
4044 /* MUX Indices: Stereo Mixer = 5 */
4045 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4046
4047 /* Setup default input of PW4 to MW0 */
4048 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4049
4050 /* Setup default input of SW1 as MW0 */
4051 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4052
4053 /* Setup default input of SW4 as AOW0 */
4054 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4055
4056 /* PW9 PW10 Output enable */
4057 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4058 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4059
4060 /* Unmute SW1, PW12 */
4061 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4062 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4063 /* PW12 Output enable */
4064 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4065 /* Enable Boost Volume backdoor */
4066 {0x1, 0xf8a, 0x80},
4067 /* don't bybass mixer */
4068 {0x1, 0xf88, 0xc0},
4069 /* Enable mono output */
4070 {0x1, 0xf90, 0x08},
4071 { }
4072};
4073
4074
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004075static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004076 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4077 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4078 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4079 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4080 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4081 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4082 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4083 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4084 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4085 { }
4086};
4087
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004088static const struct hda_pcm_stream vt1716S_pcm_analog_playback = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004089 .substreams = 2,
4090 .channels_min = 2,
4091 .channels_max = 6,
4092 .nid = 0x10, /* NID to query formats and rates */
4093 .ops = {
4094 .open = via_playback_pcm_open,
4095 .prepare = via_playback_multi_pcm_prepare,
4096 .cleanup = via_playback_multi_pcm_cleanup,
4097 .close = via_pcm_open_close,
4098 },
4099};
4100
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004101static const struct hda_pcm_stream vt1716S_pcm_analog_capture = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004102 .substreams = 2,
4103 .channels_min = 2,
4104 .channels_max = 2,
4105 .nid = 0x13, /* NID to query formats and rates */
4106 .ops = {
4107 .open = via_pcm_open_close,
4108 .prepare = via_capture_pcm_prepare,
4109 .cleanup = via_capture_pcm_cleanup,
4110 .close = via_pcm_open_close,
4111 },
4112};
4113
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004114static const struct hda_pcm_stream vt1716S_pcm_digital_playback = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004115 .substreams = 2,
4116 .channels_min = 2,
4117 .channels_max = 2,
Lydia Wangf3db4232009-10-10 19:08:41 +08004118 /* NID is set in via_build_pcms */
4119 .ops = {
4120 .open = via_dig_playback_pcm_open,
4121 .close = via_dig_playback_pcm_close,
4122 .prepare = via_dig_playback_pcm_prepare,
4123 .cleanup = via_dig_playback_pcm_cleanup
4124 },
4125};
4126
Lydia Wangf3db4232009-10-10 19:08:41 +08004127static int vt1716S_parse_auto_config(struct hda_codec *codec)
4128{
4129 struct via_spec *spec = codec->spec;
4130 int err;
4131
4132 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4133 if (err < 0)
4134 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02004135 err = via_auto_fill_dac_nids(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08004136 if (err < 0)
4137 return err;
4138 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4139 return 0; /* can't find valid BIOS pin config */
4140
Takashi Iwai4a796162011-06-17 17:53:38 +02004141 err = via_auto_create_multi_out_ctls(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08004142 if (err < 0)
4143 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02004144 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08004145 if (err < 0)
4146 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02004147 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangf3db4232009-10-10 19:08:41 +08004148 if (err < 0)
4149 return err;
4150
4151 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4152
4153 fill_dig_outs(codec);
4154
4155 if (spec->kctls.list)
4156 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4157
4158 spec->input_mux = &spec->private_imux[0];
4159
4160 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004161 via_hp_build(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08004162
Takashi Iwaif4a78282011-06-17 18:46:48 +02004163 err = via_smart51_build(codec);
4164 if (err < 0)
4165 return err;
Lydia Wangf3db4232009-10-10 19:08:41 +08004166
4167 return 1;
4168}
4169
4170#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004171static const struct hda_amp_list vt1716S_loopbacks[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004172 { 0x16, HDA_INPUT, 1 },
4173 { 0x16, HDA_INPUT, 2 },
4174 { 0x16, HDA_INPUT, 3 },
4175 { 0x16, HDA_INPUT, 4 },
4176 { } /* end */
4177};
4178#endif
4179
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004180static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
4181{
4182 struct via_spec *spec = codec->spec;
4183 int imux_is_smixer;
4184 unsigned int parm;
4185 unsigned int mono_out, present;
4186 /* SW0 (17h) = stereo mixer */
4187 imux_is_smixer =
4188 (snd_hda_codec_read(codec, 0x17, 0,
4189 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
4190 /* inputs */
4191 /* PW 1/2/5 (1ah/1bh/1eh) */
4192 parm = AC_PWRST_D3;
4193 set_pin_power_state(codec, 0x1a, &parm);
4194 set_pin_power_state(codec, 0x1b, &parm);
4195 set_pin_power_state(codec, 0x1e, &parm);
4196 if (imux_is_smixer)
4197 parm = AC_PWRST_D0;
4198 /* SW0 (17h), AIW0(13h) */
4199 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
4200 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4201
4202 parm = AC_PWRST_D3;
4203 set_pin_power_state(codec, 0x1e, &parm);
4204 /* PW11 (22h) */
4205 if (spec->dmic_enabled)
4206 set_pin_power_state(codec, 0x22, &parm);
4207 else
4208 snd_hda_codec_write(codec, 0x22, 0,
4209 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4210
4211 /* SW2(26h), AIW1(14h) */
4212 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
4213 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
4214
4215 /* outputs */
4216 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
4217 parm = AC_PWRST_D3;
4218 set_pin_power_state(codec, 0x19, &parm);
4219 /* Smart 5.1 PW2(1bh) */
4220 if (spec->smart51_enabled)
4221 set_pin_power_state(codec, 0x1b, &parm);
4222 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
4223 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4224
4225 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
4226 parm = AC_PWRST_D3;
4227 set_pin_power_state(codec, 0x23, &parm);
4228 /* Smart 5.1 PW1(1ah) */
4229 if (spec->smart51_enabled)
4230 set_pin_power_state(codec, 0x1a, &parm);
4231 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
4232
4233 /* Smart 5.1 PW5(1eh) */
4234 if (spec->smart51_enabled)
4235 set_pin_power_state(codec, 0x1e, &parm);
4236 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
4237
4238 /* Mono out */
4239 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
4240 present = snd_hda_jack_detect(codec, 0x1c);
4241
4242 if (present)
4243 mono_out = 0;
4244 else {
4245 present = snd_hda_jack_detect(codec, 0x1d);
4246 if (!spec->hp_independent_mode && present)
4247 mono_out = 0;
4248 else
4249 mono_out = 1;
4250 }
4251 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
4252 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
4253 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
4254 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
4255
4256 /* PW 3/4 (1ch/1dh) */
4257 parm = AC_PWRST_D3;
4258 set_pin_power_state(codec, 0x1c, &parm);
4259 set_pin_power_state(codec, 0x1d, &parm);
4260 /* HP Independent Mode, power on AOW3 */
4261 if (spec->hp_independent_mode)
4262 snd_hda_codec_write(codec, 0x25, 0,
4263 AC_VERB_SET_POWER_STATE, parm);
4264
4265 /* force to D0 for internal Speaker */
4266 /* MW0 (16h), AOW0 (10h) */
4267 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
4268 imux_is_smixer ? AC_PWRST_D0 : parm);
4269 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
4270 mono_out ? AC_PWRST_D0 : parm);
4271}
4272
Lydia Wangf3db4232009-10-10 19:08:41 +08004273static int patch_vt1716S(struct hda_codec *codec)
4274{
4275 struct via_spec *spec;
4276 int err;
4277
4278 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004279 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08004280 if (spec == NULL)
4281 return -ENOMEM;
4282
Takashi Iwai620e2b22011-06-17 17:19:19 +02004283 spec->aa_mix_nid = 0x16;
4284
Lydia Wangf3db4232009-10-10 19:08:41 +08004285 /* automatic parse from the BIOS config */
4286 err = vt1716S_parse_auto_config(codec);
4287 if (err < 0) {
4288 via_free(codec);
4289 return err;
4290 } else if (!err) {
4291 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4292 "from BIOS. Using genenic mode...\n");
4293 }
4294
4295 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
4296 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
4297
Lydia Wangf3db4232009-10-10 19:08:41 +08004298 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
4299 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
4300
Lydia Wangf3db4232009-10-10 19:08:41 +08004301 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
4302
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004303 if (spec->adc_nids && spec->input_mux) {
Lydia Wangf3db4232009-10-10 19:08:41 +08004304 override_mic_boost(codec, 0x1a, 0, 3, 40);
4305 override_mic_boost(codec, 0x1e, 0, 3, 40);
4306 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
4307 spec->num_mixers++;
4308 }
4309
4310 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
4311 spec->num_mixers++;
4312
4313 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
4314
4315 codec->patch_ops = via_patch_ops;
4316
4317 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11004318 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangf3db4232009-10-10 19:08:41 +08004319
4320#ifdef CONFIG_SND_HDA_POWER_SAVE
4321 spec->loopback.amplist = vt1716S_loopbacks;
4322#endif
4323
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004324 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08004325 return 0;
4326}
Lydia Wang25eaba22009-10-10 19:08:43 +08004327
4328/* for vt2002P */
4329
4330/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004331static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08004332 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4333 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4334 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4335 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4336 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4337 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4338 HDA_INPUT),
4339 {
4340 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4341 /* The multiple "Capture Source" controls confuse alsamixer
4342 * So call somewhat different..
4343 */
4344 /* .name = "Capture Source", */
4345 .name = "Input Source",
4346 .count = 2,
4347 .info = via_mux_enum_info,
4348 .get = via_mux_enum_get,
4349 .put = via_mux_enum_put,
4350 },
4351 { } /* end */
4352};
4353
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004354static const struct hda_verb vt2002P_volume_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08004355 /* Class-D speaker related verbs */
4356 {0x1, 0xfe0, 0x4},
4357 {0x1, 0xfe9, 0x80},
4358 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08004359 /*
4360 * Unmute ADC0-1 and set the default input to mic-in
4361 */
4362 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4363 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4364
4365
4366 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4367 * mixer widget
4368 */
4369 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4370 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4371 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4372 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4373 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4374 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4375
4376 /* MUX Indices: Mic = 0 */
4377 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
4378 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
4379
4380 /* PW9 Output enable */
4381 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4382
4383 /* Enable Boost Volume backdoor */
4384 {0x1, 0xfb9, 0x24},
4385
4386 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
4387 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4388 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4389 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4390 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4391 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4392 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4393 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4394 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4395
4396 /* set MUX0/1/4/8 = 0 (AOW0) */
4397 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
4398 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
4399 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
4400 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
4401
4402 /* set PW0 index=0 (MW0) */
4403 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
4404
4405 /* Enable AOW0 to MW9 */
4406 {0x1, 0xfb8, 0x88},
4407 { }
4408};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004409static const struct hda_verb vt1802_volume_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08004410 /*
4411 * Unmute ADC0-1 and set the default input to mic-in
4412 */
4413 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4414 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4415
4416
4417 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4418 * mixer widget
4419 */
4420 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4421 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4422 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4423 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4424 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4425 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4426
4427 /* MUX Indices: Mic = 0 */
4428 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
4429 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
4430
4431 /* PW9 Output enable */
4432 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4433
4434 /* Enable Boost Volume backdoor */
4435 {0x1, 0xfb9, 0x24},
4436
4437 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
4438 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4439 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4440 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4441 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4442 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4443 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4444 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4445 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4446
4447 /* set MUX0/1/4/8 = 0 (AOW0) */
4448 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
4449 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
4450 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
4451 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
4452
4453 /* set PW0 index=0 (MW0) */
4454 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
4455
4456 /* Enable AOW0 to MW9 */
4457 {0x1, 0xfb8, 0x88},
4458 { }
4459};
Lydia Wang25eaba22009-10-10 19:08:43 +08004460
4461
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004462static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08004463 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
4464 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4465 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
4466 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4467 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4468 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4469 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4470 { }
4471};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004472static const struct hda_verb vt1802_uniwill_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08004473 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
4474 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4475 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4476 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4477 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4478 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4479 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4480 { }
4481};
Lydia Wang25eaba22009-10-10 19:08:43 +08004482
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004483static const struct hda_pcm_stream vt2002P_pcm_analog_playback = {
Lydia Wang25eaba22009-10-10 19:08:43 +08004484 .substreams = 2,
4485 .channels_min = 2,
4486 .channels_max = 2,
4487 .nid = 0x8, /* NID to query formats and rates */
4488 .ops = {
4489 .open = via_playback_pcm_open,
4490 .prepare = via_playback_multi_pcm_prepare,
4491 .cleanup = via_playback_multi_pcm_cleanup,
4492 .close = via_pcm_open_close,
4493 },
4494};
4495
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004496static const struct hda_pcm_stream vt2002P_pcm_analog_capture = {
Lydia Wang25eaba22009-10-10 19:08:43 +08004497 .substreams = 2,
4498 .channels_min = 2,
4499 .channels_max = 2,
4500 .nid = 0x10, /* NID to query formats and rates */
4501 .ops = {
4502 .open = via_pcm_open_close,
4503 .prepare = via_capture_pcm_prepare,
4504 .cleanup = via_capture_pcm_cleanup,
4505 .close = via_pcm_open_close,
4506 },
4507};
4508
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004509static const struct hda_pcm_stream vt2002P_pcm_digital_playback = {
Lydia Wang25eaba22009-10-10 19:08:43 +08004510 .substreams = 1,
4511 .channels_min = 2,
4512 .channels_max = 2,
Lydia Wang25eaba22009-10-10 19:08:43 +08004513 /* NID is set in via_build_pcms */
4514 .ops = {
4515 .open = via_dig_playback_pcm_open,
4516 .close = via_dig_playback_pcm_close,
4517 .prepare = via_dig_playback_pcm_prepare,
4518 .cleanup = via_dig_playback_pcm_cleanup
4519 },
4520};
4521
Lydia Wang25eaba22009-10-10 19:08:43 +08004522static int vt2002P_parse_auto_config(struct hda_codec *codec)
4523{
4524 struct via_spec *spec = codec->spec;
4525 int err;
4526
4527
4528 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4529 if (err < 0)
4530 return err;
4531
Takashi Iwai4a796162011-06-17 17:53:38 +02004532 err = via_auto_fill_dac_nids(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08004533 if (err < 0)
4534 return err;
4535
4536 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4537 return 0; /* can't find valid BIOS pin config */
4538
Takashi Iwai4a796162011-06-17 17:53:38 +02004539 err = via_auto_create_multi_out_ctls(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08004540 if (err < 0)
4541 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02004542 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08004543 if (err < 0)
4544 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02004545 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wang25eaba22009-10-10 19:08:43 +08004546 if (err < 0)
4547 return err;
4548
4549 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4550
4551 fill_dig_outs(codec);
4552
4553 if (spec->kctls.list)
4554 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4555
4556 spec->input_mux = &spec->private_imux[0];
4557
4558 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004559 via_hp_build(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08004560
4561 return 1;
4562}
4563
4564#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004565static const struct hda_amp_list vt2002P_loopbacks[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08004566 { 0x21, HDA_INPUT, 0 },
4567 { 0x21, HDA_INPUT, 1 },
4568 { 0x21, HDA_INPUT, 2 },
4569 { } /* end */
4570};
4571#endif
4572
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004573static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
4574{
4575 struct via_spec *spec = codec->spec;
4576 int imux_is_smixer;
4577 unsigned int parm;
4578 unsigned int present;
4579 /* MUX9 (1eh) = stereo mixer */
4580 imux_is_smixer =
4581 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4582 /* inputs */
4583 /* PW 5/6/7 (29h/2ah/2bh) */
4584 parm = AC_PWRST_D3;
4585 set_pin_power_state(codec, 0x29, &parm);
4586 set_pin_power_state(codec, 0x2a, &parm);
4587 set_pin_power_state(codec, 0x2b, &parm);
4588 parm = AC_PWRST_D0;
4589 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
4590 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4591 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4592 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4593 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4594
4595 /* outputs */
4596 /* AOW0 (8h)*/
4597 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4598
Lydia Wang118909562011-03-23 17:57:34 +08004599 if (spec->codec_type == VT1802) {
4600 /* PW4 (28h), MW4 (18h), MUX4(38h) */
4601 parm = AC_PWRST_D3;
4602 set_pin_power_state(codec, 0x28, &parm);
4603 snd_hda_codec_write(codec, 0x18, 0,
4604 AC_VERB_SET_POWER_STATE, parm);
4605 snd_hda_codec_write(codec, 0x38, 0,
4606 AC_VERB_SET_POWER_STATE, parm);
4607 } else {
4608 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
4609 parm = AC_PWRST_D3;
4610 set_pin_power_state(codec, 0x26, &parm);
4611 snd_hda_codec_write(codec, 0x1c, 0,
4612 AC_VERB_SET_POWER_STATE, parm);
4613 snd_hda_codec_write(codec, 0x37, 0,
4614 AC_VERB_SET_POWER_STATE, parm);
4615 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004616
Lydia Wang118909562011-03-23 17:57:34 +08004617 if (spec->codec_type == VT1802) {
4618 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
4619 parm = AC_PWRST_D3;
4620 set_pin_power_state(codec, 0x25, &parm);
4621 snd_hda_codec_write(codec, 0x15, 0,
4622 AC_VERB_SET_POWER_STATE, parm);
4623 snd_hda_codec_write(codec, 0x35, 0,
4624 AC_VERB_SET_POWER_STATE, parm);
4625 } else {
4626 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
4627 parm = AC_PWRST_D3;
4628 set_pin_power_state(codec, 0x25, &parm);
4629 snd_hda_codec_write(codec, 0x19, 0,
4630 AC_VERB_SET_POWER_STATE, parm);
4631 snd_hda_codec_write(codec, 0x35, 0,
4632 AC_VERB_SET_POWER_STATE, parm);
4633 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004634
4635 if (spec->hp_independent_mode)
4636 snd_hda_codec_write(codec, 0x9, 0,
4637 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4638
4639 /* Class-D */
4640 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
4641 present = snd_hda_jack_detect(codec, 0x25);
4642
4643 parm = AC_PWRST_D3;
4644 set_pin_power_state(codec, 0x24, &parm);
4645 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08004646 if (spec->codec_type == VT1802)
4647 snd_hda_codec_write(codec, 0x14, 0,
4648 AC_VERB_SET_POWER_STATE, parm);
4649 else
4650 snd_hda_codec_write(codec, 0x18, 0,
4651 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004652 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
4653
4654 /* Mono Out */
4655 present = snd_hda_jack_detect(codec, 0x26);
4656
4657 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08004658 if (spec->codec_type == VT1802) {
4659 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
4660 snd_hda_codec_write(codec, 0x33, 0,
4661 AC_VERB_SET_POWER_STATE, parm);
4662 snd_hda_codec_write(codec, 0x1c, 0,
4663 AC_VERB_SET_POWER_STATE, parm);
4664 snd_hda_codec_write(codec, 0x3c, 0,
4665 AC_VERB_SET_POWER_STATE, parm);
4666 } else {
4667 /* PW15 (31h), MW8(17h), MUX8(3bh) */
4668 snd_hda_codec_write(codec, 0x31, 0,
4669 AC_VERB_SET_POWER_STATE, parm);
4670 snd_hda_codec_write(codec, 0x17, 0,
4671 AC_VERB_SET_POWER_STATE, parm);
4672 snd_hda_codec_write(codec, 0x3b, 0,
4673 AC_VERB_SET_POWER_STATE, parm);
4674 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004675 /* MW9 (21h) */
4676 if (imux_is_smixer || !is_aa_path_mute(codec))
4677 snd_hda_codec_write(codec, 0x21, 0,
4678 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4679 else
4680 snd_hda_codec_write(codec, 0x21, 0,
4681 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4682}
Lydia Wang25eaba22009-10-10 19:08:43 +08004683
4684/* patch for vt2002P */
4685static int patch_vt2002P(struct hda_codec *codec)
4686{
4687 struct via_spec *spec;
4688 int err;
4689
4690 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004691 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08004692 if (spec == NULL)
4693 return -ENOMEM;
4694
Takashi Iwai620e2b22011-06-17 17:19:19 +02004695 spec->aa_mix_nid = 0x21;
4696
Lydia Wang25eaba22009-10-10 19:08:43 +08004697 /* automatic parse from the BIOS config */
4698 err = vt2002P_parse_auto_config(codec);
4699 if (err < 0) {
4700 via_free(codec);
4701 return err;
4702 } else if (!err) {
4703 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4704 "from BIOS. Using genenic mode...\n");
4705 }
4706
Lydia Wang118909562011-03-23 17:57:34 +08004707 if (spec->codec_type == VT1802)
4708 spec->init_verbs[spec->num_iverbs++] =
4709 vt1802_volume_init_verbs;
4710 else
4711 spec->init_verbs[spec->num_iverbs++] =
4712 vt2002P_volume_init_verbs;
Lydia Wang25eaba22009-10-10 19:08:43 +08004713
Lydia Wang118909562011-03-23 17:57:34 +08004714 if (spec->codec_type == VT1802)
4715 spec->init_verbs[spec->num_iverbs++] =
4716 vt1802_uniwill_init_verbs;
4717 else
4718 spec->init_verbs[spec->num_iverbs++] =
4719 vt2002P_uniwill_init_verbs;
4720
Lydia Wang25eaba22009-10-10 19:08:43 +08004721 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
4722 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
4723
Lydia Wang25eaba22009-10-10 19:08:43 +08004724 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
4725
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004726 if (spec->adc_nids && spec->input_mux) {
Lydia Wang25eaba22009-10-10 19:08:43 +08004727 override_mic_boost(codec, 0x2b, 0, 3, 40);
4728 override_mic_boost(codec, 0x29, 0, 3, 40);
4729 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
4730 spec->num_mixers++;
4731 }
4732
4733 codec->patch_ops = via_patch_ops;
4734
4735 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11004736 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wang25eaba22009-10-10 19:08:43 +08004737
4738#ifdef CONFIG_SND_HDA_POWER_SAVE
4739 spec->loopback.amplist = vt2002P_loopbacks;
4740#endif
4741
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004742 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08004743 return 0;
4744}
Lydia Wangab6734e2009-10-10 19:08:46 +08004745
4746/* for vt1812 */
4747
4748/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004749static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08004750 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4751 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4752 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4753 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4754 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4755 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
4756 HDA_INPUT),
4757 {
4758 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4759 /* The multiple "Capture Source" controls confuse alsamixer
4760 * So call somewhat different..
4761 */
4762 .name = "Input Source",
4763 .count = 2,
4764 .info = via_mux_enum_info,
4765 .get = via_mux_enum_get,
4766 .put = via_mux_enum_put,
4767 },
4768 { } /* end */
4769};
4770
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004771static const struct hda_verb vt1812_volume_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08004772 /*
4773 * Unmute ADC0-1 and set the default input to mic-in
4774 */
4775 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4776 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4777
4778
4779 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4780 * mixer widget
4781 */
4782 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4783 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4784 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4785 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4786 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4787 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4788
4789 /* MUX Indices: Mic = 0 */
4790 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
4791 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
4792
4793 /* PW9 Output enable */
4794 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4795
4796 /* Enable Boost Volume backdoor */
4797 {0x1, 0xfb9, 0x24},
4798
4799 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
4800 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4801 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4802 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4803 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4804 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4805 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4806 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4807 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4808 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4809 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4810
4811 /* set MUX0/1/4/13/15 = 0 (AOW0) */
4812 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
4813 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
4814 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
4815 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
4816 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
4817
4818 /* Enable AOW0 to MW9 */
4819 {0x1, 0xfb8, 0xa8},
4820 { }
4821};
4822
4823
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004824static const struct hda_verb vt1812_uniwill_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08004825 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
4826 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4827 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
4828 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4829 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4830 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4831 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4832 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4833 { }
4834};
4835
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004836static const struct hda_pcm_stream vt1812_pcm_analog_playback = {
Lydia Wangab6734e2009-10-10 19:08:46 +08004837 .substreams = 2,
4838 .channels_min = 2,
4839 .channels_max = 2,
4840 .nid = 0x8, /* NID to query formats and rates */
4841 .ops = {
4842 .open = via_playback_pcm_open,
4843 .prepare = via_playback_multi_pcm_prepare,
4844 .cleanup = via_playback_multi_pcm_cleanup,
4845 .close = via_pcm_open_close,
4846 },
4847};
4848
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004849static const struct hda_pcm_stream vt1812_pcm_analog_capture = {
Lydia Wangab6734e2009-10-10 19:08:46 +08004850 .substreams = 2,
4851 .channels_min = 2,
4852 .channels_max = 2,
4853 .nid = 0x10, /* NID to query formats and rates */
4854 .ops = {
4855 .open = via_pcm_open_close,
4856 .prepare = via_capture_pcm_prepare,
4857 .cleanup = via_capture_pcm_cleanup,
4858 .close = via_pcm_open_close,
4859 },
4860};
4861
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004862static const struct hda_pcm_stream vt1812_pcm_digital_playback = {
Lydia Wangab6734e2009-10-10 19:08:46 +08004863 .substreams = 1,
4864 .channels_min = 2,
4865 .channels_max = 2,
Lydia Wangab6734e2009-10-10 19:08:46 +08004866 /* NID is set in via_build_pcms */
4867 .ops = {
4868 .open = via_dig_playback_pcm_open,
4869 .close = via_dig_playback_pcm_close,
4870 .prepare = via_dig_playback_pcm_prepare,
4871 .cleanup = via_dig_playback_pcm_cleanup
4872 },
4873};
Lydia Wangab6734e2009-10-10 19:08:46 +08004874
Lydia Wangab6734e2009-10-10 19:08:46 +08004875static int vt1812_parse_auto_config(struct hda_codec *codec)
4876{
4877 struct via_spec *spec = codec->spec;
4878 int err;
4879
4880
4881 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4882 if (err < 0)
4883 return err;
4884 fill_dig_outs(codec);
Takashi Iwai4a796162011-06-17 17:53:38 +02004885 err = via_auto_fill_dac_nids(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08004886 if (err < 0)
4887 return err;
4888
4889 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
4890 return 0; /* can't find valid BIOS pin config */
4891
Takashi Iwai4a796162011-06-17 17:53:38 +02004892 err = via_auto_create_multi_out_ctls(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08004893 if (err < 0)
4894 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02004895 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Lydia Wangab6734e2009-10-10 19:08:46 +08004896 if (err < 0)
4897 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02004898 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangab6734e2009-10-10 19:08:46 +08004899 if (err < 0)
4900 return err;
4901
4902 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4903
4904 fill_dig_outs(codec);
4905
4906 if (spec->kctls.list)
4907 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4908
4909 spec->input_mux = &spec->private_imux[0];
4910
4911 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004912 via_hp_build(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08004913
4914 return 1;
4915}
4916
4917#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004918static const struct hda_amp_list vt1812_loopbacks[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08004919 { 0x21, HDA_INPUT, 0 },
4920 { 0x21, HDA_INPUT, 1 },
4921 { 0x21, HDA_INPUT, 2 },
4922 { } /* end */
4923};
4924#endif
4925
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004926static void set_widgets_power_state_vt1812(struct hda_codec *codec)
4927{
4928 struct via_spec *spec = codec->spec;
4929 int imux_is_smixer =
4930 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4931 unsigned int parm;
4932 unsigned int present;
4933 /* MUX10 (1eh) = stereo mixer */
4934 imux_is_smixer =
4935 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4936 /* inputs */
4937 /* PW 5/6/7 (29h/2ah/2bh) */
4938 parm = AC_PWRST_D3;
4939 set_pin_power_state(codec, 0x29, &parm);
4940 set_pin_power_state(codec, 0x2a, &parm);
4941 set_pin_power_state(codec, 0x2b, &parm);
4942 parm = AC_PWRST_D0;
4943 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
4944 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4945 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4946 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4947 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4948
4949 /* outputs */
4950 /* AOW0 (8h)*/
4951 snd_hda_codec_write(codec, 0x8, 0,
4952 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4953
4954 /* PW4 (28h), MW4 (18h), MUX4(38h) */
4955 parm = AC_PWRST_D3;
4956 set_pin_power_state(codec, 0x28, &parm);
4957 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
4958 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
4959
4960 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
4961 parm = AC_PWRST_D3;
4962 set_pin_power_state(codec, 0x25, &parm);
4963 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
4964 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
4965 if (spec->hp_independent_mode)
4966 snd_hda_codec_write(codec, 0x9, 0,
4967 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4968
4969 /* Internal Speaker */
4970 /* PW0 (24h), MW0(14h), MUX0(34h) */
4971 present = snd_hda_jack_detect(codec, 0x25);
4972
4973 parm = AC_PWRST_D3;
4974 set_pin_power_state(codec, 0x24, &parm);
4975 if (present) {
4976 snd_hda_codec_write(codec, 0x14, 0,
4977 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4978 snd_hda_codec_write(codec, 0x34, 0,
4979 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4980 } else {
4981 snd_hda_codec_write(codec, 0x14, 0,
4982 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4983 snd_hda_codec_write(codec, 0x34, 0,
4984 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4985 }
4986
4987
4988 /* Mono Out */
4989 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
4990 present = snd_hda_jack_detect(codec, 0x28);
4991
4992 parm = AC_PWRST_D3;
4993 set_pin_power_state(codec, 0x31, &parm);
4994 if (present) {
4995 snd_hda_codec_write(codec, 0x1c, 0,
4996 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4997 snd_hda_codec_write(codec, 0x3c, 0,
4998 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4999 snd_hda_codec_write(codec, 0x3e, 0,
5000 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5001 } else {
5002 snd_hda_codec_write(codec, 0x1c, 0,
5003 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5004 snd_hda_codec_write(codec, 0x3c, 0,
5005 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5006 snd_hda_codec_write(codec, 0x3e, 0,
5007 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5008 }
5009
5010 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
5011 parm = AC_PWRST_D3;
5012 set_pin_power_state(codec, 0x33, &parm);
5013 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
5014 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
5015
5016}
Lydia Wangab6734e2009-10-10 19:08:46 +08005017
5018/* patch for vt1812 */
5019static int patch_vt1812(struct hda_codec *codec)
5020{
5021 struct via_spec *spec;
5022 int err;
5023
5024 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005025 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08005026 if (spec == NULL)
5027 return -ENOMEM;
5028
Takashi Iwai620e2b22011-06-17 17:19:19 +02005029 spec->aa_mix_nid = 0x21;
5030
Lydia Wangab6734e2009-10-10 19:08:46 +08005031 /* automatic parse from the BIOS config */
5032 err = vt1812_parse_auto_config(codec);
5033 if (err < 0) {
5034 via_free(codec);
5035 return err;
5036 } else if (!err) {
5037 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5038 "from BIOS. Using genenic mode...\n");
5039 }
5040
5041
5042 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
5043 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
5044
Lydia Wangab6734e2009-10-10 19:08:46 +08005045 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
5046 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
5047
Lydia Wangab6734e2009-10-10 19:08:46 +08005048 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
5049
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005050 if (spec->adc_nids && spec->input_mux) {
Lydia Wangab6734e2009-10-10 19:08:46 +08005051 override_mic_boost(codec, 0x2b, 0, 3, 40);
5052 override_mic_boost(codec, 0x29, 0, 3, 40);
5053 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
5054 spec->num_mixers++;
5055 }
5056
5057 codec->patch_ops = via_patch_ops;
5058
5059 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005060 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangab6734e2009-10-10 19:08:46 +08005061
5062#ifdef CONFIG_SND_HDA_POWER_SAVE
5063 spec->loopback.amplist = vt1812_loopbacks;
5064#endif
5065
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005066 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08005067 return 0;
5068}
5069
Joseph Chanc577b8a2006-11-29 15:29:40 +01005070/*
5071 * patch entries
5072 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005073static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01005074 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
5075 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
5076 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
5077 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
5078 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005079 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005080 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005081 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005082 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005083 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005084 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005085 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005086 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005087 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005088 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005089 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005090 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005091 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005092 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005093 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005094 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005095 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005096 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005097 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005098 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005099 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005100 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005101 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005102 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005103 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005104 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005105 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005106 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005107 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005108 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01005109 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01005110 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005111 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005112 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005113 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005114 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005115 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005116 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005117 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08005118 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08005119 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005120 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005121 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005122 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005123 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005124 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08005125 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01005126 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08005127 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01005128 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08005129 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01005130 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08005131 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01005132 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08005133 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01005134 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08005135 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01005136 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08005137 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01005138 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08005139 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01005140 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08005141 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08005142 { .id = 0x11060428, .name = "VT1718S",
5143 .patch = patch_vt1718S},
5144 { .id = 0x11064428, .name = "VT1718S",
5145 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08005146 { .id = 0x11060441, .name = "VT2020",
5147 .patch = patch_vt1718S},
5148 { .id = 0x11064441, .name = "VT1828S",
5149 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08005150 { .id = 0x11060433, .name = "VT1716S",
5151 .patch = patch_vt1716S},
5152 { .id = 0x1106a721, .name = "VT1716S",
5153 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08005154 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
5155 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08005156 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08005157 { .id = 0x11060440, .name = "VT1818S",
5158 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08005159 { .id = 0x11060446, .name = "VT1802",
5160 .patch = patch_vt2002P},
5161 { .id = 0x11068446, .name = "VT1802",
5162 .patch = patch_vt2002P},
Joseph Chanc577b8a2006-11-29 15:29:40 +01005163 {} /* terminator */
5164};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005165
5166MODULE_ALIAS("snd-hda-codec-id:1106*");
5167
5168static struct hda_codec_preset_list via_list = {
5169 .preset = snd_hda_preset_via,
5170 .owner = THIS_MODULE,
5171};
5172
5173MODULE_LICENSE("GPL");
5174MODULE_DESCRIPTION("VIA HD-audio codec");
5175
5176static int __init patch_via_init(void)
5177{
5178 return snd_hda_add_codec_preset(&via_list);
5179}
5180
5181static void __exit patch_via_exit(void)
5182{
5183 snd_hda_delete_codec_preset(&via_list);
5184}
5185
5186module_init(patch_via_init)
5187module_exit(patch_via_exit)