blob: 18f2a135c026921958d9af26177935cf984387b5 [file] [log] [blame]
Joseph Chanc577b8a2006-11-29 15:29:40 +01001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Lydia Wang8e865972009-10-10 19:08:52 +08004 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
Joseph Chanc577b8a2006-11-29 15:29:40 +01005 *
Lydia Wang8e865972009-10-10 19:08:52 +08006 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
Joseph Chanc577b8a2006-11-29 15:29:40 +01008 *
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24/* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
Lydia Wang377ff312009-10-10 19:08:55 +080025/* */
Joseph Chanc577b8a2006-11-29 15:29:40 +010026/* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
Lydia Wang377ff312009-10-10 19:08:55 +080027/* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28/* 2006-08-02 Lydia Wang Add support to VT1709 codec */
Joseph Chanc577b8a2006-11-29 15:29:40 +010029/* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
Lydia Wang377ff312009-10-10 19:08:55 +080030/* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31/* 2007-09-17 Lydia Wang Add VT1708B codec support */
Harald Welte76d9b0d2008-09-09 15:50:37 +080032/* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
Harald Weltefb4cb772008-09-09 15:53:36 +080033/* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
Lydia Wang377ff312009-10-10 19:08:55 +080034/* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35/* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36/* 2008-04-09 Lydia Wang Add Independent HP feature */
Harald Welte98aa34c2008-09-09 16:02:09 +080037/* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
Lydia Wang377ff312009-10-10 19:08:55 +080038/* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
Lydia Wang8e865972009-10-10 19:08:52 +080039/* 2009-02-16 Logan Li Add support for VT1718S */
40/* 2009-03-13 Logan Li Add support for VT1716S */
41/* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42/* 2009-07-08 Lydia Wang Add support for VT2002P */
43/* 2009-07-21 Lydia Wang Add support for VT1812 */
Lydia Wang36dd5c42009-10-20 13:18:04 +080044/* 2009-09-19 Lydia Wang Add support for VT1818S */
Lydia Wang377ff312009-10-10 19:08:55 +080045/* */
Joseph Chanc577b8a2006-11-29 15:29:40 +010046/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
47
48
Joseph Chanc577b8a2006-11-29 15:29:40 +010049#include <linux/init.h>
50#include <linux/delay.h>
51#include <linux/slab.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010052#include <sound/core.h>
Harald Welte0aa62ae2008-09-09 15:58:27 +080053#include <sound/asoundef.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010054#include "hda_codec.h"
55#include "hda_local.h"
Joseph Chanc577b8a2006-11-29 15:29:40 +010056
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010057#define NID_MAPPING (-1)
58
Joseph Chanc577b8a2006-11-29 15:29:40 +010059/* amp values */
60#define AMP_VAL_IDX_SHIFT 19
61#define AMP_VAL_IDX_MASK (0x0f<<19)
62
Joseph Chanc577b8a2006-11-29 15:29:40 +010063/* Pin Widget NID */
64#define VT1708_HP_NID 0x13
65#define VT1708_DIGOUT_NID 0x14
66#define VT1708_DIGIN_NID 0x16
Josepch Chanf7278fd2007-12-13 16:40:40 +010067#define VT1708_DIGIN_PIN 0x26
Harald Welted949cac2008-09-09 15:56:01 +080068#define VT1708_HP_PIN_NID 0x20
69#define VT1708_CD_PIN_NID 0x24
Joseph Chanc577b8a2006-11-29 15:29:40 +010070
71#define VT1709_HP_DAC_NID 0x28
72#define VT1709_DIGOUT_NID 0x13
73#define VT1709_DIGIN_NID 0x17
Josepch Chanf7278fd2007-12-13 16:40:40 +010074#define VT1709_DIGIN_PIN 0x25
75
76#define VT1708B_HP_NID 0x25
77#define VT1708B_DIGOUT_NID 0x12
78#define VT1708B_DIGIN_NID 0x15
79#define VT1708B_DIGIN_PIN 0x21
Joseph Chanc577b8a2006-11-29 15:29:40 +010080
Harald Welted949cac2008-09-09 15:56:01 +080081#define VT1708S_HP_NID 0x25
82#define VT1708S_DIGOUT_NID 0x12
83
84#define VT1702_HP_NID 0x17
85#define VT1702_DIGOUT_NID 0x11
86
Harald Welted7426322008-09-15 22:43:23 +080087enum VIA_HDA_CODEC {
88 UNKNOWN = -1,
89 VT1708,
90 VT1709_10CH,
91 VT1709_6CH,
92 VT1708B_8CH,
93 VT1708B_4CH,
94 VT1708S,
Lydia Wang518bf3b2009-10-10 19:07:29 +080095 VT1708BCE,
Harald Welted7426322008-09-15 22:43:23 +080096 VT1702,
Lydia Wangeb7188c2009-10-10 19:08:34 +080097 VT1718S,
Lydia Wangf3db4232009-10-10 19:08:41 +080098 VT1716S,
Lydia Wang25eaba22009-10-10 19:08:43 +080099 VT2002P,
Lydia Wangab6734e2009-10-10 19:08:46 +0800100 VT1812,
Lydia Wang118909562011-03-23 17:57:34 +0800101 VT1802,
Harald Welted7426322008-09-15 22:43:23 +0800102 CODEC_TYPES,
103};
104
Lydia Wang118909562011-03-23 17:57:34 +0800105#define VT2002P_COMPATIBLE(spec) \
106 ((spec)->codec_type == VT2002P ||\
107 (spec)->codec_type == VT1812 ||\
108 (spec)->codec_type == VT1802)
109
Takashi Iwai4a796162011-06-17 17:53:38 +0200110struct nid_path {
111 int depth;
112 hda_nid_t path[5];
113 short idx[5];
114};
115
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800116struct via_spec {
117 /* codec parameterization */
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200118 const struct snd_kcontrol_new *mixers[6];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800119 unsigned int num_mixers;
120
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200121 const struct hda_verb *init_verbs[5];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800122 unsigned int num_iverbs;
123
Takashi Iwai82673bc2011-06-17 16:24:21 +0200124 char stream_name_analog[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200125 const struct hda_pcm_stream *stream_analog_playback;
126 const struct hda_pcm_stream *stream_analog_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800127
Takashi Iwai82673bc2011-06-17 16:24:21 +0200128 char stream_name_digital[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200129 const struct hda_pcm_stream *stream_digital_playback;
130 const struct hda_pcm_stream *stream_digital_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800131
132 /* playback */
133 struct hda_multi_out multiout;
134 hda_nid_t slave_dig_outs[2];
135
Takashi Iwai4a796162011-06-17 17:53:38 +0200136 struct nid_path out_path[4];
137 struct nid_path hp_path;
138 struct nid_path hp_dep_path;
139
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800140 /* capture */
141 unsigned int num_adc_nids;
Takashi Iwaia766d0d2011-06-17 09:01:29 +0200142 hda_nid_t adc_nids[3];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800143 hda_nid_t mux_nids[3];
Takashi Iwai620e2b22011-06-17 17:19:19 +0200144 hda_nid_t aa_mix_nid;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800145 hda_nid_t dig_in_nid;
146 hda_nid_t dig_in_pin;
147
148 /* capture source */
149 const struct hda_input_mux *input_mux;
150 unsigned int cur_mux[3];
151
152 /* PCM information */
153 struct hda_pcm pcm_rec[3];
154
155 /* dynamic controls, init_verbs and input_mux */
156 struct auto_pin_cfg autocfg;
157 struct snd_array kctls;
158 struct hda_input_mux private_imux[2];
159 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
160
161 /* HP mode source */
162 const struct hda_input_mux *hp_mux;
163 unsigned int hp_independent_mode;
164 unsigned int hp_independent_mode_index;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200165 unsigned int can_smart51;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800166 unsigned int smart51_enabled;
Lydia Wangf3db4232009-10-10 19:08:41 +0800167 unsigned int dmic_enabled;
Takashi Iwai24088a52011-06-17 16:59:21 +0200168 unsigned int no_pin_power_ctl;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800169 enum VIA_HDA_CODEC codec_type;
170
171 /* work to check hp jack state */
172 struct hda_codec *codec;
173 struct delayed_work vt1708_hp_work;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200174 int vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800175 int vt1708_hp_present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800176
177 void (*set_widgets_power_state)(struct hda_codec *codec);
178
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800179#ifdef CONFIG_SND_HDA_POWER_SAVE
180 struct hda_loopback_check loopback;
181#endif
182};
183
Lydia Wang0341ccd2011-03-22 16:25:03 +0800184static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100185static struct via_spec * via_new_spec(struct hda_codec *codec)
186{
187 struct via_spec *spec;
188
189 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
190 if (spec == NULL)
191 return NULL;
192
193 codec->spec = spec;
194 spec->codec = codec;
Lydia Wang0341ccd2011-03-22 16:25:03 +0800195 spec->codec_type = get_codec_type(codec);
196 /* VT1708BCE & VT1708S are almost same */
197 if (spec->codec_type == VT1708BCE)
198 spec->codec_type = VT1708S;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100199 return spec;
200}
201
Lydia Wang744ff5f2009-10-10 19:07:26 +0800202static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800203{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800204 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800205 u16 ven_id = vendor_id >> 16;
206 u16 dev_id = vendor_id & 0xffff;
207 enum VIA_HDA_CODEC codec_type;
208
209 /* get codec type */
210 if (ven_id != 0x1106)
211 codec_type = UNKNOWN;
212 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
213 codec_type = VT1708;
214 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
215 codec_type = VT1709_10CH;
216 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
217 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800218 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800219 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800220 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
221 codec_type = VT1708BCE;
222 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800223 codec_type = VT1708B_4CH;
224 else if ((dev_id & 0xfff) == 0x397
225 && (dev_id >> 12) < 8)
226 codec_type = VT1708S;
227 else if ((dev_id & 0xfff) == 0x398
228 && (dev_id >> 12) < 8)
229 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800230 else if ((dev_id & 0xfff) == 0x428
231 && (dev_id >> 12) < 8)
232 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800233 else if (dev_id == 0x0433 || dev_id == 0xa721)
234 codec_type = VT1716S;
Lydia Wangbb3c6bf2009-10-10 19:08:39 +0800235 else if (dev_id == 0x0441 || dev_id == 0x4441)
236 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800237 else if (dev_id == 0x0438 || dev_id == 0x4438)
238 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800239 else if (dev_id == 0x0448)
240 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800241 else if (dev_id == 0x0440)
242 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800243 else if ((dev_id & 0xfff) == 0x446)
244 codec_type = VT1802;
Harald Welted7426322008-09-15 22:43:23 +0800245 else
246 codec_type = UNKNOWN;
247 return codec_type;
248};
249
Lydia Wangec7e7e42011-03-24 12:43:44 +0800250#define VIA_JACK_EVENT 0x20
Harald Welte69e52a82008-09-09 15:57:32 +0800251#define VIA_HP_EVENT 0x01
252#define VIA_GPIO_EVENT 0x02
Lydia Wangec7e7e42011-03-24 12:43:44 +0800253#define VIA_MONO_EVENT 0x03
254#define VIA_SPEAKER_EVENT 0x04
255#define VIA_BIND_HP_EVENT 0x05
Harald Welte69e52a82008-09-09 15:57:32 +0800256
Joseph Chanc577b8a2006-11-29 15:29:40 +0100257enum {
258 VIA_CTL_WIDGET_VOL,
259 VIA_CTL_WIDGET_MUTE,
Lydia Wangf5271102009-10-10 19:07:35 +0800260 VIA_CTL_WIDGET_ANALOG_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800261 VIA_CTL_WIDGET_BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100262};
263
264enum {
Harald Welteeb14a462008-09-09 15:40:38 +0800265 AUTO_SEQ_FRONT = 0,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100266 AUTO_SEQ_SURROUND,
267 AUTO_SEQ_CENLFE,
268 AUTO_SEQ_SIDE
269};
270
Lydia Wangf5271102009-10-10 19:07:35 +0800271static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800272static int is_aa_path_mute(struct hda_codec *codec);
273
274static void vt1708_start_hp_work(struct via_spec *spec)
275{
276 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
277 return;
278 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200279 !spec->vt1708_jack_detect);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800280 if (!delayed_work_pending(&spec->vt1708_hp_work))
281 schedule_delayed_work(&spec->vt1708_hp_work,
282 msecs_to_jiffies(100));
283}
284
285static void vt1708_stop_hp_work(struct via_spec *spec)
286{
287 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
288 return;
289 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
290 && !is_aa_path_mute(spec->codec))
291 return;
292 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200293 !spec->vt1708_jack_detect);
Tejun Heo5b84ba22010-12-11 17:51:26 +0100294 cancel_delayed_work_sync(&spec->vt1708_hp_work);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800295}
Lydia Wangf5271102009-10-10 19:07:35 +0800296
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800297static void set_widgets_power_state(struct hda_codec *codec)
298{
299 struct via_spec *spec = codec->spec;
300 if (spec->set_widgets_power_state)
301 spec->set_widgets_power_state(codec);
302}
Lydia Wang25eaba22009-10-10 19:08:43 +0800303
Lydia Wangf5271102009-10-10 19:07:35 +0800304static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
305 struct snd_ctl_elem_value *ucontrol)
306{
307 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
308 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
309
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800310 set_widgets_power_state(codec);
Lydia Wangf5271102009-10-10 19:07:35 +0800311 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800312 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
313 if (is_aa_path_mute(codec))
314 vt1708_start_hp_work(codec->spec);
315 else
316 vt1708_stop_hp_work(codec->spec);
317 }
Lydia Wangf5271102009-10-10 19:07:35 +0800318 return change;
319}
320
321/* modify .put = snd_hda_mixer_amp_switch_put */
322#define ANALOG_INPUT_MUTE \
323 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
324 .name = NULL, \
325 .index = 0, \
326 .info = snd_hda_mixer_amp_switch_info, \
327 .get = snd_hda_mixer_amp_switch_get, \
328 .put = analog_input_switch_put, \
329 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
330
Lydia Wang25eaba22009-10-10 19:08:43 +0800331static void via_hp_bind_automute(struct hda_codec *codec);
332
333static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
334 struct snd_ctl_elem_value *ucontrol)
335{
336 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
337 struct via_spec *spec = codec->spec;
338 int i;
339 int change = 0;
340
341 long *valp = ucontrol->value.integer.value;
342 int lmute, rmute;
343 if (strstr(kcontrol->id.name, "Switch") == NULL) {
344 snd_printd("Invalid control!\n");
345 return change;
346 }
347 change = snd_hda_mixer_amp_switch_put(kcontrol,
348 ucontrol);
349 /* Get mute value */
350 lmute = *valp ? 0 : HDA_AMP_MUTE;
351 valp++;
352 rmute = *valp ? 0 : HDA_AMP_MUTE;
353
354 /* Set hp pins */
355 if (!spec->hp_independent_mode) {
356 for (i = 0; i < spec->autocfg.hp_outs; i++) {
357 snd_hda_codec_amp_update(
358 codec, spec->autocfg.hp_pins[i],
359 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
360 lmute);
361 snd_hda_codec_amp_update(
362 codec, spec->autocfg.hp_pins[i],
363 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
364 rmute);
365 }
366 }
367
368 if (!lmute && !rmute) {
369 /* Line Outs */
370 for (i = 0; i < spec->autocfg.line_outs; i++)
371 snd_hda_codec_amp_stereo(
372 codec, spec->autocfg.line_out_pins[i],
373 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
374 /* Speakers */
375 for (i = 0; i < spec->autocfg.speaker_outs; i++)
376 snd_hda_codec_amp_stereo(
377 codec, spec->autocfg.speaker_pins[i],
378 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
379 /* unmute */
380 via_hp_bind_automute(codec);
381
382 } else {
383 if (lmute) {
384 /* Mute all left channels */
385 for (i = 1; i < spec->autocfg.line_outs; i++)
386 snd_hda_codec_amp_update(
387 codec,
388 spec->autocfg.line_out_pins[i],
389 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
390 lmute);
391 for (i = 0; i < spec->autocfg.speaker_outs; i++)
392 snd_hda_codec_amp_update(
393 codec,
394 spec->autocfg.speaker_pins[i],
395 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
396 lmute);
397 }
398 if (rmute) {
399 /* mute all right channels */
400 for (i = 1; i < spec->autocfg.line_outs; i++)
401 snd_hda_codec_amp_update(
402 codec,
403 spec->autocfg.line_out_pins[i],
404 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
405 rmute);
406 for (i = 0; i < spec->autocfg.speaker_outs; i++)
407 snd_hda_codec_amp_update(
408 codec,
409 spec->autocfg.speaker_pins[i],
410 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
411 rmute);
412 }
413 }
414 return change;
415}
416
417#define BIND_PIN_MUTE \
418 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
419 .name = NULL, \
420 .index = 0, \
421 .info = snd_hda_mixer_amp_switch_info, \
422 .get = snd_hda_mixer_amp_switch_get, \
423 .put = bind_pin_switch_put, \
424 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
425
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200426static const struct snd_kcontrol_new via_control_templates[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100427 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
428 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Lydia Wangf5271102009-10-10 19:07:35 +0800429 ANALOG_INPUT_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800430 BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100431};
432
Lydia Wangab6734e2009-10-10 19:08:46 +0800433
Joseph Chanc577b8a2006-11-29 15:29:40 +0100434/* add dynamic controls */
Takashi Iwai291c9e32011-06-17 16:15:26 +0200435static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
436 const struct snd_kcontrol_new *tmpl,
437 const char *name)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100438{
439 struct snd_kcontrol_new *knew;
440
Takashi Iwai603c4012008-07-30 15:01:44 +0200441 snd_array_init(&spec->kctls, sizeof(*knew), 32);
442 knew = snd_array_new(&spec->kctls);
443 if (!knew)
Takashi Iwai291c9e32011-06-17 16:15:26 +0200444 return NULL;
445 *knew = *tmpl;
446 if (!name)
447 name = tmpl->name;
448 if (name) {
449 knew->name = kstrdup(name, GFP_KERNEL);
450 if (!knew->name)
451 return NULL;
452 }
453 return knew;
454}
455
456static int __via_add_control(struct via_spec *spec, int type, const char *name,
457 int idx, unsigned long val)
458{
459 struct snd_kcontrol_new *knew;
460
461 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
462 if (!knew)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100463 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100464 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100465 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100466 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100467 return 0;
468}
469
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200470#define via_add_control(spec, type, name, val) \
471 __via_add_control(spec, type, name, 0, val)
472
Takashi Iwai291c9e32011-06-17 16:15:26 +0200473#define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100474
Takashi Iwai603c4012008-07-30 15:01:44 +0200475static void via_free_kctls(struct hda_codec *codec)
476{
477 struct via_spec *spec = codec->spec;
478
479 if (spec->kctls.list) {
480 struct snd_kcontrol_new *kctl = spec->kctls.list;
481 int i;
482 for (i = 0; i < spec->kctls.used; i++)
483 kfree(kctl[i].name);
484 }
485 snd_array_free(&spec->kctls);
486}
487
Joseph Chanc577b8a2006-11-29 15:29:40 +0100488/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800489static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200490 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100491{
492 char name[32];
493 int err;
494
495 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200496 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100497 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
498 if (err < 0)
499 return err;
500 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200501 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100502 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
503 if (err < 0)
504 return err;
505 return 0;
506}
507
508static void via_auto_set_output_and_unmute(struct hda_codec *codec,
509 hda_nid_t nid, int pin_type,
510 int dac_idx)
511{
512 /* set as output */
513 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
514 pin_type);
515 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
516 AMP_OUT_UNMUTE);
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200517 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
Lydia Wang377ff312009-10-10 19:08:55 +0800518 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200519 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100520}
521
522
523static void via_auto_init_multi_out(struct hda_codec *codec)
524{
525 struct via_spec *spec = codec->spec;
526 int i;
527
528 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
529 hda_nid_t nid = spec->autocfg.line_out_pins[i];
530 if (nid)
531 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
532 }
533}
534
535static void via_auto_init_hp_out(struct hda_codec *codec)
536{
537 struct via_spec *spec = codec->spec;
538 hda_nid_t pin;
Lydia Wang25eaba22009-10-10 19:08:43 +0800539 int i;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100540
Lydia Wang25eaba22009-10-10 19:08:43 +0800541 for (i = 0; i < spec->autocfg.hp_outs; i++) {
542 pin = spec->autocfg.hp_pins[i];
543 if (pin) /* connect to front */
544 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
545 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100546}
547
Takashi Iwaif4a78282011-06-17 18:46:48 +0200548static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
Clemens Ladisch32e01912010-07-12 16:28:50 +0200549
Joseph Chanc577b8a2006-11-29 15:29:40 +0100550static void via_auto_init_analog_input(struct hda_codec *codec)
551{
552 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200553 const struct auto_pin_cfg *cfg = &spec->autocfg;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200554 unsigned int ctl;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100555 int i;
556
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200557 for (i = 0; i < cfg->num_inputs; i++) {
558 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200559 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
Clemens Ladisch32e01912010-07-12 16:28:50 +0200560 ctl = PIN_OUT;
David Henningsson30649672011-02-21 10:23:18 +0100561 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
Clemens Ladisch32e01912010-07-12 16:28:50 +0200562 ctl = PIN_VREF50;
563 else
564 ctl = PIN_IN;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100565 snd_hda_codec_write(codec, nid, 0,
Clemens Ladisch32e01912010-07-12 16:28:50 +0200566 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100567 }
568}
Lydia Wangf5271102009-10-10 19:07:35 +0800569
570static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
571 unsigned int *affected_parm)
572{
573 unsigned parm;
574 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
575 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
576 >> AC_DEFCFG_MISC_SHIFT
577 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800578 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200579 unsigned present = 0;
580
581 no_presence |= spec->no_pin_power_ctl;
582 if (!no_presence)
583 present = snd_hda_jack_detect(codec, nid);
Takashi Iwaif4a78282011-06-17 18:46:48 +0200584 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
Lydia Wang1564b282009-10-10 19:07:52 +0800585 || ((no_presence || present)
586 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800587 *affected_parm = AC_PWRST_D0; /* if it's connected */
588 parm = AC_PWRST_D0;
589 } else
590 parm = AC_PWRST_D3;
591
592 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
593}
594
Takashi Iwai24088a52011-06-17 16:59:21 +0200595static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
596 struct snd_ctl_elem_info *uinfo)
597{
598 static const char * const texts[] = {
599 "Disabled", "Enabled"
600 };
601
602 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
603 uinfo->count = 1;
604 uinfo->value.enumerated.items = 2;
605 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
606 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
607 strcpy(uinfo->value.enumerated.name,
608 texts[uinfo->value.enumerated.item]);
609 return 0;
610}
611
612static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
613 struct snd_ctl_elem_value *ucontrol)
614{
615 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
616 struct via_spec *spec = codec->spec;
617 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
618 return 0;
619}
620
621static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
622 struct snd_ctl_elem_value *ucontrol)
623{
624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
625 struct via_spec *spec = codec->spec;
626 unsigned int val = !ucontrol->value.enumerated.item[0];
627
628 if (val == spec->no_pin_power_ctl)
629 return 0;
630 spec->no_pin_power_ctl = val;
631 set_widgets_power_state(codec);
632 return 1;
633}
634
635static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
636 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
637 .name = "Dynamic Power-Control",
638 .info = via_pin_power_ctl_info,
639 .get = via_pin_power_ctl_get,
640 .put = via_pin_power_ctl_put,
641};
642
643
Joseph Chanc577b8a2006-11-29 15:29:40 +0100644/*
645 * input MUX handling
646 */
647static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_info *uinfo)
649{
650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
651 struct via_spec *spec = codec->spec;
652 return snd_hda_input_mux_info(spec->input_mux, uinfo);
653}
654
655static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
656 struct snd_ctl_elem_value *ucontrol)
657{
658 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
659 struct via_spec *spec = codec->spec;
660 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
661
662 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
663 return 0;
664}
665
666static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_value *ucontrol)
668{
669 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670 struct via_spec *spec = codec->spec;
671 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800672 int ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100673
Takashi Iwai337b9d02009-07-07 18:18:59 +0200674 if (!spec->mux_nids[adc_idx])
675 return -EINVAL;
Lydia Wanga80e6e32009-10-10 19:07:55 +0800676 /* switch to D0 beofre change index */
677 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
678 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
679 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
680 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800681
682 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
683 spec->mux_nids[adc_idx],
684 &spec->cur_mux[adc_idx]);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800685 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800686 set_widgets_power_state(codec);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800687
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800688 return ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100689}
690
Harald Welte0aa62ae2008-09-09 15:58:27 +0800691static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_info *uinfo)
693{
694 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
695 struct via_spec *spec = codec->spec;
696 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
697}
698
699static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
700 struct snd_ctl_elem_value *ucontrol)
701{
702 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100703 hda_nid_t nid = kcontrol->private_value;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800704 unsigned int pinsel;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800705
Lydia Wangeb7188c2009-10-10 19:08:34 +0800706 /* use !! to translate conn sel 2 for VT1718S */
707 pinsel = !!snd_hda_codec_read(codec, nid, 0,
708 AC_VERB_GET_CONNECT_SEL,
709 0x00);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800710 ucontrol->value.enumerated.item[0] = pinsel;
711
712 return 0;
713}
714
Lydia Wang0713efe2009-10-10 19:07:43 +0800715static void activate_ctl(struct hda_codec *codec, const char *name, int active)
716{
717 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
718 if (ctl) {
719 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
720 ctl->vd[0].access |= active
721 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
722 snd_ctl_notify(codec->bus->card,
723 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
724 }
725}
726
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100727static hda_nid_t side_mute_channel(struct via_spec *spec)
728{
729 switch (spec->codec_type) {
730 case VT1708: return 0x1b;
731 case VT1709_10CH: return 0x29;
732 case VT1708B_8CH: /* fall thru */
733 case VT1708S: return 0x27;
Lydia Wange87885f2011-03-24 12:39:05 +0800734 case VT2002P: return 0x19;
735 case VT1802: return 0x15;
736 case VT1812: return 0x15;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100737 default: return 0;
738 }
739}
740
Lydia Wangcdc17842009-10-10 19:07:47 +0800741static int update_side_mute_status(struct hda_codec *codec)
742{
743 /* mute side channel */
744 struct via_spec *spec = codec->spec;
Lydia Wange87885f2011-03-24 12:39:05 +0800745 unsigned int parm;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100746 hda_nid_t sw3 = side_mute_channel(spec);
Lydia Wangcdc17842009-10-10 19:07:47 +0800747
Lydia Wange87885f2011-03-24 12:39:05 +0800748 if (sw3) {
749 if (VT2002P_COMPATIBLE(spec))
750 parm = spec->hp_independent_mode ?
751 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
752 else
753 parm = spec->hp_independent_mode ?
754 AMP_OUT_MUTE : AMP_OUT_UNMUTE;
755 snd_hda_codec_write(codec, sw3, 0,
756 AC_VERB_SET_AMP_GAIN_MUTE, parm);
757 if (spec->codec_type == VT1812)
758 snd_hda_codec_write(codec, 0x1d, 0,
759 AC_VERB_SET_AMP_GAIN_MUTE, parm);
760 }
Lydia Wangcdc17842009-10-10 19:07:47 +0800761 return 0;
762}
763
Harald Welte0aa62ae2008-09-09 15:58:27 +0800764static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
765 struct snd_ctl_elem_value *ucontrol)
766{
767 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
768 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100769 hda_nid_t nid = kcontrol->private_value;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800770 unsigned int pinsel = ucontrol->value.enumerated.item[0];
Lydia Wangcdc17842009-10-10 19:07:47 +0800771 /* Get Independent Mode index of headphone pin widget */
772 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
773 ? 1 : 0;
Lydia Wangce0e5a92011-03-22 16:22:37 +0800774 if (spec->codec_type == VT1718S)
775 snd_hda_codec_write(codec, nid, 0,
776 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
777 else
778 snd_hda_codec_write(codec, nid, 0,
779 AC_VERB_SET_CONNECT_SEL, pinsel);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800780
Lydia Wangce0e5a92011-03-22 16:22:37 +0800781 if (spec->codec_type == VT1812)
782 snd_hda_codec_write(codec, 0x35, 0,
783 AC_VERB_SET_CONNECT_SEL, pinsel);
Lydia Wangcdc17842009-10-10 19:07:47 +0800784 if (spec->multiout.hp_nid && spec->multiout.hp_nid
785 != spec->multiout.dac_nids[HDA_FRONT])
786 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
787 0, 0, 0);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800788
Lydia Wangcdc17842009-10-10 19:07:47 +0800789 update_side_mute_status(codec);
Lydia Wang0713efe2009-10-10 19:07:43 +0800790 /* update HP volume/swtich active state */
791 if (spec->codec_type == VT1708S
Lydia Wangeb7188c2009-10-10 19:08:34 +0800792 || spec->codec_type == VT1702
Lydia Wangf3db4232009-10-10 19:08:41 +0800793 || spec->codec_type == VT1718S
Lydia Wang25eaba22009-10-10 19:08:43 +0800794 || spec->codec_type == VT1716S
Lydia Wang118909562011-03-23 17:57:34 +0800795 || VT2002P_COMPATIBLE(spec)) {
Lydia Wang0713efe2009-10-10 19:07:43 +0800796 activate_ctl(codec, "Headphone Playback Volume",
797 spec->hp_independent_mode);
798 activate_ctl(codec, "Headphone Playback Switch",
799 spec->hp_independent_mode);
800 }
Lydia Wangce0e5a92011-03-22 16:22:37 +0800801 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800802 set_widgets_power_state(codec);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800803 return 0;
804}
805
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200806static const struct snd_kcontrol_new via_hp_mixer[2] = {
Harald Welte0aa62ae2008-09-09 15:58:27 +0800807 {
808 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
809 .name = "Independent HP",
Harald Welte0aa62ae2008-09-09 15:58:27 +0800810 .info = via_independent_hp_info,
811 .get = via_independent_hp_get,
812 .put = via_independent_hp_put,
813 },
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100814 {
815 .iface = NID_MAPPING,
816 .name = "Independent HP",
817 },
Harald Welte0aa62ae2008-09-09 15:58:27 +0800818};
819
Takashi Iwai3d83e572010-04-14 14:36:23 +0200820static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100821{
Takashi Iwai3d83e572010-04-14 14:36:23 +0200822 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100823 struct snd_kcontrol_new *knew;
824 hda_nid_t nid;
Takashi Iwai3d83e572010-04-14 14:36:23 +0200825 int nums;
826 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100827
828 switch (spec->codec_type) {
829 case VT1718S:
830 nid = 0x34;
831 break;
832 case VT2002P:
Lydia Wang118909562011-03-23 17:57:34 +0800833 case VT1802:
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100834 nid = 0x35;
835 break;
836 case VT1812:
837 nid = 0x3d;
838 break;
839 default:
840 nid = spec->autocfg.hp_pins[0];
841 break;
842 }
843
Lydia Wangee3c35c2011-03-22 16:26:36 +0800844 if (spec->codec_type != VT1708) {
845 nums = snd_hda_get_connections(codec, nid,
846 conn, HDA_MAX_CONNECTIONS);
847 if (nums <= 1)
848 return 0;
849 }
Takashi Iwai3d83e572010-04-14 14:36:23 +0200850
851 knew = via_clone_control(spec, &via_hp_mixer[0]);
852 if (knew == NULL)
853 return -ENOMEM;
854
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100855 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
856 knew->private_value = nid;
857
858 knew = via_clone_control(spec, &via_hp_mixer[1]);
859 if (knew == NULL)
860 return -ENOMEM;
861 knew->subdevice = side_mute_channel(spec);
862
863 return 0;
864}
865
Lydia Wang1564b282009-10-10 19:07:52 +0800866static void notify_aa_path_ctls(struct hda_codec *codec)
867{
868 int i;
869 struct snd_ctl_elem_id id;
Lydia Wang525566c2011-04-28 16:03:39 +0800870 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
871 struct snd_kcontrol *ctl;
Lydia Wang1564b282009-10-10 19:07:52 +0800872
873 memset(&id, 0, sizeof(id));
874 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
875 for (i = 0; i < ARRAY_SIZE(labels); i++) {
876 sprintf(id.name, "%s Playback Volume", labels[i]);
Lydia Wang525566c2011-04-28 16:03:39 +0800877 ctl = snd_hda_find_mixer_ctl(codec, id.name);
878 if (ctl)
879 snd_ctl_notify(codec->bus->card,
880 SNDRV_CTL_EVENT_MASK_VALUE,
881 &ctl->id);
Lydia Wang1564b282009-10-10 19:07:52 +0800882 }
883}
884
885static void mute_aa_path(struct hda_codec *codec, int mute)
886{
887 struct via_spec *spec = codec->spec;
Lydia Wang1564b282009-10-10 19:07:52 +0800888 int start_idx;
889 int end_idx;
890 int i;
891 /* get nid of MW0 and start & end index */
892 switch (spec->codec_type) {
893 case VT1708:
Lydia Wang1564b282009-10-10 19:07:52 +0800894 start_idx = 2;
895 end_idx = 4;
896 break;
897 case VT1709_10CH:
898 case VT1709_6CH:
Lydia Wang1564b282009-10-10 19:07:52 +0800899 start_idx = 2;
900 end_idx = 4;
901 break;
902 case VT1708B_8CH:
903 case VT1708B_4CH:
904 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +0800905 case VT1716S:
Lydia Wang1564b282009-10-10 19:07:52 +0800906 start_idx = 2;
907 end_idx = 4;
908 break;
Lydia Wangab657e02011-03-22 16:23:23 +0800909 case VT1718S:
Lydia Wangab657e02011-03-22 16:23:23 +0800910 start_idx = 1;
911 end_idx = 3;
912 break;
Lydia Wang1564b282009-10-10 19:07:52 +0800913 default:
914 return;
915 }
916 /* check AA path's mute status */
917 for (i = start_idx; i <= end_idx; i++) {
918 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200919 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid, HDA_INPUT, i,
Lydia Wang1564b282009-10-10 19:07:52 +0800920 HDA_AMP_MUTE, val);
921 }
922}
Takashi Iwaif4a78282011-06-17 18:46:48 +0200923
924static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
Lydia Wang1564b282009-10-10 19:07:52 +0800925{
Takashi Iwaif4a78282011-06-17 18:46:48 +0200926 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200927 const struct auto_pin_cfg *cfg = &spec->autocfg;
928 int i;
929
930 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwaif4a78282011-06-17 18:46:48 +0200931 unsigned int defcfg;
932 if (pin != cfg->inputs[i].pin)
933 continue;
934 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
935 return false;
936 defcfg = snd_hda_codec_get_pincfg(codec, pin);
937 if (snd_hda_get_input_pin_attr(defcfg) < INPUT_PIN_ATTR_NORMAL)
938 return false;
939 return true;
Lydia Wang1564b282009-10-10 19:07:52 +0800940 }
Takashi Iwaif4a78282011-06-17 18:46:48 +0200941 return false;
Lydia Wang1564b282009-10-10 19:07:52 +0800942}
943
944static int via_smart51_info(struct snd_kcontrol *kcontrol,
945 struct snd_ctl_elem_info *uinfo)
946{
947 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
948 uinfo->count = 1;
949 uinfo->value.integer.min = 0;
950 uinfo->value.integer.max = 1;
951 return 0;
952}
953
954static int via_smart51_get(struct snd_kcontrol *kcontrol,
955 struct snd_ctl_elem_value *ucontrol)
956{
957 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
958 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200959 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800960 int on = 1;
961 int i;
962
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200963 for (i = 0; i < cfg->num_inputs; i++) {
964 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200965 unsigned int ctl;
Takashi Iwai86e29592010-09-09 14:50:17 +0200966 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200967 spec->hp_independent_mode && spec->codec_type != VT1718S)
968 continue; /* ignore FMic for independent HP */
Takashi Iwaif4a78282011-06-17 18:46:48 +0200969 if (!is_smart51_pins(codec, nid))
970 continue;
971 ctl = snd_hda_codec_read(codec, nid, 0,
972 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200973 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
974 on = 0;
Lydia Wang1564b282009-10-10 19:07:52 +0800975 }
976 *ucontrol->value.integer.value = on;
977 return 0;
978}
979
980static int via_smart51_put(struct snd_kcontrol *kcontrol,
981 struct snd_ctl_elem_value *ucontrol)
982{
983 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
984 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200985 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800986 int out_in = *ucontrol->value.integer.value
987 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +0800988 int i;
989
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200990 for (i = 0; i < cfg->num_inputs; i++) {
991 hda_nid_t nid = cfg->inputs[i].pin;
992 unsigned int parm;
993
Takashi Iwai86e29592010-09-09 14:50:17 +0200994 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200995 spec->hp_independent_mode && spec->codec_type != VT1718S)
Lydia Wang1564b282009-10-10 19:07:52 +0800996 continue; /* don't retask FMic for independent HP */
Takashi Iwaif4a78282011-06-17 18:46:48 +0200997 if (!is_smart51_pins(codec, nid))
998 continue;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200999
1000 parm = snd_hda_codec_read(codec, nid, 0,
1001 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1002 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1003 parm |= out_in;
1004 snd_hda_codec_write(codec, nid, 0,
1005 AC_VERB_SET_PIN_WIDGET_CONTROL,
1006 parm);
1007 if (out_in == AC_PINCTL_OUT_EN) {
1008 mute_aa_path(codec, 1);
1009 notify_aa_path_ctls(codec);
1010 }
Lydia Wang1564b282009-10-10 19:07:52 +08001011 }
1012 spec->smart51_enabled = *ucontrol->value.integer.value;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001013 set_widgets_power_state(codec);
Lydia Wang1564b282009-10-10 19:07:52 +08001014 return 1;
1015}
1016
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001017static const struct snd_kcontrol_new via_smart51_mixer = {
1018 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1019 .name = "Smart 5.1",
1020 .count = 1,
1021 .info = via_smart51_info,
1022 .get = via_smart51_get,
1023 .put = via_smart51_put,
Lydia Wang1564b282009-10-10 19:07:52 +08001024};
1025
Takashi Iwaif4a78282011-06-17 18:46:48 +02001026static int via_smart51_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001027{
Takashi Iwaif4a78282011-06-17 18:46:48 +02001028 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001029 struct snd_kcontrol_new *knew;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001030 const struct auto_pin_cfg *cfg = &spec->autocfg;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001031 hda_nid_t nid;
1032 int i;
1033
Takashi Iwaif4a78282011-06-17 18:46:48 +02001034 if (!spec->can_smart51)
Lydia Wangcb34c202011-04-27 17:44:16 +08001035 return 0;
1036
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001037 knew = via_clone_control(spec, &via_smart51_mixer);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001038 if (knew == NULL)
1039 return -ENOMEM;
1040
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001041 for (i = 0; i < cfg->num_inputs; i++) {
1042 nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001043 if (is_smart51_pins(codec, nid)) {
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001044 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001045 break;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001046 }
1047 }
1048
1049 return 0;
1050}
1051
Joseph Chanc577b8a2006-11-29 15:29:40 +01001052/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001053static const struct snd_kcontrol_new vt1708_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001054 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1055 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1056 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1057 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1058 {
1059 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1060 /* The multiple "Capture Source" controls confuse alsamixer
1061 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01001062 */
1063 /* .name = "Capture Source", */
1064 .name = "Input Source",
1065 .count = 1,
1066 .info = via_mux_enum_info,
1067 .get = via_mux_enum_get,
1068 .put = via_mux_enum_put,
1069 },
1070 { } /* end */
1071};
Lydia Wangf5271102009-10-10 19:07:35 +08001072
1073/* check AA path's mute statue */
1074static int is_aa_path_mute(struct hda_codec *codec)
1075{
1076 int mute = 1;
Lydia Wangf5271102009-10-10 19:07:35 +08001077 int start_idx;
1078 int end_idx;
1079 int i;
1080 struct via_spec *spec = codec->spec;
1081 /* get nid of MW0 and start & end index */
1082 switch (spec->codec_type) {
1083 case VT1708B_8CH:
1084 case VT1708B_4CH:
1085 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001086 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001087 start_idx = 2;
1088 end_idx = 4;
1089 break;
1090 case VT1702:
Lydia Wangf5271102009-10-10 19:07:35 +08001091 start_idx = 1;
1092 end_idx = 3;
1093 break;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001094 case VT1718S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001095 start_idx = 1;
1096 end_idx = 3;
1097 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001098 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001099 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001100 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001101 start_idx = 0;
1102 end_idx = 2;
1103 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001104 default:
1105 return 0;
1106 }
1107 /* check AA path's mute status */
1108 for (i = start_idx; i <= end_idx; i++) {
1109 unsigned int con_list = snd_hda_codec_read(
Takashi Iwai620e2b22011-06-17 17:19:19 +02001110 codec, spec->aa_mix_nid, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
Lydia Wangf5271102009-10-10 19:07:35 +08001111 int shift = 8 * (i % 4);
1112 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1113 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1114 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1115 /* check mute status while the pin is connected */
Takashi Iwai620e2b22011-06-17 17:19:19 +02001116 int mute_l = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 0,
Lydia Wangf5271102009-10-10 19:07:35 +08001117 HDA_INPUT, i) >> 7;
Takashi Iwai620e2b22011-06-17 17:19:19 +02001118 int mute_r = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 1,
Lydia Wangf5271102009-10-10 19:07:35 +08001119 HDA_INPUT, i) >> 7;
1120 if (!mute_l || !mute_r) {
1121 mute = 0;
1122 break;
1123 }
1124 }
1125 }
1126 return mute;
1127}
1128
1129/* enter/exit analog low-current mode */
1130static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1131{
1132 struct via_spec *spec = codec->spec;
1133 static int saved_stream_idle = 1; /* saved stream idle status */
1134 int enable = is_aa_path_mute(codec);
1135 unsigned int verb = 0;
1136 unsigned int parm = 0;
1137
1138 if (stream_idle == -1) /* stream status did not change */
1139 enable = enable && saved_stream_idle;
1140 else {
1141 enable = enable && stream_idle;
1142 saved_stream_idle = stream_idle;
1143 }
1144
1145 /* decide low current mode's verb & parameter */
1146 switch (spec->codec_type) {
1147 case VT1708B_8CH:
1148 case VT1708B_4CH:
1149 verb = 0xf70;
1150 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1151 break;
1152 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001153 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001154 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001155 verb = 0xf73;
1156 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1157 break;
1158 case VT1702:
1159 verb = 0xf73;
1160 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1161 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001162 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001163 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001164 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001165 verb = 0xf93;
1166 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1167 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001168 default:
1169 return; /* other codecs are not supported */
1170 }
1171 /* send verb */
1172 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1173}
1174
Joseph Chanc577b8a2006-11-29 15:29:40 +01001175/*
1176 * generic initialization of ADC, input mixers and output mixers
1177 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001178static const struct hda_verb vt1708_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001179 /*
1180 * Unmute ADC0-1 and set the default input to mic-in
1181 */
1182 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1183 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1184
1185
Josepch Chanf7278fd2007-12-13 16:40:40 +01001186 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01001187 * mixer widget
1188 */
1189 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01001190 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1191 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1192 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1193 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1194 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001195
1196 /*
1197 * Set up output mixers (0x19 - 0x1b)
1198 */
1199 /* set vol=0 to output mixers */
1200 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1201 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1202 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Lydia Wang377ff312009-10-10 19:08:55 +08001203
Lydia Wangbfdc6752009-10-10 19:08:50 +08001204 /* Setup default input MW0 to PW4 */
1205 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001206 /* PW9 Output enable */
1207 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangaa266fc2011-03-24 12:41:01 +08001208 /* power down jack detect function */
1209 {0x1, 0xf81, 0x1},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001210 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001211};
1212
1213static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1214 struct hda_codec *codec,
1215 struct snd_pcm_substream *substream)
1216{
1217 struct via_spec *spec = codec->spec;
Lydia Wang17314372009-10-10 19:07:37 +08001218 int idle = substream->pstr->substream_opened == 1
1219 && substream->ref_count == 0;
Lydia Wang17314372009-10-10 19:07:37 +08001220 analog_low_current_mode(codec, idle);
Takashi Iwai9a081602008-02-12 18:37:26 +01001221 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1222 hinfo);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001223}
1224
Takashi Iwai9af74212011-06-18 16:17:45 +02001225static int via_playback_pcm_close(struct hda_pcm_stream *hinfo,
1226 struct hda_codec *codec,
1227 struct snd_pcm_substream *substream)
1228{
1229 int idle = substream->pstr->substream_opened == 1
1230 && substream->ref_count == 0;
1231
1232 analog_low_current_mode(codec, idle);
1233 return 0;
1234}
1235
Harald Welte0aa62ae2008-09-09 15:58:27 +08001236static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1237 unsigned int stream_tag,
1238 unsigned int format,
1239 struct snd_pcm_substream *substream)
1240{
1241 struct via_spec *spec = codec->spec;
1242 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001243 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001244 int chs = substream->runtime->channels;
1245 int i;
Stephen Warren7c935972011-06-01 11:14:17 -06001246 struct hda_spdif_out *spdif =
1247 snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001248
1249 mutex_lock(&codec->spdif_mutex);
1250 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1251 if (chs == 2 &&
1252 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1253 format) &&
Stephen Warren7c935972011-06-01 11:14:17 -06001254 !(spdif->status & IEC958_AES0_NONAUDIO)) {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001255 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1256 /* turn off SPDIF once; otherwise the IEC958 bits won't
1257 * be updated */
Stephen Warren7c935972011-06-01 11:14:17 -06001258 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001259 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1260 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001261 spdif->ctls &
Harald Welte0aa62ae2008-09-09 15:58:27 +08001262 ~AC_DIG1_ENABLE & 0xff);
1263 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1264 stream_tag, 0, format);
1265 /* turn on again (if needed) */
Stephen Warren7c935972011-06-01 11:14:17 -06001266 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001267 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1268 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001269 spdif->ctls & 0xff);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001270 } else {
1271 mout->dig_out_used = 0;
1272 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1273 0, 0, 0);
1274 }
1275 }
1276 mutex_unlock(&codec->spdif_mutex);
1277
1278 /* front */
1279 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1280 0, format);
1281
Lydia Wangeb7188c2009-10-10 19:08:34 +08001282 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1283 && !spec->hp_independent_mode)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001284 /* headphone out will just decode front left/right (stereo) */
1285 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1286 0, format);
1287
1288 /* extra outputs copied from front */
1289 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1290 if (mout->extra_out_nid[i])
1291 snd_hda_codec_setup_stream(codec,
1292 mout->extra_out_nid[i],
1293 stream_tag, 0, format);
1294
1295 /* surrounds */
1296 for (i = 1; i < mout->num_dacs; i++) {
1297 if (chs >= (i + 1) * 2) /* independent out */
1298 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1299 i * 2, format);
1300 else /* copy front */
1301 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1302 0, format);
1303 }
1304}
1305
1306static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1307 struct hda_codec *codec,
1308 unsigned int stream_tag,
1309 unsigned int format,
1310 struct snd_pcm_substream *substream)
1311{
1312 struct via_spec *spec = codec->spec;
1313 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001314 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001315
1316 if (substream->number == 0)
1317 playback_multi_pcm_prep_0(codec, stream_tag, format,
1318 substream);
1319 else {
1320 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1321 spec->hp_independent_mode)
1322 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1323 stream_tag, 0, format);
1324 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001325 vt1708_start_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001326 return 0;
1327}
1328
1329static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1330 struct hda_codec *codec,
1331 struct snd_pcm_substream *substream)
1332{
1333 struct via_spec *spec = codec->spec;
1334 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001335 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001336 int i;
1337
1338 if (substream->number == 0) {
1339 for (i = 0; i < mout->num_dacs; i++)
1340 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1341
1342 if (mout->hp_nid && !spec->hp_independent_mode)
1343 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1344 0, 0, 0);
1345
1346 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1347 if (mout->extra_out_nid[i])
1348 snd_hda_codec_setup_stream(codec,
1349 mout->extra_out_nid[i],
1350 0, 0, 0);
1351 mutex_lock(&codec->spdif_mutex);
1352 if (mout->dig_out_nid &&
1353 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1354 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1355 0, 0, 0);
1356 mout->dig_out_used = 0;
1357 }
1358 mutex_unlock(&codec->spdif_mutex);
1359 } else {
1360 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1361 spec->hp_independent_mode)
1362 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1363 0, 0, 0);
1364 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001365 vt1708_stop_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001366 return 0;
1367}
1368
Joseph Chanc577b8a2006-11-29 15:29:40 +01001369/*
1370 * Digital out
1371 */
1372static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1373 struct hda_codec *codec,
1374 struct snd_pcm_substream *substream)
1375{
1376 struct via_spec *spec = codec->spec;
1377 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1378}
1379
1380static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1381 struct hda_codec *codec,
1382 struct snd_pcm_substream *substream)
1383{
1384 struct via_spec *spec = codec->spec;
1385 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1386}
1387
Harald Welte5691ec72008-09-15 22:42:26 +08001388static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001389 struct hda_codec *codec,
1390 unsigned int stream_tag,
1391 unsigned int format,
1392 struct snd_pcm_substream *substream)
1393{
1394 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001395 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1396 stream_tag, format, substream);
1397}
Harald Welte5691ec72008-09-15 22:42:26 +08001398
Takashi Iwai9da29272009-05-07 16:31:14 +02001399static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1400 struct hda_codec *codec,
1401 struct snd_pcm_substream *substream)
1402{
1403 struct via_spec *spec = codec->spec;
1404 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001405 return 0;
1406}
1407
Joseph Chanc577b8a2006-11-29 15:29:40 +01001408/*
1409 * Analog capture
1410 */
1411static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1412 struct hda_codec *codec,
1413 unsigned int stream_tag,
1414 unsigned int format,
1415 struct snd_pcm_substream *substream)
1416{
1417 struct via_spec *spec = codec->spec;
1418
1419 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1420 stream_tag, 0, format);
1421 return 0;
1422}
1423
1424static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1425 struct hda_codec *codec,
1426 struct snd_pcm_substream *substream)
1427{
1428 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001429 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001430 return 0;
1431}
1432
Takashi Iwai9af74212011-06-18 16:17:45 +02001433static const struct hda_pcm_stream via_pcm_analog_playback = {
1434 .substreams = 2, /* will be changed in via_build_pcms() */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001435 .channels_min = 2,
1436 .channels_max = 8,
Takashi Iwai9af74212011-06-18 16:17:45 +02001437 /* NID is set in via_build_pcms */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001438 .ops = {
1439 .open = via_playback_pcm_open,
Takashi Iwai9af74212011-06-18 16:17:45 +02001440 .close = via_playback_pcm_close,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001441 .prepare = via_playback_multi_pcm_prepare,
1442 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001443 },
1444};
1445
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001446static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Takashi Iwai9af74212011-06-18 16:17:45 +02001447 .substreams = 2, /* will be changed in via_build_pcms() */
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001448 .channels_min = 2,
1449 .channels_max = 8,
Takashi Iwai9af74212011-06-18 16:17:45 +02001450 /* NID is set in via_build_pcms */
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001451 /* We got noisy outputs on the right channel on VT1708 when
1452 * 24bit samples are used. Until any workaround is found,
1453 * disable the 24bit format, so far.
1454 */
1455 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1456 .ops = {
1457 .open = via_playback_pcm_open,
Takashi Iwai9af74212011-06-18 16:17:45 +02001458 .close = via_playback_pcm_close,
Lydia Wangc873cc22009-10-10 19:08:21 +08001459 .prepare = via_playback_multi_pcm_prepare,
1460 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001461 },
1462};
1463
Takashi Iwai9af74212011-06-18 16:17:45 +02001464static const struct hda_pcm_stream via_pcm_analog_capture = {
1465 .substreams = 2, /* will be changed in via_build_pcms() */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001466 .channels_min = 2,
1467 .channels_max = 2,
Takashi Iwai9af74212011-06-18 16:17:45 +02001468 /* NID is set in via_build_pcms */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001469 .ops = {
Takashi Iwai9af74212011-06-18 16:17:45 +02001470 .open = via_playback_pcm_open,
1471 .close = via_playback_pcm_close,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001472 .prepare = via_capture_pcm_prepare,
1473 .cleanup = via_capture_pcm_cleanup
1474 },
1475};
1476
Takashi Iwai9af74212011-06-18 16:17:45 +02001477static const struct hda_pcm_stream via_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001478 .substreams = 1,
1479 .channels_min = 2,
1480 .channels_max = 2,
1481 /* NID is set in via_build_pcms */
1482 .ops = {
1483 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001484 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001485 .prepare = via_dig_playback_pcm_prepare,
1486 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001487 },
1488};
1489
Takashi Iwai9af74212011-06-18 16:17:45 +02001490static const struct hda_pcm_stream via_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001491 .substreams = 1,
1492 .channels_min = 2,
1493 .channels_max = 2,
1494};
1495
1496static int via_build_controls(struct hda_codec *codec)
1497{
1498 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001499 struct snd_kcontrol *kctl;
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001500 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001501 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001502
Takashi Iwai24088a52011-06-17 16:59:21 +02001503 if (spec->set_widgets_power_state)
1504 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1505 return -ENOMEM;
1506
Joseph Chanc577b8a2006-11-29 15:29:40 +01001507 for (i = 0; i < spec->num_mixers; i++) {
1508 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1509 if (err < 0)
1510 return err;
1511 }
1512
1513 if (spec->multiout.dig_out_nid) {
1514 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001515 spec->multiout.dig_out_nid,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001516 spec->multiout.dig_out_nid);
1517 if (err < 0)
1518 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001519 err = snd_hda_create_spdif_share_sw(codec,
1520 &spec->multiout);
1521 if (err < 0)
1522 return err;
1523 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001524 }
1525 if (spec->dig_in_nid) {
1526 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1527 if (err < 0)
1528 return err;
1529 }
Lydia Wang17314372009-10-10 19:07:37 +08001530
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001531 /* assign Capture Source enums to NID */
1532 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1533 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +01001534 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001535 if (err < 0)
1536 return err;
1537 }
1538
1539 /* other nid->control mapping */
1540 for (i = 0; i < spec->num_mixers; i++) {
1541 for (knew = spec->mixers[i]; knew->name; knew++) {
1542 if (knew->iface != NID_MAPPING)
1543 continue;
1544 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1545 if (kctl == NULL)
1546 continue;
1547 err = snd_hda_add_nid(codec, kctl, 0,
1548 knew->subdevice);
1549 }
1550 }
1551
Lydia Wang17314372009-10-10 19:07:37 +08001552 /* init power states */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001553 set_widgets_power_state(codec);
Lydia Wang17314372009-10-10 19:07:37 +08001554 analog_low_current_mode(codec, 1);
1555
Takashi Iwai603c4012008-07-30 15:01:44 +02001556 via_free_kctls(codec); /* no longer needed */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001557 return 0;
1558}
1559
1560static int via_build_pcms(struct hda_codec *codec)
1561{
1562 struct via_spec *spec = codec->spec;
1563 struct hda_pcm *info = spec->pcm_rec;
1564
1565 codec->num_pcms = 1;
1566 codec->pcm_info = info;
1567
Takashi Iwai82673bc2011-06-17 16:24:21 +02001568 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1569 "%s Analog", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001570 info->name = spec->stream_name_analog;
Takashi Iwai9af74212011-06-18 16:17:45 +02001571
1572 if (!spec->stream_analog_playback)
1573 spec->stream_analog_playback = &via_pcm_analog_playback;
Lydia Wang377ff312009-10-10 19:08:55 +08001574 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001575 *spec->stream_analog_playback;
Lydia Wang377ff312009-10-10 19:08:55 +08001576 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1577 spec->multiout.dac_nids[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001578 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1579 spec->multiout.max_channels;
Takashi Iwai9af74212011-06-18 16:17:45 +02001580 if (!spec->multiout.hp_nid)
1581 info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams = 1;
1582
1583 if (!spec->stream_analog_capture)
1584 spec->stream_analog_capture = &via_pcm_analog_capture;
1585 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1586 *spec->stream_analog_capture;
1587 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1588 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1589 spec->num_adc_nids;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001590
1591 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1592 codec->num_pcms++;
1593 info++;
Takashi Iwai82673bc2011-06-17 16:24:21 +02001594 snprintf(spec->stream_name_digital,
1595 sizeof(spec->stream_name_digital),
1596 "%s Digital", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001597 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001598 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001599 if (spec->multiout.dig_out_nid) {
Takashi Iwai9af74212011-06-18 16:17:45 +02001600 if (!spec->stream_digital_playback)
1601 spec->stream_digital_playback =
1602 &via_pcm_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001603 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001604 *spec->stream_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001605 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1606 spec->multiout.dig_out_nid;
1607 }
1608 if (spec->dig_in_nid) {
Takashi Iwai9af74212011-06-18 16:17:45 +02001609 if (!spec->stream_digital_capture)
1610 spec->stream_digital_capture =
1611 &via_pcm_digital_capture;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001612 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001613 *spec->stream_digital_capture;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001614 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1615 spec->dig_in_nid;
1616 }
1617 }
1618
1619 return 0;
1620}
1621
1622static void via_free(struct hda_codec *codec)
1623{
1624 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001625
1626 if (!spec)
1627 return;
1628
Takashi Iwai603c4012008-07-30 15:01:44 +02001629 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001630 vt1708_stop_hp_work(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001631 kfree(codec->spec);
1632}
1633
Takashi Iwai64be2852011-06-17 16:51:39 +02001634/* mute/unmute outputs */
1635static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1636 hda_nid_t *pins, bool mute)
1637{
1638 int i;
1639 for (i = 0; i < num_pins; i++)
1640 snd_hda_codec_write(codec, pins[i], 0,
1641 AC_VERB_SET_PIN_WIDGET_CONTROL,
1642 mute ? 0 : PIN_OUT);
1643}
1644
Harald Welte69e52a82008-09-09 15:57:32 +08001645/* mute internal speaker if HP is plugged */
1646static void via_hp_automute(struct hda_codec *codec)
1647{
Lydia Wangdcf34c82009-10-10 19:08:15 +08001648 unsigned int present = 0;
Harald Welte69e52a82008-09-09 15:57:32 +08001649 struct via_spec *spec = codec->spec;
1650
Takashi Iwaid56757a2009-11-18 08:00:14 +01001651 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangdcf34c82009-10-10 19:08:15 +08001652
Takashi Iwai64be2852011-06-17 16:51:39 +02001653 if (!spec->hp_independent_mode)
1654 toggle_output_mutes(codec, spec->autocfg.line_outs,
1655 spec->autocfg.line_out_pins,
1656 present);
Harald Welte69e52a82008-09-09 15:57:32 +08001657}
1658
Lydia Wangf3db4232009-10-10 19:08:41 +08001659/* mute mono out if HP or Line out is plugged */
1660static void via_mono_automute(struct hda_codec *codec)
1661{
1662 unsigned int hp_present, lineout_present;
1663 struct via_spec *spec = codec->spec;
1664
1665 if (spec->codec_type != VT1716S)
1666 return;
1667
Takashi Iwaid56757a2009-11-18 08:00:14 +01001668 lineout_present = snd_hda_jack_detect(codec,
1669 spec->autocfg.line_out_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001670
1671 /* Mute Mono Out if Line Out is plugged */
1672 if (lineout_present) {
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001673 snd_hda_codec_write(codec, 0x2A, 0,
1674 AC_VERB_SET_PIN_WIDGET_CONTROL,
1675 lineout_present ? 0 : PIN_OUT);
Lydia Wangf3db4232009-10-10 19:08:41 +08001676 return;
1677 }
1678
Takashi Iwaid56757a2009-11-18 08:00:14 +01001679 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001680
1681 if (!spec->hp_independent_mode)
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001682 snd_hda_codec_write(codec, 0x2A, 0,
1683 AC_VERB_SET_PIN_WIDGET_CONTROL,
1684 hp_present ? 0 : PIN_OUT);
Lydia Wangf3db4232009-10-10 19:08:41 +08001685}
1686
Harald Welte69e52a82008-09-09 15:57:32 +08001687static void via_gpio_control(struct hda_codec *codec)
1688{
1689 unsigned int gpio_data;
1690 unsigned int vol_counter;
1691 unsigned int vol;
1692 unsigned int master_vol;
1693
1694 struct via_spec *spec = codec->spec;
1695
1696 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1697 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1698
1699 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1700 0xF84, 0) & 0x3F0000) >> 16;
1701
1702 vol = vol_counter & 0x1F;
1703 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1704 AC_VERB_GET_AMP_GAIN_MUTE,
1705 AC_AMP_GET_INPUT);
1706
1707 if (gpio_data == 0x02) {
1708 /* unmute line out */
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001709 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1710 AC_VERB_SET_PIN_WIDGET_CONTROL,
1711 PIN_OUT);
Harald Welte69e52a82008-09-09 15:57:32 +08001712 if (vol_counter & 0x20) {
1713 /* decrease volume */
1714 if (vol > master_vol)
1715 vol = master_vol;
1716 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1717 0, HDA_AMP_VOLMASK,
1718 master_vol-vol);
1719 } else {
1720 /* increase volume */
1721 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1722 HDA_AMP_VOLMASK,
1723 ((master_vol+vol) > 0x2A) ? 0x2A :
1724 (master_vol+vol));
1725 }
1726 } else if (!(gpio_data & 0x02)) {
1727 /* mute line out */
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001728 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1729 AC_VERB_SET_PIN_WIDGET_CONTROL,
1730 0);
Harald Welte69e52a82008-09-09 15:57:32 +08001731 }
1732}
1733
Lydia Wang25eaba22009-10-10 19:08:43 +08001734/* mute Internal-Speaker if HP is plugged */
1735static void via_speaker_automute(struct hda_codec *codec)
1736{
1737 unsigned int hp_present;
1738 struct via_spec *spec = codec->spec;
1739
Lydia Wang27439ce2011-03-24 12:40:10 +08001740 if (!VT2002P_COMPATIBLE(spec))
Lydia Wang25eaba22009-10-10 19:08:43 +08001741 return;
1742
Takashi Iwaid56757a2009-11-18 08:00:14 +01001743 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001744
Takashi Iwai64be2852011-06-17 16:51:39 +02001745 if (!spec->hp_independent_mode)
1746 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1747 spec->autocfg.speaker_pins,
1748 hp_present);
Lydia Wang25eaba22009-10-10 19:08:43 +08001749}
1750
1751/* mute line-out and internal speaker if HP is plugged */
1752static void via_hp_bind_automute(struct hda_codec *codec)
1753{
Takashi Iwai64be2852011-06-17 16:51:39 +02001754 int present;
Lydia Wang25eaba22009-10-10 19:08:43 +08001755 struct via_spec *spec = codec->spec;
Lydia Wang25eaba22009-10-10 19:08:43 +08001756
1757 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1758 return;
1759
Takashi Iwai64be2852011-06-17 16:51:39 +02001760 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1761 if (!spec->hp_independent_mode)
1762 toggle_output_mutes(codec, spec->autocfg.line_outs,
1763 spec->autocfg.line_out_pins,
1764 present);
Lydia Wang25eaba22009-10-10 19:08:43 +08001765
Takashi Iwai64be2852011-06-17 16:51:39 +02001766 if (!present)
1767 present = snd_hda_jack_detect(codec,
1768 spec->autocfg.line_out_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001769
Lydia Wang25eaba22009-10-10 19:08:43 +08001770 /* Speakers */
Takashi Iwai64be2852011-06-17 16:51:39 +02001771 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1772 spec->autocfg.speaker_pins,
1773 present);
Lydia Wang25eaba22009-10-10 19:08:43 +08001774}
1775
1776
Harald Welte69e52a82008-09-09 15:57:32 +08001777/* unsolicited event for jack sensing */
1778static void via_unsol_event(struct hda_codec *codec,
1779 unsigned int res)
1780{
1781 res >>= 26;
Lydia Wangec7e7e42011-03-24 12:43:44 +08001782
Lydia Wanga34df192009-10-10 19:08:01 +08001783 if (res & VIA_JACK_EVENT)
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001784 set_widgets_power_state(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001785
1786 res &= ~VIA_JACK_EVENT;
1787
1788 if (res == VIA_HP_EVENT)
1789 via_hp_automute(codec);
1790 else if (res == VIA_GPIO_EVENT)
1791 via_gpio_control(codec);
1792 else if (res == VIA_MONO_EVENT)
Lydia Wangf3db4232009-10-10 19:08:41 +08001793 via_mono_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001794 else if (res == VIA_SPEAKER_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001795 via_speaker_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001796 else if (res == VIA_BIND_HP_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001797 via_hp_bind_automute(codec);
Harald Welte69e52a82008-09-09 15:57:32 +08001798}
1799
Joseph Chanc577b8a2006-11-29 15:29:40 +01001800static int via_init(struct hda_codec *codec)
1801{
1802 struct via_spec *spec = codec->spec;
Harald Welte69e52a82008-09-09 15:57:32 +08001803 int i;
1804 for (i = 0; i < spec->num_iverbs; i++)
1805 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1806
Josepch Chanf7278fd2007-12-13 16:40:40 +01001807 /* Lydia Add for EAPD enable */
1808 if (!spec->dig_in_nid) { /* No Digital In connection */
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001809 if (spec->dig_in_pin) {
1810 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001811 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +01001812 PIN_OUT);
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001813 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001814 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1815 }
Takashi Iwai12b74c82008-01-15 12:39:38 +01001816 } else /* enable SPDIF-input pin */
1817 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1818 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
Josepch Chanf7278fd2007-12-13 16:40:40 +01001819
Takashi Iwai9da29272009-05-07 16:31:14 +02001820 /* assign slave outs */
1821 if (spec->slave_dig_outs[0])
1822 codec->slave_dig_outs = spec->slave_dig_outs;
Harald Welte5691ec72008-09-15 22:42:26 +08001823
Lydia Wang377ff312009-10-10 19:08:55 +08001824 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001825}
1826
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001827#ifdef SND_HDA_NEEDS_RESUME
1828static int via_suspend(struct hda_codec *codec, pm_message_t state)
1829{
1830 struct via_spec *spec = codec->spec;
1831 vt1708_stop_hp_work(spec);
1832 return 0;
1833}
1834#endif
1835
Takashi Iwaicb53c622007-08-10 17:21:45 +02001836#ifdef CONFIG_SND_HDA_POWER_SAVE
1837static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1838{
1839 struct via_spec *spec = codec->spec;
1840 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1841}
1842#endif
1843
Joseph Chanc577b8a2006-11-29 15:29:40 +01001844/*
1845 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001846static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001847 .build_controls = via_build_controls,
1848 .build_pcms = via_build_pcms,
1849 .init = via_init,
1850 .free = via_free,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001851#ifdef SND_HDA_NEEDS_RESUME
1852 .suspend = via_suspend,
1853#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02001854#ifdef CONFIG_SND_HDA_POWER_SAVE
1855 .check_power_status = via_check_power_status,
1856#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001857};
1858
Takashi Iwai4a796162011-06-17 17:53:38 +02001859static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001860{
Takashi Iwai4a796162011-06-17 17:53:38 +02001861 struct via_spec *spec = codec->spec;
1862 int i;
1863
1864 for (i = 0; i < spec->multiout.num_dacs; i++) {
1865 if (spec->multiout.dac_nids[i] == dac)
1866 return false;
1867 }
1868 if (spec->multiout.hp_nid == dac)
1869 return false;
1870 return true;
1871}
1872
1873static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1874 hda_nid_t target_dac, struct nid_path *path,
1875 int depth, int wid_type)
1876{
1877 hda_nid_t conn[8];
1878 int i, nums;
1879
1880 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1881 for (i = 0; i < nums; i++) {
1882 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1883 continue;
1884 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1885 path->path[depth] = conn[i];
1886 path->idx[depth] = i;
1887 path->depth = ++depth;
1888 return true;
1889 }
1890 }
1891 if (depth > 4)
1892 return false;
1893 for (i = 0; i < nums; i++) {
1894 unsigned int type;
1895 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1896 if (type == AC_WID_AUD_OUT ||
1897 (wid_type != -1 && type != wid_type))
1898 continue;
1899 if (parse_output_path(codec, conn[i], target_dac,
1900 path, depth + 1, AC_WID_AUD_SEL)) {
1901 path->path[depth] = conn[i];
1902 path->idx[depth] = i;
1903 return true;
1904 }
1905 }
1906 return false;
1907}
1908
1909static int via_auto_fill_dac_nids(struct hda_codec *codec)
1910{
1911 struct via_spec *spec = codec->spec;
1912 const struct auto_pin_cfg *cfg = &spec->autocfg;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001913 int i;
1914 hda_nid_t nid;
1915
Joseph Chanc577b8a2006-11-29 15:29:40 +01001916 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai4a796162011-06-17 17:53:38 +02001917 spec->multiout.num_dacs = cfg->line_outs;
1918 for (i = 0; i < cfg->line_outs; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001919 nid = cfg->line_out_pins[i];
Takashi Iwai4a796162011-06-17 17:53:38 +02001920 if (!nid)
1921 continue;
1922 if (parse_output_path(codec, nid, 0, &spec->out_path[i], 0, -1))
1923 spec->private_dac_nids[i] =
1924 spec->out_path[i].path[spec->out_path[i].depth - 1];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001925 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001926 return 0;
1927}
1928
Takashi Iwai4a796162011-06-17 17:53:38 +02001929static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1930 hda_nid_t pin, hda_nid_t dac, int chs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001931{
Takashi Iwai4a796162011-06-17 17:53:38 +02001932 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001933 char name[32];
Takashi Iwai4a796162011-06-17 17:53:38 +02001934 hda_nid_t nid;
1935 int err;
1936
1937 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1938 nid = dac;
1939 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1940 nid = pin;
1941 else
1942 nid = 0;
1943 if (nid) {
1944 sprintf(name, "%s Playback Volume", pfx);
1945 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1946 HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT));
1947 if (err < 0)
1948 return err;
1949 }
1950
1951 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1952 nid = dac;
1953 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1954 nid = pin;
1955 else
1956 nid = 0;
1957 if (nid) {
1958 sprintf(name, "%s Playback Switch", pfx);
1959 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1960 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1961 if (err < 0)
1962 return err;
1963 }
1964 return 0;
1965}
1966
1967static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
1968 hda_nid_t nid);
1969
Takashi Iwaif4a78282011-06-17 18:46:48 +02001970static void mangle_smart51(struct hda_codec *codec)
1971{
1972 struct via_spec *spec = codec->spec;
1973 struct auto_pin_cfg *cfg = &spec->autocfg;
1974 int i;
1975
1976 for (i = 0; i < cfg->num_inputs; i++) {
1977 if (!is_smart51_pins(codec, cfg->inputs[i].pin))
1978 continue;
1979 spec->can_smart51 = 1;
1980 cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin;
1981 if (cfg->line_outs == 3)
1982 break;
1983 }
1984}
1985
Takashi Iwai4a796162011-06-17 17:53:38 +02001986/* add playback controls from the parsed DAC table */
1987static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1988{
1989 struct via_spec *spec = codec->spec;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001990 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaiea734962011-01-17 11:29:34 +01001991 static const char * const chname[4] = {
1992 "Front", "Surround", "C/LFE", "Side"
1993 };
Takashi Iwai4a796162011-06-17 17:53:38 +02001994 int i, idx, err;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001995 int old_line_outs;
1996
1997 /* check smart51 */
1998 old_line_outs = cfg->line_outs;
1999 if (cfg->line_outs == 1)
2000 mangle_smart51(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002001
Takashi Iwai4a796162011-06-17 17:53:38 +02002002 for (i = 0; i < cfg->line_outs; i++) {
2003 hda_nid_t pin, dac;
2004 pin = cfg->line_out_pins[i];
2005 dac = spec->multiout.dac_nids[i];
2006 if (!pin || !dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002007 continue;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002008 if (i == AUTO_SEQ_CENLFE) {
Takashi Iwai4a796162011-06-17 17:53:38 +02002009 err = create_ch_ctls(codec, "Center", pin, dac, 1);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002010 if (err < 0)
2011 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002012 err = create_ch_ctls(codec, "LFE", pin, dac, 2);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002013 if (err < 0)
2014 return err;
2015 } else {
Takashi Iwai4a796162011-06-17 17:53:38 +02002016 err = create_ch_ctls(codec, chname[i], pin, dac, 3);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002017 if (err < 0)
2018 return err;
2019 }
2020 }
2021
Takashi Iwai4a796162011-06-17 17:53:38 +02002022 idx = get_connection_index(codec, spec->aa_mix_nid,
2023 spec->multiout.dac_nids[0]);
2024 if (idx >= 0) {
2025 /* add control to mixer */
2026 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2027 "PCM Playback Volume",
2028 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2029 idx, HDA_INPUT));
2030 if (err < 0)
2031 return err;
2032 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2033 "PCM Playback Switch",
2034 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2035 idx, HDA_INPUT));
2036 if (err < 0)
2037 return err;
2038 }
2039
Takashi Iwaif4a78282011-06-17 18:46:48 +02002040 cfg->line_outs = old_line_outs;
2041
Joseph Chanc577b8a2006-11-29 15:29:40 +01002042 return 0;
2043}
2044
Harald Welte0aa62ae2008-09-09 15:58:27 +08002045static void create_hp_imux(struct via_spec *spec)
2046{
2047 int i;
2048 struct hda_input_mux *imux = &spec->private_imux[1];
Takashi Iwaiea734962011-01-17 11:29:34 +01002049 static const char * const texts[] = { "OFF", "ON", NULL};
Harald Welte0aa62ae2008-09-09 15:58:27 +08002050
2051 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002052 for (i = 0; texts[i]; i++)
2053 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Harald Welte0aa62ae2008-09-09 15:58:27 +08002054
2055 spec->hp_mux = &spec->private_imux[1];
2056}
2057
Takashi Iwai4a796162011-06-17 17:53:38 +02002058static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002059{
Takashi Iwai4a796162011-06-17 17:53:38 +02002060 struct via_spec *spec = codec->spec;
2061 hda_nid_t dac = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002062 int err;
2063
2064 if (!pin)
2065 return 0;
2066
Takashi Iwai4a796162011-06-17 17:53:38 +02002067 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2068 &spec->hp_dep_path, 0, -1))
2069 return 0;
2070 if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) {
2071 dac = spec->hp_path.path[spec->hp_path.depth - 1];
2072 spec->multiout.hp_nid = dac;
2073 spec->hp_independent_mode_index =
2074 spec->hp_path.idx[spec->hp_path.depth - 1];
2075 create_hp_imux(spec);
2076 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002077
Takashi Iwai4a796162011-06-17 17:53:38 +02002078 err = create_ch_ctls(codec, "Headphone", pin, dac, 3);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002079 if (err < 0)
2080 return err;
Harald Welte0aa62ae2008-09-09 15:58:27 +08002081
Joseph Chanc577b8a2006-11-29 15:29:40 +01002082 return 0;
2083}
2084
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002085static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
2086 hda_nid_t nid)
2087{
2088 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
2089 int i, nums;
2090
2091 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
2092 for (i = 0; i < nums; i++)
2093 if (conn[i] == nid)
2094 return i;
2095 return -1;
2096}
2097
2098/* look for ADCs */
2099static int via_fill_adcs(struct hda_codec *codec)
2100{
2101 struct via_spec *spec = codec->spec;
2102 hda_nid_t nid = codec->start_nid;
2103 int i;
2104
2105 for (i = 0; i < codec->num_nodes; i++, nid++) {
2106 unsigned int wcaps = get_wcaps(codec, nid);
2107 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2108 continue;
2109 if (wcaps & AC_WCAP_DIGITAL)
2110 continue;
2111 if (!(wcaps & AC_WCAP_CONN_LIST))
2112 continue;
2113 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2114 return -ENOMEM;
2115 spec->adc_nids[spec->num_adc_nids++] = nid;
2116 }
2117 return 0;
2118}
2119
2120static int get_mux_nids(struct hda_codec *codec);
2121
Joseph Chanc577b8a2006-11-29 15:29:40 +01002122/* create playback/capture controls for input pins */
Takashi Iwai620e2b22011-06-17 17:19:19 +02002123static int via_auto_create_analog_input_ctls(struct hda_codec *codec,
2124 const struct auto_pin_cfg *cfg)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002125{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002126 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08002127 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002128 int i, err, idx, idx2, type, type_idx = 0;
2129 hda_nid_t cap_nid;
2130 hda_nid_t pin_idxs[8];
2131 int num_idxs;
2132
2133 err = via_fill_adcs(codec);
2134 if (err < 0)
2135 return err;
2136 err = get_mux_nids(codec);
2137 if (err < 0)
2138 return err;
2139 cap_nid = spec->mux_nids[0];
2140
2141 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
2142 ARRAY_SIZE(pin_idxs));
2143 if (num_idxs <= 0)
2144 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002145
2146 /* for internal loopback recording select */
Takashi Iwaif3268512010-08-30 11:00:19 +02002147 for (idx = 0; idx < num_idxs; idx++) {
Takashi Iwai620e2b22011-06-17 17:19:19 +02002148 if (pin_idxs[idx] == spec->aa_mix_nid) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002149 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
Takashi Iwaif3268512010-08-30 11:00:19 +02002150 break;
2151 }
2152 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002153
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002154 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002155 const char *label;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002156 type = cfg->inputs[i].type;
Takashi Iwaif3268512010-08-30 11:00:19 +02002157 for (idx = 0; idx < num_idxs; idx++)
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002158 if (pin_idxs[idx] == cfg->inputs[i].pin)
Takashi Iwaif3268512010-08-30 11:00:19 +02002159 break;
2160 if (idx >= num_idxs)
2161 continue;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002162 if (i > 0 && type == cfg->inputs[i - 1].type)
2163 type_idx++;
2164 else
2165 type_idx = 0;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002166 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai620e2b22011-06-17 17:19:19 +02002167 idx2 = get_connection_index(codec, spec->aa_mix_nid,
2168 pin_idxs[idx]);
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002169 if (idx2 >= 0)
Lydia Wang16922282011-03-22 16:24:10 +08002170 err = via_new_analog_input(spec, label, type_idx,
Takashi Iwai620e2b22011-06-17 17:19:19 +02002171 idx2, spec->aa_mix_nid);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002172 if (err < 0)
2173 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002174 snd_hda_add_imux_item(imux, label, idx, NULL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002175 }
2176 return 0;
2177}
2178
Takashi Iwaicb53c622007-08-10 17:21:45 +02002179#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002180static const struct hda_amp_list vt1708_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002181 { 0x17, HDA_INPUT, 1 },
2182 { 0x17, HDA_INPUT, 2 },
2183 { 0x17, HDA_INPUT, 3 },
2184 { 0x17, HDA_INPUT, 4 },
2185 { } /* end */
2186};
2187#endif
2188
Harald Welte76d9b0d2008-09-09 15:50:37 +08002189static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2190{
2191 unsigned int def_conf;
2192 unsigned char seqassoc;
2193
Takashi Iwai2f334f92009-02-20 14:37:42 +01002194 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002195 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2196 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002197 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2198 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2199 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2200 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002201 }
2202
2203 return;
2204}
2205
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002206static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002207 struct snd_ctl_elem_value *ucontrol)
2208{
2209 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2210 struct via_spec *spec = codec->spec;
2211
2212 if (spec->codec_type != VT1708)
2213 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002214 spec->vt1708_jack_detect =
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002215 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002216 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002217 return 0;
2218}
2219
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002220static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002221 struct snd_ctl_elem_value *ucontrol)
2222{
2223 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2224 struct via_spec *spec = codec->spec;
2225 int change;
2226
2227 if (spec->codec_type != VT1708)
2228 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002229 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002230 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002231 == !spec->vt1708_jack_detect;
2232 if (spec->vt1708_jack_detect) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002233 mute_aa_path(codec, 1);
2234 notify_aa_path_ctls(codec);
2235 }
2236 return change;
2237}
2238
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002239static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2240 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2241 .name = "Jack Detect",
2242 .count = 1,
2243 .info = snd_ctl_boolean_mono_info,
2244 .get = vt1708_jack_detect_get,
2245 .put = vt1708_jack_detect_put,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002246};
2247
Joseph Chanc577b8a2006-11-29 15:29:40 +01002248static int vt1708_parse_auto_config(struct hda_codec *codec)
2249{
2250 struct via_spec *spec = codec->spec;
2251 int err;
2252
Harald Welte76d9b0d2008-09-09 15:50:37 +08002253 /* Add HP and CD pin config connect bit re-config action */
2254 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2255 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2256
Joseph Chanc577b8a2006-11-29 15:29:40 +01002257 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2258 if (err < 0)
2259 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002260 err = via_auto_fill_dac_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002261 if (err < 0)
2262 return err;
2263 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2264 return 0; /* can't find valid BIOS pin config */
2265
Takashi Iwai4a796162011-06-17 17:53:38 +02002266 err = via_auto_create_multi_out_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002267 if (err < 0)
2268 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002269 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002270 if (err < 0)
2271 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02002272 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002273 if (err < 0)
2274 return err;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002275 /* add jack detect on/off control */
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002276 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2277 return -ENOMEM;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002278
2279 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2280
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002281 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002282 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002283 spec->dig_in_pin = VT1708_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002284 if (spec->autocfg.dig_in_pin)
2285 spec->dig_in_nid = VT1708_DIGIN_NID;
2286
Takashi Iwai603c4012008-07-30 15:01:44 +02002287 if (spec->kctls.list)
2288 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002289
Harald Welte69e52a82008-09-09 15:57:32 +08002290 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002291
Harald Welte0aa62ae2008-09-09 15:58:27 +08002292 spec->input_mux = &spec->private_imux[0];
2293
Harald Weltef8fdd492008-09-15 22:41:31 +08002294 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002295 via_hp_build(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002296
Takashi Iwaif4a78282011-06-17 18:46:48 +02002297 err = via_smart51_build(codec);
2298 if (err < 0)
2299 return err;
2300
Joseph Chanc577b8a2006-11-29 15:29:40 +01002301 return 1;
2302}
2303
2304/* init callback for auto-configuration model -- overriding the default init */
2305static int via_auto_init(struct hda_codec *codec)
2306{
Lydia Wang25eaba22009-10-10 19:08:43 +08002307 struct via_spec *spec = codec->spec;
2308
Joseph Chanc577b8a2006-11-29 15:29:40 +01002309 via_init(codec);
2310 via_auto_init_multi_out(codec);
2311 via_auto_init_hp_out(codec);
2312 via_auto_init_analog_input(codec);
Lydia Wang118909562011-03-23 17:57:34 +08002313
2314 if (VT2002P_COMPATIBLE(spec)) {
Lydia Wang25eaba22009-10-10 19:08:43 +08002315 via_hp_bind_automute(codec);
2316 } else {
2317 via_hp_automute(codec);
2318 via_speaker_automute(codec);
2319 }
2320
Joseph Chanc577b8a2006-11-29 15:29:40 +01002321 return 0;
2322}
2323
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002324static void vt1708_update_hp_jack_state(struct work_struct *work)
2325{
2326 struct via_spec *spec = container_of(work, struct via_spec,
2327 vt1708_hp_work.work);
2328 if (spec->codec_type != VT1708)
2329 return;
2330 /* if jack state toggled */
2331 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002332 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002333 spec->vt1708_hp_present ^= 1;
2334 via_hp_automute(spec->codec);
2335 }
2336 vt1708_start_hp_work(spec);
2337}
2338
Takashi Iwai337b9d02009-07-07 18:18:59 +02002339static int get_mux_nids(struct hda_codec *codec)
2340{
2341 struct via_spec *spec = codec->spec;
2342 hda_nid_t nid, conn[8];
2343 unsigned int type;
2344 int i, n;
2345
2346 for (i = 0; i < spec->num_adc_nids; i++) {
2347 nid = spec->adc_nids[i];
2348 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002349 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002350 if (type == AC_WID_PIN)
2351 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002352 n = snd_hda_get_connections(codec, nid, conn,
2353 ARRAY_SIZE(conn));
2354 if (n <= 0)
2355 break;
2356 if (n > 1) {
2357 spec->mux_nids[i] = nid;
2358 break;
2359 }
2360 nid = conn[0];
2361 }
2362 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002363 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002364}
2365
Joseph Chanc577b8a2006-11-29 15:29:40 +01002366static int patch_vt1708(struct hda_codec *codec)
2367{
2368 struct via_spec *spec;
2369 int err;
2370
2371 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002372 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002373 if (spec == NULL)
2374 return -ENOMEM;
2375
Takashi Iwai620e2b22011-06-17 17:19:19 +02002376 spec->aa_mix_nid = 0x17;
2377
Joseph Chanc577b8a2006-11-29 15:29:40 +01002378 /* automatic parse from the BIOS config */
2379 err = vt1708_parse_auto_config(codec);
2380 if (err < 0) {
2381 via_free(codec);
2382 return err;
2383 } else if (!err) {
2384 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2385 "from BIOS. Using genenic mode...\n");
2386 }
2387
Lydia Wang377ff312009-10-10 19:08:55 +08002388
Takashi Iwaibc9b5622008-05-23 17:50:27 +02002389 /* disable 32bit format on VT1708 */
2390 if (codec->vendor_id == 0x11061708)
2391 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002392
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002393 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002394 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2395 spec->num_mixers++;
2396 }
2397
2398 codec->patch_ops = via_patch_ops;
2399
2400 codec->patch_ops.init = via_auto_init;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002401#ifdef CONFIG_SND_HDA_POWER_SAVE
2402 spec->loopback.amplist = vt1708_loopbacks;
2403#endif
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002404 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002405 return 0;
2406}
2407
2408/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002409static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002410 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2411 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2412 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2413 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2414 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2415 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2416 {
2417 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2418 /* The multiple "Capture Source" controls confuse alsamixer
2419 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01002420 */
2421 /* .name = "Capture Source", */
2422 .name = "Input Source",
2423 .count = 1,
2424 .info = via_mux_enum_info,
2425 .get = via_mux_enum_get,
2426 .put = via_mux_enum_put,
2427 },
2428 { } /* end */
2429};
2430
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002431static const struct hda_verb vt1709_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002432 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2433 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002434 { }
2435};
2436
Joseph Chanc577b8a2006-11-29 15:29:40 +01002437/*
2438 * generic initialization of ADC, input mixers and output mixers
2439 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002440static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002441 /*
2442 * Unmute ADC0-2 and set the default input to mic-in
2443 */
2444 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2445 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2446 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2447
2448
Josepch Chanf7278fd2007-12-13 16:40:40 +01002449 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01002450 * mixer widget
2451 */
2452 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01002453 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2454 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2455 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2456 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2457 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002458
2459 /*
2460 * Set up output selector (0x1a, 0x1b, 0x29)
2461 */
2462 /* set vol=0 to output mixers */
2463 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2464 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2465 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2466
2467 /*
2468 * Unmute PW3 and PW4
2469 */
2470 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2471 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2472
Lydia Wangbfdc6752009-10-10 19:08:50 +08002473 /* Set input of PW4 as MW0 */
2474 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002475 /* PW9 Output enable */
2476 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2477 { }
2478};
2479
Joseph Chanc577b8a2006-11-29 15:29:40 +01002480static int vt1709_parse_auto_config(struct hda_codec *codec)
2481{
2482 struct via_spec *spec = codec->spec;
2483 int err;
2484
2485 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2486 if (err < 0)
2487 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002488 err = via_auto_fill_dac_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002489 if (err < 0)
2490 return err;
2491 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2492 return 0; /* can't find valid BIOS pin config */
2493
Takashi Iwai4a796162011-06-17 17:53:38 +02002494 err = via_auto_create_multi_out_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002495 if (err < 0)
2496 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002497 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002498 if (err < 0)
2499 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02002500 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002501 if (err < 0)
2502 return err;
2503
2504 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2505
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002506 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002507 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002508 spec->dig_in_pin = VT1709_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002509 if (spec->autocfg.dig_in_pin)
2510 spec->dig_in_nid = VT1709_DIGIN_NID;
2511
Takashi Iwai603c4012008-07-30 15:01:44 +02002512 if (spec->kctls.list)
2513 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002514
Harald Welte0aa62ae2008-09-09 15:58:27 +08002515 spec->input_mux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01002516
Harald Weltef8fdd492008-09-15 22:41:31 +08002517 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002518 via_hp_build(codec);
Harald Weltef8fdd492008-09-15 22:41:31 +08002519
Takashi Iwaif4a78282011-06-17 18:46:48 +02002520 err = via_smart51_build(codec);
2521 if (err < 0)
2522 return err;
2523
Joseph Chanc577b8a2006-11-29 15:29:40 +01002524 return 1;
2525}
2526
Takashi Iwaicb53c622007-08-10 17:21:45 +02002527#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002528static const struct hda_amp_list vt1709_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002529 { 0x18, HDA_INPUT, 1 },
2530 { 0x18, HDA_INPUT, 2 },
2531 { 0x18, HDA_INPUT, 3 },
2532 { 0x18, HDA_INPUT, 4 },
2533 { } /* end */
2534};
2535#endif
2536
Joseph Chanc577b8a2006-11-29 15:29:40 +01002537static int patch_vt1709_10ch(struct hda_codec *codec)
2538{
2539 struct via_spec *spec;
2540 int err;
2541
2542 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002543 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002544 if (spec == NULL)
2545 return -ENOMEM;
2546
Takashi Iwai620e2b22011-06-17 17:19:19 +02002547 spec->aa_mix_nid = 0x18;
2548
Joseph Chanc577b8a2006-11-29 15:29:40 +01002549 err = vt1709_parse_auto_config(codec);
2550 if (err < 0) {
2551 via_free(codec);
2552 return err;
2553 } else if (!err) {
2554 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2555 "Using genenic mode...\n");
2556 }
2557
Harald Welte69e52a82008-09-09 15:57:32 +08002558 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2559 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002560
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002561 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002562 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2563 spec->num_mixers++;
2564 }
2565
2566 codec->patch_ops = via_patch_ops;
2567
2568 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002569 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002570#ifdef CONFIG_SND_HDA_POWER_SAVE
2571 spec->loopback.amplist = vt1709_loopbacks;
2572#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002573
2574 return 0;
2575}
2576/*
2577 * generic initialization of ADC, input mixers and output mixers
2578 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002579static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002580 /*
2581 * Unmute ADC0-2 and set the default input to mic-in
2582 */
2583 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2584 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2585 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2586
2587
2588 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2589 * mixer widget
2590 */
2591 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2592 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2593 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2594 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2595 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2596 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2597
2598 /*
2599 * Set up output selector (0x1a, 0x1b, 0x29)
2600 */
2601 /* set vol=0 to output mixers */
2602 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2603 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2604 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2605
2606 /*
2607 * Unmute PW3 and PW4
2608 */
2609 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2610 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2611
2612 /* Set input of PW4 as MW0 */
2613 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002614 /* PW9 Output enable */
2615 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2616 { }
2617};
2618
2619static int patch_vt1709_6ch(struct hda_codec *codec)
2620{
2621 struct via_spec *spec;
2622 int err;
2623
2624 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002625 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002626 if (spec == NULL)
2627 return -ENOMEM;
2628
Takashi Iwai620e2b22011-06-17 17:19:19 +02002629 spec->aa_mix_nid = 0x18;
2630
Joseph Chanc577b8a2006-11-29 15:29:40 +01002631 err = vt1709_parse_auto_config(codec);
2632 if (err < 0) {
2633 via_free(codec);
2634 return err;
2635 } else if (!err) {
2636 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2637 "Using genenic mode...\n");
2638 }
2639
Harald Welte69e52a82008-09-09 15:57:32 +08002640 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2641 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002642
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002643 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002644 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2645 spec->num_mixers++;
2646 }
2647
2648 codec->patch_ops = via_patch_ops;
2649
2650 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002651 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002652#ifdef CONFIG_SND_HDA_POWER_SAVE
2653 spec->loopback.amplist = vt1709_loopbacks;
2654#endif
Josepch Chanf7278fd2007-12-13 16:40:40 +01002655 return 0;
2656}
2657
2658/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002659static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002660 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2661 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2662 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2663 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2664 {
2665 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2666 /* The multiple "Capture Source" controls confuse alsamixer
2667 * So call somewhat different..
Josepch Chanf7278fd2007-12-13 16:40:40 +01002668 */
2669 /* .name = "Capture Source", */
2670 .name = "Input Source",
2671 .count = 1,
2672 .info = via_mux_enum_info,
2673 .get = via_mux_enum_get,
2674 .put = via_mux_enum_put,
2675 },
2676 { } /* end */
2677};
2678/*
2679 * generic initialization of ADC, input mixers and output mixers
2680 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002681static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002682 /*
2683 * Unmute ADC0-1 and set the default input to mic-in
2684 */
2685 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2686 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2687
2688
2689 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2690 * mixer widget
2691 */
2692 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2693 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2694 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2695 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2696 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2697 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2698
2699 /*
2700 * Set up output mixers
2701 */
2702 /* set vol=0 to output mixers */
2703 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2704 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2705 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2706
2707 /* Setup default input to PW4 */
Lydia Wangbfdc6752009-10-10 19:08:50 +08002708 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
Josepch Chanf7278fd2007-12-13 16:40:40 +01002709 /* PW9 Output enable */
2710 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2711 /* PW10 Input enable */
2712 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2713 { }
2714};
2715
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002716static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002717 /*
2718 * Unmute ADC0-1 and set the default input to mic-in
2719 */
2720 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2721 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2722
2723
2724 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2725 * mixer widget
2726 */
2727 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2728 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2729 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2730 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2731 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2732 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2733
2734 /*
2735 * Set up output mixers
2736 */
2737 /* set vol=0 to output mixers */
2738 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2739 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2740 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2741
2742 /* Setup default input of PW4 to MW0 */
2743 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2744 /* PW9 Output enable */
2745 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2746 /* PW10 Input enable */
2747 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2748 { }
2749};
2750
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002751static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002752 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2753 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2754 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2755 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2756 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2757 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2758 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2759 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2760 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002761 { }
2762};
2763
Josepch Chanf7278fd2007-12-13 16:40:40 +01002764static int vt1708B_parse_auto_config(struct hda_codec *codec)
2765{
2766 struct via_spec *spec = codec->spec;
2767 int err;
2768
2769 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2770 if (err < 0)
2771 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002772 err = via_auto_fill_dac_nids(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002773 if (err < 0)
2774 return err;
2775 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2776 return 0; /* can't find valid BIOS pin config */
2777
Takashi Iwai4a796162011-06-17 17:53:38 +02002778 err = via_auto_create_multi_out_ctls(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002779 if (err < 0)
2780 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002781 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002782 if (err < 0)
2783 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02002784 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002785 if (err < 0)
2786 return err;
2787
2788 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2789
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002790 if (spec->autocfg.dig_outs)
Josepch Chanf7278fd2007-12-13 16:40:40 +01002791 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002792 spec->dig_in_pin = VT1708B_DIGIN_PIN;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002793 if (spec->autocfg.dig_in_pin)
2794 spec->dig_in_nid = VT1708B_DIGIN_NID;
2795
Takashi Iwai603c4012008-07-30 15:01:44 +02002796 if (spec->kctls.list)
2797 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002798
Harald Welte0aa62ae2008-09-09 15:58:27 +08002799 spec->input_mux = &spec->private_imux[0];
2800
Harald Weltef8fdd492008-09-15 22:41:31 +08002801 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002802 via_hp_build(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002803
Takashi Iwaif4a78282011-06-17 18:46:48 +02002804 err = via_smart51_build(codec);
2805 if (err < 0)
2806 return err;
2807
Josepch Chanf7278fd2007-12-13 16:40:40 +01002808 return 1;
2809}
2810
2811#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002812static const struct hda_amp_list vt1708B_loopbacks[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002813 { 0x16, HDA_INPUT, 1 },
2814 { 0x16, HDA_INPUT, 2 },
2815 { 0x16, HDA_INPUT, 3 },
2816 { 0x16, HDA_INPUT, 4 },
2817 { } /* end */
2818};
2819#endif
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002820
2821static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2822{
2823 struct via_spec *spec = codec->spec;
2824 int imux_is_smixer;
2825 unsigned int parm;
2826 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +08002827 if ((spec->codec_type != VT1708B_4CH) &&
2828 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002829 is_8ch = 1;
2830
2831 /* SW0 (17h) = stereo mixer */
2832 imux_is_smixer =
2833 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2834 == ((spec->codec_type == VT1708S) ? 5 : 0));
2835 /* inputs */
2836 /* PW 1/2/5 (1ah/1bh/1eh) */
2837 parm = AC_PWRST_D3;
2838 set_pin_power_state(codec, 0x1a, &parm);
2839 set_pin_power_state(codec, 0x1b, &parm);
2840 set_pin_power_state(codec, 0x1e, &parm);
2841 if (imux_is_smixer)
2842 parm = AC_PWRST_D0;
2843 /* SW0 (17h), AIW 0/1 (13h/14h) */
2844 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2845 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2846 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2847
2848 /* outputs */
2849 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2850 parm = AC_PWRST_D3;
2851 set_pin_power_state(codec, 0x19, &parm);
2852 if (spec->smart51_enabled)
2853 set_pin_power_state(codec, 0x1b, &parm);
2854 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2855 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2856
2857 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2858 if (is_8ch) {
2859 parm = AC_PWRST_D3;
2860 set_pin_power_state(codec, 0x22, &parm);
2861 if (spec->smart51_enabled)
2862 set_pin_power_state(codec, 0x1a, &parm);
2863 snd_hda_codec_write(codec, 0x26, 0,
2864 AC_VERB_SET_POWER_STATE, parm);
2865 snd_hda_codec_write(codec, 0x24, 0,
2866 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002867 } else if (codec->vendor_id == 0x11064397) {
2868 /* PW7(23h), SW2(27h), AOW2(25h) */
2869 parm = AC_PWRST_D3;
2870 set_pin_power_state(codec, 0x23, &parm);
2871 if (spec->smart51_enabled)
2872 set_pin_power_state(codec, 0x1a, &parm);
2873 snd_hda_codec_write(codec, 0x27, 0,
2874 AC_VERB_SET_POWER_STATE, parm);
2875 snd_hda_codec_write(codec, 0x25, 0,
2876 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002877 }
2878
2879 /* PW 3/4/7 (1ch/1dh/23h) */
2880 parm = AC_PWRST_D3;
2881 /* force to D0 for internal Speaker */
2882 set_pin_power_state(codec, 0x1c, &parm);
2883 set_pin_power_state(codec, 0x1d, &parm);
2884 if (is_8ch)
2885 set_pin_power_state(codec, 0x23, &parm);
2886
2887 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2888 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2889 imux_is_smixer ? AC_PWRST_D0 : parm);
2890 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2891 if (is_8ch) {
2892 snd_hda_codec_write(codec, 0x25, 0,
2893 AC_VERB_SET_POWER_STATE, parm);
2894 snd_hda_codec_write(codec, 0x27, 0,
2895 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002896 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2897 snd_hda_codec_write(codec, 0x25, 0,
2898 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002899}
2900
Lydia Wang518bf3b2009-10-10 19:07:29 +08002901static int patch_vt1708S(struct hda_codec *codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002902static int patch_vt1708B_8ch(struct hda_codec *codec)
2903{
2904 struct via_spec *spec;
2905 int err;
2906
Lydia Wang518bf3b2009-10-10 19:07:29 +08002907 if (get_codec_type(codec) == VT1708BCE)
2908 return patch_vt1708S(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002909 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002910 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002911 if (spec == NULL)
2912 return -ENOMEM;
2913
Takashi Iwai620e2b22011-06-17 17:19:19 +02002914 spec->aa_mix_nid = 0x16;
2915
Josepch Chanf7278fd2007-12-13 16:40:40 +01002916 /* automatic parse from the BIOS config */
2917 err = vt1708B_parse_auto_config(codec);
2918 if (err < 0) {
2919 via_free(codec);
2920 return err;
2921 } else if (!err) {
2922 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2923 "from BIOS. Using genenic mode...\n");
2924 }
2925
Harald Welte69e52a82008-09-09 15:57:32 +08002926 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
2927 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002928
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002929 if (spec->adc_nids && spec->input_mux) {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002930 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2931 spec->num_mixers++;
2932 }
2933
2934 codec->patch_ops = via_patch_ops;
2935
2936 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002937 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002938#ifdef CONFIG_SND_HDA_POWER_SAVE
2939 spec->loopback.amplist = vt1708B_loopbacks;
2940#endif
2941
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002942 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2943
Josepch Chanf7278fd2007-12-13 16:40:40 +01002944 return 0;
2945}
2946
2947static int patch_vt1708B_4ch(struct hda_codec *codec)
2948{
2949 struct via_spec *spec;
2950 int err;
2951
2952 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002953 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002954 if (spec == NULL)
2955 return -ENOMEM;
2956
Josepch Chanf7278fd2007-12-13 16:40:40 +01002957 /* automatic parse from the BIOS config */
2958 err = vt1708B_parse_auto_config(codec);
2959 if (err < 0) {
2960 via_free(codec);
2961 return err;
2962 } else if (!err) {
2963 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2964 "from BIOS. Using genenic mode...\n");
2965 }
2966
Harald Welte69e52a82008-09-09 15:57:32 +08002967 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
2968 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002969
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002970 if (spec->adc_nids && spec->input_mux) {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002971 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2972 spec->num_mixers++;
2973 }
2974
2975 codec->patch_ops = via_patch_ops;
2976
2977 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002978 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002979#ifdef CONFIG_SND_HDA_POWER_SAVE
2980 spec->loopback.amplist = vt1708B_loopbacks;
2981#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002982
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002983 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2984
Joseph Chanc577b8a2006-11-29 15:29:40 +01002985 return 0;
2986}
2987
Harald Welted949cac2008-09-09 15:56:01 +08002988/* Patch for VT1708S */
2989
2990/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002991static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08002992 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2993 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2994 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2995 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
Lydia Wang6369bcf2009-10-10 19:08:31 +08002996 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
2997 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
2998 HDA_INPUT),
Harald Welted949cac2008-09-09 15:56:01 +08002999 {
3000 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3001 /* The multiple "Capture Source" controls confuse alsamixer
3002 * So call somewhat different..
3003 */
3004 /* .name = "Capture Source", */
3005 .name = "Input Source",
3006 .count = 1,
3007 .info = via_mux_enum_info,
3008 .get = via_mux_enum_get,
3009 .put = via_mux_enum_put,
3010 },
3011 { } /* end */
3012};
3013
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003014static const struct hda_verb vt1708S_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003015 /* Unmute ADC0-1 and set the default input to mic-in */
3016 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3017 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3018
3019 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3020 * analog-loopback mixer widget */
3021 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3022 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3023 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3024 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3025 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3026 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3027
3028 /* Setup default input of PW4 to MW0 */
3029 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
Harald Welte5691ec72008-09-15 22:42:26 +08003030 /* PW9, PW10 Output enable */
Harald Welted949cac2008-09-09 15:56:01 +08003031 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welte5691ec72008-09-15 22:42:26 +08003032 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welted7426322008-09-15 22:43:23 +08003033 /* Enable Mic Boost Volume backdoor */
3034 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003035 /* don't bybass mixer */
3036 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08003037 { }
3038};
3039
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003040static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003041 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3042 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3043 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3044 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3045 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3046 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3047 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3048 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3049 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003050 { }
3051};
3052
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003053static const struct hda_verb vt1705_uniwill_init_verbs[] = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003054 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3055 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3056 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3057 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3058 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3059 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3060 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3061 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3062 { }
3063};
3064
Takashi Iwai9da29272009-05-07 16:31:14 +02003065/* fill out digital output widgets; one for master and one for slave outputs */
3066static void fill_dig_outs(struct hda_codec *codec)
3067{
3068 struct via_spec *spec = codec->spec;
3069 int i;
3070
3071 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3072 hda_nid_t nid;
3073 int conn;
3074
3075 nid = spec->autocfg.dig_out_pins[i];
3076 if (!nid)
3077 continue;
3078 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3079 if (conn < 1)
3080 continue;
3081 if (!spec->multiout.dig_out_nid)
3082 spec->multiout.dig_out_nid = nid;
3083 else {
3084 spec->slave_dig_outs[0] = nid;
3085 break; /* at most two dig outs */
3086 }
3087 }
3088}
3089
Harald Welted949cac2008-09-09 15:56:01 +08003090static int vt1708S_parse_auto_config(struct hda_codec *codec)
3091{
3092 struct via_spec *spec = codec->spec;
3093 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003094
Takashi Iwai9da29272009-05-07 16:31:14 +02003095 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08003096 if (err < 0)
3097 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003098 err = via_auto_fill_dac_nids(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003099 if (err < 0)
3100 return err;
3101 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3102 return 0; /* can't find valid BIOS pin config */
3103
Takashi Iwai4a796162011-06-17 17:53:38 +02003104 err = via_auto_create_multi_out_ctls(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003105 if (err < 0)
3106 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003107 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Harald Welted949cac2008-09-09 15:56:01 +08003108 if (err < 0)
3109 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02003110 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003111 if (err < 0)
3112 return err;
3113
3114 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3115
Takashi Iwai9da29272009-05-07 16:31:14 +02003116 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08003117
Takashi Iwai603c4012008-07-30 15:01:44 +02003118 if (spec->kctls.list)
3119 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08003120
Harald Welte0aa62ae2008-09-09 15:58:27 +08003121 spec->input_mux = &spec->private_imux[0];
3122
Harald Weltef8fdd492008-09-15 22:41:31 +08003123 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003124 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003125
Takashi Iwaif4a78282011-06-17 18:46:48 +02003126 err = via_smart51_build(codec);
3127 if (err < 0)
3128 return err;
3129
Harald Welted949cac2008-09-09 15:56:01 +08003130 return 1;
3131}
3132
3133#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003134static const struct hda_amp_list vt1708S_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003135 { 0x16, HDA_INPUT, 1 },
3136 { 0x16, HDA_INPUT, 2 },
3137 { 0x16, HDA_INPUT, 3 },
3138 { 0x16, HDA_INPUT, 4 },
3139 { } /* end */
3140};
3141#endif
3142
Lydia Wang6369bcf2009-10-10 19:08:31 +08003143static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3144 int offset, int num_steps, int step_size)
3145{
3146 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3147 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3148 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3149 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3150 (0 << AC_AMPCAP_MUTE_SHIFT));
3151}
3152
Harald Welted949cac2008-09-09 15:56:01 +08003153static int patch_vt1708S(struct hda_codec *codec)
3154{
3155 struct via_spec *spec;
3156 int err;
3157
3158 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003159 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003160 if (spec == NULL)
3161 return -ENOMEM;
3162
Takashi Iwai620e2b22011-06-17 17:19:19 +02003163 spec->aa_mix_nid = 0x16;
3164
Harald Welted949cac2008-09-09 15:56:01 +08003165 /* automatic parse from the BIOS config */
3166 err = vt1708S_parse_auto_config(codec);
3167 if (err < 0) {
3168 via_free(codec);
3169 return err;
3170 } else if (!err) {
3171 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3172 "from BIOS. Using genenic mode...\n");
3173 }
3174
Harald Welte69e52a82008-09-09 15:57:32 +08003175 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
Lydia Wangbc92df72011-03-23 17:56:05 +08003176 if (codec->vendor_id == 0x11064397)
3177 spec->init_verbs[spec->num_iverbs++] =
3178 vt1705_uniwill_init_verbs;
3179 else
3180 spec->init_verbs[spec->num_iverbs++] =
3181 vt1708S_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003182
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003183 if (spec->adc_nids && spec->input_mux) {
Lydia Wang6369bcf2009-10-10 19:08:31 +08003184 override_mic_boost(codec, 0x1a, 0, 3, 40);
3185 override_mic_boost(codec, 0x1e, 0, 3, 40);
Harald Welted949cac2008-09-09 15:56:01 +08003186 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3187 spec->num_mixers++;
3188 }
3189
3190 codec->patch_ops = via_patch_ops;
3191
3192 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003193 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08003194#ifdef CONFIG_SND_HDA_POWER_SAVE
3195 spec->loopback.amplist = vt1708S_loopbacks;
3196#endif
3197
Lydia Wang518bf3b2009-10-10 19:07:29 +08003198 /* correct names for VT1708BCE */
3199 if (get_codec_type(codec) == VT1708BCE) {
3200 kfree(codec->chip_name);
3201 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3202 snprintf(codec->bus->card->mixername,
3203 sizeof(codec->bus->card->mixername),
3204 "%s %s", codec->vendor_name, codec->chip_name);
Lydia Wang970f6302011-03-22 16:25:56 +08003205 }
Lydia Wangbc92df72011-03-23 17:56:05 +08003206 /* correct names for VT1705 */
3207 if (codec->vendor_id == 0x11064397) {
3208 kfree(codec->chip_name);
3209 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3210 snprintf(codec->bus->card->mixername,
3211 sizeof(codec->bus->card->mixername),
3212 "%s %s", codec->vendor_name, codec->chip_name);
3213 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003214 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +08003215 return 0;
3216}
3217
3218/* Patch for VT1702 */
3219
3220/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003221static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003222 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3223 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3224 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3225 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3226 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3227 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3228 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3229 HDA_INPUT),
3230 {
3231 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3232 /* The multiple "Capture Source" controls confuse alsamixer
3233 * So call somewhat different..
3234 */
3235 /* .name = "Capture Source", */
3236 .name = "Input Source",
3237 .count = 1,
3238 .info = via_mux_enum_info,
3239 .get = via_mux_enum_get,
3240 .put = via_mux_enum_put,
3241 },
3242 { } /* end */
3243};
3244
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003245static const struct hda_verb vt1702_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003246 /*
3247 * Unmute ADC0-1 and set the default input to mic-in
3248 */
3249 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3250 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3251 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3252
3253
3254 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3255 * mixer widget
3256 */
3257 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3258 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3259 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3260 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3261 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3262 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3263
3264 /* Setup default input of PW4 to MW0 */
3265 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3266 /* PW6 PW7 Output enable */
3267 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3268 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003269 /* mixer enable */
3270 {0x1, 0xF88, 0x3},
3271 /* GPIO 0~2 */
3272 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08003273 { }
3274};
3275
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003276static const struct hda_verb vt1702_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003277 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3278 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3279 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3280 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3281 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3282 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003283 { }
3284};
3285
Harald Welted949cac2008-09-09 15:56:01 +08003286static int vt1702_parse_auto_config(struct hda_codec *codec)
3287{
3288 struct via_spec *spec = codec->spec;
3289 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003290
Takashi Iwai9da29272009-05-07 16:31:14 +02003291 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08003292 if (err < 0)
3293 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003294 err = via_auto_fill_dac_nids(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003295 if (err < 0)
3296 return err;
3297 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3298 return 0; /* can't find valid BIOS pin config */
3299
Takashi Iwai4a796162011-06-17 17:53:38 +02003300 err = via_auto_create_multi_out_ctls(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003301 if (err < 0)
3302 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003303 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Harald Welted949cac2008-09-09 15:56:01 +08003304 if (err < 0)
3305 return err;
Lydia Wangc2c02ea2009-10-10 19:07:32 +08003306 /* limit AA path volume to 0 dB */
3307 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3308 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3309 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3310 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3311 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai620e2b22011-06-17 17:19:19 +02003312 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003313 if (err < 0)
3314 return err;
3315
3316 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3317
Takashi Iwai9da29272009-05-07 16:31:14 +02003318 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08003319
Takashi Iwai603c4012008-07-30 15:01:44 +02003320 if (spec->kctls.list)
3321 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08003322
Harald Welte0aa62ae2008-09-09 15:58:27 +08003323 spec->input_mux = &spec->private_imux[0];
3324
Harald Weltef8fdd492008-09-15 22:41:31 +08003325 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003326 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003327
3328 return 1;
3329}
3330
3331#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003332static const struct hda_amp_list vt1702_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003333 { 0x1A, HDA_INPUT, 1 },
3334 { 0x1A, HDA_INPUT, 2 },
3335 { 0x1A, HDA_INPUT, 3 },
3336 { 0x1A, HDA_INPUT, 4 },
3337 { } /* end */
3338};
3339#endif
3340
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003341static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3342{
3343 int imux_is_smixer =
3344 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3345 unsigned int parm;
3346 /* inputs */
3347 /* PW 1/2/5 (14h/15h/18h) */
3348 parm = AC_PWRST_D3;
3349 set_pin_power_state(codec, 0x14, &parm);
3350 set_pin_power_state(codec, 0x15, &parm);
3351 set_pin_power_state(codec, 0x18, &parm);
3352 if (imux_is_smixer)
3353 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3354 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3355 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3356 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
3357 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3358 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
3359
3360 /* outputs */
3361 /* PW 3/4 (16h/17h) */
3362 parm = AC_PWRST_D3;
3363 set_pin_power_state(codec, 0x17, &parm);
3364 set_pin_power_state(codec, 0x16, &parm);
3365 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3366 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
3367 imux_is_smixer ? AC_PWRST_D0 : parm);
3368 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3369 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3370}
3371
Harald Welted949cac2008-09-09 15:56:01 +08003372static int patch_vt1702(struct hda_codec *codec)
3373{
3374 struct via_spec *spec;
3375 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003376
3377 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003378 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003379 if (spec == NULL)
3380 return -ENOMEM;
3381
Takashi Iwai620e2b22011-06-17 17:19:19 +02003382 spec->aa_mix_nid = 0x1a;
3383
Harald Welted949cac2008-09-09 15:56:01 +08003384 /* automatic parse from the BIOS config */
3385 err = vt1702_parse_auto_config(codec);
3386 if (err < 0) {
3387 via_free(codec);
3388 return err;
3389 } else if (!err) {
3390 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3391 "from BIOS. Using genenic mode...\n");
3392 }
3393
Harald Welte69e52a82008-09-09 15:57:32 +08003394 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
3395 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003396
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003397 if (spec->adc_nids && spec->input_mux) {
Harald Welted949cac2008-09-09 15:56:01 +08003398 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3399 spec->num_mixers++;
3400 }
3401
3402 codec->patch_ops = via_patch_ops;
3403
3404 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003405 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08003406#ifdef CONFIG_SND_HDA_POWER_SAVE
3407 spec->loopback.amplist = vt1702_loopbacks;
3408#endif
3409
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003410 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08003411 return 0;
3412}
3413
Lydia Wangeb7188c2009-10-10 19:08:34 +08003414/* Patch for VT1718S */
3415
3416/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003417static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08003418 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
3419 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
3420 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
3421 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
3422 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
3423 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
3424 HDA_INPUT),
3425 {
3426 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3427 /* The multiple "Capture Source" controls confuse alsamixer
3428 * So call somewhat different..
3429 */
3430 .name = "Input Source",
3431 .count = 2,
3432 .info = via_mux_enum_info,
3433 .get = via_mux_enum_get,
3434 .put = via_mux_enum_put,
3435 },
3436 { } /* end */
3437};
3438
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003439static const struct hda_verb vt1718S_volume_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08003440 /*
3441 * Unmute ADC0-1 and set the default input to mic-in
3442 */
3443 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3444 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3445
Lydia Wang4ab2d532011-03-24 12:42:03 +08003446 /* Enable MW0 adjust Gain 5 */
3447 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08003448 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3449 * mixer widget
3450 */
3451 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3452 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3453 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3454 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3455 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
Lydia Wang4ab2d532011-03-24 12:42:03 +08003456 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
Lydia Wangeb7188c2009-10-10 19:08:34 +08003457
3458 /* Setup default input of Front HP to MW9 */
3459 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
3460 /* PW9 PW10 Output enable */
3461 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
3462 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
3463 /* PW11 Input enable */
3464 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
3465 /* Enable Boost Volume backdoor */
3466 {0x1, 0xf88, 0x8},
3467 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
3468 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3469 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3470 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3471 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3472 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3473 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3474 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3475 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3476 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3477 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3478 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
3479 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
3480 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
3481 /* Unmute MW4's index 0 */
3482 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3483 { }
3484};
3485
3486
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003487static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08003488 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
3489 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3490 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3491 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3492 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3493 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3494 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3495 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3496 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3497 { }
3498};
3499
Lydia Wangeb7188c2009-10-10 19:08:34 +08003500static int vt1718S_parse_auto_config(struct hda_codec *codec)
3501{
3502 struct via_spec *spec = codec->spec;
3503 int err;
3504
3505 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3506
3507 if (err < 0)
3508 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003509 err = via_auto_fill_dac_nids(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003510 if (err < 0)
3511 return err;
3512 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3513 return 0; /* can't find valid BIOS pin config */
3514
Takashi Iwai4a796162011-06-17 17:53:38 +02003515 err = via_auto_create_multi_out_ctls(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003516 if (err < 0)
3517 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003518 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003519 if (err < 0)
3520 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02003521 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003522 if (err < 0)
3523 return err;
3524
3525 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3526
3527 fill_dig_outs(codec);
3528
3529 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
3530 spec->dig_in_nid = 0x13;
3531
3532 if (spec->kctls.list)
3533 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3534
3535 spec->input_mux = &spec->private_imux[0];
3536
3537 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003538 via_hp_build(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003539
Takashi Iwaif4a78282011-06-17 18:46:48 +02003540 err = via_smart51_build(codec);
3541 if (err < 0)
3542 return err;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003543
3544 return 1;
3545}
3546
3547#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003548static const struct hda_amp_list vt1718S_loopbacks[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08003549 { 0x21, HDA_INPUT, 1 },
3550 { 0x21, HDA_INPUT, 2 },
3551 { 0x21, HDA_INPUT, 3 },
3552 { 0x21, HDA_INPUT, 4 },
3553 { } /* end */
3554};
3555#endif
3556
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003557static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3558{
3559 struct via_spec *spec = codec->spec;
3560 int imux_is_smixer;
3561 unsigned int parm;
3562 /* MUX6 (1eh) = stereo mixer */
3563 imux_is_smixer =
3564 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3565 /* inputs */
3566 /* PW 5/6/7 (29h/2ah/2bh) */
3567 parm = AC_PWRST_D3;
3568 set_pin_power_state(codec, 0x29, &parm);
3569 set_pin_power_state(codec, 0x2a, &parm);
3570 set_pin_power_state(codec, 0x2b, &parm);
3571 if (imux_is_smixer)
3572 parm = AC_PWRST_D0;
3573 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3574 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3575 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3576 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3577 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3578
3579 /* outputs */
3580 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3581 parm = AC_PWRST_D3;
3582 set_pin_power_state(codec, 0x27, &parm);
3583 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
3584 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
3585
3586 /* PW2 (26h), AOW2 (ah) */
3587 parm = AC_PWRST_D3;
3588 set_pin_power_state(codec, 0x26, &parm);
3589 if (spec->smart51_enabled)
3590 set_pin_power_state(codec, 0x2b, &parm);
3591 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
3592
3593 /* PW0 (24h), AOW0 (8h) */
3594 parm = AC_PWRST_D3;
3595 set_pin_power_state(codec, 0x24, &parm);
3596 if (!spec->hp_independent_mode) /* check for redirected HP */
3597 set_pin_power_state(codec, 0x28, &parm);
3598 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3599 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3600 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
3601 imux_is_smixer ? AC_PWRST_D0 : parm);
3602
3603 /* PW1 (25h), AOW1 (9h) */
3604 parm = AC_PWRST_D3;
3605 set_pin_power_state(codec, 0x25, &parm);
3606 if (spec->smart51_enabled)
3607 set_pin_power_state(codec, 0x2a, &parm);
3608 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
3609
3610 if (spec->hp_independent_mode) {
3611 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3612 parm = AC_PWRST_D3;
3613 set_pin_power_state(codec, 0x28, &parm);
3614 snd_hda_codec_write(codec, 0x1b, 0,
3615 AC_VERB_SET_POWER_STATE, parm);
3616 snd_hda_codec_write(codec, 0x34, 0,
3617 AC_VERB_SET_POWER_STATE, parm);
3618 snd_hda_codec_write(codec, 0xc, 0,
3619 AC_VERB_SET_POWER_STATE, parm);
3620 }
3621}
3622
Lydia Wangeb7188c2009-10-10 19:08:34 +08003623static int patch_vt1718S(struct hda_codec *codec)
3624{
3625 struct via_spec *spec;
3626 int err;
3627
3628 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003629 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003630 if (spec == NULL)
3631 return -ENOMEM;
3632
Takashi Iwai620e2b22011-06-17 17:19:19 +02003633 spec->aa_mix_nid = 0x21;
3634
Lydia Wangeb7188c2009-10-10 19:08:34 +08003635 /* automatic parse from the BIOS config */
3636 err = vt1718S_parse_auto_config(codec);
3637 if (err < 0) {
3638 via_free(codec);
3639 return err;
3640 } else if (!err) {
3641 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3642 "from BIOS. Using genenic mode...\n");
3643 }
3644
3645 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
3646 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
3647
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003648 if (spec->adc_nids && spec->input_mux) {
Lydia Wangbb3c6bf2009-10-10 19:08:39 +08003649 override_mic_boost(codec, 0x2b, 0, 3, 40);
3650 override_mic_boost(codec, 0x29, 0, 3, 40);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003651 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
3652 spec->num_mixers++;
3653 }
3654
3655 codec->patch_ops = via_patch_ops;
3656
3657 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11003658 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003659
3660#ifdef CONFIG_SND_HDA_POWER_SAVE
3661 spec->loopback.amplist = vt1718S_loopbacks;
3662#endif
3663
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003664 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3665
Lydia Wangeb7188c2009-10-10 19:08:34 +08003666 return 0;
3667}
Lydia Wangf3db4232009-10-10 19:08:41 +08003668
3669/* Patch for VT1716S */
3670
3671static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3672 struct snd_ctl_elem_info *uinfo)
3673{
3674 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3675 uinfo->count = 1;
3676 uinfo->value.integer.min = 0;
3677 uinfo->value.integer.max = 1;
3678 return 0;
3679}
3680
3681static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3682 struct snd_ctl_elem_value *ucontrol)
3683{
3684 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3685 int index = 0;
3686
3687 index = snd_hda_codec_read(codec, 0x26, 0,
3688 AC_VERB_GET_CONNECT_SEL, 0);
3689 if (index != -1)
3690 *ucontrol->value.integer.value = index;
3691
3692 return 0;
3693}
3694
3695static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3696 struct snd_ctl_elem_value *ucontrol)
3697{
3698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3699 struct via_spec *spec = codec->spec;
3700 int index = *ucontrol->value.integer.value;
3701
3702 snd_hda_codec_write(codec, 0x26, 0,
3703 AC_VERB_SET_CONNECT_SEL, index);
3704 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003705 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003706 return 1;
3707}
3708
3709/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003710static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003711 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3712 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3713 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3714 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3715 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3716 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3717 HDA_INPUT),
3718 {
3719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3720 .name = "Input Source",
3721 .count = 1,
3722 .info = via_mux_enum_info,
3723 .get = via_mux_enum_get,
3724 .put = via_mux_enum_put,
3725 },
3726 { } /* end */
3727};
3728
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003729static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003730 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3731 {
3732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3733 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003734 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08003735 .count = 1,
3736 .info = vt1716s_dmic_info,
3737 .get = vt1716s_dmic_get,
3738 .put = vt1716s_dmic_put,
3739 },
3740 {} /* end */
3741};
3742
3743
3744/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003745static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003746 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3747 { } /* end */
3748};
3749
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003750static const struct hda_verb vt1716S_volume_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003751 /*
3752 * Unmute ADC0-1 and set the default input to mic-in
3753 */
3754 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3755 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3756
3757
3758 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3759 * mixer widget
3760 */
3761 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3762 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3763 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3764 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3765 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3766 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3767
3768 /* MUX Indices: Stereo Mixer = 5 */
3769 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
3770
3771 /* Setup default input of PW4 to MW0 */
3772 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3773
3774 /* Setup default input of SW1 as MW0 */
3775 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
3776
3777 /* Setup default input of SW4 as AOW0 */
3778 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
3779
3780 /* PW9 PW10 Output enable */
3781 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3782 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3783
3784 /* Unmute SW1, PW12 */
3785 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3786 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3787 /* PW12 Output enable */
3788 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3789 /* Enable Boost Volume backdoor */
3790 {0x1, 0xf8a, 0x80},
3791 /* don't bybass mixer */
3792 {0x1, 0xf88, 0xc0},
3793 /* Enable mono output */
3794 {0x1, 0xf90, 0x08},
3795 { }
3796};
3797
3798
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003799static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003800 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3801 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3802 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3803 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3804 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3805 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
3806 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
3807 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3808 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3809 { }
3810};
3811
Lydia Wangf3db4232009-10-10 19:08:41 +08003812static int vt1716S_parse_auto_config(struct hda_codec *codec)
3813{
3814 struct via_spec *spec = codec->spec;
3815 int err;
3816
3817 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3818 if (err < 0)
3819 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003820 err = via_auto_fill_dac_nids(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003821 if (err < 0)
3822 return err;
3823 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3824 return 0; /* can't find valid BIOS pin config */
3825
Takashi Iwai4a796162011-06-17 17:53:38 +02003826 err = via_auto_create_multi_out_ctls(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003827 if (err < 0)
3828 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02003829 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08003830 if (err < 0)
3831 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02003832 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangf3db4232009-10-10 19:08:41 +08003833 if (err < 0)
3834 return err;
3835
3836 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3837
3838 fill_dig_outs(codec);
3839
3840 if (spec->kctls.list)
3841 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3842
3843 spec->input_mux = &spec->private_imux[0];
3844
3845 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003846 via_hp_build(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003847
Takashi Iwaif4a78282011-06-17 18:46:48 +02003848 err = via_smart51_build(codec);
3849 if (err < 0)
3850 return err;
Lydia Wangf3db4232009-10-10 19:08:41 +08003851
3852 return 1;
3853}
3854
3855#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003856static const struct hda_amp_list vt1716S_loopbacks[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003857 { 0x16, HDA_INPUT, 1 },
3858 { 0x16, HDA_INPUT, 2 },
3859 { 0x16, HDA_INPUT, 3 },
3860 { 0x16, HDA_INPUT, 4 },
3861 { } /* end */
3862};
3863#endif
3864
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003865static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3866{
3867 struct via_spec *spec = codec->spec;
3868 int imux_is_smixer;
3869 unsigned int parm;
3870 unsigned int mono_out, present;
3871 /* SW0 (17h) = stereo mixer */
3872 imux_is_smixer =
3873 (snd_hda_codec_read(codec, 0x17, 0,
3874 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3875 /* inputs */
3876 /* PW 1/2/5 (1ah/1bh/1eh) */
3877 parm = AC_PWRST_D3;
3878 set_pin_power_state(codec, 0x1a, &parm);
3879 set_pin_power_state(codec, 0x1b, &parm);
3880 set_pin_power_state(codec, 0x1e, &parm);
3881 if (imux_is_smixer)
3882 parm = AC_PWRST_D0;
3883 /* SW0 (17h), AIW0(13h) */
3884 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3885 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3886
3887 parm = AC_PWRST_D3;
3888 set_pin_power_state(codec, 0x1e, &parm);
3889 /* PW11 (22h) */
3890 if (spec->dmic_enabled)
3891 set_pin_power_state(codec, 0x22, &parm);
3892 else
3893 snd_hda_codec_write(codec, 0x22, 0,
3894 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3895
3896 /* SW2(26h), AIW1(14h) */
3897 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3898 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3899
3900 /* outputs */
3901 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3902 parm = AC_PWRST_D3;
3903 set_pin_power_state(codec, 0x19, &parm);
3904 /* Smart 5.1 PW2(1bh) */
3905 if (spec->smart51_enabled)
3906 set_pin_power_state(codec, 0x1b, &parm);
3907 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3908 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3909
3910 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3911 parm = AC_PWRST_D3;
3912 set_pin_power_state(codec, 0x23, &parm);
3913 /* Smart 5.1 PW1(1ah) */
3914 if (spec->smart51_enabled)
3915 set_pin_power_state(codec, 0x1a, &parm);
3916 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3917
3918 /* Smart 5.1 PW5(1eh) */
3919 if (spec->smart51_enabled)
3920 set_pin_power_state(codec, 0x1e, &parm);
3921 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3922
3923 /* Mono out */
3924 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3925 present = snd_hda_jack_detect(codec, 0x1c);
3926
3927 if (present)
3928 mono_out = 0;
3929 else {
3930 present = snd_hda_jack_detect(codec, 0x1d);
3931 if (!spec->hp_independent_mode && present)
3932 mono_out = 0;
3933 else
3934 mono_out = 1;
3935 }
3936 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3937 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3938 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3939 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3940
3941 /* PW 3/4 (1ch/1dh) */
3942 parm = AC_PWRST_D3;
3943 set_pin_power_state(codec, 0x1c, &parm);
3944 set_pin_power_state(codec, 0x1d, &parm);
3945 /* HP Independent Mode, power on AOW3 */
3946 if (spec->hp_independent_mode)
3947 snd_hda_codec_write(codec, 0x25, 0,
3948 AC_VERB_SET_POWER_STATE, parm);
3949
3950 /* force to D0 for internal Speaker */
3951 /* MW0 (16h), AOW0 (10h) */
3952 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3953 imux_is_smixer ? AC_PWRST_D0 : parm);
3954 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3955 mono_out ? AC_PWRST_D0 : parm);
3956}
3957
Lydia Wangf3db4232009-10-10 19:08:41 +08003958static int patch_vt1716S(struct hda_codec *codec)
3959{
3960 struct via_spec *spec;
3961 int err;
3962
3963 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003964 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003965 if (spec == NULL)
3966 return -ENOMEM;
3967
Takashi Iwai620e2b22011-06-17 17:19:19 +02003968 spec->aa_mix_nid = 0x16;
3969
Lydia Wangf3db4232009-10-10 19:08:41 +08003970 /* automatic parse from the BIOS config */
3971 err = vt1716S_parse_auto_config(codec);
3972 if (err < 0) {
3973 via_free(codec);
3974 return err;
3975 } else if (!err) {
3976 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3977 "from BIOS. Using genenic mode...\n");
3978 }
3979
3980 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
3981 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
3982
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003983 if (spec->adc_nids && spec->input_mux) {
Lydia Wangf3db4232009-10-10 19:08:41 +08003984 override_mic_boost(codec, 0x1a, 0, 3, 40);
3985 override_mic_boost(codec, 0x1e, 0, 3, 40);
3986 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
3987 spec->num_mixers++;
3988 }
3989
3990 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3991 spec->num_mixers++;
3992
3993 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3994
3995 codec->patch_ops = via_patch_ops;
3996
3997 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11003998 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangf3db4232009-10-10 19:08:41 +08003999
4000#ifdef CONFIG_SND_HDA_POWER_SAVE
4001 spec->loopback.amplist = vt1716S_loopbacks;
4002#endif
4003
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004004 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08004005 return 0;
4006}
Lydia Wang25eaba22009-10-10 19:08:43 +08004007
4008/* for vt2002P */
4009
4010/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004011static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08004012 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4013 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4014 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4015 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4016 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4017 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4018 HDA_INPUT),
4019 {
4020 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4021 /* The multiple "Capture Source" controls confuse alsamixer
4022 * So call somewhat different..
4023 */
4024 /* .name = "Capture Source", */
4025 .name = "Input Source",
4026 .count = 2,
4027 .info = via_mux_enum_info,
4028 .get = via_mux_enum_get,
4029 .put = via_mux_enum_put,
4030 },
4031 { } /* end */
4032};
4033
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004034static const struct hda_verb vt2002P_volume_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08004035 /* Class-D speaker related verbs */
4036 {0x1, 0xfe0, 0x4},
4037 {0x1, 0xfe9, 0x80},
4038 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08004039 /*
4040 * Unmute ADC0-1 and set the default input to mic-in
4041 */
4042 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4043 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4044
4045
4046 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4047 * mixer widget
4048 */
4049 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4050 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4051 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4052 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4053 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4054 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4055
4056 /* MUX Indices: Mic = 0 */
4057 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
4058 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
4059
4060 /* PW9 Output enable */
4061 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4062
4063 /* Enable Boost Volume backdoor */
4064 {0x1, 0xfb9, 0x24},
4065
4066 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
4067 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4068 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4069 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4070 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4071 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4072 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4073 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4074 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4075
4076 /* set MUX0/1/4/8 = 0 (AOW0) */
4077 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
4078 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
4079 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
4080 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
4081
4082 /* set PW0 index=0 (MW0) */
4083 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
4084
4085 /* Enable AOW0 to MW9 */
4086 {0x1, 0xfb8, 0x88},
4087 { }
4088};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004089static const struct hda_verb vt1802_volume_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08004090 /*
4091 * Unmute ADC0-1 and set the default input to mic-in
4092 */
4093 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4094 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4095
4096
4097 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4098 * mixer widget
4099 */
4100 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4101 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4102 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4103 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4104 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4105 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4106
4107 /* MUX Indices: Mic = 0 */
4108 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
4109 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
4110
4111 /* PW9 Output enable */
4112 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4113
4114 /* Enable Boost Volume backdoor */
4115 {0x1, 0xfb9, 0x24},
4116
4117 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
4118 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4119 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4120 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4121 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4122 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4123 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4124 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4125 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4126
4127 /* set MUX0/1/4/8 = 0 (AOW0) */
4128 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
4129 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
4130 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
4131 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
4132
4133 /* set PW0 index=0 (MW0) */
4134 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
4135
4136 /* Enable AOW0 to MW9 */
4137 {0x1, 0xfb8, 0x88},
4138 { }
4139};
Lydia Wang25eaba22009-10-10 19:08:43 +08004140
4141
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004142static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08004143 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
4144 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4145 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
4146 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4147 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4148 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4149 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4150 { }
4151};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004152static const struct hda_verb vt1802_uniwill_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08004153 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
4154 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4155 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4156 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4157 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4158 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4159 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4160 { }
4161};
Lydia Wang25eaba22009-10-10 19:08:43 +08004162
Lydia Wang25eaba22009-10-10 19:08:43 +08004163static int vt2002P_parse_auto_config(struct hda_codec *codec)
4164{
4165 struct via_spec *spec = codec->spec;
4166 int err;
4167
4168
4169 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4170 if (err < 0)
4171 return err;
4172
Takashi Iwai4a796162011-06-17 17:53:38 +02004173 err = via_auto_fill_dac_nids(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08004174 if (err < 0)
4175 return err;
4176
4177 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4178 return 0; /* can't find valid BIOS pin config */
4179
Takashi Iwai4a796162011-06-17 17:53:38 +02004180 err = via_auto_create_multi_out_ctls(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08004181 if (err < 0)
4182 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02004183 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08004184 if (err < 0)
4185 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02004186 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wang25eaba22009-10-10 19:08:43 +08004187 if (err < 0)
4188 return err;
4189
4190 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4191
4192 fill_dig_outs(codec);
4193
4194 if (spec->kctls.list)
4195 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4196
4197 spec->input_mux = &spec->private_imux[0];
4198
4199 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004200 via_hp_build(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08004201
4202 return 1;
4203}
4204
4205#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004206static const struct hda_amp_list vt2002P_loopbacks[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08004207 { 0x21, HDA_INPUT, 0 },
4208 { 0x21, HDA_INPUT, 1 },
4209 { 0x21, HDA_INPUT, 2 },
4210 { } /* end */
4211};
4212#endif
4213
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004214static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
4215{
4216 struct via_spec *spec = codec->spec;
4217 int imux_is_smixer;
4218 unsigned int parm;
4219 unsigned int present;
4220 /* MUX9 (1eh) = stereo mixer */
4221 imux_is_smixer =
4222 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4223 /* inputs */
4224 /* PW 5/6/7 (29h/2ah/2bh) */
4225 parm = AC_PWRST_D3;
4226 set_pin_power_state(codec, 0x29, &parm);
4227 set_pin_power_state(codec, 0x2a, &parm);
4228 set_pin_power_state(codec, 0x2b, &parm);
4229 parm = AC_PWRST_D0;
4230 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
4231 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4232 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4233 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4234 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4235
4236 /* outputs */
4237 /* AOW0 (8h)*/
4238 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4239
Lydia Wang118909562011-03-23 17:57:34 +08004240 if (spec->codec_type == VT1802) {
4241 /* PW4 (28h), MW4 (18h), MUX4(38h) */
4242 parm = AC_PWRST_D3;
4243 set_pin_power_state(codec, 0x28, &parm);
4244 snd_hda_codec_write(codec, 0x18, 0,
4245 AC_VERB_SET_POWER_STATE, parm);
4246 snd_hda_codec_write(codec, 0x38, 0,
4247 AC_VERB_SET_POWER_STATE, parm);
4248 } else {
4249 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
4250 parm = AC_PWRST_D3;
4251 set_pin_power_state(codec, 0x26, &parm);
4252 snd_hda_codec_write(codec, 0x1c, 0,
4253 AC_VERB_SET_POWER_STATE, parm);
4254 snd_hda_codec_write(codec, 0x37, 0,
4255 AC_VERB_SET_POWER_STATE, parm);
4256 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004257
Lydia Wang118909562011-03-23 17:57:34 +08004258 if (spec->codec_type == VT1802) {
4259 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
4260 parm = AC_PWRST_D3;
4261 set_pin_power_state(codec, 0x25, &parm);
4262 snd_hda_codec_write(codec, 0x15, 0,
4263 AC_VERB_SET_POWER_STATE, parm);
4264 snd_hda_codec_write(codec, 0x35, 0,
4265 AC_VERB_SET_POWER_STATE, parm);
4266 } else {
4267 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
4268 parm = AC_PWRST_D3;
4269 set_pin_power_state(codec, 0x25, &parm);
4270 snd_hda_codec_write(codec, 0x19, 0,
4271 AC_VERB_SET_POWER_STATE, parm);
4272 snd_hda_codec_write(codec, 0x35, 0,
4273 AC_VERB_SET_POWER_STATE, parm);
4274 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004275
4276 if (spec->hp_independent_mode)
4277 snd_hda_codec_write(codec, 0x9, 0,
4278 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4279
4280 /* Class-D */
4281 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
4282 present = snd_hda_jack_detect(codec, 0x25);
4283
4284 parm = AC_PWRST_D3;
4285 set_pin_power_state(codec, 0x24, &parm);
4286 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08004287 if (spec->codec_type == VT1802)
4288 snd_hda_codec_write(codec, 0x14, 0,
4289 AC_VERB_SET_POWER_STATE, parm);
4290 else
4291 snd_hda_codec_write(codec, 0x18, 0,
4292 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004293 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
4294
4295 /* Mono Out */
4296 present = snd_hda_jack_detect(codec, 0x26);
4297
4298 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08004299 if (spec->codec_type == VT1802) {
4300 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
4301 snd_hda_codec_write(codec, 0x33, 0,
4302 AC_VERB_SET_POWER_STATE, parm);
4303 snd_hda_codec_write(codec, 0x1c, 0,
4304 AC_VERB_SET_POWER_STATE, parm);
4305 snd_hda_codec_write(codec, 0x3c, 0,
4306 AC_VERB_SET_POWER_STATE, parm);
4307 } else {
4308 /* PW15 (31h), MW8(17h), MUX8(3bh) */
4309 snd_hda_codec_write(codec, 0x31, 0,
4310 AC_VERB_SET_POWER_STATE, parm);
4311 snd_hda_codec_write(codec, 0x17, 0,
4312 AC_VERB_SET_POWER_STATE, parm);
4313 snd_hda_codec_write(codec, 0x3b, 0,
4314 AC_VERB_SET_POWER_STATE, parm);
4315 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004316 /* MW9 (21h) */
4317 if (imux_is_smixer || !is_aa_path_mute(codec))
4318 snd_hda_codec_write(codec, 0x21, 0,
4319 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4320 else
4321 snd_hda_codec_write(codec, 0x21, 0,
4322 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4323}
Lydia Wang25eaba22009-10-10 19:08:43 +08004324
4325/* patch for vt2002P */
4326static int patch_vt2002P(struct hda_codec *codec)
4327{
4328 struct via_spec *spec;
4329 int err;
4330
4331 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004332 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08004333 if (spec == NULL)
4334 return -ENOMEM;
4335
Takashi Iwai620e2b22011-06-17 17:19:19 +02004336 spec->aa_mix_nid = 0x21;
4337
Lydia Wang25eaba22009-10-10 19:08:43 +08004338 /* automatic parse from the BIOS config */
4339 err = vt2002P_parse_auto_config(codec);
4340 if (err < 0) {
4341 via_free(codec);
4342 return err;
4343 } else if (!err) {
4344 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4345 "from BIOS. Using genenic mode...\n");
4346 }
4347
Lydia Wang118909562011-03-23 17:57:34 +08004348 if (spec->codec_type == VT1802)
4349 spec->init_verbs[spec->num_iverbs++] =
4350 vt1802_volume_init_verbs;
4351 else
4352 spec->init_verbs[spec->num_iverbs++] =
4353 vt2002P_volume_init_verbs;
Lydia Wang25eaba22009-10-10 19:08:43 +08004354
Lydia Wang118909562011-03-23 17:57:34 +08004355 if (spec->codec_type == VT1802)
4356 spec->init_verbs[spec->num_iverbs++] =
4357 vt1802_uniwill_init_verbs;
4358 else
4359 spec->init_verbs[spec->num_iverbs++] =
4360 vt2002P_uniwill_init_verbs;
4361
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004362 if (spec->adc_nids && spec->input_mux) {
Lydia Wang25eaba22009-10-10 19:08:43 +08004363 override_mic_boost(codec, 0x2b, 0, 3, 40);
4364 override_mic_boost(codec, 0x29, 0, 3, 40);
4365 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
4366 spec->num_mixers++;
4367 }
4368
4369 codec->patch_ops = via_patch_ops;
4370
4371 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11004372 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wang25eaba22009-10-10 19:08:43 +08004373
4374#ifdef CONFIG_SND_HDA_POWER_SAVE
4375 spec->loopback.amplist = vt2002P_loopbacks;
4376#endif
4377
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004378 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08004379 return 0;
4380}
Lydia Wangab6734e2009-10-10 19:08:46 +08004381
4382/* for vt1812 */
4383
4384/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004385static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08004386 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4387 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4388 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4389 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4390 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4391 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
4392 HDA_INPUT),
4393 {
4394 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4395 /* The multiple "Capture Source" controls confuse alsamixer
4396 * So call somewhat different..
4397 */
4398 .name = "Input Source",
4399 .count = 2,
4400 .info = via_mux_enum_info,
4401 .get = via_mux_enum_get,
4402 .put = via_mux_enum_put,
4403 },
4404 { } /* end */
4405};
4406
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004407static const struct hda_verb vt1812_volume_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08004408 /*
4409 * Unmute ADC0-1 and set the default input to mic-in
4410 */
4411 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4412 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4413
4414
4415 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4416 * mixer widget
4417 */
4418 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4419 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4420 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4421 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4422 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4423 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4424
4425 /* MUX Indices: Mic = 0 */
4426 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
4427 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
4428
4429 /* PW9 Output enable */
4430 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4431
4432 /* Enable Boost Volume backdoor */
4433 {0x1, 0xfb9, 0x24},
4434
4435 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
4436 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4437 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4438 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4439 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4440 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4441 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4442 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4443 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4444 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4445 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4446
4447 /* set MUX0/1/4/13/15 = 0 (AOW0) */
4448 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
4449 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
4450 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
4451 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
4452 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
4453
4454 /* Enable AOW0 to MW9 */
4455 {0x1, 0xfb8, 0xa8},
4456 { }
4457};
4458
4459
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004460static const struct hda_verb vt1812_uniwill_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08004461 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
4462 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4463 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
4464 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4465 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4466 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4467 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4468 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4469 { }
4470};
4471
Lydia Wangab6734e2009-10-10 19:08:46 +08004472static int vt1812_parse_auto_config(struct hda_codec *codec)
4473{
4474 struct via_spec *spec = codec->spec;
4475 int err;
4476
4477
4478 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4479 if (err < 0)
4480 return err;
4481 fill_dig_outs(codec);
Takashi Iwai4a796162011-06-17 17:53:38 +02004482 err = via_auto_fill_dac_nids(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08004483 if (err < 0)
4484 return err;
4485
4486 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
4487 return 0; /* can't find valid BIOS pin config */
4488
Takashi Iwai4a796162011-06-17 17:53:38 +02004489 err = via_auto_create_multi_out_ctls(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08004490 if (err < 0)
4491 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02004492 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Lydia Wangab6734e2009-10-10 19:08:46 +08004493 if (err < 0)
4494 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02004495 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangab6734e2009-10-10 19:08:46 +08004496 if (err < 0)
4497 return err;
4498
4499 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4500
4501 fill_dig_outs(codec);
4502
4503 if (spec->kctls.list)
4504 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4505
4506 spec->input_mux = &spec->private_imux[0];
4507
4508 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004509 via_hp_build(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08004510
4511 return 1;
4512}
4513
4514#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004515static const struct hda_amp_list vt1812_loopbacks[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08004516 { 0x21, HDA_INPUT, 0 },
4517 { 0x21, HDA_INPUT, 1 },
4518 { 0x21, HDA_INPUT, 2 },
4519 { } /* end */
4520};
4521#endif
4522
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004523static void set_widgets_power_state_vt1812(struct hda_codec *codec)
4524{
4525 struct via_spec *spec = codec->spec;
4526 int imux_is_smixer =
4527 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4528 unsigned int parm;
4529 unsigned int present;
4530 /* MUX10 (1eh) = stereo mixer */
4531 imux_is_smixer =
4532 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4533 /* inputs */
4534 /* PW 5/6/7 (29h/2ah/2bh) */
4535 parm = AC_PWRST_D3;
4536 set_pin_power_state(codec, 0x29, &parm);
4537 set_pin_power_state(codec, 0x2a, &parm);
4538 set_pin_power_state(codec, 0x2b, &parm);
4539 parm = AC_PWRST_D0;
4540 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
4541 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4542 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4543 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4544 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4545
4546 /* outputs */
4547 /* AOW0 (8h)*/
4548 snd_hda_codec_write(codec, 0x8, 0,
4549 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4550
4551 /* PW4 (28h), MW4 (18h), MUX4(38h) */
4552 parm = AC_PWRST_D3;
4553 set_pin_power_state(codec, 0x28, &parm);
4554 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
4555 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
4556
4557 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
4558 parm = AC_PWRST_D3;
4559 set_pin_power_state(codec, 0x25, &parm);
4560 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
4561 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
4562 if (spec->hp_independent_mode)
4563 snd_hda_codec_write(codec, 0x9, 0,
4564 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4565
4566 /* Internal Speaker */
4567 /* PW0 (24h), MW0(14h), MUX0(34h) */
4568 present = snd_hda_jack_detect(codec, 0x25);
4569
4570 parm = AC_PWRST_D3;
4571 set_pin_power_state(codec, 0x24, &parm);
4572 if (present) {
4573 snd_hda_codec_write(codec, 0x14, 0,
4574 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4575 snd_hda_codec_write(codec, 0x34, 0,
4576 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4577 } else {
4578 snd_hda_codec_write(codec, 0x14, 0,
4579 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4580 snd_hda_codec_write(codec, 0x34, 0,
4581 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4582 }
4583
4584
4585 /* Mono Out */
4586 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
4587 present = snd_hda_jack_detect(codec, 0x28);
4588
4589 parm = AC_PWRST_D3;
4590 set_pin_power_state(codec, 0x31, &parm);
4591 if (present) {
4592 snd_hda_codec_write(codec, 0x1c, 0,
4593 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4594 snd_hda_codec_write(codec, 0x3c, 0,
4595 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4596 snd_hda_codec_write(codec, 0x3e, 0,
4597 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4598 } else {
4599 snd_hda_codec_write(codec, 0x1c, 0,
4600 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4601 snd_hda_codec_write(codec, 0x3c, 0,
4602 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4603 snd_hda_codec_write(codec, 0x3e, 0,
4604 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4605 }
4606
4607 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
4608 parm = AC_PWRST_D3;
4609 set_pin_power_state(codec, 0x33, &parm);
4610 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4611 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
4612
4613}
Lydia Wangab6734e2009-10-10 19:08:46 +08004614
4615/* patch for vt1812 */
4616static int patch_vt1812(struct hda_codec *codec)
4617{
4618 struct via_spec *spec;
4619 int err;
4620
4621 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004622 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08004623 if (spec == NULL)
4624 return -ENOMEM;
4625
Takashi Iwai620e2b22011-06-17 17:19:19 +02004626 spec->aa_mix_nid = 0x21;
4627
Lydia Wangab6734e2009-10-10 19:08:46 +08004628 /* automatic parse from the BIOS config */
4629 err = vt1812_parse_auto_config(codec);
4630 if (err < 0) {
4631 via_free(codec);
4632 return err;
4633 } else if (!err) {
4634 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4635 "from BIOS. Using genenic mode...\n");
4636 }
4637
4638
4639 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
4640 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
4641
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004642 if (spec->adc_nids && spec->input_mux) {
Lydia Wangab6734e2009-10-10 19:08:46 +08004643 override_mic_boost(codec, 0x2b, 0, 3, 40);
4644 override_mic_boost(codec, 0x29, 0, 3, 40);
4645 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
4646 spec->num_mixers++;
4647 }
4648
4649 codec->patch_ops = via_patch_ops;
4650
4651 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11004652 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangab6734e2009-10-10 19:08:46 +08004653
4654#ifdef CONFIG_SND_HDA_POWER_SAVE
4655 spec->loopback.amplist = vt1812_loopbacks;
4656#endif
4657
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004658 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08004659 return 0;
4660}
4661
Joseph Chanc577b8a2006-11-29 15:29:40 +01004662/*
4663 * patch entries
4664 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004665static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01004666 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
4667 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
4668 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
4669 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
4670 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004671 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004672 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004673 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004674 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004675 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004676 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004677 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004678 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004679 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004680 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004681 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004682 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004683 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004684 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004685 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004686 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004687 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004688 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004689 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004690 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004691 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004692 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004693 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004694 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004695 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004696 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004697 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004698 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004699 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004700 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01004701 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01004702 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004703 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004704 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004705 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004706 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004707 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004708 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004709 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08004710 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08004711 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004712 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004713 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004714 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004715 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004716 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004717 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004718 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004719 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004720 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004721 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004722 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004723 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004724 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004725 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004726 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004727 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004728 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004729 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004730 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004731 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004732 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004733 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08004734 { .id = 0x11060428, .name = "VT1718S",
4735 .patch = patch_vt1718S},
4736 { .id = 0x11064428, .name = "VT1718S",
4737 .patch = patch_vt1718S},
Lydia Wangbb3c6bf2009-10-10 19:08:39 +08004738 { .id = 0x11060441, .name = "VT2020",
4739 .patch = patch_vt1718S},
4740 { .id = 0x11064441, .name = "VT1828S",
4741 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08004742 { .id = 0x11060433, .name = "VT1716S",
4743 .patch = patch_vt1716S},
4744 { .id = 0x1106a721, .name = "VT1716S",
4745 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08004746 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
4747 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08004748 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08004749 { .id = 0x11060440, .name = "VT1818S",
4750 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08004751 { .id = 0x11060446, .name = "VT1802",
4752 .patch = patch_vt2002P},
4753 { .id = 0x11068446, .name = "VT1802",
4754 .patch = patch_vt2002P},
Joseph Chanc577b8a2006-11-29 15:29:40 +01004755 {} /* terminator */
4756};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004757
4758MODULE_ALIAS("snd-hda-codec-id:1106*");
4759
4760static struct hda_codec_preset_list via_list = {
4761 .preset = snd_hda_preset_via,
4762 .owner = THIS_MODULE,
4763};
4764
4765MODULE_LICENSE("GPL");
4766MODULE_DESCRIPTION("VIA HD-audio codec");
4767
4768static int __init patch_via_init(void)
4769{
4770 return snd_hda_add_codec_preset(&via_list);
4771}
4772
4773static void __exit patch_via_exit(void)
4774{
4775 snd_hda_delete_codec_preset(&via_list);
4776}
4777
4778module_init(patch_via_init)
4779module_exit(patch_via_exit)