blob: 68f435dbbfd4346a05060f2b414801b8a28802cf [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 Iwai7eb56e842011-06-18 16:40:14 +0200125 char stream_name_hp[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200126 const struct hda_pcm_stream *stream_analog_playback;
127 const struct hda_pcm_stream *stream_analog_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800128
Takashi Iwai82673bc2011-06-17 16:24:21 +0200129 char stream_name_digital[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200130 const struct hda_pcm_stream *stream_digital_playback;
131 const struct hda_pcm_stream *stream_digital_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800132
133 /* playback */
134 struct hda_multi_out multiout;
135 hda_nid_t slave_dig_outs[2];
Takashi Iwaiece8d042011-06-19 16:24:21 +0200136 hda_nid_t hp_dac_nid;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800137
Takashi Iwai4a796162011-06-17 17:53:38 +0200138 struct nid_path out_path[4];
139 struct nid_path hp_path;
140 struct nid_path hp_dep_path;
141
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800142 /* capture */
143 unsigned int num_adc_nids;
Takashi Iwaia766d0d2011-06-17 09:01:29 +0200144 hda_nid_t adc_nids[3];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800145 hda_nid_t mux_nids[3];
Takashi Iwai620e2b22011-06-17 17:19:19 +0200146 hda_nid_t aa_mix_nid;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800147 hda_nid_t dig_in_nid;
148 hda_nid_t dig_in_pin;
149
150 /* capture source */
151 const struct hda_input_mux *input_mux;
152 unsigned int cur_mux[3];
153
154 /* PCM information */
155 struct hda_pcm pcm_rec[3];
156
157 /* dynamic controls, init_verbs and input_mux */
158 struct auto_pin_cfg autocfg;
159 struct snd_array kctls;
160 struct hda_input_mux private_imux[2];
161 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
162
163 /* HP mode source */
164 const struct hda_input_mux *hp_mux;
165 unsigned int hp_independent_mode;
166 unsigned int hp_independent_mode_index;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200167 unsigned int can_smart51;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800168 unsigned int smart51_enabled;
Lydia Wangf3db4232009-10-10 19:08:41 +0800169 unsigned int dmic_enabled;
Takashi Iwai24088a52011-06-17 16:59:21 +0200170 unsigned int no_pin_power_ctl;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800171 enum VIA_HDA_CODEC codec_type;
172
173 /* work to check hp jack state */
174 struct hda_codec *codec;
175 struct delayed_work vt1708_hp_work;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200176 int vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800177 int vt1708_hp_present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800178
179 void (*set_widgets_power_state)(struct hda_codec *codec);
180
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800181#ifdef CONFIG_SND_HDA_POWER_SAVE
182 struct hda_loopback_check loopback;
183#endif
184};
185
Lydia Wang0341ccd2011-03-22 16:25:03 +0800186static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100187static struct via_spec * via_new_spec(struct hda_codec *codec)
188{
189 struct via_spec *spec;
190
191 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
192 if (spec == NULL)
193 return NULL;
194
195 codec->spec = spec;
196 spec->codec = codec;
Lydia Wang0341ccd2011-03-22 16:25:03 +0800197 spec->codec_type = get_codec_type(codec);
198 /* VT1708BCE & VT1708S are almost same */
199 if (spec->codec_type == VT1708BCE)
200 spec->codec_type = VT1708S;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100201 return spec;
202}
203
Lydia Wang744ff5f2009-10-10 19:07:26 +0800204static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800205{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800206 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800207 u16 ven_id = vendor_id >> 16;
208 u16 dev_id = vendor_id & 0xffff;
209 enum VIA_HDA_CODEC codec_type;
210
211 /* get codec type */
212 if (ven_id != 0x1106)
213 codec_type = UNKNOWN;
214 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
215 codec_type = VT1708;
216 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
217 codec_type = VT1709_10CH;
218 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
219 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800220 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800221 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800222 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
223 codec_type = VT1708BCE;
224 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800225 codec_type = VT1708B_4CH;
226 else if ((dev_id & 0xfff) == 0x397
227 && (dev_id >> 12) < 8)
228 codec_type = VT1708S;
229 else if ((dev_id & 0xfff) == 0x398
230 && (dev_id >> 12) < 8)
231 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800232 else if ((dev_id & 0xfff) == 0x428
233 && (dev_id >> 12) < 8)
234 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800235 else if (dev_id == 0x0433 || dev_id == 0xa721)
236 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800237 else if (dev_id == 0x0441 || dev_id == 0x4441)
238 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800239 else if (dev_id == 0x0438 || dev_id == 0x4438)
240 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800241 else if (dev_id == 0x0448)
242 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800243 else if (dev_id == 0x0440)
244 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800245 else if ((dev_id & 0xfff) == 0x446)
246 codec_type = VT1802;
Harald Welted7426322008-09-15 22:43:23 +0800247 else
248 codec_type = UNKNOWN;
249 return codec_type;
250};
251
Lydia Wangec7e7e42011-03-24 12:43:44 +0800252#define VIA_JACK_EVENT 0x20
Harald Welte69e52a82008-09-09 15:57:32 +0800253#define VIA_HP_EVENT 0x01
254#define VIA_GPIO_EVENT 0x02
Lydia Wangec7e7e42011-03-24 12:43:44 +0800255#define VIA_MONO_EVENT 0x03
256#define VIA_SPEAKER_EVENT 0x04
257#define VIA_BIND_HP_EVENT 0x05
Harald Welte69e52a82008-09-09 15:57:32 +0800258
Joseph Chanc577b8a2006-11-29 15:29:40 +0100259enum {
260 VIA_CTL_WIDGET_VOL,
261 VIA_CTL_WIDGET_MUTE,
Lydia Wangf5271102009-10-10 19:07:35 +0800262 VIA_CTL_WIDGET_ANALOG_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800263 VIA_CTL_WIDGET_BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100264};
265
Lydia Wangf5271102009-10-10 19:07:35 +0800266static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800267static int is_aa_path_mute(struct hda_codec *codec);
268
269static void vt1708_start_hp_work(struct via_spec *spec)
270{
271 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
272 return;
273 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200274 !spec->vt1708_jack_detect);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800275 if (!delayed_work_pending(&spec->vt1708_hp_work))
276 schedule_delayed_work(&spec->vt1708_hp_work,
277 msecs_to_jiffies(100));
278}
279
280static void vt1708_stop_hp_work(struct via_spec *spec)
281{
282 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
283 return;
284 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
285 && !is_aa_path_mute(spec->codec))
286 return;
287 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200288 !spec->vt1708_jack_detect);
Tejun Heo5b84ba22010-12-11 17:51:26 +0100289 cancel_delayed_work_sync(&spec->vt1708_hp_work);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800290}
Lydia Wangf5271102009-10-10 19:07:35 +0800291
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800292static void set_widgets_power_state(struct hda_codec *codec)
293{
294 struct via_spec *spec = codec->spec;
295 if (spec->set_widgets_power_state)
296 spec->set_widgets_power_state(codec);
297}
Lydia Wang25eaba22009-10-10 19:08:43 +0800298
Lydia Wangf5271102009-10-10 19:07:35 +0800299static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
300 struct snd_ctl_elem_value *ucontrol)
301{
302 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
304
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800305 set_widgets_power_state(codec);
Lydia Wangf5271102009-10-10 19:07:35 +0800306 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800307 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
308 if (is_aa_path_mute(codec))
309 vt1708_start_hp_work(codec->spec);
310 else
311 vt1708_stop_hp_work(codec->spec);
312 }
Lydia Wangf5271102009-10-10 19:07:35 +0800313 return change;
314}
315
316/* modify .put = snd_hda_mixer_amp_switch_put */
317#define ANALOG_INPUT_MUTE \
318 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
319 .name = NULL, \
320 .index = 0, \
321 .info = snd_hda_mixer_amp_switch_info, \
322 .get = snd_hda_mixer_amp_switch_get, \
323 .put = analog_input_switch_put, \
324 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
325
Lydia Wang25eaba22009-10-10 19:08:43 +0800326static void via_hp_bind_automute(struct hda_codec *codec);
327
328static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
329 struct snd_ctl_elem_value *ucontrol)
330{
331 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
332 struct via_spec *spec = codec->spec;
333 int i;
334 int change = 0;
335
336 long *valp = ucontrol->value.integer.value;
337 int lmute, rmute;
338 if (strstr(kcontrol->id.name, "Switch") == NULL) {
339 snd_printd("Invalid control!\n");
340 return change;
341 }
342 change = snd_hda_mixer_amp_switch_put(kcontrol,
343 ucontrol);
344 /* Get mute value */
345 lmute = *valp ? 0 : HDA_AMP_MUTE;
346 valp++;
347 rmute = *valp ? 0 : HDA_AMP_MUTE;
348
349 /* Set hp pins */
350 if (!spec->hp_independent_mode) {
351 for (i = 0; i < spec->autocfg.hp_outs; i++) {
352 snd_hda_codec_amp_update(
353 codec, spec->autocfg.hp_pins[i],
354 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
355 lmute);
356 snd_hda_codec_amp_update(
357 codec, spec->autocfg.hp_pins[i],
358 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
359 rmute);
360 }
361 }
362
363 if (!lmute && !rmute) {
364 /* Line Outs */
365 for (i = 0; i < spec->autocfg.line_outs; i++)
366 snd_hda_codec_amp_stereo(
367 codec, spec->autocfg.line_out_pins[i],
368 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
369 /* Speakers */
370 for (i = 0; i < spec->autocfg.speaker_outs; i++)
371 snd_hda_codec_amp_stereo(
372 codec, spec->autocfg.speaker_pins[i],
373 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
374 /* unmute */
375 via_hp_bind_automute(codec);
376
377 } else {
378 if (lmute) {
379 /* Mute all left channels */
380 for (i = 1; i < spec->autocfg.line_outs; i++)
381 snd_hda_codec_amp_update(
382 codec,
383 spec->autocfg.line_out_pins[i],
384 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
385 lmute);
386 for (i = 0; i < spec->autocfg.speaker_outs; i++)
387 snd_hda_codec_amp_update(
388 codec,
389 spec->autocfg.speaker_pins[i],
390 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
391 lmute);
392 }
393 if (rmute) {
394 /* mute all right channels */
395 for (i = 1; i < spec->autocfg.line_outs; i++)
396 snd_hda_codec_amp_update(
397 codec,
398 spec->autocfg.line_out_pins[i],
399 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
400 rmute);
401 for (i = 0; i < spec->autocfg.speaker_outs; i++)
402 snd_hda_codec_amp_update(
403 codec,
404 spec->autocfg.speaker_pins[i],
405 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
406 rmute);
407 }
408 }
409 return change;
410}
411
412#define BIND_PIN_MUTE \
413 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
414 .name = NULL, \
415 .index = 0, \
416 .info = snd_hda_mixer_amp_switch_info, \
417 .get = snd_hda_mixer_amp_switch_get, \
418 .put = bind_pin_switch_put, \
419 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
420
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200421static const struct snd_kcontrol_new via_control_templates[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100422 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
423 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Lydia Wangf5271102009-10-10 19:07:35 +0800424 ANALOG_INPUT_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800425 BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100426};
427
Lydia Wangab6734e2009-10-10 19:08:46 +0800428
Joseph Chanc577b8a2006-11-29 15:29:40 +0100429/* add dynamic controls */
Takashi Iwai291c9e32011-06-17 16:15:26 +0200430static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
431 const struct snd_kcontrol_new *tmpl,
432 const char *name)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100433{
434 struct snd_kcontrol_new *knew;
435
Takashi Iwai603c4012008-07-30 15:01:44 +0200436 snd_array_init(&spec->kctls, sizeof(*knew), 32);
437 knew = snd_array_new(&spec->kctls);
438 if (!knew)
Takashi Iwai291c9e32011-06-17 16:15:26 +0200439 return NULL;
440 *knew = *tmpl;
441 if (!name)
442 name = tmpl->name;
443 if (name) {
444 knew->name = kstrdup(name, GFP_KERNEL);
445 if (!knew->name)
446 return NULL;
447 }
448 return knew;
449}
450
451static int __via_add_control(struct via_spec *spec, int type, const char *name,
452 int idx, unsigned long val)
453{
454 struct snd_kcontrol_new *knew;
455
456 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
457 if (!knew)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100458 return -ENOMEM;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +0200459 knew->index = idx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100460 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100461 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100462 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100463 return 0;
464}
465
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200466#define via_add_control(spec, type, name, val) \
467 __via_add_control(spec, type, name, 0, val)
468
Takashi Iwai291c9e32011-06-17 16:15:26 +0200469#define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100470
Takashi Iwai603c4012008-07-30 15:01:44 +0200471static void via_free_kctls(struct hda_codec *codec)
472{
473 struct via_spec *spec = codec->spec;
474
475 if (spec->kctls.list) {
476 struct snd_kcontrol_new *kctl = spec->kctls.list;
477 int i;
478 for (i = 0; i < spec->kctls.used; i++)
479 kfree(kctl[i].name);
480 }
481 snd_array_free(&spec->kctls);
482}
483
Joseph Chanc577b8a2006-11-29 15:29:40 +0100484/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800485static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200486 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100487{
488 char name[32];
489 int err;
490
491 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200492 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100493 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
494 if (err < 0)
495 return err;
496 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200497 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100498 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
499 if (err < 0)
500 return err;
501 return 0;
502}
503
Takashi Iwai5d417622011-06-20 11:32:27 +0200504/* return the index of the given widget nid as the source of mux;
505 * return -1 if not found;
506 * if num_conns is non-NULL, set the total number of connections
507 */
508static int __get_connection_index(struct hda_codec *codec, hda_nid_t mux,
509 hda_nid_t nid, int *num_conns)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100510{
Takashi Iwai5d417622011-06-20 11:32:27 +0200511 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
512 int i, nums;
513
514 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
515 if (num_conns)
516 *num_conns = nums;
517 for (i = 0; i < nums; i++)
518 if (conn[i] == nid)
519 return i;
520 return -1;
521}
522
523#define get_connection_index(codec, mux, nid) \
524 __get_connection_index(codec, mux, nid, NULL)
525
526/* unmute input amp and select the specificed source */
527static void unmute_and_select(struct hda_codec *codec, hda_nid_t nid,
528 hda_nid_t src, hda_nid_t mix)
529{
530 int idx, num_conns;
531
532 idx = __get_connection_index(codec, nid, src, &num_conns);
533 if (idx < 0)
534 return;
535
536 /* select the route explicitly when multiple connections exist */
537 if (num_conns > 1)
Lydia Wang377ff312009-10-10 19:08:55 +0800538 snd_hda_codec_write(codec, nid, 0,
Takashi Iwai5d417622011-06-20 11:32:27 +0200539 AC_VERB_SET_CONNECT_SEL, idx);
540 /* unmute if the input amp is present */
541 if (!(query_amp_caps(codec, nid, HDA_INPUT) &
542 (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE)))
543 return;
544 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
545 AMP_IN_UNMUTE(idx));
546
547 /* unmute AA-path if present */
548 if (!mix)
549 return;
550 idx = __get_connection_index(codec, nid, mix, NULL);
551 if (idx >= 0)
552 snd_hda_codec_write(codec, nid, 0,
553 AC_VERB_SET_AMP_GAIN_MUTE,
554 AMP_IN_UNMUTE(idx));
555}
556
557/* set the given pin as output */
558static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
559 int pin_type)
560{
561 if (!pin)
562 return;
563 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
564 pin_type);
565 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
566 snd_hda_codec_write(codec, pin, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200567 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100568}
569
Takashi Iwai5d417622011-06-20 11:32:27 +0200570static void via_auto_init_output(struct hda_codec *codec, hda_nid_t pin,
571 int pin_type, struct nid_path *path)
572{
573 struct via_spec *spec = codec->spec;
574 unsigned int caps;
575 hda_nid_t nid;
576 int i;
577
578 if (!pin)
579 return;
580
581 init_output_pin(codec, pin, pin_type);
582 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
583 if (caps & AC_AMPCAP_MUTE) {
584 unsigned int val;
585 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
586 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
587 AMP_OUT_MUTE | val);
588 }
589
590 /* initialize the output path */
591 nid = pin;
592 for (i = 0; i < path->depth; i++) {
593 unmute_and_select(codec, nid, path->idx[i], spec->aa_mix_nid);
594 nid = path->path[i];
595 if (query_amp_caps(codec, nid, HDA_OUTPUT) &
596 (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE))
597 snd_hda_codec_write(codec, nid, 0,
598 AC_VERB_SET_AMP_GAIN_MUTE,
599 AMP_OUT_UNMUTE);
600 }
601}
602
Joseph Chanc577b8a2006-11-29 15:29:40 +0100603
604static void via_auto_init_multi_out(struct hda_codec *codec)
605{
606 struct via_spec *spec = codec->spec;
607 int i;
608
Takashi Iwai5d417622011-06-20 11:32:27 +0200609 for (i = 0; i < spec->autocfg.line_outs; i++)
610 via_auto_init_output(codec, spec->autocfg.line_out_pins[i],
611 PIN_OUT, &spec->out_path[i]);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100612}
613
614static void via_auto_init_hp_out(struct hda_codec *codec)
615{
616 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100617
Takashi Iwai5d417622011-06-20 11:32:27 +0200618 if (spec->hp_dac_nid)
619 via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP,
620 &spec->hp_path);
621 else
622 via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP,
623 &spec->hp_dep_path);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100624}
625
Takashi Iwaif4a78282011-06-17 18:46:48 +0200626static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
Clemens Ladisch32e01912010-07-12 16:28:50 +0200627
Joseph Chanc577b8a2006-11-29 15:29:40 +0100628static void via_auto_init_analog_input(struct hda_codec *codec)
629{
630 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200631 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai096a8852011-06-20 12:09:02 +0200632 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Clemens Ladisch32e01912010-07-12 16:28:50 +0200633 unsigned int ctl;
Takashi Iwai096a8852011-06-20 12:09:02 +0200634 int i, num_conns;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100635
Takashi Iwai096a8852011-06-20 12:09:02 +0200636 /* init ADCs */
637 for (i = 0; i < spec->num_adc_nids; i++) {
638 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
639 AC_VERB_SET_AMP_GAIN_MUTE,
640 AMP_IN_UNMUTE(0));
641 }
642
643 /* init pins */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200644 for (i = 0; i < cfg->num_inputs; i++) {
645 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200646 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
Clemens Ladisch32e01912010-07-12 16:28:50 +0200647 ctl = PIN_OUT;
David Henningsson30649672011-02-21 10:23:18 +0100648 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
Clemens Ladisch32e01912010-07-12 16:28:50 +0200649 ctl = PIN_VREF50;
650 else
651 ctl = PIN_IN;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100652 snd_hda_codec_write(codec, nid, 0,
Clemens Ladisch32e01912010-07-12 16:28:50 +0200653 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100654 }
Takashi Iwai096a8852011-06-20 12:09:02 +0200655
656 /* init input-src */
657 for (i = 0; i < spec->num_adc_nids; i++) {
658 const struct hda_input_mux *imux = spec->input_mux;
659 if (!imux || !spec->mux_nids[i])
660 continue;
661 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
662 AC_VERB_SET_CONNECT_SEL,
663 imux->items[spec->cur_mux[i]].index);
664 }
665
666 /* init aa-mixer */
667 if (!spec->aa_mix_nid)
668 return;
669 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
670 ARRAY_SIZE(conn));
671 for (i = 0; i < num_conns; i++) {
672 unsigned int caps = get_wcaps(codec, conn[i]);
673 if (get_wcaps_type(caps) == AC_WID_PIN)
674 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
675 AC_VERB_SET_AMP_GAIN_MUTE,
676 AMP_IN_MUTE(i));
677 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100678}
Lydia Wangf5271102009-10-10 19:07:35 +0800679
680static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
681 unsigned int *affected_parm)
682{
683 unsigned parm;
684 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
685 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
686 >> AC_DEFCFG_MISC_SHIFT
687 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800688 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200689 unsigned present = 0;
690
691 no_presence |= spec->no_pin_power_ctl;
692 if (!no_presence)
693 present = snd_hda_jack_detect(codec, nid);
Takashi Iwaif4a78282011-06-17 18:46:48 +0200694 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
Lydia Wang1564b282009-10-10 19:07:52 +0800695 || ((no_presence || present)
696 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800697 *affected_parm = AC_PWRST_D0; /* if it's connected */
698 parm = AC_PWRST_D0;
699 } else
700 parm = AC_PWRST_D3;
701
702 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
703}
704
Takashi Iwai24088a52011-06-17 16:59:21 +0200705static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
706 struct snd_ctl_elem_info *uinfo)
707{
708 static const char * const texts[] = {
709 "Disabled", "Enabled"
710 };
711
712 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
713 uinfo->count = 1;
714 uinfo->value.enumerated.items = 2;
715 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
716 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
717 strcpy(uinfo->value.enumerated.name,
718 texts[uinfo->value.enumerated.item]);
719 return 0;
720}
721
722static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
723 struct snd_ctl_elem_value *ucontrol)
724{
725 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
726 struct via_spec *spec = codec->spec;
727 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
728 return 0;
729}
730
731static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
732 struct snd_ctl_elem_value *ucontrol)
733{
734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
735 struct via_spec *spec = codec->spec;
736 unsigned int val = !ucontrol->value.enumerated.item[0];
737
738 if (val == spec->no_pin_power_ctl)
739 return 0;
740 spec->no_pin_power_ctl = val;
741 set_widgets_power_state(codec);
742 return 1;
743}
744
745static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
746 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
747 .name = "Dynamic Power-Control",
748 .info = via_pin_power_ctl_info,
749 .get = via_pin_power_ctl_get,
750 .put = via_pin_power_ctl_put,
751};
752
753
Joseph Chanc577b8a2006-11-29 15:29:40 +0100754/*
755 * input MUX handling
756 */
757static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
758 struct snd_ctl_elem_info *uinfo)
759{
760 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
761 struct via_spec *spec = codec->spec;
762 return snd_hda_input_mux_info(spec->input_mux, uinfo);
763}
764
765static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
766 struct snd_ctl_elem_value *ucontrol)
767{
768 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
769 struct via_spec *spec = codec->spec;
770 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
771
772 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
773 return 0;
774}
775
776static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
777 struct snd_ctl_elem_value *ucontrol)
778{
779 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
780 struct via_spec *spec = codec->spec;
781 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800782 int ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100783
Takashi Iwai337b9d02009-07-07 18:18:59 +0200784 if (!spec->mux_nids[adc_idx])
785 return -EINVAL;
Lydia Wanga80e6e32009-10-10 19:07:55 +0800786 /* switch to D0 beofre change index */
787 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
788 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
789 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
790 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800791
792 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
793 spec->mux_nids[adc_idx],
794 &spec->cur_mux[adc_idx]);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800795 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800796 set_widgets_power_state(codec);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800797
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800798 return ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100799}
800
Harald Welte0aa62ae2008-09-09 15:58:27 +0800801static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
802 struct snd_ctl_elem_info *uinfo)
803{
804 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
805 struct via_spec *spec = codec->spec;
806 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
807}
808
809static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
810 struct snd_ctl_elem_value *ucontrol)
811{
812 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Lydia Wangcdc17842009-10-10 19:07:47 +0800813 struct via_spec *spec = codec->spec;
Lydia Wangcdc17842009-10-10 19:07:47 +0800814
Takashi Iwaiece8d042011-06-19 16:24:21 +0200815 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
Lydia Wangcdc17842009-10-10 19:07:47 +0800816 return 0;
817}
818
Harald Welte0aa62ae2008-09-09 15:58:27 +0800819static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
820 struct snd_ctl_elem_value *ucontrol)
821{
822 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
823 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100824 hda_nid_t nid = kcontrol->private_value;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800825 unsigned int pinsel = ucontrol->value.enumerated.item[0];
Lydia Wangcdc17842009-10-10 19:07:47 +0800826 /* Get Independent Mode index of headphone pin widget */
827 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
828 ? 1 : 0;
Takashi Iwaiece8d042011-06-19 16:24:21 +0200829 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800830
Lydia Wangce0e5a92011-03-22 16:22:37 +0800831 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800832 set_widgets_power_state(codec);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800833 return 0;
834}
835
Takashi Iwaiece8d042011-06-19 16:24:21 +0200836static const struct snd_kcontrol_new via_hp_mixer = {
837 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
838 .name = "Independent HP",
839 .info = via_independent_hp_info,
840 .get = via_independent_hp_get,
841 .put = via_independent_hp_put,
Harald Welte0aa62ae2008-09-09 15:58:27 +0800842};
843
Takashi Iwai3d83e572010-04-14 14:36:23 +0200844static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100845{
Takashi Iwai3d83e572010-04-14 14:36:23 +0200846 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100847 struct snd_kcontrol_new *knew;
848 hda_nid_t nid;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100849
Takashi Iwaiece8d042011-06-19 16:24:21 +0200850 nid = spec->autocfg.hp_pins[0];
851 knew = via_clone_control(spec, &via_hp_mixer);
Takashi Iwai3d83e572010-04-14 14:36:23 +0200852 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
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100858 return 0;
859}
860
Lydia Wang1564b282009-10-10 19:07:52 +0800861static void notify_aa_path_ctls(struct hda_codec *codec)
862{
863 int i;
864 struct snd_ctl_elem_id id;
Lydia Wang525566c2011-04-28 16:03:39 +0800865 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
866 struct snd_kcontrol *ctl;
Lydia Wang1564b282009-10-10 19:07:52 +0800867
868 memset(&id, 0, sizeof(id));
869 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
870 for (i = 0; i < ARRAY_SIZE(labels); i++) {
871 sprintf(id.name, "%s Playback Volume", labels[i]);
Lydia Wang525566c2011-04-28 16:03:39 +0800872 ctl = snd_hda_find_mixer_ctl(codec, id.name);
873 if (ctl)
874 snd_ctl_notify(codec->bus->card,
875 SNDRV_CTL_EVENT_MASK_VALUE,
876 &ctl->id);
Lydia Wang1564b282009-10-10 19:07:52 +0800877 }
878}
879
880static void mute_aa_path(struct hda_codec *codec, int mute)
881{
882 struct via_spec *spec = codec->spec;
Lydia Wang1564b282009-10-10 19:07:52 +0800883 int start_idx;
884 int end_idx;
885 int i;
886 /* get nid of MW0 and start & end index */
887 switch (spec->codec_type) {
888 case VT1708:
Lydia Wang1564b282009-10-10 19:07:52 +0800889 start_idx = 2;
890 end_idx = 4;
891 break;
892 case VT1709_10CH:
893 case VT1709_6CH:
Lydia Wang1564b282009-10-10 19:07:52 +0800894 start_idx = 2;
895 end_idx = 4;
896 break;
897 case VT1708B_8CH:
898 case VT1708B_4CH:
899 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +0800900 case VT1716S:
Lydia Wang1564b282009-10-10 19:07:52 +0800901 start_idx = 2;
902 end_idx = 4;
903 break;
Lydia Wangab657e02011-03-22 16:23:23 +0800904 case VT1718S:
Lydia Wangab657e02011-03-22 16:23:23 +0800905 start_idx = 1;
906 end_idx = 3;
907 break;
Lydia Wang1564b282009-10-10 19:07:52 +0800908 default:
909 return;
910 }
911 /* check AA path's mute status */
912 for (i = start_idx; i <= end_idx; i++) {
913 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200914 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid, HDA_INPUT, i,
Lydia Wang1564b282009-10-10 19:07:52 +0800915 HDA_AMP_MUTE, val);
916 }
917}
Takashi Iwaif4a78282011-06-17 18:46:48 +0200918
919static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
Lydia Wang1564b282009-10-10 19:07:52 +0800920{
Takashi Iwaif4a78282011-06-17 18:46:48 +0200921 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200922 const struct auto_pin_cfg *cfg = &spec->autocfg;
923 int i;
924
925 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwaif4a78282011-06-17 18:46:48 +0200926 unsigned int defcfg;
927 if (pin != cfg->inputs[i].pin)
928 continue;
929 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
930 return false;
931 defcfg = snd_hda_codec_get_pincfg(codec, pin);
932 if (snd_hda_get_input_pin_attr(defcfg) < INPUT_PIN_ATTR_NORMAL)
933 return false;
934 return true;
Lydia Wang1564b282009-10-10 19:07:52 +0800935 }
Takashi Iwaif4a78282011-06-17 18:46:48 +0200936 return false;
Lydia Wang1564b282009-10-10 19:07:52 +0800937}
938
939static int via_smart51_info(struct snd_kcontrol *kcontrol,
940 struct snd_ctl_elem_info *uinfo)
941{
942 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
943 uinfo->count = 1;
944 uinfo->value.integer.min = 0;
945 uinfo->value.integer.max = 1;
946 return 0;
947}
948
949static int via_smart51_get(struct snd_kcontrol *kcontrol,
950 struct snd_ctl_elem_value *ucontrol)
951{
952 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
953 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200954 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800955 int on = 1;
956 int i;
957
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200958 for (i = 0; i < cfg->num_inputs; i++) {
959 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200960 unsigned int ctl;
Takashi Iwai86e29592010-09-09 14:50:17 +0200961 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200962 spec->hp_independent_mode && spec->codec_type != VT1718S)
963 continue; /* ignore FMic for independent HP */
Takashi Iwaif4a78282011-06-17 18:46:48 +0200964 if (!is_smart51_pins(codec, nid))
965 continue;
966 ctl = snd_hda_codec_read(codec, nid, 0,
967 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200968 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
969 on = 0;
Lydia Wang1564b282009-10-10 19:07:52 +0800970 }
971 *ucontrol->value.integer.value = on;
972 return 0;
973}
974
975static int via_smart51_put(struct snd_kcontrol *kcontrol,
976 struct snd_ctl_elem_value *ucontrol)
977{
978 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
979 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200980 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800981 int out_in = *ucontrol->value.integer.value
982 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +0800983 int i;
984
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200985 for (i = 0; i < cfg->num_inputs; i++) {
986 hda_nid_t nid = cfg->inputs[i].pin;
987 unsigned int parm;
988
Takashi Iwai86e29592010-09-09 14:50:17 +0200989 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200990 spec->hp_independent_mode && spec->codec_type != VT1718S)
Lydia Wang1564b282009-10-10 19:07:52 +0800991 continue; /* don't retask FMic for independent HP */
Takashi Iwaif4a78282011-06-17 18:46:48 +0200992 if (!is_smart51_pins(codec, nid))
993 continue;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200994
995 parm = snd_hda_codec_read(codec, nid, 0,
996 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
997 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
998 parm |= out_in;
999 snd_hda_codec_write(codec, nid, 0,
1000 AC_VERB_SET_PIN_WIDGET_CONTROL,
1001 parm);
1002 if (out_in == AC_PINCTL_OUT_EN) {
1003 mute_aa_path(codec, 1);
1004 notify_aa_path_ctls(codec);
1005 }
Lydia Wang1564b282009-10-10 19:07:52 +08001006 }
1007 spec->smart51_enabled = *ucontrol->value.integer.value;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001008 set_widgets_power_state(codec);
Lydia Wang1564b282009-10-10 19:07:52 +08001009 return 1;
1010}
1011
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001012static const struct snd_kcontrol_new via_smart51_mixer = {
1013 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1014 .name = "Smart 5.1",
1015 .count = 1,
1016 .info = via_smart51_info,
1017 .get = via_smart51_get,
1018 .put = via_smart51_put,
Lydia Wang1564b282009-10-10 19:07:52 +08001019};
1020
Takashi Iwaif4a78282011-06-17 18:46:48 +02001021static int via_smart51_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001022{
Takashi Iwaif4a78282011-06-17 18:46:48 +02001023 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001024 struct snd_kcontrol_new *knew;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001025 const struct auto_pin_cfg *cfg = &spec->autocfg;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001026 hda_nid_t nid;
1027 int i;
1028
Takashi Iwaif4a78282011-06-17 18:46:48 +02001029 if (!spec->can_smart51)
Lydia Wangcb34c202011-04-27 17:44:16 +08001030 return 0;
1031
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001032 knew = via_clone_control(spec, &via_smart51_mixer);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001033 if (knew == NULL)
1034 return -ENOMEM;
1035
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001036 for (i = 0; i < cfg->num_inputs; i++) {
1037 nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001038 if (is_smart51_pins(codec, nid)) {
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001039 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001040 break;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001041 }
1042 }
1043
1044 return 0;
1045}
1046
Lydia Wangf5271102009-10-10 19:07:35 +08001047/* check AA path's mute statue */
1048static int is_aa_path_mute(struct hda_codec *codec)
1049{
1050 int mute = 1;
Lydia Wangf5271102009-10-10 19:07:35 +08001051 int start_idx;
1052 int end_idx;
1053 int i;
1054 struct via_spec *spec = codec->spec;
1055 /* get nid of MW0 and start & end index */
1056 switch (spec->codec_type) {
1057 case VT1708B_8CH:
1058 case VT1708B_4CH:
1059 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001060 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001061 start_idx = 2;
1062 end_idx = 4;
1063 break;
1064 case VT1702:
Lydia Wangf5271102009-10-10 19:07:35 +08001065 start_idx = 1;
1066 end_idx = 3;
1067 break;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001068 case VT1718S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001069 start_idx = 1;
1070 end_idx = 3;
1071 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001072 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001073 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001074 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001075 start_idx = 0;
1076 end_idx = 2;
1077 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001078 default:
1079 return 0;
1080 }
1081 /* check AA path's mute status */
1082 for (i = start_idx; i <= end_idx; i++) {
1083 unsigned int con_list = snd_hda_codec_read(
Takashi Iwai620e2b22011-06-17 17:19:19 +02001084 codec, spec->aa_mix_nid, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
Lydia Wangf5271102009-10-10 19:07:35 +08001085 int shift = 8 * (i % 4);
1086 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1087 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1088 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1089 /* check mute status while the pin is connected */
Takashi Iwai620e2b22011-06-17 17:19:19 +02001090 int mute_l = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 0,
Lydia Wangf5271102009-10-10 19:07:35 +08001091 HDA_INPUT, i) >> 7;
Takashi Iwai620e2b22011-06-17 17:19:19 +02001092 int mute_r = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 1,
Lydia Wangf5271102009-10-10 19:07:35 +08001093 HDA_INPUT, i) >> 7;
1094 if (!mute_l || !mute_r) {
1095 mute = 0;
1096 break;
1097 }
1098 }
1099 }
1100 return mute;
1101}
1102
1103/* enter/exit analog low-current mode */
1104static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1105{
1106 struct via_spec *spec = codec->spec;
1107 static int saved_stream_idle = 1; /* saved stream idle status */
1108 int enable = is_aa_path_mute(codec);
1109 unsigned int verb = 0;
1110 unsigned int parm = 0;
1111
1112 if (stream_idle == -1) /* stream status did not change */
1113 enable = enable && saved_stream_idle;
1114 else {
1115 enable = enable && stream_idle;
1116 saved_stream_idle = stream_idle;
1117 }
1118
1119 /* decide low current mode's verb & parameter */
1120 switch (spec->codec_type) {
1121 case VT1708B_8CH:
1122 case VT1708B_4CH:
1123 verb = 0xf70;
1124 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1125 break;
1126 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001127 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001128 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001129 verb = 0xf73;
1130 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1131 break;
1132 case VT1702:
1133 verb = 0xf73;
1134 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1135 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001136 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001137 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001138 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001139 verb = 0xf93;
1140 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1141 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001142 default:
1143 return; /* other codecs are not supported */
1144 }
1145 /* send verb */
1146 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1147}
1148
Joseph Chanc577b8a2006-11-29 15:29:40 +01001149/*
1150 * generic initialization of ADC, input mixers and output mixers
1151 */
Takashi Iwai096a8852011-06-20 12:09:02 +02001152static const struct hda_verb vt1708_init_verbs[] = {
Lydia Wangaa266fc2011-03-24 12:41:01 +08001153 /* power down jack detect function */
1154 {0x1, 0xf81, 0x1},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001155 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001156};
1157
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001158static void substream_set_idle(struct hda_codec *codec,
1159 struct snd_pcm_substream *substream)
1160{
1161 int idle = substream->pstr->substream_opened == 1
1162 && substream->ref_count == 0;
1163 analog_low_current_mode(codec, idle);
1164}
1165
Takashi Iwaiece8d042011-06-19 16:24:21 +02001166static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001167 struct hda_codec *codec,
1168 struct snd_pcm_substream *substream)
1169{
1170 struct via_spec *spec = codec->spec;
Takashi Iwaiece8d042011-06-19 16:24:21 +02001171
1172 if (!spec->hp_independent_mode)
1173 spec->multiout.hp_nid = spec->hp_dac_nid;
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001174 substream_set_idle(codec, substream);
Takashi Iwai9a081602008-02-12 18:37:26 +01001175 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1176 hinfo);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001177}
1178
Takashi Iwaiece8d042011-06-19 16:24:21 +02001179static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
Takashi Iwai9af74212011-06-18 16:17:45 +02001180 struct hda_codec *codec,
1181 struct snd_pcm_substream *substream)
1182{
Takashi Iwaiece8d042011-06-19 16:24:21 +02001183 struct via_spec *spec = codec->spec;
1184
1185 spec->multiout.hp_nid = 0;
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001186 substream_set_idle(codec, substream);
Takashi Iwai9af74212011-06-18 16:17:45 +02001187 return 0;
1188}
1189
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001190static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1191 struct hda_codec *codec,
1192 struct snd_pcm_substream *substream)
1193{
1194 struct via_spec *spec = codec->spec;
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001195
Takashi Iwaiece8d042011-06-19 16:24:21 +02001196 if (snd_BUG_ON(!spec->hp_dac_nid))
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001197 return -EINVAL;
Takashi Iwaiece8d042011-06-19 16:24:21 +02001198 if (!spec->hp_independent_mode || spec->multiout.hp_nid)
1199 return -EBUSY;
1200 substream_set_idle(codec, substream);
1201 return 0;
1202}
1203
1204static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1205 struct hda_codec *codec,
1206 struct snd_pcm_substream *substream)
1207{
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001208 substream_set_idle(codec, substream);
1209 return 0;
1210}
1211
1212static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1213 struct hda_codec *codec,
1214 unsigned int stream_tag,
1215 unsigned int format,
1216 struct snd_pcm_substream *substream)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001217{
1218 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001219
Takashi Iwaiece8d042011-06-19 16:24:21 +02001220 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1221 format, substream);
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001222 vt1708_start_hp_work(spec);
1223 return 0;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001224}
1225
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001226static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1227 struct hda_codec *codec,
1228 unsigned int stream_tag,
1229 unsigned int format,
1230 struct snd_pcm_substream *substream)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001231{
1232 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001233
Takashi Iwaiece8d042011-06-19 16:24:21 +02001234 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1235 stream_tag, 0, format);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001236 vt1708_start_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001237 return 0;
1238}
1239
1240static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1241 struct hda_codec *codec,
1242 struct snd_pcm_substream *substream)
1243{
1244 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001245
Takashi Iwaiece8d042011-06-19 16:24:21 +02001246 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001247 vt1708_stop_hp_work(spec);
1248 return 0;
1249}
1250
1251static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1252 struct hda_codec *codec,
1253 struct snd_pcm_substream *substream)
1254{
1255 struct via_spec *spec = codec->spec;
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001256
Takashi Iwaiece8d042011-06-19 16:24:21 +02001257 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001258 vt1708_stop_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001259 return 0;
1260}
1261
Joseph Chanc577b8a2006-11-29 15:29:40 +01001262/*
1263 * Digital out
1264 */
1265static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1266 struct hda_codec *codec,
1267 struct snd_pcm_substream *substream)
1268{
1269 struct via_spec *spec = codec->spec;
1270 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1271}
1272
1273static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1274 struct hda_codec *codec,
1275 struct snd_pcm_substream *substream)
1276{
1277 struct via_spec *spec = codec->spec;
1278 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1279}
1280
Harald Welte5691ec72008-09-15 22:42:26 +08001281static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001282 struct hda_codec *codec,
1283 unsigned int stream_tag,
1284 unsigned int format,
1285 struct snd_pcm_substream *substream)
1286{
1287 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001288 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1289 stream_tag, format, substream);
1290}
Harald Welte5691ec72008-09-15 22:42:26 +08001291
Takashi Iwai9da29272009-05-07 16:31:14 +02001292static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1293 struct hda_codec *codec,
1294 struct snd_pcm_substream *substream)
1295{
1296 struct via_spec *spec = codec->spec;
1297 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001298 return 0;
1299}
1300
Joseph Chanc577b8a2006-11-29 15:29:40 +01001301/*
1302 * Analog capture
1303 */
1304static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1305 struct hda_codec *codec,
1306 unsigned int stream_tag,
1307 unsigned int format,
1308 struct snd_pcm_substream *substream)
1309{
1310 struct via_spec *spec = codec->spec;
1311
1312 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1313 stream_tag, 0, format);
1314 return 0;
1315}
1316
1317static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1318 struct hda_codec *codec,
1319 struct snd_pcm_substream *substream)
1320{
1321 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001322 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001323 return 0;
1324}
1325
Takashi Iwai9af74212011-06-18 16:17:45 +02001326static const struct hda_pcm_stream via_pcm_analog_playback = {
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001327 .substreams = 1,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001328 .channels_min = 2,
1329 .channels_max = 8,
Takashi Iwai9af74212011-06-18 16:17:45 +02001330 /* NID is set in via_build_pcms */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001331 .ops = {
Takashi Iwaiece8d042011-06-19 16:24:21 +02001332 .open = via_playback_multi_pcm_open,
1333 .close = via_playback_multi_pcm_close,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001334 .prepare = via_playback_multi_pcm_prepare,
1335 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001336 },
1337};
1338
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001339static const struct hda_pcm_stream via_pcm_hp_playback = {
1340 .substreams = 1,
1341 .channels_min = 2,
1342 .channels_max = 2,
1343 /* NID is set in via_build_pcms */
1344 .ops = {
1345 .open = via_playback_hp_pcm_open,
Takashi Iwaiece8d042011-06-19 16:24:21 +02001346 .close = via_playback_hp_pcm_close,
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001347 .prepare = via_playback_hp_pcm_prepare,
1348 .cleanup = via_playback_hp_pcm_cleanup
1349 },
1350};
1351
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001352static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001353 .substreams = 1,
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001354 .channels_min = 2,
1355 .channels_max = 8,
Takashi Iwai9af74212011-06-18 16:17:45 +02001356 /* NID is set in via_build_pcms */
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001357 /* We got noisy outputs on the right channel on VT1708 when
1358 * 24bit samples are used. Until any workaround is found,
1359 * disable the 24bit format, so far.
1360 */
1361 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1362 .ops = {
Takashi Iwaiece8d042011-06-19 16:24:21 +02001363 .open = via_playback_multi_pcm_open,
1364 .close = via_playback_multi_pcm_close,
Lydia Wangc873cc22009-10-10 19:08:21 +08001365 .prepare = via_playback_multi_pcm_prepare,
1366 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001367 },
1368};
1369
Takashi Iwai9af74212011-06-18 16:17:45 +02001370static const struct hda_pcm_stream via_pcm_analog_capture = {
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001371 .substreams = 1, /* will be changed in via_build_pcms() */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001372 .channels_min = 2,
1373 .channels_max = 2,
Takashi Iwai9af74212011-06-18 16:17:45 +02001374 /* NID is set in via_build_pcms */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001375 .ops = {
1376 .prepare = via_capture_pcm_prepare,
1377 .cleanup = via_capture_pcm_cleanup
1378 },
1379};
1380
Takashi Iwai9af74212011-06-18 16:17:45 +02001381static const struct hda_pcm_stream via_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001382 .substreams = 1,
1383 .channels_min = 2,
1384 .channels_max = 2,
1385 /* NID is set in via_build_pcms */
1386 .ops = {
1387 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001388 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001389 .prepare = via_dig_playback_pcm_prepare,
1390 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001391 },
1392};
1393
Takashi Iwai9af74212011-06-18 16:17:45 +02001394static const struct hda_pcm_stream via_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001395 .substreams = 1,
1396 .channels_min = 2,
1397 .channels_max = 2,
1398};
1399
1400static int via_build_controls(struct hda_codec *codec)
1401{
1402 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001403 struct snd_kcontrol *kctl;
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001404 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001405 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001406
Takashi Iwai24088a52011-06-17 16:59:21 +02001407 if (spec->set_widgets_power_state)
1408 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1409 return -ENOMEM;
1410
Joseph Chanc577b8a2006-11-29 15:29:40 +01001411 for (i = 0; i < spec->num_mixers; i++) {
1412 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1413 if (err < 0)
1414 return err;
1415 }
1416
1417 if (spec->multiout.dig_out_nid) {
1418 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001419 spec->multiout.dig_out_nid,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001420 spec->multiout.dig_out_nid);
1421 if (err < 0)
1422 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001423 err = snd_hda_create_spdif_share_sw(codec,
1424 &spec->multiout);
1425 if (err < 0)
1426 return err;
1427 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001428 }
1429 if (spec->dig_in_nid) {
1430 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1431 if (err < 0)
1432 return err;
1433 }
Lydia Wang17314372009-10-10 19:07:37 +08001434
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001435 /* assign Capture Source enums to NID */
1436 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1437 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +01001438 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001439 if (err < 0)
1440 return err;
1441 }
1442
1443 /* other nid->control mapping */
1444 for (i = 0; i < spec->num_mixers; i++) {
1445 for (knew = spec->mixers[i]; knew->name; knew++) {
1446 if (knew->iface != NID_MAPPING)
1447 continue;
1448 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1449 if (kctl == NULL)
1450 continue;
1451 err = snd_hda_add_nid(codec, kctl, 0,
1452 knew->subdevice);
1453 }
1454 }
1455
Lydia Wang17314372009-10-10 19:07:37 +08001456 /* init power states */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001457 set_widgets_power_state(codec);
Lydia Wang17314372009-10-10 19:07:37 +08001458 analog_low_current_mode(codec, 1);
1459
Takashi Iwai603c4012008-07-30 15:01:44 +02001460 via_free_kctls(codec); /* no longer needed */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001461 return 0;
1462}
1463
1464static int via_build_pcms(struct hda_codec *codec)
1465{
1466 struct via_spec *spec = codec->spec;
1467 struct hda_pcm *info = spec->pcm_rec;
1468
1469 codec->num_pcms = 1;
1470 codec->pcm_info = info;
1471
Takashi Iwai82673bc2011-06-17 16:24:21 +02001472 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1473 "%s Analog", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001474 info->name = spec->stream_name_analog;
Takashi Iwai9af74212011-06-18 16:17:45 +02001475
1476 if (!spec->stream_analog_playback)
1477 spec->stream_analog_playback = &via_pcm_analog_playback;
Lydia Wang377ff312009-10-10 19:08:55 +08001478 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001479 *spec->stream_analog_playback;
Lydia Wang377ff312009-10-10 19:08:55 +08001480 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1481 spec->multiout.dac_nids[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001482 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1483 spec->multiout.max_channels;
Takashi Iwai9af74212011-06-18 16:17:45 +02001484
1485 if (!spec->stream_analog_capture)
1486 spec->stream_analog_capture = &via_pcm_analog_capture;
1487 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1488 *spec->stream_analog_capture;
1489 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1490 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1491 spec->num_adc_nids;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001492
1493 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1494 codec->num_pcms++;
1495 info++;
Takashi Iwai82673bc2011-06-17 16:24:21 +02001496 snprintf(spec->stream_name_digital,
1497 sizeof(spec->stream_name_digital),
1498 "%s Digital", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001499 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001500 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001501 if (spec->multiout.dig_out_nid) {
Takashi Iwai9af74212011-06-18 16:17:45 +02001502 if (!spec->stream_digital_playback)
1503 spec->stream_digital_playback =
1504 &via_pcm_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001505 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001506 *spec->stream_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001507 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1508 spec->multiout.dig_out_nid;
1509 }
1510 if (spec->dig_in_nid) {
Takashi Iwai9af74212011-06-18 16:17:45 +02001511 if (!spec->stream_digital_capture)
1512 spec->stream_digital_capture =
1513 &via_pcm_digital_capture;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001514 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001515 *spec->stream_digital_capture;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001516 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1517 spec->dig_in_nid;
1518 }
1519 }
1520
Takashi Iwaiece8d042011-06-19 16:24:21 +02001521 if (spec->hp_dac_nid) {
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001522 codec->num_pcms++;
1523 info++;
1524 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1525 "%s HP", codec->chip_name);
1526 info->name = spec->stream_name_hp;
1527 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1528 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
Takashi Iwaiece8d042011-06-19 16:24:21 +02001529 spec->hp_dac_nid;
Takashi Iwai7eb56e842011-06-18 16:40:14 +02001530 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001531 return 0;
1532}
1533
1534static void via_free(struct hda_codec *codec)
1535{
1536 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001537
1538 if (!spec)
1539 return;
1540
Takashi Iwai603c4012008-07-30 15:01:44 +02001541 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001542 vt1708_stop_hp_work(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001543 kfree(codec->spec);
1544}
1545
Takashi Iwai64be2852011-06-17 16:51:39 +02001546/* mute/unmute outputs */
1547static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1548 hda_nid_t *pins, bool mute)
1549{
1550 int i;
1551 for (i = 0; i < num_pins; i++)
1552 snd_hda_codec_write(codec, pins[i], 0,
1553 AC_VERB_SET_PIN_WIDGET_CONTROL,
1554 mute ? 0 : PIN_OUT);
1555}
1556
Harald Welte69e52a82008-09-09 15:57:32 +08001557/* mute internal speaker if HP is plugged */
1558static void via_hp_automute(struct hda_codec *codec)
1559{
Lydia Wangdcf34c82009-10-10 19:08:15 +08001560 unsigned int present = 0;
Harald Welte69e52a82008-09-09 15:57:32 +08001561 struct via_spec *spec = codec->spec;
1562
Takashi Iwaid56757a2009-11-18 08:00:14 +01001563 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangdcf34c82009-10-10 19:08:15 +08001564
Takashi Iwai64be2852011-06-17 16:51:39 +02001565 if (!spec->hp_independent_mode)
1566 toggle_output_mutes(codec, spec->autocfg.line_outs,
1567 spec->autocfg.line_out_pins,
1568 present);
Harald Welte69e52a82008-09-09 15:57:32 +08001569}
1570
Lydia Wangf3db4232009-10-10 19:08:41 +08001571/* mute mono out if HP or Line out is plugged */
1572static void via_mono_automute(struct hda_codec *codec)
1573{
1574 unsigned int hp_present, lineout_present;
1575 struct via_spec *spec = codec->spec;
1576
1577 if (spec->codec_type != VT1716S)
1578 return;
1579
Takashi Iwaid56757a2009-11-18 08:00:14 +01001580 lineout_present = snd_hda_jack_detect(codec,
1581 spec->autocfg.line_out_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001582
1583 /* Mute Mono Out if Line Out is plugged */
1584 if (lineout_present) {
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001585 snd_hda_codec_write(codec, 0x2A, 0,
1586 AC_VERB_SET_PIN_WIDGET_CONTROL,
1587 lineout_present ? 0 : PIN_OUT);
Lydia Wangf3db4232009-10-10 19:08:41 +08001588 return;
1589 }
1590
Takashi Iwaid56757a2009-11-18 08:00:14 +01001591 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001592
1593 if (!spec->hp_independent_mode)
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001594 snd_hda_codec_write(codec, 0x2A, 0,
1595 AC_VERB_SET_PIN_WIDGET_CONTROL,
1596 hp_present ? 0 : PIN_OUT);
Lydia Wangf3db4232009-10-10 19:08:41 +08001597}
1598
Harald Welte69e52a82008-09-09 15:57:32 +08001599static void via_gpio_control(struct hda_codec *codec)
1600{
1601 unsigned int gpio_data;
1602 unsigned int vol_counter;
1603 unsigned int vol;
1604 unsigned int master_vol;
1605
1606 struct via_spec *spec = codec->spec;
1607
1608 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1609 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1610
1611 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1612 0xF84, 0) & 0x3F0000) >> 16;
1613
1614 vol = vol_counter & 0x1F;
1615 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1616 AC_VERB_GET_AMP_GAIN_MUTE,
1617 AC_AMP_GET_INPUT);
1618
1619 if (gpio_data == 0x02) {
1620 /* unmute line out */
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001621 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1622 AC_VERB_SET_PIN_WIDGET_CONTROL,
1623 PIN_OUT);
Harald Welte69e52a82008-09-09 15:57:32 +08001624 if (vol_counter & 0x20) {
1625 /* decrease volume */
1626 if (vol > master_vol)
1627 vol = master_vol;
1628 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1629 0, HDA_AMP_VOLMASK,
1630 master_vol-vol);
1631 } else {
1632 /* increase volume */
1633 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1634 HDA_AMP_VOLMASK,
1635 ((master_vol+vol) > 0x2A) ? 0x2A :
1636 (master_vol+vol));
1637 }
1638 } else if (!(gpio_data & 0x02)) {
1639 /* mute line out */
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001640 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1641 AC_VERB_SET_PIN_WIDGET_CONTROL,
1642 0);
Harald Welte69e52a82008-09-09 15:57:32 +08001643 }
1644}
1645
Lydia Wang25eaba22009-10-10 19:08:43 +08001646/* mute Internal-Speaker if HP is plugged */
1647static void via_speaker_automute(struct hda_codec *codec)
1648{
1649 unsigned int hp_present;
1650 struct via_spec *spec = codec->spec;
1651
Lydia Wang27439ce2011-03-24 12:40:10 +08001652 if (!VT2002P_COMPATIBLE(spec))
Lydia Wang25eaba22009-10-10 19:08:43 +08001653 return;
1654
Takashi Iwaid56757a2009-11-18 08:00:14 +01001655 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001656
Takashi Iwai64be2852011-06-17 16:51:39 +02001657 if (!spec->hp_independent_mode)
1658 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1659 spec->autocfg.speaker_pins,
1660 hp_present);
Lydia Wang25eaba22009-10-10 19:08:43 +08001661}
1662
1663/* mute line-out and internal speaker if HP is plugged */
1664static void via_hp_bind_automute(struct hda_codec *codec)
1665{
Takashi Iwai64be2852011-06-17 16:51:39 +02001666 int present;
Lydia Wang25eaba22009-10-10 19:08:43 +08001667 struct via_spec *spec = codec->spec;
Lydia Wang25eaba22009-10-10 19:08:43 +08001668
1669 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1670 return;
1671
Takashi Iwai64be2852011-06-17 16:51:39 +02001672 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1673 if (!spec->hp_independent_mode)
1674 toggle_output_mutes(codec, spec->autocfg.line_outs,
1675 spec->autocfg.line_out_pins,
1676 present);
Lydia Wang25eaba22009-10-10 19:08:43 +08001677
Takashi Iwai64be2852011-06-17 16:51:39 +02001678 if (!present)
1679 present = snd_hda_jack_detect(codec,
1680 spec->autocfg.line_out_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001681
Lydia Wang25eaba22009-10-10 19:08:43 +08001682 /* Speakers */
Takashi Iwai64be2852011-06-17 16:51:39 +02001683 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1684 spec->autocfg.speaker_pins,
1685 present);
Lydia Wang25eaba22009-10-10 19:08:43 +08001686}
1687
1688
Harald Welte69e52a82008-09-09 15:57:32 +08001689/* unsolicited event for jack sensing */
1690static void via_unsol_event(struct hda_codec *codec,
1691 unsigned int res)
1692{
1693 res >>= 26;
Lydia Wangec7e7e42011-03-24 12:43:44 +08001694
Lydia Wanga34df192009-10-10 19:08:01 +08001695 if (res & VIA_JACK_EVENT)
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001696 set_widgets_power_state(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001697
1698 res &= ~VIA_JACK_EVENT;
1699
1700 if (res == VIA_HP_EVENT)
1701 via_hp_automute(codec);
1702 else if (res == VIA_GPIO_EVENT)
1703 via_gpio_control(codec);
1704 else if (res == VIA_MONO_EVENT)
Lydia Wangf3db4232009-10-10 19:08:41 +08001705 via_mono_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001706 else if (res == VIA_SPEAKER_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001707 via_speaker_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001708 else if (res == VIA_BIND_HP_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001709 via_hp_bind_automute(codec);
Harald Welte69e52a82008-09-09 15:57:32 +08001710}
1711
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001712#ifdef SND_HDA_NEEDS_RESUME
1713static int via_suspend(struct hda_codec *codec, pm_message_t state)
1714{
1715 struct via_spec *spec = codec->spec;
1716 vt1708_stop_hp_work(spec);
1717 return 0;
1718}
1719#endif
1720
Takashi Iwaicb53c622007-08-10 17:21:45 +02001721#ifdef CONFIG_SND_HDA_POWER_SAVE
1722static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1723{
1724 struct via_spec *spec = codec->spec;
1725 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1726}
1727#endif
1728
Joseph Chanc577b8a2006-11-29 15:29:40 +01001729/*
1730 */
Takashi Iwai5d417622011-06-20 11:32:27 +02001731
1732static int via_init(struct hda_codec *codec);
1733
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001734static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001735 .build_controls = via_build_controls,
1736 .build_pcms = via_build_pcms,
1737 .init = via_init,
1738 .free = via_free,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001739#ifdef SND_HDA_NEEDS_RESUME
1740 .suspend = via_suspend,
1741#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02001742#ifdef CONFIG_SND_HDA_POWER_SAVE
1743 .check_power_status = via_check_power_status,
1744#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001745};
1746
Takashi Iwai4a796162011-06-17 17:53:38 +02001747static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001748{
Takashi Iwai4a796162011-06-17 17:53:38 +02001749 struct via_spec *spec = codec->spec;
1750 int i;
1751
1752 for (i = 0; i < spec->multiout.num_dacs; i++) {
1753 if (spec->multiout.dac_nids[i] == dac)
1754 return false;
1755 }
Takashi Iwaiece8d042011-06-19 16:24:21 +02001756 if (spec->hp_dac_nid == dac)
Takashi Iwai4a796162011-06-17 17:53:38 +02001757 return false;
1758 return true;
1759}
1760
1761static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1762 hda_nid_t target_dac, struct nid_path *path,
1763 int depth, int wid_type)
1764{
1765 hda_nid_t conn[8];
1766 int i, nums;
1767
1768 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1769 for (i = 0; i < nums; i++) {
1770 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1771 continue;
1772 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1773 path->path[depth] = conn[i];
1774 path->idx[depth] = i;
1775 path->depth = ++depth;
1776 return true;
1777 }
1778 }
1779 if (depth > 4)
1780 return false;
1781 for (i = 0; i < nums; i++) {
1782 unsigned int type;
1783 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1784 if (type == AC_WID_AUD_OUT ||
1785 (wid_type != -1 && type != wid_type))
1786 continue;
1787 if (parse_output_path(codec, conn[i], target_dac,
1788 path, depth + 1, AC_WID_AUD_SEL)) {
1789 path->path[depth] = conn[i];
1790 path->idx[depth] = i;
1791 return true;
1792 }
1793 }
1794 return false;
1795}
1796
1797static int via_auto_fill_dac_nids(struct hda_codec *codec)
1798{
1799 struct via_spec *spec = codec->spec;
1800 const struct auto_pin_cfg *cfg = &spec->autocfg;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001801 int i;
1802 hda_nid_t nid;
1803
Joseph Chanc577b8a2006-11-29 15:29:40 +01001804 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai4a796162011-06-17 17:53:38 +02001805 spec->multiout.num_dacs = cfg->line_outs;
1806 for (i = 0; i < cfg->line_outs; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001807 nid = cfg->line_out_pins[i];
Takashi Iwai4a796162011-06-17 17:53:38 +02001808 if (!nid)
1809 continue;
1810 if (parse_output_path(codec, nid, 0, &spec->out_path[i], 0, -1))
1811 spec->private_dac_nids[i] =
1812 spec->out_path[i].path[spec->out_path[i].depth - 1];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001813 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001814 return 0;
1815}
1816
Takashi Iwai4a796162011-06-17 17:53:38 +02001817static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1818 hda_nid_t pin, hda_nid_t dac, int chs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001819{
Takashi Iwai4a796162011-06-17 17:53:38 +02001820 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001821 char name[32];
Takashi Iwai4a796162011-06-17 17:53:38 +02001822 hda_nid_t nid;
1823 int err;
1824
1825 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1826 nid = dac;
1827 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1828 nid = pin;
1829 else
1830 nid = 0;
1831 if (nid) {
1832 sprintf(name, "%s Playback Volume", pfx);
1833 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1834 HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT));
1835 if (err < 0)
1836 return err;
1837 }
1838
1839 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1840 nid = dac;
1841 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1842 nid = pin;
1843 else
1844 nid = 0;
1845 if (nid) {
1846 sprintf(name, "%s Playback Switch", pfx);
1847 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1848 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1849 if (err < 0)
1850 return err;
1851 }
1852 return 0;
1853}
1854
Takashi Iwaif4a78282011-06-17 18:46:48 +02001855static void mangle_smart51(struct hda_codec *codec)
1856{
1857 struct via_spec *spec = codec->spec;
1858 struct auto_pin_cfg *cfg = &spec->autocfg;
1859 int i;
1860
1861 for (i = 0; i < cfg->num_inputs; i++) {
1862 if (!is_smart51_pins(codec, cfg->inputs[i].pin))
1863 continue;
1864 spec->can_smart51 = 1;
1865 cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin;
1866 if (cfg->line_outs == 3)
1867 break;
1868 }
1869}
1870
Takashi Iwai4a796162011-06-17 17:53:38 +02001871/* add playback controls from the parsed DAC table */
1872static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1873{
1874 struct via_spec *spec = codec->spec;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001875 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaiea734962011-01-17 11:29:34 +01001876 static const char * const chname[4] = {
1877 "Front", "Surround", "C/LFE", "Side"
1878 };
Takashi Iwai4a796162011-06-17 17:53:38 +02001879 int i, idx, err;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001880 int old_line_outs;
1881
1882 /* check smart51 */
1883 old_line_outs = cfg->line_outs;
1884 if (cfg->line_outs == 1)
1885 mangle_smart51(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001886
Takashi Iwai4a796162011-06-17 17:53:38 +02001887 for (i = 0; i < cfg->line_outs; i++) {
1888 hda_nid_t pin, dac;
1889 pin = cfg->line_out_pins[i];
1890 dac = spec->multiout.dac_nids[i];
1891 if (!pin || !dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001892 continue;
Takashi Iwai0fe0adf2011-06-19 16:27:53 +02001893 if (i == HDA_CLFE) {
Takashi Iwai4a796162011-06-17 17:53:38 +02001894 err = create_ch_ctls(codec, "Center", pin, dac, 1);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001895 if (err < 0)
1896 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02001897 err = create_ch_ctls(codec, "LFE", pin, dac, 2);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001898 if (err < 0)
1899 return err;
1900 } else {
Takashi Iwai4a796162011-06-17 17:53:38 +02001901 err = create_ch_ctls(codec, chname[i], pin, dac, 3);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001902 if (err < 0)
1903 return err;
1904 }
1905 }
1906
Takashi Iwai4a796162011-06-17 17:53:38 +02001907 idx = get_connection_index(codec, spec->aa_mix_nid,
1908 spec->multiout.dac_nids[0]);
1909 if (idx >= 0) {
1910 /* add control to mixer */
1911 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1912 "PCM Playback Volume",
1913 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1914 idx, HDA_INPUT));
1915 if (err < 0)
1916 return err;
1917 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1918 "PCM Playback Switch",
1919 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1920 idx, HDA_INPUT));
1921 if (err < 0)
1922 return err;
1923 }
1924
Takashi Iwaif4a78282011-06-17 18:46:48 +02001925 cfg->line_outs = old_line_outs;
1926
Joseph Chanc577b8a2006-11-29 15:29:40 +01001927 return 0;
1928}
1929
Harald Welte0aa62ae2008-09-09 15:58:27 +08001930static void create_hp_imux(struct via_spec *spec)
1931{
1932 int i;
1933 struct hda_input_mux *imux = &spec->private_imux[1];
Takashi Iwaiea734962011-01-17 11:29:34 +01001934 static const char * const texts[] = { "OFF", "ON", NULL};
Harald Welte0aa62ae2008-09-09 15:58:27 +08001935
1936 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02001937 for (i = 0; texts[i]; i++)
1938 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001939
1940 spec->hp_mux = &spec->private_imux[1];
1941}
1942
Takashi Iwai4a796162011-06-17 17:53:38 +02001943static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001944{
Takashi Iwai4a796162011-06-17 17:53:38 +02001945 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001946 int err;
1947
1948 if (!pin)
1949 return 0;
1950
Takashi Iwai4a796162011-06-17 17:53:38 +02001951 if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) {
Takashi Iwaiece8d042011-06-19 16:24:21 +02001952 spec->hp_dac_nid = spec->hp_path.path[spec->hp_path.depth - 1];
Takashi Iwai4a796162011-06-17 17:53:38 +02001953 spec->hp_independent_mode_index =
1954 spec->hp_path.idx[spec->hp_path.depth - 1];
1955 create_hp_imux(spec);
1956 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001957
Takashi Iwaiece8d042011-06-19 16:24:21 +02001958 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1959 &spec->hp_dep_path, 0, -1) &&
1960 !spec->hp_dac_nid)
1961 return 0;
1962
1963
1964 err = create_ch_ctls(codec, "Headphone", pin, spec->hp_dac_nid, 3);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001965 if (err < 0)
1966 return err;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001967
Joseph Chanc577b8a2006-11-29 15:29:40 +01001968 return 0;
1969}
1970
Takashi Iwaia766d0d2011-06-17 09:01:29 +02001971/* look for ADCs */
1972static int via_fill_adcs(struct hda_codec *codec)
1973{
1974 struct via_spec *spec = codec->spec;
1975 hda_nid_t nid = codec->start_nid;
1976 int i;
1977
1978 for (i = 0; i < codec->num_nodes; i++, nid++) {
1979 unsigned int wcaps = get_wcaps(codec, nid);
1980 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1981 continue;
1982 if (wcaps & AC_WCAP_DIGITAL)
1983 continue;
1984 if (!(wcaps & AC_WCAP_CONN_LIST))
1985 continue;
1986 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
1987 return -ENOMEM;
1988 spec->adc_nids[spec->num_adc_nids++] = nid;
1989 }
1990 return 0;
1991}
1992
1993static int get_mux_nids(struct hda_codec *codec);
1994
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001995static const struct snd_kcontrol_new via_input_src_ctl = {
1996 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1997 /* The multiple "Capture Source" controls confuse alsamixer
1998 * So call somewhat different..
1999 */
2000 /* .name = "Capture Source", */
2001 .name = "Input Source",
2002 .info = via_mux_enum_info,
2003 .get = via_mux_enum_get,
2004 .put = via_mux_enum_put,
2005};
2006
Joseph Chanc577b8a2006-11-29 15:29:40 +01002007/* create playback/capture controls for input pins */
Takashi Iwai620e2b22011-06-17 17:19:19 +02002008static int via_auto_create_analog_input_ctls(struct hda_codec *codec,
2009 const struct auto_pin_cfg *cfg)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002010{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002011 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08002012 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002013 int i, err, idx, idx2, type, type_idx = 0;
2014 hda_nid_t cap_nid;
2015 hda_nid_t pin_idxs[8];
2016 int num_idxs;
2017
2018 err = via_fill_adcs(codec);
2019 if (err < 0)
2020 return err;
2021 err = get_mux_nids(codec);
2022 if (err < 0)
2023 return err;
2024 cap_nid = spec->mux_nids[0];
2025
2026 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
2027 ARRAY_SIZE(pin_idxs));
2028 if (num_idxs <= 0)
2029 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002030
2031 /* for internal loopback recording select */
Takashi Iwaif3268512010-08-30 11:00:19 +02002032 for (idx = 0; idx < num_idxs; idx++) {
Takashi Iwai620e2b22011-06-17 17:19:19 +02002033 if (pin_idxs[idx] == spec->aa_mix_nid) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002034 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
Takashi Iwaif3268512010-08-30 11:00:19 +02002035 break;
2036 }
2037 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002038
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002039 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002040 const char *label;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002041 type = cfg->inputs[i].type;
Takashi Iwaif3268512010-08-30 11:00:19 +02002042 for (idx = 0; idx < num_idxs; idx++)
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002043 if (pin_idxs[idx] == cfg->inputs[i].pin)
Takashi Iwaif3268512010-08-30 11:00:19 +02002044 break;
2045 if (idx >= num_idxs)
2046 continue;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002047 if (i > 0 && type == cfg->inputs[i - 1].type)
2048 type_idx++;
2049 else
2050 type_idx = 0;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002051 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai620e2b22011-06-17 17:19:19 +02002052 idx2 = get_connection_index(codec, spec->aa_mix_nid,
2053 pin_idxs[idx]);
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002054 if (idx2 >= 0)
Lydia Wang16922282011-03-22 16:24:10 +08002055 err = via_new_analog_input(spec, label, type_idx,
Takashi Iwai620e2b22011-06-17 17:19:19 +02002056 idx2, spec->aa_mix_nid);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002057 if (err < 0)
2058 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002059 snd_hda_add_imux_item(imux, label, idx, NULL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002060 }
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002061
2062 /* create capture mixer elements */
2063 for (i = 0; i < spec->num_adc_nids; i++) {
2064 hda_nid_t adc = spec->adc_nids[i];
2065 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2066 "Capture Volume", i,
2067 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2068 HDA_INPUT));
2069 if (err < 0)
2070 return err;
2071 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2072 "Capture Switch", i,
2073 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2074 HDA_INPUT));
2075 if (err < 0)
2076 return err;
2077 }
2078
2079 /* input-source control */
2080 for (i = 0; i < spec->num_adc_nids; i++)
2081 if (!spec->mux_nids[i])
2082 break;
2083 if (i) {
2084 struct snd_kcontrol_new *knew;
2085 knew = via_clone_control(spec, &via_input_src_ctl);
2086 if (!knew)
2087 return -ENOMEM;
2088 knew->count = i;
2089 }
2090
2091 /* mic-boosts */
2092 for (i = 0; i < cfg->num_inputs; i++) {
2093 hda_nid_t pin = cfg->inputs[i].pin;
2094 unsigned int caps;
2095 const char *label;
2096 char name[32];
2097
2098 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2099 continue;
2100 caps = query_amp_caps(codec, pin, HDA_INPUT);
2101 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2102 continue;
2103 label = hda_get_autocfg_input_label(codec, cfg, i);
2104 snprintf(name, sizeof(name), "%s Boost Capture Volume", label);
2105 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2106 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2107 if (err < 0)
2108 return err;
2109 }
2110
Joseph Chanc577b8a2006-11-29 15:29:40 +01002111 return 0;
2112}
2113
Takashi Iwaicb53c622007-08-10 17:21:45 +02002114#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002115static const struct hda_amp_list vt1708_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002116 { 0x17, HDA_INPUT, 1 },
2117 { 0x17, HDA_INPUT, 2 },
2118 { 0x17, HDA_INPUT, 3 },
2119 { 0x17, HDA_INPUT, 4 },
2120 { } /* end */
2121};
2122#endif
2123
Harald Welte76d9b0d2008-09-09 15:50:37 +08002124static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2125{
2126 unsigned int def_conf;
2127 unsigned char seqassoc;
2128
Takashi Iwai2f334f92009-02-20 14:37:42 +01002129 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002130 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2131 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002132 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2133 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2134 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2135 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002136 }
2137
2138 return;
2139}
2140
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002141static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002142 struct snd_ctl_elem_value *ucontrol)
2143{
2144 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2145 struct via_spec *spec = codec->spec;
2146
2147 if (spec->codec_type != VT1708)
2148 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002149 spec->vt1708_jack_detect =
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002150 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002151 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002152 return 0;
2153}
2154
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002155static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002156 struct snd_ctl_elem_value *ucontrol)
2157{
2158 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2159 struct via_spec *spec = codec->spec;
2160 int change;
2161
2162 if (spec->codec_type != VT1708)
2163 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002164 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002165 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002166 == !spec->vt1708_jack_detect;
2167 if (spec->vt1708_jack_detect) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002168 mute_aa_path(codec, 1);
2169 notify_aa_path_ctls(codec);
2170 }
2171 return change;
2172}
2173
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002174static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2175 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2176 .name = "Jack Detect",
2177 .count = 1,
2178 .info = snd_ctl_boolean_mono_info,
2179 .get = vt1708_jack_detect_get,
2180 .put = vt1708_jack_detect_put,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002181};
2182
Takashi Iwai12daef62011-06-18 17:45:49 +02002183static void fill_dig_outs(struct hda_codec *codec);
2184static void fill_dig_in(struct hda_codec *codec);
2185
2186static int via_parse_auto_config(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002187{
2188 struct via_spec *spec = codec->spec;
2189 int err;
2190
2191 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2192 if (err < 0)
2193 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002194 err = via_auto_fill_dac_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002195 if (err < 0)
2196 return err;
2197 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
Takashi Iwai7f0df882011-06-18 17:33:34 +02002198 return -EINVAL;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002199
Takashi Iwai4a796162011-06-17 17:53:38 +02002200 err = via_auto_create_multi_out_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002201 if (err < 0)
2202 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002203 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002204 if (err < 0)
2205 return err;
Takashi Iwai620e2b22011-06-17 17:19:19 +02002206 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002207 if (err < 0)
2208 return err;
2209
2210 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2211
Takashi Iwai12daef62011-06-18 17:45:49 +02002212 fill_dig_outs(codec);
2213 fill_dig_in(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002214
Takashi Iwai603c4012008-07-30 15:01:44 +02002215 if (spec->kctls.list)
2216 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002217
Takashi Iwai096a8852011-06-20 12:09:02 +02002218 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002219
Harald Welte0aa62ae2008-09-09 15:58:27 +08002220 spec->input_mux = &spec->private_imux[0];
2221
Takashi Iwaiece8d042011-06-19 16:24:21 +02002222 if (spec->hp_mux) {
2223 err = via_hp_build(codec);
2224 if (err < 0)
2225 return err;
2226 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002227
Takashi Iwaif4a78282011-06-17 18:46:48 +02002228 err = via_smart51_build(codec);
2229 if (err < 0)
2230 return err;
2231
Takashi Iwai5d417622011-06-20 11:32:27 +02002232 /* assign slave outs */
2233 if (spec->slave_dig_outs[0])
2234 codec->slave_dig_outs = spec->slave_dig_outs;
2235
Joseph Chanc577b8a2006-11-29 15:29:40 +01002236 return 1;
2237}
2238
Takashi Iwai5d417622011-06-20 11:32:27 +02002239static void via_auto_init_dig_outs(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002240{
Lydia Wang25eaba22009-10-10 19:08:43 +08002241 struct via_spec *spec = codec->spec;
Takashi Iwai5d417622011-06-20 11:32:27 +02002242 if (spec->multiout.dig_out_nid)
2243 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2244 if (spec->slave_dig_outs[0])
2245 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2246}
Lydia Wang25eaba22009-10-10 19:08:43 +08002247
Takashi Iwai5d417622011-06-20 11:32:27 +02002248static void via_auto_init_dig_in(struct hda_codec *codec)
2249{
2250 struct via_spec *spec = codec->spec;
2251 if (!spec->dig_in_nid)
2252 return;
2253 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2254 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2255}
2256
2257static int via_init(struct hda_codec *codec)
2258{
2259 struct via_spec *spec = codec->spec;
2260 int i;
2261
2262 for (i = 0; i < spec->num_iverbs; i++)
2263 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2264
Joseph Chanc577b8a2006-11-29 15:29:40 +01002265 via_auto_init_multi_out(codec);
2266 via_auto_init_hp_out(codec);
2267 via_auto_init_analog_input(codec);
Takashi Iwai5d417622011-06-20 11:32:27 +02002268 via_auto_init_dig_outs(codec);
2269 via_auto_init_dig_in(codec);
Lydia Wang118909562011-03-23 17:57:34 +08002270
2271 if (VT2002P_COMPATIBLE(spec)) {
Lydia Wang25eaba22009-10-10 19:08:43 +08002272 via_hp_bind_automute(codec);
2273 } else {
2274 via_hp_automute(codec);
2275 via_speaker_automute(codec);
2276 }
2277
Joseph Chanc577b8a2006-11-29 15:29:40 +01002278 return 0;
2279}
2280
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002281static void vt1708_update_hp_jack_state(struct work_struct *work)
2282{
2283 struct via_spec *spec = container_of(work, struct via_spec,
2284 vt1708_hp_work.work);
2285 if (spec->codec_type != VT1708)
2286 return;
2287 /* if jack state toggled */
2288 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002289 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002290 spec->vt1708_hp_present ^= 1;
2291 via_hp_automute(spec->codec);
2292 }
2293 vt1708_start_hp_work(spec);
2294}
2295
Takashi Iwai337b9d02009-07-07 18:18:59 +02002296static int get_mux_nids(struct hda_codec *codec)
2297{
2298 struct via_spec *spec = codec->spec;
2299 hda_nid_t nid, conn[8];
2300 unsigned int type;
2301 int i, n;
2302
2303 for (i = 0; i < spec->num_adc_nids; i++) {
2304 nid = spec->adc_nids[i];
2305 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002306 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002307 if (type == AC_WID_PIN)
2308 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002309 n = snd_hda_get_connections(codec, nid, conn,
2310 ARRAY_SIZE(conn));
2311 if (n <= 0)
2312 break;
2313 if (n > 1) {
2314 spec->mux_nids[i] = nid;
2315 break;
2316 }
2317 nid = conn[0];
2318 }
2319 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002320 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002321}
2322
Joseph Chanc577b8a2006-11-29 15:29:40 +01002323static int patch_vt1708(struct hda_codec *codec)
2324{
2325 struct via_spec *spec;
2326 int err;
2327
2328 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002329 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002330 if (spec == NULL)
2331 return -ENOMEM;
2332
Takashi Iwai620e2b22011-06-17 17:19:19 +02002333 spec->aa_mix_nid = 0x17;
2334
Takashi Iwai12daef62011-06-18 17:45:49 +02002335 /* Add HP and CD pin config connect bit re-config action */
2336 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2337 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2338
Joseph Chanc577b8a2006-11-29 15:29:40 +01002339 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002340 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002341 if (err < 0) {
2342 via_free(codec);
2343 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002344 }
2345
Takashi Iwai12daef62011-06-18 17:45:49 +02002346 /* add jack detect on/off control */
2347 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2348 return -ENOMEM;
2349
Takashi Iwaibc9b562382008-05-23 17:50:27 +02002350 /* disable 32bit format on VT1708 */
2351 if (codec->vendor_id == 0x11061708)
2352 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002353
Joseph Chanc577b8a2006-11-29 15:29:40 +01002354 codec->patch_ops = via_patch_ops;
2355
Takashi Iwaicb53c622007-08-10 17:21:45 +02002356#ifdef CONFIG_SND_HDA_POWER_SAVE
2357 spec->loopback.amplist = vt1708_loopbacks;
2358#endif
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002359 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002360 return 0;
2361}
2362
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002363static const struct hda_verb vt1709_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002364 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2365 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002366 { }
2367};
2368
Joseph Chanc577b8a2006-11-29 15:29:40 +01002369/*
2370 * generic initialization of ADC, input mixers and output mixers
2371 */
Takashi Iwaicb53c622007-08-10 17:21:45 +02002372#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002373static const struct hda_amp_list vt1709_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002374 { 0x18, HDA_INPUT, 1 },
2375 { 0x18, HDA_INPUT, 2 },
2376 { 0x18, HDA_INPUT, 3 },
2377 { 0x18, HDA_INPUT, 4 },
2378 { } /* end */
2379};
2380#endif
2381
Joseph Chanc577b8a2006-11-29 15:29:40 +01002382static int patch_vt1709_10ch(struct hda_codec *codec)
2383{
2384 struct via_spec *spec;
2385 int err;
2386
2387 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002388 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002389 if (spec == NULL)
2390 return -ENOMEM;
2391
Takashi Iwai620e2b22011-06-17 17:19:19 +02002392 spec->aa_mix_nid = 0x18;
2393
Takashi Iwai12daef62011-06-18 17:45:49 +02002394 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002395 if (err < 0) {
2396 via_free(codec);
2397 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002398 }
2399
Harald Welte69e52a82008-09-09 15:57:32 +08002400 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002401
Joseph Chanc577b8a2006-11-29 15:29:40 +01002402 codec->patch_ops = via_patch_ops;
2403
Harald Welte69e52a82008-09-09 15:57:32 +08002404 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002405#ifdef CONFIG_SND_HDA_POWER_SAVE
2406 spec->loopback.amplist = vt1709_loopbacks;
2407#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002408
2409 return 0;
2410}
2411/*
2412 * generic initialization of ADC, input mixers and output mixers
2413 */
Joseph Chanc577b8a2006-11-29 15:29:40 +01002414static int patch_vt1709_6ch(struct hda_codec *codec)
2415{
2416 struct via_spec *spec;
2417 int err;
2418
2419 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002420 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002421 if (spec == NULL)
2422 return -ENOMEM;
2423
Takashi Iwai620e2b22011-06-17 17:19:19 +02002424 spec->aa_mix_nid = 0x18;
2425
Takashi Iwai12daef62011-06-18 17:45:49 +02002426 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002427 if (err < 0) {
2428 via_free(codec);
2429 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002430 }
2431
Harald Welte69e52a82008-09-09 15:57:32 +08002432 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002433
Joseph Chanc577b8a2006-11-29 15:29:40 +01002434 codec->patch_ops = via_patch_ops;
2435
Harald Welte69e52a82008-09-09 15:57:32 +08002436 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002437#ifdef CONFIG_SND_HDA_POWER_SAVE
2438 spec->loopback.amplist = vt1709_loopbacks;
2439#endif
Josepch Chanf7278fd2007-12-13 16:40:40 +01002440 return 0;
2441}
2442
Josepch Chanf7278fd2007-12-13 16:40:40 +01002443/*
2444 * generic initialization of ADC, input mixers and output mixers
2445 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002446static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002447 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2448 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2449 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2450 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2451 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2452 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2453 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2454 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2455 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002456 { }
2457};
2458
Josepch Chanf7278fd2007-12-13 16:40:40 +01002459#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002460static const struct hda_amp_list vt1708B_loopbacks[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002461 { 0x16, HDA_INPUT, 1 },
2462 { 0x16, HDA_INPUT, 2 },
2463 { 0x16, HDA_INPUT, 3 },
2464 { 0x16, HDA_INPUT, 4 },
2465 { } /* end */
2466};
2467#endif
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002468
2469static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2470{
2471 struct via_spec *spec = codec->spec;
2472 int imux_is_smixer;
2473 unsigned int parm;
2474 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +08002475 if ((spec->codec_type != VT1708B_4CH) &&
2476 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002477 is_8ch = 1;
2478
2479 /* SW0 (17h) = stereo mixer */
2480 imux_is_smixer =
2481 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2482 == ((spec->codec_type == VT1708S) ? 5 : 0));
2483 /* inputs */
2484 /* PW 1/2/5 (1ah/1bh/1eh) */
2485 parm = AC_PWRST_D3;
2486 set_pin_power_state(codec, 0x1a, &parm);
2487 set_pin_power_state(codec, 0x1b, &parm);
2488 set_pin_power_state(codec, 0x1e, &parm);
2489 if (imux_is_smixer)
2490 parm = AC_PWRST_D0;
2491 /* SW0 (17h), AIW 0/1 (13h/14h) */
2492 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2493 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2494 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2495
2496 /* outputs */
2497 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2498 parm = AC_PWRST_D3;
2499 set_pin_power_state(codec, 0x19, &parm);
2500 if (spec->smart51_enabled)
2501 set_pin_power_state(codec, 0x1b, &parm);
2502 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2503 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2504
2505 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2506 if (is_8ch) {
2507 parm = AC_PWRST_D3;
2508 set_pin_power_state(codec, 0x22, &parm);
2509 if (spec->smart51_enabled)
2510 set_pin_power_state(codec, 0x1a, &parm);
2511 snd_hda_codec_write(codec, 0x26, 0,
2512 AC_VERB_SET_POWER_STATE, parm);
2513 snd_hda_codec_write(codec, 0x24, 0,
2514 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002515 } else if (codec->vendor_id == 0x11064397) {
2516 /* PW7(23h), SW2(27h), AOW2(25h) */
2517 parm = AC_PWRST_D3;
2518 set_pin_power_state(codec, 0x23, &parm);
2519 if (spec->smart51_enabled)
2520 set_pin_power_state(codec, 0x1a, &parm);
2521 snd_hda_codec_write(codec, 0x27, 0,
2522 AC_VERB_SET_POWER_STATE, parm);
2523 snd_hda_codec_write(codec, 0x25, 0,
2524 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002525 }
2526
2527 /* PW 3/4/7 (1ch/1dh/23h) */
2528 parm = AC_PWRST_D3;
2529 /* force to D0 for internal Speaker */
2530 set_pin_power_state(codec, 0x1c, &parm);
2531 set_pin_power_state(codec, 0x1d, &parm);
2532 if (is_8ch)
2533 set_pin_power_state(codec, 0x23, &parm);
2534
2535 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2536 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2537 imux_is_smixer ? AC_PWRST_D0 : parm);
2538 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2539 if (is_8ch) {
2540 snd_hda_codec_write(codec, 0x25, 0,
2541 AC_VERB_SET_POWER_STATE, parm);
2542 snd_hda_codec_write(codec, 0x27, 0,
2543 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002544 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2545 snd_hda_codec_write(codec, 0x25, 0,
2546 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002547}
2548
Lydia Wang518bf3b2009-10-10 19:07:29 +08002549static int patch_vt1708S(struct hda_codec *codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002550static int patch_vt1708B_8ch(struct hda_codec *codec)
2551{
2552 struct via_spec *spec;
2553 int err;
2554
Lydia Wang518bf3b2009-10-10 19:07:29 +08002555 if (get_codec_type(codec) == VT1708BCE)
2556 return patch_vt1708S(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002557 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002558 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002559 if (spec == NULL)
2560 return -ENOMEM;
2561
Takashi Iwai620e2b22011-06-17 17:19:19 +02002562 spec->aa_mix_nid = 0x16;
2563
Josepch Chanf7278fd2007-12-13 16:40:40 +01002564 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002565 err = via_parse_auto_config(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002566 if (err < 0) {
2567 via_free(codec);
2568 return err;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002569 }
2570
Harald Welte69e52a82008-09-09 15:57:32 +08002571 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002572
Josepch Chanf7278fd2007-12-13 16:40:40 +01002573 codec->patch_ops = via_patch_ops;
2574
Harald Welte69e52a82008-09-09 15:57:32 +08002575 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002576#ifdef CONFIG_SND_HDA_POWER_SAVE
2577 spec->loopback.amplist = vt1708B_loopbacks;
2578#endif
2579
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002580 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2581
Josepch Chanf7278fd2007-12-13 16:40:40 +01002582 return 0;
2583}
2584
2585static int patch_vt1708B_4ch(struct hda_codec *codec)
2586{
2587 struct via_spec *spec;
2588 int err;
2589
2590 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002591 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002592 if (spec == NULL)
2593 return -ENOMEM;
2594
Josepch Chanf7278fd2007-12-13 16:40:40 +01002595 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002596 err = via_parse_auto_config(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002597 if (err < 0) {
2598 via_free(codec);
2599 return err;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002600 }
2601
Harald Welte69e52a82008-09-09 15:57:32 +08002602 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002603
Josepch Chanf7278fd2007-12-13 16:40:40 +01002604 codec->patch_ops = via_patch_ops;
2605
Harald Welte69e52a82008-09-09 15:57:32 +08002606 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002607#ifdef CONFIG_SND_HDA_POWER_SAVE
2608 spec->loopback.amplist = vt1708B_loopbacks;
2609#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002610
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002611 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2612
Joseph Chanc577b8a2006-11-29 15:29:40 +01002613 return 0;
2614}
2615
Harald Welted949cac2008-09-09 15:56:01 +08002616/* Patch for VT1708S */
Takashi Iwai096a8852011-06-20 12:09:02 +02002617static const struct hda_verb vt1708S_init_verbs[] = {
Harald Welted7426322008-09-15 22:43:23 +08002618 /* Enable Mic Boost Volume backdoor */
2619 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08002620 /* don't bybass mixer */
2621 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08002622 { }
2623};
2624
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002625static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002626 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2627 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2628 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2629 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2630 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2631 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2632 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2633 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2634 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002635 { }
2636};
2637
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002638static const struct hda_verb vt1705_uniwill_init_verbs[] = {
Lydia Wangbc92df72011-03-23 17:56:05 +08002639 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2640 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2641 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2642 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2643 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2644 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2645 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2646 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2647 { }
2648};
2649
Takashi Iwai9da29272009-05-07 16:31:14 +02002650/* fill out digital output widgets; one for master and one for slave outputs */
2651static void fill_dig_outs(struct hda_codec *codec)
2652{
2653 struct via_spec *spec = codec->spec;
2654 int i;
2655
2656 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2657 hda_nid_t nid;
2658 int conn;
2659
2660 nid = spec->autocfg.dig_out_pins[i];
2661 if (!nid)
2662 continue;
2663 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2664 if (conn < 1)
2665 continue;
2666 if (!spec->multiout.dig_out_nid)
2667 spec->multiout.dig_out_nid = nid;
2668 else {
2669 spec->slave_dig_outs[0] = nid;
2670 break; /* at most two dig outs */
2671 }
2672 }
2673}
2674
Takashi Iwai12daef62011-06-18 17:45:49 +02002675static void fill_dig_in(struct hda_codec *codec)
Harald Welted949cac2008-09-09 15:56:01 +08002676{
2677 struct via_spec *spec = codec->spec;
Takashi Iwai12daef62011-06-18 17:45:49 +02002678 hda_nid_t dig_nid;
2679 int i, err;
Harald Welted949cac2008-09-09 15:56:01 +08002680
Takashi Iwai12daef62011-06-18 17:45:49 +02002681 if (!spec->autocfg.dig_in_pin)
2682 return;
Harald Welted949cac2008-09-09 15:56:01 +08002683
Takashi Iwai12daef62011-06-18 17:45:49 +02002684 dig_nid = codec->start_nid;
2685 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2686 unsigned int wcaps = get_wcaps(codec, dig_nid);
2687 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2688 continue;
2689 if (!(wcaps & AC_WCAP_DIGITAL))
2690 continue;
2691 if (!(wcaps & AC_WCAP_CONN_LIST))
2692 continue;
2693 err = get_connection_index(codec, dig_nid,
2694 spec->autocfg.dig_in_pin);
2695 if (err >= 0) {
2696 spec->dig_in_nid = dig_nid;
2697 break;
2698 }
2699 }
Harald Welted949cac2008-09-09 15:56:01 +08002700}
2701
2702#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002703static const struct hda_amp_list vt1708S_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08002704 { 0x16, HDA_INPUT, 1 },
2705 { 0x16, HDA_INPUT, 2 },
2706 { 0x16, HDA_INPUT, 3 },
2707 { 0x16, HDA_INPUT, 4 },
2708 { } /* end */
2709};
2710#endif
2711
Lydia Wang6369bcf2009-10-10 19:08:31 +08002712static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
2713 int offset, int num_steps, int step_size)
2714{
2715 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
2716 (offset << AC_AMPCAP_OFFSET_SHIFT) |
2717 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
2718 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
2719 (0 << AC_AMPCAP_MUTE_SHIFT));
2720}
2721
Harald Welted949cac2008-09-09 15:56:01 +08002722static int patch_vt1708S(struct hda_codec *codec)
2723{
2724 struct via_spec *spec;
2725 int err;
2726
2727 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002728 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08002729 if (spec == NULL)
2730 return -ENOMEM;
2731
Takashi Iwai620e2b22011-06-17 17:19:19 +02002732 spec->aa_mix_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002733 override_mic_boost(codec, 0x1a, 0, 3, 40);
2734 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02002735
Harald Welted949cac2008-09-09 15:56:01 +08002736 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002737 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +08002738 if (err < 0) {
2739 via_free(codec);
2740 return err;
Harald Welted949cac2008-09-09 15:56:01 +08002741 }
2742
Takashi Iwai096a8852011-06-20 12:09:02 +02002743 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
Lydia Wangbc92df72011-03-23 17:56:05 +08002744 if (codec->vendor_id == 0x11064397)
2745 spec->init_verbs[spec->num_iverbs++] =
2746 vt1705_uniwill_init_verbs;
2747 else
2748 spec->init_verbs[spec->num_iverbs++] =
2749 vt1708S_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08002750
Harald Welted949cac2008-09-09 15:56:01 +08002751 codec->patch_ops = via_patch_ops;
2752
Harald Welte69e52a82008-09-09 15:57:32 +08002753 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08002754#ifdef CONFIG_SND_HDA_POWER_SAVE
2755 spec->loopback.amplist = vt1708S_loopbacks;
2756#endif
2757
Lydia Wang518bf3b2009-10-10 19:07:29 +08002758 /* correct names for VT1708BCE */
2759 if (get_codec_type(codec) == VT1708BCE) {
2760 kfree(codec->chip_name);
2761 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
2762 snprintf(codec->bus->card->mixername,
2763 sizeof(codec->bus->card->mixername),
2764 "%s %s", codec->vendor_name, codec->chip_name);
Lydia Wang970f630f2011-03-22 16:25:56 +08002765 }
Lydia Wangbc92df72011-03-23 17:56:05 +08002766 /* correct names for VT1705 */
2767 if (codec->vendor_id == 0x11064397) {
2768 kfree(codec->chip_name);
2769 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
2770 snprintf(codec->bus->card->mixername,
2771 sizeof(codec->bus->card->mixername),
2772 "%s %s", codec->vendor_name, codec->chip_name);
2773 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002774 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +08002775 return 0;
2776}
2777
2778/* Patch for VT1702 */
2779
Takashi Iwai096a8852011-06-20 12:09:02 +02002780static const struct hda_verb vt1702_init_verbs[] = {
Lydia Wangbc7e7e52009-10-10 19:08:32 +08002781 /* mixer enable */
2782 {0x1, 0xF88, 0x3},
2783 /* GPIO 0~2 */
2784 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08002785 { }
2786};
2787
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002788static const struct hda_verb vt1702_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002789 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
2790 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2791 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2792 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2793 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2794 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002795 { }
2796};
2797
Harald Welted949cac2008-09-09 15:56:01 +08002798#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002799static const struct hda_amp_list vt1702_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08002800 { 0x1A, HDA_INPUT, 1 },
2801 { 0x1A, HDA_INPUT, 2 },
2802 { 0x1A, HDA_INPUT, 3 },
2803 { 0x1A, HDA_INPUT, 4 },
2804 { } /* end */
2805};
2806#endif
2807
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002808static void set_widgets_power_state_vt1702(struct hda_codec *codec)
2809{
2810 int imux_is_smixer =
2811 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2812 unsigned int parm;
2813 /* inputs */
2814 /* PW 1/2/5 (14h/15h/18h) */
2815 parm = AC_PWRST_D3;
2816 set_pin_power_state(codec, 0x14, &parm);
2817 set_pin_power_state(codec, 0x15, &parm);
2818 set_pin_power_state(codec, 0x18, &parm);
2819 if (imux_is_smixer)
2820 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
2821 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
2822 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2823 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
2824 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2825 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
2826
2827 /* outputs */
2828 /* PW 3/4 (16h/17h) */
2829 parm = AC_PWRST_D3;
2830 set_pin_power_state(codec, 0x17, &parm);
2831 set_pin_power_state(codec, 0x16, &parm);
2832 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
2833 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
2834 imux_is_smixer ? AC_PWRST_D0 : parm);
2835 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2836 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
2837}
2838
Harald Welted949cac2008-09-09 15:56:01 +08002839static int patch_vt1702(struct hda_codec *codec)
2840{
2841 struct via_spec *spec;
2842 int err;
Harald Welted949cac2008-09-09 15:56:01 +08002843
2844 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002845 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08002846 if (spec == NULL)
2847 return -ENOMEM;
2848
Takashi Iwai620e2b22011-06-17 17:19:19 +02002849 spec->aa_mix_nid = 0x1a;
2850
Takashi Iwai12daef62011-06-18 17:45:49 +02002851 /* limit AA path volume to 0 dB */
2852 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
2853 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
2854 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2855 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2856 (1 << AC_AMPCAP_MUTE_SHIFT));
2857
Harald Welted949cac2008-09-09 15:56:01 +08002858 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002859 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +08002860 if (err < 0) {
2861 via_free(codec);
2862 return err;
Harald Welted949cac2008-09-09 15:56:01 +08002863 }
2864
Takashi Iwai096a8852011-06-20 12:09:02 +02002865 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
Harald Welte69e52a82008-09-09 15:57:32 +08002866 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08002867
Harald Welted949cac2008-09-09 15:56:01 +08002868 codec->patch_ops = via_patch_ops;
2869
Harald Welte69e52a82008-09-09 15:57:32 +08002870 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08002871#ifdef CONFIG_SND_HDA_POWER_SAVE
2872 spec->loopback.amplist = vt1702_loopbacks;
2873#endif
2874
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002875 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08002876 return 0;
2877}
2878
Lydia Wangeb7188c2009-10-10 19:08:34 +08002879/* Patch for VT1718S */
2880
Takashi Iwai096a8852011-06-20 12:09:02 +02002881static const struct hda_verb vt1718S_init_verbs[] = {
Lydia Wang4ab2d532011-03-24 12:42:03 +08002882 /* Enable MW0 adjust Gain 5 */
2883 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08002884 /* Enable Boost Volume backdoor */
2885 {0x1, 0xf88, 0x8},
Takashi Iwai5d417622011-06-20 11:32:27 +02002886
Lydia Wangeb7188c2009-10-10 19:08:34 +08002887 { }
2888};
2889
2890
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002891static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08002892 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
2893 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2894 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2895 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2896 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2897 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2898 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2899 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2900 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2901 { }
2902};
2903
Lydia Wangeb7188c2009-10-10 19:08:34 +08002904#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002905static const struct hda_amp_list vt1718S_loopbacks[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08002906 { 0x21, HDA_INPUT, 1 },
2907 { 0x21, HDA_INPUT, 2 },
2908 { 0x21, HDA_INPUT, 3 },
2909 { 0x21, HDA_INPUT, 4 },
2910 { } /* end */
2911};
2912#endif
2913
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002914static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
2915{
2916 struct via_spec *spec = codec->spec;
2917 int imux_is_smixer;
2918 unsigned int parm;
2919 /* MUX6 (1eh) = stereo mixer */
2920 imux_is_smixer =
2921 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
2922 /* inputs */
2923 /* PW 5/6/7 (29h/2ah/2bh) */
2924 parm = AC_PWRST_D3;
2925 set_pin_power_state(codec, 0x29, &parm);
2926 set_pin_power_state(codec, 0x2a, &parm);
2927 set_pin_power_state(codec, 0x2b, &parm);
2928 if (imux_is_smixer)
2929 parm = AC_PWRST_D0;
2930 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
2931 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2932 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2933 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2934 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2935
2936 /* outputs */
2937 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
2938 parm = AC_PWRST_D3;
2939 set_pin_power_state(codec, 0x27, &parm);
2940 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
2941 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
2942
2943 /* PW2 (26h), AOW2 (ah) */
2944 parm = AC_PWRST_D3;
2945 set_pin_power_state(codec, 0x26, &parm);
2946 if (spec->smart51_enabled)
2947 set_pin_power_state(codec, 0x2b, &parm);
2948 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
2949
2950 /* PW0 (24h), AOW0 (8h) */
2951 parm = AC_PWRST_D3;
2952 set_pin_power_state(codec, 0x24, &parm);
2953 if (!spec->hp_independent_mode) /* check for redirected HP */
2954 set_pin_power_state(codec, 0x28, &parm);
2955 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
2956 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
2957 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
2958 imux_is_smixer ? AC_PWRST_D0 : parm);
2959
2960 /* PW1 (25h), AOW1 (9h) */
2961 parm = AC_PWRST_D3;
2962 set_pin_power_state(codec, 0x25, &parm);
2963 if (spec->smart51_enabled)
2964 set_pin_power_state(codec, 0x2a, &parm);
2965 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
2966
2967 if (spec->hp_independent_mode) {
2968 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
2969 parm = AC_PWRST_D3;
2970 set_pin_power_state(codec, 0x28, &parm);
2971 snd_hda_codec_write(codec, 0x1b, 0,
2972 AC_VERB_SET_POWER_STATE, parm);
2973 snd_hda_codec_write(codec, 0x34, 0,
2974 AC_VERB_SET_POWER_STATE, parm);
2975 snd_hda_codec_write(codec, 0xc, 0,
2976 AC_VERB_SET_POWER_STATE, parm);
2977 }
2978}
2979
Lydia Wangeb7188c2009-10-10 19:08:34 +08002980static int patch_vt1718S(struct hda_codec *codec)
2981{
2982 struct via_spec *spec;
2983 int err;
2984
2985 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002986 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08002987 if (spec == NULL)
2988 return -ENOMEM;
2989
Takashi Iwai620e2b22011-06-17 17:19:19 +02002990 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002991 override_mic_boost(codec, 0x2b, 0, 3, 40);
2992 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02002993
Lydia Wangeb7188c2009-10-10 19:08:34 +08002994 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002995 err = via_parse_auto_config(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08002996 if (err < 0) {
2997 via_free(codec);
2998 return err;
Lydia Wangeb7188c2009-10-10 19:08:34 +08002999 }
3000
Takashi Iwai096a8852011-06-20 12:09:02 +02003001 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003002 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
3003
Lydia Wangeb7188c2009-10-10 19:08:34 +08003004 codec->patch_ops = via_patch_ops;
3005
Stephen Rothwell0f483272009-10-12 15:56:17 +11003006 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003007
3008#ifdef CONFIG_SND_HDA_POWER_SAVE
3009 spec->loopback.amplist = vt1718S_loopbacks;
3010#endif
3011
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003012 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3013
Lydia Wangeb7188c2009-10-10 19:08:34 +08003014 return 0;
3015}
Lydia Wangf3db4232009-10-10 19:08:41 +08003016
3017/* Patch for VT1716S */
3018
3019static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3020 struct snd_ctl_elem_info *uinfo)
3021{
3022 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3023 uinfo->count = 1;
3024 uinfo->value.integer.min = 0;
3025 uinfo->value.integer.max = 1;
3026 return 0;
3027}
3028
3029static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3030 struct snd_ctl_elem_value *ucontrol)
3031{
3032 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3033 int index = 0;
3034
3035 index = snd_hda_codec_read(codec, 0x26, 0,
3036 AC_VERB_GET_CONNECT_SEL, 0);
3037 if (index != -1)
3038 *ucontrol->value.integer.value = index;
3039
3040 return 0;
3041}
3042
3043static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3044 struct snd_ctl_elem_value *ucontrol)
3045{
3046 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3047 struct via_spec *spec = codec->spec;
3048 int index = *ucontrol->value.integer.value;
3049
3050 snd_hda_codec_write(codec, 0x26, 0,
3051 AC_VERB_SET_CONNECT_SEL, index);
3052 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003053 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003054 return 1;
3055}
3056
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003057static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003058 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3059 {
3060 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3061 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003062 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08003063 .count = 1,
3064 .info = vt1716s_dmic_info,
3065 .get = vt1716s_dmic_get,
3066 .put = vt1716s_dmic_put,
3067 },
3068 {} /* end */
3069};
3070
3071
3072/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003073static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003074 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3075 { } /* end */
3076};
3077
Takashi Iwai096a8852011-06-20 12:09:02 +02003078static const struct hda_verb vt1716S_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003079 /* Enable Boost Volume backdoor */
3080 {0x1, 0xf8a, 0x80},
3081 /* don't bybass mixer */
3082 {0x1, 0xf88, 0xc0},
3083 /* Enable mono output */
3084 {0x1, 0xf90, 0x08},
3085 { }
3086};
3087
3088
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003089static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003090 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3091 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3092 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3093 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3094 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3095 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
3096 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
3097 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3098 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3099 { }
3100};
3101
Lydia Wangf3db4232009-10-10 19:08:41 +08003102#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003103static const struct hda_amp_list vt1716S_loopbacks[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003104 { 0x16, HDA_INPUT, 1 },
3105 { 0x16, HDA_INPUT, 2 },
3106 { 0x16, HDA_INPUT, 3 },
3107 { 0x16, HDA_INPUT, 4 },
3108 { } /* end */
3109};
3110#endif
3111
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003112static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3113{
3114 struct via_spec *spec = codec->spec;
3115 int imux_is_smixer;
3116 unsigned int parm;
3117 unsigned int mono_out, present;
3118 /* SW0 (17h) = stereo mixer */
3119 imux_is_smixer =
3120 (snd_hda_codec_read(codec, 0x17, 0,
3121 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3122 /* inputs */
3123 /* PW 1/2/5 (1ah/1bh/1eh) */
3124 parm = AC_PWRST_D3;
3125 set_pin_power_state(codec, 0x1a, &parm);
3126 set_pin_power_state(codec, 0x1b, &parm);
3127 set_pin_power_state(codec, 0x1e, &parm);
3128 if (imux_is_smixer)
3129 parm = AC_PWRST_D0;
3130 /* SW0 (17h), AIW0(13h) */
3131 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3132 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3133
3134 parm = AC_PWRST_D3;
3135 set_pin_power_state(codec, 0x1e, &parm);
3136 /* PW11 (22h) */
3137 if (spec->dmic_enabled)
3138 set_pin_power_state(codec, 0x22, &parm);
3139 else
3140 snd_hda_codec_write(codec, 0x22, 0,
3141 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3142
3143 /* SW2(26h), AIW1(14h) */
3144 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3145 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3146
3147 /* outputs */
3148 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3149 parm = AC_PWRST_D3;
3150 set_pin_power_state(codec, 0x19, &parm);
3151 /* Smart 5.1 PW2(1bh) */
3152 if (spec->smart51_enabled)
3153 set_pin_power_state(codec, 0x1b, &parm);
3154 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3155 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3156
3157 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3158 parm = AC_PWRST_D3;
3159 set_pin_power_state(codec, 0x23, &parm);
3160 /* Smart 5.1 PW1(1ah) */
3161 if (spec->smart51_enabled)
3162 set_pin_power_state(codec, 0x1a, &parm);
3163 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3164
3165 /* Smart 5.1 PW5(1eh) */
3166 if (spec->smart51_enabled)
3167 set_pin_power_state(codec, 0x1e, &parm);
3168 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3169
3170 /* Mono out */
3171 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3172 present = snd_hda_jack_detect(codec, 0x1c);
3173
3174 if (present)
3175 mono_out = 0;
3176 else {
3177 present = snd_hda_jack_detect(codec, 0x1d);
3178 if (!spec->hp_independent_mode && present)
3179 mono_out = 0;
3180 else
3181 mono_out = 1;
3182 }
3183 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3184 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3185 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3186 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3187
3188 /* PW 3/4 (1ch/1dh) */
3189 parm = AC_PWRST_D3;
3190 set_pin_power_state(codec, 0x1c, &parm);
3191 set_pin_power_state(codec, 0x1d, &parm);
3192 /* HP Independent Mode, power on AOW3 */
3193 if (spec->hp_independent_mode)
3194 snd_hda_codec_write(codec, 0x25, 0,
3195 AC_VERB_SET_POWER_STATE, parm);
3196
3197 /* force to D0 for internal Speaker */
3198 /* MW0 (16h), AOW0 (10h) */
3199 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3200 imux_is_smixer ? AC_PWRST_D0 : parm);
3201 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3202 mono_out ? AC_PWRST_D0 : parm);
3203}
3204
Lydia Wangf3db4232009-10-10 19:08:41 +08003205static int patch_vt1716S(struct hda_codec *codec)
3206{
3207 struct via_spec *spec;
3208 int err;
3209
3210 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003211 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003212 if (spec == NULL)
3213 return -ENOMEM;
3214
Takashi Iwai620e2b22011-06-17 17:19:19 +02003215 spec->aa_mix_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003216 override_mic_boost(codec, 0x1a, 0, 3, 40);
3217 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003218
Lydia Wangf3db4232009-10-10 19:08:41 +08003219 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003220 err = via_parse_auto_config(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003221 if (err < 0) {
3222 via_free(codec);
3223 return err;
Lydia Wangf3db4232009-10-10 19:08:41 +08003224 }
3225
Takashi Iwai096a8852011-06-20 12:09:02 +02003226 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
Lydia Wangf3db4232009-10-10 19:08:41 +08003227 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
3228
Lydia Wangf3db4232009-10-10 19:08:41 +08003229 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3230 spec->num_mixers++;
3231
3232 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3233
3234 codec->patch_ops = via_patch_ops;
3235
Stephen Rothwell0f483272009-10-12 15:56:17 +11003236 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangf3db4232009-10-10 19:08:41 +08003237
3238#ifdef CONFIG_SND_HDA_POWER_SAVE
3239 spec->loopback.amplist = vt1716S_loopbacks;
3240#endif
3241
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003242 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08003243 return 0;
3244}
Lydia Wang25eaba22009-10-10 19:08:43 +08003245
3246/* for vt2002P */
3247
Takashi Iwai096a8852011-06-20 12:09:02 +02003248static const struct hda_verb vt2002P_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08003249 /* Class-D speaker related verbs */
3250 {0x1, 0xfe0, 0x4},
3251 {0x1, 0xfe9, 0x80},
3252 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08003253 /* Enable Boost Volume backdoor */
3254 {0x1, 0xfb9, 0x24},
Lydia Wang25eaba22009-10-10 19:08:43 +08003255 /* Enable AOW0 to MW9 */
3256 {0x1, 0xfb8, 0x88},
3257 { }
3258};
Takashi Iwai096a8852011-06-20 12:09:02 +02003259static const struct hda_verb vt1802_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08003260 /* Enable Boost Volume backdoor */
3261 {0x1, 0xfb9, 0x24},
Lydia Wang118909562011-03-23 17:57:34 +08003262 /* Enable AOW0 to MW9 */
3263 {0x1, 0xfb8, 0x88},
3264 { }
3265};
Lydia Wang25eaba22009-10-10 19:08:43 +08003266
3267
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003268static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08003269 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
3270 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
3271 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
3272 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
3273 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3274 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3275 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3276 { }
3277};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003278static const struct hda_verb vt1802_uniwill_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08003279 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
3280 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
3281 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
3282 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
3283 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3284 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3285 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3286 { }
3287};
Lydia Wang25eaba22009-10-10 19:08:43 +08003288
Lydia Wang25eaba22009-10-10 19:08:43 +08003289#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003290static const struct hda_amp_list vt2002P_loopbacks[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08003291 { 0x21, HDA_INPUT, 0 },
3292 { 0x21, HDA_INPUT, 1 },
3293 { 0x21, HDA_INPUT, 2 },
3294 { } /* end */
3295};
3296#endif
3297
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003298static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3299{
3300 struct via_spec *spec = codec->spec;
3301 int imux_is_smixer;
3302 unsigned int parm;
3303 unsigned int present;
3304 /* MUX9 (1eh) = stereo mixer */
3305 imux_is_smixer =
3306 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3307 /* inputs */
3308 /* PW 5/6/7 (29h/2ah/2bh) */
3309 parm = AC_PWRST_D3;
3310 set_pin_power_state(codec, 0x29, &parm);
3311 set_pin_power_state(codec, 0x2a, &parm);
3312 set_pin_power_state(codec, 0x2b, &parm);
3313 parm = AC_PWRST_D0;
3314 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3315 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3316 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3317 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3318 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3319
3320 /* outputs */
3321 /* AOW0 (8h)*/
3322 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3323
Lydia Wang118909562011-03-23 17:57:34 +08003324 if (spec->codec_type == VT1802) {
3325 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3326 parm = AC_PWRST_D3;
3327 set_pin_power_state(codec, 0x28, &parm);
3328 snd_hda_codec_write(codec, 0x18, 0,
3329 AC_VERB_SET_POWER_STATE, parm);
3330 snd_hda_codec_write(codec, 0x38, 0,
3331 AC_VERB_SET_POWER_STATE, parm);
3332 } else {
3333 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3334 parm = AC_PWRST_D3;
3335 set_pin_power_state(codec, 0x26, &parm);
3336 snd_hda_codec_write(codec, 0x1c, 0,
3337 AC_VERB_SET_POWER_STATE, parm);
3338 snd_hda_codec_write(codec, 0x37, 0,
3339 AC_VERB_SET_POWER_STATE, parm);
3340 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003341
Lydia Wang118909562011-03-23 17:57:34 +08003342 if (spec->codec_type == VT1802) {
3343 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3344 parm = AC_PWRST_D3;
3345 set_pin_power_state(codec, 0x25, &parm);
3346 snd_hda_codec_write(codec, 0x15, 0,
3347 AC_VERB_SET_POWER_STATE, parm);
3348 snd_hda_codec_write(codec, 0x35, 0,
3349 AC_VERB_SET_POWER_STATE, parm);
3350 } else {
3351 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3352 parm = AC_PWRST_D3;
3353 set_pin_power_state(codec, 0x25, &parm);
3354 snd_hda_codec_write(codec, 0x19, 0,
3355 AC_VERB_SET_POWER_STATE, parm);
3356 snd_hda_codec_write(codec, 0x35, 0,
3357 AC_VERB_SET_POWER_STATE, parm);
3358 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003359
3360 if (spec->hp_independent_mode)
3361 snd_hda_codec_write(codec, 0x9, 0,
3362 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3363
3364 /* Class-D */
3365 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3366 present = snd_hda_jack_detect(codec, 0x25);
3367
3368 parm = AC_PWRST_D3;
3369 set_pin_power_state(codec, 0x24, &parm);
3370 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08003371 if (spec->codec_type == VT1802)
3372 snd_hda_codec_write(codec, 0x14, 0,
3373 AC_VERB_SET_POWER_STATE, parm);
3374 else
3375 snd_hda_codec_write(codec, 0x18, 0,
3376 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003377 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3378
3379 /* Mono Out */
3380 present = snd_hda_jack_detect(codec, 0x26);
3381
3382 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08003383 if (spec->codec_type == VT1802) {
3384 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3385 snd_hda_codec_write(codec, 0x33, 0,
3386 AC_VERB_SET_POWER_STATE, parm);
3387 snd_hda_codec_write(codec, 0x1c, 0,
3388 AC_VERB_SET_POWER_STATE, parm);
3389 snd_hda_codec_write(codec, 0x3c, 0,
3390 AC_VERB_SET_POWER_STATE, parm);
3391 } else {
3392 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3393 snd_hda_codec_write(codec, 0x31, 0,
3394 AC_VERB_SET_POWER_STATE, parm);
3395 snd_hda_codec_write(codec, 0x17, 0,
3396 AC_VERB_SET_POWER_STATE, parm);
3397 snd_hda_codec_write(codec, 0x3b, 0,
3398 AC_VERB_SET_POWER_STATE, parm);
3399 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003400 /* MW9 (21h) */
3401 if (imux_is_smixer || !is_aa_path_mute(codec))
3402 snd_hda_codec_write(codec, 0x21, 0,
3403 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3404 else
3405 snd_hda_codec_write(codec, 0x21, 0,
3406 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3407}
Lydia Wang25eaba22009-10-10 19:08:43 +08003408
3409/* patch for vt2002P */
3410static int patch_vt2002P(struct hda_codec *codec)
3411{
3412 struct via_spec *spec;
3413 int err;
3414
3415 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003416 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08003417 if (spec == NULL)
3418 return -ENOMEM;
3419
Takashi Iwai620e2b22011-06-17 17:19:19 +02003420 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003421 override_mic_boost(codec, 0x2b, 0, 3, 40);
3422 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003423
Lydia Wang25eaba22009-10-10 19:08:43 +08003424 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003425 err = via_parse_auto_config(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08003426 if (err < 0) {
3427 via_free(codec);
3428 return err;
Lydia Wang25eaba22009-10-10 19:08:43 +08003429 }
3430
Lydia Wang118909562011-03-23 17:57:34 +08003431 if (spec->codec_type == VT1802)
3432 spec->init_verbs[spec->num_iverbs++] =
Takashi Iwai096a8852011-06-20 12:09:02 +02003433 vt1802_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08003434 else
3435 spec->init_verbs[spec->num_iverbs++] =
Takashi Iwai096a8852011-06-20 12:09:02 +02003436 vt2002P_init_verbs;
Lydia Wang25eaba22009-10-10 19:08:43 +08003437
Lydia Wang118909562011-03-23 17:57:34 +08003438 if (spec->codec_type == VT1802)
3439 spec->init_verbs[spec->num_iverbs++] =
3440 vt1802_uniwill_init_verbs;
3441 else
3442 spec->init_verbs[spec->num_iverbs++] =
3443 vt2002P_uniwill_init_verbs;
3444
Lydia Wang25eaba22009-10-10 19:08:43 +08003445 codec->patch_ops = via_patch_ops;
3446
Stephen Rothwell0f483272009-10-12 15:56:17 +11003447 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wang25eaba22009-10-10 19:08:43 +08003448
3449#ifdef CONFIG_SND_HDA_POWER_SAVE
3450 spec->loopback.amplist = vt2002P_loopbacks;
3451#endif
3452
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003453 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08003454 return 0;
3455}
Lydia Wangab6734e2009-10-10 19:08:46 +08003456
3457/* for vt1812 */
3458
Takashi Iwai096a8852011-06-20 12:09:02 +02003459static const struct hda_verb vt1812_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08003460 /* Enable Boost Volume backdoor */
3461 {0x1, 0xfb9, 0x24},
Lydia Wangab6734e2009-10-10 19:08:46 +08003462 /* Enable AOW0 to MW9 */
3463 {0x1, 0xfb8, 0xa8},
3464 { }
3465};
3466
3467
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003468static const struct hda_verb vt1812_uniwill_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08003469 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
3470 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
3471 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
3472 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
3473 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
3474 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3475 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3476 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3477 { }
3478};
3479
Lydia Wangab6734e2009-10-10 19:08:46 +08003480#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003481static const struct hda_amp_list vt1812_loopbacks[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08003482 { 0x21, HDA_INPUT, 0 },
3483 { 0x21, HDA_INPUT, 1 },
3484 { 0x21, HDA_INPUT, 2 },
3485 { } /* end */
3486};
3487#endif
3488
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003489static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3490{
3491 struct via_spec *spec = codec->spec;
3492 int imux_is_smixer =
3493 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3494 unsigned int parm;
3495 unsigned int present;
3496 /* MUX10 (1eh) = stereo mixer */
3497 imux_is_smixer =
3498 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3499 /* inputs */
3500 /* PW 5/6/7 (29h/2ah/2bh) */
3501 parm = AC_PWRST_D3;
3502 set_pin_power_state(codec, 0x29, &parm);
3503 set_pin_power_state(codec, 0x2a, &parm);
3504 set_pin_power_state(codec, 0x2b, &parm);
3505 parm = AC_PWRST_D0;
3506 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3507 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3508 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3509 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3510 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3511
3512 /* outputs */
3513 /* AOW0 (8h)*/
3514 snd_hda_codec_write(codec, 0x8, 0,
3515 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3516
3517 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3518 parm = AC_PWRST_D3;
3519 set_pin_power_state(codec, 0x28, &parm);
3520 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3521 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3522
3523 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3524 parm = AC_PWRST_D3;
3525 set_pin_power_state(codec, 0x25, &parm);
3526 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3527 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3528 if (spec->hp_independent_mode)
3529 snd_hda_codec_write(codec, 0x9, 0,
3530 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3531
3532 /* Internal Speaker */
3533 /* PW0 (24h), MW0(14h), MUX0(34h) */
3534 present = snd_hda_jack_detect(codec, 0x25);
3535
3536 parm = AC_PWRST_D3;
3537 set_pin_power_state(codec, 0x24, &parm);
3538 if (present) {
3539 snd_hda_codec_write(codec, 0x14, 0,
3540 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3541 snd_hda_codec_write(codec, 0x34, 0,
3542 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3543 } else {
3544 snd_hda_codec_write(codec, 0x14, 0,
3545 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3546 snd_hda_codec_write(codec, 0x34, 0,
3547 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3548 }
3549
3550
3551 /* Mono Out */
3552 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3553 present = snd_hda_jack_detect(codec, 0x28);
3554
3555 parm = AC_PWRST_D3;
3556 set_pin_power_state(codec, 0x31, &parm);
3557 if (present) {
3558 snd_hda_codec_write(codec, 0x1c, 0,
3559 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3560 snd_hda_codec_write(codec, 0x3c, 0,
3561 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3562 snd_hda_codec_write(codec, 0x3e, 0,
3563 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3564 } else {
3565 snd_hda_codec_write(codec, 0x1c, 0,
3566 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3567 snd_hda_codec_write(codec, 0x3c, 0,
3568 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3569 snd_hda_codec_write(codec, 0x3e, 0,
3570 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3571 }
3572
3573 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3574 parm = AC_PWRST_D3;
3575 set_pin_power_state(codec, 0x33, &parm);
3576 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3577 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3578
3579}
Lydia Wangab6734e2009-10-10 19:08:46 +08003580
3581/* patch for vt1812 */
3582static int patch_vt1812(struct hda_codec *codec)
3583{
3584 struct via_spec *spec;
3585 int err;
3586
3587 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003588 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08003589 if (spec == NULL)
3590 return -ENOMEM;
3591
Takashi Iwai620e2b22011-06-17 17:19:19 +02003592 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003593 override_mic_boost(codec, 0x2b, 0, 3, 40);
3594 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003595
Lydia Wangab6734e2009-10-10 19:08:46 +08003596 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003597 err = via_parse_auto_config(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08003598 if (err < 0) {
3599 via_free(codec);
3600 return err;
Lydia Wangab6734e2009-10-10 19:08:46 +08003601 }
3602
Takashi Iwai096a8852011-06-20 12:09:02 +02003603 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
Lydia Wangab6734e2009-10-10 19:08:46 +08003604 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
3605
Lydia Wangab6734e2009-10-10 19:08:46 +08003606 codec->patch_ops = via_patch_ops;
3607
Stephen Rothwell0f483272009-10-12 15:56:17 +11003608 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangab6734e2009-10-10 19:08:46 +08003609
3610#ifdef CONFIG_SND_HDA_POWER_SAVE
3611 spec->loopback.amplist = vt1812_loopbacks;
3612#endif
3613
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003614 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08003615 return 0;
3616}
3617
Joseph Chanc577b8a2006-11-29 15:29:40 +01003618/*
3619 * patch entries
3620 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003621static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01003622 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3623 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3624 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3625 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3626 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003627 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003628 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003629 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003630 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003631 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003632 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003633 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003634 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003635 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003636 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003637 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003638 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003639 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003640 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003641 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003642 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003643 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003644 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003645 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003646 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003647 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003648 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003649 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003650 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003651 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003652 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003653 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003654 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003655 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003656 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003657 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003658 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003659 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003660 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003661 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003662 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003663 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003664 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003665 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08003666 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08003667 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003668 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003669 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003670 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003671 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003672 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003673 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003674 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003675 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003676 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003677 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003678 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003679 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003680 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003681 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003682 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003683 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003684 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003685 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003686 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003687 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003688 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003689 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08003690 { .id = 0x11060428, .name = "VT1718S",
3691 .patch = patch_vt1718S},
3692 { .id = 0x11064428, .name = "VT1718S",
3693 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08003694 { .id = 0x11060441, .name = "VT2020",
3695 .patch = patch_vt1718S},
3696 { .id = 0x11064441, .name = "VT1828S",
3697 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08003698 { .id = 0x11060433, .name = "VT1716S",
3699 .patch = patch_vt1716S},
3700 { .id = 0x1106a721, .name = "VT1716S",
3701 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08003702 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3703 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08003704 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08003705 { .id = 0x11060440, .name = "VT1818S",
3706 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08003707 { .id = 0x11060446, .name = "VT1802",
3708 .patch = patch_vt2002P},
3709 { .id = 0x11068446, .name = "VT1802",
3710 .patch = patch_vt2002P},
Joseph Chanc577b8a2006-11-29 15:29:40 +01003711 {} /* terminator */
3712};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003713
3714MODULE_ALIAS("snd-hda-codec-id:1106*");
3715
3716static struct hda_codec_preset_list via_list = {
3717 .preset = snd_hda_preset_via,
3718 .owner = THIS_MODULE,
3719};
3720
3721MODULE_LICENSE("GPL");
3722MODULE_DESCRIPTION("VIA HD-audio codec");
3723
3724static int __init patch_via_init(void)
3725{
3726 return snd_hda_add_codec_preset(&via_list);
3727}
3728
3729static void __exit patch_via_exit(void)
3730{
3731 snd_hda_delete_codec_preset(&via_list);
3732}
3733
3734module_init(patch_via_init)
3735module_exit(patch_via_exit)