blob: eade21c3e0b1b824e0dd7692e58373ebc63257cc [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>
Paul Gortmakerda155d52011-07-15 12:38:28 -040052#include <linux/module.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010053#include <sound/core.h>
Harald Welte0aa62ae2008-09-09 15:58:27 +080054#include <sound/asoundef.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010055#include "hda_codec.h"
56#include "hda_local.h"
Takashi Iwai128bc4b2012-05-07 17:42:31 +020057#include "hda_auto_parser.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020058#include "hda_jack.h"
Takashi Iwaib3f60082013-01-07 12:27:36 +010059#include "hda_generic.h"
Joseph Chanc577b8a2006-11-29 15:29:40 +010060
Joseph Chanc577b8a2006-11-29 15:29:40 +010061/* Pin Widget NID */
Harald Welted949cac2008-09-09 15:56:01 +080062#define VT1708_HP_PIN_NID 0x20
63#define VT1708_CD_PIN_NID 0x24
Joseph Chanc577b8a2006-11-29 15:29:40 +010064
Harald Welted7426322008-09-15 22:43:23 +080065enum VIA_HDA_CODEC {
66 UNKNOWN = -1,
67 VT1708,
68 VT1709_10CH,
69 VT1709_6CH,
70 VT1708B_8CH,
71 VT1708B_4CH,
72 VT1708S,
Lydia Wang518bf3b2009-10-10 19:07:29 +080073 VT1708BCE,
Harald Welted7426322008-09-15 22:43:23 +080074 VT1702,
Lydia Wangeb7188c2009-10-10 19:08:34 +080075 VT1718S,
Lydia Wangf3db4232009-10-10 19:08:41 +080076 VT1716S,
Lydia Wang25eaba22009-10-10 19:08:43 +080077 VT2002P,
Lydia Wangab6734e2009-10-10 19:08:46 +080078 VT1812,
Lydia Wang118909562011-03-23 17:57:34 +080079 VT1802,
Lydia Wang43737e02012-12-10 18:28:11 +080080 VT1705CF,
Lydia Wang6121b842012-12-10 19:03:26 +080081 VT1808,
Harald Welted7426322008-09-15 22:43:23 +080082 CODEC_TYPES,
83};
84
Lydia Wang118909562011-03-23 17:57:34 +080085#define VT2002P_COMPATIBLE(spec) \
86 ((spec)->codec_type == VT2002P ||\
87 (spec)->codec_type == VT1812 ||\
88 (spec)->codec_type == VT1802)
89
Lydia Wang1f2e99f2009-10-10 19:08:17 +080090struct via_spec {
Takashi Iwaib3f60082013-01-07 12:27:36 +010091 struct hda_gen_spec gen;
92
Lydia Wang1f2e99f2009-10-10 19:08:17 +080093 /* codec parameterization */
Takashi Iwai90dd48a2011-05-02 12:38:19 +020094 const struct snd_kcontrol_new *mixers[6];
Lydia Wang1f2e99f2009-10-10 19:08:17 +080095 unsigned int num_mixers;
96
Takashi Iwai90dd48a2011-05-02 12:38:19 +020097 const struct hda_verb *init_verbs[5];
Lydia Wang1f2e99f2009-10-10 19:08:17 +080098 unsigned int num_iverbs;
99
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800100 /* HP mode source */
Lydia Wangf3db4232009-10-10 19:08:41 +0800101 unsigned int dmic_enabled;
Takashi Iwai24088a52011-06-17 16:59:21 +0200102 unsigned int no_pin_power_ctl;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800103 enum VIA_HDA_CODEC codec_type;
104
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100105 /* analog low-power control */
106 bool alc_mode;
107
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800108 /* work to check hp jack state */
Takashi Iwai187d3332011-11-24 16:33:09 +0100109 int hp_work_active;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200110 int vt1708_jack_detect;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800111
112 void (*set_widgets_power_state)(struct hda_codec *codec);
Lydia Wang43737e02012-12-10 18:28:11 +0800113 unsigned int dac_stream_tag[4];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800114};
115
Lydia Wang0341ccd2011-03-22 16:25:03 +0800116static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100117static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
118 struct hda_codec *codec,
119 struct snd_pcm_substream *substream,
120 int action);
121static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl);
122
123static struct via_spec *via_new_spec(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100124{
125 struct via_spec *spec;
126
127 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
128 if (spec == NULL)
129 return NULL;
130
131 codec->spec = spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100132 snd_hda_gen_spec_init(&spec->gen);
Lydia Wang0341ccd2011-03-22 16:25:03 +0800133 spec->codec_type = get_codec_type(codec);
134 /* VT1708BCE & VT1708S are almost same */
135 if (spec->codec_type == VT1708BCE)
136 spec->codec_type = VT1708S;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100137 spec->no_pin_power_ctl = 1;
138 spec->gen.pcm_playback_hook = via_playback_pcm_hook;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100139 return spec;
140}
141
Lydia Wang744ff5f2009-10-10 19:07:26 +0800142static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800143{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800144 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800145 u16 ven_id = vendor_id >> 16;
146 u16 dev_id = vendor_id & 0xffff;
147 enum VIA_HDA_CODEC codec_type;
148
149 /* get codec type */
150 if (ven_id != 0x1106)
151 codec_type = UNKNOWN;
152 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
153 codec_type = VT1708;
154 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
155 codec_type = VT1709_10CH;
156 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
157 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800158 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800159 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800160 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
161 codec_type = VT1708BCE;
162 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800163 codec_type = VT1708B_4CH;
164 else if ((dev_id & 0xfff) == 0x397
165 && (dev_id >> 12) < 8)
166 codec_type = VT1708S;
167 else if ((dev_id & 0xfff) == 0x398
168 && (dev_id >> 12) < 8)
169 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800170 else if ((dev_id & 0xfff) == 0x428
171 && (dev_id >> 12) < 8)
172 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800173 else if (dev_id == 0x0433 || dev_id == 0xa721)
174 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800175 else if (dev_id == 0x0441 || dev_id == 0x4441)
176 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800177 else if (dev_id == 0x0438 || dev_id == 0x4438)
178 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800179 else if (dev_id == 0x0448)
180 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800181 else if (dev_id == 0x0440)
182 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800183 else if ((dev_id & 0xfff) == 0x446)
184 codec_type = VT1802;
Lydia Wang43737e02012-12-10 18:28:11 +0800185 else if (dev_id == 0x4760)
186 codec_type = VT1705CF;
Lydia Wang6121b842012-12-10 19:03:26 +0800187 else if (dev_id == 0x4761 || dev_id == 0x4762)
188 codec_type = VT1808;
Harald Welted7426322008-09-15 22:43:23 +0800189 else
190 codec_type = UNKNOWN;
191 return codec_type;
192};
193
Takashi Iwaiada509e2011-06-20 15:40:19 +0200194static void analog_low_current_mode(struct hda_codec *codec);
195static bool is_aa_path_mute(struct hda_codec *codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800196
Takashi Iwai187d3332011-11-24 16:33:09 +0100197#define hp_detect_with_aa(codec) \
198 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
199 !is_aa_path_mute(codec))
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800200
Takashi Iwaib3f60082013-01-07 12:27:36 +0100201static void vt1708_stop_hp_work(struct hda_codec *codec)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800202{
Takashi Iwaib3f60082013-01-07 12:27:36 +0100203 struct via_spec *spec = codec->spec;
204 if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800205 return;
Takashi Iwai187d3332011-11-24 16:33:09 +0100206 if (spec->hp_work_active) {
Takashi Iwaib3f60082013-01-07 12:27:36 +0100207 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 1);
208 cancel_delayed_work_sync(&codec->jackpoll_work);
209 spec->hp_work_active = false;
210 codec->jackpoll_interval = 0;
Takashi Iwai187d3332011-11-24 16:33:09 +0100211 }
212}
213
Takashi Iwaib3f60082013-01-07 12:27:36 +0100214static void vt1708_update_hp_work(struct hda_codec *codec)
Takashi Iwai187d3332011-11-24 16:33:09 +0100215{
Takashi Iwaib3f60082013-01-07 12:27:36 +0100216 struct via_spec *spec = codec->spec;
217 if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800218 return;
Takashi Iwai187d3332011-11-24 16:33:09 +0100219 if (spec->vt1708_jack_detect &&
Takashi Iwaib3f60082013-01-07 12:27:36 +0100220 (spec->gen.active_streams || hp_detect_with_aa(codec))) {
Takashi Iwai187d3332011-11-24 16:33:09 +0100221 if (!spec->hp_work_active) {
Takashi Iwaib3f60082013-01-07 12:27:36 +0100222 codec->jackpoll_interval = msecs_to_jiffies(100);
223 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0);
224 queue_delayed_work(codec->bus->workq,
225 &codec->jackpoll_work, 0);
226 spec->hp_work_active = true;
Takashi Iwai187d3332011-11-24 16:33:09 +0100227 }
Takashi Iwaib3f60082013-01-07 12:27:36 +0100228 } else if (!hp_detect_with_aa(codec))
229 vt1708_stop_hp_work(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800230}
Lydia Wangf5271102009-10-10 19:07:35 +0800231
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800232static void set_widgets_power_state(struct hda_codec *codec)
233{
234 struct via_spec *spec = codec->spec;
235 if (spec->set_widgets_power_state)
236 spec->set_widgets_power_state(codec);
237}
Lydia Wang25eaba22009-10-10 19:08:43 +0800238
Takashi Iwai054d8672012-01-24 12:25:50 +0100239static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
240 unsigned int parm)
241{
242 if (snd_hda_codec_read(codec, nid, 0,
243 AC_VERB_GET_POWER_STATE, 0) == parm)
244 return;
245 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
246}
247
Lydia Wang43737e02012-12-10 18:28:11 +0800248static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
249 unsigned int parm, unsigned int index)
250{
251 struct via_spec *spec = codec->spec;
252 unsigned int format;
253 if (snd_hda_codec_read(codec, nid, 0,
254 AC_VERB_GET_POWER_STATE, 0) == parm)
255 return;
256 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
257 if (format && (spec->dac_stream_tag[index] != format))
258 spec->dac_stream_tag[index] = format;
259
260 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
261 if (parm == AC_PWRST_D0) {
262 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
263 if (!format && (spec->dac_stream_tag[index] != format))
264 snd_hda_codec_write(codec, nid, 0,
265 AC_VERB_SET_CHANNEL_STREAMID,
266 spec->dac_stream_tag[index]);
267 }
268}
269
Takashi Iwaib3f60082013-01-07 12:27:36 +0100270static bool smart51_enabled(struct hda_codec *codec)
271{
272 struct via_spec *spec = codec->spec;
273 return spec->gen.ext_channel_count > 2;
274}
275
276static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
277{
278 struct via_spec *spec = codec->spec;
279 int i;
280
281 for (i = 0; i < spec->gen.multi_ios; i++)
282 if (spec->gen.multi_io[i].pin == pin)
283 return true;
284 return false;
285}
286
Lydia Wangf5271102009-10-10 19:07:35 +0800287static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
288 unsigned int *affected_parm)
289{
290 unsigned parm;
291 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
292 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
293 >> AC_DEFCFG_MISC_SHIFT
294 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800295 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200296 unsigned present = 0;
297
298 no_presence |= spec->no_pin_power_ctl;
299 if (!no_presence)
300 present = snd_hda_jack_detect(codec, nid);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100301 if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
Lydia Wang1564b282009-10-10 19:07:52 +0800302 || ((no_presence || present)
303 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800304 *affected_parm = AC_PWRST_D0; /* if it's connected */
305 parm = AC_PWRST_D0;
306 } else
307 parm = AC_PWRST_D3;
308
Takashi Iwai054d8672012-01-24 12:25:50 +0100309 update_power_state(codec, nid, parm);
Lydia Wangf5271102009-10-10 19:07:35 +0800310}
311
Takashi Iwai24088a52011-06-17 16:59:21 +0200312static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
313 struct snd_ctl_elem_info *uinfo)
314{
Takashi Iwaidda415d2012-11-30 18:34:38 +0100315 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai24088a52011-06-17 16:59:21 +0200316}
317
318static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
319 struct snd_ctl_elem_value *ucontrol)
320{
321 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
322 struct via_spec *spec = codec->spec;
323 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
324 return 0;
325}
326
327static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
328 struct snd_ctl_elem_value *ucontrol)
329{
330 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
331 struct via_spec *spec = codec->spec;
332 unsigned int val = !ucontrol->value.enumerated.item[0];
333
334 if (val == spec->no_pin_power_ctl)
335 return 0;
336 spec->no_pin_power_ctl = val;
337 set_widgets_power_state(codec);
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100338 analog_low_current_mode(codec);
Takashi Iwai24088a52011-06-17 16:59:21 +0200339 return 1;
340}
341
Takashi Iwaib3f60082013-01-07 12:27:36 +0100342static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
343 {
Takashi Iwai24088a52011-06-17 16:59:21 +0200344 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
345 .name = "Dynamic Power-Control",
346 .info = via_pin_power_ctl_info,
347 .get = via_pin_power_ctl_get,
348 .put = via_pin_power_ctl_put,
Takashi Iwaib3f60082013-01-07 12:27:36 +0100349 },
350 {} /* terminator */
Takashi Iwai24088a52011-06-17 16:59:21 +0200351};
352
353
Takashi Iwaiada509e2011-06-20 15:40:19 +0200354/* check AA path's mute status */
355static bool is_aa_path_mute(struct hda_codec *codec)
Lydia Wangf5271102009-10-10 19:07:35 +0800356{
Lydia Wangf5271102009-10-10 19:07:35 +0800357 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +0200358 const struct hda_amp_list *p;
359 int i, ch, v;
360
Takashi Iwaib3f60082013-01-07 12:27:36 +0100361 for (i = 0; i < spec->gen.num_loopbacks; i++) {
362 p = &spec->gen.loopback_list[i];
Takashi Iwaiada509e2011-06-20 15:40:19 +0200363 for (ch = 0; ch < 2; ch++) {
364 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
365 p->idx);
366 if (!(v & HDA_AMP_MUTE) && v > 0)
367 return false;
Lydia Wangf5271102009-10-10 19:07:35 +0800368 }
369 }
Takashi Iwaiada509e2011-06-20 15:40:19 +0200370 return true;
Lydia Wangf5271102009-10-10 19:07:35 +0800371}
372
373/* enter/exit analog low-current mode */
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100374static void __analog_low_current_mode(struct hda_codec *codec, bool force)
Lydia Wangf5271102009-10-10 19:07:35 +0800375{
376 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +0200377 bool enable;
378 unsigned int verb, parm;
Lydia Wangf5271102009-10-10 19:07:35 +0800379
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100380 if (spec->no_pin_power_ctl)
381 enable = false;
382 else
Takashi Iwaib3f60082013-01-07 12:27:36 +0100383 enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100384 if (enable == spec->alc_mode && !force)
385 return;
386 spec->alc_mode = enable;
Lydia Wangf5271102009-10-10 19:07:35 +0800387
388 /* decide low current mode's verb & parameter */
389 switch (spec->codec_type) {
390 case VT1708B_8CH:
391 case VT1708B_4CH:
392 verb = 0xf70;
393 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
394 break;
395 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +0800396 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +0800397 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +0800398 verb = 0xf73;
399 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
400 break;
401 case VT1702:
402 verb = 0xf73;
403 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
404 break;
Lydia Wang25eaba22009-10-10 19:08:43 +0800405 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +0800406 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +0800407 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +0800408 verb = 0xf93;
409 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
410 break;
Lydia Wang43737e02012-12-10 18:28:11 +0800411 case VT1705CF:
Lydia Wang6121b842012-12-10 19:03:26 +0800412 case VT1808:
Lydia Wang43737e02012-12-10 18:28:11 +0800413 verb = 0xf82;
414 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
415 break;
Lydia Wangf5271102009-10-10 19:07:35 +0800416 default:
417 return; /* other codecs are not supported */
418 }
419 /* send verb */
420 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
421}
422
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100423static void analog_low_current_mode(struct hda_codec *codec)
424{
425 return __analog_low_current_mode(codec, false);
426}
427
Joseph Chanc577b8a2006-11-29 15:29:40 +0100428static int via_build_controls(struct hda_codec *codec)
429{
430 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100431 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100432
Takashi Iwaib3f60082013-01-07 12:27:36 +0100433 err = snd_hda_gen_build_controls(codec);
434 if (err < 0)
435 return err;
436
Takashi Iwai24088a52011-06-17 16:59:21 +0200437 if (spec->set_widgets_power_state)
Takashi Iwaib3f60082013-01-07 12:27:36 +0100438 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
Takashi Iwai24088a52011-06-17 16:59:21 +0200439
Joseph Chanc577b8a2006-11-29 15:29:40 +0100440 for (i = 0; i < spec->num_mixers; i++) {
441 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
442 if (err < 0)
443 return err;
444 }
445
Joseph Chanc577b8a2006-11-29 15:29:40 +0100446 return 0;
447}
448
Takashi Iwaib3f60082013-01-07 12:27:36 +0100449static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
450 struct hda_codec *codec,
451 struct snd_pcm_substream *substream,
452 int action)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100453{
Takashi Iwaib3f60082013-01-07 12:27:36 +0100454 analog_low_current_mode(codec);
455 vt1708_update_hp_work(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100456}
457
458static void via_free(struct hda_codec *codec)
459{
460 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100461
462 if (!spec)
463 return;
464
Takashi Iwaib3f60082013-01-07 12:27:36 +0100465 vt1708_stop_hp_work(codec);
466 snd_hda_gen_spec_free(&spec->gen);
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200467 kfree(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100468}
469
Takashi Iwai2a439522011-07-26 09:52:50 +0200470#ifdef CONFIG_PM
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200471static int via_suspend(struct hda_codec *codec)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800472{
473 struct via_spec *spec = codec->spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100474 vt1708_stop_hp_work(codec);
David Henningsson94c142a2012-08-09 10:56:12 +0200475
476 if (spec->codec_type == VT1802) {
477 /* Fix pop noise on headphones */
478 int i;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100479 for (i = 0; i < spec->gen.autocfg.hp_outs; i++)
480 snd_hda_set_pin_ctl(codec, spec->gen.autocfg.hp_pins[i], 0);
David Henningsson94c142a2012-08-09 10:56:12 +0200481 }
482
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800483 return 0;
484}
485#endif
486
Takashi Iwai83012a72012-08-24 18:38:08 +0200487#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200488static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
489{
490 struct via_spec *spec = codec->spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100491 set_widgets_power_state(codec);
492 analog_low_current_mode(codec);
493 vt1708_update_hp_work(codec);
494 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
Takashi Iwaicb53c622007-08-10 17:21:45 +0200495}
496#endif
497
Joseph Chanc577b8a2006-11-29 15:29:40 +0100498/*
499 */
Takashi Iwai5d417622011-06-20 11:32:27 +0200500
501static int via_init(struct hda_codec *codec);
502
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200503static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100504 .build_controls = via_build_controls,
Takashi Iwaib3f60082013-01-07 12:27:36 +0100505 .build_pcms = snd_hda_gen_build_pcms,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100506 .init = via_init,
507 .free = via_free,
David Henningsson4e2d16d2012-10-08 15:44:14 +0200508 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +0200509#ifdef CONFIG_PM
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800510 .suspend = via_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200511 .check_power_status = via_check_power_status,
512#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +0100513};
514
Takashi Iwai4a796162011-06-17 17:53:38 +0200515
Takashi Iwaib3f60082013-01-07 12:27:36 +0100516static const struct hda_verb vt1708_init_verbs[] = {
517 /* power down jack detect function */
518 {0x1, 0xf81, 0x1},
519 { }
Takashi Iwai3214b962011-07-18 12:49:25 +0200520};
Harald Welte76d9b0d2008-09-09 15:50:37 +0800521static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
522{
523 unsigned int def_conf;
524 unsigned char seqassoc;
525
Takashi Iwai2f334f92009-02-20 14:37:42 +0100526 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +0800527 seqassoc = (unsigned char) get_defcfg_association(def_conf);
528 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +0800529 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
530 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
531 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
532 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +0800533 }
534
535 return;
536}
537
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200538static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800539 struct snd_ctl_elem_value *ucontrol)
540{
541 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
542 struct via_spec *spec = codec->spec;
543
544 if (spec->codec_type != VT1708)
545 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200546 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800547 return 0;
548}
549
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200550static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800551 struct snd_ctl_elem_value *ucontrol)
552{
553 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
554 struct via_spec *spec = codec->spec;
Takashi Iwai187d3332011-11-24 16:33:09 +0100555 int val;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800556
557 if (spec->codec_type != VT1708)
558 return 0;
Takashi Iwai187d3332011-11-24 16:33:09 +0100559 val = !!ucontrol->value.integer.value[0];
560 if (spec->vt1708_jack_detect == val)
561 return 0;
562 spec->vt1708_jack_detect = val;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100563 vt1708_update_hp_work(codec);
Takashi Iwai187d3332011-11-24 16:33:09 +0100564 return 1;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800565}
566
Takashi Iwaib3f60082013-01-07 12:27:36 +0100567static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
568 {
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200569 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
570 .name = "Jack Detect",
571 .count = 1,
572 .info = snd_ctl_boolean_mono_info,
573 .get = vt1708_jack_detect_get,
574 .put = vt1708_jack_detect_put,
Takashi Iwaib3f60082013-01-07 12:27:36 +0100575 },
576 {} /* terminator */
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800577};
578
Takashi Iwaib3f60082013-01-07 12:27:36 +0100579static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
David Henningsson4e2d16d2012-10-08 15:44:14 +0200580{
581 set_widgets_power_state(codec);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100582 snd_hda_gen_hp_automute(codec, tbl);
583}
584
585static void via_line_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
586{
587 set_widgets_power_state(codec);
588 snd_hda_gen_line_automute(codec, tbl);
David Henningsson4e2d16d2012-10-08 15:44:14 +0200589}
590
591static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
592{
593 set_widgets_power_state(codec);
594}
595
Takashi Iwaib3f60082013-01-07 12:27:36 +0100596#define VIA_JACK_EVENT (HDA_GEN_LAST_EVENT + 1)
597
598static void via_set_jack_unsol_events(struct hda_codec *codec)
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200599{
600 struct via_spec *spec = codec->spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100601 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
602 hda_nid_t pin;
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200603 int i;
604
Takashi Iwaib3f60082013-01-07 12:27:36 +0100605 spec->gen.hp_automute_hook = via_hp_automute;
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200606 if (cfg->speaker_pins[0])
Takashi Iwaib3f60082013-01-07 12:27:36 +0100607 spec->gen.line_automute_hook = via_line_automute;
David Henningsson4e2d16d2012-10-08 15:44:14 +0200608
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200609 for (i = 0; i < cfg->line_outs; i++) {
Takashi Iwaib3f60082013-01-07 12:27:36 +0100610 pin = cfg->line_out_pins[i];
611 if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
612 is_jack_detectable(codec, pin))
613 snd_hda_jack_detect_enable_callback(codec, pin,
David Henningsson4e2d16d2012-10-08 15:44:14 +0200614 VIA_JACK_EVENT,
615 via_jack_powerstate_event);
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200616 }
Takashi Iwaib3f60082013-01-07 12:27:36 +0100617
618 for (i = 0; i < cfg->num_inputs; i++) {
619 pin = cfg->line_out_pins[i];
620 if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
621 is_jack_detectable(codec, pin))
622 snd_hda_jack_detect_enable_callback(codec, pin,
623 VIA_JACK_EVENT,
624 via_jack_powerstate_event);
625 }
626}
627
628static int via_parse_auto_config(struct hda_codec *codec)
629{
630 struct via_spec *spec = codec->spec;
631 int err;
632
633 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
634 if (err < 0)
635 return err;
636
637 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
638 if (err < 0)
639 return err;
640
641 via_set_jack_unsol_events(codec);
642 return 0;
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200643}
644
Takashi Iwai5d417622011-06-20 11:32:27 +0200645static int via_init(struct hda_codec *codec)
646{
647 struct via_spec *spec = codec->spec;
648 int i;
649
650 for (i = 0; i < spec->num_iverbs; i++)
651 snd_hda_sequence_write(codec, spec->init_verbs[i]);
652
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100653 /* init power states */
654 set_widgets_power_state(codec);
655 __analog_low_current_mode(codec, true);
656
Takashi Iwaib3f60082013-01-07 12:27:36 +0100657 snd_hda_gen_init(codec);
Lydia Wang118909562011-03-23 17:57:34 +0800658
Takashi Iwaib3f60082013-01-07 12:27:36 +0100659 vt1708_update_hp_work(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +0800660
Joseph Chanc577b8a2006-11-29 15:29:40 +0100661 return 0;
662}
663
Takashi Iwaib3f60082013-01-07 12:27:36 +0100664static int vt1708_build_pcms(struct hda_codec *codec)
Takashi Iwai337b9d02009-07-07 18:18:59 +0200665{
666 struct via_spec *spec = codec->spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100667 int i, err;
Takashi Iwai337b9d02009-07-07 18:18:59 +0200668
Takashi Iwaib3f60082013-01-07 12:27:36 +0100669 err = snd_hda_gen_build_pcms(codec);
670 if (err < 0 || codec->vendor_id != 0x11061708)
671 return err;
672
673 /* We got noisy outputs on the right channel on VT1708 when
674 * 24bit samples are used. Until any workaround is found,
675 * disable the 24bit format, so far.
676 */
677 for (i = 0; i < codec->num_pcms; i++) {
678 struct hda_pcm *info = &spec->gen.pcm_rec[i];
679 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
680 info->pcm_type != HDA_PCM_TYPE_AUDIO)
681 continue;
682 info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats =
683 SNDRV_PCM_FMTBIT_S16_LE;
Takashi Iwai337b9d02009-07-07 18:18:59 +0200684 }
Takashi Iwaib3f60082013-01-07 12:27:36 +0100685
Takashi Iwai1c55d522009-07-08 07:45:46 +0200686 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +0200687}
688
Joseph Chanc577b8a2006-11-29 15:29:40 +0100689static int patch_vt1708(struct hda_codec *codec)
690{
691 struct via_spec *spec;
692 int err;
693
694 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100695 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100696 if (spec == NULL)
697 return -ENOMEM;
698
Takashi Iwaib3f60082013-01-07 12:27:36 +0100699 spec->gen.mixer_nid = 0x17;
700
701 /* set jackpoll_interval while parsing the codec */
702 codec->jackpoll_interval = msecs_to_jiffies(100);
703 spec->vt1708_jack_detect = 1;
704
705 /* don't support the input jack switching due to lack of unsol event */
706 /* (it may work with polling, though, but it needs testing) */
707 spec->gen.suppress_auto_mic = 1;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200708
Takashi Iwai12daef62011-06-18 17:45:49 +0200709 /* Add HP and CD pin config connect bit re-config action */
710 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
711 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
712
Joseph Chanc577b8a2006-11-29 15:29:40 +0100713 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +0200714 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100715 if (err < 0) {
716 via_free(codec);
717 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100718 }
719
Takashi Iwai12daef62011-06-18 17:45:49 +0200720 /* add jack detect on/off control */
Takashi Iwaib3f60082013-01-07 12:27:36 +0100721 spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100722
Lydia Wange322a362011-06-29 13:52:02 +0800723 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
724
Joseph Chanc577b8a2006-11-29 15:29:40 +0100725 codec->patch_ops = via_patch_ops;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100726 codec->patch_ops.build_pcms = vt1708_build_pcms;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100727
Takashi Iwaib3f60082013-01-07 12:27:36 +0100728 /* clear jackpoll_interval again; it's set dynamically */
729 codec->jackpoll_interval = 0;
730
Joseph Chanc577b8a2006-11-29 15:29:40 +0100731 return 0;
732}
733
Takashi Iwaiddd304d2011-06-21 16:33:55 +0200734static int patch_vt1709(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100735{
736 struct via_spec *spec;
737 int err;
738
739 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100740 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100741 if (spec == NULL)
742 return -ENOMEM;
743
Takashi Iwaib3f60082013-01-07 12:27:36 +0100744 spec->gen.mixer_nid = 0x18;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200745
Takashi Iwai12daef62011-06-18 17:45:49 +0200746 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100747 if (err < 0) {
748 via_free(codec);
749 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100750 }
751
Joseph Chanc577b8a2006-11-29 15:29:40 +0100752 codec->patch_ops = via_patch_ops;
753
Josepch Chanf7278fd2007-12-13 16:40:40 +0100754 return 0;
755}
756
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800757static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
758{
759 struct via_spec *spec = codec->spec;
760 int imux_is_smixer;
761 unsigned int parm;
762 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +0800763 if ((spec->codec_type != VT1708B_4CH) &&
764 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800765 is_8ch = 1;
766
767 /* SW0 (17h) = stereo mixer */
768 imux_is_smixer =
769 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
770 == ((spec->codec_type == VT1708S) ? 5 : 0));
771 /* inputs */
772 /* PW 1/2/5 (1ah/1bh/1eh) */
773 parm = AC_PWRST_D3;
774 set_pin_power_state(codec, 0x1a, &parm);
775 set_pin_power_state(codec, 0x1b, &parm);
776 set_pin_power_state(codec, 0x1e, &parm);
777 if (imux_is_smixer)
778 parm = AC_PWRST_D0;
779 /* SW0 (17h), AIW 0/1 (13h/14h) */
Takashi Iwai054d8672012-01-24 12:25:50 +0100780 update_power_state(codec, 0x17, parm);
781 update_power_state(codec, 0x13, parm);
782 update_power_state(codec, 0x14, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800783
784 /* outputs */
785 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
786 parm = AC_PWRST_D3;
787 set_pin_power_state(codec, 0x19, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100788 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800789 set_pin_power_state(codec, 0x1b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +0100790 update_power_state(codec, 0x18, parm);
791 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800792
793 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
794 if (is_8ch) {
795 parm = AC_PWRST_D3;
796 set_pin_power_state(codec, 0x22, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100797 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800798 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +0100799 update_power_state(codec, 0x26, parm);
800 update_power_state(codec, 0x24, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +0800801 } else if (codec->vendor_id == 0x11064397) {
802 /* PW7(23h), SW2(27h), AOW2(25h) */
803 parm = AC_PWRST_D3;
804 set_pin_power_state(codec, 0x23, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100805 if (smart51_enabled(codec))
Lydia Wangbc92df72011-03-23 17:56:05 +0800806 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +0100807 update_power_state(codec, 0x27, parm);
808 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800809 }
810
811 /* PW 3/4/7 (1ch/1dh/23h) */
812 parm = AC_PWRST_D3;
813 /* force to D0 for internal Speaker */
814 set_pin_power_state(codec, 0x1c, &parm);
815 set_pin_power_state(codec, 0x1d, &parm);
816 if (is_8ch)
817 set_pin_power_state(codec, 0x23, &parm);
818
819 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
Takashi Iwai054d8672012-01-24 12:25:50 +0100820 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
821 update_power_state(codec, 0x10, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800822 if (is_8ch) {
Takashi Iwai054d8672012-01-24 12:25:50 +0100823 update_power_state(codec, 0x25, parm);
824 update_power_state(codec, 0x27, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100825 } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
Takashi Iwai054d8672012-01-24 12:25:50 +0100826 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800827}
828
Lydia Wang518bf3b2009-10-10 19:07:29 +0800829static int patch_vt1708S(struct hda_codec *codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +0200830static int patch_vt1708B(struct hda_codec *codec)
Josepch Chanf7278fd2007-12-13 16:40:40 +0100831{
832 struct via_spec *spec;
833 int err;
834
Lydia Wang518bf3b2009-10-10 19:07:29 +0800835 if (get_codec_type(codec) == VT1708BCE)
836 return patch_vt1708S(codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +0200837
Josepch Chanf7278fd2007-12-13 16:40:40 +0100838 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100839 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +0100840 if (spec == NULL)
841 return -ENOMEM;
842
Takashi Iwaib3f60082013-01-07 12:27:36 +0100843 spec->gen.mixer_nid = 0x16;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200844
Josepch Chanf7278fd2007-12-13 16:40:40 +0100845 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +0200846 err = via_parse_auto_config(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +0100847 if (err < 0) {
848 via_free(codec);
849 return err;
Josepch Chanf7278fd2007-12-13 16:40:40 +0100850 }
851
Josepch Chanf7278fd2007-12-13 16:40:40 +0100852 codec->patch_ops = via_patch_ops;
853
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800854 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
855
Josepch Chanf7278fd2007-12-13 16:40:40 +0100856 return 0;
857}
858
Harald Welted949cac2008-09-09 15:56:01 +0800859/* Patch for VT1708S */
Takashi Iwai096a8852011-06-20 12:09:02 +0200860static const struct hda_verb vt1708S_init_verbs[] = {
Harald Welted7426322008-09-15 22:43:23 +0800861 /* Enable Mic Boost Volume backdoor */
862 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +0800863 /* don't bybass mixer */
864 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +0800865 { }
866};
867
Lydia Wang6369bcf2009-10-10 19:08:31 +0800868static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
869 int offset, int num_steps, int step_size)
870{
871 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
872 (offset << AC_AMPCAP_OFFSET_SHIFT) |
873 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
874 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
875 (0 << AC_AMPCAP_MUTE_SHIFT));
876}
877
Harald Welted949cac2008-09-09 15:56:01 +0800878static int patch_vt1708S(struct hda_codec *codec)
879{
880 struct via_spec *spec;
881 int err;
882
883 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100884 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +0800885 if (spec == NULL)
886 return -ENOMEM;
887
Takashi Iwaib3f60082013-01-07 12:27:36 +0100888 spec->gen.mixer_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +0200889 override_mic_boost(codec, 0x1a, 0, 3, 40);
890 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +0200891
Lydia Wang518bf3b2009-10-10 19:07:29 +0800892 /* correct names for VT1708BCE */
893 if (get_codec_type(codec) == VT1708BCE) {
894 kfree(codec->chip_name);
895 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
896 snprintf(codec->bus->card->mixername,
897 sizeof(codec->bus->card->mixername),
898 "%s %s", codec->vendor_name, codec->chip_name);
Lydia Wang970f6302011-03-22 16:25:56 +0800899 }
Lydia Wangbc92df72011-03-23 17:56:05 +0800900 /* correct names for VT1705 */
901 if (codec->vendor_id == 0x11064397) {
902 kfree(codec->chip_name);
903 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
904 snprintf(codec->bus->card->mixername,
905 sizeof(codec->bus->card->mixername),
906 "%s %s", codec->vendor_name, codec->chip_name);
907 }
Takashi Iwaib3f60082013-01-07 12:27:36 +0100908
909 /* automatic parse from the BIOS config */
910 err = via_parse_auto_config(codec);
911 if (err < 0) {
912 via_free(codec);
913 return err;
914 }
915
916 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
917
918 codec->patch_ops = via_patch_ops;
919
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800920 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +0800921 return 0;
922}
923
924/* Patch for VT1702 */
925
Takashi Iwai096a8852011-06-20 12:09:02 +0200926static const struct hda_verb vt1702_init_verbs[] = {
Lydia Wangbc7e7e52009-10-10 19:08:32 +0800927 /* mixer enable */
928 {0x1, 0xF88, 0x3},
929 /* GPIO 0~2 */
930 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +0800931 { }
932};
933
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800934static void set_widgets_power_state_vt1702(struct hda_codec *codec)
935{
936 int imux_is_smixer =
937 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
938 unsigned int parm;
939 /* inputs */
940 /* PW 1/2/5 (14h/15h/18h) */
941 parm = AC_PWRST_D3;
942 set_pin_power_state(codec, 0x14, &parm);
943 set_pin_power_state(codec, 0x15, &parm);
944 set_pin_power_state(codec, 0x18, &parm);
945 if (imux_is_smixer)
946 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
947 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
Takashi Iwai054d8672012-01-24 12:25:50 +0100948 update_power_state(codec, 0x13, parm);
949 update_power_state(codec, 0x12, parm);
950 update_power_state(codec, 0x1f, parm);
951 update_power_state(codec, 0x20, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800952
953 /* outputs */
954 /* PW 3/4 (16h/17h) */
955 parm = AC_PWRST_D3;
956 set_pin_power_state(codec, 0x17, &parm);
957 set_pin_power_state(codec, 0x16, &parm);
958 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
Takashi Iwai054d8672012-01-24 12:25:50 +0100959 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
960 update_power_state(codec, 0x10, parm);
961 update_power_state(codec, 0x1d, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800962}
963
Harald Welted949cac2008-09-09 15:56:01 +0800964static int patch_vt1702(struct hda_codec *codec)
965{
966 struct via_spec *spec;
967 int err;
Harald Welted949cac2008-09-09 15:56:01 +0800968
969 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100970 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +0800971 if (spec == NULL)
972 return -ENOMEM;
973
Takashi Iwaib3f60082013-01-07 12:27:36 +0100974 spec->gen.mixer_nid = 0x1a;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200975
Takashi Iwai12daef62011-06-18 17:45:49 +0200976 /* limit AA path volume to 0 dB */
977 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
978 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
979 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
980 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
981 (1 << AC_AMPCAP_MUTE_SHIFT));
982
Harald Welted949cac2008-09-09 15:56:01 +0800983 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +0200984 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +0800985 if (err < 0) {
986 via_free(codec);
987 return err;
Harald Welted949cac2008-09-09 15:56:01 +0800988 }
989
Takashi Iwai096a8852011-06-20 12:09:02 +0200990 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +0800991
Harald Welted949cac2008-09-09 15:56:01 +0800992 codec->patch_ops = via_patch_ops;
993
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800994 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +0800995 return 0;
996}
997
Lydia Wangeb7188c2009-10-10 19:08:34 +0800998/* Patch for VT1718S */
999
Takashi Iwai096a8852011-06-20 12:09:02 +02001000static const struct hda_verb vt1718S_init_verbs[] = {
Lydia Wang4ab2d532011-03-24 12:42:03 +08001001 /* Enable MW0 adjust Gain 5 */
1002 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08001003 /* Enable Boost Volume backdoor */
1004 {0x1, 0xf88, 0x8},
Takashi Iwai5d417622011-06-20 11:32:27 +02001005
Lydia Wangeb7188c2009-10-10 19:08:34 +08001006 { }
1007};
1008
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001009static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
1010{
1011 struct via_spec *spec = codec->spec;
1012 int imux_is_smixer;
Takashi Iwai61625522012-07-25 13:54:55 +02001013 unsigned int parm, parm2;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001014 /* MUX6 (1eh) = stereo mixer */
1015 imux_is_smixer =
1016 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
1017 /* inputs */
1018 /* PW 5/6/7 (29h/2ah/2bh) */
1019 parm = AC_PWRST_D3;
1020 set_pin_power_state(codec, 0x29, &parm);
1021 set_pin_power_state(codec, 0x2a, &parm);
1022 set_pin_power_state(codec, 0x2b, &parm);
1023 if (imux_is_smixer)
1024 parm = AC_PWRST_D0;
1025 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001026 update_power_state(codec, 0x1e, parm);
1027 update_power_state(codec, 0x1f, parm);
1028 update_power_state(codec, 0x10, parm);
1029 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001030
1031 /* outputs */
1032 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
1033 parm = AC_PWRST_D3;
1034 set_pin_power_state(codec, 0x27, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001035 update_power_state(codec, 0x1a, parm);
Takashi Iwai61625522012-07-25 13:54:55 +02001036 parm2 = parm; /* for pin 0x0b */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001037
1038 /* PW2 (26h), AOW2 (ah) */
1039 parm = AC_PWRST_D3;
1040 set_pin_power_state(codec, 0x26, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001041 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001042 set_pin_power_state(codec, 0x2b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001043 update_power_state(codec, 0xa, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001044
1045 /* PW0 (24h), AOW0 (8h) */
1046 parm = AC_PWRST_D3;
1047 set_pin_power_state(codec, 0x24, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001048 if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001049 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001050 update_power_state(codec, 0x8, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001051 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
Takashi Iwai61625522012-07-25 13:54:55 +02001052 parm = parm2;
1053 update_power_state(codec, 0xb, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001054 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001055 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001056
1057 /* PW1 (25h), AOW1 (9h) */
1058 parm = AC_PWRST_D3;
1059 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001060 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001061 set_pin_power_state(codec, 0x2a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001062 update_power_state(codec, 0x9, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001063
Takashi Iwaib3f60082013-01-07 12:27:36 +01001064 if (spec->gen.indep_hp_enabled) {
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001065 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
1066 parm = AC_PWRST_D3;
1067 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001068 update_power_state(codec, 0x1b, parm);
1069 update_power_state(codec, 0x34, parm);
1070 update_power_state(codec, 0xc, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001071 }
1072}
1073
Takashi Iwai30b45032011-07-11 17:05:04 +02001074/* Add a connection to the primary DAC from AA-mixer for some codecs
1075 * This isn't listed from the raw info, but the chip has a secret connection.
1076 */
1077static int add_secret_dac_path(struct hda_codec *codec)
1078{
1079 struct via_spec *spec = codec->spec;
1080 int i, nums;
1081 hda_nid_t conn[8];
1082 hda_nid_t nid;
1083
Takashi Iwaib3f60082013-01-07 12:27:36 +01001084 if (!spec->gen.mixer_nid)
Takashi Iwai30b45032011-07-11 17:05:04 +02001085 return 0;
Takashi Iwaib3f60082013-01-07 12:27:36 +01001086 nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn,
Takashi Iwai30b45032011-07-11 17:05:04 +02001087 ARRAY_SIZE(conn) - 1);
1088 for (i = 0; i < nums; i++) {
1089 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
1090 return 0;
1091 }
1092
1093 /* find the primary DAC and add to the connection list */
1094 nid = codec->start_nid;
1095 for (i = 0; i < codec->num_nodes; i++, nid++) {
1096 unsigned int caps = get_wcaps(codec, nid);
1097 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
1098 !(caps & AC_WCAP_DIGITAL)) {
1099 conn[nums++] = nid;
1100 return snd_hda_override_conn_list(codec,
Takashi Iwaib3f60082013-01-07 12:27:36 +01001101 spec->gen.mixer_nid,
Takashi Iwai30b45032011-07-11 17:05:04 +02001102 nums, conn);
1103 }
1104 }
1105 return 0;
1106}
1107
1108
Lydia Wangeb7188c2009-10-10 19:08:34 +08001109static int patch_vt1718S(struct hda_codec *codec)
1110{
1111 struct via_spec *spec;
1112 int err;
1113
1114 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001115 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08001116 if (spec == NULL)
1117 return -ENOMEM;
1118
Takashi Iwaib3f60082013-01-07 12:27:36 +01001119 spec->gen.mixer_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001120 override_mic_boost(codec, 0x2b, 0, 3, 40);
1121 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02001122 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02001123
Lydia Wangeb7188c2009-10-10 19:08:34 +08001124 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001125 err = via_parse_auto_config(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08001126 if (err < 0) {
1127 via_free(codec);
1128 return err;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001129 }
1130
Takashi Iwai096a8852011-06-20 12:09:02 +02001131 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001132
Lydia Wangeb7188c2009-10-10 19:08:34 +08001133 codec->patch_ops = via_patch_ops;
1134
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001135 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
1136
Lydia Wangeb7188c2009-10-10 19:08:34 +08001137 return 0;
1138}
Lydia Wangf3db4232009-10-10 19:08:41 +08001139
1140/* Patch for VT1716S */
1141
1142static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
1143 struct snd_ctl_elem_info *uinfo)
1144{
1145 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1146 uinfo->count = 1;
1147 uinfo->value.integer.min = 0;
1148 uinfo->value.integer.max = 1;
1149 return 0;
1150}
1151
1152static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
1153 struct snd_ctl_elem_value *ucontrol)
1154{
1155 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1156 int index = 0;
1157
1158 index = snd_hda_codec_read(codec, 0x26, 0,
1159 AC_VERB_GET_CONNECT_SEL, 0);
1160 if (index != -1)
1161 *ucontrol->value.integer.value = index;
1162
1163 return 0;
1164}
1165
1166static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
1167 struct snd_ctl_elem_value *ucontrol)
1168{
1169 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1170 struct via_spec *spec = codec->spec;
1171 int index = *ucontrol->value.integer.value;
1172
1173 snd_hda_codec_write(codec, 0x26, 0,
1174 AC_VERB_SET_CONNECT_SEL, index);
1175 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001176 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08001177 return 1;
1178}
1179
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001180static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08001181 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
1182 {
1183 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1184 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001185 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08001186 .count = 1,
1187 .info = vt1716s_dmic_info,
1188 .get = vt1716s_dmic_get,
1189 .put = vt1716s_dmic_put,
1190 },
1191 {} /* end */
1192};
1193
1194
1195/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001196static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08001197 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
1198 { } /* end */
1199};
1200
Takashi Iwai096a8852011-06-20 12:09:02 +02001201static const struct hda_verb vt1716S_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08001202 /* Enable Boost Volume backdoor */
1203 {0x1, 0xf8a, 0x80},
1204 /* don't bybass mixer */
1205 {0x1, 0xf88, 0xc0},
1206 /* Enable mono output */
1207 {0x1, 0xf90, 0x08},
1208 { }
1209};
1210
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001211static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
1212{
1213 struct via_spec *spec = codec->spec;
1214 int imux_is_smixer;
1215 unsigned int parm;
1216 unsigned int mono_out, present;
1217 /* SW0 (17h) = stereo mixer */
1218 imux_is_smixer =
1219 (snd_hda_codec_read(codec, 0x17, 0,
1220 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
1221 /* inputs */
1222 /* PW 1/2/5 (1ah/1bh/1eh) */
1223 parm = AC_PWRST_D3;
1224 set_pin_power_state(codec, 0x1a, &parm);
1225 set_pin_power_state(codec, 0x1b, &parm);
1226 set_pin_power_state(codec, 0x1e, &parm);
1227 if (imux_is_smixer)
1228 parm = AC_PWRST_D0;
1229 /* SW0 (17h), AIW0(13h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001230 update_power_state(codec, 0x17, parm);
1231 update_power_state(codec, 0x13, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001232
1233 parm = AC_PWRST_D3;
1234 set_pin_power_state(codec, 0x1e, &parm);
1235 /* PW11 (22h) */
1236 if (spec->dmic_enabled)
1237 set_pin_power_state(codec, 0x22, &parm);
1238 else
Takashi Iwai054d8672012-01-24 12:25:50 +01001239 update_power_state(codec, 0x22, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001240
1241 /* SW2(26h), AIW1(14h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001242 update_power_state(codec, 0x26, parm);
1243 update_power_state(codec, 0x14, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001244
1245 /* outputs */
1246 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
1247 parm = AC_PWRST_D3;
1248 set_pin_power_state(codec, 0x19, &parm);
1249 /* Smart 5.1 PW2(1bh) */
Takashi Iwaib3f60082013-01-07 12:27:36 +01001250 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001251 set_pin_power_state(codec, 0x1b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001252 update_power_state(codec, 0x18, parm);
1253 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001254
1255 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
1256 parm = AC_PWRST_D3;
1257 set_pin_power_state(codec, 0x23, &parm);
1258 /* Smart 5.1 PW1(1ah) */
Takashi Iwaib3f60082013-01-07 12:27:36 +01001259 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001260 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001261 update_power_state(codec, 0x27, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001262
1263 /* Smart 5.1 PW5(1eh) */
Takashi Iwaib3f60082013-01-07 12:27:36 +01001264 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001265 set_pin_power_state(codec, 0x1e, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001266 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001267
1268 /* Mono out */
1269 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
1270 present = snd_hda_jack_detect(codec, 0x1c);
1271
1272 if (present)
1273 mono_out = 0;
1274 else {
1275 present = snd_hda_jack_detect(codec, 0x1d);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001276 if (!spec->gen.indep_hp_enabled && present)
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001277 mono_out = 0;
1278 else
1279 mono_out = 1;
1280 }
1281 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
Takashi Iwai054d8672012-01-24 12:25:50 +01001282 update_power_state(codec, 0x28, parm);
1283 update_power_state(codec, 0x29, parm);
1284 update_power_state(codec, 0x2a, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001285
1286 /* PW 3/4 (1ch/1dh) */
1287 parm = AC_PWRST_D3;
1288 set_pin_power_state(codec, 0x1c, &parm);
1289 set_pin_power_state(codec, 0x1d, &parm);
1290 /* HP Independent Mode, power on AOW3 */
Takashi Iwaib3f60082013-01-07 12:27:36 +01001291 if (spec->gen.indep_hp_enabled)
Takashi Iwai054d8672012-01-24 12:25:50 +01001292 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001293
1294 /* force to D0 for internal Speaker */
1295 /* MW0 (16h), AOW0 (10h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001296 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
1297 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001298}
1299
Lydia Wangf3db4232009-10-10 19:08:41 +08001300static int patch_vt1716S(struct hda_codec *codec)
1301{
1302 struct via_spec *spec;
1303 int err;
1304
1305 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001306 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08001307 if (spec == NULL)
1308 return -ENOMEM;
1309
Takashi Iwaib3f60082013-01-07 12:27:36 +01001310 spec->gen.mixer_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001311 override_mic_boost(codec, 0x1a, 0, 3, 40);
1312 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02001313
Lydia Wangf3db4232009-10-10 19:08:41 +08001314 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001315 err = via_parse_auto_config(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08001316 if (err < 0) {
1317 via_free(codec);
1318 return err;
Lydia Wangf3db4232009-10-10 19:08:41 +08001319 }
1320
Takashi Iwai096a8852011-06-20 12:09:02 +02001321 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
Lydia Wangf3db4232009-10-10 19:08:41 +08001322
Takashi Iwaib3f60082013-01-07 12:27:36 +01001323 spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer;
Lydia Wangf3db4232009-10-10 19:08:41 +08001324 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
1325
1326 codec->patch_ops = via_patch_ops;
1327
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001328 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08001329 return 0;
1330}
Lydia Wang25eaba22009-10-10 19:08:43 +08001331
1332/* for vt2002P */
1333
Takashi Iwai096a8852011-06-20 12:09:02 +02001334static const struct hda_verb vt2002P_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08001335 /* Class-D speaker related verbs */
1336 {0x1, 0xfe0, 0x4},
1337 {0x1, 0xfe9, 0x80},
1338 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08001339 /* Enable Boost Volume backdoor */
1340 {0x1, 0xfb9, 0x24},
Lydia Wang25eaba22009-10-10 19:08:43 +08001341 /* Enable AOW0 to MW9 */
1342 {0x1, 0xfb8, 0x88},
1343 { }
1344};
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001345
Takashi Iwai096a8852011-06-20 12:09:02 +02001346static const struct hda_verb vt1802_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08001347 /* Enable Boost Volume backdoor */
1348 {0x1, 0xfb9, 0x24},
Lydia Wang118909562011-03-23 17:57:34 +08001349 /* Enable AOW0 to MW9 */
1350 {0x1, 0xfb8, 0x88},
1351 { }
1352};
Lydia Wang25eaba22009-10-10 19:08:43 +08001353
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001354static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
1355{
1356 struct via_spec *spec = codec->spec;
1357 int imux_is_smixer;
1358 unsigned int parm;
1359 unsigned int present;
1360 /* MUX9 (1eh) = stereo mixer */
1361 imux_is_smixer =
1362 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
1363 /* inputs */
1364 /* PW 5/6/7 (29h/2ah/2bh) */
1365 parm = AC_PWRST_D3;
1366 set_pin_power_state(codec, 0x29, &parm);
1367 set_pin_power_state(codec, 0x2a, &parm);
1368 set_pin_power_state(codec, 0x2b, &parm);
1369 parm = AC_PWRST_D0;
1370 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001371 update_power_state(codec, 0x1e, parm);
1372 update_power_state(codec, 0x1f, parm);
1373 update_power_state(codec, 0x10, parm);
1374 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001375
1376 /* outputs */
1377 /* AOW0 (8h)*/
Takashi Iwai054d8672012-01-24 12:25:50 +01001378 update_power_state(codec, 0x8, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001379
Lydia Wang118909562011-03-23 17:57:34 +08001380 if (spec->codec_type == VT1802) {
1381 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1382 parm = AC_PWRST_D3;
1383 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001384 update_power_state(codec, 0x18, parm);
1385 update_power_state(codec, 0x38, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001386 } else {
1387 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
1388 parm = AC_PWRST_D3;
1389 set_pin_power_state(codec, 0x26, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001390 update_power_state(codec, 0x1c, parm);
1391 update_power_state(codec, 0x37, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001392 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001393
Lydia Wang118909562011-03-23 17:57:34 +08001394 if (spec->codec_type == VT1802) {
1395 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1396 parm = AC_PWRST_D3;
1397 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001398 update_power_state(codec, 0x15, parm);
1399 update_power_state(codec, 0x35, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001400 } else {
1401 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
1402 parm = AC_PWRST_D3;
1403 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001404 update_power_state(codec, 0x19, parm);
1405 update_power_state(codec, 0x35, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001406 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001407
Takashi Iwaib3f60082013-01-07 12:27:36 +01001408 if (spec->gen.indep_hp_enabled)
Takashi Iwai054d8672012-01-24 12:25:50 +01001409 update_power_state(codec, 0x9, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001410
1411 /* Class-D */
1412 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
1413 present = snd_hda_jack_detect(codec, 0x25);
1414
1415 parm = AC_PWRST_D3;
1416 set_pin_power_state(codec, 0x24, &parm);
1417 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08001418 if (spec->codec_type == VT1802)
Takashi Iwai054d8672012-01-24 12:25:50 +01001419 update_power_state(codec, 0x14, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001420 else
Takashi Iwai054d8672012-01-24 12:25:50 +01001421 update_power_state(codec, 0x18, parm);
1422 update_power_state(codec, 0x34, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001423
1424 /* Mono Out */
1425 present = snd_hda_jack_detect(codec, 0x26);
1426
1427 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08001428 if (spec->codec_type == VT1802) {
1429 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001430 update_power_state(codec, 0x33, parm);
1431 update_power_state(codec, 0x1c, parm);
1432 update_power_state(codec, 0x3c, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001433 } else {
1434 /* PW15 (31h), MW8(17h), MUX8(3bh) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001435 update_power_state(codec, 0x31, parm);
1436 update_power_state(codec, 0x17, parm);
1437 update_power_state(codec, 0x3b, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001438 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001439 /* MW9 (21h) */
1440 if (imux_is_smixer || !is_aa_path_mute(codec))
Takashi Iwai054d8672012-01-24 12:25:50 +01001441 update_power_state(codec, 0x21, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001442 else
Takashi Iwai054d8672012-01-24 12:25:50 +01001443 update_power_state(codec, 0x21, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001444}
Lydia Wang25eaba22009-10-10 19:08:43 +08001445
David Henningsson4b527b62012-09-18 14:26:59 +02001446/*
1447 * pin fix-up
1448 */
1449enum {
1450 VIA_FIXUP_INTMIC_BOOST,
Takashi Iwaid5266122012-11-07 10:40:36 +01001451 VIA_FIXUP_ASUS_G75,
David Henningsson4b527b62012-09-18 14:26:59 +02001452};
1453
1454static void via_fixup_intmic_boost(struct hda_codec *codec,
1455 const struct hda_fixup *fix, int action)
1456{
1457 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1458 override_mic_boost(codec, 0x30, 0, 2, 40);
1459}
1460
1461static const struct hda_fixup via_fixups[] = {
1462 [VIA_FIXUP_INTMIC_BOOST] = {
1463 .type = HDA_FIXUP_FUNC,
1464 .v.func = via_fixup_intmic_boost,
1465 },
Takashi Iwaid5266122012-11-07 10:40:36 +01001466 [VIA_FIXUP_ASUS_G75] = {
1467 .type = HDA_FIXUP_PINS,
1468 .v.pins = (const struct hda_pintbl[]) {
1469 /* set 0x24 and 0x33 as speakers */
1470 { 0x24, 0x991301f0 },
1471 { 0x33, 0x991301f1 }, /* subwoofer */
1472 { }
1473 }
1474 },
David Henningsson4b527b62012-09-18 14:26:59 +02001475};
1476
1477static const struct snd_pci_quirk vt2002p_fixups[] = {
Takashi Iwaid5266122012-11-07 10:40:36 +01001478 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
David Henningsson4b527b62012-09-18 14:26:59 +02001479 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
1480 {}
1481};
1482
Takashi Iwaief4da452012-11-07 10:37:48 +01001483/* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
1484 * Replace this with mixer NID 0x1c
1485 */
1486static void fix_vt1802_connections(struct hda_codec *codec)
1487{
1488 static hda_nid_t conn_24[] = { 0x14, 0x1c };
1489 static hda_nid_t conn_33[] = { 0x1c };
1490
1491 snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
1492 snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
1493}
1494
Lydia Wang25eaba22009-10-10 19:08:43 +08001495/* patch for vt2002P */
1496static int patch_vt2002P(struct hda_codec *codec)
1497{
1498 struct via_spec *spec;
1499 int err;
1500
1501 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001502 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08001503 if (spec == NULL)
1504 return -ENOMEM;
1505
Takashi Iwaib3f60082013-01-07 12:27:36 +01001506 spec->gen.mixer_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001507 override_mic_boost(codec, 0x2b, 0, 3, 40);
1508 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwaief4da452012-11-07 10:37:48 +01001509 if (spec->codec_type == VT1802)
1510 fix_vt1802_connections(codec);
Takashi Iwai30b45032011-07-11 17:05:04 +02001511 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02001512
David Henningsson4b527b62012-09-18 14:26:59 +02001513 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
1514 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1515
Lydia Wang25eaba22009-10-10 19:08:43 +08001516 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001517 err = via_parse_auto_config(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08001518 if (err < 0) {
1519 via_free(codec);
1520 return err;
Lydia Wang25eaba22009-10-10 19:08:43 +08001521 }
1522
Lydia Wang118909562011-03-23 17:57:34 +08001523 if (spec->codec_type == VT1802)
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001524 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08001525 else
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001526 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08001527
Lydia Wang25eaba22009-10-10 19:08:43 +08001528 codec->patch_ops = via_patch_ops;
1529
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001530 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08001531 return 0;
1532}
Lydia Wangab6734e2009-10-10 19:08:46 +08001533
1534/* for vt1812 */
1535
Takashi Iwai096a8852011-06-20 12:09:02 +02001536static const struct hda_verb vt1812_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08001537 /* Enable Boost Volume backdoor */
1538 {0x1, 0xfb9, 0x24},
Lydia Wangab6734e2009-10-10 19:08:46 +08001539 /* Enable AOW0 to MW9 */
1540 {0x1, 0xfb8, 0xa8},
1541 { }
1542};
1543
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001544static void set_widgets_power_state_vt1812(struct hda_codec *codec)
1545{
1546 struct via_spec *spec = codec->spec;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001547 unsigned int parm;
1548 unsigned int present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001549 /* inputs */
1550 /* PW 5/6/7 (29h/2ah/2bh) */
1551 parm = AC_PWRST_D3;
1552 set_pin_power_state(codec, 0x29, &parm);
1553 set_pin_power_state(codec, 0x2a, &parm);
1554 set_pin_power_state(codec, 0x2b, &parm);
1555 parm = AC_PWRST_D0;
1556 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001557 update_power_state(codec, 0x1e, parm);
1558 update_power_state(codec, 0x1f, parm);
1559 update_power_state(codec, 0x10, parm);
1560 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001561
1562 /* outputs */
1563 /* AOW0 (8h)*/
Takashi Iwai054d8672012-01-24 12:25:50 +01001564 update_power_state(codec, 0x8, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001565
1566 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1567 parm = AC_PWRST_D3;
1568 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001569 update_power_state(codec, 0x18, parm);
1570 update_power_state(codec, 0x38, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001571
1572 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1573 parm = AC_PWRST_D3;
1574 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001575 update_power_state(codec, 0x15, parm);
1576 update_power_state(codec, 0x35, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001577 if (spec->gen.indep_hp_enabled)
Takashi Iwai054d8672012-01-24 12:25:50 +01001578 update_power_state(codec, 0x9, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001579
1580 /* Internal Speaker */
1581 /* PW0 (24h), MW0(14h), MUX0(34h) */
1582 present = snd_hda_jack_detect(codec, 0x25);
1583
1584 parm = AC_PWRST_D3;
1585 set_pin_power_state(codec, 0x24, &parm);
1586 if (present) {
Takashi Iwai054d8672012-01-24 12:25:50 +01001587 update_power_state(codec, 0x14, AC_PWRST_D3);
1588 update_power_state(codec, 0x34, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001589 } else {
Takashi Iwai054d8672012-01-24 12:25:50 +01001590 update_power_state(codec, 0x14, AC_PWRST_D0);
1591 update_power_state(codec, 0x34, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001592 }
1593
1594
1595 /* Mono Out */
1596 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1597 present = snd_hda_jack_detect(codec, 0x28);
1598
1599 parm = AC_PWRST_D3;
1600 set_pin_power_state(codec, 0x31, &parm);
1601 if (present) {
Takashi Iwai054d8672012-01-24 12:25:50 +01001602 update_power_state(codec, 0x1c, AC_PWRST_D3);
1603 update_power_state(codec, 0x3c, AC_PWRST_D3);
1604 update_power_state(codec, 0x3e, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001605 } else {
Takashi Iwai054d8672012-01-24 12:25:50 +01001606 update_power_state(codec, 0x1c, AC_PWRST_D0);
1607 update_power_state(codec, 0x3c, AC_PWRST_D0);
1608 update_power_state(codec, 0x3e, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001609 }
1610
1611 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1612 parm = AC_PWRST_D3;
1613 set_pin_power_state(codec, 0x33, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001614 update_power_state(codec, 0x1d, parm);
1615 update_power_state(codec, 0x3d, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001616
1617}
Lydia Wangab6734e2009-10-10 19:08:46 +08001618
1619/* patch for vt1812 */
1620static int patch_vt1812(struct hda_codec *codec)
1621{
1622 struct via_spec *spec;
1623 int err;
1624
1625 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001626 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08001627 if (spec == NULL)
1628 return -ENOMEM;
1629
Takashi Iwaib3f60082013-01-07 12:27:36 +01001630 spec->gen.mixer_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001631 override_mic_boost(codec, 0x2b, 0, 3, 40);
1632 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02001633 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02001634
Lydia Wangab6734e2009-10-10 19:08:46 +08001635 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001636 err = via_parse_auto_config(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08001637 if (err < 0) {
1638 via_free(codec);
1639 return err;
Lydia Wangab6734e2009-10-10 19:08:46 +08001640 }
1641
Takashi Iwai096a8852011-06-20 12:09:02 +02001642 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
Lydia Wangab6734e2009-10-10 19:08:46 +08001643
Lydia Wangab6734e2009-10-10 19:08:46 +08001644 codec->patch_ops = via_patch_ops;
1645
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001646 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08001647 return 0;
1648}
1649
Lydia Wang43737e02012-12-10 18:28:11 +08001650/* patch for vt3476 */
1651
1652static const struct hda_verb vt3476_init_verbs[] = {
1653 /* Enable DMic 8/16/32K */
1654 {0x1, 0xF7B, 0x30},
1655 /* Enable Boost Volume backdoor */
1656 {0x1, 0xFB9, 0x20},
1657 /* Enable AOW-MW9 path */
1658 {0x1, 0xFB8, 0x10},
1659 { }
1660};
1661
1662static void set_widgets_power_state_vt3476(struct hda_codec *codec)
1663{
1664 struct via_spec *spec = codec->spec;
1665 int imux_is_smixer;
1666 unsigned int parm, parm2;
1667 /* MUX10 (1eh) = stereo mixer */
1668 imux_is_smixer =
1669 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
1670 /* inputs */
1671 /* PW 5/6/7 (29h/2ah/2bh) */
1672 parm = AC_PWRST_D3;
1673 set_pin_power_state(codec, 0x29, &parm);
1674 set_pin_power_state(codec, 0x2a, &parm);
1675 set_pin_power_state(codec, 0x2b, &parm);
1676 if (imux_is_smixer)
1677 parm = AC_PWRST_D0;
1678 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1679 update_power_state(codec, 0x1e, parm);
1680 update_power_state(codec, 0x1f, parm);
1681 update_power_state(codec, 0x10, parm);
1682 update_power_state(codec, 0x11, parm);
1683
1684 /* outputs */
1685 /* PW3 (27h), MW3(37h), AOW3 (bh) */
1686 if (spec->codec_type == VT1705CF) {
1687 parm = AC_PWRST_D3;
1688 update_power_state(codec, 0x27, parm);
1689 update_power_state(codec, 0x37, parm);
1690 } else {
1691 parm = AC_PWRST_D3;
1692 set_pin_power_state(codec, 0x27, &parm);
1693 update_power_state(codec, 0x37, parm);
1694 }
1695
1696 /* PW2 (26h), MW2(36h), AOW2 (ah) */
1697 parm = AC_PWRST_D3;
1698 set_pin_power_state(codec, 0x26, &parm);
1699 update_power_state(codec, 0x36, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001700 if (smart51_enabled(codec)) {
Lydia Wang43737e02012-12-10 18:28:11 +08001701 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
1702 set_pin_power_state(codec, 0x2b, &parm);
1703 update_power_state(codec, 0x3b, parm);
1704 update_power_state(codec, 0x1b, parm);
1705 }
1706 update_conv_power_state(codec, 0xa, parm, 2);
1707
1708 /* PW1 (25h), MW1(35h), AOW1 (9h) */
1709 parm = AC_PWRST_D3;
1710 set_pin_power_state(codec, 0x25, &parm);
1711 update_power_state(codec, 0x35, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001712 if (smart51_enabled(codec)) {
Lydia Wang43737e02012-12-10 18:28:11 +08001713 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
1714 set_pin_power_state(codec, 0x2a, &parm);
1715 update_power_state(codec, 0x3a, parm);
1716 update_power_state(codec, 0x1a, parm);
1717 }
1718 update_conv_power_state(codec, 0x9, parm, 1);
1719
1720 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
1721 parm = AC_PWRST_D3;
1722 set_pin_power_state(codec, 0x28, &parm);
1723 update_power_state(codec, 0x38, parm);
1724 update_power_state(codec, 0x18, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001725 if (spec->gen.indep_hp_enabled)
Lydia Wang43737e02012-12-10 18:28:11 +08001726 update_conv_power_state(codec, 0xb, parm, 3);
1727 parm2 = parm; /* for pin 0x0b */
1728
1729 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
1730 parm = AC_PWRST_D3;
1731 set_pin_power_state(codec, 0x24, &parm);
1732 update_power_state(codec, 0x34, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001733 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
Lydia Wang43737e02012-12-10 18:28:11 +08001734 parm = parm2;
1735 update_conv_power_state(codec, 0x8, parm, 0);
1736 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1737 update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
1738}
1739
1740static int patch_vt3476(struct hda_codec *codec)
1741{
1742 struct via_spec *spec;
1743 int err;
1744
1745 /* create a codec specific record */
1746 spec = via_new_spec(codec);
1747 if (spec == NULL)
1748 return -ENOMEM;
1749
Takashi Iwaib3f60082013-01-07 12:27:36 +01001750 spec->gen.mixer_nid = 0x3f;
Lydia Wang43737e02012-12-10 18:28:11 +08001751 add_secret_dac_path(codec);
1752
1753 /* automatic parse from the BIOS config */
1754 err = via_parse_auto_config(codec);
1755 if (err < 0) {
1756 via_free(codec);
1757 return err;
1758 }
1759
1760 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
1761
1762 codec->patch_ops = via_patch_ops;
1763
1764 spec->set_widgets_power_state = set_widgets_power_state_vt3476;
1765
1766 return 0;
1767}
1768
Joseph Chanc577b8a2006-11-29 15:29:40 +01001769/*
1770 * patch entries
1771 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001772static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01001773 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
1774 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
1775 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
1776 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
1777 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001778 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001779 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001780 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001781 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001782 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001783 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001784 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001785 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001786 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001787 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001788 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001789 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001790 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001791 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001792 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001793 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001794 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001795 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001796 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001797 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001798 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001799 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001800 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001801 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001802 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001803 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001804 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001805 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001806 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001807 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001808 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001809 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001810 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001811 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001812 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001813 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001814 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001815 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001816 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08001817 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08001818 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001819 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001820 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001821 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001822 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001823 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001824 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001825 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001826 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001827 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001828 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001829 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001830 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001831 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001832 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001833 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001834 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001835 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001836 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001837 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001838 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001839 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001840 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08001841 { .id = 0x11060428, .name = "VT1718S",
1842 .patch = patch_vt1718S},
1843 { .id = 0x11064428, .name = "VT1718S",
1844 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08001845 { .id = 0x11060441, .name = "VT2020",
1846 .patch = patch_vt1718S},
1847 { .id = 0x11064441, .name = "VT1828S",
1848 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08001849 { .id = 0x11060433, .name = "VT1716S",
1850 .patch = patch_vt1716S},
1851 { .id = 0x1106a721, .name = "VT1716S",
1852 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08001853 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
1854 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08001855 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08001856 { .id = 0x11060440, .name = "VT1818S",
1857 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08001858 { .id = 0x11060446, .name = "VT1802",
1859 .patch = patch_vt2002P},
1860 { .id = 0x11068446, .name = "VT1802",
1861 .patch = patch_vt2002P},
Lydia Wang43737e02012-12-10 18:28:11 +08001862 { .id = 0x11064760, .name = "VT1705CF",
1863 .patch = patch_vt3476},
Lydia Wang6121b842012-12-10 19:03:26 +08001864 { .id = 0x11064761, .name = "VT1708SCE",
1865 .patch = patch_vt3476},
1866 { .id = 0x11064762, .name = "VT1808",
1867 .patch = patch_vt3476},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001868 {} /* terminator */
1869};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001870
1871MODULE_ALIAS("snd-hda-codec-id:1106*");
1872
1873static struct hda_codec_preset_list via_list = {
1874 .preset = snd_hda_preset_via,
1875 .owner = THIS_MODULE,
1876};
1877
1878MODULE_LICENSE("GPL");
1879MODULE_DESCRIPTION("VIA HD-audio codec");
1880
1881static int __init patch_via_init(void)
1882{
1883 return snd_hda_add_codec_preset(&via_list);
1884}
1885
1886static void __exit patch_via_exit(void)
1887{
1888 snd_hda_delete_codec_preset(&via_list);
1889}
1890
1891module_init(patch_via_init)
1892module_exit(patch_via_exit)