blob: c35338a8771d9a01020c5c088be985402041a17c [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;
Takashi Iwai13961172013-01-21 15:15:55 +0100138 spec->gen.indep_hp = 1;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100139 spec->gen.pcm_playback_hook = via_playback_pcm_hook;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100140 return spec;
141}
142
Lydia Wang744ff5f2009-10-10 19:07:26 +0800143static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800144{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800145 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800146 u16 ven_id = vendor_id >> 16;
147 u16 dev_id = vendor_id & 0xffff;
148 enum VIA_HDA_CODEC codec_type;
149
150 /* get codec type */
151 if (ven_id != 0x1106)
152 codec_type = UNKNOWN;
153 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
154 codec_type = VT1708;
155 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
156 codec_type = VT1709_10CH;
157 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
158 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800159 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800160 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800161 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
162 codec_type = VT1708BCE;
163 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800164 codec_type = VT1708B_4CH;
165 else if ((dev_id & 0xfff) == 0x397
166 && (dev_id >> 12) < 8)
167 codec_type = VT1708S;
168 else if ((dev_id & 0xfff) == 0x398
169 && (dev_id >> 12) < 8)
170 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800171 else if ((dev_id & 0xfff) == 0x428
172 && (dev_id >> 12) < 8)
173 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800174 else if (dev_id == 0x0433 || dev_id == 0xa721)
175 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800176 else if (dev_id == 0x0441 || dev_id == 0x4441)
177 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800178 else if (dev_id == 0x0438 || dev_id == 0x4438)
179 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800180 else if (dev_id == 0x0448)
181 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800182 else if (dev_id == 0x0440)
183 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800184 else if ((dev_id & 0xfff) == 0x446)
185 codec_type = VT1802;
Lydia Wang43737e02012-12-10 18:28:11 +0800186 else if (dev_id == 0x4760)
187 codec_type = VT1705CF;
Lydia Wang6121b842012-12-10 19:03:26 +0800188 else if (dev_id == 0x4761 || dev_id == 0x4762)
189 codec_type = VT1808;
Harald Welted7426322008-09-15 22:43:23 +0800190 else
191 codec_type = UNKNOWN;
192 return codec_type;
193};
194
Takashi Iwaiada509e2011-06-20 15:40:19 +0200195static void analog_low_current_mode(struct hda_codec *codec);
196static bool is_aa_path_mute(struct hda_codec *codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800197
Takashi Iwai187d3332011-11-24 16:33:09 +0100198#define hp_detect_with_aa(codec) \
199 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
200 !is_aa_path_mute(codec))
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800201
Takashi Iwaib3f60082013-01-07 12:27:36 +0100202static void vt1708_stop_hp_work(struct hda_codec *codec)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800203{
Takashi Iwaib3f60082013-01-07 12:27:36 +0100204 struct via_spec *spec = codec->spec;
205 if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800206 return;
Takashi Iwai187d3332011-11-24 16:33:09 +0100207 if (spec->hp_work_active) {
Takashi Iwaib3f60082013-01-07 12:27:36 +0100208 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 1);
209 cancel_delayed_work_sync(&codec->jackpoll_work);
210 spec->hp_work_active = false;
211 codec->jackpoll_interval = 0;
Takashi Iwai187d3332011-11-24 16:33:09 +0100212 }
213}
214
Takashi Iwaib3f60082013-01-07 12:27:36 +0100215static void vt1708_update_hp_work(struct hda_codec *codec)
Takashi Iwai187d3332011-11-24 16:33:09 +0100216{
Takashi Iwaib3f60082013-01-07 12:27:36 +0100217 struct via_spec *spec = codec->spec;
218 if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800219 return;
David Henningsson05dc0fc2013-02-05 12:06:03 +0100220 if (spec->vt1708_jack_detect) {
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{
Takashi Iwai9040d102013-01-24 17:47:17 +0100242 if (snd_hda_check_power_state(codec, nid, parm))
Takashi Iwai054d8672012-01-24 12:25:50 +0100243 return;
244 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
245}
246
Lydia Wang43737e02012-12-10 18:28:11 +0800247static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
248 unsigned int parm, unsigned int index)
249{
250 struct via_spec *spec = codec->spec;
251 unsigned int format;
Takashi Iwai9040d102013-01-24 17:47:17 +0100252
253 if (snd_hda_check_power_state(codec, nid, parm))
Lydia Wang43737e02012-12-10 18:28:11 +0800254 return;
255 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
256 if (format && (spec->dac_stream_tag[index] != format))
257 spec->dac_stream_tag[index] = format;
258
259 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
260 if (parm == AC_PWRST_D0) {
261 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
262 if (!format && (spec->dac_stream_tag[index] != format))
263 snd_hda_codec_write(codec, nid, 0,
264 AC_VERB_SET_CHANNEL_STREAMID,
265 spec->dac_stream_tag[index]);
266 }
267}
268
Takashi Iwaib3f60082013-01-07 12:27:36 +0100269static bool smart51_enabled(struct hda_codec *codec)
270{
271 struct via_spec *spec = codec->spec;
272 return spec->gen.ext_channel_count > 2;
273}
274
275static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
276{
277 struct via_spec *spec = codec->spec;
278 int i;
279
280 for (i = 0; i < spec->gen.multi_ios; i++)
281 if (spec->gen.multi_io[i].pin == pin)
282 return true;
283 return false;
284}
285
Lydia Wangf5271102009-10-10 19:07:35 +0800286static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
287 unsigned int *affected_parm)
288{
289 unsigned parm;
290 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
291 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
292 >> AC_DEFCFG_MISC_SHIFT
293 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800294 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200295 unsigned present = 0;
296
297 no_presence |= spec->no_pin_power_ctl;
298 if (!no_presence)
299 present = snd_hda_jack_detect(codec, nid);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100300 if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
Lydia Wang1564b282009-10-10 19:07:52 +0800301 || ((no_presence || present)
302 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800303 *affected_parm = AC_PWRST_D0; /* if it's connected */
304 parm = AC_PWRST_D0;
305 } else
306 parm = AC_PWRST_D3;
307
Takashi Iwai054d8672012-01-24 12:25:50 +0100308 update_power_state(codec, nid, parm);
Lydia Wangf5271102009-10-10 19:07:35 +0800309}
310
Takashi Iwai24088a52011-06-17 16:59:21 +0200311static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
312 struct snd_ctl_elem_info *uinfo)
313{
Takashi Iwaidda415d2012-11-30 18:34:38 +0100314 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai24088a52011-06-17 16:59:21 +0200315}
316
317static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
318 struct snd_ctl_elem_value *ucontrol)
319{
320 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
321 struct via_spec *spec = codec->spec;
322 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
323 return 0;
324}
325
326static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
327 struct snd_ctl_elem_value *ucontrol)
328{
329 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
330 struct via_spec *spec = codec->spec;
331 unsigned int val = !ucontrol->value.enumerated.item[0];
332
333 if (val == spec->no_pin_power_ctl)
334 return 0;
335 spec->no_pin_power_ctl = val;
336 set_widgets_power_state(codec);
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100337 analog_low_current_mode(codec);
Takashi Iwai24088a52011-06-17 16:59:21 +0200338 return 1;
339}
340
Takashi Iwaib3f60082013-01-07 12:27:36 +0100341static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
342 {
Takashi Iwai24088a52011-06-17 16:59:21 +0200343 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
344 .name = "Dynamic Power-Control",
345 .info = via_pin_power_ctl_info,
346 .get = via_pin_power_ctl_get,
347 .put = via_pin_power_ctl_put,
Takashi Iwaib3f60082013-01-07 12:27:36 +0100348 },
349 {} /* terminator */
Takashi Iwai24088a52011-06-17 16:59:21 +0200350};
351
352
Takashi Iwaiada509e2011-06-20 15:40:19 +0200353/* check AA path's mute status */
354static bool is_aa_path_mute(struct hda_codec *codec)
Lydia Wangf5271102009-10-10 19:07:35 +0800355{
Lydia Wangf5271102009-10-10 19:07:35 +0800356 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +0200357 const struct hda_amp_list *p;
Takashi Iwai0186f4f2013-02-07 10:45:11 +0100358 int ch, v;
Takashi Iwaiada509e2011-06-20 15:40:19 +0200359
Takashi Iwai0186f4f2013-02-07 10:45:11 +0100360 p = spec->gen.loopback.amplist;
361 if (!p)
362 return true;
363 for (; p->nid; p++) {
Takashi Iwaiada509e2011-06-20 15:40:19 +0200364 for (ch = 0; ch < 2; ch++) {
365 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
366 p->idx);
367 if (!(v & HDA_AMP_MUTE) && v > 0)
368 return false;
Lydia Wangf5271102009-10-10 19:07:35 +0800369 }
370 }
Takashi Iwaiada509e2011-06-20 15:40:19 +0200371 return true;
Lydia Wangf5271102009-10-10 19:07:35 +0800372}
373
374/* enter/exit analog low-current mode */
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100375static void __analog_low_current_mode(struct hda_codec *codec, bool force)
Lydia Wangf5271102009-10-10 19:07:35 +0800376{
377 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +0200378 bool enable;
379 unsigned int verb, parm;
Lydia Wangf5271102009-10-10 19:07:35 +0800380
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100381 if (spec->no_pin_power_ctl)
382 enable = false;
383 else
Takashi Iwaib3f60082013-01-07 12:27:36 +0100384 enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100385 if (enable == spec->alc_mode && !force)
386 return;
387 spec->alc_mode = enable;
Lydia Wangf5271102009-10-10 19:07:35 +0800388
389 /* decide low current mode's verb & parameter */
390 switch (spec->codec_type) {
391 case VT1708B_8CH:
392 case VT1708B_4CH:
393 verb = 0xf70;
394 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
395 break;
396 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +0800397 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +0800398 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +0800399 verb = 0xf73;
400 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
401 break;
402 case VT1702:
403 verb = 0xf73;
404 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
405 break;
Lydia Wang25eaba22009-10-10 19:08:43 +0800406 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +0800407 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +0800408 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +0800409 verb = 0xf93;
410 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
411 break;
Lydia Wang43737e02012-12-10 18:28:11 +0800412 case VT1705CF:
Lydia Wang6121b842012-12-10 19:03:26 +0800413 case VT1808:
Lydia Wang43737e02012-12-10 18:28:11 +0800414 verb = 0xf82;
415 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
416 break;
Lydia Wangf5271102009-10-10 19:07:35 +0800417 default:
418 return; /* other codecs are not supported */
419 }
420 /* send verb */
421 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
422}
423
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100424static void analog_low_current_mode(struct hda_codec *codec)
425{
426 return __analog_low_current_mode(codec, false);
427}
428
Joseph Chanc577b8a2006-11-29 15:29:40 +0100429static int via_build_controls(struct hda_codec *codec)
430{
431 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100432 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100433
Takashi Iwaib3f60082013-01-07 12:27:36 +0100434 err = snd_hda_gen_build_controls(codec);
435 if (err < 0)
436 return err;
437
Takashi Iwai24088a52011-06-17 16:59:21 +0200438 if (spec->set_widgets_power_state)
Takashi Iwaib3f60082013-01-07 12:27:36 +0100439 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
Takashi Iwai24088a52011-06-17 16:59:21 +0200440
Joseph Chanc577b8a2006-11-29 15:29:40 +0100441 for (i = 0; i < spec->num_mixers; i++) {
442 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
443 if (err < 0)
444 return err;
445 }
446
Joseph Chanc577b8a2006-11-29 15:29:40 +0100447 return 0;
448}
449
Takashi Iwaib3f60082013-01-07 12:27:36 +0100450static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
451 struct hda_codec *codec,
452 struct snd_pcm_substream *substream,
453 int action)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100454{
Takashi Iwaib3f60082013-01-07 12:27:36 +0100455 analog_low_current_mode(codec);
456 vt1708_update_hp_work(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100457}
458
459static void via_free(struct hda_codec *codec)
460{
461 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100462
463 if (!spec)
464 return;
465
Takashi Iwaib3f60082013-01-07 12:27:36 +0100466 vt1708_stop_hp_work(codec);
467 snd_hda_gen_spec_free(&spec->gen);
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200468 kfree(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100469}
470
Takashi Iwai2a439522011-07-26 09:52:50 +0200471#ifdef CONFIG_PM
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200472static int via_suspend(struct hda_codec *codec)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800473{
474 struct via_spec *spec = codec->spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100475 vt1708_stop_hp_work(codec);
David Henningsson94c142a2012-08-09 10:56:12 +0200476
477 if (spec->codec_type == VT1802) {
478 /* Fix pop noise on headphones */
479 int i;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100480 for (i = 0; i < spec->gen.autocfg.hp_outs; i++)
481 snd_hda_set_pin_ctl(codec, spec->gen.autocfg.hp_pins[i], 0);
David Henningsson94c142a2012-08-09 10:56:12 +0200482 }
483
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800484 return 0;
485}
486#endif
487
Takashi Iwai83012a72012-08-24 18:38:08 +0200488#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200489static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
490{
491 struct via_spec *spec = codec->spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100492 set_widgets_power_state(codec);
493 analog_low_current_mode(codec);
494 vt1708_update_hp_work(codec);
495 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
Takashi Iwaicb53c622007-08-10 17:21:45 +0200496}
497#endif
498
Joseph Chanc577b8a2006-11-29 15:29:40 +0100499/*
500 */
Takashi Iwai5d417622011-06-20 11:32:27 +0200501
502static int via_init(struct hda_codec *codec);
503
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200504static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100505 .build_controls = via_build_controls,
Takashi Iwaib3f60082013-01-07 12:27:36 +0100506 .build_pcms = snd_hda_gen_build_pcms,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100507 .init = via_init,
508 .free = via_free,
David Henningsson4e2d16d2012-10-08 15:44:14 +0200509 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +0200510#ifdef CONFIG_PM
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800511 .suspend = via_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200512 .check_power_status = via_check_power_status,
513#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +0100514};
515
Takashi Iwai4a796162011-06-17 17:53:38 +0200516
Takashi Iwaib3f60082013-01-07 12:27:36 +0100517static const struct hda_verb vt1708_init_verbs[] = {
518 /* power down jack detect function */
519 {0x1, 0xf81, 0x1},
520 { }
Takashi Iwai3214b962011-07-18 12:49:25 +0200521};
Harald Welte76d9b0d2008-09-09 15:50:37 +0800522static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
523{
524 unsigned int def_conf;
525 unsigned char seqassoc;
526
Takashi Iwai2f334f92009-02-20 14:37:42 +0100527 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +0800528 seqassoc = (unsigned char) get_defcfg_association(def_conf);
529 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +0800530 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
531 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
532 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
533 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +0800534 }
535
536 return;
537}
538
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200539static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800540 struct snd_ctl_elem_value *ucontrol)
541{
542 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
543 struct via_spec *spec = codec->spec;
544
545 if (spec->codec_type != VT1708)
546 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200547 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800548 return 0;
549}
550
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200551static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800552 struct snd_ctl_elem_value *ucontrol)
553{
554 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
555 struct via_spec *spec = codec->spec;
Takashi Iwai187d3332011-11-24 16:33:09 +0100556 int val;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800557
558 if (spec->codec_type != VT1708)
559 return 0;
Takashi Iwai187d3332011-11-24 16:33:09 +0100560 val = !!ucontrol->value.integer.value[0];
561 if (spec->vt1708_jack_detect == val)
562 return 0;
563 spec->vt1708_jack_detect = val;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100564 vt1708_update_hp_work(codec);
Takashi Iwai187d3332011-11-24 16:33:09 +0100565 return 1;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800566}
567
Takashi Iwaib3f60082013-01-07 12:27:36 +0100568static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
569 {
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200570 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
571 .name = "Jack Detect",
572 .count = 1,
573 .info = snd_ctl_boolean_mono_info,
574 .get = vt1708_jack_detect_get,
575 .put = vt1708_jack_detect_put,
Takashi Iwaib3f60082013-01-07 12:27:36 +0100576 },
577 {} /* terminator */
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800578};
579
Takashi Iwaib3f60082013-01-07 12:27:36 +0100580static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
David Henningsson4e2d16d2012-10-08 15:44:14 +0200581{
582 set_widgets_power_state(codec);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100583 snd_hda_gen_hp_automute(codec, tbl);
584}
585
586static void via_line_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
587{
588 set_widgets_power_state(codec);
589 snd_hda_gen_line_automute(codec, tbl);
David Henningsson4e2d16d2012-10-08 15:44:14 +0200590}
591
592static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
593{
594 set_widgets_power_state(codec);
595}
596
Takashi Iwaib3f60082013-01-07 12:27:36 +0100597#define VIA_JACK_EVENT (HDA_GEN_LAST_EVENT + 1)
598
599static void via_set_jack_unsol_events(struct hda_codec *codec)
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200600{
601 struct via_spec *spec = codec->spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100602 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
603 hda_nid_t pin;
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200604 int i;
605
Takashi Iwaib3f60082013-01-07 12:27:36 +0100606 spec->gen.hp_automute_hook = via_hp_automute;
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200607 if (cfg->speaker_pins[0])
Takashi Iwaib3f60082013-01-07 12:27:36 +0100608 spec->gen.line_automute_hook = via_line_automute;
David Henningsson4e2d16d2012-10-08 15:44:14 +0200609
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200610 for (i = 0; i < cfg->line_outs; i++) {
Takashi Iwaib3f60082013-01-07 12:27:36 +0100611 pin = cfg->line_out_pins[i];
612 if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
613 is_jack_detectable(codec, pin))
614 snd_hda_jack_detect_enable_callback(codec, pin,
David Henningsson4e2d16d2012-10-08 15:44:14 +0200615 VIA_JACK_EVENT,
616 via_jack_powerstate_event);
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200617 }
Takashi Iwaib3f60082013-01-07 12:27:36 +0100618
619 for (i = 0; i < cfg->num_inputs; i++) {
620 pin = cfg->line_out_pins[i];
621 if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
622 is_jack_detectable(codec, pin))
623 snd_hda_jack_detect_enable_callback(codec, pin,
624 VIA_JACK_EVENT,
625 via_jack_powerstate_event);
626 }
627}
628
629static int via_parse_auto_config(struct hda_codec *codec)
630{
631 struct via_spec *spec = codec->spec;
632 int err;
633
634 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
635 if (err < 0)
636 return err;
637
638 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
639 if (err < 0)
640 return err;
641
642 via_set_jack_unsol_events(codec);
643 return 0;
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200644}
645
Takashi Iwai5d417622011-06-20 11:32:27 +0200646static int via_init(struct hda_codec *codec)
647{
648 struct via_spec *spec = codec->spec;
649 int i;
650
651 for (i = 0; i < spec->num_iverbs; i++)
652 snd_hda_sequence_write(codec, spec->init_verbs[i]);
653
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100654 /* init power states */
655 set_widgets_power_state(codec);
656 __analog_low_current_mode(codec, true);
657
Takashi Iwaib3f60082013-01-07 12:27:36 +0100658 snd_hda_gen_init(codec);
Lydia Wang118909562011-03-23 17:57:34 +0800659
Takashi Iwaib3f60082013-01-07 12:27:36 +0100660 vt1708_update_hp_work(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +0800661
Joseph Chanc577b8a2006-11-29 15:29:40 +0100662 return 0;
663}
664
David Henningssonf672f652013-02-05 12:06:02 +0100665static int vt1708_build_controls(struct hda_codec *codec)
666{
667 /* In order not to create "Phantom Jack" controls,
668 temporary enable jackpoll */
669 int err;
670 int old_interval = codec->jackpoll_interval;
671 codec->jackpoll_interval = msecs_to_jiffies(100);
672 err = via_build_controls(codec);
673 codec->jackpoll_interval = old_interval;
674 return err;
675}
676
Takashi Iwaib3f60082013-01-07 12:27:36 +0100677static int vt1708_build_pcms(struct hda_codec *codec)
Takashi Iwai337b9d02009-07-07 18:18:59 +0200678{
679 struct via_spec *spec = codec->spec;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100680 int i, err;
Takashi Iwai337b9d02009-07-07 18:18:59 +0200681
Takashi Iwaib3f60082013-01-07 12:27:36 +0100682 err = snd_hda_gen_build_pcms(codec);
683 if (err < 0 || codec->vendor_id != 0x11061708)
684 return err;
685
686 /* We got noisy outputs on the right channel on VT1708 when
687 * 24bit samples are used. Until any workaround is found,
688 * disable the 24bit format, so far.
689 */
690 for (i = 0; i < codec->num_pcms; i++) {
691 struct hda_pcm *info = &spec->gen.pcm_rec[i];
692 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
693 info->pcm_type != HDA_PCM_TYPE_AUDIO)
694 continue;
695 info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats =
696 SNDRV_PCM_FMTBIT_S16_LE;
Takashi Iwai337b9d02009-07-07 18:18:59 +0200697 }
Takashi Iwaib3f60082013-01-07 12:27:36 +0100698
Takashi Iwai1c55d522009-07-08 07:45:46 +0200699 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +0200700}
701
Joseph Chanc577b8a2006-11-29 15:29:40 +0100702static int patch_vt1708(struct hda_codec *codec)
703{
704 struct via_spec *spec;
705 int err;
706
707 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100708 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100709 if (spec == NULL)
710 return -ENOMEM;
711
Takashi Iwaib3f60082013-01-07 12:27:36 +0100712 spec->gen.mixer_nid = 0x17;
713
714 /* set jackpoll_interval while parsing the codec */
715 codec->jackpoll_interval = msecs_to_jiffies(100);
716 spec->vt1708_jack_detect = 1;
717
718 /* don't support the input jack switching due to lack of unsol event */
719 /* (it may work with polling, though, but it needs testing) */
720 spec->gen.suppress_auto_mic = 1;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200721
Takashi Iwai12daef62011-06-18 17:45:49 +0200722 /* Add HP and CD pin config connect bit re-config action */
723 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
724 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
725
Joseph Chanc577b8a2006-11-29 15:29:40 +0100726 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +0200727 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100728 if (err < 0) {
729 via_free(codec);
730 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100731 }
732
Takashi Iwai12daef62011-06-18 17:45:49 +0200733 /* add jack detect on/off control */
Takashi Iwaib3f60082013-01-07 12:27:36 +0100734 spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100735
Lydia Wange322a362011-06-29 13:52:02 +0800736 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
737
Joseph Chanc577b8a2006-11-29 15:29:40 +0100738 codec->patch_ops = via_patch_ops;
David Henningssonf672f652013-02-05 12:06:02 +0100739 codec->patch_ops.build_controls = vt1708_build_controls;
Takashi Iwaib3f60082013-01-07 12:27:36 +0100740 codec->patch_ops.build_pcms = vt1708_build_pcms;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100741
Takashi Iwaib3f60082013-01-07 12:27:36 +0100742 /* clear jackpoll_interval again; it's set dynamically */
743 codec->jackpoll_interval = 0;
744
Joseph Chanc577b8a2006-11-29 15:29:40 +0100745 return 0;
746}
747
Takashi Iwaiddd304d2011-06-21 16:33:55 +0200748static int patch_vt1709(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100749{
750 struct via_spec *spec;
751 int err;
752
753 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100754 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100755 if (spec == NULL)
756 return -ENOMEM;
757
Takashi Iwaib3f60082013-01-07 12:27:36 +0100758 spec->gen.mixer_nid = 0x18;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200759
Takashi Iwai12daef62011-06-18 17:45:49 +0200760 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100761 if (err < 0) {
762 via_free(codec);
763 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100764 }
765
Joseph Chanc577b8a2006-11-29 15:29:40 +0100766 codec->patch_ops = via_patch_ops;
767
Josepch Chanf7278fd2007-12-13 16:40:40 +0100768 return 0;
769}
770
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800771static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
772{
773 struct via_spec *spec = codec->spec;
774 int imux_is_smixer;
775 unsigned int parm;
776 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +0800777 if ((spec->codec_type != VT1708B_4CH) &&
778 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800779 is_8ch = 1;
780
781 /* SW0 (17h) = stereo mixer */
782 imux_is_smixer =
783 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
784 == ((spec->codec_type == VT1708S) ? 5 : 0));
785 /* inputs */
786 /* PW 1/2/5 (1ah/1bh/1eh) */
787 parm = AC_PWRST_D3;
788 set_pin_power_state(codec, 0x1a, &parm);
789 set_pin_power_state(codec, 0x1b, &parm);
790 set_pin_power_state(codec, 0x1e, &parm);
791 if (imux_is_smixer)
792 parm = AC_PWRST_D0;
793 /* SW0 (17h), AIW 0/1 (13h/14h) */
Takashi Iwai054d8672012-01-24 12:25:50 +0100794 update_power_state(codec, 0x17, parm);
795 update_power_state(codec, 0x13, parm);
796 update_power_state(codec, 0x14, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800797
798 /* outputs */
799 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
800 parm = AC_PWRST_D3;
801 set_pin_power_state(codec, 0x19, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100802 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800803 set_pin_power_state(codec, 0x1b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +0100804 update_power_state(codec, 0x18, parm);
805 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800806
807 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
808 if (is_8ch) {
809 parm = AC_PWRST_D3;
810 set_pin_power_state(codec, 0x22, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100811 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800812 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +0100813 update_power_state(codec, 0x26, parm);
814 update_power_state(codec, 0x24, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +0800815 } else if (codec->vendor_id == 0x11064397) {
816 /* PW7(23h), SW2(27h), AOW2(25h) */
817 parm = AC_PWRST_D3;
818 set_pin_power_state(codec, 0x23, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100819 if (smart51_enabled(codec))
Lydia Wangbc92df72011-03-23 17:56:05 +0800820 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +0100821 update_power_state(codec, 0x27, parm);
822 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800823 }
824
825 /* PW 3/4/7 (1ch/1dh/23h) */
826 parm = AC_PWRST_D3;
827 /* force to D0 for internal Speaker */
828 set_pin_power_state(codec, 0x1c, &parm);
829 set_pin_power_state(codec, 0x1d, &parm);
830 if (is_8ch)
831 set_pin_power_state(codec, 0x23, &parm);
832
833 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
Takashi Iwai054d8672012-01-24 12:25:50 +0100834 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
835 update_power_state(codec, 0x10, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800836 if (is_8ch) {
Takashi Iwai054d8672012-01-24 12:25:50 +0100837 update_power_state(codec, 0x25, parm);
838 update_power_state(codec, 0x27, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +0100839 } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
Takashi Iwai054d8672012-01-24 12:25:50 +0100840 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800841}
842
Lydia Wang518bf3b2009-10-10 19:07:29 +0800843static int patch_vt1708S(struct hda_codec *codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +0200844static int patch_vt1708B(struct hda_codec *codec)
Josepch Chanf7278fd2007-12-13 16:40:40 +0100845{
846 struct via_spec *spec;
847 int err;
848
Lydia Wang518bf3b2009-10-10 19:07:29 +0800849 if (get_codec_type(codec) == VT1708BCE)
850 return patch_vt1708S(codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +0200851
Josepch Chanf7278fd2007-12-13 16:40:40 +0100852 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100853 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +0100854 if (spec == NULL)
855 return -ENOMEM;
856
Takashi Iwaib3f60082013-01-07 12:27:36 +0100857 spec->gen.mixer_nid = 0x16;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200858
Josepch Chanf7278fd2007-12-13 16:40:40 +0100859 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +0200860 err = via_parse_auto_config(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +0100861 if (err < 0) {
862 via_free(codec);
863 return err;
Josepch Chanf7278fd2007-12-13 16:40:40 +0100864 }
865
Josepch Chanf7278fd2007-12-13 16:40:40 +0100866 codec->patch_ops = via_patch_ops;
867
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800868 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
869
Josepch Chanf7278fd2007-12-13 16:40:40 +0100870 return 0;
871}
872
Harald Welted949cac2008-09-09 15:56:01 +0800873/* Patch for VT1708S */
Takashi Iwai096a8852011-06-20 12:09:02 +0200874static const struct hda_verb vt1708S_init_verbs[] = {
Harald Welted7426322008-09-15 22:43:23 +0800875 /* Enable Mic Boost Volume backdoor */
876 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +0800877 /* don't bybass mixer */
878 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +0800879 { }
880};
881
Lydia Wang6369bcf2009-10-10 19:08:31 +0800882static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
883 int offset, int num_steps, int step_size)
884{
885 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
886 (offset << AC_AMPCAP_OFFSET_SHIFT) |
887 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
888 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
889 (0 << AC_AMPCAP_MUTE_SHIFT));
890}
891
Harald Welted949cac2008-09-09 15:56:01 +0800892static int patch_vt1708S(struct hda_codec *codec)
893{
894 struct via_spec *spec;
895 int err;
896
897 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100898 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +0800899 if (spec == NULL)
900 return -ENOMEM;
901
Takashi Iwaib3f60082013-01-07 12:27:36 +0100902 spec->gen.mixer_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +0200903 override_mic_boost(codec, 0x1a, 0, 3, 40);
904 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +0200905
Lydia Wang518bf3b2009-10-10 19:07:29 +0800906 /* correct names for VT1708BCE */
907 if (get_codec_type(codec) == VT1708BCE) {
908 kfree(codec->chip_name);
909 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
910 snprintf(codec->bus->card->mixername,
911 sizeof(codec->bus->card->mixername),
912 "%s %s", codec->vendor_name, codec->chip_name);
Lydia Wang970f630f2011-03-22 16:25:56 +0800913 }
Lydia Wangbc92df72011-03-23 17:56:05 +0800914 /* correct names for VT1705 */
915 if (codec->vendor_id == 0x11064397) {
916 kfree(codec->chip_name);
917 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
918 snprintf(codec->bus->card->mixername,
919 sizeof(codec->bus->card->mixername),
920 "%s %s", codec->vendor_name, codec->chip_name);
921 }
Takashi Iwaib3f60082013-01-07 12:27:36 +0100922
923 /* automatic parse from the BIOS config */
924 err = via_parse_auto_config(codec);
925 if (err < 0) {
926 via_free(codec);
927 return err;
928 }
929
930 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
931
932 codec->patch_ops = via_patch_ops;
933
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800934 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +0800935 return 0;
936}
937
938/* Patch for VT1702 */
939
Takashi Iwai096a8852011-06-20 12:09:02 +0200940static const struct hda_verb vt1702_init_verbs[] = {
Lydia Wangbc7e7e52009-10-10 19:08:32 +0800941 /* mixer enable */
942 {0x1, 0xF88, 0x3},
943 /* GPIO 0~2 */
944 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +0800945 { }
946};
947
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800948static void set_widgets_power_state_vt1702(struct hda_codec *codec)
949{
950 int imux_is_smixer =
951 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
952 unsigned int parm;
953 /* inputs */
954 /* PW 1/2/5 (14h/15h/18h) */
955 parm = AC_PWRST_D3;
956 set_pin_power_state(codec, 0x14, &parm);
957 set_pin_power_state(codec, 0x15, &parm);
958 set_pin_power_state(codec, 0x18, &parm);
959 if (imux_is_smixer)
960 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
961 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
Takashi Iwai054d8672012-01-24 12:25:50 +0100962 update_power_state(codec, 0x13, parm);
963 update_power_state(codec, 0x12, parm);
964 update_power_state(codec, 0x1f, parm);
965 update_power_state(codec, 0x20, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800966
967 /* outputs */
968 /* PW 3/4 (16h/17h) */
969 parm = AC_PWRST_D3;
970 set_pin_power_state(codec, 0x17, &parm);
971 set_pin_power_state(codec, 0x16, &parm);
972 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
Takashi Iwai054d8672012-01-24 12:25:50 +0100973 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
974 update_power_state(codec, 0x10, parm);
975 update_power_state(codec, 0x1d, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800976}
977
Harald Welted949cac2008-09-09 15:56:01 +0800978static int patch_vt1702(struct hda_codec *codec)
979{
980 struct via_spec *spec;
981 int err;
Harald Welted949cac2008-09-09 15:56:01 +0800982
983 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100984 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +0800985 if (spec == NULL)
986 return -ENOMEM;
987
Takashi Iwaib3f60082013-01-07 12:27:36 +0100988 spec->gen.mixer_nid = 0x1a;
Takashi Iwai620e2b22011-06-17 17:19:19 +0200989
Takashi Iwai12daef62011-06-18 17:45:49 +0200990 /* limit AA path volume to 0 dB */
991 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
992 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
993 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
994 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
995 (1 << AC_AMPCAP_MUTE_SHIFT));
996
Harald Welted949cac2008-09-09 15:56:01 +0800997 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +0200998 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +0800999 if (err < 0) {
1000 via_free(codec);
1001 return err;
Harald Welted949cac2008-09-09 15:56:01 +08001002 }
1003
Takashi Iwai096a8852011-06-20 12:09:02 +02001004 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08001005
Harald Welted949cac2008-09-09 15:56:01 +08001006 codec->patch_ops = via_patch_ops;
1007
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001008 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08001009 return 0;
1010}
1011
Lydia Wangeb7188c2009-10-10 19:08:34 +08001012/* Patch for VT1718S */
1013
Takashi Iwai096a8852011-06-20 12:09:02 +02001014static const struct hda_verb vt1718S_init_verbs[] = {
Lydia Wang4ab2d532011-03-24 12:42:03 +08001015 /* Enable MW0 adjust Gain 5 */
1016 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08001017 /* Enable Boost Volume backdoor */
1018 {0x1, 0xf88, 0x8},
Takashi Iwai5d417622011-06-20 11:32:27 +02001019
Lydia Wangeb7188c2009-10-10 19:08:34 +08001020 { }
1021};
1022
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001023static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
1024{
1025 struct via_spec *spec = codec->spec;
1026 int imux_is_smixer;
Takashi Iwai61625522012-07-25 13:54:55 +02001027 unsigned int parm, parm2;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001028 /* MUX6 (1eh) = stereo mixer */
1029 imux_is_smixer =
1030 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
1031 /* inputs */
1032 /* PW 5/6/7 (29h/2ah/2bh) */
1033 parm = AC_PWRST_D3;
1034 set_pin_power_state(codec, 0x29, &parm);
1035 set_pin_power_state(codec, 0x2a, &parm);
1036 set_pin_power_state(codec, 0x2b, &parm);
1037 if (imux_is_smixer)
1038 parm = AC_PWRST_D0;
1039 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001040 update_power_state(codec, 0x1e, parm);
1041 update_power_state(codec, 0x1f, parm);
1042 update_power_state(codec, 0x10, parm);
1043 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001044
1045 /* outputs */
1046 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
1047 parm = AC_PWRST_D3;
1048 set_pin_power_state(codec, 0x27, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001049 update_power_state(codec, 0x1a, parm);
Takashi Iwai61625522012-07-25 13:54:55 +02001050 parm2 = parm; /* for pin 0x0b */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001051
1052 /* PW2 (26h), AOW2 (ah) */
1053 parm = AC_PWRST_D3;
1054 set_pin_power_state(codec, 0x26, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001055 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001056 set_pin_power_state(codec, 0x2b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001057 update_power_state(codec, 0xa, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001058
1059 /* PW0 (24h), AOW0 (8h) */
1060 parm = AC_PWRST_D3;
1061 set_pin_power_state(codec, 0x24, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001062 if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001063 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001064 update_power_state(codec, 0x8, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001065 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
Takashi Iwai61625522012-07-25 13:54:55 +02001066 parm = parm2;
1067 update_power_state(codec, 0xb, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001068 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001069 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001070
1071 /* PW1 (25h), AOW1 (9h) */
1072 parm = AC_PWRST_D3;
1073 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001074 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001075 set_pin_power_state(codec, 0x2a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001076 update_power_state(codec, 0x9, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001077
Takashi Iwaib3f60082013-01-07 12:27:36 +01001078 if (spec->gen.indep_hp_enabled) {
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001079 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
1080 parm = AC_PWRST_D3;
1081 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001082 update_power_state(codec, 0x1b, parm);
1083 update_power_state(codec, 0x34, parm);
1084 update_power_state(codec, 0xc, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001085 }
1086}
1087
Takashi Iwai30b45032011-07-11 17:05:04 +02001088/* Add a connection to the primary DAC from AA-mixer for some codecs
1089 * This isn't listed from the raw info, but the chip has a secret connection.
1090 */
1091static int add_secret_dac_path(struct hda_codec *codec)
1092{
1093 struct via_spec *spec = codec->spec;
1094 int i, nums;
1095 hda_nid_t conn[8];
1096 hda_nid_t nid;
1097
Takashi Iwaib3f60082013-01-07 12:27:36 +01001098 if (!spec->gen.mixer_nid)
Takashi Iwai30b45032011-07-11 17:05:04 +02001099 return 0;
Takashi Iwaib3f60082013-01-07 12:27:36 +01001100 nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn,
Takashi Iwai30b45032011-07-11 17:05:04 +02001101 ARRAY_SIZE(conn) - 1);
1102 for (i = 0; i < nums; i++) {
1103 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
1104 return 0;
1105 }
1106
1107 /* find the primary DAC and add to the connection list */
1108 nid = codec->start_nid;
1109 for (i = 0; i < codec->num_nodes; i++, nid++) {
1110 unsigned int caps = get_wcaps(codec, nid);
1111 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
1112 !(caps & AC_WCAP_DIGITAL)) {
1113 conn[nums++] = nid;
1114 return snd_hda_override_conn_list(codec,
Takashi Iwaib3f60082013-01-07 12:27:36 +01001115 spec->gen.mixer_nid,
Takashi Iwai30b45032011-07-11 17:05:04 +02001116 nums, conn);
1117 }
1118 }
1119 return 0;
1120}
1121
1122
Lydia Wangeb7188c2009-10-10 19:08:34 +08001123static int patch_vt1718S(struct hda_codec *codec)
1124{
1125 struct via_spec *spec;
1126 int err;
1127
1128 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001129 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08001130 if (spec == NULL)
1131 return -ENOMEM;
1132
Takashi Iwaib3f60082013-01-07 12:27:36 +01001133 spec->gen.mixer_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001134 override_mic_boost(codec, 0x2b, 0, 3, 40);
1135 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02001136 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02001137
Lydia Wangeb7188c2009-10-10 19:08:34 +08001138 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001139 err = via_parse_auto_config(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08001140 if (err < 0) {
1141 via_free(codec);
1142 return err;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001143 }
1144
Takashi Iwai096a8852011-06-20 12:09:02 +02001145 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001146
Lydia Wangeb7188c2009-10-10 19:08:34 +08001147 codec->patch_ops = via_patch_ops;
1148
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001149 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
1150
Lydia Wangeb7188c2009-10-10 19:08:34 +08001151 return 0;
1152}
Lydia Wangf3db4232009-10-10 19:08:41 +08001153
1154/* Patch for VT1716S */
1155
1156static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
1157 struct snd_ctl_elem_info *uinfo)
1158{
1159 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1160 uinfo->count = 1;
1161 uinfo->value.integer.min = 0;
1162 uinfo->value.integer.max = 1;
1163 return 0;
1164}
1165
1166static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
1167 struct snd_ctl_elem_value *ucontrol)
1168{
1169 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1170 int index = 0;
1171
1172 index = snd_hda_codec_read(codec, 0x26, 0,
1173 AC_VERB_GET_CONNECT_SEL, 0);
1174 if (index != -1)
1175 *ucontrol->value.integer.value = index;
1176
1177 return 0;
1178}
1179
1180static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
1181 struct snd_ctl_elem_value *ucontrol)
1182{
1183 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1184 struct via_spec *spec = codec->spec;
1185 int index = *ucontrol->value.integer.value;
1186
1187 snd_hda_codec_write(codec, 0x26, 0,
1188 AC_VERB_SET_CONNECT_SEL, index);
1189 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001190 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08001191 return 1;
1192}
1193
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001194static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08001195 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
1196 {
1197 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1198 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001199 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08001200 .count = 1,
1201 .info = vt1716s_dmic_info,
1202 .get = vt1716s_dmic_get,
1203 .put = vt1716s_dmic_put,
1204 },
1205 {} /* end */
1206};
1207
1208
1209/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001210static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08001211 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
1212 { } /* end */
1213};
1214
Takashi Iwai096a8852011-06-20 12:09:02 +02001215static const struct hda_verb vt1716S_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08001216 /* Enable Boost Volume backdoor */
1217 {0x1, 0xf8a, 0x80},
1218 /* don't bybass mixer */
1219 {0x1, 0xf88, 0xc0},
1220 /* Enable mono output */
1221 {0x1, 0xf90, 0x08},
1222 { }
1223};
1224
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001225static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
1226{
1227 struct via_spec *spec = codec->spec;
1228 int imux_is_smixer;
1229 unsigned int parm;
1230 unsigned int mono_out, present;
1231 /* SW0 (17h) = stereo mixer */
1232 imux_is_smixer =
1233 (snd_hda_codec_read(codec, 0x17, 0,
1234 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
1235 /* inputs */
1236 /* PW 1/2/5 (1ah/1bh/1eh) */
1237 parm = AC_PWRST_D3;
1238 set_pin_power_state(codec, 0x1a, &parm);
1239 set_pin_power_state(codec, 0x1b, &parm);
1240 set_pin_power_state(codec, 0x1e, &parm);
1241 if (imux_is_smixer)
1242 parm = AC_PWRST_D0;
1243 /* SW0 (17h), AIW0(13h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001244 update_power_state(codec, 0x17, parm);
1245 update_power_state(codec, 0x13, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001246
1247 parm = AC_PWRST_D3;
1248 set_pin_power_state(codec, 0x1e, &parm);
1249 /* PW11 (22h) */
1250 if (spec->dmic_enabled)
1251 set_pin_power_state(codec, 0x22, &parm);
1252 else
Takashi Iwai054d8672012-01-24 12:25:50 +01001253 update_power_state(codec, 0x22, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001254
1255 /* SW2(26h), AIW1(14h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001256 update_power_state(codec, 0x26, parm);
1257 update_power_state(codec, 0x14, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001258
1259 /* outputs */
1260 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
1261 parm = AC_PWRST_D3;
1262 set_pin_power_state(codec, 0x19, &parm);
1263 /* Smart 5.1 PW2(1bh) */
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, 0x1b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001266 update_power_state(codec, 0x18, parm);
1267 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001268
1269 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
1270 parm = AC_PWRST_D3;
1271 set_pin_power_state(codec, 0x23, &parm);
1272 /* Smart 5.1 PW1(1ah) */
Takashi Iwaib3f60082013-01-07 12:27:36 +01001273 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001274 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001275 update_power_state(codec, 0x27, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001276
1277 /* Smart 5.1 PW5(1eh) */
Takashi Iwaib3f60082013-01-07 12:27:36 +01001278 if (smart51_enabled(codec))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001279 set_pin_power_state(codec, 0x1e, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001280 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001281
1282 /* Mono out */
1283 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
1284 present = snd_hda_jack_detect(codec, 0x1c);
1285
1286 if (present)
1287 mono_out = 0;
1288 else {
1289 present = snd_hda_jack_detect(codec, 0x1d);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001290 if (!spec->gen.indep_hp_enabled && present)
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001291 mono_out = 0;
1292 else
1293 mono_out = 1;
1294 }
1295 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
Takashi Iwai054d8672012-01-24 12:25:50 +01001296 update_power_state(codec, 0x28, parm);
1297 update_power_state(codec, 0x29, parm);
1298 update_power_state(codec, 0x2a, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001299
1300 /* PW 3/4 (1ch/1dh) */
1301 parm = AC_PWRST_D3;
1302 set_pin_power_state(codec, 0x1c, &parm);
1303 set_pin_power_state(codec, 0x1d, &parm);
1304 /* HP Independent Mode, power on AOW3 */
Takashi Iwaib3f60082013-01-07 12:27:36 +01001305 if (spec->gen.indep_hp_enabled)
Takashi Iwai054d8672012-01-24 12:25:50 +01001306 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001307
1308 /* force to D0 for internal Speaker */
1309 /* MW0 (16h), AOW0 (10h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001310 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
1311 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001312}
1313
Lydia Wangf3db4232009-10-10 19:08:41 +08001314static int patch_vt1716S(struct hda_codec *codec)
1315{
1316 struct via_spec *spec;
1317 int err;
1318
1319 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001320 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08001321 if (spec == NULL)
1322 return -ENOMEM;
1323
Takashi Iwaib3f60082013-01-07 12:27:36 +01001324 spec->gen.mixer_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001325 override_mic_boost(codec, 0x1a, 0, 3, 40);
1326 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02001327
Lydia Wangf3db4232009-10-10 19:08:41 +08001328 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001329 err = via_parse_auto_config(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08001330 if (err < 0) {
1331 via_free(codec);
1332 return err;
Lydia Wangf3db4232009-10-10 19:08:41 +08001333 }
1334
Takashi Iwai096a8852011-06-20 12:09:02 +02001335 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
Lydia Wangf3db4232009-10-10 19:08:41 +08001336
Takashi Iwaib3f60082013-01-07 12:27:36 +01001337 spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer;
Lydia Wangf3db4232009-10-10 19:08:41 +08001338 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
1339
1340 codec->patch_ops = via_patch_ops;
1341
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001342 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08001343 return 0;
1344}
Lydia Wang25eaba22009-10-10 19:08:43 +08001345
1346/* for vt2002P */
1347
Takashi Iwai096a8852011-06-20 12:09:02 +02001348static const struct hda_verb vt2002P_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08001349 /* Class-D speaker related verbs */
1350 {0x1, 0xfe0, 0x4},
1351 {0x1, 0xfe9, 0x80},
1352 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08001353 /* Enable Boost Volume backdoor */
1354 {0x1, 0xfb9, 0x24},
Lydia Wang25eaba22009-10-10 19:08:43 +08001355 /* Enable AOW0 to MW9 */
1356 {0x1, 0xfb8, 0x88},
1357 { }
1358};
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001359
Takashi Iwai096a8852011-06-20 12:09:02 +02001360static const struct hda_verb vt1802_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08001361 /* Enable Boost Volume backdoor */
1362 {0x1, 0xfb9, 0x24},
Lydia Wang118909562011-03-23 17:57:34 +08001363 /* Enable AOW0 to MW9 */
1364 {0x1, 0xfb8, 0x88},
1365 { }
1366};
Lydia Wang25eaba22009-10-10 19:08:43 +08001367
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001368static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
1369{
1370 struct via_spec *spec = codec->spec;
1371 int imux_is_smixer;
1372 unsigned int parm;
1373 unsigned int present;
1374 /* MUX9 (1eh) = stereo mixer */
1375 imux_is_smixer =
1376 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
1377 /* inputs */
1378 /* PW 5/6/7 (29h/2ah/2bh) */
1379 parm = AC_PWRST_D3;
1380 set_pin_power_state(codec, 0x29, &parm);
1381 set_pin_power_state(codec, 0x2a, &parm);
1382 set_pin_power_state(codec, 0x2b, &parm);
1383 parm = AC_PWRST_D0;
1384 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001385 update_power_state(codec, 0x1e, parm);
1386 update_power_state(codec, 0x1f, parm);
1387 update_power_state(codec, 0x10, parm);
1388 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001389
1390 /* outputs */
1391 /* AOW0 (8h)*/
Takashi Iwai054d8672012-01-24 12:25:50 +01001392 update_power_state(codec, 0x8, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001393
Lydia Wang118909562011-03-23 17:57:34 +08001394 if (spec->codec_type == VT1802) {
1395 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1396 parm = AC_PWRST_D3;
1397 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001398 update_power_state(codec, 0x18, parm);
1399 update_power_state(codec, 0x38, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001400 } else {
1401 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
1402 parm = AC_PWRST_D3;
1403 set_pin_power_state(codec, 0x26, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001404 update_power_state(codec, 0x1c, parm);
1405 update_power_state(codec, 0x37, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001406 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001407
Lydia Wang118909562011-03-23 17:57:34 +08001408 if (spec->codec_type == VT1802) {
1409 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1410 parm = AC_PWRST_D3;
1411 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001412 update_power_state(codec, 0x15, parm);
1413 update_power_state(codec, 0x35, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001414 } else {
1415 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
1416 parm = AC_PWRST_D3;
1417 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001418 update_power_state(codec, 0x19, parm);
1419 update_power_state(codec, 0x35, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001420 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001421
Takashi Iwaib3f60082013-01-07 12:27:36 +01001422 if (spec->gen.indep_hp_enabled)
Takashi Iwai054d8672012-01-24 12:25:50 +01001423 update_power_state(codec, 0x9, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001424
1425 /* Class-D */
1426 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
1427 present = snd_hda_jack_detect(codec, 0x25);
1428
1429 parm = AC_PWRST_D3;
1430 set_pin_power_state(codec, 0x24, &parm);
1431 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08001432 if (spec->codec_type == VT1802)
Takashi Iwai054d8672012-01-24 12:25:50 +01001433 update_power_state(codec, 0x14, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001434 else
Takashi Iwai054d8672012-01-24 12:25:50 +01001435 update_power_state(codec, 0x18, parm);
1436 update_power_state(codec, 0x34, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001437
1438 /* Mono Out */
1439 present = snd_hda_jack_detect(codec, 0x26);
1440
1441 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08001442 if (spec->codec_type == VT1802) {
1443 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001444 update_power_state(codec, 0x33, parm);
1445 update_power_state(codec, 0x1c, parm);
1446 update_power_state(codec, 0x3c, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001447 } else {
1448 /* PW15 (31h), MW8(17h), MUX8(3bh) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001449 update_power_state(codec, 0x31, parm);
1450 update_power_state(codec, 0x17, parm);
1451 update_power_state(codec, 0x3b, parm);
Lydia Wang118909562011-03-23 17:57:34 +08001452 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001453 /* MW9 (21h) */
1454 if (imux_is_smixer || !is_aa_path_mute(codec))
Takashi Iwai054d8672012-01-24 12:25:50 +01001455 update_power_state(codec, 0x21, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001456 else
Takashi Iwai054d8672012-01-24 12:25:50 +01001457 update_power_state(codec, 0x21, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001458}
Lydia Wang25eaba22009-10-10 19:08:43 +08001459
David Henningsson4b527b62012-09-18 14:26:59 +02001460/*
1461 * pin fix-up
1462 */
1463enum {
1464 VIA_FIXUP_INTMIC_BOOST,
Takashi Iwaid5266122012-11-07 10:40:36 +01001465 VIA_FIXUP_ASUS_G75,
David Henningsson4b527b62012-09-18 14:26:59 +02001466};
1467
1468static void via_fixup_intmic_boost(struct hda_codec *codec,
1469 const struct hda_fixup *fix, int action)
1470{
1471 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1472 override_mic_boost(codec, 0x30, 0, 2, 40);
1473}
1474
1475static const struct hda_fixup via_fixups[] = {
1476 [VIA_FIXUP_INTMIC_BOOST] = {
1477 .type = HDA_FIXUP_FUNC,
1478 .v.func = via_fixup_intmic_boost,
1479 },
Takashi Iwaid5266122012-11-07 10:40:36 +01001480 [VIA_FIXUP_ASUS_G75] = {
1481 .type = HDA_FIXUP_PINS,
1482 .v.pins = (const struct hda_pintbl[]) {
1483 /* set 0x24 and 0x33 as speakers */
1484 { 0x24, 0x991301f0 },
1485 { 0x33, 0x991301f1 }, /* subwoofer */
1486 { }
1487 }
1488 },
David Henningsson4b527b62012-09-18 14:26:59 +02001489};
1490
1491static const struct snd_pci_quirk vt2002p_fixups[] = {
Takashi Iwaid5266122012-11-07 10:40:36 +01001492 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
David Henningsson4b527b62012-09-18 14:26:59 +02001493 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
1494 {}
1495};
1496
Takashi Iwaief4da452012-11-07 10:37:48 +01001497/* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
1498 * Replace this with mixer NID 0x1c
1499 */
1500static void fix_vt1802_connections(struct hda_codec *codec)
1501{
1502 static hda_nid_t conn_24[] = { 0x14, 0x1c };
1503 static hda_nid_t conn_33[] = { 0x1c };
1504
1505 snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
1506 snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
1507}
1508
Lydia Wang25eaba22009-10-10 19:08:43 +08001509/* patch for vt2002P */
1510static int patch_vt2002P(struct hda_codec *codec)
1511{
1512 struct via_spec *spec;
1513 int err;
1514
1515 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001516 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08001517 if (spec == NULL)
1518 return -ENOMEM;
1519
Takashi Iwaib3f60082013-01-07 12:27:36 +01001520 spec->gen.mixer_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001521 override_mic_boost(codec, 0x2b, 0, 3, 40);
1522 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwaief4da452012-11-07 10:37:48 +01001523 if (spec->codec_type == VT1802)
1524 fix_vt1802_connections(codec);
Takashi Iwai30b45032011-07-11 17:05:04 +02001525 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02001526
David Henningsson4b527b62012-09-18 14:26:59 +02001527 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
1528 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1529
Lydia Wang25eaba22009-10-10 19:08:43 +08001530 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001531 err = via_parse_auto_config(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08001532 if (err < 0) {
1533 via_free(codec);
1534 return err;
Lydia Wang25eaba22009-10-10 19:08:43 +08001535 }
1536
Lydia Wang118909562011-03-23 17:57:34 +08001537 if (spec->codec_type == VT1802)
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001538 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08001539 else
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001540 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08001541
Lydia Wang25eaba22009-10-10 19:08:43 +08001542 codec->patch_ops = via_patch_ops;
1543
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001544 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08001545 return 0;
1546}
Lydia Wangab6734e2009-10-10 19:08:46 +08001547
1548/* for vt1812 */
1549
Takashi Iwai096a8852011-06-20 12:09:02 +02001550static const struct hda_verb vt1812_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08001551 /* Enable Boost Volume backdoor */
1552 {0x1, 0xfb9, 0x24},
Lydia Wangab6734e2009-10-10 19:08:46 +08001553 /* Enable AOW0 to MW9 */
1554 {0x1, 0xfb8, 0xa8},
1555 { }
1556};
1557
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001558static void set_widgets_power_state_vt1812(struct hda_codec *codec)
1559{
1560 struct via_spec *spec = codec->spec;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001561 unsigned int parm;
1562 unsigned int present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001563 /* inputs */
1564 /* PW 5/6/7 (29h/2ah/2bh) */
1565 parm = AC_PWRST_D3;
1566 set_pin_power_state(codec, 0x29, &parm);
1567 set_pin_power_state(codec, 0x2a, &parm);
1568 set_pin_power_state(codec, 0x2b, &parm);
1569 parm = AC_PWRST_D0;
1570 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01001571 update_power_state(codec, 0x1e, parm);
1572 update_power_state(codec, 0x1f, parm);
1573 update_power_state(codec, 0x10, parm);
1574 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001575
1576 /* outputs */
1577 /* AOW0 (8h)*/
Takashi Iwai054d8672012-01-24 12:25:50 +01001578 update_power_state(codec, 0x8, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001579
1580 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1581 parm = AC_PWRST_D3;
1582 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001583 update_power_state(codec, 0x18, parm);
1584 update_power_state(codec, 0x38, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001585
1586 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1587 parm = AC_PWRST_D3;
1588 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001589 update_power_state(codec, 0x15, parm);
1590 update_power_state(codec, 0x35, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001591 if (spec->gen.indep_hp_enabled)
Takashi Iwai054d8672012-01-24 12:25:50 +01001592 update_power_state(codec, 0x9, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001593
1594 /* Internal Speaker */
1595 /* PW0 (24h), MW0(14h), MUX0(34h) */
1596 present = snd_hda_jack_detect(codec, 0x25);
1597
1598 parm = AC_PWRST_D3;
1599 set_pin_power_state(codec, 0x24, &parm);
1600 if (present) {
Takashi Iwai054d8672012-01-24 12:25:50 +01001601 update_power_state(codec, 0x14, AC_PWRST_D3);
1602 update_power_state(codec, 0x34, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001603 } else {
Takashi Iwai054d8672012-01-24 12:25:50 +01001604 update_power_state(codec, 0x14, AC_PWRST_D0);
1605 update_power_state(codec, 0x34, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001606 }
1607
1608
1609 /* Mono Out */
1610 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1611 present = snd_hda_jack_detect(codec, 0x28);
1612
1613 parm = AC_PWRST_D3;
1614 set_pin_power_state(codec, 0x31, &parm);
1615 if (present) {
Takashi Iwai054d8672012-01-24 12:25:50 +01001616 update_power_state(codec, 0x1c, AC_PWRST_D3);
1617 update_power_state(codec, 0x3c, AC_PWRST_D3);
1618 update_power_state(codec, 0x3e, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001619 } else {
Takashi Iwai054d8672012-01-24 12:25:50 +01001620 update_power_state(codec, 0x1c, AC_PWRST_D0);
1621 update_power_state(codec, 0x3c, AC_PWRST_D0);
1622 update_power_state(codec, 0x3e, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001623 }
1624
1625 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1626 parm = AC_PWRST_D3;
1627 set_pin_power_state(codec, 0x33, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01001628 update_power_state(codec, 0x1d, parm);
1629 update_power_state(codec, 0x3d, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001630
1631}
Lydia Wangab6734e2009-10-10 19:08:46 +08001632
1633/* patch for vt1812 */
1634static int patch_vt1812(struct hda_codec *codec)
1635{
1636 struct via_spec *spec;
1637 int err;
1638
1639 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001640 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08001641 if (spec == NULL)
1642 return -ENOMEM;
1643
Takashi Iwaib3f60082013-01-07 12:27:36 +01001644 spec->gen.mixer_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02001645 override_mic_boost(codec, 0x2b, 0, 3, 40);
1646 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02001647 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02001648
Lydia Wangab6734e2009-10-10 19:08:46 +08001649 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02001650 err = via_parse_auto_config(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08001651 if (err < 0) {
1652 via_free(codec);
1653 return err;
Lydia Wangab6734e2009-10-10 19:08:46 +08001654 }
1655
Takashi Iwai096a8852011-06-20 12:09:02 +02001656 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
Lydia Wangab6734e2009-10-10 19:08:46 +08001657
Lydia Wangab6734e2009-10-10 19:08:46 +08001658 codec->patch_ops = via_patch_ops;
1659
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001660 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08001661 return 0;
1662}
1663
Lydia Wang43737e02012-12-10 18:28:11 +08001664/* patch for vt3476 */
1665
1666static const struct hda_verb vt3476_init_verbs[] = {
1667 /* Enable DMic 8/16/32K */
1668 {0x1, 0xF7B, 0x30},
1669 /* Enable Boost Volume backdoor */
1670 {0x1, 0xFB9, 0x20},
1671 /* Enable AOW-MW9 path */
1672 {0x1, 0xFB8, 0x10},
1673 { }
1674};
1675
1676static void set_widgets_power_state_vt3476(struct hda_codec *codec)
1677{
1678 struct via_spec *spec = codec->spec;
1679 int imux_is_smixer;
1680 unsigned int parm, parm2;
1681 /* MUX10 (1eh) = stereo mixer */
1682 imux_is_smixer =
1683 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
1684 /* inputs */
1685 /* PW 5/6/7 (29h/2ah/2bh) */
1686 parm = AC_PWRST_D3;
1687 set_pin_power_state(codec, 0x29, &parm);
1688 set_pin_power_state(codec, 0x2a, &parm);
1689 set_pin_power_state(codec, 0x2b, &parm);
1690 if (imux_is_smixer)
1691 parm = AC_PWRST_D0;
1692 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1693 update_power_state(codec, 0x1e, parm);
1694 update_power_state(codec, 0x1f, parm);
1695 update_power_state(codec, 0x10, parm);
1696 update_power_state(codec, 0x11, parm);
1697
1698 /* outputs */
1699 /* PW3 (27h), MW3(37h), AOW3 (bh) */
1700 if (spec->codec_type == VT1705CF) {
1701 parm = AC_PWRST_D3;
1702 update_power_state(codec, 0x27, parm);
1703 update_power_state(codec, 0x37, parm);
1704 } else {
1705 parm = AC_PWRST_D3;
1706 set_pin_power_state(codec, 0x27, &parm);
1707 update_power_state(codec, 0x37, parm);
1708 }
1709
1710 /* PW2 (26h), MW2(36h), AOW2 (ah) */
1711 parm = AC_PWRST_D3;
1712 set_pin_power_state(codec, 0x26, &parm);
1713 update_power_state(codec, 0x36, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001714 if (smart51_enabled(codec)) {
Lydia Wang43737e02012-12-10 18:28:11 +08001715 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
1716 set_pin_power_state(codec, 0x2b, &parm);
1717 update_power_state(codec, 0x3b, parm);
1718 update_power_state(codec, 0x1b, parm);
1719 }
1720 update_conv_power_state(codec, 0xa, parm, 2);
1721
1722 /* PW1 (25h), MW1(35h), AOW1 (9h) */
1723 parm = AC_PWRST_D3;
1724 set_pin_power_state(codec, 0x25, &parm);
1725 update_power_state(codec, 0x35, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001726 if (smart51_enabled(codec)) {
Lydia Wang43737e02012-12-10 18:28:11 +08001727 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
1728 set_pin_power_state(codec, 0x2a, &parm);
1729 update_power_state(codec, 0x3a, parm);
1730 update_power_state(codec, 0x1a, parm);
1731 }
1732 update_conv_power_state(codec, 0x9, parm, 1);
1733
1734 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
1735 parm = AC_PWRST_D3;
1736 set_pin_power_state(codec, 0x28, &parm);
1737 update_power_state(codec, 0x38, parm);
1738 update_power_state(codec, 0x18, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001739 if (spec->gen.indep_hp_enabled)
Lydia Wang43737e02012-12-10 18:28:11 +08001740 update_conv_power_state(codec, 0xb, parm, 3);
1741 parm2 = parm; /* for pin 0x0b */
1742
1743 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
1744 parm = AC_PWRST_D3;
1745 set_pin_power_state(codec, 0x24, &parm);
1746 update_power_state(codec, 0x34, parm);
Takashi Iwaib3f60082013-01-07 12:27:36 +01001747 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
Lydia Wang43737e02012-12-10 18:28:11 +08001748 parm = parm2;
1749 update_conv_power_state(codec, 0x8, parm, 0);
1750 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1751 update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
1752}
1753
1754static int patch_vt3476(struct hda_codec *codec)
1755{
1756 struct via_spec *spec;
1757 int err;
1758
1759 /* create a codec specific record */
1760 spec = via_new_spec(codec);
1761 if (spec == NULL)
1762 return -ENOMEM;
1763
Takashi Iwaib3f60082013-01-07 12:27:36 +01001764 spec->gen.mixer_nid = 0x3f;
Lydia Wang43737e02012-12-10 18:28:11 +08001765 add_secret_dac_path(codec);
1766
1767 /* automatic parse from the BIOS config */
1768 err = via_parse_auto_config(codec);
1769 if (err < 0) {
1770 via_free(codec);
1771 return err;
1772 }
1773
1774 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
1775
1776 codec->patch_ops = via_patch_ops;
1777
1778 spec->set_widgets_power_state = set_widgets_power_state_vt3476;
1779
1780 return 0;
1781}
1782
Joseph Chanc577b8a2006-11-29 15:29:40 +01001783/*
1784 * patch entries
1785 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001786static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01001787 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
1788 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
1789 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
1790 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
1791 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001792 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001793 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001794 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001795 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001796 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001797 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001798 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001799 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001800 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001801 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001802 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001803 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001804 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001805 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001806 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01001807 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001808 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001809 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001810 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001811 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001812 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001813 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001814 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001815 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001816 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001817 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001818 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001819 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001820 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001821 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02001822 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01001823 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001824 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001825 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001826 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001827 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001828 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001829 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001830 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08001831 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08001832 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001833 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001834 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001835 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001836 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001837 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08001838 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01001839 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001840 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001841 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001842 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001843 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001844 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001845 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001846 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001847 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001848 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001849 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001850 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001851 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001852 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01001853 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08001854 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08001855 { .id = 0x11060428, .name = "VT1718S",
1856 .patch = patch_vt1718S},
1857 { .id = 0x11064428, .name = "VT1718S",
1858 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08001859 { .id = 0x11060441, .name = "VT2020",
1860 .patch = patch_vt1718S},
1861 { .id = 0x11064441, .name = "VT1828S",
1862 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08001863 { .id = 0x11060433, .name = "VT1716S",
1864 .patch = patch_vt1716S},
1865 { .id = 0x1106a721, .name = "VT1716S",
1866 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08001867 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
1868 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08001869 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08001870 { .id = 0x11060440, .name = "VT1818S",
1871 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08001872 { .id = 0x11060446, .name = "VT1802",
1873 .patch = patch_vt2002P},
1874 { .id = 0x11068446, .name = "VT1802",
1875 .patch = patch_vt2002P},
Lydia Wang43737e02012-12-10 18:28:11 +08001876 { .id = 0x11064760, .name = "VT1705CF",
1877 .patch = patch_vt3476},
Lydia Wang6121b842012-12-10 19:03:26 +08001878 { .id = 0x11064761, .name = "VT1708SCE",
1879 .patch = patch_vt3476},
1880 { .id = 0x11064762, .name = "VT1808",
1881 .patch = patch_vt3476},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001882 {} /* terminator */
1883};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001884
1885MODULE_ALIAS("snd-hda-codec-id:1106*");
1886
1887static struct hda_codec_preset_list via_list = {
1888 .preset = snd_hda_preset_via,
1889 .owner = THIS_MODULE,
1890};
1891
1892MODULE_LICENSE("GPL");
1893MODULE_DESCRIPTION("VIA HD-audio codec");
1894
1895static int __init patch_via_init(void)
1896{
1897 return snd_hda_add_codec_preset(&via_list);
1898}
1899
1900static void __exit patch_via_exit(void)
1901{
1902 snd_hda_delete_codec_preset(&via_list);
1903}
1904
1905module_init(patch_via_init)
1906module_exit(patch_via_exit)