blob: c66ff69eccf2650cf29ed74f77ac8f5e3ebdc278 [file] [log] [blame]
Joseph Chanc577b8a2006-11-29 15:29:40 +01001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Lydia Wang8e865972009-10-10 19:08:52 +08004 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
Joseph Chanc577b8a2006-11-29 15:29:40 +01005 *
Lydia Wang8e865972009-10-10 19:08:52 +08006 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
Joseph Chanc577b8a2006-11-29 15:29:40 +01008 *
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24/* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
Lydia Wang377ff312009-10-10 19:08:55 +080025/* */
Joseph Chanc577b8a2006-11-29 15:29:40 +010026/* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
Lydia Wang377ff312009-10-10 19:08:55 +080027/* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28/* 2006-08-02 Lydia Wang Add support to VT1709 codec */
Joseph Chanc577b8a2006-11-29 15:29:40 +010029/* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
Lydia Wang377ff312009-10-10 19:08:55 +080030/* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31/* 2007-09-17 Lydia Wang Add VT1708B codec support */
Harald Welte76d9b0d2008-09-09 15:50:37 +080032/* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
Harald Weltefb4cb772008-09-09 15:53:36 +080033/* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
Lydia Wang377ff312009-10-10 19:08:55 +080034/* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35/* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36/* 2008-04-09 Lydia Wang Add Independent HP feature */
Harald Welte98aa34c2008-09-09 16:02:09 +080037/* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
Lydia Wang377ff312009-10-10 19:08:55 +080038/* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
Lydia Wang8e865972009-10-10 19:08:52 +080039/* 2009-02-16 Logan Li Add support for VT1718S */
40/* 2009-03-13 Logan Li Add support for VT1716S */
41/* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42/* 2009-07-08 Lydia Wang Add support for VT2002P */
43/* 2009-07-21 Lydia Wang Add support for VT1812 */
Lydia Wang36dd5c42009-10-20 13:18:04 +080044/* 2009-09-19 Lydia Wang Add support for VT1818S */
Lydia Wang377ff312009-10-10 19:08:55 +080045/* */
Joseph Chanc577b8a2006-11-29 15:29:40 +010046/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
47
48
Joseph Chanc577b8a2006-11-29 15:29:40 +010049#include <linux/init.h>
50#include <linux/delay.h>
51#include <linux/slab.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010052#include <sound/core.h>
Harald Welte0aa62ae2008-09-09 15:58:27 +080053#include <sound/asoundef.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010054#include "hda_codec.h"
55#include "hda_local.h"
Joseph Chanc577b8a2006-11-29 15:29:40 +010056
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010057#define NID_MAPPING (-1)
58
Joseph Chanc577b8a2006-11-29 15:29:40 +010059/* amp values */
60#define AMP_VAL_IDX_SHIFT 19
61#define AMP_VAL_IDX_MASK (0x0f<<19)
62
Joseph Chanc577b8a2006-11-29 15:29:40 +010063/* Pin Widget NID */
64#define VT1708_HP_NID 0x13
65#define VT1708_DIGOUT_NID 0x14
66#define VT1708_DIGIN_NID 0x16
Josepch Chanf7278fd2007-12-13 16:40:40 +010067#define VT1708_DIGIN_PIN 0x26
Harald Welted949cac2008-09-09 15:56:01 +080068#define VT1708_HP_PIN_NID 0x20
69#define VT1708_CD_PIN_NID 0x24
Joseph Chanc577b8a2006-11-29 15:29:40 +010070
71#define VT1709_HP_DAC_NID 0x28
72#define VT1709_DIGOUT_NID 0x13
73#define VT1709_DIGIN_NID 0x17
Josepch Chanf7278fd2007-12-13 16:40:40 +010074#define VT1709_DIGIN_PIN 0x25
75
76#define VT1708B_HP_NID 0x25
77#define VT1708B_DIGOUT_NID 0x12
78#define VT1708B_DIGIN_NID 0x15
79#define VT1708B_DIGIN_PIN 0x21
Joseph Chanc577b8a2006-11-29 15:29:40 +010080
Harald Welted949cac2008-09-09 15:56:01 +080081#define VT1708S_HP_NID 0x25
82#define VT1708S_DIGOUT_NID 0x12
83
84#define VT1702_HP_NID 0x17
85#define VT1702_DIGOUT_NID 0x11
86
Harald Welted7426322008-09-15 22:43:23 +080087enum VIA_HDA_CODEC {
88 UNKNOWN = -1,
89 VT1708,
90 VT1709_10CH,
91 VT1709_6CH,
92 VT1708B_8CH,
93 VT1708B_4CH,
94 VT1708S,
Lydia Wang518bf3b2009-10-10 19:07:29 +080095 VT1708BCE,
Harald Welted7426322008-09-15 22:43:23 +080096 VT1702,
Lydia Wangeb7188c2009-10-10 19:08:34 +080097 VT1718S,
Lydia Wangf3db4232009-10-10 19:08:41 +080098 VT1716S,
Lydia Wang25eaba22009-10-10 19:08:43 +080099 VT2002P,
Lydia Wangab6734e2009-10-10 19:08:46 +0800100 VT1812,
Lydia Wang118909562011-03-23 17:57:34 +0800101 VT1802,
Harald Welted7426322008-09-15 22:43:23 +0800102 CODEC_TYPES,
103};
104
Lydia Wang118909562011-03-23 17:57:34 +0800105#define VT2002P_COMPATIBLE(spec) \
106 ((spec)->codec_type == VT2002P ||\
107 (spec)->codec_type == VT1812 ||\
108 (spec)->codec_type == VT1802)
109
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800110struct via_spec {
111 /* codec parameterization */
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200112 const struct snd_kcontrol_new *mixers[6];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800113 unsigned int num_mixers;
114
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200115 const struct hda_verb *init_verbs[5];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800116 unsigned int num_iverbs;
117
Takashi Iwai82673bc2011-06-17 16:24:21 +0200118 char stream_name_analog[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200119 const struct hda_pcm_stream *stream_analog_playback;
120 const struct hda_pcm_stream *stream_analog_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800121
Takashi Iwai82673bc2011-06-17 16:24:21 +0200122 char stream_name_digital[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200123 const struct hda_pcm_stream *stream_digital_playback;
124 const struct hda_pcm_stream *stream_digital_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800125
126 /* playback */
127 struct hda_multi_out multiout;
128 hda_nid_t slave_dig_outs[2];
129
130 /* capture */
131 unsigned int num_adc_nids;
Takashi Iwaia766d0d2011-06-17 09:01:29 +0200132 hda_nid_t adc_nids[3];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800133 hda_nid_t mux_nids[3];
134 hda_nid_t dig_in_nid;
135 hda_nid_t dig_in_pin;
136
137 /* capture source */
138 const struct hda_input_mux *input_mux;
139 unsigned int cur_mux[3];
140
141 /* PCM information */
142 struct hda_pcm pcm_rec[3];
143
144 /* dynamic controls, init_verbs and input_mux */
145 struct auto_pin_cfg autocfg;
146 struct snd_array kctls;
147 struct hda_input_mux private_imux[2];
148 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
149
150 /* HP mode source */
151 const struct hda_input_mux *hp_mux;
152 unsigned int hp_independent_mode;
153 unsigned int hp_independent_mode_index;
154 unsigned int smart51_enabled;
Lydia Wangf3db4232009-10-10 19:08:41 +0800155 unsigned int dmic_enabled;
Takashi Iwai24088a52011-06-17 16:59:21 +0200156 unsigned int no_pin_power_ctl;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800157 enum VIA_HDA_CODEC codec_type;
158
159 /* work to check hp jack state */
160 struct hda_codec *codec;
161 struct delayed_work vt1708_hp_work;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200162 int vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800163 int vt1708_hp_present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800164
165 void (*set_widgets_power_state)(struct hda_codec *codec);
166
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800167#ifdef CONFIG_SND_HDA_POWER_SAVE
168 struct hda_loopback_check loopback;
169#endif
170};
171
Lydia Wang0341ccd2011-03-22 16:25:03 +0800172static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100173static struct via_spec * via_new_spec(struct hda_codec *codec)
174{
175 struct via_spec *spec;
176
177 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
178 if (spec == NULL)
179 return NULL;
180
181 codec->spec = spec;
182 spec->codec = codec;
Lydia Wang0341ccd2011-03-22 16:25:03 +0800183 spec->codec_type = get_codec_type(codec);
184 /* VT1708BCE & VT1708S are almost same */
185 if (spec->codec_type == VT1708BCE)
186 spec->codec_type = VT1708S;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100187 return spec;
188}
189
Lydia Wang744ff5f2009-10-10 19:07:26 +0800190static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800191{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800192 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800193 u16 ven_id = vendor_id >> 16;
194 u16 dev_id = vendor_id & 0xffff;
195 enum VIA_HDA_CODEC codec_type;
196
197 /* get codec type */
198 if (ven_id != 0x1106)
199 codec_type = UNKNOWN;
200 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
201 codec_type = VT1708;
202 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
203 codec_type = VT1709_10CH;
204 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
205 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800206 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800207 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800208 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
209 codec_type = VT1708BCE;
210 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800211 codec_type = VT1708B_4CH;
212 else if ((dev_id & 0xfff) == 0x397
213 && (dev_id >> 12) < 8)
214 codec_type = VT1708S;
215 else if ((dev_id & 0xfff) == 0x398
216 && (dev_id >> 12) < 8)
217 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800218 else if ((dev_id & 0xfff) == 0x428
219 && (dev_id >> 12) < 8)
220 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800221 else if (dev_id == 0x0433 || dev_id == 0xa721)
222 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800223 else if (dev_id == 0x0441 || dev_id == 0x4441)
224 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800225 else if (dev_id == 0x0438 || dev_id == 0x4438)
226 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800227 else if (dev_id == 0x0448)
228 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800229 else if (dev_id == 0x0440)
230 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800231 else if ((dev_id & 0xfff) == 0x446)
232 codec_type = VT1802;
Harald Welted7426322008-09-15 22:43:23 +0800233 else
234 codec_type = UNKNOWN;
235 return codec_type;
236};
237
Lydia Wangec7e7e42011-03-24 12:43:44 +0800238#define VIA_JACK_EVENT 0x20
Harald Welte69e52a82008-09-09 15:57:32 +0800239#define VIA_HP_EVENT 0x01
240#define VIA_GPIO_EVENT 0x02
Lydia Wangec7e7e42011-03-24 12:43:44 +0800241#define VIA_MONO_EVENT 0x03
242#define VIA_SPEAKER_EVENT 0x04
243#define VIA_BIND_HP_EVENT 0x05
Harald Welte69e52a82008-09-09 15:57:32 +0800244
Joseph Chanc577b8a2006-11-29 15:29:40 +0100245enum {
246 VIA_CTL_WIDGET_VOL,
247 VIA_CTL_WIDGET_MUTE,
Lydia Wangf5271102009-10-10 19:07:35 +0800248 VIA_CTL_WIDGET_ANALOG_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800249 VIA_CTL_WIDGET_BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100250};
251
252enum {
Harald Welteeb14a462008-09-09 15:40:38 +0800253 AUTO_SEQ_FRONT = 0,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100254 AUTO_SEQ_SURROUND,
255 AUTO_SEQ_CENLFE,
256 AUTO_SEQ_SIDE
257};
258
Lydia Wangf5271102009-10-10 19:07:35 +0800259static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800260static int is_aa_path_mute(struct hda_codec *codec);
261
262static void vt1708_start_hp_work(struct via_spec *spec)
263{
264 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
265 return;
266 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200267 !spec->vt1708_jack_detect);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800268 if (!delayed_work_pending(&spec->vt1708_hp_work))
269 schedule_delayed_work(&spec->vt1708_hp_work,
270 msecs_to_jiffies(100));
271}
272
273static void vt1708_stop_hp_work(struct via_spec *spec)
274{
275 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
276 return;
277 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
278 && !is_aa_path_mute(spec->codec))
279 return;
280 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200281 !spec->vt1708_jack_detect);
Tejun Heo5b84ba22010-12-11 17:51:26 +0100282 cancel_delayed_work_sync(&spec->vt1708_hp_work);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800283}
Lydia Wangf5271102009-10-10 19:07:35 +0800284
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800285static void set_widgets_power_state(struct hda_codec *codec)
286{
287 struct via_spec *spec = codec->spec;
288 if (spec->set_widgets_power_state)
289 spec->set_widgets_power_state(codec);
290}
Lydia Wang25eaba22009-10-10 19:08:43 +0800291
Lydia Wangf5271102009-10-10 19:07:35 +0800292static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_value *ucontrol)
294{
295 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
296 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
297
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800298 set_widgets_power_state(codec);
Lydia Wangf5271102009-10-10 19:07:35 +0800299 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800300 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
301 if (is_aa_path_mute(codec))
302 vt1708_start_hp_work(codec->spec);
303 else
304 vt1708_stop_hp_work(codec->spec);
305 }
Lydia Wangf5271102009-10-10 19:07:35 +0800306 return change;
307}
308
309/* modify .put = snd_hda_mixer_amp_switch_put */
310#define ANALOG_INPUT_MUTE \
311 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
312 .name = NULL, \
313 .index = 0, \
314 .info = snd_hda_mixer_amp_switch_info, \
315 .get = snd_hda_mixer_amp_switch_get, \
316 .put = analog_input_switch_put, \
317 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
318
Lydia Wang25eaba22009-10-10 19:08:43 +0800319static void via_hp_bind_automute(struct hda_codec *codec);
320
321static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
322 struct snd_ctl_elem_value *ucontrol)
323{
324 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
325 struct via_spec *spec = codec->spec;
326 int i;
327 int change = 0;
328
329 long *valp = ucontrol->value.integer.value;
330 int lmute, rmute;
331 if (strstr(kcontrol->id.name, "Switch") == NULL) {
332 snd_printd("Invalid control!\n");
333 return change;
334 }
335 change = snd_hda_mixer_amp_switch_put(kcontrol,
336 ucontrol);
337 /* Get mute value */
338 lmute = *valp ? 0 : HDA_AMP_MUTE;
339 valp++;
340 rmute = *valp ? 0 : HDA_AMP_MUTE;
341
342 /* Set hp pins */
343 if (!spec->hp_independent_mode) {
344 for (i = 0; i < spec->autocfg.hp_outs; i++) {
345 snd_hda_codec_amp_update(
346 codec, spec->autocfg.hp_pins[i],
347 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
348 lmute);
349 snd_hda_codec_amp_update(
350 codec, spec->autocfg.hp_pins[i],
351 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
352 rmute);
353 }
354 }
355
356 if (!lmute && !rmute) {
357 /* Line Outs */
358 for (i = 0; i < spec->autocfg.line_outs; i++)
359 snd_hda_codec_amp_stereo(
360 codec, spec->autocfg.line_out_pins[i],
361 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
362 /* Speakers */
363 for (i = 0; i < spec->autocfg.speaker_outs; i++)
364 snd_hda_codec_amp_stereo(
365 codec, spec->autocfg.speaker_pins[i],
366 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
367 /* unmute */
368 via_hp_bind_automute(codec);
369
370 } else {
371 if (lmute) {
372 /* Mute all left channels */
373 for (i = 1; i < spec->autocfg.line_outs; i++)
374 snd_hda_codec_amp_update(
375 codec,
376 spec->autocfg.line_out_pins[i],
377 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
378 lmute);
379 for (i = 0; i < spec->autocfg.speaker_outs; i++)
380 snd_hda_codec_amp_update(
381 codec,
382 spec->autocfg.speaker_pins[i],
383 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
384 lmute);
385 }
386 if (rmute) {
387 /* mute all right channels */
388 for (i = 1; i < spec->autocfg.line_outs; i++)
389 snd_hda_codec_amp_update(
390 codec,
391 spec->autocfg.line_out_pins[i],
392 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
393 rmute);
394 for (i = 0; i < spec->autocfg.speaker_outs; i++)
395 snd_hda_codec_amp_update(
396 codec,
397 spec->autocfg.speaker_pins[i],
398 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
399 rmute);
400 }
401 }
402 return change;
403}
404
405#define BIND_PIN_MUTE \
406 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
407 .name = NULL, \
408 .index = 0, \
409 .info = snd_hda_mixer_amp_switch_info, \
410 .get = snd_hda_mixer_amp_switch_get, \
411 .put = bind_pin_switch_put, \
412 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
413
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200414static const struct snd_kcontrol_new via_control_templates[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100415 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
416 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Lydia Wangf5271102009-10-10 19:07:35 +0800417 ANALOG_INPUT_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800418 BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100419};
420
Lydia Wangab6734e2009-10-10 19:08:46 +0800421
Joseph Chanc577b8a2006-11-29 15:29:40 +0100422/* add dynamic controls */
Takashi Iwai291c9e32011-06-17 16:15:26 +0200423static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
424 const struct snd_kcontrol_new *tmpl,
425 const char *name)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100426{
427 struct snd_kcontrol_new *knew;
428
Takashi Iwai603c4012008-07-30 15:01:44 +0200429 snd_array_init(&spec->kctls, sizeof(*knew), 32);
430 knew = snd_array_new(&spec->kctls);
431 if (!knew)
Takashi Iwai291c9e32011-06-17 16:15:26 +0200432 return NULL;
433 *knew = *tmpl;
434 if (!name)
435 name = tmpl->name;
436 if (name) {
437 knew->name = kstrdup(name, GFP_KERNEL);
438 if (!knew->name)
439 return NULL;
440 }
441 return knew;
442}
443
444static int __via_add_control(struct via_spec *spec, int type, const char *name,
445 int idx, unsigned long val)
446{
447 struct snd_kcontrol_new *knew;
448
449 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
450 if (!knew)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100451 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100452 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100453 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100454 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100455 return 0;
456}
457
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200458#define via_add_control(spec, type, name, val) \
459 __via_add_control(spec, type, name, 0, val)
460
Takashi Iwai291c9e32011-06-17 16:15:26 +0200461#define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100462
Takashi Iwai603c4012008-07-30 15:01:44 +0200463static void via_free_kctls(struct hda_codec *codec)
464{
465 struct via_spec *spec = codec->spec;
466
467 if (spec->kctls.list) {
468 struct snd_kcontrol_new *kctl = spec->kctls.list;
469 int i;
470 for (i = 0; i < spec->kctls.used; i++)
471 kfree(kctl[i].name);
472 }
473 snd_array_free(&spec->kctls);
474}
475
Joseph Chanc577b8a2006-11-29 15:29:40 +0100476/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800477static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200478 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100479{
480 char name[32];
481 int err;
482
483 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200484 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100485 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
486 if (err < 0)
487 return err;
488 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200489 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100490 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
491 if (err < 0)
492 return err;
493 return 0;
494}
495
496static void via_auto_set_output_and_unmute(struct hda_codec *codec,
497 hda_nid_t nid, int pin_type,
498 int dac_idx)
499{
500 /* set as output */
501 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
502 pin_type);
503 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
504 AMP_OUT_UNMUTE);
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200505 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
Lydia Wang377ff312009-10-10 19:08:55 +0800506 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200507 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100508}
509
510
511static void via_auto_init_multi_out(struct hda_codec *codec)
512{
513 struct via_spec *spec = codec->spec;
514 int i;
515
516 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
517 hda_nid_t nid = spec->autocfg.line_out_pins[i];
518 if (nid)
519 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
520 }
521}
522
523static void via_auto_init_hp_out(struct hda_codec *codec)
524{
525 struct via_spec *spec = codec->spec;
526 hda_nid_t pin;
Lydia Wang25eaba22009-10-10 19:08:43 +0800527 int i;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100528
Lydia Wang25eaba22009-10-10 19:08:43 +0800529 for (i = 0; i < spec->autocfg.hp_outs; i++) {
530 pin = spec->autocfg.hp_pins[i];
531 if (pin) /* connect to front */
532 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
533 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100534}
535
Clemens Ladisch32e01912010-07-12 16:28:50 +0200536static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
537
Joseph Chanc577b8a2006-11-29 15:29:40 +0100538static void via_auto_init_analog_input(struct hda_codec *codec)
539{
540 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200541 const struct auto_pin_cfg *cfg = &spec->autocfg;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200542 unsigned int ctl;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100543 int i;
544
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200545 for (i = 0; i < cfg->num_inputs; i++) {
546 hda_nid_t nid = cfg->inputs[i].pin;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200547 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
548 ctl = PIN_OUT;
David Henningsson30649672011-02-21 10:23:18 +0100549 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
Clemens Ladisch32e01912010-07-12 16:28:50 +0200550 ctl = PIN_VREF50;
551 else
552 ctl = PIN_IN;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100553 snd_hda_codec_write(codec, nid, 0,
Clemens Ladisch32e01912010-07-12 16:28:50 +0200554 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100555 }
556}
Lydia Wangf5271102009-10-10 19:07:35 +0800557
558static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
559 unsigned int *affected_parm)
560{
561 unsigned parm;
562 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
563 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
564 >> AC_DEFCFG_MISC_SHIFT
565 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800566 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200567 unsigned present = 0;
568
569 no_presence |= spec->no_pin_power_ctl;
570 if (!no_presence)
571 present = snd_hda_jack_detect(codec, nid);
Lydia Wang1564b282009-10-10 19:07:52 +0800572 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
573 || ((no_presence || present)
574 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800575 *affected_parm = AC_PWRST_D0; /* if it's connected */
576 parm = AC_PWRST_D0;
577 } else
578 parm = AC_PWRST_D3;
579
580 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
581}
582
Takashi Iwai24088a52011-06-17 16:59:21 +0200583static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
584 struct snd_ctl_elem_info *uinfo)
585{
586 static const char * const texts[] = {
587 "Disabled", "Enabled"
588 };
589
590 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
591 uinfo->count = 1;
592 uinfo->value.enumerated.items = 2;
593 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
594 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
595 strcpy(uinfo->value.enumerated.name,
596 texts[uinfo->value.enumerated.item]);
597 return 0;
598}
599
600static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
601 struct snd_ctl_elem_value *ucontrol)
602{
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 struct via_spec *spec = codec->spec;
605 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
606 return 0;
607}
608
609static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
610 struct snd_ctl_elem_value *ucontrol)
611{
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613 struct via_spec *spec = codec->spec;
614 unsigned int val = !ucontrol->value.enumerated.item[0];
615
616 if (val == spec->no_pin_power_ctl)
617 return 0;
618 spec->no_pin_power_ctl = val;
619 set_widgets_power_state(codec);
620 return 1;
621}
622
623static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
625 .name = "Dynamic Power-Control",
626 .info = via_pin_power_ctl_info,
627 .get = via_pin_power_ctl_get,
628 .put = via_pin_power_ctl_put,
629};
630
631
Joseph Chanc577b8a2006-11-29 15:29:40 +0100632/*
633 * input MUX handling
634 */
635static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
636 struct snd_ctl_elem_info *uinfo)
637{
638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639 struct via_spec *spec = codec->spec;
640 return snd_hda_input_mux_info(spec->input_mux, uinfo);
641}
642
643static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_value *ucontrol)
645{
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct via_spec *spec = codec->spec;
648 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
649
650 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
651 return 0;
652}
653
654static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
655 struct snd_ctl_elem_value *ucontrol)
656{
657 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
658 struct via_spec *spec = codec->spec;
659 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800660 int ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100661
Takashi Iwai337b9d02009-07-07 18:18:59 +0200662 if (!spec->mux_nids[adc_idx])
663 return -EINVAL;
Lydia Wanga80e6e32009-10-10 19:07:55 +0800664 /* switch to D0 beofre change index */
665 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
666 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
667 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
668 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800669
670 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
671 spec->mux_nids[adc_idx],
672 &spec->cur_mux[adc_idx]);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800673 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800674 set_widgets_power_state(codec);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800675
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800676 return ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100677}
678
Harald Welte0aa62ae2008-09-09 15:58:27 +0800679static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
680 struct snd_ctl_elem_info *uinfo)
681{
682 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
683 struct via_spec *spec = codec->spec;
684 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
685}
686
687static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
688 struct snd_ctl_elem_value *ucontrol)
689{
690 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100691 hda_nid_t nid = kcontrol->private_value;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800692 unsigned int pinsel;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800693
Lydia Wangeb7188c2009-10-10 19:08:34 +0800694 /* use !! to translate conn sel 2 for VT1718S */
695 pinsel = !!snd_hda_codec_read(codec, nid, 0,
696 AC_VERB_GET_CONNECT_SEL,
697 0x00);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800698 ucontrol->value.enumerated.item[0] = pinsel;
699
700 return 0;
701}
702
Lydia Wang0713efe2009-10-10 19:07:43 +0800703static void activate_ctl(struct hda_codec *codec, const char *name, int active)
704{
705 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
706 if (ctl) {
707 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
708 ctl->vd[0].access |= active
709 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
710 snd_ctl_notify(codec->bus->card,
711 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
712 }
713}
714
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100715static hda_nid_t side_mute_channel(struct via_spec *spec)
716{
717 switch (spec->codec_type) {
718 case VT1708: return 0x1b;
719 case VT1709_10CH: return 0x29;
720 case VT1708B_8CH: /* fall thru */
721 case VT1708S: return 0x27;
Lydia Wange87885f2011-03-24 12:39:05 +0800722 case VT2002P: return 0x19;
723 case VT1802: return 0x15;
724 case VT1812: return 0x15;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100725 default: return 0;
726 }
727}
728
Lydia Wangcdc17842009-10-10 19:07:47 +0800729static int update_side_mute_status(struct hda_codec *codec)
730{
731 /* mute side channel */
732 struct via_spec *spec = codec->spec;
Lydia Wange87885f2011-03-24 12:39:05 +0800733 unsigned int parm;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100734 hda_nid_t sw3 = side_mute_channel(spec);
Lydia Wangcdc17842009-10-10 19:07:47 +0800735
Lydia Wange87885f2011-03-24 12:39:05 +0800736 if (sw3) {
737 if (VT2002P_COMPATIBLE(spec))
738 parm = spec->hp_independent_mode ?
739 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
740 else
741 parm = spec->hp_independent_mode ?
742 AMP_OUT_MUTE : AMP_OUT_UNMUTE;
743 snd_hda_codec_write(codec, sw3, 0,
744 AC_VERB_SET_AMP_GAIN_MUTE, parm);
745 if (spec->codec_type == VT1812)
746 snd_hda_codec_write(codec, 0x1d, 0,
747 AC_VERB_SET_AMP_GAIN_MUTE, parm);
748 }
Lydia Wangcdc17842009-10-10 19:07:47 +0800749 return 0;
750}
751
Harald Welte0aa62ae2008-09-09 15:58:27 +0800752static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
753 struct snd_ctl_elem_value *ucontrol)
754{
755 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
756 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100757 hda_nid_t nid = kcontrol->private_value;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800758 unsigned int pinsel = ucontrol->value.enumerated.item[0];
Lydia Wangcdc17842009-10-10 19:07:47 +0800759 /* Get Independent Mode index of headphone pin widget */
760 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
761 ? 1 : 0;
Lydia Wangce0e5a92011-03-22 16:22:37 +0800762 if (spec->codec_type == VT1718S)
763 snd_hda_codec_write(codec, nid, 0,
764 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
765 else
766 snd_hda_codec_write(codec, nid, 0,
767 AC_VERB_SET_CONNECT_SEL, pinsel);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800768
Lydia Wangce0e5a92011-03-22 16:22:37 +0800769 if (spec->codec_type == VT1812)
770 snd_hda_codec_write(codec, 0x35, 0,
771 AC_VERB_SET_CONNECT_SEL, pinsel);
Lydia Wangcdc17842009-10-10 19:07:47 +0800772 if (spec->multiout.hp_nid && spec->multiout.hp_nid
773 != spec->multiout.dac_nids[HDA_FRONT])
774 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
775 0, 0, 0);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800776
Lydia Wangcdc17842009-10-10 19:07:47 +0800777 update_side_mute_status(codec);
Lydia Wang0713efe2009-10-10 19:07:43 +0800778 /* update HP volume/swtich active state */
779 if (spec->codec_type == VT1708S
Lydia Wangeb7188c2009-10-10 19:08:34 +0800780 || spec->codec_type == VT1702
Lydia Wangf3db4232009-10-10 19:08:41 +0800781 || spec->codec_type == VT1718S
Lydia Wang25eaba22009-10-10 19:08:43 +0800782 || spec->codec_type == VT1716S
Lydia Wang118909562011-03-23 17:57:34 +0800783 || VT2002P_COMPATIBLE(spec)) {
Lydia Wang0713efe2009-10-10 19:07:43 +0800784 activate_ctl(codec, "Headphone Playback Volume",
785 spec->hp_independent_mode);
786 activate_ctl(codec, "Headphone Playback Switch",
787 spec->hp_independent_mode);
788 }
Lydia Wangce0e5a92011-03-22 16:22:37 +0800789 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800790 set_widgets_power_state(codec);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800791 return 0;
792}
793
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200794static const struct snd_kcontrol_new via_hp_mixer[2] = {
Harald Welte0aa62ae2008-09-09 15:58:27 +0800795 {
796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
797 .name = "Independent HP",
Harald Welte0aa62ae2008-09-09 15:58:27 +0800798 .info = via_independent_hp_info,
799 .get = via_independent_hp_get,
800 .put = via_independent_hp_put,
801 },
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100802 {
803 .iface = NID_MAPPING,
804 .name = "Independent HP",
805 },
Harald Welte0aa62ae2008-09-09 15:58:27 +0800806};
807
Takashi Iwai3d83e572010-04-14 14:36:23 +0200808static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100809{
Takashi Iwai3d83e572010-04-14 14:36:23 +0200810 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100811 struct snd_kcontrol_new *knew;
812 hda_nid_t nid;
Takashi Iwai3d83e572010-04-14 14:36:23 +0200813 int nums;
814 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100815
816 switch (spec->codec_type) {
817 case VT1718S:
818 nid = 0x34;
819 break;
820 case VT2002P:
Lydia Wang118909562011-03-23 17:57:34 +0800821 case VT1802:
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100822 nid = 0x35;
823 break;
824 case VT1812:
825 nid = 0x3d;
826 break;
827 default:
828 nid = spec->autocfg.hp_pins[0];
829 break;
830 }
831
Lydia Wangee3c35c2011-03-22 16:26:36 +0800832 if (spec->codec_type != VT1708) {
833 nums = snd_hda_get_connections(codec, nid,
834 conn, HDA_MAX_CONNECTIONS);
835 if (nums <= 1)
836 return 0;
837 }
Takashi Iwai3d83e572010-04-14 14:36:23 +0200838
839 knew = via_clone_control(spec, &via_hp_mixer[0]);
840 if (knew == NULL)
841 return -ENOMEM;
842
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100843 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
844 knew->private_value = nid;
845
846 knew = via_clone_control(spec, &via_hp_mixer[1]);
847 if (knew == NULL)
848 return -ENOMEM;
849 knew->subdevice = side_mute_channel(spec);
850
851 return 0;
852}
853
Lydia Wang1564b282009-10-10 19:07:52 +0800854static void notify_aa_path_ctls(struct hda_codec *codec)
855{
856 int i;
857 struct snd_ctl_elem_id id;
Lydia Wang525566c2011-04-28 16:03:39 +0800858 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
859 struct snd_kcontrol *ctl;
Lydia Wang1564b282009-10-10 19:07:52 +0800860
861 memset(&id, 0, sizeof(id));
862 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
863 for (i = 0; i < ARRAY_SIZE(labels); i++) {
864 sprintf(id.name, "%s Playback Volume", labels[i]);
Lydia Wang525566c2011-04-28 16:03:39 +0800865 ctl = snd_hda_find_mixer_ctl(codec, id.name);
866 if (ctl)
867 snd_ctl_notify(codec->bus->card,
868 SNDRV_CTL_EVENT_MASK_VALUE,
869 &ctl->id);
Lydia Wang1564b282009-10-10 19:07:52 +0800870 }
871}
872
873static void mute_aa_path(struct hda_codec *codec, int mute)
874{
875 struct via_spec *spec = codec->spec;
876 hda_nid_t nid_mixer;
877 int start_idx;
878 int end_idx;
879 int i;
880 /* get nid of MW0 and start & end index */
881 switch (spec->codec_type) {
882 case VT1708:
883 nid_mixer = 0x17;
884 start_idx = 2;
885 end_idx = 4;
886 break;
887 case VT1709_10CH:
888 case VT1709_6CH:
889 nid_mixer = 0x18;
890 start_idx = 2;
891 end_idx = 4;
892 break;
893 case VT1708B_8CH:
894 case VT1708B_4CH:
895 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +0800896 case VT1716S:
Lydia Wang1564b282009-10-10 19:07:52 +0800897 nid_mixer = 0x16;
898 start_idx = 2;
899 end_idx = 4;
900 break;
Lydia Wangab657e02011-03-22 16:23:23 +0800901 case VT1718S:
902 nid_mixer = 0x21;
903 start_idx = 1;
904 end_idx = 3;
905 break;
Lydia Wang1564b282009-10-10 19:07:52 +0800906 default:
907 return;
908 }
909 /* check AA path's mute status */
910 for (i = start_idx; i <= end_idx; i++) {
911 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
912 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
913 HDA_AMP_MUTE, val);
914 }
915}
916static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
917{
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200918 const struct auto_pin_cfg *cfg = &spec->autocfg;
919 int i;
920
921 for (i = 0; i < cfg->num_inputs; i++) {
922 if (pin == cfg->inputs[i].pin)
Takashi Iwai86e29592010-09-09 14:50:17 +0200923 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
Lydia Wang1564b282009-10-10 19:07:52 +0800924 }
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200925 return 0;
Lydia Wang1564b282009-10-10 19:07:52 +0800926}
927
928static int via_smart51_info(struct snd_kcontrol *kcontrol,
929 struct snd_ctl_elem_info *uinfo)
930{
931 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
932 uinfo->count = 1;
933 uinfo->value.integer.min = 0;
934 uinfo->value.integer.max = 1;
935 return 0;
936}
937
938static int via_smart51_get(struct snd_kcontrol *kcontrol,
939 struct snd_ctl_elem_value *ucontrol)
940{
941 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
942 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200943 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800944 int on = 1;
945 int i;
946
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200947 for (i = 0; i < cfg->num_inputs; i++) {
948 hda_nid_t nid = cfg->inputs[i].pin;
949 int ctl = snd_hda_codec_read(codec, nid, 0,
950 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai86e29592010-09-09 14:50:17 +0200951 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200952 continue;
Takashi Iwai86e29592010-09-09 14:50:17 +0200953 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200954 spec->hp_independent_mode && spec->codec_type != VT1718S)
955 continue; /* ignore FMic for independent HP */
956 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
957 on = 0;
Lydia Wang1564b282009-10-10 19:07:52 +0800958 }
959 *ucontrol->value.integer.value = on;
960 return 0;
961}
962
963static int via_smart51_put(struct snd_kcontrol *kcontrol,
964 struct snd_ctl_elem_value *ucontrol)
965{
966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
967 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200968 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800969 int out_in = *ucontrol->value.integer.value
970 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +0800971 int i;
972
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200973 for (i = 0; i < cfg->num_inputs; i++) {
974 hda_nid_t nid = cfg->inputs[i].pin;
975 unsigned int parm;
976
Takashi Iwai86e29592010-09-09 14:50:17 +0200977 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200978 continue;
Takashi Iwai86e29592010-09-09 14:50:17 +0200979 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200980 spec->hp_independent_mode && spec->codec_type != VT1718S)
Lydia Wang1564b282009-10-10 19:07:52 +0800981 continue; /* don't retask FMic for independent HP */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200982
983 parm = snd_hda_codec_read(codec, nid, 0,
984 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
985 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
986 parm |= out_in;
987 snd_hda_codec_write(codec, nid, 0,
988 AC_VERB_SET_PIN_WIDGET_CONTROL,
989 parm);
990 if (out_in == AC_PINCTL_OUT_EN) {
991 mute_aa_path(codec, 1);
992 notify_aa_path_ctls(codec);
993 }
994 if (spec->codec_type == VT1718S) {
995 snd_hda_codec_amp_stereo(
Lydia Wangeb7188c2009-10-10 19:08:34 +0800996 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
997 HDA_AMP_UNMUTE);
Lydia Wang1564b282009-10-10 19:07:52 +0800998 }
Takashi Iwai86e29592010-09-09 14:50:17 +0200999 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
Lydia Wangf3db4232009-10-10 19:08:41 +08001000 if (spec->codec_type == VT1708S
1001 || spec->codec_type == VT1716S) {
Lydia Wang1564b282009-10-10 19:07:52 +08001002 /* input = index 1 (AOW3) */
1003 snd_hda_codec_write(
1004 codec, nid, 0,
1005 AC_VERB_SET_CONNECT_SEL, 1);
1006 snd_hda_codec_amp_stereo(
1007 codec, nid, HDA_OUTPUT,
1008 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1009 }
1010 }
1011 }
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
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001026static int via_smart51_build(struct via_spec *spec)
1027{
1028 struct snd_kcontrol_new *knew;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001029 const struct auto_pin_cfg *cfg = &spec->autocfg;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001030 hda_nid_t nid;
1031 int i;
1032
Lydia Wangcb34c202011-04-27 17:44:16 +08001033 if (!cfg)
1034 return 0;
1035 if (cfg->line_outs > 2)
1036 return 0;
1037
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001038 knew = via_clone_control(spec, &via_smart51_mixer);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001039 if (knew == NULL)
1040 return -ENOMEM;
1041
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001042 for (i = 0; i < cfg->num_inputs; i++) {
1043 nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02001044 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001045 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001046 break;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001047 }
1048 }
1049
1050 return 0;
1051}
1052
Joseph Chanc577b8a2006-11-29 15:29:40 +01001053/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001054static const struct snd_kcontrol_new vt1708_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001055 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1056 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1057 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1058 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1059 {
1060 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1061 /* The multiple "Capture Source" controls confuse alsamixer
1062 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01001063 */
1064 /* .name = "Capture Source", */
1065 .name = "Input Source",
1066 .count = 1,
1067 .info = via_mux_enum_info,
1068 .get = via_mux_enum_get,
1069 .put = via_mux_enum_put,
1070 },
1071 { } /* end */
1072};
Lydia Wangf5271102009-10-10 19:07:35 +08001073
1074/* check AA path's mute statue */
1075static int is_aa_path_mute(struct hda_codec *codec)
1076{
1077 int mute = 1;
1078 hda_nid_t nid_mixer;
1079 int start_idx;
1080 int end_idx;
1081 int i;
1082 struct via_spec *spec = codec->spec;
1083 /* get nid of MW0 and start & end index */
1084 switch (spec->codec_type) {
1085 case VT1708B_8CH:
1086 case VT1708B_4CH:
1087 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001088 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001089 nid_mixer = 0x16;
1090 start_idx = 2;
1091 end_idx = 4;
1092 break;
1093 case VT1702:
1094 nid_mixer = 0x1a;
1095 start_idx = 1;
1096 end_idx = 3;
1097 break;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001098 case VT1718S:
1099 nid_mixer = 0x21;
1100 start_idx = 1;
1101 end_idx = 3;
1102 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001103 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001104 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001105 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001106 nid_mixer = 0x21;
1107 start_idx = 0;
1108 end_idx = 2;
1109 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001110 default:
1111 return 0;
1112 }
1113 /* check AA path's mute status */
1114 for (i = start_idx; i <= end_idx; i++) {
1115 unsigned int con_list = snd_hda_codec_read(
1116 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1117 int shift = 8 * (i % 4);
1118 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1119 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1120 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1121 /* check mute status while the pin is connected */
1122 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1123 HDA_INPUT, i) >> 7;
1124 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1125 HDA_INPUT, i) >> 7;
1126 if (!mute_l || !mute_r) {
1127 mute = 0;
1128 break;
1129 }
1130 }
1131 }
1132 return mute;
1133}
1134
1135/* enter/exit analog low-current mode */
1136static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1137{
1138 struct via_spec *spec = codec->spec;
1139 static int saved_stream_idle = 1; /* saved stream idle status */
1140 int enable = is_aa_path_mute(codec);
1141 unsigned int verb = 0;
1142 unsigned int parm = 0;
1143
1144 if (stream_idle == -1) /* stream status did not change */
1145 enable = enable && saved_stream_idle;
1146 else {
1147 enable = enable && stream_idle;
1148 saved_stream_idle = stream_idle;
1149 }
1150
1151 /* decide low current mode's verb & parameter */
1152 switch (spec->codec_type) {
1153 case VT1708B_8CH:
1154 case VT1708B_4CH:
1155 verb = 0xf70;
1156 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1157 break;
1158 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001159 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001160 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001161 verb = 0xf73;
1162 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1163 break;
1164 case VT1702:
1165 verb = 0xf73;
1166 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1167 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001168 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001169 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001170 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001171 verb = 0xf93;
1172 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1173 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001174 default:
1175 return; /* other codecs are not supported */
1176 }
1177 /* send verb */
1178 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1179}
1180
Joseph Chanc577b8a2006-11-29 15:29:40 +01001181/*
1182 * generic initialization of ADC, input mixers and output mixers
1183 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001184static const struct hda_verb vt1708_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001185 /*
1186 * Unmute ADC0-1 and set the default input to mic-in
1187 */
1188 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1189 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1190
1191
Josepch Chanf7278fd2007-12-13 16:40:40 +01001192 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01001193 * mixer widget
1194 */
1195 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01001196 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1197 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1198 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1199 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1200 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001201
1202 /*
1203 * Set up output mixers (0x19 - 0x1b)
1204 */
1205 /* set vol=0 to output mixers */
1206 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1207 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1208 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Lydia Wang377ff312009-10-10 19:08:55 +08001209
Lydia Wangbfdc6752009-10-10 19:08:50 +08001210 /* Setup default input MW0 to PW4 */
1211 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001212 /* PW9 Output enable */
1213 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangaa266fc2011-03-24 12:41:01 +08001214 /* power down jack detect function */
1215 {0x1, 0xf81, 0x1},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001216 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001217};
1218
1219static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1220 struct hda_codec *codec,
1221 struct snd_pcm_substream *substream)
1222{
1223 struct via_spec *spec = codec->spec;
Lydia Wang17314372009-10-10 19:07:37 +08001224 int idle = substream->pstr->substream_opened == 1
1225 && substream->ref_count == 0;
Lydia Wang17314372009-10-10 19:07:37 +08001226 analog_low_current_mode(codec, idle);
Takashi Iwai9a081602008-02-12 18:37:26 +01001227 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1228 hinfo);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001229}
1230
Harald Welte0aa62ae2008-09-09 15:58:27 +08001231static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1232 unsigned int stream_tag,
1233 unsigned int format,
1234 struct snd_pcm_substream *substream)
1235{
1236 struct via_spec *spec = codec->spec;
1237 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001238 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001239 int chs = substream->runtime->channels;
1240 int i;
Stephen Warren7c935972011-06-01 11:14:17 -06001241 struct hda_spdif_out *spdif =
1242 snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001243
1244 mutex_lock(&codec->spdif_mutex);
1245 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1246 if (chs == 2 &&
1247 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1248 format) &&
Stephen Warren7c935972011-06-01 11:14:17 -06001249 !(spdif->status & IEC958_AES0_NONAUDIO)) {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001250 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1251 /* turn off SPDIF once; otherwise the IEC958 bits won't
1252 * be updated */
Stephen Warren7c935972011-06-01 11:14:17 -06001253 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001254 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1255 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001256 spdif->ctls &
Harald Welte0aa62ae2008-09-09 15:58:27 +08001257 ~AC_DIG1_ENABLE & 0xff);
1258 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1259 stream_tag, 0, format);
1260 /* turn on again (if needed) */
Stephen Warren7c935972011-06-01 11:14:17 -06001261 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001262 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1263 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001264 spdif->ctls & 0xff);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001265 } else {
1266 mout->dig_out_used = 0;
1267 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1268 0, 0, 0);
1269 }
1270 }
1271 mutex_unlock(&codec->spdif_mutex);
1272
1273 /* front */
1274 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1275 0, format);
1276
Lydia Wangeb7188c2009-10-10 19:08:34 +08001277 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1278 && !spec->hp_independent_mode)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001279 /* headphone out will just decode front left/right (stereo) */
1280 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1281 0, format);
1282
1283 /* extra outputs copied from front */
1284 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1285 if (mout->extra_out_nid[i])
1286 snd_hda_codec_setup_stream(codec,
1287 mout->extra_out_nid[i],
1288 stream_tag, 0, format);
1289
1290 /* surrounds */
1291 for (i = 1; i < mout->num_dacs; i++) {
1292 if (chs >= (i + 1) * 2) /* independent out */
1293 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1294 i * 2, format);
1295 else /* copy front */
1296 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1297 0, format);
1298 }
1299}
1300
1301static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1302 struct hda_codec *codec,
1303 unsigned int stream_tag,
1304 unsigned int format,
1305 struct snd_pcm_substream *substream)
1306{
1307 struct via_spec *spec = codec->spec;
1308 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001309 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001310
1311 if (substream->number == 0)
1312 playback_multi_pcm_prep_0(codec, stream_tag, format,
1313 substream);
1314 else {
1315 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1316 spec->hp_independent_mode)
1317 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1318 stream_tag, 0, format);
1319 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001320 vt1708_start_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001321 return 0;
1322}
1323
1324static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1325 struct hda_codec *codec,
1326 struct snd_pcm_substream *substream)
1327{
1328 struct via_spec *spec = codec->spec;
1329 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001330 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001331 int i;
1332
1333 if (substream->number == 0) {
1334 for (i = 0; i < mout->num_dacs; i++)
1335 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1336
1337 if (mout->hp_nid && !spec->hp_independent_mode)
1338 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1339 0, 0, 0);
1340
1341 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1342 if (mout->extra_out_nid[i])
1343 snd_hda_codec_setup_stream(codec,
1344 mout->extra_out_nid[i],
1345 0, 0, 0);
1346 mutex_lock(&codec->spdif_mutex);
1347 if (mout->dig_out_nid &&
1348 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1349 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1350 0, 0, 0);
1351 mout->dig_out_used = 0;
1352 }
1353 mutex_unlock(&codec->spdif_mutex);
1354 } else {
1355 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1356 spec->hp_independent_mode)
1357 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1358 0, 0, 0);
1359 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001360 vt1708_stop_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001361 return 0;
1362}
1363
Joseph Chanc577b8a2006-11-29 15:29:40 +01001364/*
1365 * Digital out
1366 */
1367static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1368 struct hda_codec *codec,
1369 struct snd_pcm_substream *substream)
1370{
1371 struct via_spec *spec = codec->spec;
1372 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1373}
1374
1375static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1376 struct hda_codec *codec,
1377 struct snd_pcm_substream *substream)
1378{
1379 struct via_spec *spec = codec->spec;
1380 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1381}
1382
Harald Welte5691ec72008-09-15 22:42:26 +08001383static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001384 struct hda_codec *codec,
1385 unsigned int stream_tag,
1386 unsigned int format,
1387 struct snd_pcm_substream *substream)
1388{
1389 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001390 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1391 stream_tag, format, substream);
1392}
Harald Welte5691ec72008-09-15 22:42:26 +08001393
Takashi Iwai9da29272009-05-07 16:31:14 +02001394static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1395 struct hda_codec *codec,
1396 struct snd_pcm_substream *substream)
1397{
1398 struct via_spec *spec = codec->spec;
1399 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001400 return 0;
1401}
1402
Joseph Chanc577b8a2006-11-29 15:29:40 +01001403/*
1404 * Analog capture
1405 */
1406static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1407 struct hda_codec *codec,
1408 unsigned int stream_tag,
1409 unsigned int format,
1410 struct snd_pcm_substream *substream)
1411{
1412 struct via_spec *spec = codec->spec;
1413
1414 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1415 stream_tag, 0, format);
1416 return 0;
1417}
1418
1419static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1420 struct hda_codec *codec,
1421 struct snd_pcm_substream *substream)
1422{
1423 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001424 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001425 return 0;
1426}
1427
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001428static const struct hda_pcm_stream vt1708_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001429 .substreams = 2,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001430 .channels_min = 2,
1431 .channels_max = 8,
1432 .nid = 0x10, /* NID to query formats and rates */
1433 .ops = {
1434 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001435 .prepare = via_playback_multi_pcm_prepare,
1436 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001437 },
1438};
1439
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001440static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Lydia Wangc873cc22009-10-10 19:08:21 +08001441 .substreams = 2,
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001442 .channels_min = 2,
1443 .channels_max = 8,
1444 .nid = 0x10, /* NID to query formats and rates */
1445 /* We got noisy outputs on the right channel on VT1708 when
1446 * 24bit samples are used. Until any workaround is found,
1447 * disable the 24bit format, so far.
1448 */
1449 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1450 .ops = {
1451 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08001452 .prepare = via_playback_multi_pcm_prepare,
1453 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001454 },
1455};
1456
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001457static const struct hda_pcm_stream vt1708_pcm_analog_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001458 .substreams = 2,
1459 .channels_min = 2,
1460 .channels_max = 2,
1461 .nid = 0x15, /* NID to query formats and rates */
1462 .ops = {
1463 .prepare = via_capture_pcm_prepare,
1464 .cleanup = via_capture_pcm_cleanup
1465 },
1466};
1467
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001468static const struct hda_pcm_stream vt1708_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001469 .substreams = 1,
1470 .channels_min = 2,
1471 .channels_max = 2,
1472 /* NID is set in via_build_pcms */
1473 .ops = {
1474 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001475 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001476 .prepare = via_dig_playback_pcm_prepare,
1477 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001478 },
1479};
1480
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001481static const struct hda_pcm_stream vt1708_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001482 .substreams = 1,
1483 .channels_min = 2,
1484 .channels_max = 2,
1485};
1486
1487static int via_build_controls(struct hda_codec *codec)
1488{
1489 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001490 struct snd_kcontrol *kctl;
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001491 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001492 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001493
Takashi Iwai24088a52011-06-17 16:59:21 +02001494 if (spec->set_widgets_power_state)
1495 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1496 return -ENOMEM;
1497
Joseph Chanc577b8a2006-11-29 15:29:40 +01001498 for (i = 0; i < spec->num_mixers; i++) {
1499 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1500 if (err < 0)
1501 return err;
1502 }
1503
1504 if (spec->multiout.dig_out_nid) {
1505 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001506 spec->multiout.dig_out_nid,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001507 spec->multiout.dig_out_nid);
1508 if (err < 0)
1509 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001510 err = snd_hda_create_spdif_share_sw(codec,
1511 &spec->multiout);
1512 if (err < 0)
1513 return err;
1514 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001515 }
1516 if (spec->dig_in_nid) {
1517 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1518 if (err < 0)
1519 return err;
1520 }
Lydia Wang17314372009-10-10 19:07:37 +08001521
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001522 /* assign Capture Source enums to NID */
1523 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1524 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +01001525 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001526 if (err < 0)
1527 return err;
1528 }
1529
1530 /* other nid->control mapping */
1531 for (i = 0; i < spec->num_mixers; i++) {
1532 for (knew = spec->mixers[i]; knew->name; knew++) {
1533 if (knew->iface != NID_MAPPING)
1534 continue;
1535 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1536 if (kctl == NULL)
1537 continue;
1538 err = snd_hda_add_nid(codec, kctl, 0,
1539 knew->subdevice);
1540 }
1541 }
1542
Lydia Wang17314372009-10-10 19:07:37 +08001543 /* init power states */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001544 set_widgets_power_state(codec);
Lydia Wang17314372009-10-10 19:07:37 +08001545 analog_low_current_mode(codec, 1);
1546
Takashi Iwai603c4012008-07-30 15:01:44 +02001547 via_free_kctls(codec); /* no longer needed */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001548 return 0;
1549}
1550
1551static int via_build_pcms(struct hda_codec *codec)
1552{
1553 struct via_spec *spec = codec->spec;
1554 struct hda_pcm *info = spec->pcm_rec;
1555
1556 codec->num_pcms = 1;
1557 codec->pcm_info = info;
1558
Takashi Iwai82673bc2011-06-17 16:24:21 +02001559 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1560 "%s Analog", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001561 info->name = spec->stream_name_analog;
Lydia Wang377ff312009-10-10 19:08:55 +08001562 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1563 *(spec->stream_analog_playback);
1564 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1565 spec->multiout.dac_nids[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001566 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1567 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1568
1569 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1570 spec->multiout.max_channels;
1571
1572 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1573 codec->num_pcms++;
1574 info++;
Takashi Iwai82673bc2011-06-17 16:24:21 +02001575 snprintf(spec->stream_name_digital,
1576 sizeof(spec->stream_name_digital),
1577 "%s Digital", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001578 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001579 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001580 if (spec->multiout.dig_out_nid) {
1581 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1582 *(spec->stream_digital_playback);
1583 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1584 spec->multiout.dig_out_nid;
1585 }
1586 if (spec->dig_in_nid) {
1587 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1588 *(spec->stream_digital_capture);
1589 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1590 spec->dig_in_nid;
1591 }
1592 }
1593
1594 return 0;
1595}
1596
1597static void via_free(struct hda_codec *codec)
1598{
1599 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001600
1601 if (!spec)
1602 return;
1603
Takashi Iwai603c4012008-07-30 15:01:44 +02001604 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001605 vt1708_stop_hp_work(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001606 kfree(codec->spec);
1607}
1608
Harald Welte69e52a82008-09-09 15:57:32 +08001609/* mute internal speaker if HP is plugged */
1610static void via_hp_automute(struct hda_codec *codec)
1611{
Lydia Wangdcf34c82009-10-10 19:08:15 +08001612 unsigned int present = 0;
Harald Welte69e52a82008-09-09 15:57:32 +08001613 struct via_spec *spec = codec->spec;
1614
Takashi Iwaid56757a2009-11-18 08:00:14 +01001615 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangdcf34c82009-10-10 19:08:15 +08001616
1617 if (!spec->hp_independent_mode) {
1618 struct snd_ctl_elem_id id;
1619 /* auto mute */
1620 snd_hda_codec_amp_stereo(
1621 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1622 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1623 /* notify change */
1624 memset(&id, 0, sizeof(id));
1625 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1626 strcpy(id.name, "Front Playback Switch");
1627 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1628 &id);
1629 }
Harald Welte69e52a82008-09-09 15:57:32 +08001630}
1631
Lydia Wangf3db4232009-10-10 19:08:41 +08001632/* mute mono out if HP or Line out is plugged */
1633static void via_mono_automute(struct hda_codec *codec)
1634{
1635 unsigned int hp_present, lineout_present;
1636 struct via_spec *spec = codec->spec;
1637
1638 if (spec->codec_type != VT1716S)
1639 return;
1640
Takashi Iwaid56757a2009-11-18 08:00:14 +01001641 lineout_present = snd_hda_jack_detect(codec,
1642 spec->autocfg.line_out_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001643
1644 /* Mute Mono Out if Line Out is plugged */
1645 if (lineout_present) {
1646 snd_hda_codec_amp_stereo(
1647 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1648 return;
1649 }
1650
Takashi Iwaid56757a2009-11-18 08:00:14 +01001651 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001652
1653 if (!spec->hp_independent_mode)
1654 snd_hda_codec_amp_stereo(
1655 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1656 hp_present ? HDA_AMP_MUTE : 0);
1657}
1658
Harald Welte69e52a82008-09-09 15:57:32 +08001659static void via_gpio_control(struct hda_codec *codec)
1660{
1661 unsigned int gpio_data;
1662 unsigned int vol_counter;
1663 unsigned int vol;
1664 unsigned int master_vol;
1665
1666 struct via_spec *spec = codec->spec;
1667
1668 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1669 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1670
1671 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1672 0xF84, 0) & 0x3F0000) >> 16;
1673
1674 vol = vol_counter & 0x1F;
1675 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1676 AC_VERB_GET_AMP_GAIN_MUTE,
1677 AC_AMP_GET_INPUT);
1678
1679 if (gpio_data == 0x02) {
1680 /* unmute line out */
1681 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1682 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1683
1684 if (vol_counter & 0x20) {
1685 /* decrease volume */
1686 if (vol > master_vol)
1687 vol = master_vol;
1688 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1689 0, HDA_AMP_VOLMASK,
1690 master_vol-vol);
1691 } else {
1692 /* increase volume */
1693 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1694 HDA_AMP_VOLMASK,
1695 ((master_vol+vol) > 0x2A) ? 0x2A :
1696 (master_vol+vol));
1697 }
1698 } else if (!(gpio_data & 0x02)) {
1699 /* mute line out */
1700 snd_hda_codec_amp_stereo(codec,
1701 spec->autocfg.line_out_pins[0],
1702 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1703 HDA_AMP_MUTE);
1704 }
1705}
1706
Lydia Wang25eaba22009-10-10 19:08:43 +08001707/* mute Internal-Speaker if HP is plugged */
1708static void via_speaker_automute(struct hda_codec *codec)
1709{
1710 unsigned int hp_present;
1711 struct via_spec *spec = codec->spec;
1712
Lydia Wang27439ce2011-03-24 12:40:10 +08001713 if (!VT2002P_COMPATIBLE(spec))
Lydia Wang25eaba22009-10-10 19:08:43 +08001714 return;
1715
Takashi Iwaid56757a2009-11-18 08:00:14 +01001716 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001717
1718 if (!spec->hp_independent_mode) {
1719 struct snd_ctl_elem_id id;
1720 snd_hda_codec_amp_stereo(
1721 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
1722 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1723 /* notify change */
1724 memset(&id, 0, sizeof(id));
1725 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1726 strcpy(id.name, "Speaker Playback Switch");
1727 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1728 &id);
1729 }
1730}
1731
1732/* mute line-out and internal speaker if HP is plugged */
1733static void via_hp_bind_automute(struct hda_codec *codec)
1734{
akpm@linux-foundation.org01a17962009-11-13 16:47:10 -08001735 /* use long instead of int below just to avoid an internal compiler
1736 * error with gcc 4.0.x
1737 */
1738 unsigned long hp_present, present = 0;
Lydia Wang25eaba22009-10-10 19:08:43 +08001739 struct via_spec *spec = codec->spec;
1740 int i;
1741
1742 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1743 return;
1744
Takashi Iwaid56757a2009-11-18 08:00:14 +01001745 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001746
Takashi Iwaid56757a2009-11-18 08:00:14 +01001747 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001748
1749 if (!spec->hp_independent_mode) {
1750 /* Mute Line-Outs */
1751 for (i = 0; i < spec->autocfg.line_outs; i++)
1752 snd_hda_codec_amp_stereo(
1753 codec, spec->autocfg.line_out_pins[i],
1754 HDA_OUTPUT, 0,
1755 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1756 if (hp_present)
1757 present = hp_present;
1758 }
1759 /* Speakers */
1760 for (i = 0; i < spec->autocfg.speaker_outs; i++)
1761 snd_hda_codec_amp_stereo(
1762 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
1763 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1764}
1765
1766
Harald Welte69e52a82008-09-09 15:57:32 +08001767/* unsolicited event for jack sensing */
1768static void via_unsol_event(struct hda_codec *codec,
1769 unsigned int res)
1770{
1771 res >>= 26;
Lydia Wangec7e7e42011-03-24 12:43:44 +08001772
Lydia Wanga34df192009-10-10 19:08:01 +08001773 if (res & VIA_JACK_EVENT)
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001774 set_widgets_power_state(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001775
1776 res &= ~VIA_JACK_EVENT;
1777
1778 if (res == VIA_HP_EVENT)
1779 via_hp_automute(codec);
1780 else if (res == VIA_GPIO_EVENT)
1781 via_gpio_control(codec);
1782 else if (res == VIA_MONO_EVENT)
Lydia Wangf3db4232009-10-10 19:08:41 +08001783 via_mono_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001784 else if (res == VIA_SPEAKER_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001785 via_speaker_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001786 else if (res == VIA_BIND_HP_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001787 via_hp_bind_automute(codec);
Harald Welte69e52a82008-09-09 15:57:32 +08001788}
1789
Joseph Chanc577b8a2006-11-29 15:29:40 +01001790static int via_init(struct hda_codec *codec)
1791{
1792 struct via_spec *spec = codec->spec;
Harald Welte69e52a82008-09-09 15:57:32 +08001793 int i;
1794 for (i = 0; i < spec->num_iverbs; i++)
1795 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1796
Josepch Chanf7278fd2007-12-13 16:40:40 +01001797 /* Lydia Add for EAPD enable */
1798 if (!spec->dig_in_nid) { /* No Digital In connection */
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001799 if (spec->dig_in_pin) {
1800 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001801 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +01001802 PIN_OUT);
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001803 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001804 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1805 }
Takashi Iwai12b74c82008-01-15 12:39:38 +01001806 } else /* enable SPDIF-input pin */
1807 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1808 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
Josepch Chanf7278fd2007-12-13 16:40:40 +01001809
Takashi Iwai9da29272009-05-07 16:31:14 +02001810 /* assign slave outs */
1811 if (spec->slave_dig_outs[0])
1812 codec->slave_dig_outs = spec->slave_dig_outs;
Harald Welte5691ec72008-09-15 22:42:26 +08001813
Lydia Wang377ff312009-10-10 19:08:55 +08001814 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001815}
1816
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001817#ifdef SND_HDA_NEEDS_RESUME
1818static int via_suspend(struct hda_codec *codec, pm_message_t state)
1819{
1820 struct via_spec *spec = codec->spec;
1821 vt1708_stop_hp_work(spec);
1822 return 0;
1823}
1824#endif
1825
Takashi Iwaicb53c622007-08-10 17:21:45 +02001826#ifdef CONFIG_SND_HDA_POWER_SAVE
1827static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1828{
1829 struct via_spec *spec = codec->spec;
1830 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1831}
1832#endif
1833
Joseph Chanc577b8a2006-11-29 15:29:40 +01001834/*
1835 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001836static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001837 .build_controls = via_build_controls,
1838 .build_pcms = via_build_pcms,
1839 .init = via_init,
1840 .free = via_free,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001841#ifdef SND_HDA_NEEDS_RESUME
1842 .suspend = via_suspend,
1843#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02001844#ifdef CONFIG_SND_HDA_POWER_SAVE
1845 .check_power_status = via_check_power_status,
1846#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001847};
1848
1849/* fill in the dac_nids table from the parsed pin configuration */
1850static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1851 const struct auto_pin_cfg *cfg)
1852{
1853 int i;
1854 hda_nid_t nid;
1855
1856 spec->multiout.num_dacs = cfg->line_outs;
1857
1858 spec->multiout.dac_nids = spec->private_dac_nids;
Lydia Wang377ff312009-10-10 19:08:55 +08001859
1860 for (i = 0; i < 4; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001861 nid = cfg->line_out_pins[i];
1862 if (nid) {
1863 /* config dac list */
1864 switch (i) {
1865 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02001866 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001867 break;
1868 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02001869 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001870 break;
1871 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02001872 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001873 break;
1874 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02001875 spec->private_dac_nids[i] = 0x13;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001876 break;
1877 }
1878 }
1879 }
1880
1881 return 0;
1882}
1883
1884/* add playback controls from the parsed DAC table */
1885static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1886 const struct auto_pin_cfg *cfg)
1887{
1888 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01001889 static const char * const chname[4] = {
1890 "Front", "Surround", "C/LFE", "Side"
1891 };
Lydia Wang9645c202009-10-10 19:08:27 +08001892 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
Joseph Chanc577b8a2006-11-29 15:29:40 +01001893 int i, err;
1894
1895 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1896 nid = cfg->line_out_pins[i];
1897
1898 if (!nid)
1899 continue;
Lydia Wang377ff312009-10-10 19:08:55 +08001900
Lydia Wang9645c202009-10-10 19:08:27 +08001901 nid_vol = nid_vols[i];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001902
1903 if (i == AUTO_SEQ_CENLFE) {
1904 /* Center/LFE */
1905 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001906 "Center Playback Volume",
1907 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1908 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001909 if (err < 0)
1910 return err;
1911 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1912 "LFE Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001913 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1914 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001915 if (err < 0)
1916 return err;
1917 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1918 "Center Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001919 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1920 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001921 if (err < 0)
1922 return err;
1923 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1924 "LFE Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001925 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1926 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001927 if (err < 0)
1928 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08001929 } else if (i == AUTO_SEQ_FRONT) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001930 /* add control to mixer index 0 */
1931 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1932 "Master Front Playback Volume",
Lydia Wang9645c202009-10-10 19:08:27 +08001933 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001934 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001935 if (err < 0)
1936 return err;
1937 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1938 "Master Front Playback Switch",
Lydia Wang9645c202009-10-10 19:08:27 +08001939 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001940 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001941 if (err < 0)
1942 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08001943
Joseph Chanc577b8a2006-11-29 15:29:40 +01001944 /* add control to PW3 */
1945 sprintf(name, "%s Playback Volume", chname[i]);
1946 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001947 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1948 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001949 if (err < 0)
1950 return err;
1951 sprintf(name, "%s Playback Switch", chname[i]);
1952 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001953 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1954 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001955 if (err < 0)
1956 return err;
1957 } else {
1958 sprintf(name, "%s Playback Volume", chname[i]);
1959 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001960 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1961 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001962 if (err < 0)
1963 return err;
1964 sprintf(name, "%s Playback Switch", chname[i]);
1965 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001966 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1967 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001968 if (err < 0)
1969 return err;
1970 }
1971 }
1972
1973 return 0;
1974}
1975
Harald Welte0aa62ae2008-09-09 15:58:27 +08001976static void create_hp_imux(struct via_spec *spec)
1977{
1978 int i;
1979 struct hda_input_mux *imux = &spec->private_imux[1];
Takashi Iwaiea734962011-01-17 11:29:34 +01001980 static const char * const texts[] = { "OFF", "ON", NULL};
Harald Welte0aa62ae2008-09-09 15:58:27 +08001981
1982 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02001983 for (i = 0; texts[i]; i++)
1984 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001985
1986 spec->hp_mux = &spec->private_imux[1];
1987}
1988
Joseph Chanc577b8a2006-11-29 15:29:40 +01001989static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1990{
1991 int err;
1992
1993 if (!pin)
1994 return 0;
1995
1996 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08001997 spec->hp_independent_mode_index = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001998
1999 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2000 "Headphone Playback Volume",
2001 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2002 if (err < 0)
2003 return err;
2004 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2005 "Headphone Playback Switch",
2006 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2007 if (err < 0)
2008 return err;
2009
Harald Welte0aa62ae2008-09-09 15:58:27 +08002010 create_hp_imux(spec);
2011
Joseph Chanc577b8a2006-11-29 15:29:40 +01002012 return 0;
2013}
2014
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002015static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
2016 hda_nid_t nid)
2017{
2018 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
2019 int i, nums;
2020
2021 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
2022 for (i = 0; i < nums; i++)
2023 if (conn[i] == nid)
2024 return i;
2025 return -1;
2026}
2027
2028/* look for ADCs */
2029static int via_fill_adcs(struct hda_codec *codec)
2030{
2031 struct via_spec *spec = codec->spec;
2032 hda_nid_t nid = codec->start_nid;
2033 int i;
2034
2035 for (i = 0; i < codec->num_nodes; i++, nid++) {
2036 unsigned int wcaps = get_wcaps(codec, nid);
2037 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2038 continue;
2039 if (wcaps & AC_WCAP_DIGITAL)
2040 continue;
2041 if (!(wcaps & AC_WCAP_CONN_LIST))
2042 continue;
2043 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2044 return -ENOMEM;
2045 spec->adc_nids[spec->num_adc_nids++] = nid;
2046 }
2047 return 0;
2048}
2049
2050static int get_mux_nids(struct hda_codec *codec);
2051
Joseph Chanc577b8a2006-11-29 15:29:40 +01002052/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002053static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaif3268512010-08-30 11:00:19 +02002054 const struct auto_pin_cfg *cfg,
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002055 hda_nid_t mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002056{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002057 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08002058 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002059 int i, err, idx, idx2, type, type_idx = 0;
2060 hda_nid_t cap_nid;
2061 hda_nid_t pin_idxs[8];
2062 int num_idxs;
2063
2064 err = via_fill_adcs(codec);
2065 if (err < 0)
2066 return err;
2067 err = get_mux_nids(codec);
2068 if (err < 0)
2069 return err;
2070 cap_nid = spec->mux_nids[0];
2071
2072 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
2073 ARRAY_SIZE(pin_idxs));
2074 if (num_idxs <= 0)
2075 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002076
2077 /* for internal loopback recording select */
Takashi Iwaif3268512010-08-30 11:00:19 +02002078 for (idx = 0; idx < num_idxs; idx++) {
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002079 if (pin_idxs[idx] == mix_nid) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002080 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
Takashi Iwaif3268512010-08-30 11:00:19 +02002081 break;
2082 }
2083 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002084
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002085 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002086 const char *label;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002087 type = cfg->inputs[i].type;
Takashi Iwaif3268512010-08-30 11:00:19 +02002088 for (idx = 0; idx < num_idxs; idx++)
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002089 if (pin_idxs[idx] == cfg->inputs[i].pin)
Takashi Iwaif3268512010-08-30 11:00:19 +02002090 break;
2091 if (idx >= num_idxs)
2092 continue;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002093 if (i > 0 && type == cfg->inputs[i - 1].type)
2094 type_idx++;
2095 else
2096 type_idx = 0;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002097 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002098 idx2 = get_connection_index(codec, mix_nid, pin_idxs[idx]);
2099 if (idx2 >= 0)
Lydia Wang16922282011-03-22 16:24:10 +08002100 err = via_new_analog_input(spec, label, type_idx,
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002101 idx2, mix_nid);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002102 if (err < 0)
2103 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002104 snd_hda_add_imux_item(imux, label, idx, NULL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002105 }
2106 return 0;
2107}
2108
Takashi Iwaif3268512010-08-30 11:00:19 +02002109/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002110static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaif3268512010-08-30 11:00:19 +02002111 const struct auto_pin_cfg *cfg)
2112{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002113 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17);
Takashi Iwaif3268512010-08-30 11:00:19 +02002114}
2115
Takashi Iwaicb53c622007-08-10 17:21:45 +02002116#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002117static const struct hda_amp_list vt1708_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002118 { 0x17, HDA_INPUT, 1 },
2119 { 0x17, HDA_INPUT, 2 },
2120 { 0x17, HDA_INPUT, 3 },
2121 { 0x17, HDA_INPUT, 4 },
2122 { } /* end */
2123};
2124#endif
2125
Harald Welte76d9b0d2008-09-09 15:50:37 +08002126static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2127{
2128 unsigned int def_conf;
2129 unsigned char seqassoc;
2130
Takashi Iwai2f334f92009-02-20 14:37:42 +01002131 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002132 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2133 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002134 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2135 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2136 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2137 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002138 }
2139
2140 return;
2141}
2142
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002143static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002144 struct snd_ctl_elem_value *ucontrol)
2145{
2146 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2147 struct via_spec *spec = codec->spec;
2148
2149 if (spec->codec_type != VT1708)
2150 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002151 spec->vt1708_jack_detect =
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002152 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002153 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002154 return 0;
2155}
2156
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002157static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002158 struct snd_ctl_elem_value *ucontrol)
2159{
2160 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2161 struct via_spec *spec = codec->spec;
2162 int change;
2163
2164 if (spec->codec_type != VT1708)
2165 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002166 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002167 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002168 == !spec->vt1708_jack_detect;
2169 if (spec->vt1708_jack_detect) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002170 mute_aa_path(codec, 1);
2171 notify_aa_path_ctls(codec);
2172 }
2173 return change;
2174}
2175
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002176static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2177 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2178 .name = "Jack Detect",
2179 .count = 1,
2180 .info = snd_ctl_boolean_mono_info,
2181 .get = vt1708_jack_detect_get,
2182 .put = vt1708_jack_detect_put,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002183};
2184
Joseph Chanc577b8a2006-11-29 15:29:40 +01002185static int vt1708_parse_auto_config(struct hda_codec *codec)
2186{
2187 struct via_spec *spec = codec->spec;
2188 int err;
2189
Harald Welte76d9b0d2008-09-09 15:50:37 +08002190 /* Add HP and CD pin config connect bit re-config action */
2191 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2192 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2193
Joseph Chanc577b8a2006-11-29 15:29:40 +01002194 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2195 if (err < 0)
2196 return err;
2197 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2198 if (err < 0)
2199 return err;
2200 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2201 return 0; /* can't find valid BIOS pin config */
2202
2203 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2204 if (err < 0)
2205 return err;
2206 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2207 if (err < 0)
2208 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002209 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002210 if (err < 0)
2211 return err;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002212 /* add jack detect on/off control */
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002213 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2214 return -ENOMEM;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002215
2216 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2217
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002218 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002219 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002220 spec->dig_in_pin = VT1708_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002221 if (spec->autocfg.dig_in_pin)
2222 spec->dig_in_nid = VT1708_DIGIN_NID;
2223
Takashi Iwai603c4012008-07-30 15:01:44 +02002224 if (spec->kctls.list)
2225 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002226
Harald Welte69e52a82008-09-09 15:57:32 +08002227 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002228
Harald Welte0aa62ae2008-09-09 15:58:27 +08002229 spec->input_mux = &spec->private_imux[0];
2230
Harald Weltef8fdd492008-09-15 22:41:31 +08002231 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002232 via_hp_build(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002233
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002234 via_smart51_build(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002235 return 1;
2236}
2237
2238/* init callback for auto-configuration model -- overriding the default init */
2239static int via_auto_init(struct hda_codec *codec)
2240{
Lydia Wang25eaba22009-10-10 19:08:43 +08002241 struct via_spec *spec = codec->spec;
2242
Joseph Chanc577b8a2006-11-29 15:29:40 +01002243 via_init(codec);
2244 via_auto_init_multi_out(codec);
2245 via_auto_init_hp_out(codec);
2246 via_auto_init_analog_input(codec);
Lydia Wang118909562011-03-23 17:57:34 +08002247
2248 if (VT2002P_COMPATIBLE(spec)) {
Lydia Wang25eaba22009-10-10 19:08:43 +08002249 via_hp_bind_automute(codec);
2250 } else {
2251 via_hp_automute(codec);
2252 via_speaker_automute(codec);
2253 }
2254
Joseph Chanc577b8a2006-11-29 15:29:40 +01002255 return 0;
2256}
2257
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002258static void vt1708_update_hp_jack_state(struct work_struct *work)
2259{
2260 struct via_spec *spec = container_of(work, struct via_spec,
2261 vt1708_hp_work.work);
2262 if (spec->codec_type != VT1708)
2263 return;
2264 /* if jack state toggled */
2265 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002266 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002267 spec->vt1708_hp_present ^= 1;
2268 via_hp_automute(spec->codec);
2269 }
2270 vt1708_start_hp_work(spec);
2271}
2272
Takashi Iwai337b9d02009-07-07 18:18:59 +02002273static int get_mux_nids(struct hda_codec *codec)
2274{
2275 struct via_spec *spec = codec->spec;
2276 hda_nid_t nid, conn[8];
2277 unsigned int type;
2278 int i, n;
2279
2280 for (i = 0; i < spec->num_adc_nids; i++) {
2281 nid = spec->adc_nids[i];
2282 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002283 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002284 if (type == AC_WID_PIN)
2285 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002286 n = snd_hda_get_connections(codec, nid, conn,
2287 ARRAY_SIZE(conn));
2288 if (n <= 0)
2289 break;
2290 if (n > 1) {
2291 spec->mux_nids[i] = nid;
2292 break;
2293 }
2294 nid = conn[0];
2295 }
2296 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002297 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002298}
2299
Joseph Chanc577b8a2006-11-29 15:29:40 +01002300static int patch_vt1708(struct hda_codec *codec)
2301{
2302 struct via_spec *spec;
2303 int err;
2304
2305 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002306 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002307 if (spec == NULL)
2308 return -ENOMEM;
2309
Joseph Chanc577b8a2006-11-29 15:29:40 +01002310 /* automatic parse from the BIOS config */
2311 err = vt1708_parse_auto_config(codec);
2312 if (err < 0) {
2313 via_free(codec);
2314 return err;
2315 } else if (!err) {
2316 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2317 "from BIOS. Using genenic mode...\n");
2318 }
2319
Lydia Wang377ff312009-10-10 19:08:55 +08002320
Joseph Chanc577b8a2006-11-29 15:29:40 +01002321 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
Takashi Iwaibc9b562382008-05-23 17:50:27 +02002322 /* disable 32bit format on VT1708 */
2323 if (codec->vendor_id == 0x11061708)
2324 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002325 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2326
Joseph Chanc577b8a2006-11-29 15:29:40 +01002327 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2328 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2329
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002330 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002331 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2332 spec->num_mixers++;
2333 }
2334
2335 codec->patch_ops = via_patch_ops;
2336
2337 codec->patch_ops.init = via_auto_init;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002338#ifdef CONFIG_SND_HDA_POWER_SAVE
2339 spec->loopback.amplist = vt1708_loopbacks;
2340#endif
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002341 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002342 return 0;
2343}
2344
2345/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002346static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002347 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2348 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2349 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2350 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2351 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2352 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2353 {
2354 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2355 /* The multiple "Capture Source" controls confuse alsamixer
2356 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01002357 */
2358 /* .name = "Capture Source", */
2359 .name = "Input Source",
2360 .count = 1,
2361 .info = via_mux_enum_info,
2362 .get = via_mux_enum_get,
2363 .put = via_mux_enum_put,
2364 },
2365 { } /* end */
2366};
2367
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002368static const struct hda_verb vt1709_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002369 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2370 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002371 { }
2372};
2373
Joseph Chanc577b8a2006-11-29 15:29:40 +01002374/*
2375 * generic initialization of ADC, input mixers and output mixers
2376 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002377static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002378 /*
2379 * Unmute ADC0-2 and set the default input to mic-in
2380 */
2381 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2382 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2383 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2384
2385
Josepch Chanf7278fd2007-12-13 16:40:40 +01002386 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01002387 * mixer widget
2388 */
2389 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01002390 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2391 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2392 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2393 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2394 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002395
2396 /*
2397 * Set up output selector (0x1a, 0x1b, 0x29)
2398 */
2399 /* set vol=0 to output mixers */
2400 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2401 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2402 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2403
2404 /*
2405 * Unmute PW3 and PW4
2406 */
2407 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2408 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2409
Lydia Wangbfdc6752009-10-10 19:08:50 +08002410 /* Set input of PW4 as MW0 */
2411 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002412 /* PW9 Output enable */
2413 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2414 { }
2415};
2416
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002417static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002418 .substreams = 1,
2419 .channels_min = 2,
2420 .channels_max = 10,
2421 .nid = 0x10, /* NID to query formats and rates */
2422 .ops = {
2423 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002424 .prepare = via_playback_multi_pcm_prepare,
2425 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002426 },
2427};
2428
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002429static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002430 .substreams = 1,
2431 .channels_min = 2,
2432 .channels_max = 6,
2433 .nid = 0x10, /* NID to query formats and rates */
2434 .ops = {
2435 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002436 .prepare = via_playback_multi_pcm_prepare,
2437 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002438 },
2439};
2440
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002441static const struct hda_pcm_stream vt1709_pcm_analog_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002442 .substreams = 2,
2443 .channels_min = 2,
2444 .channels_max = 2,
2445 .nid = 0x14, /* NID to query formats and rates */
2446 .ops = {
2447 .prepare = via_capture_pcm_prepare,
2448 .cleanup = via_capture_pcm_cleanup
2449 },
2450};
2451
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002452static const struct hda_pcm_stream vt1709_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002453 .substreams = 1,
2454 .channels_min = 2,
2455 .channels_max = 2,
2456 /* NID is set in via_build_pcms */
2457 .ops = {
2458 .open = via_dig_playback_pcm_open,
2459 .close = via_dig_playback_pcm_close
2460 },
2461};
2462
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002463static const struct hda_pcm_stream vt1709_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002464 .substreams = 1,
2465 .channels_min = 2,
2466 .channels_max = 2,
2467};
2468
2469static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2470 const struct auto_pin_cfg *cfg)
2471{
2472 int i;
2473 hda_nid_t nid;
2474
2475 if (cfg->line_outs == 4) /* 10 channels */
2476 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2477 else if (cfg->line_outs == 3) /* 6 channels */
2478 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2479
2480 spec->multiout.dac_nids = spec->private_dac_nids;
2481
2482 if (cfg->line_outs == 4) { /* 10 channels */
2483 for (i = 0; i < cfg->line_outs; i++) {
2484 nid = cfg->line_out_pins[i];
2485 if (nid) {
2486 /* config dac list */
2487 switch (i) {
2488 case AUTO_SEQ_FRONT:
2489 /* AOW0 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002490 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002491 break;
2492 case AUTO_SEQ_CENLFE:
2493 /* AOW2 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002494 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002495 break;
2496 case AUTO_SEQ_SURROUND:
2497 /* AOW3 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002498 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002499 break;
2500 case AUTO_SEQ_SIDE:
2501 /* AOW1 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002502 spec->private_dac_nids[i] = 0x27;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002503 break;
2504 default:
2505 break;
2506 }
2507 }
2508 }
Takashi Iwaidda14412011-05-02 11:29:30 +02002509 spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
Joseph Chanc577b8a2006-11-29 15:29:40 +01002510
2511 } else if (cfg->line_outs == 3) { /* 6 channels */
Lydia Wang377ff312009-10-10 19:08:55 +08002512 for (i = 0; i < cfg->line_outs; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002513 nid = cfg->line_out_pins[i];
2514 if (nid) {
2515 /* config dac list */
Lydia Wang377ff312009-10-10 19:08:55 +08002516 switch (i) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002517 case AUTO_SEQ_FRONT:
2518 /* AOW0 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002519 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002520 break;
2521 case AUTO_SEQ_CENLFE:
2522 /* AOW2 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002523 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002524 break;
2525 case AUTO_SEQ_SURROUND:
2526 /* AOW1 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002527 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002528 break;
2529 default:
2530 break;
2531 }
2532 }
2533 }
2534 }
2535
2536 return 0;
2537}
2538
2539/* add playback controls from the parsed DAC table */
2540static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2541 const struct auto_pin_cfg *cfg)
2542{
2543 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01002544 static const char * const chname[4] = {
2545 "Front", "Surround", "C/LFE", "Side"
2546 };
Lydia Wang4483a2f2009-10-10 19:08:29 +08002547 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
Joseph Chanc577b8a2006-11-29 15:29:40 +01002548 int i, err;
2549
2550 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2551 nid = cfg->line_out_pins[i];
2552
Lydia Wang377ff312009-10-10 19:08:55 +08002553 if (!nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002554 continue;
2555
Lydia Wang4483a2f2009-10-10 19:08:29 +08002556 nid_vol = nid_vols[i];
2557
Joseph Chanc577b8a2006-11-29 15:29:40 +01002558 if (i == AUTO_SEQ_CENLFE) {
2559 /* Center/LFE */
2560 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2561 "Center Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002562 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002563 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002564 if (err < 0)
2565 return err;
2566 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2567 "LFE Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002568 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002569 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002570 if (err < 0)
2571 return err;
2572 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2573 "Center Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002574 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002575 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002576 if (err < 0)
2577 return err;
2578 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2579 "LFE Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002580 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002581 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002582 if (err < 0)
2583 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002584 } else if (i == AUTO_SEQ_FRONT) {
Lydia Wang4483a2f2009-10-10 19:08:29 +08002585 /* ADD control to mixer index 0 */
Joseph Chanc577b8a2006-11-29 15:29:40 +01002586 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2587 "Master Front Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002588 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002589 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002590 if (err < 0)
2591 return err;
2592 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2593 "Master Front Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002594 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002595 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002596 if (err < 0)
2597 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002598
Joseph Chanc577b8a2006-11-29 15:29:40 +01002599 /* add control to PW3 */
2600 sprintf(name, "%s Playback Volume", chname[i]);
2601 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002602 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2603 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002604 if (err < 0)
2605 return err;
2606 sprintf(name, "%s Playback Switch", chname[i]);
2607 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002608 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2609 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002610 if (err < 0)
2611 return err;
2612 } else if (i == AUTO_SEQ_SURROUND) {
2613 sprintf(name, "%s Playback Volume", chname[i]);
2614 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002615 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002616 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002617 if (err < 0)
2618 return err;
2619 sprintf(name, "%s Playback Switch", chname[i]);
2620 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002621 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002622 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002623 if (err < 0)
2624 return err;
2625 } else if (i == AUTO_SEQ_SIDE) {
2626 sprintf(name, "%s Playback Volume", chname[i]);
2627 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002628 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002629 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002630 if (err < 0)
2631 return err;
2632 sprintf(name, "%s Playback Switch", chname[i]);
2633 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002634 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002635 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002636 if (err < 0)
2637 return err;
2638 }
2639 }
2640
2641 return 0;
2642}
2643
2644static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2645{
2646 int err;
2647
2648 if (!pin)
2649 return 0;
2650
2651 if (spec->multiout.num_dacs == 5) /* 10 channels */
2652 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2653 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2654 spec->multiout.hp_nid = 0;
Lydia Wangcdc17842009-10-10 19:07:47 +08002655 spec->hp_independent_mode_index = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002656
2657 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2658 "Headphone Playback Volume",
2659 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2660 if (err < 0)
2661 return err;
2662 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2663 "Headphone Playback Switch",
2664 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2665 if (err < 0)
2666 return err;
2667
2668 return 0;
2669}
2670
2671/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002672static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002673 const struct auto_pin_cfg *cfg)
2674{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002675 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002676}
2677
2678static int vt1709_parse_auto_config(struct hda_codec *codec)
2679{
2680 struct via_spec *spec = codec->spec;
2681 int err;
2682
2683 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2684 if (err < 0)
2685 return err;
2686 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2687 if (err < 0)
2688 return err;
2689 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2690 return 0; /* can't find valid BIOS pin config */
2691
2692 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2693 if (err < 0)
2694 return err;
2695 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2696 if (err < 0)
2697 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002698 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002699 if (err < 0)
2700 return err;
2701
2702 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2703
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002704 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002705 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002706 spec->dig_in_pin = VT1709_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002707 if (spec->autocfg.dig_in_pin)
2708 spec->dig_in_nid = VT1709_DIGIN_NID;
2709
Takashi Iwai603c4012008-07-30 15:01:44 +02002710 if (spec->kctls.list)
2711 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002712
Harald Welte0aa62ae2008-09-09 15:58:27 +08002713 spec->input_mux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01002714
Harald Weltef8fdd492008-09-15 22:41:31 +08002715 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002716 via_hp_build(codec);
Harald Weltef8fdd492008-09-15 22:41:31 +08002717
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002718 via_smart51_build(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002719 return 1;
2720}
2721
Takashi Iwaicb53c622007-08-10 17:21:45 +02002722#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002723static const struct hda_amp_list vt1709_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002724 { 0x18, HDA_INPUT, 1 },
2725 { 0x18, HDA_INPUT, 2 },
2726 { 0x18, HDA_INPUT, 3 },
2727 { 0x18, HDA_INPUT, 4 },
2728 { } /* end */
2729};
2730#endif
2731
Joseph Chanc577b8a2006-11-29 15:29:40 +01002732static int patch_vt1709_10ch(struct hda_codec *codec)
2733{
2734 struct via_spec *spec;
2735 int err;
2736
2737 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002738 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002739 if (spec == NULL)
2740 return -ENOMEM;
2741
Joseph Chanc577b8a2006-11-29 15:29:40 +01002742 err = vt1709_parse_auto_config(codec);
2743 if (err < 0) {
2744 via_free(codec);
2745 return err;
2746 } else if (!err) {
2747 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2748 "Using genenic mode...\n");
2749 }
2750
Harald Welte69e52a82008-09-09 15:57:32 +08002751 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2752 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002753
Joseph Chanc577b8a2006-11-29 15:29:40 +01002754 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2755 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2756
Joseph Chanc577b8a2006-11-29 15:29:40 +01002757 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2758 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2759
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002760 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002761 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2762 spec->num_mixers++;
2763 }
2764
2765 codec->patch_ops = via_patch_ops;
2766
2767 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002768 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002769#ifdef CONFIG_SND_HDA_POWER_SAVE
2770 spec->loopback.amplist = vt1709_loopbacks;
2771#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002772
2773 return 0;
2774}
2775/*
2776 * generic initialization of ADC, input mixers and output mixers
2777 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002778static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002779 /*
2780 * Unmute ADC0-2 and set the default input to mic-in
2781 */
2782 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2783 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2784 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2785
2786
2787 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2788 * mixer widget
2789 */
2790 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2791 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2792 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2793 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2794 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2795 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2796
2797 /*
2798 * Set up output selector (0x1a, 0x1b, 0x29)
2799 */
2800 /* set vol=0 to output mixers */
2801 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2802 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2803 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2804
2805 /*
2806 * Unmute PW3 and PW4
2807 */
2808 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2809 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2810
2811 /* Set input of PW4 as MW0 */
2812 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002813 /* PW9 Output enable */
2814 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2815 { }
2816};
2817
2818static int patch_vt1709_6ch(struct hda_codec *codec)
2819{
2820 struct via_spec *spec;
2821 int err;
2822
2823 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002824 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002825 if (spec == NULL)
2826 return -ENOMEM;
2827
Joseph Chanc577b8a2006-11-29 15:29:40 +01002828 err = vt1709_parse_auto_config(codec);
2829 if (err < 0) {
2830 via_free(codec);
2831 return err;
2832 } else if (!err) {
2833 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2834 "Using genenic mode...\n");
2835 }
2836
Harald Welte69e52a82008-09-09 15:57:32 +08002837 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2838 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002839
Joseph Chanc577b8a2006-11-29 15:29:40 +01002840 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2841 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2842
Joseph Chanc577b8a2006-11-29 15:29:40 +01002843 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2844 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2845
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002846 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002847 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2848 spec->num_mixers++;
2849 }
2850
2851 codec->patch_ops = via_patch_ops;
2852
2853 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002854 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002855#ifdef CONFIG_SND_HDA_POWER_SAVE
2856 spec->loopback.amplist = vt1709_loopbacks;
2857#endif
Josepch Chanf7278fd2007-12-13 16:40:40 +01002858 return 0;
2859}
2860
2861/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002862static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002863 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2864 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2865 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2866 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2867 {
2868 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2869 /* The multiple "Capture Source" controls confuse alsamixer
2870 * So call somewhat different..
Josepch Chanf7278fd2007-12-13 16:40:40 +01002871 */
2872 /* .name = "Capture Source", */
2873 .name = "Input Source",
2874 .count = 1,
2875 .info = via_mux_enum_info,
2876 .get = via_mux_enum_get,
2877 .put = via_mux_enum_put,
2878 },
2879 { } /* end */
2880};
2881/*
2882 * generic initialization of ADC, input mixers and output mixers
2883 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002884static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002885 /*
2886 * Unmute ADC0-1 and set the default input to mic-in
2887 */
2888 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2889 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2890
2891
2892 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2893 * mixer widget
2894 */
2895 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2896 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2897 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2898 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2899 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2900 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2901
2902 /*
2903 * Set up output mixers
2904 */
2905 /* set vol=0 to output mixers */
2906 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2907 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2908 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2909
2910 /* Setup default input to PW4 */
Lydia Wangbfdc6752009-10-10 19:08:50 +08002911 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
Josepch Chanf7278fd2007-12-13 16:40:40 +01002912 /* PW9 Output enable */
2913 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2914 /* PW10 Input enable */
2915 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2916 { }
2917};
2918
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002919static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002920 /*
2921 * Unmute ADC0-1 and set the default input to mic-in
2922 */
2923 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2924 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2925
2926
2927 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2928 * mixer widget
2929 */
2930 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2931 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2932 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2933 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2934 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2935 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2936
2937 /*
2938 * Set up output mixers
2939 */
2940 /* set vol=0 to output mixers */
2941 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2942 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2943 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2944
2945 /* Setup default input of PW4 to MW0 */
2946 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2947 /* PW9 Output enable */
2948 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2949 /* PW10 Input enable */
2950 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2951 { }
2952};
2953
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002954static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002955 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2956 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2957 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2958 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2959 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2960 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2961 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2962 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2963 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002964 { }
2965};
2966
Lydia Wang17314372009-10-10 19:07:37 +08002967static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2968 struct hda_codec *codec,
2969 struct snd_pcm_substream *substream)
2970{
2971 int idle = substream->pstr->substream_opened == 1
2972 && substream->ref_count == 0;
2973
2974 analog_low_current_mode(codec, idle);
2975 return 0;
2976}
2977
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002978static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002979 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002980 .channels_min = 2,
2981 .channels_max = 8,
2982 .nid = 0x10, /* NID to query formats and rates */
2983 .ops = {
2984 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002985 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08002986 .cleanup = via_playback_multi_pcm_cleanup,
2987 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01002988 },
2989};
2990
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002991static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002992 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002993 .channels_min = 2,
2994 .channels_max = 4,
2995 .nid = 0x10, /* NID to query formats and rates */
2996 .ops = {
2997 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002998 .prepare = via_playback_multi_pcm_prepare,
2999 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01003000 },
3001};
3002
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003003static const struct hda_pcm_stream vt1708B_pcm_analog_capture = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003004 .substreams = 2,
3005 .channels_min = 2,
3006 .channels_max = 2,
3007 .nid = 0x13, /* NID to query formats and rates */
3008 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003009 .open = via_pcm_open_close,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003010 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003011 .cleanup = via_capture_pcm_cleanup,
3012 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01003013 },
3014};
3015
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003016static const struct hda_pcm_stream vt1708B_pcm_digital_playback = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003017 .substreams = 1,
3018 .channels_min = 2,
3019 .channels_max = 2,
3020 /* NID is set in via_build_pcms */
3021 .ops = {
3022 .open = via_dig_playback_pcm_open,
3023 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003024 .prepare = via_dig_playback_pcm_prepare,
3025 .cleanup = via_dig_playback_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01003026 },
3027};
3028
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003029static const struct hda_pcm_stream vt1708B_pcm_digital_capture = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003030 .substreams = 1,
3031 .channels_min = 2,
3032 .channels_max = 2,
3033};
3034
3035/* fill in the dac_nids table from the parsed pin configuration */
3036static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3037 const struct auto_pin_cfg *cfg)
3038{
3039 int i;
3040 hda_nid_t nid;
3041
3042 spec->multiout.num_dacs = cfg->line_outs;
3043
3044 spec->multiout.dac_nids = spec->private_dac_nids;
3045
3046 for (i = 0; i < 4; i++) {
3047 nid = cfg->line_out_pins[i];
3048 if (nid) {
3049 /* config dac list */
3050 switch (i) {
3051 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02003052 spec->private_dac_nids[i] = 0x10;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003053 break;
3054 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003055 spec->private_dac_nids[i] = 0x24;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003056 break;
3057 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02003058 spec->private_dac_nids[i] = 0x11;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003059 break;
3060 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003061 spec->private_dac_nids[i] = 0x25;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003062 break;
3063 }
3064 }
3065 }
3066
3067 return 0;
3068}
3069
3070/* add playback controls from the parsed DAC table */
3071static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3072 const struct auto_pin_cfg *cfg)
3073{
3074 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01003075 static const char * const chname[4] = {
3076 "Front", "Surround", "C/LFE", "Side"
3077 };
Harald Weltefb4cb772008-09-09 15:53:36 +08003078 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
Josepch Chanf7278fd2007-12-13 16:40:40 +01003079 hda_nid_t nid, nid_vol = 0;
3080 int i, err;
3081
3082 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3083 nid = cfg->line_out_pins[i];
3084
3085 if (!nid)
3086 continue;
3087
3088 nid_vol = nid_vols[i];
3089
3090 if (i == AUTO_SEQ_CENLFE) {
3091 /* Center/LFE */
3092 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3093 "Center Playback Volume",
3094 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3095 HDA_OUTPUT));
3096 if (err < 0)
3097 return err;
3098 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3099 "LFE Playback Volume",
3100 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3101 HDA_OUTPUT));
3102 if (err < 0)
3103 return err;
3104 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3105 "Center Playback Switch",
3106 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3107 HDA_OUTPUT));
3108 if (err < 0)
3109 return err;
3110 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3111 "LFE Playback Switch",
3112 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3113 HDA_OUTPUT));
3114 if (err < 0)
3115 return err;
3116 } else if (i == AUTO_SEQ_FRONT) {
3117 /* add control to mixer index 0 */
3118 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3119 "Master Front Playback Volume",
3120 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3121 HDA_INPUT));
3122 if (err < 0)
3123 return err;
3124 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3125 "Master Front Playback Switch",
3126 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3127 HDA_INPUT));
3128 if (err < 0)
3129 return err;
3130
3131 /* add control to PW3 */
3132 sprintf(name, "%s Playback Volume", chname[i]);
3133 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3134 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3135 HDA_OUTPUT));
3136 if (err < 0)
3137 return err;
3138 sprintf(name, "%s Playback Switch", chname[i]);
3139 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3140 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3141 HDA_OUTPUT));
3142 if (err < 0)
3143 return err;
3144 } else {
3145 sprintf(name, "%s Playback Volume", chname[i]);
3146 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3147 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3148 HDA_OUTPUT));
3149 if (err < 0)
3150 return err;
3151 sprintf(name, "%s Playback Switch", chname[i]);
3152 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3153 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3154 HDA_OUTPUT));
3155 if (err < 0)
3156 return err;
3157 }
3158 }
3159
3160 return 0;
3161}
3162
3163static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3164{
3165 int err;
3166
3167 if (!pin)
3168 return 0;
3169
3170 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08003171 spec->hp_independent_mode_index = 1;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003172
3173 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3174 "Headphone Playback Volume",
3175 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3176 if (err < 0)
3177 return err;
3178 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3179 "Headphone Playback Switch",
3180 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3181 if (err < 0)
3182 return err;
3183
Harald Welte0aa62ae2008-09-09 15:58:27 +08003184 create_hp_imux(spec);
3185
Josepch Chanf7278fd2007-12-13 16:40:40 +01003186 return 0;
3187}
3188
3189/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003190static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003191 const struct auto_pin_cfg *cfg)
3192{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003193 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003194}
3195
3196static int vt1708B_parse_auto_config(struct hda_codec *codec)
3197{
3198 struct via_spec *spec = codec->spec;
3199 int err;
3200
3201 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3202 if (err < 0)
3203 return err;
3204 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3205 if (err < 0)
3206 return err;
3207 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3208 return 0; /* can't find valid BIOS pin config */
3209
3210 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3211 if (err < 0)
3212 return err;
3213 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3214 if (err < 0)
3215 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003216 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003217 if (err < 0)
3218 return err;
3219
3220 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3221
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003222 if (spec->autocfg.dig_outs)
Josepch Chanf7278fd2007-12-13 16:40:40 +01003223 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02003224 spec->dig_in_pin = VT1708B_DIGIN_PIN;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003225 if (spec->autocfg.dig_in_pin)
3226 spec->dig_in_nid = VT1708B_DIGIN_NID;
3227
Takashi Iwai603c4012008-07-30 15:01:44 +02003228 if (spec->kctls.list)
3229 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003230
Harald Welte0aa62ae2008-09-09 15:58:27 +08003231 spec->input_mux = &spec->private_imux[0];
3232
Harald Weltef8fdd492008-09-15 22:41:31 +08003233 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003234 via_hp_build(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003235
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003236 via_smart51_build(spec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003237 return 1;
3238}
3239
3240#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003241static const struct hda_amp_list vt1708B_loopbacks[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003242 { 0x16, HDA_INPUT, 1 },
3243 { 0x16, HDA_INPUT, 2 },
3244 { 0x16, HDA_INPUT, 3 },
3245 { 0x16, HDA_INPUT, 4 },
3246 { } /* end */
3247};
3248#endif
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003249
3250static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3251{
3252 struct via_spec *spec = codec->spec;
3253 int imux_is_smixer;
3254 unsigned int parm;
3255 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +08003256 if ((spec->codec_type != VT1708B_4CH) &&
3257 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003258 is_8ch = 1;
3259
3260 /* SW0 (17h) = stereo mixer */
3261 imux_is_smixer =
3262 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3263 == ((spec->codec_type == VT1708S) ? 5 : 0));
3264 /* inputs */
3265 /* PW 1/2/5 (1ah/1bh/1eh) */
3266 parm = AC_PWRST_D3;
3267 set_pin_power_state(codec, 0x1a, &parm);
3268 set_pin_power_state(codec, 0x1b, &parm);
3269 set_pin_power_state(codec, 0x1e, &parm);
3270 if (imux_is_smixer)
3271 parm = AC_PWRST_D0;
3272 /* SW0 (17h), AIW 0/1 (13h/14h) */
3273 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3274 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3275 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3276
3277 /* outputs */
3278 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3279 parm = AC_PWRST_D3;
3280 set_pin_power_state(codec, 0x19, &parm);
3281 if (spec->smart51_enabled)
3282 set_pin_power_state(codec, 0x1b, &parm);
3283 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3284 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3285
3286 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3287 if (is_8ch) {
3288 parm = AC_PWRST_D3;
3289 set_pin_power_state(codec, 0x22, &parm);
3290 if (spec->smart51_enabled)
3291 set_pin_power_state(codec, 0x1a, &parm);
3292 snd_hda_codec_write(codec, 0x26, 0,
3293 AC_VERB_SET_POWER_STATE, parm);
3294 snd_hda_codec_write(codec, 0x24, 0,
3295 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08003296 } else if (codec->vendor_id == 0x11064397) {
3297 /* PW7(23h), SW2(27h), AOW2(25h) */
3298 parm = AC_PWRST_D3;
3299 set_pin_power_state(codec, 0x23, &parm);
3300 if (spec->smart51_enabled)
3301 set_pin_power_state(codec, 0x1a, &parm);
3302 snd_hda_codec_write(codec, 0x27, 0,
3303 AC_VERB_SET_POWER_STATE, parm);
3304 snd_hda_codec_write(codec, 0x25, 0,
3305 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003306 }
3307
3308 /* PW 3/4/7 (1ch/1dh/23h) */
3309 parm = AC_PWRST_D3;
3310 /* force to D0 for internal Speaker */
3311 set_pin_power_state(codec, 0x1c, &parm);
3312 set_pin_power_state(codec, 0x1d, &parm);
3313 if (is_8ch)
3314 set_pin_power_state(codec, 0x23, &parm);
3315
3316 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3317 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3318 imux_is_smixer ? AC_PWRST_D0 : parm);
3319 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3320 if (is_8ch) {
3321 snd_hda_codec_write(codec, 0x25, 0,
3322 AC_VERB_SET_POWER_STATE, parm);
3323 snd_hda_codec_write(codec, 0x27, 0,
3324 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08003325 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3326 snd_hda_codec_write(codec, 0x25, 0,
3327 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003328}
3329
Lydia Wang518bf3b2009-10-10 19:07:29 +08003330static int patch_vt1708S(struct hda_codec *codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003331static int patch_vt1708B_8ch(struct hda_codec *codec)
3332{
3333 struct via_spec *spec;
3334 int err;
3335
Lydia Wang518bf3b2009-10-10 19:07:29 +08003336 if (get_codec_type(codec) == VT1708BCE)
3337 return patch_vt1708S(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003338 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003339 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003340 if (spec == NULL)
3341 return -ENOMEM;
3342
Josepch Chanf7278fd2007-12-13 16:40:40 +01003343 /* automatic parse from the BIOS config */
3344 err = vt1708B_parse_auto_config(codec);
3345 if (err < 0) {
3346 via_free(codec);
3347 return err;
3348 } else if (!err) {
3349 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3350 "from BIOS. Using genenic mode...\n");
3351 }
3352
Harald Welte69e52a82008-09-09 15:57:32 +08003353 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3354 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003355
Josepch Chanf7278fd2007-12-13 16:40:40 +01003356 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3357 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3358
Josepch Chanf7278fd2007-12-13 16:40:40 +01003359 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3360 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3361
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003362 if (spec->adc_nids && spec->input_mux) {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003363 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3364 spec->num_mixers++;
3365 }
3366
3367 codec->patch_ops = via_patch_ops;
3368
3369 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003370 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003371#ifdef CONFIG_SND_HDA_POWER_SAVE
3372 spec->loopback.amplist = vt1708B_loopbacks;
3373#endif
3374
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003375 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3376
Josepch Chanf7278fd2007-12-13 16:40:40 +01003377 return 0;
3378}
3379
3380static int patch_vt1708B_4ch(struct hda_codec *codec)
3381{
3382 struct via_spec *spec;
3383 int err;
3384
3385 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003386 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003387 if (spec == NULL)
3388 return -ENOMEM;
3389
Josepch Chanf7278fd2007-12-13 16:40:40 +01003390 /* automatic parse from the BIOS config */
3391 err = vt1708B_parse_auto_config(codec);
3392 if (err < 0) {
3393 via_free(codec);
3394 return err;
3395 } else if (!err) {
3396 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3397 "from BIOS. Using genenic mode...\n");
3398 }
3399
Harald Welte69e52a82008-09-09 15:57:32 +08003400 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3401 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003402
Josepch Chanf7278fd2007-12-13 16:40:40 +01003403 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3404 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3405
Josepch Chanf7278fd2007-12-13 16:40:40 +01003406 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3407 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3408
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003409 if (spec->adc_nids && spec->input_mux) {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003410 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3411 spec->num_mixers++;
3412 }
3413
3414 codec->patch_ops = via_patch_ops;
3415
3416 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003417 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003418#ifdef CONFIG_SND_HDA_POWER_SAVE
3419 spec->loopback.amplist = vt1708B_loopbacks;
3420#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01003421
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003422 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3423
Joseph Chanc577b8a2006-11-29 15:29:40 +01003424 return 0;
3425}
3426
Harald Welted949cac2008-09-09 15:56:01 +08003427/* Patch for VT1708S */
3428
3429/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003430static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003431 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3432 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3433 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3434 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
Lydia Wang6369bcf2009-10-10 19:08:31 +08003435 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3436 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3437 HDA_INPUT),
Harald Welted949cac2008-09-09 15:56:01 +08003438 {
3439 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3440 /* The multiple "Capture Source" controls confuse alsamixer
3441 * So call somewhat different..
3442 */
3443 /* .name = "Capture Source", */
3444 .name = "Input Source",
3445 .count = 1,
3446 .info = via_mux_enum_info,
3447 .get = via_mux_enum_get,
3448 .put = via_mux_enum_put,
3449 },
3450 { } /* end */
3451};
3452
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003453static const struct hda_verb vt1708S_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003454 /* Unmute ADC0-1 and set the default input to mic-in */
3455 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3456 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3457
3458 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3459 * analog-loopback mixer widget */
3460 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3461 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3462 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3463 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3464 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3465 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3466
3467 /* Setup default input of PW4 to MW0 */
3468 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
Harald Welte5691ec72008-09-15 22:42:26 +08003469 /* PW9, PW10 Output enable */
Harald Welted949cac2008-09-09 15:56:01 +08003470 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welte5691ec72008-09-15 22:42:26 +08003471 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welted7426322008-09-15 22:43:23 +08003472 /* Enable Mic Boost Volume backdoor */
3473 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003474 /* don't bybass mixer */
3475 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08003476 { }
3477};
3478
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003479static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003480 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3481 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3482 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3483 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3484 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3485 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3486 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3487 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3488 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003489 { }
3490};
3491
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003492static const struct hda_verb vt1705_uniwill_init_verbs[] = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003493 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3494 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3495 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3496 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3497 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3498 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3499 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3500 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3501 { }
3502};
3503
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003504static const struct hda_pcm_stream vt1708S_pcm_analog_playback = {
Harald Welted949cac2008-09-09 15:56:01 +08003505 .substreams = 2,
3506 .channels_min = 2,
3507 .channels_max = 8,
3508 .nid = 0x10, /* NID to query formats and rates */
3509 .ops = {
3510 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08003511 .prepare = via_playback_multi_pcm_prepare,
3512 .cleanup = via_playback_multi_pcm_cleanup,
Lydia Wang17314372009-10-10 19:07:37 +08003513 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003514 },
3515};
3516
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003517static const struct hda_pcm_stream vt1705_pcm_analog_playback = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003518 .substreams = 2,
3519 .channels_min = 2,
3520 .channels_max = 6,
3521 .nid = 0x10, /* NID to query formats and rates */
3522 .ops = {
3523 .open = via_playback_pcm_open,
3524 .prepare = via_playback_multi_pcm_prepare,
3525 .cleanup = via_playback_multi_pcm_cleanup,
3526 .close = via_pcm_open_close
3527 },
3528};
3529
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003530static const struct hda_pcm_stream vt1708S_pcm_analog_capture = {
Harald Welted949cac2008-09-09 15:56:01 +08003531 .substreams = 2,
3532 .channels_min = 2,
3533 .channels_max = 2,
3534 .nid = 0x13, /* NID to query formats and rates */
3535 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003536 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08003537 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003538 .cleanup = via_capture_pcm_cleanup,
3539 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003540 },
3541};
3542
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003543static const struct hda_pcm_stream vt1708S_pcm_digital_playback = {
Takashi Iwai9da29272009-05-07 16:31:14 +02003544 .substreams = 1,
Harald Welted949cac2008-09-09 15:56:01 +08003545 .channels_min = 2,
3546 .channels_max = 2,
3547 /* NID is set in via_build_pcms */
3548 .ops = {
3549 .open = via_dig_playback_pcm_open,
3550 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003551 .prepare = via_dig_playback_pcm_prepare,
3552 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08003553 },
3554};
3555
3556/* fill in the dac_nids table from the parsed pin configuration */
3557static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3558 const struct auto_pin_cfg *cfg)
3559{
3560 int i;
3561 hda_nid_t nid;
3562
3563 spec->multiout.num_dacs = cfg->line_outs;
3564
3565 spec->multiout.dac_nids = spec->private_dac_nids;
3566
3567 for (i = 0; i < 4; i++) {
3568 nid = cfg->line_out_pins[i];
3569 if (nid) {
3570 /* config dac list */
3571 switch (i) {
3572 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02003573 spec->private_dac_nids[i] = 0x10;
Harald Welted949cac2008-09-09 15:56:01 +08003574 break;
3575 case AUTO_SEQ_CENLFE:
Lydia Wangbc92df72011-03-23 17:56:05 +08003576 if (spec->codec->vendor_id == 0x11064397)
Takashi Iwaidda14412011-05-02 11:29:30 +02003577 spec->private_dac_nids[i] = 0x25;
Lydia Wangbc92df72011-03-23 17:56:05 +08003578 else
Takashi Iwaidda14412011-05-02 11:29:30 +02003579 spec->private_dac_nids[i] = 0x24;
Harald Welted949cac2008-09-09 15:56:01 +08003580 break;
3581 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02003582 spec->private_dac_nids[i] = 0x11;
Harald Welted949cac2008-09-09 15:56:01 +08003583 break;
3584 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003585 spec->private_dac_nids[i] = 0x25;
Harald Welted949cac2008-09-09 15:56:01 +08003586 break;
3587 }
3588 }
3589 }
3590
Clemens Ladisch32e01912010-07-12 16:28:50 +02003591 /* for Smart 5.1, line/mic inputs double as output pins */
3592 if (cfg->line_outs == 1) {
3593 spec->multiout.num_dacs = 3;
Takashi Iwaidda14412011-05-02 11:29:30 +02003594 spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11;
Lydia Wangbc92df72011-03-23 17:56:05 +08003595 if (spec->codec->vendor_id == 0x11064397)
Takashi Iwaidda14412011-05-02 11:29:30 +02003596 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25;
Lydia Wangbc92df72011-03-23 17:56:05 +08003597 else
Takashi Iwaidda14412011-05-02 11:29:30 +02003598 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24;
Clemens Ladisch32e01912010-07-12 16:28:50 +02003599 }
3600
Harald Welted949cac2008-09-09 15:56:01 +08003601 return 0;
3602}
3603
3604/* add playback controls from the parsed DAC table */
Lydia Wangbc92df72011-03-23 17:56:05 +08003605static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08003606 const struct auto_pin_cfg *cfg)
3607{
Lydia Wangbc92df72011-03-23 17:56:05 +08003608 struct via_spec *spec = codec->spec;
Harald Welted949cac2008-09-09 15:56:01 +08003609 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01003610 static const char * const chname[4] = {
3611 "Front", "Surround", "C/LFE", "Side"
3612 };
Lydia Wangbc92df72011-03-23 17:56:05 +08003613 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3614 {0x10, 0x11, 0x25, 0} };
3615 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3616 {0x1C, 0x18, 0x27, 0} };
Harald Welted949cac2008-09-09 15:56:01 +08003617 hda_nid_t nid, nid_vol, nid_mute;
3618 int i, err;
3619
3620 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3621 nid = cfg->line_out_pins[i];
3622
Clemens Ladisch32e01912010-07-12 16:28:50 +02003623 /* for Smart 5.1, there are always at least six channels */
3624 if (!nid && i > AUTO_SEQ_CENLFE)
Harald Welted949cac2008-09-09 15:56:01 +08003625 continue;
3626
Lydia Wangbc92df72011-03-23 17:56:05 +08003627 if (codec->vendor_id == 0x11064397) {
3628 nid_vol = nid_vols[1][i];
3629 nid_mute = nid_mutes[1][i];
3630 } else {
3631 nid_vol = nid_vols[0][i];
3632 nid_mute = nid_mutes[0][i];
3633 }
3634 if (!nid_vol && !nid_mute)
3635 continue;
Harald Welted949cac2008-09-09 15:56:01 +08003636
3637 if (i == AUTO_SEQ_CENLFE) {
3638 /* Center/LFE */
3639 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3640 "Center Playback Volume",
3641 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3642 HDA_OUTPUT));
3643 if (err < 0)
3644 return err;
3645 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3646 "LFE Playback Volume",
3647 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3648 HDA_OUTPUT));
3649 if (err < 0)
3650 return err;
3651 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3652 "Center Playback Switch",
3653 HDA_COMPOSE_AMP_VAL(nid_mute,
3654 1, 0,
3655 HDA_OUTPUT));
3656 if (err < 0)
3657 return err;
3658 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3659 "LFE Playback Switch",
3660 HDA_COMPOSE_AMP_VAL(nid_mute,
3661 2, 0,
3662 HDA_OUTPUT));
3663 if (err < 0)
3664 return err;
3665 } else if (i == AUTO_SEQ_FRONT) {
3666 /* add control to mixer index 0 */
3667 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3668 "Master Front Playback Volume",
3669 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3670 HDA_INPUT));
3671 if (err < 0)
3672 return err;
3673 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3674 "Master Front Playback Switch",
3675 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3676 HDA_INPUT));
3677 if (err < 0)
3678 return err;
3679
3680 /* Front */
3681 sprintf(name, "%s Playback Volume", chname[i]);
3682 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3683 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3684 HDA_OUTPUT));
3685 if (err < 0)
3686 return err;
3687 sprintf(name, "%s Playback Switch", chname[i]);
3688 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3689 HDA_COMPOSE_AMP_VAL(nid_mute,
3690 3, 0,
3691 HDA_OUTPUT));
3692 if (err < 0)
3693 return err;
3694 } else {
3695 sprintf(name, "%s Playback Volume", chname[i]);
3696 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3697 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3698 HDA_OUTPUT));
3699 if (err < 0)
3700 return err;
3701 sprintf(name, "%s Playback Switch", chname[i]);
3702 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3703 HDA_COMPOSE_AMP_VAL(nid_mute,
3704 3, 0,
3705 HDA_OUTPUT));
3706 if (err < 0)
3707 return err;
3708 }
3709 }
3710
3711 return 0;
3712}
3713
3714static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3715{
3716 int err;
3717
3718 if (!pin)
3719 return 0;
3720
3721 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08003722 spec->hp_independent_mode_index = 1;
Harald Welted949cac2008-09-09 15:56:01 +08003723
3724 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3725 "Headphone Playback Volume",
3726 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3727 if (err < 0)
3728 return err;
3729
3730 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3731 "Headphone Playback Switch",
3732 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3733 if (err < 0)
3734 return err;
3735
Harald Welte0aa62ae2008-09-09 15:58:27 +08003736 create_hp_imux(spec);
3737
Harald Welted949cac2008-09-09 15:56:01 +08003738 return 0;
3739}
3740
3741/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003742static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08003743 const struct auto_pin_cfg *cfg)
3744{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003745 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
Harald Welted949cac2008-09-09 15:56:01 +08003746}
3747
Takashi Iwai9da29272009-05-07 16:31:14 +02003748/* fill out digital output widgets; one for master and one for slave outputs */
3749static void fill_dig_outs(struct hda_codec *codec)
3750{
3751 struct via_spec *spec = codec->spec;
3752 int i;
3753
3754 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3755 hda_nid_t nid;
3756 int conn;
3757
3758 nid = spec->autocfg.dig_out_pins[i];
3759 if (!nid)
3760 continue;
3761 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3762 if (conn < 1)
3763 continue;
3764 if (!spec->multiout.dig_out_nid)
3765 spec->multiout.dig_out_nid = nid;
3766 else {
3767 spec->slave_dig_outs[0] = nid;
3768 break; /* at most two dig outs */
3769 }
3770 }
3771}
3772
Harald Welted949cac2008-09-09 15:56:01 +08003773static int vt1708S_parse_auto_config(struct hda_codec *codec)
3774{
3775 struct via_spec *spec = codec->spec;
3776 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003777
Takashi Iwai9da29272009-05-07 16:31:14 +02003778 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08003779 if (err < 0)
3780 return err;
3781 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3782 if (err < 0)
3783 return err;
3784 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3785 return 0; /* can't find valid BIOS pin config */
3786
Lydia Wangbc92df72011-03-23 17:56:05 +08003787 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003788 if (err < 0)
3789 return err;
3790 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3791 if (err < 0)
3792 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003793 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003794 if (err < 0)
3795 return err;
3796
3797 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3798
Takashi Iwai9da29272009-05-07 16:31:14 +02003799 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08003800
Takashi Iwai603c4012008-07-30 15:01:44 +02003801 if (spec->kctls.list)
3802 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08003803
Harald Welte0aa62ae2008-09-09 15:58:27 +08003804 spec->input_mux = &spec->private_imux[0];
3805
Harald Weltef8fdd492008-09-15 22:41:31 +08003806 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003807 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003808
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003809 via_smart51_build(spec);
Harald Welted949cac2008-09-09 15:56:01 +08003810 return 1;
3811}
3812
3813#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003814static const struct hda_amp_list vt1708S_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003815 { 0x16, HDA_INPUT, 1 },
3816 { 0x16, HDA_INPUT, 2 },
3817 { 0x16, HDA_INPUT, 3 },
3818 { 0x16, HDA_INPUT, 4 },
3819 { } /* end */
3820};
3821#endif
3822
Lydia Wang6369bcf2009-10-10 19:08:31 +08003823static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3824 int offset, int num_steps, int step_size)
3825{
3826 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3827 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3828 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3829 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3830 (0 << AC_AMPCAP_MUTE_SHIFT));
3831}
3832
Harald Welted949cac2008-09-09 15:56:01 +08003833static int patch_vt1708S(struct hda_codec *codec)
3834{
3835 struct via_spec *spec;
3836 int err;
3837
3838 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003839 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003840 if (spec == NULL)
3841 return -ENOMEM;
3842
Harald Welted949cac2008-09-09 15:56:01 +08003843 /* automatic parse from the BIOS config */
3844 err = vt1708S_parse_auto_config(codec);
3845 if (err < 0) {
3846 via_free(codec);
3847 return err;
3848 } else if (!err) {
3849 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3850 "from BIOS. Using genenic mode...\n");
3851 }
3852
Harald Welte69e52a82008-09-09 15:57:32 +08003853 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
Lydia Wangbc92df72011-03-23 17:56:05 +08003854 if (codec->vendor_id == 0x11064397)
3855 spec->init_verbs[spec->num_iverbs++] =
3856 vt1705_uniwill_init_verbs;
3857 else
3858 spec->init_verbs[spec->num_iverbs++] =
3859 vt1708S_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003860
Lydia Wangbc92df72011-03-23 17:56:05 +08003861 if (codec->vendor_id == 0x11064397)
3862 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3863 else
3864 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
Harald Welted949cac2008-09-09 15:56:01 +08003865 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3866
Harald Welted949cac2008-09-09 15:56:01 +08003867 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3868
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003869 if (spec->adc_nids && spec->input_mux) {
Lydia Wang6369bcf2009-10-10 19:08:31 +08003870 override_mic_boost(codec, 0x1a, 0, 3, 40);
3871 override_mic_boost(codec, 0x1e, 0, 3, 40);
Harald Welted949cac2008-09-09 15:56:01 +08003872 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3873 spec->num_mixers++;
3874 }
3875
3876 codec->patch_ops = via_patch_ops;
3877
3878 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003879 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08003880#ifdef CONFIG_SND_HDA_POWER_SAVE
3881 spec->loopback.amplist = vt1708S_loopbacks;
3882#endif
3883
Lydia Wang518bf3b2009-10-10 19:07:29 +08003884 /* correct names for VT1708BCE */
3885 if (get_codec_type(codec) == VT1708BCE) {
3886 kfree(codec->chip_name);
3887 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3888 snprintf(codec->bus->card->mixername,
3889 sizeof(codec->bus->card->mixername),
3890 "%s %s", codec->vendor_name, codec->chip_name);
Lydia Wang970f630f2011-03-22 16:25:56 +08003891 }
Lydia Wangbc92df72011-03-23 17:56:05 +08003892 /* correct names for VT1705 */
3893 if (codec->vendor_id == 0x11064397) {
3894 kfree(codec->chip_name);
3895 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3896 snprintf(codec->bus->card->mixername,
3897 sizeof(codec->bus->card->mixername),
3898 "%s %s", codec->vendor_name, codec->chip_name);
3899 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003900 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +08003901 return 0;
3902}
3903
3904/* Patch for VT1702 */
3905
3906/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003907static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003908 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3909 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3910 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3911 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3912 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3913 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3914 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3915 HDA_INPUT),
3916 {
3917 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3918 /* The multiple "Capture Source" controls confuse alsamixer
3919 * So call somewhat different..
3920 */
3921 /* .name = "Capture Source", */
3922 .name = "Input Source",
3923 .count = 1,
3924 .info = via_mux_enum_info,
3925 .get = via_mux_enum_get,
3926 .put = via_mux_enum_put,
3927 },
3928 { } /* end */
3929};
3930
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003931static const struct hda_verb vt1702_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003932 /*
3933 * Unmute ADC0-1 and set the default input to mic-in
3934 */
3935 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3936 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3937 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3938
3939
3940 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3941 * mixer widget
3942 */
3943 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3944 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3945 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3946 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3947 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3948 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3949
3950 /* Setup default input of PW4 to MW0 */
3951 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3952 /* PW6 PW7 Output enable */
3953 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3954 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003955 /* mixer enable */
3956 {0x1, 0xF88, 0x3},
3957 /* GPIO 0~2 */
3958 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08003959 { }
3960};
3961
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003962static const struct hda_verb vt1702_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003963 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3964 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3965 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3966 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3967 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3968 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003969 { }
3970};
3971
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003972static const struct hda_pcm_stream vt1702_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08003973 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08003974 .channels_min = 2,
3975 .channels_max = 2,
3976 .nid = 0x10, /* NID to query formats and rates */
3977 .ops = {
3978 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08003979 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003980 .cleanup = via_playback_multi_pcm_cleanup,
3981 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003982 },
3983};
3984
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003985static const struct hda_pcm_stream vt1702_pcm_analog_capture = {
Harald Welted949cac2008-09-09 15:56:01 +08003986 .substreams = 3,
3987 .channels_min = 2,
3988 .channels_max = 2,
3989 .nid = 0x12, /* NID to query formats and rates */
3990 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003991 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08003992 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003993 .cleanup = via_capture_pcm_cleanup,
3994 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003995 },
3996};
3997
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003998static const struct hda_pcm_stream vt1702_pcm_digital_playback = {
Harald Welte5691ec72008-09-15 22:42:26 +08003999 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08004000 .channels_min = 2,
4001 .channels_max = 2,
4002 /* NID is set in via_build_pcms */
4003 .ops = {
4004 .open = via_dig_playback_pcm_open,
4005 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02004006 .prepare = via_dig_playback_pcm_prepare,
4007 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08004008 },
4009};
4010
4011/* fill in the dac_nids table from the parsed pin configuration */
4012static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4013 const struct auto_pin_cfg *cfg)
4014{
4015 spec->multiout.num_dacs = 1;
4016 spec->multiout.dac_nids = spec->private_dac_nids;
4017
4018 if (cfg->line_out_pins[0]) {
4019 /* config dac list */
Takashi Iwaidda14412011-05-02 11:29:30 +02004020 spec->private_dac_nids[0] = 0x10;
Harald Welted949cac2008-09-09 15:56:01 +08004021 }
4022
4023 return 0;
4024}
4025
4026/* add playback controls from the parsed DAC table */
4027static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4028 const struct auto_pin_cfg *cfg)
4029{
4030 int err;
4031
4032 if (!cfg->line_out_pins[0])
4033 return -1;
4034
4035 /* add control to mixer index 0 */
4036 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4037 "Master Front Playback Volume",
4038 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4039 if (err < 0)
4040 return err;
4041 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4042 "Master Front Playback Switch",
4043 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4044 if (err < 0)
4045 return err;
4046
4047 /* Front */
4048 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4049 "Front Playback Volume",
4050 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4051 if (err < 0)
4052 return err;
4053 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4054 "Front Playback Switch",
4055 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4056 if (err < 0)
4057 return err;
4058
4059 return 0;
4060}
4061
4062static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4063{
Lydia Wang0713efe2009-10-10 19:07:43 +08004064 int err, i;
4065 struct hda_input_mux *imux;
Takashi Iwaiea734962011-01-17 11:29:34 +01004066 static const char * const texts[] = { "ON", "OFF", NULL};
Harald Welted949cac2008-09-09 15:56:01 +08004067 if (!pin)
4068 return 0;
Harald Welted949cac2008-09-09 15:56:01 +08004069 spec->multiout.hp_nid = 0x1D;
Lydia Wangcdc17842009-10-10 19:07:47 +08004070 spec->hp_independent_mode_index = 0;
Harald Welted949cac2008-09-09 15:56:01 +08004071
4072 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4073 "Headphone Playback Volume",
4074 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4075 if (err < 0)
4076 return err;
4077
4078 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4079 "Headphone Playback Switch",
4080 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4081 if (err < 0)
4082 return err;
4083
Lydia Wang0713efe2009-10-10 19:07:43 +08004084 imux = &spec->private_imux[1];
Harald Welte0aa62ae2008-09-09 15:58:27 +08004085
Lydia Wang0713efe2009-10-10 19:07:43 +08004086 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004087 for (i = 0; texts[i]; i++)
4088 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Lydia Wang0713efe2009-10-10 19:07:43 +08004089
4090 spec->hp_mux = &spec->private_imux[1];
Harald Welted949cac2008-09-09 15:56:01 +08004091 return 0;
4092}
4093
4094/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004095static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08004096 const struct auto_pin_cfg *cfg)
4097{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004098 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a);
Harald Welted949cac2008-09-09 15:56:01 +08004099}
4100
4101static int vt1702_parse_auto_config(struct hda_codec *codec)
4102{
4103 struct via_spec *spec = codec->spec;
4104 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004105
Takashi Iwai9da29272009-05-07 16:31:14 +02004106 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08004107 if (err < 0)
4108 return err;
4109 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4110 if (err < 0)
4111 return err;
4112 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4113 return 0; /* can't find valid BIOS pin config */
4114
4115 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4116 if (err < 0)
4117 return err;
4118 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4119 if (err < 0)
4120 return err;
Lydia Wangc2c02ea2009-10-10 19:07:32 +08004121 /* limit AA path volume to 0 dB */
4122 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4123 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4124 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4125 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4126 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai10a20af2010-09-09 16:28:02 +02004127 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08004128 if (err < 0)
4129 return err;
4130
4131 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4132
Takashi Iwai9da29272009-05-07 16:31:14 +02004133 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08004134
Takashi Iwai603c4012008-07-30 15:01:44 +02004135 if (spec->kctls.list)
4136 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08004137
Harald Welte0aa62ae2008-09-09 15:58:27 +08004138 spec->input_mux = &spec->private_imux[0];
4139
Harald Weltef8fdd492008-09-15 22:41:31 +08004140 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004141 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004142
4143 return 1;
4144}
4145
4146#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004147static const struct hda_amp_list vt1702_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08004148 { 0x1A, HDA_INPUT, 1 },
4149 { 0x1A, HDA_INPUT, 2 },
4150 { 0x1A, HDA_INPUT, 3 },
4151 { 0x1A, HDA_INPUT, 4 },
4152 { } /* end */
4153};
4154#endif
4155
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004156static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4157{
4158 int imux_is_smixer =
4159 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4160 unsigned int parm;
4161 /* inputs */
4162 /* PW 1/2/5 (14h/15h/18h) */
4163 parm = AC_PWRST_D3;
4164 set_pin_power_state(codec, 0x14, &parm);
4165 set_pin_power_state(codec, 0x15, &parm);
4166 set_pin_power_state(codec, 0x18, &parm);
4167 if (imux_is_smixer)
4168 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4169 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4170 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4171 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4172 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4173 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4174
4175 /* outputs */
4176 /* PW 3/4 (16h/17h) */
4177 parm = AC_PWRST_D3;
4178 set_pin_power_state(codec, 0x17, &parm);
4179 set_pin_power_state(codec, 0x16, &parm);
4180 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4181 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4182 imux_is_smixer ? AC_PWRST_D0 : parm);
4183 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4184 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4185}
4186
Harald Welted949cac2008-09-09 15:56:01 +08004187static int patch_vt1702(struct hda_codec *codec)
4188{
4189 struct via_spec *spec;
4190 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004191
4192 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004193 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004194 if (spec == NULL)
4195 return -ENOMEM;
4196
Harald Welted949cac2008-09-09 15:56:01 +08004197 /* automatic parse from the BIOS config */
4198 err = vt1702_parse_auto_config(codec);
4199 if (err < 0) {
4200 via_free(codec);
4201 return err;
4202 } else if (!err) {
4203 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4204 "from BIOS. Using genenic mode...\n");
4205 }
4206
Harald Welte69e52a82008-09-09 15:57:32 +08004207 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4208 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08004209
Harald Welted949cac2008-09-09 15:56:01 +08004210 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4211 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4212
Harald Welted949cac2008-09-09 15:56:01 +08004213 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4214
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004215 if (spec->adc_nids && spec->input_mux) {
Harald Welted949cac2008-09-09 15:56:01 +08004216 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4217 spec->num_mixers++;
4218 }
4219
4220 codec->patch_ops = via_patch_ops;
4221
4222 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08004223 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08004224#ifdef CONFIG_SND_HDA_POWER_SAVE
4225 spec->loopback.amplist = vt1702_loopbacks;
4226#endif
4227
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004228 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08004229 return 0;
4230}
4231
Lydia Wangeb7188c2009-10-10 19:08:34 +08004232/* Patch for VT1718S */
4233
4234/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004235static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004236 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4237 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4238 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4239 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4240 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4241 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4242 HDA_INPUT),
4243 {
4244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4245 /* The multiple "Capture Source" controls confuse alsamixer
4246 * So call somewhat different..
4247 */
4248 .name = "Input Source",
4249 .count = 2,
4250 .info = via_mux_enum_info,
4251 .get = via_mux_enum_get,
4252 .put = via_mux_enum_put,
4253 },
4254 { } /* end */
4255};
4256
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004257static const struct hda_verb vt1718S_volume_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004258 /*
4259 * Unmute ADC0-1 and set the default input to mic-in
4260 */
4261 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4262 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4263
Lydia Wang4ab2d532011-03-24 12:42:03 +08004264 /* Enable MW0 adjust Gain 5 */
4265 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08004266 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4267 * mixer widget
4268 */
4269 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4270 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4271 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4272 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4273 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
Lydia Wang4ab2d532011-03-24 12:42:03 +08004274 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
Lydia Wangeb7188c2009-10-10 19:08:34 +08004275
4276 /* Setup default input of Front HP to MW9 */
4277 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4278 /* PW9 PW10 Output enable */
4279 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4280 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4281 /* PW11 Input enable */
4282 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4283 /* Enable Boost Volume backdoor */
4284 {0x1, 0xf88, 0x8},
4285 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4286 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4287 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4288 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4289 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4290 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4291 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4292 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4293 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4294 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4295 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4296 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4297 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4298 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4299 /* Unmute MW4's index 0 */
4300 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4301 { }
4302};
4303
4304
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004305static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004306 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4307 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4308 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4309 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4310 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4311 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4312 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4313 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4314 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4315 { }
4316};
4317
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004318static const struct hda_pcm_stream vt1718S_pcm_analog_playback = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004319 .substreams = 2,
4320 .channels_min = 2,
4321 .channels_max = 10,
4322 .nid = 0x8, /* NID to query formats and rates */
4323 .ops = {
4324 .open = via_playback_pcm_open,
4325 .prepare = via_playback_multi_pcm_prepare,
4326 .cleanup = via_playback_multi_pcm_cleanup,
4327 .close = via_pcm_open_close,
4328 },
4329};
4330
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004331static const struct hda_pcm_stream vt1718S_pcm_analog_capture = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004332 .substreams = 2,
4333 .channels_min = 2,
4334 .channels_max = 2,
4335 .nid = 0x10, /* NID to query formats and rates */
4336 .ops = {
4337 .open = via_pcm_open_close,
4338 .prepare = via_capture_pcm_prepare,
4339 .cleanup = via_capture_pcm_cleanup,
4340 .close = via_pcm_open_close,
4341 },
4342};
4343
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004344static const struct hda_pcm_stream vt1718S_pcm_digital_playback = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004345 .substreams = 2,
4346 .channels_min = 2,
4347 .channels_max = 2,
Lydia Wangeb7188c2009-10-10 19:08:34 +08004348 /* NID is set in via_build_pcms */
4349 .ops = {
4350 .open = via_dig_playback_pcm_open,
4351 .close = via_dig_playback_pcm_close,
4352 .prepare = via_dig_playback_pcm_prepare,
4353 .cleanup = via_dig_playback_pcm_cleanup
4354 },
4355};
4356
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004357static const struct hda_pcm_stream vt1718S_pcm_digital_capture = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004358 .substreams = 1,
4359 .channels_min = 2,
4360 .channels_max = 2,
4361};
4362
4363/* fill in the dac_nids table from the parsed pin configuration */
4364static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4365 const struct auto_pin_cfg *cfg)
4366{
4367 int i;
4368 hda_nid_t nid;
4369
4370 spec->multiout.num_dacs = cfg->line_outs;
4371
4372 spec->multiout.dac_nids = spec->private_dac_nids;
4373
4374 for (i = 0; i < 4; i++) {
4375 nid = cfg->line_out_pins[i];
4376 if (nid) {
4377 /* config dac list */
4378 switch (i) {
4379 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02004380 spec->private_dac_nids[i] = 0x8;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004381 break;
4382 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004383 spec->private_dac_nids[i] = 0xa;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004384 break;
4385 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02004386 spec->private_dac_nids[i] = 0x9;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004387 break;
4388 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004389 spec->private_dac_nids[i] = 0xb;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004390 break;
4391 }
4392 }
4393 }
4394
4395 return 0;
4396}
4397
4398/* add playback controls from the parsed DAC table */
4399static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4400 const struct auto_pin_cfg *cfg)
4401{
4402 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01004403 static const char * const chname[4] = {
4404 "Front", "Surround", "C/LFE", "Side"
4405 };
Lydia Wangeb7188c2009-10-10 19:08:34 +08004406 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4407 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4408 hda_nid_t nid, nid_vol, nid_mute = 0;
4409 int i, err;
4410
4411 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4412 nid = cfg->line_out_pins[i];
4413
4414 if (!nid)
4415 continue;
4416 nid_vol = nid_vols[i];
4417 nid_mute = nid_mutes[i];
4418
4419 if (i == AUTO_SEQ_CENLFE) {
4420 /* Center/LFE */
4421 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4422 "Center Playback Volume",
4423 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4424 HDA_OUTPUT));
4425 if (err < 0)
4426 return err;
4427 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4428 "LFE Playback Volume",
4429 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4430 HDA_OUTPUT));
4431 if (err < 0)
4432 return err;
4433 err = via_add_control(
4434 spec, VIA_CTL_WIDGET_MUTE,
4435 "Center Playback Switch",
4436 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4437 HDA_OUTPUT));
4438 if (err < 0)
4439 return err;
4440 err = via_add_control(
4441 spec, VIA_CTL_WIDGET_MUTE,
4442 "LFE Playback Switch",
4443 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4444 HDA_OUTPUT));
4445 if (err < 0)
4446 return err;
4447 } else if (i == AUTO_SEQ_FRONT) {
4448 /* Front */
4449 sprintf(name, "%s Playback Volume", chname[i]);
4450 err = via_add_control(
4451 spec, VIA_CTL_WIDGET_VOL, name,
4452 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4453 if (err < 0)
4454 return err;
4455 sprintf(name, "%s Playback Switch", chname[i]);
4456 err = via_add_control(
4457 spec, VIA_CTL_WIDGET_MUTE, name,
4458 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4459 HDA_OUTPUT));
4460 if (err < 0)
4461 return err;
4462 } else {
4463 sprintf(name, "%s Playback Volume", chname[i]);
4464 err = via_add_control(
4465 spec, VIA_CTL_WIDGET_VOL, name,
4466 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4467 if (err < 0)
4468 return err;
4469 sprintf(name, "%s Playback Switch", chname[i]);
4470 err = via_add_control(
4471 spec, VIA_CTL_WIDGET_MUTE, name,
4472 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4473 HDA_OUTPUT));
4474 if (err < 0)
4475 return err;
4476 }
4477 }
4478 return 0;
4479}
4480
4481static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4482{
4483 int err;
4484
4485 if (!pin)
4486 return 0;
4487
4488 spec->multiout.hp_nid = 0xc; /* AOW4 */
4489 spec->hp_independent_mode_index = 1;
4490
4491 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4492 "Headphone Playback Volume",
4493 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4494 if (err < 0)
4495 return err;
4496
4497 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4498 "Headphone Playback Switch",
4499 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4500 if (err < 0)
4501 return err;
4502
4503 create_hp_imux(spec);
4504 return 0;
4505}
4506
4507/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004508static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangeb7188c2009-10-10 19:08:34 +08004509 const struct auto_pin_cfg *cfg)
4510{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004511 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004512}
4513
4514static int vt1718S_parse_auto_config(struct hda_codec *codec)
4515{
4516 struct via_spec *spec = codec->spec;
4517 int err;
4518
4519 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4520
4521 if (err < 0)
4522 return err;
4523 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4524 if (err < 0)
4525 return err;
4526 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4527 return 0; /* can't find valid BIOS pin config */
4528
4529 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4530 if (err < 0)
4531 return err;
4532 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4533 if (err < 0)
4534 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02004535 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004536 if (err < 0)
4537 return err;
4538
4539 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4540
4541 fill_dig_outs(codec);
4542
4543 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4544 spec->dig_in_nid = 0x13;
4545
4546 if (spec->kctls.list)
4547 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4548
4549 spec->input_mux = &spec->private_imux[0];
4550
4551 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004552 via_hp_build(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004553
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004554 via_smart51_build(spec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004555
4556 return 1;
4557}
4558
4559#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004560static const struct hda_amp_list vt1718S_loopbacks[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004561 { 0x21, HDA_INPUT, 1 },
4562 { 0x21, HDA_INPUT, 2 },
4563 { 0x21, HDA_INPUT, 3 },
4564 { 0x21, HDA_INPUT, 4 },
4565 { } /* end */
4566};
4567#endif
4568
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004569static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4570{
4571 struct via_spec *spec = codec->spec;
4572 int imux_is_smixer;
4573 unsigned int parm;
4574 /* MUX6 (1eh) = stereo mixer */
4575 imux_is_smixer =
4576 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4577 /* inputs */
4578 /* PW 5/6/7 (29h/2ah/2bh) */
4579 parm = AC_PWRST_D3;
4580 set_pin_power_state(codec, 0x29, &parm);
4581 set_pin_power_state(codec, 0x2a, &parm);
4582 set_pin_power_state(codec, 0x2b, &parm);
4583 if (imux_is_smixer)
4584 parm = AC_PWRST_D0;
4585 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4586 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4587 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4588 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4589 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4590
4591 /* outputs */
4592 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4593 parm = AC_PWRST_D3;
4594 set_pin_power_state(codec, 0x27, &parm);
4595 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4596 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4597
4598 /* PW2 (26h), AOW2 (ah) */
4599 parm = AC_PWRST_D3;
4600 set_pin_power_state(codec, 0x26, &parm);
4601 if (spec->smart51_enabled)
4602 set_pin_power_state(codec, 0x2b, &parm);
4603 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4604
4605 /* PW0 (24h), AOW0 (8h) */
4606 parm = AC_PWRST_D3;
4607 set_pin_power_state(codec, 0x24, &parm);
4608 if (!spec->hp_independent_mode) /* check for redirected HP */
4609 set_pin_power_state(codec, 0x28, &parm);
4610 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4611 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4612 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4613 imux_is_smixer ? AC_PWRST_D0 : parm);
4614
4615 /* PW1 (25h), AOW1 (9h) */
4616 parm = AC_PWRST_D3;
4617 set_pin_power_state(codec, 0x25, &parm);
4618 if (spec->smart51_enabled)
4619 set_pin_power_state(codec, 0x2a, &parm);
4620 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4621
4622 if (spec->hp_independent_mode) {
4623 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4624 parm = AC_PWRST_D3;
4625 set_pin_power_state(codec, 0x28, &parm);
4626 snd_hda_codec_write(codec, 0x1b, 0,
4627 AC_VERB_SET_POWER_STATE, parm);
4628 snd_hda_codec_write(codec, 0x34, 0,
4629 AC_VERB_SET_POWER_STATE, parm);
4630 snd_hda_codec_write(codec, 0xc, 0,
4631 AC_VERB_SET_POWER_STATE, parm);
4632 }
4633}
4634
Lydia Wangeb7188c2009-10-10 19:08:34 +08004635static int patch_vt1718S(struct hda_codec *codec)
4636{
4637 struct via_spec *spec;
4638 int err;
4639
4640 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004641 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004642 if (spec == NULL)
4643 return -ENOMEM;
4644
Lydia Wangeb7188c2009-10-10 19:08:34 +08004645 /* automatic parse from the BIOS config */
4646 err = vt1718S_parse_auto_config(codec);
4647 if (err < 0) {
4648 via_free(codec);
4649 return err;
4650 } else if (!err) {
4651 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4652 "from BIOS. Using genenic mode...\n");
4653 }
4654
4655 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4656 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4657
Lydia Wangeb7188c2009-10-10 19:08:34 +08004658 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4659 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4660
Lydia Wangeb7188c2009-10-10 19:08:34 +08004661 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004662 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
Lydia Wangeb7188c2009-10-10 19:08:34 +08004663 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4664
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004665 if (spec->adc_nids && spec->input_mux) {
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004666 override_mic_boost(codec, 0x2b, 0, 3, 40);
4667 override_mic_boost(codec, 0x29, 0, 3, 40);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004668 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4669 spec->num_mixers++;
4670 }
4671
4672 codec->patch_ops = via_patch_ops;
4673
4674 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11004675 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004676
4677#ifdef CONFIG_SND_HDA_POWER_SAVE
4678 spec->loopback.amplist = vt1718S_loopbacks;
4679#endif
4680
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004681 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4682
Lydia Wangeb7188c2009-10-10 19:08:34 +08004683 return 0;
4684}
Lydia Wangf3db4232009-10-10 19:08:41 +08004685
4686/* Patch for VT1716S */
4687
4688static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4689 struct snd_ctl_elem_info *uinfo)
4690{
4691 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4692 uinfo->count = 1;
4693 uinfo->value.integer.min = 0;
4694 uinfo->value.integer.max = 1;
4695 return 0;
4696}
4697
4698static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4699 struct snd_ctl_elem_value *ucontrol)
4700{
4701 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4702 int index = 0;
4703
4704 index = snd_hda_codec_read(codec, 0x26, 0,
4705 AC_VERB_GET_CONNECT_SEL, 0);
4706 if (index != -1)
4707 *ucontrol->value.integer.value = index;
4708
4709 return 0;
4710}
4711
4712static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4713 struct snd_ctl_elem_value *ucontrol)
4714{
4715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4716 struct via_spec *spec = codec->spec;
4717 int index = *ucontrol->value.integer.value;
4718
4719 snd_hda_codec_write(codec, 0x26, 0,
4720 AC_VERB_SET_CONNECT_SEL, index);
4721 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004722 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08004723 return 1;
4724}
4725
4726/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004727static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004728 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4729 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4730 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4731 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4732 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4733 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4734 HDA_INPUT),
4735 {
4736 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4737 .name = "Input Source",
4738 .count = 1,
4739 .info = via_mux_enum_info,
4740 .get = via_mux_enum_get,
4741 .put = via_mux_enum_put,
4742 },
4743 { } /* end */
4744};
4745
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004746static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004747 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4748 {
4749 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4750 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004751 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08004752 .count = 1,
4753 .info = vt1716s_dmic_info,
4754 .get = vt1716s_dmic_get,
4755 .put = vt1716s_dmic_put,
4756 },
4757 {} /* end */
4758};
4759
4760
4761/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004762static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004763 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4764 { } /* end */
4765};
4766
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004767static const struct hda_verb vt1716S_volume_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004768 /*
4769 * Unmute ADC0-1 and set the default input to mic-in
4770 */
4771 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4772 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4773
4774
4775 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4776 * mixer widget
4777 */
4778 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4779 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4780 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4781 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4782 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4783 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4784
4785 /* MUX Indices: Stereo Mixer = 5 */
4786 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4787
4788 /* Setup default input of PW4 to MW0 */
4789 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4790
4791 /* Setup default input of SW1 as MW0 */
4792 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4793
4794 /* Setup default input of SW4 as AOW0 */
4795 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4796
4797 /* PW9 PW10 Output enable */
4798 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4799 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4800
4801 /* Unmute SW1, PW12 */
4802 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4803 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4804 /* PW12 Output enable */
4805 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4806 /* Enable Boost Volume backdoor */
4807 {0x1, 0xf8a, 0x80},
4808 /* don't bybass mixer */
4809 {0x1, 0xf88, 0xc0},
4810 /* Enable mono output */
4811 {0x1, 0xf90, 0x08},
4812 { }
4813};
4814
4815
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004816static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004817 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4818 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4819 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4820 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4821 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4822 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4823 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4824 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4825 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4826 { }
4827};
4828
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004829static const struct hda_pcm_stream vt1716S_pcm_analog_playback = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004830 .substreams = 2,
4831 .channels_min = 2,
4832 .channels_max = 6,
4833 .nid = 0x10, /* NID to query formats and rates */
4834 .ops = {
4835 .open = via_playback_pcm_open,
4836 .prepare = via_playback_multi_pcm_prepare,
4837 .cleanup = via_playback_multi_pcm_cleanup,
4838 .close = via_pcm_open_close,
4839 },
4840};
4841
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004842static const struct hda_pcm_stream vt1716S_pcm_analog_capture = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004843 .substreams = 2,
4844 .channels_min = 2,
4845 .channels_max = 2,
4846 .nid = 0x13, /* NID to query formats and rates */
4847 .ops = {
4848 .open = via_pcm_open_close,
4849 .prepare = via_capture_pcm_prepare,
4850 .cleanup = via_capture_pcm_cleanup,
4851 .close = via_pcm_open_close,
4852 },
4853};
4854
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004855static const struct hda_pcm_stream vt1716S_pcm_digital_playback = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004856 .substreams = 2,
4857 .channels_min = 2,
4858 .channels_max = 2,
Lydia Wangf3db4232009-10-10 19:08:41 +08004859 /* NID is set in via_build_pcms */
4860 .ops = {
4861 .open = via_dig_playback_pcm_open,
4862 .close = via_dig_playback_pcm_close,
4863 .prepare = via_dig_playback_pcm_prepare,
4864 .cleanup = via_dig_playback_pcm_cleanup
4865 },
4866};
4867
4868/* fill in the dac_nids table from the parsed pin configuration */
4869static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4870 const struct auto_pin_cfg *cfg)
4871{ int i;
4872 hda_nid_t nid;
4873
4874 spec->multiout.num_dacs = cfg->line_outs;
4875
4876 spec->multiout.dac_nids = spec->private_dac_nids;
4877
4878 for (i = 0; i < 3; i++) {
4879 nid = cfg->line_out_pins[i];
4880 if (nid) {
4881 /* config dac list */
4882 switch (i) {
4883 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02004884 spec->private_dac_nids[i] = 0x10;
Lydia Wangf3db4232009-10-10 19:08:41 +08004885 break;
4886 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004887 spec->private_dac_nids[i] = 0x25;
Lydia Wangf3db4232009-10-10 19:08:41 +08004888 break;
4889 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02004890 spec->private_dac_nids[i] = 0x11;
Lydia Wangf3db4232009-10-10 19:08:41 +08004891 break;
4892 }
4893 }
4894 }
4895
4896 return 0;
4897}
4898
4899/* add playback controls from the parsed DAC table */
4900static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4901 const struct auto_pin_cfg *cfg)
4902{
4903 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01004904 static const char * const chname[3] = {
4905 "Front", "Surround", "C/LFE"
4906 };
Lydia Wangf3db4232009-10-10 19:08:41 +08004907 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4908 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4909 hda_nid_t nid, nid_vol, nid_mute;
4910 int i, err;
4911
4912 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4913 nid = cfg->line_out_pins[i];
4914
4915 if (!nid)
4916 continue;
4917
4918 nid_vol = nid_vols[i];
4919 nid_mute = nid_mutes[i];
4920
4921 if (i == AUTO_SEQ_CENLFE) {
4922 err = via_add_control(
4923 spec, VIA_CTL_WIDGET_VOL,
4924 "Center Playback Volume",
4925 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
4926 if (err < 0)
4927 return err;
4928 err = via_add_control(
4929 spec, VIA_CTL_WIDGET_VOL,
4930 "LFE Playback Volume",
4931 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
4932 if (err < 0)
4933 return err;
4934 err = via_add_control(
4935 spec, VIA_CTL_WIDGET_MUTE,
4936 "Center Playback Switch",
4937 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4938 HDA_OUTPUT));
4939 if (err < 0)
4940 return err;
4941 err = via_add_control(
4942 spec, VIA_CTL_WIDGET_MUTE,
4943 "LFE Playback Switch",
4944 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4945 HDA_OUTPUT));
4946 if (err < 0)
4947 return err;
4948 } else if (i == AUTO_SEQ_FRONT) {
4949
4950 err = via_add_control(
4951 spec, VIA_CTL_WIDGET_VOL,
4952 "Master Front Playback Volume",
4953 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4954 if (err < 0)
4955 return err;
4956 err = via_add_control(
4957 spec, VIA_CTL_WIDGET_MUTE,
4958 "Master Front Playback Switch",
4959 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4960 if (err < 0)
4961 return err;
4962
4963 sprintf(name, "%s Playback Volume", chname[i]);
4964 err = via_add_control(
4965 spec, VIA_CTL_WIDGET_VOL, name,
4966 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4967 if (err < 0)
4968 return err;
4969 sprintf(name, "%s Playback Switch", chname[i]);
4970 err = via_add_control(
4971 spec, VIA_CTL_WIDGET_MUTE, name,
4972 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4973 HDA_OUTPUT));
4974 if (err < 0)
4975 return err;
4976 } else {
4977 sprintf(name, "%s Playback Volume", chname[i]);
4978 err = via_add_control(
4979 spec, VIA_CTL_WIDGET_VOL, name,
4980 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4981 if (err < 0)
4982 return err;
4983 sprintf(name, "%s Playback Switch", chname[i]);
4984 err = via_add_control(
4985 spec, VIA_CTL_WIDGET_MUTE, name,
4986 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4987 HDA_OUTPUT));
4988 if (err < 0)
4989 return err;
4990 }
4991 }
4992 return 0;
4993}
4994
4995static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4996{
4997 int err;
4998
4999 if (!pin)
5000 return 0;
5001
5002 spec->multiout.hp_nid = 0x25; /* AOW3 */
5003 spec->hp_independent_mode_index = 1;
5004
5005 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5006 "Headphone Playback Volume",
5007 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5008 if (err < 0)
5009 return err;
5010
5011 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5012 "Headphone Playback Switch",
5013 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5014 if (err < 0)
5015 return err;
5016
5017 create_hp_imux(spec);
5018 return 0;
5019}
5020
5021/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005022static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangf3db4232009-10-10 19:08:41 +08005023 const struct auto_pin_cfg *cfg)
5024{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005025 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
Lydia Wangf3db4232009-10-10 19:08:41 +08005026}
5027
5028static int vt1716S_parse_auto_config(struct hda_codec *codec)
5029{
5030 struct via_spec *spec = codec->spec;
5031 int err;
5032
5033 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5034 if (err < 0)
5035 return err;
5036 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5037 if (err < 0)
5038 return err;
5039 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5040 return 0; /* can't find valid BIOS pin config */
5041
5042 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5043 if (err < 0)
5044 return err;
5045 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5046 if (err < 0)
5047 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005048 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangf3db4232009-10-10 19:08:41 +08005049 if (err < 0)
5050 return err;
5051
5052 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5053
5054 fill_dig_outs(codec);
5055
5056 if (spec->kctls.list)
5057 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5058
5059 spec->input_mux = &spec->private_imux[0];
5060
5061 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005062 via_hp_build(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005063
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005064 via_smart51_build(spec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005065
5066 return 1;
5067}
5068
5069#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005070static const struct hda_amp_list vt1716S_loopbacks[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08005071 { 0x16, HDA_INPUT, 1 },
5072 { 0x16, HDA_INPUT, 2 },
5073 { 0x16, HDA_INPUT, 3 },
5074 { 0x16, HDA_INPUT, 4 },
5075 { } /* end */
5076};
5077#endif
5078
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005079static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5080{
5081 struct via_spec *spec = codec->spec;
5082 int imux_is_smixer;
5083 unsigned int parm;
5084 unsigned int mono_out, present;
5085 /* SW0 (17h) = stereo mixer */
5086 imux_is_smixer =
5087 (snd_hda_codec_read(codec, 0x17, 0,
5088 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5089 /* inputs */
5090 /* PW 1/2/5 (1ah/1bh/1eh) */
5091 parm = AC_PWRST_D3;
5092 set_pin_power_state(codec, 0x1a, &parm);
5093 set_pin_power_state(codec, 0x1b, &parm);
5094 set_pin_power_state(codec, 0x1e, &parm);
5095 if (imux_is_smixer)
5096 parm = AC_PWRST_D0;
5097 /* SW0 (17h), AIW0(13h) */
5098 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5099 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5100
5101 parm = AC_PWRST_D3;
5102 set_pin_power_state(codec, 0x1e, &parm);
5103 /* PW11 (22h) */
5104 if (spec->dmic_enabled)
5105 set_pin_power_state(codec, 0x22, &parm);
5106 else
5107 snd_hda_codec_write(codec, 0x22, 0,
5108 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5109
5110 /* SW2(26h), AIW1(14h) */
5111 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5112 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5113
5114 /* outputs */
5115 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5116 parm = AC_PWRST_D3;
5117 set_pin_power_state(codec, 0x19, &parm);
5118 /* Smart 5.1 PW2(1bh) */
5119 if (spec->smart51_enabled)
5120 set_pin_power_state(codec, 0x1b, &parm);
5121 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5122 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5123
5124 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5125 parm = AC_PWRST_D3;
5126 set_pin_power_state(codec, 0x23, &parm);
5127 /* Smart 5.1 PW1(1ah) */
5128 if (spec->smart51_enabled)
5129 set_pin_power_state(codec, 0x1a, &parm);
5130 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5131
5132 /* Smart 5.1 PW5(1eh) */
5133 if (spec->smart51_enabled)
5134 set_pin_power_state(codec, 0x1e, &parm);
5135 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5136
5137 /* Mono out */
5138 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5139 present = snd_hda_jack_detect(codec, 0x1c);
5140
5141 if (present)
5142 mono_out = 0;
5143 else {
5144 present = snd_hda_jack_detect(codec, 0x1d);
5145 if (!spec->hp_independent_mode && present)
5146 mono_out = 0;
5147 else
5148 mono_out = 1;
5149 }
5150 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5151 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5152 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5153 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5154
5155 /* PW 3/4 (1ch/1dh) */
5156 parm = AC_PWRST_D3;
5157 set_pin_power_state(codec, 0x1c, &parm);
5158 set_pin_power_state(codec, 0x1d, &parm);
5159 /* HP Independent Mode, power on AOW3 */
5160 if (spec->hp_independent_mode)
5161 snd_hda_codec_write(codec, 0x25, 0,
5162 AC_VERB_SET_POWER_STATE, parm);
5163
5164 /* force to D0 for internal Speaker */
5165 /* MW0 (16h), AOW0 (10h) */
5166 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5167 imux_is_smixer ? AC_PWRST_D0 : parm);
5168 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5169 mono_out ? AC_PWRST_D0 : parm);
5170}
5171
Lydia Wangf3db4232009-10-10 19:08:41 +08005172static int patch_vt1716S(struct hda_codec *codec)
5173{
5174 struct via_spec *spec;
5175 int err;
5176
5177 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005178 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005179 if (spec == NULL)
5180 return -ENOMEM;
5181
Lydia Wangf3db4232009-10-10 19:08:41 +08005182 /* automatic parse from the BIOS config */
5183 err = vt1716S_parse_auto_config(codec);
5184 if (err < 0) {
5185 via_free(codec);
5186 return err;
5187 } else if (!err) {
5188 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5189 "from BIOS. Using genenic mode...\n");
5190 }
5191
5192 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5193 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5194
Lydia Wangf3db4232009-10-10 19:08:41 +08005195 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5196 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5197
Lydia Wangf3db4232009-10-10 19:08:41 +08005198 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5199
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005200 if (spec->adc_nids && spec->input_mux) {
Lydia Wangf3db4232009-10-10 19:08:41 +08005201 override_mic_boost(codec, 0x1a, 0, 3, 40);
5202 override_mic_boost(codec, 0x1e, 0, 3, 40);
5203 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5204 spec->num_mixers++;
5205 }
5206
5207 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5208 spec->num_mixers++;
5209
5210 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5211
5212 codec->patch_ops = via_patch_ops;
5213
5214 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005215 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangf3db4232009-10-10 19:08:41 +08005216
5217#ifdef CONFIG_SND_HDA_POWER_SAVE
5218 spec->loopback.amplist = vt1716S_loopbacks;
5219#endif
5220
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005221 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08005222 return 0;
5223}
Lydia Wang25eaba22009-10-10 19:08:43 +08005224
5225/* for vt2002P */
5226
5227/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005228static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005229 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5230 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5231 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5232 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5233 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5234 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5235 HDA_INPUT),
5236 {
5237 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5238 /* The multiple "Capture Source" controls confuse alsamixer
5239 * So call somewhat different..
5240 */
5241 /* .name = "Capture Source", */
5242 .name = "Input Source",
5243 .count = 2,
5244 .info = via_mux_enum_info,
5245 .get = via_mux_enum_get,
5246 .put = via_mux_enum_put,
5247 },
5248 { } /* end */
5249};
5250
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005251static const struct hda_verb vt2002P_volume_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08005252 /* Class-D speaker related verbs */
5253 {0x1, 0xfe0, 0x4},
5254 {0x1, 0xfe9, 0x80},
5255 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08005256 /*
5257 * Unmute ADC0-1 and set the default input to mic-in
5258 */
5259 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5260 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5261
5262
5263 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5264 * mixer widget
5265 */
5266 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5267 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5268 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5269 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5270 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5271 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5272
5273 /* MUX Indices: Mic = 0 */
5274 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5275 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5276
5277 /* PW9 Output enable */
5278 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5279
5280 /* Enable Boost Volume backdoor */
5281 {0x1, 0xfb9, 0x24},
5282
5283 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5284 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5285 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5286 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5287 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5288 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5289 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5290 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5291 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5292
5293 /* set MUX0/1/4/8 = 0 (AOW0) */
5294 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5295 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5296 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5297 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5298
5299 /* set PW0 index=0 (MW0) */
5300 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5301
5302 /* Enable AOW0 to MW9 */
5303 {0x1, 0xfb8, 0x88},
5304 { }
5305};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005306static const struct hda_verb vt1802_volume_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08005307 /*
5308 * Unmute ADC0-1 and set the default input to mic-in
5309 */
5310 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5311 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5312
5313
5314 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5315 * mixer widget
5316 */
5317 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5318 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5319 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5320 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5321 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5322 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5323
5324 /* MUX Indices: Mic = 0 */
5325 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5326 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5327
5328 /* PW9 Output enable */
5329 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5330
5331 /* Enable Boost Volume backdoor */
5332 {0x1, 0xfb9, 0x24},
5333
5334 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5335 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5336 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5337 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5338 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5339 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5340 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5341 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5342 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5343
5344 /* set MUX0/1/4/8 = 0 (AOW0) */
5345 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5346 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5347 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5348 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5349
5350 /* set PW0 index=0 (MW0) */
5351 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5352
5353 /* Enable AOW0 to MW9 */
5354 {0x1, 0xfb8, 0x88},
5355 { }
5356};
Lydia Wang25eaba22009-10-10 19:08:43 +08005357
5358
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005359static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005360 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5361 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5362 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5363 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5364 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5365 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5366 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5367 { }
5368};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005369static const struct hda_verb vt1802_uniwill_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08005370 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5371 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5372 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5373 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5374 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5375 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5376 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5377 { }
5378};
Lydia Wang25eaba22009-10-10 19:08:43 +08005379
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005380static const struct hda_pcm_stream vt2002P_pcm_analog_playback = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005381 .substreams = 2,
5382 .channels_min = 2,
5383 .channels_max = 2,
5384 .nid = 0x8, /* NID to query formats and rates */
5385 .ops = {
5386 .open = via_playback_pcm_open,
5387 .prepare = via_playback_multi_pcm_prepare,
5388 .cleanup = via_playback_multi_pcm_cleanup,
5389 .close = via_pcm_open_close,
5390 },
5391};
5392
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005393static const struct hda_pcm_stream vt2002P_pcm_analog_capture = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005394 .substreams = 2,
5395 .channels_min = 2,
5396 .channels_max = 2,
5397 .nid = 0x10, /* NID to query formats and rates */
5398 .ops = {
5399 .open = via_pcm_open_close,
5400 .prepare = via_capture_pcm_prepare,
5401 .cleanup = via_capture_pcm_cleanup,
5402 .close = via_pcm_open_close,
5403 },
5404};
5405
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005406static const struct hda_pcm_stream vt2002P_pcm_digital_playback = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005407 .substreams = 1,
5408 .channels_min = 2,
5409 .channels_max = 2,
Lydia Wang25eaba22009-10-10 19:08:43 +08005410 /* NID is set in via_build_pcms */
5411 .ops = {
5412 .open = via_dig_playback_pcm_open,
5413 .close = via_dig_playback_pcm_close,
5414 .prepare = via_dig_playback_pcm_prepare,
5415 .cleanup = via_dig_playback_pcm_cleanup
5416 },
5417};
5418
5419/* fill in the dac_nids table from the parsed pin configuration */
5420static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5421 const struct auto_pin_cfg *cfg)
5422{
5423 spec->multiout.num_dacs = 1;
5424 spec->multiout.dac_nids = spec->private_dac_nids;
5425 if (cfg->line_out_pins[0])
Takashi Iwaidda14412011-05-02 11:29:30 +02005426 spec->private_dac_nids[0] = 0x8;
Lydia Wang25eaba22009-10-10 19:08:43 +08005427 return 0;
5428}
5429
5430/* add playback controls from the parsed DAC table */
5431static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5432 const struct auto_pin_cfg *cfg)
5433{
5434 int err;
Lydia Wang118909562011-03-23 17:57:34 +08005435 hda_nid_t sw_nid;
Lydia Wang25eaba22009-10-10 19:08:43 +08005436
5437 if (!cfg->line_out_pins[0])
5438 return -1;
5439
Lydia Wang118909562011-03-23 17:57:34 +08005440 if (spec->codec_type == VT1802)
5441 sw_nid = 0x28;
5442 else
5443 sw_nid = 0x26;
Lydia Wang25eaba22009-10-10 19:08:43 +08005444
5445 /* Line-Out: PortE */
5446 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5447 "Master Front Playback Volume",
5448 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5449 if (err < 0)
5450 return err;
5451 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5452 "Master Front Playback Switch",
Lydia Wang118909562011-03-23 17:57:34 +08005453 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
Lydia Wang25eaba22009-10-10 19:08:43 +08005454 if (err < 0)
5455 return err;
5456
5457 return 0;
5458}
5459
5460static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5461{
5462 int err;
5463
5464 if (!pin)
5465 return 0;
5466
5467 spec->multiout.hp_nid = 0x9;
5468 spec->hp_independent_mode_index = 1;
5469
5470 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5471 "Headphone Playback Volume",
5472 HDA_COMPOSE_AMP_VAL(
5473 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5474 if (err < 0)
5475 return err;
5476
5477 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5478 "Headphone Playback Switch",
5479 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5480 if (err < 0)
5481 return err;
5482
5483 create_hp_imux(spec);
5484 return 0;
5485}
5486
5487/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005488static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wang25eaba22009-10-10 19:08:43 +08005489 const struct auto_pin_cfg *cfg)
5490{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005491 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
Lydia Wang25eaba22009-10-10 19:08:43 +08005492}
5493
5494static int vt2002P_parse_auto_config(struct hda_codec *codec)
5495{
5496 struct via_spec *spec = codec->spec;
5497 int err;
5498
5499
5500 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5501 if (err < 0)
5502 return err;
5503
5504 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5505 if (err < 0)
5506 return err;
5507
5508 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5509 return 0; /* can't find valid BIOS pin config */
5510
5511 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5512 if (err < 0)
5513 return err;
5514 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5515 if (err < 0)
5516 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005517 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wang25eaba22009-10-10 19:08:43 +08005518 if (err < 0)
5519 return err;
5520
5521 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5522
5523 fill_dig_outs(codec);
5524
5525 if (spec->kctls.list)
5526 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5527
5528 spec->input_mux = &spec->private_imux[0];
5529
5530 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005531 via_hp_build(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08005532
5533 return 1;
5534}
5535
5536#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005537static const struct hda_amp_list vt2002P_loopbacks[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005538 { 0x21, HDA_INPUT, 0 },
5539 { 0x21, HDA_INPUT, 1 },
5540 { 0x21, HDA_INPUT, 2 },
5541 { } /* end */
5542};
5543#endif
5544
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005545static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5546{
5547 struct via_spec *spec = codec->spec;
5548 int imux_is_smixer;
5549 unsigned int parm;
5550 unsigned int present;
5551 /* MUX9 (1eh) = stereo mixer */
5552 imux_is_smixer =
5553 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5554 /* inputs */
5555 /* PW 5/6/7 (29h/2ah/2bh) */
5556 parm = AC_PWRST_D3;
5557 set_pin_power_state(codec, 0x29, &parm);
5558 set_pin_power_state(codec, 0x2a, &parm);
5559 set_pin_power_state(codec, 0x2b, &parm);
5560 parm = AC_PWRST_D0;
5561 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5562 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5563 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5564 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5565 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5566
5567 /* outputs */
5568 /* AOW0 (8h)*/
5569 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5570
Lydia Wang118909562011-03-23 17:57:34 +08005571 if (spec->codec_type == VT1802) {
5572 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5573 parm = AC_PWRST_D3;
5574 set_pin_power_state(codec, 0x28, &parm);
5575 snd_hda_codec_write(codec, 0x18, 0,
5576 AC_VERB_SET_POWER_STATE, parm);
5577 snd_hda_codec_write(codec, 0x38, 0,
5578 AC_VERB_SET_POWER_STATE, parm);
5579 } else {
5580 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5581 parm = AC_PWRST_D3;
5582 set_pin_power_state(codec, 0x26, &parm);
5583 snd_hda_codec_write(codec, 0x1c, 0,
5584 AC_VERB_SET_POWER_STATE, parm);
5585 snd_hda_codec_write(codec, 0x37, 0,
5586 AC_VERB_SET_POWER_STATE, parm);
5587 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005588
Lydia Wang118909562011-03-23 17:57:34 +08005589 if (spec->codec_type == VT1802) {
5590 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5591 parm = AC_PWRST_D3;
5592 set_pin_power_state(codec, 0x25, &parm);
5593 snd_hda_codec_write(codec, 0x15, 0,
5594 AC_VERB_SET_POWER_STATE, parm);
5595 snd_hda_codec_write(codec, 0x35, 0,
5596 AC_VERB_SET_POWER_STATE, parm);
5597 } else {
5598 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5599 parm = AC_PWRST_D3;
5600 set_pin_power_state(codec, 0x25, &parm);
5601 snd_hda_codec_write(codec, 0x19, 0,
5602 AC_VERB_SET_POWER_STATE, parm);
5603 snd_hda_codec_write(codec, 0x35, 0,
5604 AC_VERB_SET_POWER_STATE, parm);
5605 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005606
5607 if (spec->hp_independent_mode)
5608 snd_hda_codec_write(codec, 0x9, 0,
5609 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5610
5611 /* Class-D */
5612 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5613 present = snd_hda_jack_detect(codec, 0x25);
5614
5615 parm = AC_PWRST_D3;
5616 set_pin_power_state(codec, 0x24, &parm);
5617 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08005618 if (spec->codec_type == VT1802)
5619 snd_hda_codec_write(codec, 0x14, 0,
5620 AC_VERB_SET_POWER_STATE, parm);
5621 else
5622 snd_hda_codec_write(codec, 0x18, 0,
5623 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005624 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5625
5626 /* Mono Out */
5627 present = snd_hda_jack_detect(codec, 0x26);
5628
5629 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08005630 if (spec->codec_type == VT1802) {
5631 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5632 snd_hda_codec_write(codec, 0x33, 0,
5633 AC_VERB_SET_POWER_STATE, parm);
5634 snd_hda_codec_write(codec, 0x1c, 0,
5635 AC_VERB_SET_POWER_STATE, parm);
5636 snd_hda_codec_write(codec, 0x3c, 0,
5637 AC_VERB_SET_POWER_STATE, parm);
5638 } else {
5639 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5640 snd_hda_codec_write(codec, 0x31, 0,
5641 AC_VERB_SET_POWER_STATE, parm);
5642 snd_hda_codec_write(codec, 0x17, 0,
5643 AC_VERB_SET_POWER_STATE, parm);
5644 snd_hda_codec_write(codec, 0x3b, 0,
5645 AC_VERB_SET_POWER_STATE, parm);
5646 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005647 /* MW9 (21h) */
5648 if (imux_is_smixer || !is_aa_path_mute(codec))
5649 snd_hda_codec_write(codec, 0x21, 0,
5650 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5651 else
5652 snd_hda_codec_write(codec, 0x21, 0,
5653 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5654}
Lydia Wang25eaba22009-10-10 19:08:43 +08005655
5656/* patch for vt2002P */
5657static int patch_vt2002P(struct hda_codec *codec)
5658{
5659 struct via_spec *spec;
5660 int err;
5661
5662 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005663 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08005664 if (spec == NULL)
5665 return -ENOMEM;
5666
Lydia Wang25eaba22009-10-10 19:08:43 +08005667 /* automatic parse from the BIOS config */
5668 err = vt2002P_parse_auto_config(codec);
5669 if (err < 0) {
5670 via_free(codec);
5671 return err;
5672 } else if (!err) {
5673 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5674 "from BIOS. Using genenic mode...\n");
5675 }
5676
Lydia Wang118909562011-03-23 17:57:34 +08005677 if (spec->codec_type == VT1802)
5678 spec->init_verbs[spec->num_iverbs++] =
5679 vt1802_volume_init_verbs;
5680 else
5681 spec->init_verbs[spec->num_iverbs++] =
5682 vt2002P_volume_init_verbs;
Lydia Wang25eaba22009-10-10 19:08:43 +08005683
Lydia Wang118909562011-03-23 17:57:34 +08005684 if (spec->codec_type == VT1802)
5685 spec->init_verbs[spec->num_iverbs++] =
5686 vt1802_uniwill_init_verbs;
5687 else
5688 spec->init_verbs[spec->num_iverbs++] =
5689 vt2002P_uniwill_init_verbs;
5690
Lydia Wang25eaba22009-10-10 19:08:43 +08005691 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5692 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5693
Lydia Wang25eaba22009-10-10 19:08:43 +08005694 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5695
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005696 if (spec->adc_nids && spec->input_mux) {
Lydia Wang25eaba22009-10-10 19:08:43 +08005697 override_mic_boost(codec, 0x2b, 0, 3, 40);
5698 override_mic_boost(codec, 0x29, 0, 3, 40);
5699 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5700 spec->num_mixers++;
5701 }
5702
5703 codec->patch_ops = via_patch_ops;
5704
5705 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005706 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wang25eaba22009-10-10 19:08:43 +08005707
5708#ifdef CONFIG_SND_HDA_POWER_SAVE
5709 spec->loopback.amplist = vt2002P_loopbacks;
5710#endif
5711
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005712 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08005713 return 0;
5714}
Lydia Wangab6734e2009-10-10 19:08:46 +08005715
5716/* for vt1812 */
5717
5718/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005719static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005720 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5721 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5722 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5723 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5724 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5725 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5726 HDA_INPUT),
5727 {
5728 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5729 /* The multiple "Capture Source" controls confuse alsamixer
5730 * So call somewhat different..
5731 */
5732 .name = "Input Source",
5733 .count = 2,
5734 .info = via_mux_enum_info,
5735 .get = via_mux_enum_get,
5736 .put = via_mux_enum_put,
5737 },
5738 { } /* end */
5739};
5740
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005741static const struct hda_verb vt1812_volume_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005742 /*
5743 * Unmute ADC0-1 and set the default input to mic-in
5744 */
5745 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5746 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5747
5748
5749 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5750 * mixer widget
5751 */
5752 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5753 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5754 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5755 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5756 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5757 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5758
5759 /* MUX Indices: Mic = 0 */
5760 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5761 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5762
5763 /* PW9 Output enable */
5764 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5765
5766 /* Enable Boost Volume backdoor */
5767 {0x1, 0xfb9, 0x24},
5768
5769 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5770 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5771 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5772 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5773 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5774 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5775 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5776 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5777 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5778 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5779 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5780
5781 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5782 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5783 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5784 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5785 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5786 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5787
5788 /* Enable AOW0 to MW9 */
5789 {0x1, 0xfb8, 0xa8},
5790 { }
5791};
5792
5793
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005794static const struct hda_verb vt1812_uniwill_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005795 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5796 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5797 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5798 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5799 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5800 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5801 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5802 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5803 { }
5804};
5805
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005806static const struct hda_pcm_stream vt1812_pcm_analog_playback = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005807 .substreams = 2,
5808 .channels_min = 2,
5809 .channels_max = 2,
5810 .nid = 0x8, /* NID to query formats and rates */
5811 .ops = {
5812 .open = via_playback_pcm_open,
5813 .prepare = via_playback_multi_pcm_prepare,
5814 .cleanup = via_playback_multi_pcm_cleanup,
5815 .close = via_pcm_open_close,
5816 },
5817};
5818
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005819static const struct hda_pcm_stream vt1812_pcm_analog_capture = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005820 .substreams = 2,
5821 .channels_min = 2,
5822 .channels_max = 2,
5823 .nid = 0x10, /* NID to query formats and rates */
5824 .ops = {
5825 .open = via_pcm_open_close,
5826 .prepare = via_capture_pcm_prepare,
5827 .cleanup = via_capture_pcm_cleanup,
5828 .close = via_pcm_open_close,
5829 },
5830};
5831
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005832static const struct hda_pcm_stream vt1812_pcm_digital_playback = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005833 .substreams = 1,
5834 .channels_min = 2,
5835 .channels_max = 2,
Lydia Wangab6734e2009-10-10 19:08:46 +08005836 /* NID is set in via_build_pcms */
5837 .ops = {
5838 .open = via_dig_playback_pcm_open,
5839 .close = via_dig_playback_pcm_close,
5840 .prepare = via_dig_playback_pcm_prepare,
5841 .cleanup = via_dig_playback_pcm_cleanup
5842 },
5843};
5844/* fill in the dac_nids table from the parsed pin configuration */
5845static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5846 const struct auto_pin_cfg *cfg)
5847{
5848 spec->multiout.num_dacs = 1;
5849 spec->multiout.dac_nids = spec->private_dac_nids;
5850 if (cfg->line_out_pins[0])
Takashi Iwaidda14412011-05-02 11:29:30 +02005851 spec->private_dac_nids[0] = 0x8;
Lydia Wangab6734e2009-10-10 19:08:46 +08005852 return 0;
5853}
5854
5855
5856/* add playback controls from the parsed DAC table */
5857static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5858 const struct auto_pin_cfg *cfg)
5859{
5860 int err;
5861
5862 if (!cfg->line_out_pins[0])
5863 return -1;
5864
5865 /* Line-Out: PortE */
5866 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Takashi Iwai3d83e572010-04-14 14:36:23 +02005867 "Front Playback Volume",
Lydia Wangab6734e2009-10-10 19:08:46 +08005868 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5869 if (err < 0)
5870 return err;
5871 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
Takashi Iwai3d83e572010-04-14 14:36:23 +02005872 "Front Playback Switch",
Lydia Wangab6734e2009-10-10 19:08:46 +08005873 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5874 if (err < 0)
5875 return err;
5876
5877 return 0;
5878}
5879
5880static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5881{
5882 int err;
5883
5884 if (!pin)
5885 return 0;
5886
5887 spec->multiout.hp_nid = 0x9;
5888 spec->hp_independent_mode_index = 1;
5889
5890
5891 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5892 "Headphone Playback Volume",
5893 HDA_COMPOSE_AMP_VAL(
5894 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5895 if (err < 0)
5896 return err;
5897
5898 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5899 "Headphone Playback Switch",
5900 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5901 if (err < 0)
5902 return err;
5903
5904 create_hp_imux(spec);
5905 return 0;
5906}
5907
5908/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005909static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangab6734e2009-10-10 19:08:46 +08005910 const struct auto_pin_cfg *cfg)
5911{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005912 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
Lydia Wangab6734e2009-10-10 19:08:46 +08005913}
5914
5915static int vt1812_parse_auto_config(struct hda_codec *codec)
5916{
5917 struct via_spec *spec = codec->spec;
5918 int err;
5919
5920
5921 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5922 if (err < 0)
5923 return err;
5924 fill_dig_outs(codec);
5925 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5926 if (err < 0)
5927 return err;
5928
5929 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5930 return 0; /* can't find valid BIOS pin config */
5931
5932 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5933 if (err < 0)
5934 return err;
5935 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5936 if (err < 0)
5937 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005938 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangab6734e2009-10-10 19:08:46 +08005939 if (err < 0)
5940 return err;
5941
5942 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5943
5944 fill_dig_outs(codec);
5945
5946 if (spec->kctls.list)
5947 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5948
5949 spec->input_mux = &spec->private_imux[0];
5950
5951 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005952 via_hp_build(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08005953
5954 return 1;
5955}
5956
5957#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005958static const struct hda_amp_list vt1812_loopbacks[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005959 { 0x21, HDA_INPUT, 0 },
5960 { 0x21, HDA_INPUT, 1 },
5961 { 0x21, HDA_INPUT, 2 },
5962 { } /* end */
5963};
5964#endif
5965
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005966static void set_widgets_power_state_vt1812(struct hda_codec *codec)
5967{
5968 struct via_spec *spec = codec->spec;
5969 int imux_is_smixer =
5970 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5971 unsigned int parm;
5972 unsigned int present;
5973 /* MUX10 (1eh) = stereo mixer */
5974 imux_is_smixer =
5975 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
5976 /* inputs */
5977 /* PW 5/6/7 (29h/2ah/2bh) */
5978 parm = AC_PWRST_D3;
5979 set_pin_power_state(codec, 0x29, &parm);
5980 set_pin_power_state(codec, 0x2a, &parm);
5981 set_pin_power_state(codec, 0x2b, &parm);
5982 parm = AC_PWRST_D0;
5983 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
5984 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5985 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5986 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5987 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5988
5989 /* outputs */
5990 /* AOW0 (8h)*/
5991 snd_hda_codec_write(codec, 0x8, 0,
5992 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5993
5994 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5995 parm = AC_PWRST_D3;
5996 set_pin_power_state(codec, 0x28, &parm);
5997 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5998 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
5999
6000 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
6001 parm = AC_PWRST_D3;
6002 set_pin_power_state(codec, 0x25, &parm);
6003 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
6004 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
6005 if (spec->hp_independent_mode)
6006 snd_hda_codec_write(codec, 0x9, 0,
6007 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6008
6009 /* Internal Speaker */
6010 /* PW0 (24h), MW0(14h), MUX0(34h) */
6011 present = snd_hda_jack_detect(codec, 0x25);
6012
6013 parm = AC_PWRST_D3;
6014 set_pin_power_state(codec, 0x24, &parm);
6015 if (present) {
6016 snd_hda_codec_write(codec, 0x14, 0,
6017 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6018 snd_hda_codec_write(codec, 0x34, 0,
6019 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6020 } else {
6021 snd_hda_codec_write(codec, 0x14, 0,
6022 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6023 snd_hda_codec_write(codec, 0x34, 0,
6024 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6025 }
6026
6027
6028 /* Mono Out */
6029 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6030 present = snd_hda_jack_detect(codec, 0x28);
6031
6032 parm = AC_PWRST_D3;
6033 set_pin_power_state(codec, 0x31, &parm);
6034 if (present) {
6035 snd_hda_codec_write(codec, 0x1c, 0,
6036 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6037 snd_hda_codec_write(codec, 0x3c, 0,
6038 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6039 snd_hda_codec_write(codec, 0x3e, 0,
6040 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6041 } else {
6042 snd_hda_codec_write(codec, 0x1c, 0,
6043 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6044 snd_hda_codec_write(codec, 0x3c, 0,
6045 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6046 snd_hda_codec_write(codec, 0x3e, 0,
6047 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6048 }
6049
6050 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6051 parm = AC_PWRST_D3;
6052 set_pin_power_state(codec, 0x33, &parm);
6053 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6054 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6055
6056}
Lydia Wangab6734e2009-10-10 19:08:46 +08006057
6058/* patch for vt1812 */
6059static int patch_vt1812(struct hda_codec *codec)
6060{
6061 struct via_spec *spec;
6062 int err;
6063
6064 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01006065 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08006066 if (spec == NULL)
6067 return -ENOMEM;
6068
Lydia Wangab6734e2009-10-10 19:08:46 +08006069 /* automatic parse from the BIOS config */
6070 err = vt1812_parse_auto_config(codec);
6071 if (err < 0) {
6072 via_free(codec);
6073 return err;
6074 } else if (!err) {
6075 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6076 "from BIOS. Using genenic mode...\n");
6077 }
6078
6079
6080 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6081 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6082
Lydia Wangab6734e2009-10-10 19:08:46 +08006083 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6084 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6085
Lydia Wangab6734e2009-10-10 19:08:46 +08006086 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6087
Takashi Iwaia766d0d2011-06-17 09:01:29 +02006088 if (spec->adc_nids && spec->input_mux) {
Lydia Wangab6734e2009-10-10 19:08:46 +08006089 override_mic_boost(codec, 0x2b, 0, 3, 40);
6090 override_mic_boost(codec, 0x29, 0, 3, 40);
6091 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6092 spec->num_mixers++;
6093 }
6094
6095 codec->patch_ops = via_patch_ops;
6096
6097 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11006098 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangab6734e2009-10-10 19:08:46 +08006099
6100#ifdef CONFIG_SND_HDA_POWER_SAVE
6101 spec->loopback.amplist = vt1812_loopbacks;
6102#endif
6103
Lydia Wang3e95b9a2011-03-23 15:13:28 +08006104 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08006105 return 0;
6106}
6107
Joseph Chanc577b8a2006-11-29 15:29:40 +01006108/*
6109 * patch entries
6110 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02006111static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01006112 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6113 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6114 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6115 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6116 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006117 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006118 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006119 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006120 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006121 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006122 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006123 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006124 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006125 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006126 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006127 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006128 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006129 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006130 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006131 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006132 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006133 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006134 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006135 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006136 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006137 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006138 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006139 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006140 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006141 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006142 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006143 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006144 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006145 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006146 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006147 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006148 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006149 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006150 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006151 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006152 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006153 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006154 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006155 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08006156 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08006157 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006158 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006159 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006160 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006161 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006162 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006163 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006164 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006165 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006166 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006167 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006168 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006169 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006170 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006171 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006172 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006173 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006174 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006175 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006176 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006177 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006178 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006179 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08006180 { .id = 0x11060428, .name = "VT1718S",
6181 .patch = patch_vt1718S},
6182 { .id = 0x11064428, .name = "VT1718S",
6183 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08006184 { .id = 0x11060441, .name = "VT2020",
6185 .patch = patch_vt1718S},
6186 { .id = 0x11064441, .name = "VT1828S",
6187 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08006188 { .id = 0x11060433, .name = "VT1716S",
6189 .patch = patch_vt1716S},
6190 { .id = 0x1106a721, .name = "VT1716S",
6191 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08006192 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6193 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08006194 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08006195 { .id = 0x11060440, .name = "VT1818S",
6196 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08006197 { .id = 0x11060446, .name = "VT1802",
6198 .patch = patch_vt2002P},
6199 { .id = 0x11068446, .name = "VT1802",
6200 .patch = patch_vt2002P},
Joseph Chanc577b8a2006-11-29 15:29:40 +01006201 {} /* terminator */
6202};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006203
6204MODULE_ALIAS("snd-hda-codec-id:1106*");
6205
6206static struct hda_codec_preset_list via_list = {
6207 .preset = snd_hda_preset_via,
6208 .owner = THIS_MODULE,
6209};
6210
6211MODULE_LICENSE("GPL");
6212MODULE_DESCRIPTION("VIA HD-audio codec");
6213
6214static int __init patch_via_init(void)
6215{
6216 return snd_hda_add_codec_preset(&via_list);
6217}
6218
6219static void __exit patch_via_exit(void)
6220{
6221 snd_hda_delete_codec_preset(&via_list);
6222}
6223
6224module_init(patch_via_init)
6225module_exit(patch_via_exit)