blob: d3c852ab105e10cf4b6092dec32ece86a44bdb57 [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"
Joseph Chanc577b8a2006-11-29 15:29:40 +010059
Joseph Chanc577b8a2006-11-29 15:29:40 +010060/* Pin Widget NID */
Harald Welted949cac2008-09-09 15:56:01 +080061#define VT1708_HP_PIN_NID 0x20
62#define VT1708_CD_PIN_NID 0x24
Joseph Chanc577b8a2006-11-29 15:29:40 +010063
Harald Welted7426322008-09-15 22:43:23 +080064enum VIA_HDA_CODEC {
65 UNKNOWN = -1,
66 VT1708,
67 VT1709_10CH,
68 VT1709_6CH,
69 VT1708B_8CH,
70 VT1708B_4CH,
71 VT1708S,
Lydia Wang518bf3b2009-10-10 19:07:29 +080072 VT1708BCE,
Harald Welted7426322008-09-15 22:43:23 +080073 VT1702,
Lydia Wangeb7188c2009-10-10 19:08:34 +080074 VT1718S,
Lydia Wangf3db4232009-10-10 19:08:41 +080075 VT1716S,
Lydia Wang25eaba22009-10-10 19:08:43 +080076 VT2002P,
Lydia Wangab6734e2009-10-10 19:08:46 +080077 VT1812,
Lydia Wang118909562011-03-23 17:57:34 +080078 VT1802,
Lydia Wang43737e02012-12-10 18:28:11 +080079 VT1705CF,
Lydia Wang6121b842012-12-10 19:03:26 +080080 VT1808,
Harald Welted7426322008-09-15 22:43:23 +080081 CODEC_TYPES,
82};
83
Lydia Wang118909562011-03-23 17:57:34 +080084#define VT2002P_COMPATIBLE(spec) \
85 ((spec)->codec_type == VT2002P ||\
86 (spec)->codec_type == VT1812 ||\
87 (spec)->codec_type == VT1802)
88
Takashi Iwai8e3679d2011-06-21 09:01:36 +020089#define MAX_NID_PATH_DEPTH 5
90
Takashi Iwai09a9ad692011-06-21 15:57:44 +020091/* output-path: DAC -> ... -> pin
92 * idx[] contains the source index number of the next widget;
93 * e.g. idx[0] is the index of the DAC selected by path[1] widget
94 * multi[] indicates whether it's a selector widget with multi-connectors
95 * (i.e. the connection selection is mandatory)
96 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
97 */
Takashi Iwai4a796162011-06-17 17:53:38 +020098struct nid_path {
99 int depth;
Takashi Iwai8e3679d2011-06-21 09:01:36 +0200100 hda_nid_t path[MAX_NID_PATH_DEPTH];
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200101 unsigned char idx[MAX_NID_PATH_DEPTH];
102 unsigned char multi[MAX_NID_PATH_DEPTH];
103 unsigned int vol_ctl;
104 unsigned int mute_ctl;
Takashi Iwai4a796162011-06-17 17:53:38 +0200105};
106
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200107/* input-path */
108struct via_input {
109 hda_nid_t pin; /* input-pin or aa-mix */
110 int adc_idx; /* ADC index to be used */
111 int mux_idx; /* MUX index (if any) */
112 const char *label; /* input-source label */
113};
114
Takashi Iwaide6c74f2011-07-04 14:46:42 +0200115#define VIA_MAX_ADCS 3
116
Takashi Iwai3b607e32011-07-18 16:54:40 +0200117enum {
118 STREAM_MULTI_OUT = (1 << 0),
119 STREAM_INDEP_HP = (1 << 1),
120};
121
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800122struct via_spec {
123 /* codec parameterization */
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200124 const struct snd_kcontrol_new *mixers[6];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800125 unsigned int num_mixers;
126
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200127 const struct hda_verb *init_verbs[5];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800128 unsigned int num_iverbs;
129
Takashi Iwai82673bc2011-06-17 16:24:21 +0200130 char stream_name_analog[32];
Takashi Iwai7eb56e82011-06-18 16:40:14 +0200131 char stream_name_hp[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200132 const struct hda_pcm_stream *stream_analog_playback;
133 const struct hda_pcm_stream *stream_analog_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800134
Takashi Iwai82673bc2011-06-17 16:24:21 +0200135 char stream_name_digital[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200136 const struct hda_pcm_stream *stream_digital_playback;
137 const struct hda_pcm_stream *stream_digital_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800138
139 /* playback */
140 struct hda_multi_out multiout;
141 hda_nid_t slave_dig_outs[2];
Takashi Iwaiece8d042011-06-19 16:24:21 +0200142 hda_nid_t hp_dac_nid;
Takashi Iwai3214b962011-07-18 12:49:25 +0200143 hda_nid_t speaker_dac_nid;
144 int hp_indep_shared; /* indep HP-DAC is shared with side ch */
Takashi Iwai3b607e32011-07-18 16:54:40 +0200145 int opened_streams; /* STREAM_* bits */
146 int active_streams; /* STREAM_* bits */
Takashi Iwai3214b962011-07-18 12:49:25 +0200147 int aamix_mode; /* loopback is enabled for output-path? */
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800148
Takashi Iwai3214b962011-07-18 12:49:25 +0200149 /* Output-paths:
150 * There are different output-paths depending on the setup.
151 * out_path, hp_path and speaker_path are primary paths. If both
152 * direct DAC and aa-loopback routes are available, these contain
153 * the former paths. Meanwhile *_mix_path contain the paths with
154 * loopback mixer. (Since the loopback is only for front channel,
155 * no out_mix_path for surround channels.)
156 * The HP output has another path, hp_indep_path, which is used in
157 * the independent-HP mode.
158 */
Takashi Iwaide6c74f2011-07-04 14:46:42 +0200159 struct nid_path out_path[HDA_SIDE + 1];
Takashi Iwai3214b962011-07-18 12:49:25 +0200160 struct nid_path out_mix_path;
Takashi Iwai4a796162011-06-17 17:53:38 +0200161 struct nid_path hp_path;
Takashi Iwai3214b962011-07-18 12:49:25 +0200162 struct nid_path hp_mix_path;
163 struct nid_path hp_indep_path;
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200164 struct nid_path speaker_path;
Takashi Iwai3214b962011-07-18 12:49:25 +0200165 struct nid_path speaker_mix_path;
Takashi Iwai4a796162011-06-17 17:53:38 +0200166
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800167 /* capture */
168 unsigned int num_adc_nids;
Takashi Iwaide6c74f2011-07-04 14:46:42 +0200169 hda_nid_t adc_nids[VIA_MAX_ADCS];
170 hda_nid_t mux_nids[VIA_MAX_ADCS];
Takashi Iwai620e2b22011-06-17 17:19:19 +0200171 hda_nid_t aa_mix_nid;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800172 hda_nid_t dig_in_nid;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800173
174 /* capture source */
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200175 bool dyn_adc_switch;
176 int num_inputs;
177 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
Takashi Iwaide6c74f2011-07-04 14:46:42 +0200178 unsigned int cur_mux[VIA_MAX_ADCS];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800179
Takashi Iwai3b607e32011-07-18 16:54:40 +0200180 /* dynamic DAC switching */
181 unsigned int cur_dac_stream_tag;
182 unsigned int cur_dac_format;
183 unsigned int cur_hp_stream_tag;
184 unsigned int cur_hp_format;
185
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200186 /* dynamic ADC switching */
187 hda_nid_t cur_adc;
188 unsigned int cur_adc_stream_tag;
189 unsigned int cur_adc_format;
190
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800191 /* PCM information */
192 struct hda_pcm pcm_rec[3];
193
194 /* dynamic controls, init_verbs and input_mux */
195 struct auto_pin_cfg autocfg;
196 struct snd_array kctls;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800197 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
198
199 /* HP mode source */
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800200 unsigned int hp_independent_mode;
Lydia Wangf3db4232009-10-10 19:08:41 +0800201 unsigned int dmic_enabled;
Takashi Iwai24088a52011-06-17 16:59:21 +0200202 unsigned int no_pin_power_ctl;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800203 enum VIA_HDA_CODEC codec_type;
204
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100205 /* analog low-power control */
206 bool alc_mode;
207
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200208 /* smart51 setup */
209 unsigned int smart51_nums;
210 hda_nid_t smart51_pins[2];
211 int smart51_idxs[2];
212 const char *smart51_labels[2];
213 unsigned int smart51_enabled;
214
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800215 /* work to check hp jack state */
216 struct hda_codec *codec;
217 struct delayed_work vt1708_hp_work;
Takashi Iwai187d3332011-11-24 16:33:09 +0100218 int hp_work_active;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200219 int vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800220 int vt1708_hp_present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800221
222 void (*set_widgets_power_state)(struct hda_codec *codec);
Lydia Wang43737e02012-12-10 18:28:11 +0800223 unsigned int dac_stream_tag[4];
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800224
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800225 struct hda_loopback_check loopback;
Takashi Iwai13af8e72011-06-20 14:05:46 +0200226 int num_loopbacks;
227 struct hda_amp_list loopback_list[8];
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200228
229 /* bind capture-volume */
230 struct hda_bind_ctls *bind_cap_vol;
231 struct hda_bind_ctls *bind_cap_sw;
Takashi Iwai3b607e32011-07-18 16:54:40 +0200232
233 struct mutex config_mutex;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800234};
235
Lydia Wang0341ccd2011-03-22 16:25:03 +0800236static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100237static struct via_spec * via_new_spec(struct hda_codec *codec)
238{
239 struct via_spec *spec;
240
241 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
242 if (spec == NULL)
243 return NULL;
244
Takashi Iwai361dab32012-05-09 14:35:27 +0200245 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
Takashi Iwai3b607e32011-07-18 16:54:40 +0200246 mutex_init(&spec->config_mutex);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100247 codec->spec = spec;
248 spec->codec = codec;
Lydia Wang0341ccd2011-03-22 16:25:03 +0800249 spec->codec_type = get_codec_type(codec);
250 /* VT1708BCE & VT1708S are almost same */
251 if (spec->codec_type == VT1708BCE)
252 spec->codec_type = VT1708S;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100253 return spec;
254}
255
Lydia Wang744ff5f2009-10-10 19:07:26 +0800256static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800257{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800258 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800259 u16 ven_id = vendor_id >> 16;
260 u16 dev_id = vendor_id & 0xffff;
261 enum VIA_HDA_CODEC codec_type;
262
263 /* get codec type */
264 if (ven_id != 0x1106)
265 codec_type = UNKNOWN;
266 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
267 codec_type = VT1708;
268 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
269 codec_type = VT1709_10CH;
270 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
271 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800272 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800273 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800274 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
275 codec_type = VT1708BCE;
276 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800277 codec_type = VT1708B_4CH;
278 else if ((dev_id & 0xfff) == 0x397
279 && (dev_id >> 12) < 8)
280 codec_type = VT1708S;
281 else if ((dev_id & 0xfff) == 0x398
282 && (dev_id >> 12) < 8)
283 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800284 else if ((dev_id & 0xfff) == 0x428
285 && (dev_id >> 12) < 8)
286 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800287 else if (dev_id == 0x0433 || dev_id == 0xa721)
288 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800289 else if (dev_id == 0x0441 || dev_id == 0x4441)
290 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800291 else if (dev_id == 0x0438 || dev_id == 0x4438)
292 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800293 else if (dev_id == 0x0448)
294 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800295 else if (dev_id == 0x0440)
296 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800297 else if ((dev_id & 0xfff) == 0x446)
298 codec_type = VT1802;
Lydia Wang43737e02012-12-10 18:28:11 +0800299 else if (dev_id == 0x4760)
300 codec_type = VT1705CF;
Lydia Wang6121b842012-12-10 19:03:26 +0800301 else if (dev_id == 0x4761 || dev_id == 0x4762)
302 codec_type = VT1808;
Harald Welted7426322008-09-15 22:43:23 +0800303 else
304 codec_type = UNKNOWN;
305 return codec_type;
306};
307
Lydia Wangec7e7e42011-03-24 12:43:44 +0800308#define VIA_JACK_EVENT 0x20
Harald Welte69e52a82008-09-09 15:57:32 +0800309#define VIA_HP_EVENT 0x01
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200310#define VIA_LINE_EVENT 0x03
Harald Welte69e52a82008-09-09 15:57:32 +0800311
Joseph Chanc577b8a2006-11-29 15:29:40 +0100312enum {
313 VIA_CTL_WIDGET_VOL,
314 VIA_CTL_WIDGET_MUTE,
Lydia Wangf5271102009-10-10 19:07:35 +0800315 VIA_CTL_WIDGET_ANALOG_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100316};
317
Takashi Iwaiada509e2011-06-20 15:40:19 +0200318static void analog_low_current_mode(struct hda_codec *codec);
319static bool is_aa_path_mute(struct hda_codec *codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800320
Takashi Iwai187d3332011-11-24 16:33:09 +0100321#define hp_detect_with_aa(codec) \
322 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
323 !is_aa_path_mute(codec))
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800324
325static void vt1708_stop_hp_work(struct via_spec *spec)
326{
327 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
328 return;
Takashi Iwai187d3332011-11-24 16:33:09 +0100329 if (spec->hp_work_active) {
330 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 1);
331 cancel_delayed_work_sync(&spec->vt1708_hp_work);
332 spec->hp_work_active = 0;
333 }
334}
335
336static void vt1708_update_hp_work(struct via_spec *spec)
337{
338 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800339 return;
Takashi Iwai187d3332011-11-24 16:33:09 +0100340 if (spec->vt1708_jack_detect &&
341 (spec->active_streams || hp_detect_with_aa(spec->codec))) {
342 if (!spec->hp_work_active) {
343 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 0);
344 schedule_delayed_work(&spec->vt1708_hp_work,
345 msecs_to_jiffies(100));
346 spec->hp_work_active = 1;
347 }
348 } else if (!hp_detect_with_aa(spec->codec))
349 vt1708_stop_hp_work(spec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800350}
Lydia Wangf5271102009-10-10 19:07:35 +0800351
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800352static void set_widgets_power_state(struct hda_codec *codec)
353{
354 struct via_spec *spec = codec->spec;
355 if (spec->set_widgets_power_state)
356 spec->set_widgets_power_state(codec);
357}
Lydia Wang25eaba22009-10-10 19:08:43 +0800358
Lydia Wangf5271102009-10-10 19:07:35 +0800359static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
360 struct snd_ctl_elem_value *ucontrol)
361{
362 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
363 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
364
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800365 set_widgets_power_state(codec);
Takashi Iwaiada509e2011-06-20 15:40:19 +0200366 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
Takashi Iwai187d3332011-11-24 16:33:09 +0100367 vt1708_update_hp_work(codec->spec);
Lydia Wangf5271102009-10-10 19:07:35 +0800368 return change;
369}
370
371/* modify .put = snd_hda_mixer_amp_switch_put */
372#define ANALOG_INPUT_MUTE \
373 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
374 .name = NULL, \
375 .index = 0, \
376 .info = snd_hda_mixer_amp_switch_info, \
377 .get = snd_hda_mixer_amp_switch_get, \
378 .put = analog_input_switch_put, \
379 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
380
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200381static const struct snd_kcontrol_new via_control_templates[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100382 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
383 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Lydia Wangf5271102009-10-10 19:07:35 +0800384 ANALOG_INPUT_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100385};
386
Lydia Wangab6734e2009-10-10 19:08:46 +0800387
Joseph Chanc577b8a2006-11-29 15:29:40 +0100388/* add dynamic controls */
Takashi Iwai291c9e32011-06-17 16:15:26 +0200389static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
390 const struct snd_kcontrol_new *tmpl,
391 const char *name)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100392{
393 struct snd_kcontrol_new *knew;
394
Takashi Iwai603c4012008-07-30 15:01:44 +0200395 knew = snd_array_new(&spec->kctls);
396 if (!knew)
Takashi Iwai291c9e32011-06-17 16:15:26 +0200397 return NULL;
398 *knew = *tmpl;
399 if (!name)
400 name = tmpl->name;
401 if (name) {
402 knew->name = kstrdup(name, GFP_KERNEL);
403 if (!knew->name)
404 return NULL;
405 }
406 return knew;
407}
408
409static int __via_add_control(struct via_spec *spec, int type, const char *name,
410 int idx, unsigned long val)
411{
412 struct snd_kcontrol_new *knew;
413
414 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
415 if (!knew)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100416 return -ENOMEM;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +0200417 knew->index = idx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100418 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100419 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100420 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100421 return 0;
422}
423
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200424#define via_add_control(spec, type, name, val) \
425 __via_add_control(spec, type, name, 0, val)
426
Takashi Iwai291c9e32011-06-17 16:15:26 +0200427#define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100428
Takashi Iwai603c4012008-07-30 15:01:44 +0200429static void via_free_kctls(struct hda_codec *codec)
430{
431 struct via_spec *spec = codec->spec;
432
433 if (spec->kctls.list) {
434 struct snd_kcontrol_new *kctl = spec->kctls.list;
435 int i;
436 for (i = 0; i < spec->kctls.used; i++)
437 kfree(kctl[i].name);
438 }
439 snd_array_free(&spec->kctls);
440}
441
Joseph Chanc577b8a2006-11-29 15:29:40 +0100442/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800443static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200444 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100445{
446 char name[32];
447 int err;
448
449 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200450 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100451 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
452 if (err < 0)
453 return err;
454 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200455 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100456 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
457 if (err < 0)
458 return err;
459 return 0;
460}
461
Takashi Iwai5d417622011-06-20 11:32:27 +0200462#define get_connection_index(codec, mux, nid) \
Takashi Iwai8d087c72011-06-28 12:45:47 +0200463 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai5d417622011-06-20 11:32:27 +0200464
Takashi Iwai8df2a312011-06-21 11:48:29 +0200465static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
466 unsigned int mask)
467{
Takashi Iwaia934d5a2011-06-21 14:22:14 +0200468 unsigned int caps;
469 if (!nid)
470 return false;
471 caps = get_wcaps(codec, nid);
Takashi Iwai8df2a312011-06-21 11:48:29 +0200472 if (dir == HDA_INPUT)
473 caps &= AC_WCAP_IN_AMP;
474 else
475 caps &= AC_WCAP_OUT_AMP;
476 if (!caps)
477 return false;
478 if (query_amp_caps(codec, nid, dir) & mask)
479 return true;
480 return false;
481}
482
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200483#define have_mute(codec, nid, dir) \
484 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
Takashi Iwai8df2a312011-06-21 11:48:29 +0200485
Lydia Wangd69607b32011-07-08 14:02:52 +0800486/* enable/disable the output-route mixers */
487static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai3214b962011-07-18 12:49:25 +0200488 hda_nid_t mix_nid, int idx, bool enable)
Lydia Wangd69607b32011-07-08 14:02:52 +0800489{
490 int i, num, val;
Lydia Wangd69607b32011-07-08 14:02:52 +0800491
492 if (!path)
493 return;
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200494 num = snd_hda_get_num_conns(codec, mix_nid);
Lydia Wangd69607b32011-07-08 14:02:52 +0800495 for (i = 0; i < num; i++) {
Takashi Iwai3214b962011-07-18 12:49:25 +0200496 if (i == idx)
497 val = AMP_IN_UNMUTE(i);
498 else
499 val = AMP_IN_MUTE(i);
Lydia Wangd69607b32011-07-08 14:02:52 +0800500 snd_hda_codec_write(codec, mix_nid, 0,
501 AC_VERB_SET_AMP_GAIN_MUTE, val);
502 }
503}
504
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200505/* enable/disable the output-route */
506static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
507 bool enable, bool force)
Takashi Iwai5d417622011-06-20 11:32:27 +0200508{
Lydia Wangd69607b32011-07-08 14:02:52 +0800509 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200510 int i;
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200511 for (i = 0; i < path->depth; i++) {
512 hda_nid_t src, dst;
513 int idx = path->idx[i];
514 src = path->path[i];
515 if (i < path->depth - 1)
516 dst = path->path[i + 1];
517 else
518 dst = 0;
519 if (enable && path->multi[i])
520 snd_hda_codec_write(codec, dst, 0,
521 AC_VERB_SET_CONNECT_SEL, idx);
Takashi Iwai3214b962011-07-18 12:49:25 +0200522 if (!force && (dst == spec->aa_mix_nid))
Lydia Wange5e14682011-07-01 10:55:07 +0800523 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +0200524 if (have_mute(codec, dst, HDA_INPUT))
525 activate_output_mix(codec, path, dst, idx, enable);
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200526 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
527 continue;
528 if (have_mute(codec, src, HDA_OUTPUT)) {
529 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
530 snd_hda_codec_write(codec, src, 0,
531 AC_VERB_SET_AMP_GAIN_MUTE, val);
532 }
533 }
Takashi Iwai5d417622011-06-20 11:32:27 +0200534}
535
536/* set the given pin as output */
537static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
538 int pin_type)
539{
540 if (!pin)
541 return;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200542 snd_hda_set_pin_ctl(codec, pin, pin_type);
Takashi Iwai5d417622011-06-20 11:32:27 +0200543 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
544 snd_hda_codec_write(codec, pin, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200545 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100546}
547
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200548static void via_auto_init_output(struct hda_codec *codec,
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200549 struct nid_path *path, int pin_type)
Takashi Iwai5d417622011-06-20 11:32:27 +0200550{
Takashi Iwai5d417622011-06-20 11:32:27 +0200551 unsigned int caps;
Lydia Wangd69607b32011-07-08 14:02:52 +0800552 hda_nid_t pin;
Takashi Iwai5d417622011-06-20 11:32:27 +0200553
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200554 if (!path->depth)
Takashi Iwai5d417622011-06-20 11:32:27 +0200555 return;
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200556 pin = path->path[path->depth - 1];
Takashi Iwai5d417622011-06-20 11:32:27 +0200557
558 init_output_pin(codec, pin, pin_type);
Takashi Iwai77e314f2012-02-22 12:34:08 +0100559 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
560 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
561 else
562 caps = 0;
Takashi Iwai5d417622011-06-20 11:32:27 +0200563 if (caps & AC_AMPCAP_MUTE) {
564 unsigned int val;
565 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
566 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
567 AMP_OUT_MUTE | val);
568 }
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200569 activate_output_path(codec, path, true, true); /* force on */
Takashi Iwai5d417622011-06-20 11:32:27 +0200570}
571
Joseph Chanc577b8a2006-11-29 15:29:40 +0100572static void via_auto_init_multi_out(struct hda_codec *codec)
573{
574 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200575 struct nid_path *path;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100576 int i;
577
Takashi Iwai3214b962011-07-18 12:49:25 +0200578 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
579 path = &spec->out_path[i];
580 if (!i && spec->aamix_mode && spec->out_mix_path.depth)
581 path = &spec->out_mix_path;
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200582 via_auto_init_output(codec, path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200583 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100584}
585
Takashi Iwai020066d2011-07-21 13:45:56 +0200586/* deactivate the inactive headphone-paths */
587static void deactivate_hp_paths(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100588{
589 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200590 int shared = spec->hp_indep_shared;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100591
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200592 if (spec->hp_independent_mode) {
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200593 activate_output_path(codec, &spec->hp_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200594 activate_output_path(codec, &spec->hp_mix_path, false, false);
595 if (shared)
596 activate_output_path(codec, &spec->out_path[shared],
597 false, false);
Takashi Iwai020066d2011-07-21 13:45:56 +0200598 } else if (spec->aamix_mode || !spec->hp_path.depth) {
599 activate_output_path(codec, &spec->hp_indep_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200600 activate_output_path(codec, &spec->hp_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200601 } else {
Takashi Iwai020066d2011-07-21 13:45:56 +0200602 activate_output_path(codec, &spec->hp_indep_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200603 activate_output_path(codec, &spec->hp_mix_path, false, false);
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200604 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100605}
606
Takashi Iwai020066d2011-07-21 13:45:56 +0200607static void via_auto_init_hp_out(struct hda_codec *codec)
608{
609 struct via_spec *spec = codec->spec;
610
611 if (!spec->hp_path.depth) {
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200612 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200613 return;
614 }
615 deactivate_hp_paths(codec);
616 if (spec->hp_independent_mode)
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200617 via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200618 else if (spec->aamix_mode)
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200619 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200620 else
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200621 via_auto_init_output(codec, &spec->hp_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200622}
623
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200624static void via_auto_init_speaker_out(struct hda_codec *codec)
625{
626 struct via_spec *spec = codec->spec;
627
Takashi Iwai3214b962011-07-18 12:49:25 +0200628 if (!spec->autocfg.speaker_outs)
629 return;
630 if (!spec->speaker_path.depth) {
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200631 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200632 return;
633 }
634 if (!spec->aamix_mode) {
635 activate_output_path(codec, &spec->speaker_mix_path,
636 false, false);
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200637 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200638 } else {
639 activate_output_path(codec, &spec->speaker_path, false, false);
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200640 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200641 }
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200642}
643
Takashi Iwaif4a78282011-06-17 18:46:48 +0200644static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
Takashi Iwai6e969d92011-07-11 11:28:13 +0200645static void via_hp_automute(struct hda_codec *codec);
Clemens Ladisch32e01912010-07-12 16:28:50 +0200646
Joseph Chanc577b8a2006-11-29 15:29:40 +0100647static void via_auto_init_analog_input(struct hda_codec *codec)
648{
649 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200650 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai096a8852011-06-20 12:09:02 +0200651 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Clemens Ladisch32e01912010-07-12 16:28:50 +0200652 unsigned int ctl;
Takashi Iwai096a8852011-06-20 12:09:02 +0200653 int i, num_conns;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100654
Takashi Iwai096a8852011-06-20 12:09:02 +0200655 /* init ADCs */
656 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai77e314f2012-02-22 12:34:08 +0100657 hda_nid_t nid = spec->adc_nids[i];
658 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP) ||
659 !(query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE))
660 continue;
Takashi Iwai096a8852011-06-20 12:09:02 +0200661 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
662 AC_VERB_SET_AMP_GAIN_MUTE,
663 AMP_IN_UNMUTE(0));
664 }
665
666 /* init pins */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200667 for (i = 0; i < cfg->num_inputs; i++) {
668 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200669 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
Clemens Ladisch32e01912010-07-12 16:28:50 +0200670 ctl = PIN_OUT;
Takashi Iwai47408602012-04-20 13:06:53 +0200671 else {
Clemens Ladisch32e01912010-07-12 16:28:50 +0200672 ctl = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200673 if (cfg->inputs[i].type == AUTO_PIN_MIC)
674 ctl |= snd_hda_get_default_vref(codec, nid);
675 }
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200676 snd_hda_set_pin_ctl(codec, nid, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100677 }
Takashi Iwai096a8852011-06-20 12:09:02 +0200678
679 /* init input-src */
680 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200681 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
Takashi Iwaifc1156c2012-02-13 15:04:06 +0100682 /* secondary ADCs must have the unique MUX */
683 if (i > 0 && !spec->mux_nids[i])
684 break;
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200685 if (spec->mux_nids[adc_idx]) {
686 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
687 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
688 AC_VERB_SET_CONNECT_SEL,
689 mux_idx);
690 }
691 if (spec->dyn_adc_switch)
692 break; /* only one input-src */
Takashi Iwai096a8852011-06-20 12:09:02 +0200693 }
694
695 /* init aa-mixer */
696 if (!spec->aa_mix_nid)
697 return;
698 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
699 ARRAY_SIZE(conn));
700 for (i = 0; i < num_conns; i++) {
701 unsigned int caps = get_wcaps(codec, conn[i]);
702 if (get_wcaps_type(caps) == AC_WID_PIN)
703 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
704 AC_VERB_SET_AMP_GAIN_MUTE,
705 AMP_IN_MUTE(i));
706 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100707}
Lydia Wangf5271102009-10-10 19:07:35 +0800708
Takashi Iwai054d8672012-01-24 12:25:50 +0100709static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
710 unsigned int parm)
711{
712 if (snd_hda_codec_read(codec, nid, 0,
713 AC_VERB_GET_POWER_STATE, 0) == parm)
714 return;
715 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
716}
717
Lydia Wang43737e02012-12-10 18:28:11 +0800718static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
719 unsigned int parm, unsigned int index)
720{
721 struct via_spec *spec = codec->spec;
722 unsigned int format;
723 if (snd_hda_codec_read(codec, nid, 0,
724 AC_VERB_GET_POWER_STATE, 0) == parm)
725 return;
726 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
727 if (format && (spec->dac_stream_tag[index] != format))
728 spec->dac_stream_tag[index] = format;
729
730 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
731 if (parm == AC_PWRST_D0) {
732 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
733 if (!format && (spec->dac_stream_tag[index] != format))
734 snd_hda_codec_write(codec, nid, 0,
735 AC_VERB_SET_CHANNEL_STREAMID,
736 spec->dac_stream_tag[index]);
737 }
738}
739
Lydia Wangf5271102009-10-10 19:07:35 +0800740static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
741 unsigned int *affected_parm)
742{
743 unsigned parm;
744 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
745 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
746 >> AC_DEFCFG_MISC_SHIFT
747 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800748 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200749 unsigned present = 0;
750
751 no_presence |= spec->no_pin_power_ctl;
752 if (!no_presence)
753 present = snd_hda_jack_detect(codec, nid);
Takashi Iwaif4a78282011-06-17 18:46:48 +0200754 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
Lydia Wang1564b282009-10-10 19:07:52 +0800755 || ((no_presence || present)
756 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800757 *affected_parm = AC_PWRST_D0; /* if it's connected */
758 parm = AC_PWRST_D0;
759 } else
760 parm = AC_PWRST_D3;
761
Takashi Iwai054d8672012-01-24 12:25:50 +0100762 update_power_state(codec, nid, parm);
Lydia Wangf5271102009-10-10 19:07:35 +0800763}
764
Takashi Iwai24088a52011-06-17 16:59:21 +0200765static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
766 struct snd_ctl_elem_info *uinfo)
767{
Takashi Iwaidda415d2012-11-30 18:34:38 +0100768 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai24088a52011-06-17 16:59:21 +0200769}
770
771static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
772 struct snd_ctl_elem_value *ucontrol)
773{
774 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
775 struct via_spec *spec = codec->spec;
776 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
777 return 0;
778}
779
780static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
781 struct snd_ctl_elem_value *ucontrol)
782{
783 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
784 struct via_spec *spec = codec->spec;
785 unsigned int val = !ucontrol->value.enumerated.item[0];
786
787 if (val == spec->no_pin_power_ctl)
788 return 0;
789 spec->no_pin_power_ctl = val;
790 set_widgets_power_state(codec);
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100791 analog_low_current_mode(codec);
Takashi Iwai24088a52011-06-17 16:59:21 +0200792 return 1;
793}
794
795static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
797 .name = "Dynamic Power-Control",
798 .info = via_pin_power_ctl_info,
799 .get = via_pin_power_ctl_get,
800 .put = via_pin_power_ctl_put,
801};
802
803
Harald Welte0aa62ae2008-09-09 15:58:27 +0800804static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
805 struct snd_ctl_elem_info *uinfo)
806{
Takashi Iwai8df2a312011-06-21 11:48:29 +0200807 static const char * const texts[] = { "OFF", "ON" };
808
809 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
810 uinfo->count = 1;
811 uinfo->value.enumerated.items = 2;
812 if (uinfo->value.enumerated.item >= 2)
813 uinfo->value.enumerated.item = 1;
814 strcpy(uinfo->value.enumerated.name,
815 texts[uinfo->value.enumerated.item]);
816 return 0;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800817}
818
819static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
820 struct snd_ctl_elem_value *ucontrol)
821{
822 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Lydia Wangcdc17842009-10-10 19:07:47 +0800823 struct via_spec *spec = codec->spec;
Lydia Wangcdc17842009-10-10 19:07:47 +0800824
Takashi Iwaiece8d042011-06-19 16:24:21 +0200825 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
Lydia Wangcdc17842009-10-10 19:07:47 +0800826 return 0;
827}
828
Takashi Iwai3b607e32011-07-18 16:54:40 +0200829/* adjust spec->multiout setup according to the current flags */
830static void setup_playback_multi_pcm(struct via_spec *spec)
831{
832 const struct auto_pin_cfg *cfg = &spec->autocfg;
833 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
834 spec->multiout.hp_nid = 0;
835 if (!spec->hp_independent_mode) {
836 if (!spec->hp_indep_shared)
837 spec->multiout.hp_nid = spec->hp_dac_nid;
838 } else {
839 if (spec->hp_indep_shared)
840 spec->multiout.num_dacs = cfg->line_outs - 1;
841 }
842}
843
844/* update DAC setups according to indep-HP switch;
845 * this function is called only when indep-HP is modified
846 */
847static void switch_indep_hp_dacs(struct hda_codec *codec)
848{
849 struct via_spec *spec = codec->spec;
850 int shared = spec->hp_indep_shared;
851 hda_nid_t shared_dac, hp_dac;
852
853 if (!spec->opened_streams)
854 return;
855
856 shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
857 hp_dac = spec->hp_dac_nid;
858 if (spec->hp_independent_mode) {
859 /* switch to indep-HP mode */
860 if (spec->active_streams & STREAM_MULTI_OUT) {
861 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
862 __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
863 }
864 if (spec->active_streams & STREAM_INDEP_HP)
865 snd_hda_codec_setup_stream(codec, hp_dac,
866 spec->cur_hp_stream_tag, 0,
867 spec->cur_hp_format);
868 } else {
869 /* back to HP or shared-DAC */
870 if (spec->active_streams & STREAM_INDEP_HP)
871 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
872 if (spec->active_streams & STREAM_MULTI_OUT) {
873 hda_nid_t dac;
874 int ch;
875 if (shared_dac) { /* reset mutli-ch DAC */
876 dac = shared_dac;
877 ch = shared * 2;
878 } else { /* reset HP DAC */
879 dac = hp_dac;
880 ch = 0;
881 }
882 snd_hda_codec_setup_stream(codec, dac,
883 spec->cur_dac_stream_tag, ch,
884 spec->cur_dac_format);
885 }
886 }
887 setup_playback_multi_pcm(spec);
888}
889
Harald Welte0aa62ae2008-09-09 15:58:27 +0800890static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
891 struct snd_ctl_elem_value *ucontrol)
892{
893 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
894 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200895 int cur, shared;
Takashi Iwai8df2a312011-06-21 11:48:29 +0200896
Takashi Iwai3b607e32011-07-18 16:54:40 +0200897 mutex_lock(&spec->config_mutex);
Takashi Iwai25250502011-06-30 17:24:47 +0200898 cur = !!ucontrol->value.enumerated.item[0];
Takashi Iwai3b607e32011-07-18 16:54:40 +0200899 if (spec->hp_independent_mode == cur) {
900 mutex_unlock(&spec->config_mutex);
Takashi Iwai25250502011-06-30 17:24:47 +0200901 return 0;
Takashi Iwai3b607e32011-07-18 16:54:40 +0200902 }
Takashi Iwai25250502011-06-30 17:24:47 +0200903 spec->hp_independent_mode = cur;
Takashi Iwai3214b962011-07-18 12:49:25 +0200904 shared = spec->hp_indep_shared;
Takashi Iwai020066d2011-07-21 13:45:56 +0200905 deactivate_hp_paths(codec);
906 if (cur)
907 activate_output_path(codec, &spec->hp_indep_path, true, false);
908 else {
Takashi Iwai3214b962011-07-18 12:49:25 +0200909 if (shared)
910 activate_output_path(codec, &spec->out_path[shared],
Takashi Iwai25250502011-06-30 17:24:47 +0200911 true, false);
Takashi Iwai020066d2011-07-21 13:45:56 +0200912 if (spec->aamix_mode || !spec->hp_path.depth)
913 activate_output_path(codec, &spec->hp_mix_path,
914 true, false);
915 else
916 activate_output_path(codec, &spec->hp_path,
917 true, false);
Takashi Iwai8df2a312011-06-21 11:48:29 +0200918 }
Harald Welte0aa62ae2008-09-09 15:58:27 +0800919
Takashi Iwai3b607e32011-07-18 16:54:40 +0200920 switch_indep_hp_dacs(codec);
921 mutex_unlock(&spec->config_mutex);
922
Lydia Wangce0e5a92011-03-22 16:22:37 +0800923 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800924 set_widgets_power_state(codec);
Takashi Iwai6e969d92011-07-11 11:28:13 +0200925 via_hp_automute(codec);
Takashi Iwai25250502011-06-30 17:24:47 +0200926 return 1;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800927}
928
Takashi Iwaiece8d042011-06-19 16:24:21 +0200929static const struct snd_kcontrol_new via_hp_mixer = {
930 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
931 .name = "Independent HP",
932 .info = via_independent_hp_info,
933 .get = via_independent_hp_get,
934 .put = via_independent_hp_put,
Harald Welte0aa62ae2008-09-09 15:58:27 +0800935};
936
Takashi Iwai3d83e572010-04-14 14:36:23 +0200937static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100938{
Takashi Iwai3d83e572010-04-14 14:36:23 +0200939 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100940 struct snd_kcontrol_new *knew;
941 hda_nid_t nid;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100942
Takashi Iwaiece8d042011-06-19 16:24:21 +0200943 nid = spec->autocfg.hp_pins[0];
944 knew = via_clone_control(spec, &via_hp_mixer);
Takashi Iwai3d83e572010-04-14 14:36:23 +0200945 if (knew == NULL)
946 return -ENOMEM;
947
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100948 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100949
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100950 return 0;
951}
952
Lydia Wang1564b282009-10-10 19:07:52 +0800953static void notify_aa_path_ctls(struct hda_codec *codec)
954{
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200955 struct via_spec *spec = codec->spec;
Lydia Wang1564b282009-10-10 19:07:52 +0800956 int i;
Lydia Wang1564b282009-10-10 19:07:52 +0800957
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200958 for (i = 0; i < spec->smart51_nums; i++) {
959 struct snd_kcontrol *ctl;
960 struct snd_ctl_elem_id id;
961 memset(&id, 0, sizeof(id));
962 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
963 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
Lydia Wang525566c2011-04-28 16:03:39 +0800964 ctl = snd_hda_find_mixer_ctl(codec, id.name);
965 if (ctl)
966 snd_ctl_notify(codec->bus->card,
967 SNDRV_CTL_EVENT_MASK_VALUE,
968 &ctl->id);
Lydia Wang1564b282009-10-10 19:07:52 +0800969 }
970}
971
972static void mute_aa_path(struct hda_codec *codec, int mute)
973{
974 struct via_spec *spec = codec->spec;
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200975 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
Lydia Wang1564b282009-10-10 19:07:52 +0800976 int i;
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200977
Lydia Wang1564b282009-10-10 19:07:52 +0800978 /* check AA path's mute status */
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200979 for (i = 0; i < spec->smart51_nums; i++) {
980 if (spec->smart51_idxs[i] < 0)
981 continue;
982 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
983 HDA_INPUT, spec->smart51_idxs[i],
Lydia Wang1564b282009-10-10 19:07:52 +0800984 HDA_AMP_MUTE, val);
985 }
986}
Takashi Iwaif4a78282011-06-17 18:46:48 +0200987
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200988static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
989{
990 struct via_spec *spec = codec->spec;
991 int i;
992
993 for (i = 0; i < spec->smart51_nums; i++)
994 if (spec->smart51_pins[i] == pin)
995 return true;
996 return false;
997}
998
Lydia Wang1564b282009-10-10 19:07:52 +0800999static int via_smart51_get(struct snd_kcontrol *kcontrol,
1000 struct snd_ctl_elem_value *ucontrol)
1001{
1002 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1003 struct via_spec *spec = codec->spec;
Lydia Wang1564b282009-10-10 19:07:52 +08001004
Takashi Iwaif2b1c9f2011-06-21 16:52:39 +02001005 *ucontrol->value.integer.value = spec->smart51_enabled;
Lydia Wang1564b282009-10-10 19:07:52 +08001006 return 0;
1007}
1008
1009static int via_smart51_put(struct snd_kcontrol *kcontrol,
1010 struct snd_ctl_elem_value *ucontrol)
1011{
1012 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1013 struct via_spec *spec = codec->spec;
1014 int out_in = *ucontrol->value.integer.value
1015 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +08001016 int i;
1017
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001018 for (i = 0; i < spec->smart51_nums; i++) {
1019 hda_nid_t nid = spec->smart51_pins[i];
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001020 unsigned int parm;
1021
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001022 parm = snd_hda_codec_read(codec, nid, 0,
1023 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1024 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1025 parm |= out_in;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001026 snd_hda_set_pin_ctl(codec, nid, parm);
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001027 if (out_in == AC_PINCTL_OUT_EN) {
1028 mute_aa_path(codec, 1);
1029 notify_aa_path_ctls(codec);
1030 }
Lydia Wang1564b282009-10-10 19:07:52 +08001031 }
1032 spec->smart51_enabled = *ucontrol->value.integer.value;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001033 set_widgets_power_state(codec);
Lydia Wang1564b282009-10-10 19:07:52 +08001034 return 1;
1035}
1036
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001037static const struct snd_kcontrol_new via_smart51_mixer = {
1038 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1039 .name = "Smart 5.1",
1040 .count = 1,
Takashi Iwaif2b1c9f2011-06-21 16:52:39 +02001041 .info = snd_ctl_boolean_mono_info,
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001042 .get = via_smart51_get,
1043 .put = via_smart51_put,
Lydia Wang1564b282009-10-10 19:07:52 +08001044};
1045
Takashi Iwaif4a78282011-06-17 18:46:48 +02001046static int via_smart51_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001047{
Takashi Iwaif4a78282011-06-17 18:46:48 +02001048 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001049
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001050 if (!spec->smart51_nums)
Lydia Wangcb34c202011-04-27 17:44:16 +08001051 return 0;
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001052 if (!via_clone_control(spec, &via_smart51_mixer))
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001053 return -ENOMEM;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001054 return 0;
1055}
1056
Takashi Iwaiada509e2011-06-20 15:40:19 +02001057/* check AA path's mute status */
1058static bool is_aa_path_mute(struct hda_codec *codec)
Lydia Wangf5271102009-10-10 19:07:35 +08001059{
Lydia Wangf5271102009-10-10 19:07:35 +08001060 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001061 const struct hda_amp_list *p;
1062 int i, ch, v;
1063
1064 for (i = 0; i < spec->num_loopbacks; i++) {
1065 p = &spec->loopback_list[i];
1066 for (ch = 0; ch < 2; ch++) {
1067 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
1068 p->idx);
1069 if (!(v & HDA_AMP_MUTE) && v > 0)
1070 return false;
Lydia Wangf5271102009-10-10 19:07:35 +08001071 }
1072 }
Takashi Iwaiada509e2011-06-20 15:40:19 +02001073 return true;
Lydia Wangf5271102009-10-10 19:07:35 +08001074}
1075
1076/* enter/exit analog low-current mode */
Takashi Iwaie9d010c2012-02-01 10:33:23 +01001077static void __analog_low_current_mode(struct hda_codec *codec, bool force)
Lydia Wangf5271102009-10-10 19:07:35 +08001078{
1079 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001080 bool enable;
1081 unsigned int verb, parm;
Lydia Wangf5271102009-10-10 19:07:35 +08001082
Takashi Iwaie9d010c2012-02-01 10:33:23 +01001083 if (spec->no_pin_power_ctl)
1084 enable = false;
1085 else
1086 enable = is_aa_path_mute(codec) && !spec->opened_streams;
1087 if (enable == spec->alc_mode && !force)
1088 return;
1089 spec->alc_mode = enable;
Lydia Wangf5271102009-10-10 19:07:35 +08001090
1091 /* decide low current mode's verb & parameter */
1092 switch (spec->codec_type) {
1093 case VT1708B_8CH:
1094 case VT1708B_4CH:
1095 verb = 0xf70;
1096 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1097 break;
1098 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001099 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001100 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001101 verb = 0xf73;
1102 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1103 break;
1104 case VT1702:
1105 verb = 0xf73;
1106 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1107 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001108 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001109 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001110 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001111 verb = 0xf93;
1112 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1113 break;
Lydia Wang43737e02012-12-10 18:28:11 +08001114 case VT1705CF:
Lydia Wang6121b842012-12-10 19:03:26 +08001115 case VT1808:
Lydia Wang43737e02012-12-10 18:28:11 +08001116 verb = 0xf82;
1117 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1118 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001119 default:
1120 return; /* other codecs are not supported */
1121 }
1122 /* send verb */
1123 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1124}
1125
Takashi Iwaie9d010c2012-02-01 10:33:23 +01001126static void analog_low_current_mode(struct hda_codec *codec)
1127{
1128 return __analog_low_current_mode(codec, false);
1129}
1130
Joseph Chanc577b8a2006-11-29 15:29:40 +01001131/*
1132 * generic initialization of ADC, input mixers and output mixers
1133 */
Takashi Iwai096a8852011-06-20 12:09:02 +02001134static const struct hda_verb vt1708_init_verbs[] = {
Lydia Wangaa266fc2011-03-24 12:41:01 +08001135 /* power down jack detect function */
1136 {0x1, 0xf81, 0x1},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001137 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001138};
1139
Takashi Iwai3b607e32011-07-18 16:54:40 +02001140static void set_stream_open(struct hda_codec *codec, int bit, bool active)
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001141{
Takashi Iwaiada509e2011-06-20 15:40:19 +02001142 struct via_spec *spec = codec->spec;
1143
1144 if (active)
Takashi Iwai3b607e32011-07-18 16:54:40 +02001145 spec->opened_streams |= bit;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001146 else
Takashi Iwai3b607e32011-07-18 16:54:40 +02001147 spec->opened_streams &= ~bit;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001148 analog_low_current_mode(codec);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001149}
1150
Takashi Iwaiece8d042011-06-19 16:24:21 +02001151static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001152 struct hda_codec *codec,
1153 struct snd_pcm_substream *substream)
1154{
1155 struct via_spec *spec = codec->spec;
Takashi Iwai25250502011-06-30 17:24:47 +02001156 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001157 int err;
Takashi Iwaiece8d042011-06-19 16:24:21 +02001158
Takashi Iwai25250502011-06-30 17:24:47 +02001159 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
Takashi Iwai25250502011-06-30 17:24:47 +02001160 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai3b607e32011-07-18 16:54:40 +02001161 set_stream_open(codec, STREAM_MULTI_OUT, true);
Takashi Iwaiada509e2011-06-20 15:40:19 +02001162 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1163 hinfo);
1164 if (err < 0) {
Takashi Iwai3b607e32011-07-18 16:54:40 +02001165 set_stream_open(codec, STREAM_MULTI_OUT, false);
Takashi Iwaiada509e2011-06-20 15:40:19 +02001166 return err;
1167 }
1168 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001169}
1170
Takashi Iwaiece8d042011-06-19 16:24:21 +02001171static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
Takashi Iwai9af74212011-06-18 16:17:45 +02001172 struct hda_codec *codec,
1173 struct snd_pcm_substream *substream)
1174{
Takashi Iwai3b607e32011-07-18 16:54:40 +02001175 set_stream_open(codec, STREAM_MULTI_OUT, false);
Takashi Iwai9af74212011-06-18 16:17:45 +02001176 return 0;
1177}
1178
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001179static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1180 struct hda_codec *codec,
1181 struct snd_pcm_substream *substream)
1182{
1183 struct via_spec *spec = codec->spec;
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001184
Takashi Iwaiece8d042011-06-19 16:24:21 +02001185 if (snd_BUG_ON(!spec->hp_dac_nid))
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001186 return -EINVAL;
Takashi Iwai3b607e32011-07-18 16:54:40 +02001187 set_stream_open(codec, STREAM_INDEP_HP, true);
Takashi Iwaiece8d042011-06-19 16:24:21 +02001188 return 0;
1189}
1190
1191static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1192 struct hda_codec *codec,
1193 struct snd_pcm_substream *substream)
1194{
Takashi Iwai3b607e32011-07-18 16:54:40 +02001195 set_stream_open(codec, STREAM_INDEP_HP, false);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001196 return 0;
1197}
1198
1199static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1200 struct hda_codec *codec,
1201 unsigned int stream_tag,
1202 unsigned int format,
1203 struct snd_pcm_substream *substream)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001204{
1205 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001206
Takashi Iwai3b607e32011-07-18 16:54:40 +02001207 mutex_lock(&spec->config_mutex);
1208 setup_playback_multi_pcm(spec);
Takashi Iwaiece8d042011-06-19 16:24:21 +02001209 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1210 format, substream);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001211 /* remember for dynamic DAC switch with indep-HP */
1212 spec->active_streams |= STREAM_MULTI_OUT;
1213 spec->cur_dac_stream_tag = stream_tag;
1214 spec->cur_dac_format = format;
1215 mutex_unlock(&spec->config_mutex);
Takashi Iwai187d3332011-11-24 16:33:09 +01001216 vt1708_update_hp_work(spec);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001217 return 0;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001218}
1219
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001220static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1221 struct hda_codec *codec,
1222 unsigned int stream_tag,
1223 unsigned int format,
1224 struct snd_pcm_substream *substream)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001225{
1226 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001227
Takashi Iwai3b607e32011-07-18 16:54:40 +02001228 mutex_lock(&spec->config_mutex);
1229 if (spec->hp_independent_mode)
1230 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1231 stream_tag, 0, format);
1232 spec->active_streams |= STREAM_INDEP_HP;
1233 spec->cur_hp_stream_tag = stream_tag;
1234 spec->cur_hp_format = format;
1235 mutex_unlock(&spec->config_mutex);
Takashi Iwai187d3332011-11-24 16:33:09 +01001236 vt1708_update_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001237 return 0;
1238}
1239
1240static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1241 struct hda_codec *codec,
1242 struct snd_pcm_substream *substream)
1243{
1244 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001245
Takashi Iwai3b607e32011-07-18 16:54:40 +02001246 mutex_lock(&spec->config_mutex);
Takashi Iwaiece8d042011-06-19 16:24:21 +02001247 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001248 spec->active_streams &= ~STREAM_MULTI_OUT;
1249 mutex_unlock(&spec->config_mutex);
Takashi Iwai187d3332011-11-24 16:33:09 +01001250 vt1708_update_hp_work(spec);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001251 return 0;
1252}
1253
1254static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1255 struct hda_codec *codec,
1256 struct snd_pcm_substream *substream)
1257{
1258 struct via_spec *spec = codec->spec;
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001259
Takashi Iwai3b607e32011-07-18 16:54:40 +02001260 mutex_lock(&spec->config_mutex);
1261 if (spec->hp_independent_mode)
1262 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1263 spec->active_streams &= ~STREAM_INDEP_HP;
1264 mutex_unlock(&spec->config_mutex);
Takashi Iwai187d3332011-11-24 16:33:09 +01001265 vt1708_update_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001266 return 0;
1267}
1268
Joseph Chanc577b8a2006-11-29 15:29:40 +01001269/*
1270 * Digital out
1271 */
1272static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1273 struct hda_codec *codec,
1274 struct snd_pcm_substream *substream)
1275{
1276 struct via_spec *spec = codec->spec;
1277 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1278}
1279
1280static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1281 struct hda_codec *codec,
1282 struct snd_pcm_substream *substream)
1283{
1284 struct via_spec *spec = codec->spec;
1285 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1286}
1287
Harald Welte5691ec72008-09-15 22:42:26 +08001288static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001289 struct hda_codec *codec,
1290 unsigned int stream_tag,
1291 unsigned int format,
1292 struct snd_pcm_substream *substream)
1293{
1294 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001295 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1296 stream_tag, format, substream);
1297}
Harald Welte5691ec72008-09-15 22:42:26 +08001298
Takashi Iwai9da29272009-05-07 16:31:14 +02001299static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1300 struct hda_codec *codec,
1301 struct snd_pcm_substream *substream)
1302{
1303 struct via_spec *spec = codec->spec;
1304 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001305 return 0;
1306}
1307
Joseph Chanc577b8a2006-11-29 15:29:40 +01001308/*
1309 * Analog capture
1310 */
1311static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1312 struct hda_codec *codec,
1313 unsigned int stream_tag,
1314 unsigned int format,
1315 struct snd_pcm_substream *substream)
1316{
1317 struct via_spec *spec = codec->spec;
1318
1319 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1320 stream_tag, 0, format);
1321 return 0;
1322}
1323
1324static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1325 struct hda_codec *codec,
1326 struct snd_pcm_substream *substream)
1327{
1328 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001329 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001330 return 0;
1331}
1332
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001333/* analog capture with dynamic ADC switching */
1334static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1335 struct hda_codec *codec,
1336 unsigned int stream_tag,
1337 unsigned int format,
1338 struct snd_pcm_substream *substream)
1339{
1340 struct via_spec *spec = codec->spec;
1341 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1342
Takashi Iwai3b607e32011-07-18 16:54:40 +02001343 mutex_lock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001344 spec->cur_adc = spec->adc_nids[adc_idx];
1345 spec->cur_adc_stream_tag = stream_tag;
1346 spec->cur_adc_format = format;
1347 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001348 mutex_unlock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001349 return 0;
1350}
1351
1352static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1353 struct hda_codec *codec,
1354 struct snd_pcm_substream *substream)
1355{
1356 struct via_spec *spec = codec->spec;
1357
Takashi Iwai3b607e32011-07-18 16:54:40 +02001358 mutex_lock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001359 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1360 spec->cur_adc = 0;
Takashi Iwai3b607e32011-07-18 16:54:40 +02001361 mutex_unlock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001362 return 0;
1363}
1364
1365/* re-setup the stream if running; called from input-src put */
1366static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1367{
1368 struct via_spec *spec = codec->spec;
1369 int adc_idx = spec->inputs[cur].adc_idx;
1370 hda_nid_t adc = spec->adc_nids[adc_idx];
Takashi Iwai3b607e32011-07-18 16:54:40 +02001371 bool ret = false;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001372
Takashi Iwai3b607e32011-07-18 16:54:40 +02001373 mutex_lock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001374 if (spec->cur_adc && spec->cur_adc != adc) {
1375 /* stream is running, let's swap the current ADC */
1376 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1377 spec->cur_adc = adc;
1378 snd_hda_codec_setup_stream(codec, adc,
1379 spec->cur_adc_stream_tag, 0,
1380 spec->cur_adc_format);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001381 ret = true;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001382 }
Takashi Iwai3b607e32011-07-18 16:54:40 +02001383 mutex_unlock(&spec->config_mutex);
1384 return ret;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001385}
1386
Takashi Iwai9af74212011-06-18 16:17:45 +02001387static const struct hda_pcm_stream via_pcm_analog_playback = {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001388 .substreams = 1,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001389 .channels_min = 2,
1390 .channels_max = 8,
Takashi Iwai9af74212011-06-18 16:17:45 +02001391 /* NID is set in via_build_pcms */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001392 .ops = {
Takashi Iwaiece8d042011-06-19 16:24:21 +02001393 .open = via_playback_multi_pcm_open,
1394 .close = via_playback_multi_pcm_close,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001395 .prepare = via_playback_multi_pcm_prepare,
1396 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001397 },
1398};
1399
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001400static const struct hda_pcm_stream via_pcm_hp_playback = {
1401 .substreams = 1,
1402 .channels_min = 2,
1403 .channels_max = 2,
1404 /* NID is set in via_build_pcms */
1405 .ops = {
1406 .open = via_playback_hp_pcm_open,
Takashi Iwaiece8d042011-06-19 16:24:21 +02001407 .close = via_playback_hp_pcm_close,
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001408 .prepare = via_playback_hp_pcm_prepare,
1409 .cleanup = via_playback_hp_pcm_cleanup
1410 },
1411};
1412
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001413static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001414 .substreams = 1,
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001415 .channels_min = 2,
1416 .channels_max = 8,
Takashi Iwai9af74212011-06-18 16:17:45 +02001417 /* NID is set in via_build_pcms */
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001418 /* We got noisy outputs on the right channel on VT1708 when
1419 * 24bit samples are used. Until any workaround is found,
1420 * disable the 24bit format, so far.
1421 */
1422 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1423 .ops = {
Takashi Iwaiece8d042011-06-19 16:24:21 +02001424 .open = via_playback_multi_pcm_open,
1425 .close = via_playback_multi_pcm_close,
Lydia Wangc873cc22009-10-10 19:08:21 +08001426 .prepare = via_playback_multi_pcm_prepare,
1427 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001428 },
1429};
1430
Takashi Iwai9af74212011-06-18 16:17:45 +02001431static const struct hda_pcm_stream via_pcm_analog_capture = {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001432 .substreams = 1, /* will be changed in via_build_pcms() */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001433 .channels_min = 2,
1434 .channels_max = 2,
Takashi Iwai9af74212011-06-18 16:17:45 +02001435 /* NID is set in via_build_pcms */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001436 .ops = {
1437 .prepare = via_capture_pcm_prepare,
1438 .cleanup = via_capture_pcm_cleanup
1439 },
1440};
1441
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001442static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1443 .substreams = 1,
1444 .channels_min = 2,
1445 .channels_max = 2,
1446 /* NID is set in via_build_pcms */
1447 .ops = {
1448 .prepare = via_dyn_adc_capture_pcm_prepare,
1449 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1450 },
1451};
1452
Takashi Iwai9af74212011-06-18 16:17:45 +02001453static const struct hda_pcm_stream via_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001454 .substreams = 1,
1455 .channels_min = 2,
1456 .channels_max = 2,
1457 /* NID is set in via_build_pcms */
1458 .ops = {
1459 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001460 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001461 .prepare = via_dig_playback_pcm_prepare,
1462 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001463 },
1464};
1465
Takashi Iwai9af74212011-06-18 16:17:45 +02001466static const struct hda_pcm_stream via_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001467 .substreams = 1,
1468 .channels_min = 2,
1469 .channels_max = 2,
1470};
1471
Takashi Iwai370bafb2011-06-20 12:47:45 +02001472/*
1473 * slave controls for virtual master
1474 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001475static const char * const via_slave_pfxs[] = {
1476 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01001477 "Headphone", "Speaker", "Bass Speaker",
Takashi Iwai370bafb2011-06-20 12:47:45 +02001478 NULL,
1479};
1480
Joseph Chanc577b8a2006-11-29 15:29:40 +01001481static int via_build_controls(struct hda_codec *codec)
1482{
1483 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001484 struct snd_kcontrol *kctl;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001485 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001486
Takashi Iwaib5bcc182012-02-02 10:30:17 +01001487 spec->no_pin_power_ctl = 1;
Takashi Iwai24088a52011-06-17 16:59:21 +02001488 if (spec->set_widgets_power_state)
1489 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1490 return -ENOMEM;
1491
Joseph Chanc577b8a2006-11-29 15:29:40 +01001492 for (i = 0; i < spec->num_mixers; i++) {
1493 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1494 if (err < 0)
1495 return err;
1496 }
1497
1498 if (spec->multiout.dig_out_nid) {
1499 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001500 spec->multiout.dig_out_nid,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001501 spec->multiout.dig_out_nid);
1502 if (err < 0)
1503 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001504 err = snd_hda_create_spdif_share_sw(codec,
1505 &spec->multiout);
1506 if (err < 0)
1507 return err;
1508 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001509 }
1510 if (spec->dig_in_nid) {
1511 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1512 if (err < 0)
1513 return err;
1514 }
Lydia Wang17314372009-10-10 19:07:37 +08001515
Takashi Iwai370bafb2011-06-20 12:47:45 +02001516 /* if we have no master control, let's create it */
1517 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1518 unsigned int vmaster_tlv[4];
1519 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1520 HDA_OUTPUT, vmaster_tlv);
1521 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001522 vmaster_tlv, via_slave_pfxs,
1523 "Playback Volume");
Takashi Iwai370bafb2011-06-20 12:47:45 +02001524 if (err < 0)
1525 return err;
1526 }
1527 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1528 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001529 NULL, via_slave_pfxs,
1530 "Playback Switch");
Takashi Iwai370bafb2011-06-20 12:47:45 +02001531 if (err < 0)
1532 return err;
1533 }
1534
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001535 /* assign Capture Source enums to NID */
1536 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1537 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai77e314f2012-02-22 12:34:08 +01001538 if (!spec->mux_nids[i])
1539 continue;
Takashi Iwai21949f02009-12-23 08:31:59 +01001540 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001541 if (err < 0)
1542 return err;
1543 }
1544
Takashi Iwai603c4012008-07-30 15:01:44 +02001545 via_free_kctls(codec); /* no longer needed */
Takashi Iwai01a61e12011-10-28 00:03:22 +02001546
1547 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1548 if (err < 0)
1549 return err;
1550
Joseph Chanc577b8a2006-11-29 15:29:40 +01001551 return 0;
1552}
1553
1554static int via_build_pcms(struct hda_codec *codec)
1555{
1556 struct via_spec *spec = codec->spec;
1557 struct hda_pcm *info = spec->pcm_rec;
1558
Takashi Iwaia5973102011-09-28 16:43:36 +02001559 codec->num_pcms = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001560 codec->pcm_info = info;
1561
Takashi Iwaia5973102011-09-28 16:43:36 +02001562 if (spec->multiout.num_dacs || spec->num_adc_nids) {
1563 snprintf(spec->stream_name_analog,
1564 sizeof(spec->stream_name_analog),
1565 "%s Analog", codec->chip_name);
1566 info->name = spec->stream_name_analog;
Takashi Iwai9af74212011-06-18 16:17:45 +02001567
Takashi Iwaia5973102011-09-28 16:43:36 +02001568 if (spec->multiout.num_dacs) {
1569 if (!spec->stream_analog_playback)
1570 spec->stream_analog_playback =
1571 &via_pcm_analog_playback;
1572 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1573 *spec->stream_analog_playback;
1574 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1575 spec->multiout.dac_nids[0];
1576 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1577 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01001578 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT
1579 && spec->autocfg.line_outs == 2)
1580 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
1581 snd_pcm_2_1_chmaps;
Takashi Iwaia5973102011-09-28 16:43:36 +02001582 }
Takashi Iwai9af74212011-06-18 16:17:45 +02001583
Takashi Iwaia5973102011-09-28 16:43:36 +02001584 if (!spec->stream_analog_capture) {
1585 if (spec->dyn_adc_switch)
1586 spec->stream_analog_capture =
1587 &via_pcm_dyn_adc_analog_capture;
1588 else
1589 spec->stream_analog_capture =
1590 &via_pcm_analog_capture;
1591 }
1592 if (spec->num_adc_nids) {
1593 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1594 *spec->stream_analog_capture;
1595 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1596 spec->adc_nids[0];
1597 if (!spec->dyn_adc_switch)
1598 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1599 spec->num_adc_nids;
1600 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001601 codec->num_pcms++;
1602 info++;
Takashi Iwaia5973102011-09-28 16:43:36 +02001603 }
1604
1605 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai82673bc2011-06-17 16:24:21 +02001606 snprintf(spec->stream_name_digital,
1607 sizeof(spec->stream_name_digital),
1608 "%s Digital", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001609 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001610 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001611 if (spec->multiout.dig_out_nid) {
Takashi Iwai9af74212011-06-18 16:17:45 +02001612 if (!spec->stream_digital_playback)
1613 spec->stream_digital_playback =
1614 &via_pcm_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001615 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001616 *spec->stream_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001617 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1618 spec->multiout.dig_out_nid;
1619 }
1620 if (spec->dig_in_nid) {
Takashi Iwai9af74212011-06-18 16:17:45 +02001621 if (!spec->stream_digital_capture)
1622 spec->stream_digital_capture =
1623 &via_pcm_digital_capture;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001624 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001625 *spec->stream_digital_capture;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001626 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1627 spec->dig_in_nid;
1628 }
Takashi Iwaia5973102011-09-28 16:43:36 +02001629 codec->num_pcms++;
1630 info++;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001631 }
1632
Takashi Iwaiece8d042011-06-19 16:24:21 +02001633 if (spec->hp_dac_nid) {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001634 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1635 "%s HP", codec->chip_name);
1636 info->name = spec->stream_name_hp;
1637 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1638 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
Takashi Iwaiece8d042011-06-19 16:24:21 +02001639 spec->hp_dac_nid;
Takashi Iwaia5973102011-09-28 16:43:36 +02001640 codec->num_pcms++;
1641 info++;
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001642 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001643 return 0;
1644}
1645
1646static void via_free(struct hda_codec *codec)
1647{
1648 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001649
1650 if (!spec)
1651 return;
1652
Takashi Iwai603c4012008-07-30 15:01:44 +02001653 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001654 vt1708_stop_hp_work(spec);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001655 kfree(spec->bind_cap_vol);
1656 kfree(spec->bind_cap_sw);
1657 kfree(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001658}
1659
Takashi Iwai64be2852011-06-17 16:51:39 +02001660/* mute/unmute outputs */
1661static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1662 hda_nid_t *pins, bool mute)
1663{
1664 int i;
Takashi Iwai94994732011-07-11 11:36:44 +02001665 for (i = 0; i < num_pins; i++) {
1666 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1667 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1668 if (parm & AC_PINCTL_IN_EN)
1669 continue;
1670 if (mute)
1671 parm &= ~AC_PINCTL_OUT_EN;
1672 else
1673 parm |= AC_PINCTL_OUT_EN;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001674 snd_hda_set_pin_ctl(codec, pins[i], parm);
Takashi Iwai94994732011-07-11 11:36:44 +02001675 }
Takashi Iwai64be2852011-06-17 16:51:39 +02001676}
1677
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001678/* mute internal speaker if line-out is plugged */
1679static void via_line_automute(struct hda_codec *codec, int present)
1680{
1681 struct via_spec *spec = codec->spec;
1682
1683 if (!spec->autocfg.speaker_outs)
1684 return;
1685 if (!present)
1686 present = snd_hda_jack_detect(codec,
1687 spec->autocfg.line_out_pins[0]);
1688 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1689 spec->autocfg.speaker_pins,
1690 present);
1691}
1692
Harald Welte69e52a82008-09-09 15:57:32 +08001693/* mute internal speaker if HP is plugged */
1694static void via_hp_automute(struct hda_codec *codec)
1695{
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001696 int present = 0;
Takashi Iwai6e969d92011-07-11 11:28:13 +02001697 int nums;
Harald Welte69e52a82008-09-09 15:57:32 +08001698 struct via_spec *spec = codec->spec;
1699
Takashi Iwai187d3332011-11-24 16:33:09 +01001700 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0] &&
Herton Ronaldo Krzesinskicf55e902012-09-21 20:45:19 -03001701 (spec->codec_type != VT1708 || spec->vt1708_jack_detect) &&
1702 is_jack_detectable(codec, spec->autocfg.hp_pins[0]))
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001703 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Takashi Iwai6e969d92011-07-11 11:28:13 +02001704
1705 if (spec->smart51_enabled)
1706 nums = spec->autocfg.line_outs + spec->smart51_nums;
1707 else
1708 nums = spec->autocfg.line_outs;
1709 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1710
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001711 via_line_automute(codec, present);
Lydia Wangf3db4232009-10-10 19:08:41 +08001712}
1713
Takashi Iwai2a439522011-07-26 09:52:50 +02001714#ifdef CONFIG_PM
Takashi Iwai68cb2b52012-07-02 15:20:37 +02001715static int via_suspend(struct hda_codec *codec)
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001716{
1717 struct via_spec *spec = codec->spec;
1718 vt1708_stop_hp_work(spec);
David Henningsson94c142a2012-08-09 10:56:12 +02001719
1720 if (spec->codec_type == VT1802) {
1721 /* Fix pop noise on headphones */
1722 int i;
1723 for (i = 0; i < spec->autocfg.hp_outs; i++)
1724 snd_hda_set_pin_ctl(codec, spec->autocfg.hp_pins[i], 0);
1725 }
1726
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001727 return 0;
1728}
1729#endif
1730
Takashi Iwai83012a72012-08-24 18:38:08 +02001731#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001732static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1733{
1734 struct via_spec *spec = codec->spec;
1735 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1736}
1737#endif
1738
Joseph Chanc577b8a2006-11-29 15:29:40 +01001739/*
1740 */
Takashi Iwai5d417622011-06-20 11:32:27 +02001741
1742static int via_init(struct hda_codec *codec);
1743
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001744static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001745 .build_controls = via_build_controls,
1746 .build_pcms = via_build_pcms,
1747 .init = via_init,
1748 .free = via_free,
David Henningsson4e2d16d2012-10-08 15:44:14 +02001749 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02001750#ifdef CONFIG_PM
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001751 .suspend = via_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02001752 .check_power_status = via_check_power_status,
1753#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001754};
1755
Takashi Iwai4a796162011-06-17 17:53:38 +02001756static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001757{
Takashi Iwai4a796162011-06-17 17:53:38 +02001758 struct via_spec *spec = codec->spec;
1759 int i;
1760
1761 for (i = 0; i < spec->multiout.num_dacs; i++) {
1762 if (spec->multiout.dac_nids[i] == dac)
1763 return false;
1764 }
Takashi Iwaiece8d042011-06-19 16:24:21 +02001765 if (spec->hp_dac_nid == dac)
Takashi Iwai4a796162011-06-17 17:53:38 +02001766 return false;
1767 return true;
1768}
1769
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001770static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai3214b962011-07-18 12:49:25 +02001771 hda_nid_t target_dac, int with_aa_mix,
1772 struct nid_path *path, int depth)
Takashi Iwai4a796162011-06-17 17:53:38 +02001773{
Takashi Iwai3214b962011-07-18 12:49:25 +02001774 struct via_spec *spec = codec->spec;
Takashi Iwai4a796162011-06-17 17:53:38 +02001775 hda_nid_t conn[8];
1776 int i, nums;
1777
Takashi Iwai3214b962011-07-18 12:49:25 +02001778 if (nid == spec->aa_mix_nid) {
1779 if (!with_aa_mix)
1780 return false;
1781 with_aa_mix = 2; /* mark aa-mix is included */
1782 }
1783
Takashi Iwai4a796162011-06-17 17:53:38 +02001784 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1785 for (i = 0; i < nums; i++) {
1786 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1787 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +02001788 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1789 /* aa-mix is requested but not included? */
1790 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1791 goto found;
1792 }
Takashi Iwai4a796162011-06-17 17:53:38 +02001793 }
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001794 if (depth >= MAX_NID_PATH_DEPTH)
Takashi Iwai4a796162011-06-17 17:53:38 +02001795 return false;
1796 for (i = 0; i < nums; i++) {
1797 unsigned int type;
1798 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai3214b962011-07-18 12:49:25 +02001799 if (type == AC_WID_AUD_OUT)
Takashi Iwai4a796162011-06-17 17:53:38 +02001800 continue;
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001801 if (__parse_output_path(codec, conn[i], target_dac,
Takashi Iwai3214b962011-07-18 12:49:25 +02001802 with_aa_mix, path, depth + 1))
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001803 goto found;
Takashi Iwai4a796162011-06-17 17:53:38 +02001804 }
1805 return false;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001806
1807 found:
1808 path->path[path->depth] = conn[i];
1809 path->idx[path->depth] = i;
1810 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1811 path->multi[path->depth] = 1;
1812 path->depth++;
1813 return true;
Takashi Iwai4a796162011-06-17 17:53:38 +02001814}
1815
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001816static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai3214b962011-07-18 12:49:25 +02001817 hda_nid_t target_dac, int with_aa_mix,
1818 struct nid_path *path)
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001819{
Takashi Iwai3214b962011-07-18 12:49:25 +02001820 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001821 path->path[path->depth] = nid;
1822 path->depth++;
Takashi Iwai3214b962011-07-18 12:49:25 +02001823 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1824 path->depth, path->path[0], path->path[1],
1825 path->path[2], path->path[3], path->path[4]);
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001826 return true;
1827 }
1828 return false;
1829}
1830
Takashi Iwai4a796162011-06-17 17:53:38 +02001831static int via_auto_fill_dac_nids(struct hda_codec *codec)
1832{
1833 struct via_spec *spec = codec->spec;
1834 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai5b376192012-11-07 10:32:47 +01001835 int i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001836 hda_nid_t nid;
1837
Takashi Iwai5b376192012-11-07 10:32:47 +01001838 spec->multiout.num_dacs = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001839 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai4a796162011-06-17 17:53:38 +02001840 for (i = 0; i < cfg->line_outs; i++) {
Takashi Iwai3214b962011-07-18 12:49:25 +02001841 hda_nid_t dac = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001842 nid = cfg->line_out_pins[i];
Takashi Iwai4a796162011-06-17 17:53:38 +02001843 if (!nid)
1844 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +02001845 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1846 dac = spec->out_path[i].path[0];
1847 if (!i && parse_output_path(codec, nid, dac, 1,
1848 &spec->out_mix_path))
1849 dac = spec->out_mix_path.path[0];
Takashi Iwai5b376192012-11-07 10:32:47 +01001850 if (dac)
1851 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001852 }
Takashi Iwai3214b962011-07-18 12:49:25 +02001853 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1854 spec->out_path[0] = spec->out_mix_path;
1855 spec->out_mix_path.depth = 0;
1856 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001857 return 0;
1858}
1859
Takashi Iwai4a796162011-06-17 17:53:38 +02001860static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001861 int chs, bool check_dac, struct nid_path *path)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001862{
Takashi Iwai4a796162011-06-17 17:53:38 +02001863 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001864 char name[32];
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001865 hda_nid_t dac, pin, sel, nid;
1866 int err;
Takashi Iwaia934d5a2011-06-21 14:22:14 +02001867
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001868 dac = check_dac ? path->path[0] : 0;
1869 pin = path->path[path->depth - 1];
1870 sel = path->depth > 1 ? path->path[1] : 0;
Takashi Iwai4a796162011-06-17 17:53:38 +02001871
Takashi Iwai8df2a312011-06-21 11:48:29 +02001872 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
Takashi Iwai4a796162011-06-17 17:53:38 +02001873 nid = dac;
Takashi Iwai8df2a312011-06-21 11:48:29 +02001874 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
Takashi Iwai4a796162011-06-17 17:53:38 +02001875 nid = pin;
Takashi Iwaia934d5a2011-06-21 14:22:14 +02001876 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1877 nid = sel;
Takashi Iwai4a796162011-06-17 17:53:38 +02001878 else
1879 nid = 0;
1880 if (nid) {
1881 sprintf(name, "%s Playback Volume", pfx);
1882 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wanga00a5fa2011-06-21 16:11:11 +08001883 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
Takashi Iwai4a796162011-06-17 17:53:38 +02001884 if (err < 0)
1885 return err;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001886 path->vol_ctl = nid;
Takashi Iwai4a796162011-06-17 17:53:38 +02001887 }
1888
Takashi Iwai8df2a312011-06-21 11:48:29 +02001889 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
Takashi Iwai4a796162011-06-17 17:53:38 +02001890 nid = dac;
Takashi Iwai8df2a312011-06-21 11:48:29 +02001891 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
Takashi Iwai4a796162011-06-17 17:53:38 +02001892 nid = pin;
Takashi Iwaia934d5a2011-06-21 14:22:14 +02001893 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1894 nid = sel;
Takashi Iwai4a796162011-06-17 17:53:38 +02001895 else
1896 nid = 0;
1897 if (nid) {
1898 sprintf(name, "%s Playback Switch", pfx);
1899 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1900 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1901 if (err < 0)
1902 return err;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001903 path->mute_ctl = nid;
Takashi Iwai4a796162011-06-17 17:53:38 +02001904 }
1905 return 0;
1906}
1907
Takashi Iwaif4a78282011-06-17 18:46:48 +02001908static void mangle_smart51(struct hda_codec *codec)
1909{
1910 struct via_spec *spec = codec->spec;
1911 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0f98c242011-06-21 12:51:33 +02001912 struct auto_pin_cfg_item *ins = cfg->inputs;
1913 int i, j, nums, attr;
1914 int pins[AUTO_CFG_MAX_INS];
Takashi Iwaif4a78282011-06-17 18:46:48 +02001915
Takashi Iwai5ec16d12012-11-28 18:11:59 +01001916 for (attr = INPUT_PIN_ATTR_LAST; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
Takashi Iwai0f98c242011-06-21 12:51:33 +02001917 nums = 0;
1918 for (i = 0; i < cfg->num_inputs; i++) {
1919 unsigned int def;
1920 if (ins[i].type > AUTO_PIN_LINE_IN)
1921 continue;
1922 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1923 if (snd_hda_get_input_pin_attr(def) != attr)
1924 continue;
1925 for (j = 0; j < nums; j++)
1926 if (ins[pins[j]].type < ins[i].type) {
1927 memmove(pins + j + 1, pins + j,
Takashi Iwai21d45d22011-07-08 11:35:11 +02001928 (nums - j) * sizeof(int));
Takashi Iwai0f98c242011-06-21 12:51:33 +02001929 break;
1930 }
1931 pins[j] = i;
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001932 nums++;
Takashi Iwai0f98c242011-06-21 12:51:33 +02001933 }
1934 if (cfg->line_outs + nums < 3)
Takashi Iwaif4a78282011-06-17 18:46:48 +02001935 continue;
Takashi Iwai0f98c242011-06-21 12:51:33 +02001936 for (i = 0; i < nums; i++) {
1937 hda_nid_t pin = ins[pins[i]].pin;
1938 spec->smart51_pins[spec->smart51_nums++] = pin;
1939 cfg->line_out_pins[cfg->line_outs++] = pin;
1940 if (cfg->line_outs == 3)
1941 break;
1942 }
1943 return;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001944 }
1945}
1946
Takashi Iwai020066d2011-07-21 13:45:56 +02001947static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
1948{
1949 dst->vol_ctl = src->vol_ctl;
1950 dst->mute_ctl = src->mute_ctl;
1951}
1952
Takashi Iwai4a796162011-06-17 17:53:38 +02001953/* add playback controls from the parsed DAC table */
1954static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1955{
1956 struct via_spec *spec = codec->spec;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001957 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai3214b962011-07-18 12:49:25 +02001958 struct nid_path *path;
Takashi Iwaiea734962011-01-17 11:29:34 +01001959 static const char * const chname[4] = {
David Henningsson34ca8d32012-11-09 07:03:59 +01001960 "Front", "Surround", NULL /* "CLFE" */, "Side"
Takashi Iwaiea734962011-01-17 11:29:34 +01001961 };
Takashi Iwai4a796162011-06-17 17:53:38 +02001962 int i, idx, err;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001963 int old_line_outs;
1964
1965 /* check smart51 */
1966 old_line_outs = cfg->line_outs;
1967 if (cfg->line_outs == 1)
1968 mangle_smart51(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001969
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001970 err = via_auto_fill_dac_nids(codec);
1971 if (err < 0)
1972 return err;
1973
Lydia Wang5c9a5612011-07-08 14:03:43 +08001974 if (spec->multiout.num_dacs < 3) {
1975 spec->smart51_nums = 0;
1976 cfg->line_outs = old_line_outs;
1977 }
Takashi Iwai4a796162011-06-17 17:53:38 +02001978 for (i = 0; i < cfg->line_outs; i++) {
1979 hda_nid_t pin, dac;
1980 pin = cfg->line_out_pins[i];
1981 dac = spec->multiout.dac_nids[i];
1982 if (!pin || !dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001983 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +02001984 path = spec->out_path + i;
Takashi Iwai0fe0adf2011-06-19 16:27:53 +02001985 if (i == HDA_CLFE) {
Takashi Iwai3214b962011-07-18 12:49:25 +02001986 err = create_ch_ctls(codec, "Center", 1, true, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001987 if (err < 0)
1988 return err;
Takashi Iwai3214b962011-07-18 12:49:25 +02001989 err = create_ch_ctls(codec, "LFE", 2, true, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001990 if (err < 0)
1991 return err;
1992 } else {
Takashi Iwai6aadf412011-06-20 14:09:02 +02001993 const char *pfx = chname[i];
1994 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01001995 cfg->line_outs <= 2)
1996 pfx = i ? "Bass Speaker" : "Speaker";
Takashi Iwai3214b962011-07-18 12:49:25 +02001997 err = create_ch_ctls(codec, pfx, 3, true, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001998 if (err < 0)
1999 return err;
2000 }
Takashi Iwai020066d2011-07-21 13:45:56 +02002001 if (path != spec->out_path + i)
2002 copy_path_mixer_ctls(&spec->out_path[i], path);
2003 if (path == spec->out_path && spec->out_mix_path.depth)
2004 copy_path_mixer_ctls(&spec->out_mix_path, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002005 }
2006
Takashi Iwai4a796162011-06-17 17:53:38 +02002007 idx = get_connection_index(codec, spec->aa_mix_nid,
2008 spec->multiout.dac_nids[0]);
2009 if (idx >= 0) {
2010 /* add control to mixer */
Takashi Iwai3214b962011-07-18 12:49:25 +02002011 const char *name;
2012 name = spec->out_mix_path.depth ?
2013 "PCM Loopback Playback Volume" : "PCM Playback Volume";
2014 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Takashi Iwai4a796162011-06-17 17:53:38 +02002015 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2016 idx, HDA_INPUT));
2017 if (err < 0)
2018 return err;
Takashi Iwai3214b962011-07-18 12:49:25 +02002019 name = spec->out_mix_path.depth ?
2020 "PCM Loopback Playback Switch" : "PCM Playback Switch";
2021 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Takashi Iwai4a796162011-06-17 17:53:38 +02002022 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2023 idx, HDA_INPUT));
2024 if (err < 0)
2025 return err;
2026 }
2027
Takashi Iwaif4a78282011-06-17 18:46:48 +02002028 cfg->line_outs = old_line_outs;
2029
Joseph Chanc577b8a2006-11-29 15:29:40 +01002030 return 0;
2031}
2032
Takashi Iwai4a796162011-06-17 17:53:38 +02002033static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002034{
Takashi Iwai4a796162011-06-17 17:53:38 +02002035 struct via_spec *spec = codec->spec;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02002036 struct nid_path *path;
Takashi Iwai18bd2c42011-07-04 15:55:44 +02002037 bool check_dac;
Takashi Iwai3214b962011-07-18 12:49:25 +02002038 int i, err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002039
2040 if (!pin)
2041 return 0;
2042
Takashi Iwai3214b962011-07-18 12:49:25 +02002043 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
2044 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
2045 if (i < spec->multiout.num_dacs &&
2046 parse_output_path(codec, pin,
2047 spec->multiout.dac_nids[i], 0,
2048 &spec->hp_indep_path)) {
2049 spec->hp_indep_shared = i;
2050 break;
2051 }
2052 }
Takashi Iwai25250502011-06-30 17:24:47 +02002053 }
Takashi Iwai3214b962011-07-18 12:49:25 +02002054 if (spec->hp_indep_path.depth) {
2055 spec->hp_dac_nid = spec->hp_indep_path.path[0];
2056 if (!spec->hp_indep_shared)
2057 spec->hp_path = spec->hp_indep_path;
2058 }
2059 /* optionally check front-path w/o AA-mix */
2060 if (!spec->hp_path.depth)
2061 parse_output_path(codec, pin,
2062 spec->multiout.dac_nids[HDA_FRONT], 0,
2063 &spec->hp_path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002064
Takashi Iwaiece8d042011-06-19 16:24:21 +02002065 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
Takashi Iwai3214b962011-07-18 12:49:25 +02002066 1, &spec->hp_mix_path) && !spec->hp_path.depth)
Takashi Iwaiece8d042011-06-19 16:24:21 +02002067 return 0;
2068
Takashi Iwai3214b962011-07-18 12:49:25 +02002069 if (spec->hp_path.depth) {
Takashi Iwai09a9ad692011-06-21 15:57:44 +02002070 path = &spec->hp_path;
Takashi Iwai18bd2c42011-07-04 15:55:44 +02002071 check_dac = true;
2072 } else {
Takashi Iwai3214b962011-07-18 12:49:25 +02002073 path = &spec->hp_mix_path;
Takashi Iwai18bd2c42011-07-04 15:55:44 +02002074 check_dac = false;
2075 }
2076 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002077 if (err < 0)
2078 return err;
Takashi Iwai020066d2011-07-21 13:45:56 +02002079 if (check_dac)
2080 copy_path_mixer_ctls(&spec->hp_mix_path, path);
2081 else
2082 copy_path_mixer_ctls(&spec->hp_path, path);
2083 if (spec->hp_indep_path.depth)
2084 copy_path_mixer_ctls(&spec->hp_indep_path, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002085 return 0;
2086}
2087
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002088static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2089{
2090 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +02002091 struct nid_path *path;
2092 bool check_dac;
Wang Shaoyan81c0a782011-08-05 18:51:29 +08002093 hda_nid_t pin, dac = 0;
Takashi Iwai3214b962011-07-18 12:49:25 +02002094 int err;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002095
2096 pin = spec->autocfg.speaker_pins[0];
2097 if (!spec->autocfg.speaker_outs || !pin)
2098 return 0;
2099
Takashi Iwai3214b962011-07-18 12:49:25 +02002100 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
Takashi Iwai8e3679d2011-06-21 09:01:36 +02002101 dac = spec->speaker_path.path[0];
Takashi Iwai3214b962011-07-18 12:49:25 +02002102 if (!dac)
2103 parse_output_path(codec, pin,
2104 spec->multiout.dac_nids[HDA_FRONT], 0,
2105 &spec->speaker_path);
2106 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2107 1, &spec->speaker_mix_path) && !dac)
2108 return 0;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002109
Takashi Iwai3214b962011-07-18 12:49:25 +02002110 /* no AA-path for front? */
2111 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2112 dac = 0;
2113
2114 spec->speaker_dac_nid = dac;
2115 spec->multiout.extra_out_nid[0] = dac;
2116 if (dac) {
2117 path = &spec->speaker_path;
2118 check_dac = true;
2119 } else {
2120 path = &spec->speaker_mix_path;
2121 check_dac = false;
2122 }
2123 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2124 if (err < 0)
2125 return err;
Takashi Iwai020066d2011-07-21 13:45:56 +02002126 if (check_dac)
2127 copy_path_mixer_ctls(&spec->speaker_mix_path, path);
2128 else
2129 copy_path_mixer_ctls(&spec->speaker_path, path);
Takashi Iwai3214b962011-07-18 12:49:25 +02002130 return 0;
2131}
2132
2133#define via_aamix_ctl_info via_pin_power_ctl_info
2134
2135static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2136 struct snd_ctl_elem_value *ucontrol)
2137{
2138 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2139 struct via_spec *spec = codec->spec;
2140 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2141 return 0;
2142}
2143
2144static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2145 struct nid_path *nomix, struct nid_path *mix)
2146{
2147 if (do_mix) {
2148 activate_output_path(codec, nomix, false, false);
2149 activate_output_path(codec, mix, true, false);
2150 } else {
2151 activate_output_path(codec, mix, false, false);
2152 activate_output_path(codec, nomix, true, false);
2153 }
2154}
2155
2156static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2157 struct snd_ctl_elem_value *ucontrol)
2158{
2159 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2160 struct via_spec *spec = codec->spec;
2161 unsigned int val = ucontrol->value.enumerated.item[0];
2162
2163 if (val == spec->aamix_mode)
2164 return 0;
2165 spec->aamix_mode = val;
2166 /* update front path */
2167 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2168 /* update HP path */
2169 if (!spec->hp_independent_mode) {
2170 update_aamix_paths(codec, val, &spec->hp_path,
2171 &spec->hp_mix_path);
2172 }
2173 /* update speaker path */
2174 update_aamix_paths(codec, val, &spec->speaker_path,
2175 &spec->speaker_mix_path);
2176 return 1;
2177}
2178
2179static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2180 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2181 .name = "Loopback Mixing",
2182 .info = via_aamix_ctl_info,
2183 .get = via_aamix_ctl_get,
2184 .put = via_aamix_ctl_put,
2185};
2186
2187static int via_auto_create_loopback_switch(struct hda_codec *codec)
2188{
2189 struct via_spec *spec = codec->spec;
2190
Takashi Iwai4808d122012-01-10 15:16:02 +01002191 if (!spec->aa_mix_nid)
2192 return 0; /* no loopback switching available */
2193 if (!(spec->out_mix_path.depth || spec->hp_mix_path.depth ||
2194 spec->speaker_path.depth))
Takashi Iwai3214b962011-07-18 12:49:25 +02002195 return 0; /* no loopback switching available */
2196 if (!via_clone_control(spec, &via_aamix_ctl_enum))
2197 return -ENOMEM;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002198 return 0;
2199}
2200
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002201/* look for ADCs */
2202static int via_fill_adcs(struct hda_codec *codec)
2203{
2204 struct via_spec *spec = codec->spec;
2205 hda_nid_t nid = codec->start_nid;
2206 int i;
2207
2208 for (i = 0; i < codec->num_nodes; i++, nid++) {
2209 unsigned int wcaps = get_wcaps(codec, nid);
2210 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2211 continue;
2212 if (wcaps & AC_WCAP_DIGITAL)
2213 continue;
2214 if (!(wcaps & AC_WCAP_CONN_LIST))
2215 continue;
2216 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2217 return -ENOMEM;
2218 spec->adc_nids[spec->num_adc_nids++] = nid;
2219 }
2220 return 0;
2221}
2222
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002223/* input-src control */
2224static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
2225 struct snd_ctl_elem_info *uinfo)
2226{
2227 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2228 struct via_spec *spec = codec->spec;
2229
2230 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2231 uinfo->count = 1;
2232 uinfo->value.enumerated.items = spec->num_inputs;
2233 if (uinfo->value.enumerated.item >= spec->num_inputs)
2234 uinfo->value.enumerated.item = spec->num_inputs - 1;
2235 strcpy(uinfo->value.enumerated.name,
2236 spec->inputs[uinfo->value.enumerated.item].label);
2237 return 0;
2238}
2239
2240static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2241 struct snd_ctl_elem_value *ucontrol)
2242{
2243 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2244 struct via_spec *spec = codec->spec;
2245 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2246
2247 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2248 return 0;
2249}
2250
2251static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2252 struct snd_ctl_elem_value *ucontrol)
2253{
2254 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2255 struct via_spec *spec = codec->spec;
2256 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2257 hda_nid_t mux;
2258 int cur;
2259
2260 cur = ucontrol->value.enumerated.item[0];
2261 if (cur < 0 || cur >= spec->num_inputs)
2262 return -EINVAL;
2263 if (spec->cur_mux[idx] == cur)
2264 return 0;
2265 spec->cur_mux[idx] = cur;
2266 if (spec->dyn_adc_switch) {
2267 int adc_idx = spec->inputs[cur].adc_idx;
2268 mux = spec->mux_nids[adc_idx];
2269 via_dyn_adc_pcm_resetup(codec, cur);
2270 } else {
2271 mux = spec->mux_nids[idx];
2272 if (snd_BUG_ON(!mux))
2273 return -EINVAL;
2274 }
2275
2276 if (mux) {
2277 /* switch to D0 beofre change index */
Takashi Iwai054d8672012-01-24 12:25:50 +01002278 update_power_state(codec, mux, AC_PWRST_D0);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002279 snd_hda_codec_write(codec, mux, 0,
2280 AC_VERB_SET_CONNECT_SEL,
2281 spec->inputs[cur].mux_idx);
2282 }
2283
2284 /* update jack power state */
2285 set_widgets_power_state(codec);
2286 return 0;
2287}
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002288
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002289static const struct snd_kcontrol_new via_input_src_ctl = {
2290 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2291 /* The multiple "Capture Source" controls confuse alsamixer
2292 * So call somewhat different..
2293 */
2294 /* .name = "Capture Source", */
2295 .name = "Input Source",
2296 .info = via_mux_enum_info,
2297 .get = via_mux_enum_get,
2298 .put = via_mux_enum_put,
2299};
2300
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002301static int create_input_src_ctls(struct hda_codec *codec, int count)
2302{
2303 struct via_spec *spec = codec->spec;
2304 struct snd_kcontrol_new *knew;
2305
2306 if (spec->num_inputs <= 1 || !count)
2307 return 0; /* no need for single src */
2308
2309 knew = via_clone_control(spec, &via_input_src_ctl);
2310 if (!knew)
2311 return -ENOMEM;
2312 knew->count = count;
2313 return 0;
2314}
2315
2316/* add the powersave loopback-list entry */
Takashi Iwai13af8e72011-06-20 14:05:46 +02002317static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2318{
2319 struct hda_amp_list *list;
2320
2321 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2322 return;
2323 list = spec->loopback_list + spec->num_loopbacks;
2324 list->nid = mix;
2325 list->dir = HDA_INPUT;
2326 list->idx = idx;
2327 spec->num_loopbacks++;
2328 spec->loopback.amplist = spec->loopback_list;
2329}
Takashi Iwai13af8e72011-06-20 14:05:46 +02002330
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002331static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
Takashi Iwai8d087c72011-06-28 12:45:47 +02002332 hda_nid_t dst)
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002333{
Takashi Iwai8d087c72011-06-28 12:45:47 +02002334 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002335}
2336
2337/* add the input-route to the given pin */
2338static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002339{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002340 struct via_spec *spec = codec->spec;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002341 int c, idx;
2342
2343 spec->inputs[spec->num_inputs].adc_idx = -1;
2344 spec->inputs[spec->num_inputs].pin = pin;
2345 for (c = 0; c < spec->num_adc_nids; c++) {
2346 if (spec->mux_nids[c]) {
2347 idx = get_connection_index(codec, spec->mux_nids[c],
2348 pin);
2349 if (idx < 0)
2350 continue;
2351 spec->inputs[spec->num_inputs].mux_idx = idx;
2352 } else {
Takashi Iwai8d087c72011-06-28 12:45:47 +02002353 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002354 continue;
2355 }
2356 spec->inputs[spec->num_inputs].adc_idx = c;
2357 /* Can primary ADC satisfy all inputs? */
2358 if (!spec->dyn_adc_switch &&
2359 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2360 snd_printd(KERN_INFO
2361 "via: dynamic ADC switching enabled\n");
2362 spec->dyn_adc_switch = 1;
2363 }
2364 return true;
2365 }
2366 return false;
2367}
2368
2369static int get_mux_nids(struct hda_codec *codec);
2370
2371/* parse input-routes; fill ADCs, MUXs and input-src entries */
2372static int parse_analog_inputs(struct hda_codec *codec)
2373{
2374 struct via_spec *spec = codec->spec;
2375 const struct auto_pin_cfg *cfg = &spec->autocfg;
2376 int i, err;
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002377
2378 err = via_fill_adcs(codec);
2379 if (err < 0)
2380 return err;
2381 err = get_mux_nids(codec);
2382 if (err < 0)
2383 return err;
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002384
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002385 /* fill all input-routes */
2386 for (i = 0; i < cfg->num_inputs; i++) {
2387 if (add_input_route(codec, cfg->inputs[i].pin))
2388 spec->inputs[spec->num_inputs++].label =
2389 hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwaif3268512010-08-30 11:00:19 +02002390 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002391
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002392 /* check for internal loopback recording */
2393 if (spec->aa_mix_nid &&
2394 add_input_route(codec, spec->aa_mix_nid))
2395 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2396
2397 return 0;
2398}
2399
2400/* create analog-loopback volume/switch controls */
2401static int create_loopback_ctls(struct hda_codec *codec)
2402{
2403 struct via_spec *spec = codec->spec;
2404 const struct auto_pin_cfg *cfg = &spec->autocfg;
2405 const char *prev_label = NULL;
2406 int type_idx = 0;
2407 int i, j, err, idx;
2408
2409 if (!spec->aa_mix_nid)
2410 return 0;
2411
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002412 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002413 hda_nid_t pin = cfg->inputs[i].pin;
2414 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2415
Takashi Iwai1e11cae2011-06-21 12:57:22 +02002416 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002417 type_idx++;
2418 else
2419 type_idx = 0;
Takashi Iwai1e11cae2011-06-21 12:57:22 +02002420 prev_label = label;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002421 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2422 if (idx >= 0) {
Lydia Wang16922282011-03-22 16:24:10 +08002423 err = via_new_analog_input(spec, label, type_idx,
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002424 idx, spec->aa_mix_nid);
Takashi Iwai13af8e72011-06-20 14:05:46 +02002425 if (err < 0)
2426 return err;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002427 add_loopback_list(spec, spec->aa_mix_nid, idx);
Takashi Iwai13af8e72011-06-20 14:05:46 +02002428 }
Takashi Iwaie3d7a142011-06-20 13:52:33 +02002429
2430 /* remember the label for smart51 control */
2431 for (j = 0; j < spec->smart51_nums; j++) {
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002432 if (spec->smart51_pins[j] == pin) {
Takashi Iwaie3d7a142011-06-20 13:52:33 +02002433 spec->smart51_idxs[j] = idx;
2434 spec->smart51_labels[j] = label;
2435 break;
2436 }
2437 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002438 }
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002439 return 0;
2440}
2441
2442/* create mic-boost controls (if present) */
2443static int create_mic_boost_ctls(struct hda_codec *codec)
2444{
2445 struct via_spec *spec = codec->spec;
2446 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8d8bbc62012-02-22 12:26:38 +01002447 const char *prev_label = NULL;
2448 int type_idx = 0;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002449 int i, err;
2450
2451 for (i = 0; i < cfg->num_inputs; i++) {
2452 hda_nid_t pin = cfg->inputs[i].pin;
2453 unsigned int caps;
2454 const char *label;
2455 char name[32];
2456
2457 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2458 continue;
2459 caps = query_amp_caps(codec, pin, HDA_INPUT);
2460 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2461 continue;
2462 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai8d8bbc62012-02-22 12:26:38 +01002463 if (prev_label && !strcmp(label, prev_label))
2464 type_idx++;
2465 else
2466 type_idx = 0;
2467 prev_label = label;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002468 snprintf(name, sizeof(name), "%s Boost Volume", label);
Takashi Iwai8d8bbc62012-02-22 12:26:38 +01002469 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002470 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2471 if (err < 0)
2472 return err;
2473 }
2474 return 0;
2475}
2476
2477/* create capture and input-src controls for multiple streams */
2478static int create_multi_adc_ctls(struct hda_codec *codec)
2479{
2480 struct via_spec *spec = codec->spec;
2481 int i, err;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002482
2483 /* create capture mixer elements */
2484 for (i = 0; i < spec->num_adc_nids; i++) {
2485 hda_nid_t adc = spec->adc_nids[i];
2486 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2487 "Capture Volume", i,
2488 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2489 HDA_INPUT));
2490 if (err < 0)
2491 return err;
2492 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2493 "Capture Switch", i,
2494 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2495 HDA_INPUT));
2496 if (err < 0)
2497 return err;
2498 }
2499
2500 /* input-source control */
2501 for (i = 0; i < spec->num_adc_nids; i++)
2502 if (!spec->mux_nids[i])
2503 break;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002504 err = create_input_src_ctls(codec, i);
2505 if (err < 0)
2506 return err;
2507 return 0;
2508}
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002509
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002510/* bind capture volume/switch */
2511static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2512 HDA_BIND_VOL("Capture Volume", 0);
2513static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2514 HDA_BIND_SW("Capture Switch", 0);
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002515
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002516static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2517 struct hda_ctl_ops *ops)
2518{
2519 struct hda_bind_ctls *ctl;
2520 int i;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002521
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002522 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2523 if (!ctl)
2524 return -ENOMEM;
2525 ctl->ops = ops;
2526 for (i = 0; i < spec->num_adc_nids; i++)
2527 ctl->values[i] =
2528 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2529 *ctl_ret = ctl;
2530 return 0;
2531}
2532
2533/* create capture and input-src controls for dynamic ADC-switch case */
2534static int create_dyn_adc_ctls(struct hda_codec *codec)
2535{
2536 struct via_spec *spec = codec->spec;
2537 struct snd_kcontrol_new *knew;
2538 int err;
2539
2540 /* set up the bind capture ctls */
2541 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2542 if (err < 0)
2543 return err;
2544 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2545 if (err < 0)
2546 return err;
2547
2548 /* create capture mixer elements */
2549 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2550 if (!knew)
2551 return -ENOMEM;
2552 knew->private_value = (long)spec->bind_cap_vol;
2553
2554 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2555 if (!knew)
2556 return -ENOMEM;
2557 knew->private_value = (long)spec->bind_cap_sw;
2558
2559 /* input-source control */
2560 err = create_input_src_ctls(codec, 1);
2561 if (err < 0)
2562 return err;
2563 return 0;
2564}
2565
2566/* parse and create capture-related stuff */
2567static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2568{
2569 struct via_spec *spec = codec->spec;
2570 int err;
2571
2572 err = parse_analog_inputs(codec);
2573 if (err < 0)
2574 return err;
2575 if (spec->dyn_adc_switch)
2576 err = create_dyn_adc_ctls(codec);
2577 else
2578 err = create_multi_adc_ctls(codec);
2579 if (err < 0)
2580 return err;
2581 err = create_loopback_ctls(codec);
2582 if (err < 0)
2583 return err;
2584 err = create_mic_boost_ctls(codec);
2585 if (err < 0)
2586 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002587 return 0;
2588}
2589
Harald Welte76d9b0d2008-09-09 15:50:37 +08002590static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2591{
2592 unsigned int def_conf;
2593 unsigned char seqassoc;
2594
Takashi Iwai2f334f92009-02-20 14:37:42 +01002595 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002596 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2597 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002598 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2599 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2600 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2601 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002602 }
2603
2604 return;
2605}
2606
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002607static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002608 struct snd_ctl_elem_value *ucontrol)
2609{
2610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2611 struct via_spec *spec = codec->spec;
2612
2613 if (spec->codec_type != VT1708)
2614 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002615 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002616 return 0;
2617}
2618
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002619static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002620 struct snd_ctl_elem_value *ucontrol)
2621{
2622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2623 struct via_spec *spec = codec->spec;
Takashi Iwai187d3332011-11-24 16:33:09 +01002624 int val;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002625
2626 if (spec->codec_type != VT1708)
2627 return 0;
Takashi Iwai187d3332011-11-24 16:33:09 +01002628 val = !!ucontrol->value.integer.value[0];
2629 if (spec->vt1708_jack_detect == val)
2630 return 0;
2631 spec->vt1708_jack_detect = val;
2632 if (spec->vt1708_jack_detect &&
2633 snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002634 mute_aa_path(codec, 1);
2635 notify_aa_path_ctls(codec);
2636 }
Takashi Iwai187d3332011-11-24 16:33:09 +01002637 via_hp_automute(codec);
2638 vt1708_update_hp_work(spec);
2639 return 1;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002640}
2641
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002642static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2643 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2644 .name = "Jack Detect",
2645 .count = 1,
2646 .info = snd_ctl_boolean_mono_info,
2647 .get = vt1708_jack_detect_get,
2648 .put = vt1708_jack_detect_put,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002649};
2650
Takashi Iwai12daef62011-06-18 17:45:49 +02002651static void fill_dig_outs(struct hda_codec *codec);
2652static void fill_dig_in(struct hda_codec *codec);
2653
2654static int via_parse_auto_config(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002655{
2656 struct via_spec *spec = codec->spec;
2657 int err;
2658
2659 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2660 if (err < 0)
2661 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002662 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
Takashi Iwai7f0df882011-06-18 17:33:34 +02002663 return -EINVAL;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002664
Takashi Iwai4a796162011-06-17 17:53:38 +02002665 err = via_auto_create_multi_out_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002666 if (err < 0)
2667 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002668 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002669 if (err < 0)
2670 return err;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002671 err = via_auto_create_speaker_ctls(codec);
2672 if (err < 0)
2673 return err;
Takashi Iwai3214b962011-07-18 12:49:25 +02002674 err = via_auto_create_loopback_switch(codec);
2675 if (err < 0)
2676 return err;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002677 err = via_auto_create_analog_input_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002678 if (err < 0)
2679 return err;
2680
2681 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2682
Takashi Iwai12daef62011-06-18 17:45:49 +02002683 fill_dig_outs(codec);
2684 fill_dig_in(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002685
Takashi Iwai603c4012008-07-30 15:01:44 +02002686 if (spec->kctls.list)
2687 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002688
Joseph Chanc577b8a2006-11-29 15:29:40 +01002689
Takashi Iwai3214b962011-07-18 12:49:25 +02002690 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
Takashi Iwaiece8d042011-06-19 16:24:21 +02002691 err = via_hp_build(codec);
2692 if (err < 0)
2693 return err;
2694 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002695
Takashi Iwaif4a78282011-06-17 18:46:48 +02002696 err = via_smart51_build(codec);
2697 if (err < 0)
2698 return err;
2699
Takashi Iwai5d417622011-06-20 11:32:27 +02002700 /* assign slave outs */
2701 if (spec->slave_dig_outs[0])
2702 codec->slave_dig_outs = spec->slave_dig_outs;
2703
Joseph Chanc577b8a2006-11-29 15:29:40 +01002704 return 1;
2705}
2706
Takashi Iwai5d417622011-06-20 11:32:27 +02002707static void via_auto_init_dig_outs(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002708{
Lydia Wang25eaba22009-10-10 19:08:43 +08002709 struct via_spec *spec = codec->spec;
Takashi Iwai5d417622011-06-20 11:32:27 +02002710 if (spec->multiout.dig_out_nid)
2711 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2712 if (spec->slave_dig_outs[0])
2713 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2714}
Lydia Wang25eaba22009-10-10 19:08:43 +08002715
Takashi Iwai5d417622011-06-20 11:32:27 +02002716static void via_auto_init_dig_in(struct hda_codec *codec)
2717{
2718 struct via_spec *spec = codec->spec;
2719 if (!spec->dig_in_nid)
2720 return;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002721 snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN);
Takashi Iwai5d417622011-06-20 11:32:27 +02002722}
2723
David Henningsson4e2d16d2012-10-08 15:44:14 +02002724static void via_jack_output_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2725{
2726 set_widgets_power_state(codec);
2727 via_hp_automute(codec);
2728}
2729
2730static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2731{
2732 set_widgets_power_state(codec);
2733}
2734
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002735/* initialize the unsolicited events */
2736static void via_auto_init_unsol_event(struct hda_codec *codec)
2737{
2738 struct via_spec *spec = codec->spec;
2739 struct auto_pin_cfg *cfg = &spec->autocfg;
2740 unsigned int ev;
2741 int i;
David Henningsson4e2d16d2012-10-08 15:44:14 +02002742 hda_jack_callback cb;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002743
2744 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
David Henningsson4e2d16d2012-10-08 15:44:14 +02002745 snd_hda_jack_detect_enable_callback(codec, cfg->hp_pins[0],
2746 VIA_HP_EVENT | VIA_JACK_EVENT,
2747 via_jack_output_event);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002748
2749 if (cfg->speaker_pins[0])
2750 ev = VIA_LINE_EVENT;
2751 else
2752 ev = 0;
David Henningsson4e2d16d2012-10-08 15:44:14 +02002753 cb = ev ? via_jack_output_event : via_jack_powerstate_event;
2754
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002755 for (i = 0; i < cfg->line_outs; i++) {
2756 if (cfg->line_out_pins[i] &&
2757 is_jack_detectable(codec, cfg->line_out_pins[i]))
David Henningsson4e2d16d2012-10-08 15:44:14 +02002758 snd_hda_jack_detect_enable_callback(codec, cfg->line_out_pins[i],
2759 ev | VIA_JACK_EVENT, cb);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002760 }
2761
2762 for (i = 0; i < cfg->num_inputs; i++) {
2763 if (is_jack_detectable(codec, cfg->inputs[i].pin))
David Henningsson4e2d16d2012-10-08 15:44:14 +02002764 snd_hda_jack_detect_enable_callback(codec, cfg->inputs[i].pin,
2765 VIA_JACK_EVENT,
2766 via_jack_powerstate_event);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002767 }
2768}
2769
Takashi Iwai5d417622011-06-20 11:32:27 +02002770static int via_init(struct hda_codec *codec)
2771{
2772 struct via_spec *spec = codec->spec;
2773 int i;
2774
2775 for (i = 0; i < spec->num_iverbs; i++)
2776 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2777
Takashi Iwaie9d010c2012-02-01 10:33:23 +01002778 /* init power states */
2779 set_widgets_power_state(codec);
2780 __analog_low_current_mode(codec, true);
2781
Joseph Chanc577b8a2006-11-29 15:29:40 +01002782 via_auto_init_multi_out(codec);
2783 via_auto_init_hp_out(codec);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002784 via_auto_init_speaker_out(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002785 via_auto_init_analog_input(codec);
Takashi Iwai5d417622011-06-20 11:32:27 +02002786 via_auto_init_dig_outs(codec);
2787 via_auto_init_dig_in(codec);
Lydia Wang118909562011-03-23 17:57:34 +08002788
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002789 via_auto_init_unsol_event(codec);
2790
2791 via_hp_automute(codec);
Takashi Iwai187d3332011-11-24 16:33:09 +01002792 vt1708_update_hp_work(spec);
Lydia Wang25eaba22009-10-10 19:08:43 +08002793
Joseph Chanc577b8a2006-11-29 15:29:40 +01002794 return 0;
2795}
2796
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002797static void vt1708_update_hp_jack_state(struct work_struct *work)
2798{
2799 struct via_spec *spec = container_of(work, struct via_spec,
2800 vt1708_hp_work.work);
2801 if (spec->codec_type != VT1708)
2802 return;
Takashi Iwai1835a0f2011-10-27 22:12:46 +02002803 snd_hda_jack_set_dirty_all(spec->codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002804 /* if jack state toggled */
2805 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002806 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002807 spec->vt1708_hp_present ^= 1;
2808 via_hp_automute(spec->codec);
2809 }
Takashi Iwai187d3332011-11-24 16:33:09 +01002810 if (spec->vt1708_jack_detect)
2811 schedule_delayed_work(&spec->vt1708_hp_work,
2812 msecs_to_jiffies(100));
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002813}
2814
Takashi Iwai337b9d02009-07-07 18:18:59 +02002815static int get_mux_nids(struct hda_codec *codec)
2816{
2817 struct via_spec *spec = codec->spec;
2818 hda_nid_t nid, conn[8];
2819 unsigned int type;
2820 int i, n;
2821
2822 for (i = 0; i < spec->num_adc_nids; i++) {
2823 nid = spec->adc_nids[i];
2824 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002825 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002826 if (type == AC_WID_PIN)
2827 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002828 n = snd_hda_get_connections(codec, nid, conn,
2829 ARRAY_SIZE(conn));
2830 if (n <= 0)
2831 break;
2832 if (n > 1) {
2833 spec->mux_nids[i] = nid;
2834 break;
2835 }
2836 nid = conn[0];
2837 }
2838 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002839 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002840}
2841
Joseph Chanc577b8a2006-11-29 15:29:40 +01002842static int patch_vt1708(struct hda_codec *codec)
2843{
2844 struct via_spec *spec;
2845 int err;
2846
2847 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002848 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002849 if (spec == NULL)
2850 return -ENOMEM;
2851
Takashi Iwai620e2b22011-06-17 17:19:19 +02002852 spec->aa_mix_nid = 0x17;
2853
Takashi Iwai12daef62011-06-18 17:45:49 +02002854 /* Add HP and CD pin config connect bit re-config action */
2855 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2856 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2857
Joseph Chanc577b8a2006-11-29 15:29:40 +01002858 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002859 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002860 if (err < 0) {
2861 via_free(codec);
2862 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002863 }
2864
Takashi Iwai12daef62011-06-18 17:45:49 +02002865 /* add jack detect on/off control */
2866 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2867 return -ENOMEM;
2868
Takashi Iwaibc9b562382008-05-23 17:50:27 +02002869 /* disable 32bit format on VT1708 */
2870 if (codec->vendor_id == 0x11061708)
2871 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002872
Lydia Wange322a362011-06-29 13:52:02 +08002873 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2874
Joseph Chanc577b8a2006-11-29 15:29:40 +01002875 codec->patch_ops = via_patch_ops;
2876
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002877 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002878 return 0;
2879}
2880
Takashi Iwaiddd304d2011-06-21 16:33:55 +02002881static int patch_vt1709(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002882{
2883 struct via_spec *spec;
2884 int err;
2885
2886 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002887 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002888 if (spec == NULL)
2889 return -ENOMEM;
2890
Takashi Iwai620e2b22011-06-17 17:19:19 +02002891 spec->aa_mix_nid = 0x18;
2892
Takashi Iwai12daef62011-06-18 17:45:49 +02002893 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002894 if (err < 0) {
2895 via_free(codec);
2896 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002897 }
2898
Joseph Chanc577b8a2006-11-29 15:29:40 +01002899 codec->patch_ops = via_patch_ops;
2900
Josepch Chanf7278fd2007-12-13 16:40:40 +01002901 return 0;
2902}
2903
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002904static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2905{
2906 struct via_spec *spec = codec->spec;
2907 int imux_is_smixer;
2908 unsigned int parm;
2909 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +08002910 if ((spec->codec_type != VT1708B_4CH) &&
2911 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002912 is_8ch = 1;
2913
2914 /* SW0 (17h) = stereo mixer */
2915 imux_is_smixer =
2916 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2917 == ((spec->codec_type == VT1708S) ? 5 : 0));
2918 /* inputs */
2919 /* PW 1/2/5 (1ah/1bh/1eh) */
2920 parm = AC_PWRST_D3;
2921 set_pin_power_state(codec, 0x1a, &parm);
2922 set_pin_power_state(codec, 0x1b, &parm);
2923 set_pin_power_state(codec, 0x1e, &parm);
2924 if (imux_is_smixer)
2925 parm = AC_PWRST_D0;
2926 /* SW0 (17h), AIW 0/1 (13h/14h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01002927 update_power_state(codec, 0x17, parm);
2928 update_power_state(codec, 0x13, parm);
2929 update_power_state(codec, 0x14, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002930
2931 /* outputs */
2932 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2933 parm = AC_PWRST_D3;
2934 set_pin_power_state(codec, 0x19, &parm);
2935 if (spec->smart51_enabled)
2936 set_pin_power_state(codec, 0x1b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01002937 update_power_state(codec, 0x18, parm);
2938 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002939
2940 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2941 if (is_8ch) {
2942 parm = AC_PWRST_D3;
2943 set_pin_power_state(codec, 0x22, &parm);
2944 if (spec->smart51_enabled)
2945 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01002946 update_power_state(codec, 0x26, parm);
2947 update_power_state(codec, 0x24, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002948 } else if (codec->vendor_id == 0x11064397) {
2949 /* PW7(23h), SW2(27h), AOW2(25h) */
2950 parm = AC_PWRST_D3;
2951 set_pin_power_state(codec, 0x23, &parm);
2952 if (spec->smart51_enabled)
2953 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01002954 update_power_state(codec, 0x27, parm);
2955 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002956 }
2957
2958 /* PW 3/4/7 (1ch/1dh/23h) */
2959 parm = AC_PWRST_D3;
2960 /* force to D0 for internal Speaker */
2961 set_pin_power_state(codec, 0x1c, &parm);
2962 set_pin_power_state(codec, 0x1d, &parm);
2963 if (is_8ch)
2964 set_pin_power_state(codec, 0x23, &parm);
2965
2966 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01002967 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
2968 update_power_state(codec, 0x10, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002969 if (is_8ch) {
Takashi Iwai054d8672012-01-24 12:25:50 +01002970 update_power_state(codec, 0x25, parm);
2971 update_power_state(codec, 0x27, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002972 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
Takashi Iwai054d8672012-01-24 12:25:50 +01002973 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002974}
2975
Lydia Wang518bf3b2009-10-10 19:07:29 +08002976static int patch_vt1708S(struct hda_codec *codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +02002977static int patch_vt1708B(struct hda_codec *codec)
Josepch Chanf7278fd2007-12-13 16:40:40 +01002978{
2979 struct via_spec *spec;
2980 int err;
2981
Lydia Wang518bf3b2009-10-10 19:07:29 +08002982 if (get_codec_type(codec) == VT1708BCE)
2983 return patch_vt1708S(codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +02002984
Josepch Chanf7278fd2007-12-13 16:40:40 +01002985 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002986 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002987 if (spec == NULL)
2988 return -ENOMEM;
2989
Takashi Iwai620e2b22011-06-17 17:19:19 +02002990 spec->aa_mix_nid = 0x16;
2991
Josepch Chanf7278fd2007-12-13 16:40:40 +01002992 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002993 err = via_parse_auto_config(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002994 if (err < 0) {
2995 via_free(codec);
2996 return err;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002997 }
2998
Josepch Chanf7278fd2007-12-13 16:40:40 +01002999 codec->patch_ops = via_patch_ops;
3000
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003001 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3002
Josepch Chanf7278fd2007-12-13 16:40:40 +01003003 return 0;
3004}
3005
Harald Welted949cac2008-09-09 15:56:01 +08003006/* Patch for VT1708S */
Takashi Iwai096a8852011-06-20 12:09:02 +02003007static const struct hda_verb vt1708S_init_verbs[] = {
Harald Welted7426322008-09-15 22:43:23 +08003008 /* Enable Mic Boost Volume backdoor */
3009 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003010 /* don't bybass mixer */
3011 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08003012 { }
3013};
3014
Takashi Iwai9da29272009-05-07 16:31:14 +02003015/* fill out digital output widgets; one for master and one for slave outputs */
3016static void fill_dig_outs(struct hda_codec *codec)
3017{
3018 struct via_spec *spec = codec->spec;
3019 int i;
3020
3021 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3022 hda_nid_t nid;
3023 int conn;
3024
3025 nid = spec->autocfg.dig_out_pins[i];
3026 if (!nid)
3027 continue;
3028 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3029 if (conn < 1)
3030 continue;
3031 if (!spec->multiout.dig_out_nid)
3032 spec->multiout.dig_out_nid = nid;
3033 else {
3034 spec->slave_dig_outs[0] = nid;
3035 break; /* at most two dig outs */
3036 }
3037 }
3038}
3039
Takashi Iwai12daef62011-06-18 17:45:49 +02003040static void fill_dig_in(struct hda_codec *codec)
Harald Welted949cac2008-09-09 15:56:01 +08003041{
3042 struct via_spec *spec = codec->spec;
Takashi Iwai12daef62011-06-18 17:45:49 +02003043 hda_nid_t dig_nid;
3044 int i, err;
Harald Welted949cac2008-09-09 15:56:01 +08003045
Takashi Iwai12daef62011-06-18 17:45:49 +02003046 if (!spec->autocfg.dig_in_pin)
3047 return;
Harald Welted949cac2008-09-09 15:56:01 +08003048
Takashi Iwai12daef62011-06-18 17:45:49 +02003049 dig_nid = codec->start_nid;
3050 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3051 unsigned int wcaps = get_wcaps(codec, dig_nid);
3052 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3053 continue;
3054 if (!(wcaps & AC_WCAP_DIGITAL))
3055 continue;
3056 if (!(wcaps & AC_WCAP_CONN_LIST))
3057 continue;
3058 err = get_connection_index(codec, dig_nid,
3059 spec->autocfg.dig_in_pin);
3060 if (err >= 0) {
3061 spec->dig_in_nid = dig_nid;
3062 break;
3063 }
3064 }
Harald Welted949cac2008-09-09 15:56:01 +08003065}
3066
Lydia Wang6369bcf2009-10-10 19:08:31 +08003067static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3068 int offset, int num_steps, int step_size)
3069{
3070 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3071 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3072 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3073 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3074 (0 << AC_AMPCAP_MUTE_SHIFT));
3075}
3076
Harald Welted949cac2008-09-09 15:56:01 +08003077static int patch_vt1708S(struct hda_codec *codec)
3078{
3079 struct via_spec *spec;
3080 int err;
3081
3082 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003083 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003084 if (spec == NULL)
3085 return -ENOMEM;
3086
Takashi Iwai620e2b22011-06-17 17:19:19 +02003087 spec->aa_mix_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003088 override_mic_boost(codec, 0x1a, 0, 3, 40);
3089 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003090
Harald Welted949cac2008-09-09 15:56:01 +08003091 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003092 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003093 if (err < 0) {
3094 via_free(codec);
3095 return err;
Harald Welted949cac2008-09-09 15:56:01 +08003096 }
3097
Takashi Iwai096a8852011-06-20 12:09:02 +02003098 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003099
Harald Welted949cac2008-09-09 15:56:01 +08003100 codec->patch_ops = via_patch_ops;
3101
Lydia Wang518bf3b2009-10-10 19:07:29 +08003102 /* correct names for VT1708BCE */
3103 if (get_codec_type(codec) == VT1708BCE) {
3104 kfree(codec->chip_name);
3105 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3106 snprintf(codec->bus->card->mixername,
3107 sizeof(codec->bus->card->mixername),
3108 "%s %s", codec->vendor_name, codec->chip_name);
Lydia Wang970f630f2011-03-22 16:25:56 +08003109 }
Lydia Wangbc92df72011-03-23 17:56:05 +08003110 /* correct names for VT1705 */
3111 if (codec->vendor_id == 0x11064397) {
3112 kfree(codec->chip_name);
3113 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3114 snprintf(codec->bus->card->mixername,
3115 sizeof(codec->bus->card->mixername),
3116 "%s %s", codec->vendor_name, codec->chip_name);
3117 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003118 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +08003119 return 0;
3120}
3121
3122/* Patch for VT1702 */
3123
Takashi Iwai096a8852011-06-20 12:09:02 +02003124static const struct hda_verb vt1702_init_verbs[] = {
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003125 /* mixer enable */
3126 {0x1, 0xF88, 0x3},
3127 /* GPIO 0~2 */
3128 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08003129 { }
3130};
3131
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003132static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3133{
3134 int imux_is_smixer =
3135 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3136 unsigned int parm;
3137 /* inputs */
3138 /* PW 1/2/5 (14h/15h/18h) */
3139 parm = AC_PWRST_D3;
3140 set_pin_power_state(codec, 0x14, &parm);
3141 set_pin_power_state(codec, 0x15, &parm);
3142 set_pin_power_state(codec, 0x18, &parm);
3143 if (imux_is_smixer)
3144 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3145 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003146 update_power_state(codec, 0x13, parm);
3147 update_power_state(codec, 0x12, parm);
3148 update_power_state(codec, 0x1f, parm);
3149 update_power_state(codec, 0x20, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003150
3151 /* outputs */
3152 /* PW 3/4 (16h/17h) */
3153 parm = AC_PWRST_D3;
3154 set_pin_power_state(codec, 0x17, &parm);
3155 set_pin_power_state(codec, 0x16, &parm);
3156 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003157 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
3158 update_power_state(codec, 0x10, parm);
3159 update_power_state(codec, 0x1d, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003160}
3161
Harald Welted949cac2008-09-09 15:56:01 +08003162static int patch_vt1702(struct hda_codec *codec)
3163{
3164 struct via_spec *spec;
3165 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003166
3167 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003168 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003169 if (spec == NULL)
3170 return -ENOMEM;
3171
Takashi Iwai620e2b22011-06-17 17:19:19 +02003172 spec->aa_mix_nid = 0x1a;
3173
Takashi Iwai12daef62011-06-18 17:45:49 +02003174 /* limit AA path volume to 0 dB */
3175 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3176 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3177 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3178 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3179 (1 << AC_AMPCAP_MUTE_SHIFT));
3180
Harald Welted949cac2008-09-09 15:56:01 +08003181 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003182 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003183 if (err < 0) {
3184 via_free(codec);
3185 return err;
Harald Welted949cac2008-09-09 15:56:01 +08003186 }
3187
Takashi Iwai096a8852011-06-20 12:09:02 +02003188 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003189
Harald Welted949cac2008-09-09 15:56:01 +08003190 codec->patch_ops = via_patch_ops;
3191
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003192 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08003193 return 0;
3194}
3195
Lydia Wangeb7188c2009-10-10 19:08:34 +08003196/* Patch for VT1718S */
3197
Takashi Iwai096a8852011-06-20 12:09:02 +02003198static const struct hda_verb vt1718S_init_verbs[] = {
Lydia Wang4ab2d532011-03-24 12:42:03 +08003199 /* Enable MW0 adjust Gain 5 */
3200 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08003201 /* Enable Boost Volume backdoor */
3202 {0x1, 0xf88, 0x8},
Takashi Iwai5d417622011-06-20 11:32:27 +02003203
Lydia Wangeb7188c2009-10-10 19:08:34 +08003204 { }
3205};
3206
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003207static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3208{
3209 struct via_spec *spec = codec->spec;
3210 int imux_is_smixer;
Takashi Iwai61625522012-07-25 13:54:55 +02003211 unsigned int parm, parm2;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003212 /* MUX6 (1eh) = stereo mixer */
3213 imux_is_smixer =
3214 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3215 /* inputs */
3216 /* PW 5/6/7 (29h/2ah/2bh) */
3217 parm = AC_PWRST_D3;
3218 set_pin_power_state(codec, 0x29, &parm);
3219 set_pin_power_state(codec, 0x2a, &parm);
3220 set_pin_power_state(codec, 0x2b, &parm);
3221 if (imux_is_smixer)
3222 parm = AC_PWRST_D0;
3223 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003224 update_power_state(codec, 0x1e, parm);
3225 update_power_state(codec, 0x1f, parm);
3226 update_power_state(codec, 0x10, parm);
3227 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003228
3229 /* outputs */
3230 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3231 parm = AC_PWRST_D3;
3232 set_pin_power_state(codec, 0x27, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003233 update_power_state(codec, 0x1a, parm);
Takashi Iwai61625522012-07-25 13:54:55 +02003234 parm2 = parm; /* for pin 0x0b */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003235
3236 /* PW2 (26h), AOW2 (ah) */
3237 parm = AC_PWRST_D3;
3238 set_pin_power_state(codec, 0x26, &parm);
3239 if (spec->smart51_enabled)
3240 set_pin_power_state(codec, 0x2b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003241 update_power_state(codec, 0xa, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003242
3243 /* PW0 (24h), AOW0 (8h) */
3244 parm = AC_PWRST_D3;
3245 set_pin_power_state(codec, 0x24, &parm);
3246 if (!spec->hp_independent_mode) /* check for redirected HP */
3247 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003248 update_power_state(codec, 0x8, parm);
Takashi Iwai61625522012-07-25 13:54:55 +02003249 if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3)
3250 parm = parm2;
3251 update_power_state(codec, 0xb, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003252 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003253 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003254
3255 /* PW1 (25h), AOW1 (9h) */
3256 parm = AC_PWRST_D3;
3257 set_pin_power_state(codec, 0x25, &parm);
3258 if (spec->smart51_enabled)
3259 set_pin_power_state(codec, 0x2a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003260 update_power_state(codec, 0x9, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003261
3262 if (spec->hp_independent_mode) {
3263 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3264 parm = AC_PWRST_D3;
3265 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003266 update_power_state(codec, 0x1b, parm);
3267 update_power_state(codec, 0x34, parm);
3268 update_power_state(codec, 0xc, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003269 }
3270}
3271
Takashi Iwai30b45032011-07-11 17:05:04 +02003272/* Add a connection to the primary DAC from AA-mixer for some codecs
3273 * This isn't listed from the raw info, but the chip has a secret connection.
3274 */
3275static int add_secret_dac_path(struct hda_codec *codec)
3276{
3277 struct via_spec *spec = codec->spec;
3278 int i, nums;
3279 hda_nid_t conn[8];
3280 hda_nid_t nid;
3281
3282 if (!spec->aa_mix_nid)
3283 return 0;
3284 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
3285 ARRAY_SIZE(conn) - 1);
3286 for (i = 0; i < nums; i++) {
3287 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
3288 return 0;
3289 }
3290
3291 /* find the primary DAC and add to the connection list */
3292 nid = codec->start_nid;
3293 for (i = 0; i < codec->num_nodes; i++, nid++) {
3294 unsigned int caps = get_wcaps(codec, nid);
3295 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
3296 !(caps & AC_WCAP_DIGITAL)) {
3297 conn[nums++] = nid;
3298 return snd_hda_override_conn_list(codec,
3299 spec->aa_mix_nid,
3300 nums, conn);
3301 }
3302 }
3303 return 0;
3304}
3305
3306
Lydia Wangeb7188c2009-10-10 19:08:34 +08003307static int patch_vt1718S(struct hda_codec *codec)
3308{
3309 struct via_spec *spec;
3310 int err;
3311
3312 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003313 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003314 if (spec == NULL)
3315 return -ENOMEM;
3316
Takashi Iwai620e2b22011-06-17 17:19:19 +02003317 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003318 override_mic_boost(codec, 0x2b, 0, 3, 40);
3319 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02003320 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003321
Lydia Wangeb7188c2009-10-10 19:08:34 +08003322 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003323 err = via_parse_auto_config(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003324 if (err < 0) {
3325 via_free(codec);
3326 return err;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003327 }
3328
Takashi Iwai096a8852011-06-20 12:09:02 +02003329 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003330
Lydia Wangeb7188c2009-10-10 19:08:34 +08003331 codec->patch_ops = via_patch_ops;
3332
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003333 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3334
Lydia Wangeb7188c2009-10-10 19:08:34 +08003335 return 0;
3336}
Lydia Wangf3db4232009-10-10 19:08:41 +08003337
3338/* Patch for VT1716S */
3339
3340static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3341 struct snd_ctl_elem_info *uinfo)
3342{
3343 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3344 uinfo->count = 1;
3345 uinfo->value.integer.min = 0;
3346 uinfo->value.integer.max = 1;
3347 return 0;
3348}
3349
3350static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3351 struct snd_ctl_elem_value *ucontrol)
3352{
3353 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3354 int index = 0;
3355
3356 index = snd_hda_codec_read(codec, 0x26, 0,
3357 AC_VERB_GET_CONNECT_SEL, 0);
3358 if (index != -1)
3359 *ucontrol->value.integer.value = index;
3360
3361 return 0;
3362}
3363
3364static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3365 struct snd_ctl_elem_value *ucontrol)
3366{
3367 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3368 struct via_spec *spec = codec->spec;
3369 int index = *ucontrol->value.integer.value;
3370
3371 snd_hda_codec_write(codec, 0x26, 0,
3372 AC_VERB_SET_CONNECT_SEL, index);
3373 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003374 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003375 return 1;
3376}
3377
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003378static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003379 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3380 {
3381 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3382 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003383 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08003384 .count = 1,
3385 .info = vt1716s_dmic_info,
3386 .get = vt1716s_dmic_get,
3387 .put = vt1716s_dmic_put,
3388 },
3389 {} /* end */
3390};
3391
3392
3393/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003394static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003395 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3396 { } /* end */
3397};
3398
Takashi Iwai096a8852011-06-20 12:09:02 +02003399static const struct hda_verb vt1716S_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003400 /* Enable Boost Volume backdoor */
3401 {0x1, 0xf8a, 0x80},
3402 /* don't bybass mixer */
3403 {0x1, 0xf88, 0xc0},
3404 /* Enable mono output */
3405 {0x1, 0xf90, 0x08},
3406 { }
3407};
3408
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003409static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3410{
3411 struct via_spec *spec = codec->spec;
3412 int imux_is_smixer;
3413 unsigned int parm;
3414 unsigned int mono_out, present;
3415 /* SW0 (17h) = stereo mixer */
3416 imux_is_smixer =
3417 (snd_hda_codec_read(codec, 0x17, 0,
3418 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3419 /* inputs */
3420 /* PW 1/2/5 (1ah/1bh/1eh) */
3421 parm = AC_PWRST_D3;
3422 set_pin_power_state(codec, 0x1a, &parm);
3423 set_pin_power_state(codec, 0x1b, &parm);
3424 set_pin_power_state(codec, 0x1e, &parm);
3425 if (imux_is_smixer)
3426 parm = AC_PWRST_D0;
3427 /* SW0 (17h), AIW0(13h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003428 update_power_state(codec, 0x17, parm);
3429 update_power_state(codec, 0x13, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003430
3431 parm = AC_PWRST_D3;
3432 set_pin_power_state(codec, 0x1e, &parm);
3433 /* PW11 (22h) */
3434 if (spec->dmic_enabled)
3435 set_pin_power_state(codec, 0x22, &parm);
3436 else
Takashi Iwai054d8672012-01-24 12:25:50 +01003437 update_power_state(codec, 0x22, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003438
3439 /* SW2(26h), AIW1(14h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003440 update_power_state(codec, 0x26, parm);
3441 update_power_state(codec, 0x14, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003442
3443 /* outputs */
3444 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3445 parm = AC_PWRST_D3;
3446 set_pin_power_state(codec, 0x19, &parm);
3447 /* Smart 5.1 PW2(1bh) */
3448 if (spec->smart51_enabled)
3449 set_pin_power_state(codec, 0x1b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003450 update_power_state(codec, 0x18, parm);
3451 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003452
3453 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3454 parm = AC_PWRST_D3;
3455 set_pin_power_state(codec, 0x23, &parm);
3456 /* Smart 5.1 PW1(1ah) */
3457 if (spec->smart51_enabled)
3458 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003459 update_power_state(codec, 0x27, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003460
3461 /* Smart 5.1 PW5(1eh) */
3462 if (spec->smart51_enabled)
3463 set_pin_power_state(codec, 0x1e, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003464 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003465
3466 /* Mono out */
3467 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3468 present = snd_hda_jack_detect(codec, 0x1c);
3469
3470 if (present)
3471 mono_out = 0;
3472 else {
3473 present = snd_hda_jack_detect(codec, 0x1d);
3474 if (!spec->hp_independent_mode && present)
3475 mono_out = 0;
3476 else
3477 mono_out = 1;
3478 }
3479 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
Takashi Iwai054d8672012-01-24 12:25:50 +01003480 update_power_state(codec, 0x28, parm);
3481 update_power_state(codec, 0x29, parm);
3482 update_power_state(codec, 0x2a, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003483
3484 /* PW 3/4 (1ch/1dh) */
3485 parm = AC_PWRST_D3;
3486 set_pin_power_state(codec, 0x1c, &parm);
3487 set_pin_power_state(codec, 0x1d, &parm);
3488 /* HP Independent Mode, power on AOW3 */
3489 if (spec->hp_independent_mode)
Takashi Iwai054d8672012-01-24 12:25:50 +01003490 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003491
3492 /* force to D0 for internal Speaker */
3493 /* MW0 (16h), AOW0 (10h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003494 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
3495 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003496}
3497
Lydia Wangf3db4232009-10-10 19:08:41 +08003498static int patch_vt1716S(struct hda_codec *codec)
3499{
3500 struct via_spec *spec;
3501 int err;
3502
3503 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003504 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003505 if (spec == NULL)
3506 return -ENOMEM;
3507
Takashi Iwai620e2b22011-06-17 17:19:19 +02003508 spec->aa_mix_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003509 override_mic_boost(codec, 0x1a, 0, 3, 40);
3510 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003511
Lydia Wangf3db4232009-10-10 19:08:41 +08003512 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003513 err = via_parse_auto_config(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003514 if (err < 0) {
3515 via_free(codec);
3516 return err;
Lydia Wangf3db4232009-10-10 19:08:41 +08003517 }
3518
Takashi Iwai096a8852011-06-20 12:09:02 +02003519 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
Lydia Wangf3db4232009-10-10 19:08:41 +08003520
Lydia Wangf3db4232009-10-10 19:08:41 +08003521 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3522 spec->num_mixers++;
3523
3524 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3525
3526 codec->patch_ops = via_patch_ops;
3527
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003528 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08003529 return 0;
3530}
Lydia Wang25eaba22009-10-10 19:08:43 +08003531
3532/* for vt2002P */
3533
Takashi Iwai096a8852011-06-20 12:09:02 +02003534static const struct hda_verb vt2002P_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08003535 /* Class-D speaker related verbs */
3536 {0x1, 0xfe0, 0x4},
3537 {0x1, 0xfe9, 0x80},
3538 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08003539 /* Enable Boost Volume backdoor */
3540 {0x1, 0xfb9, 0x24},
Lydia Wang25eaba22009-10-10 19:08:43 +08003541 /* Enable AOW0 to MW9 */
3542 {0x1, 0xfb8, 0x88},
3543 { }
3544};
Takashi Iwai4a918ff2011-06-20 12:39:26 +02003545
Takashi Iwai096a8852011-06-20 12:09:02 +02003546static const struct hda_verb vt1802_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08003547 /* Enable Boost Volume backdoor */
3548 {0x1, 0xfb9, 0x24},
Lydia Wang118909562011-03-23 17:57:34 +08003549 /* Enable AOW0 to MW9 */
3550 {0x1, 0xfb8, 0x88},
3551 { }
3552};
Lydia Wang25eaba22009-10-10 19:08:43 +08003553
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003554static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3555{
3556 struct via_spec *spec = codec->spec;
3557 int imux_is_smixer;
3558 unsigned int parm;
3559 unsigned int present;
3560 /* MUX9 (1eh) = stereo mixer */
3561 imux_is_smixer =
3562 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3563 /* inputs */
3564 /* PW 5/6/7 (29h/2ah/2bh) */
3565 parm = AC_PWRST_D3;
3566 set_pin_power_state(codec, 0x29, &parm);
3567 set_pin_power_state(codec, 0x2a, &parm);
3568 set_pin_power_state(codec, 0x2b, &parm);
3569 parm = AC_PWRST_D0;
3570 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003571 update_power_state(codec, 0x1e, parm);
3572 update_power_state(codec, 0x1f, parm);
3573 update_power_state(codec, 0x10, parm);
3574 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003575
3576 /* outputs */
3577 /* AOW0 (8h)*/
Takashi Iwai054d8672012-01-24 12:25:50 +01003578 update_power_state(codec, 0x8, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003579
Lydia Wang118909562011-03-23 17:57:34 +08003580 if (spec->codec_type == VT1802) {
3581 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3582 parm = AC_PWRST_D3;
3583 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003584 update_power_state(codec, 0x18, parm);
3585 update_power_state(codec, 0x38, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003586 } else {
3587 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3588 parm = AC_PWRST_D3;
3589 set_pin_power_state(codec, 0x26, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003590 update_power_state(codec, 0x1c, parm);
3591 update_power_state(codec, 0x37, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003592 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003593
Lydia Wang118909562011-03-23 17:57:34 +08003594 if (spec->codec_type == VT1802) {
3595 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3596 parm = AC_PWRST_D3;
3597 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003598 update_power_state(codec, 0x15, parm);
3599 update_power_state(codec, 0x35, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003600 } else {
3601 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3602 parm = AC_PWRST_D3;
3603 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003604 update_power_state(codec, 0x19, parm);
3605 update_power_state(codec, 0x35, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003606 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003607
3608 if (spec->hp_independent_mode)
Takashi Iwai054d8672012-01-24 12:25:50 +01003609 update_power_state(codec, 0x9, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003610
3611 /* Class-D */
3612 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3613 present = snd_hda_jack_detect(codec, 0x25);
3614
3615 parm = AC_PWRST_D3;
3616 set_pin_power_state(codec, 0x24, &parm);
3617 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08003618 if (spec->codec_type == VT1802)
Takashi Iwai054d8672012-01-24 12:25:50 +01003619 update_power_state(codec, 0x14, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003620 else
Takashi Iwai054d8672012-01-24 12:25:50 +01003621 update_power_state(codec, 0x18, parm);
3622 update_power_state(codec, 0x34, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003623
3624 /* Mono Out */
3625 present = snd_hda_jack_detect(codec, 0x26);
3626
3627 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08003628 if (spec->codec_type == VT1802) {
3629 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003630 update_power_state(codec, 0x33, parm);
3631 update_power_state(codec, 0x1c, parm);
3632 update_power_state(codec, 0x3c, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003633 } else {
3634 /* PW15 (31h), MW8(17h), MUX8(3bh) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003635 update_power_state(codec, 0x31, parm);
3636 update_power_state(codec, 0x17, parm);
3637 update_power_state(codec, 0x3b, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003638 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003639 /* MW9 (21h) */
3640 if (imux_is_smixer || !is_aa_path_mute(codec))
Takashi Iwai054d8672012-01-24 12:25:50 +01003641 update_power_state(codec, 0x21, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003642 else
Takashi Iwai054d8672012-01-24 12:25:50 +01003643 update_power_state(codec, 0x21, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003644}
Lydia Wang25eaba22009-10-10 19:08:43 +08003645
David Henningsson4b527b62012-09-18 14:26:59 +02003646/*
3647 * pin fix-up
3648 */
3649enum {
3650 VIA_FIXUP_INTMIC_BOOST,
Takashi Iwaid5266122012-11-07 10:40:36 +01003651 VIA_FIXUP_ASUS_G75,
David Henningsson4b527b62012-09-18 14:26:59 +02003652};
3653
3654static void via_fixup_intmic_boost(struct hda_codec *codec,
3655 const struct hda_fixup *fix, int action)
3656{
3657 if (action == HDA_FIXUP_ACT_PRE_PROBE)
3658 override_mic_boost(codec, 0x30, 0, 2, 40);
3659}
3660
3661static const struct hda_fixup via_fixups[] = {
3662 [VIA_FIXUP_INTMIC_BOOST] = {
3663 .type = HDA_FIXUP_FUNC,
3664 .v.func = via_fixup_intmic_boost,
3665 },
Takashi Iwaid5266122012-11-07 10:40:36 +01003666 [VIA_FIXUP_ASUS_G75] = {
3667 .type = HDA_FIXUP_PINS,
3668 .v.pins = (const struct hda_pintbl[]) {
3669 /* set 0x24 and 0x33 as speakers */
3670 { 0x24, 0x991301f0 },
3671 { 0x33, 0x991301f1 }, /* subwoofer */
3672 { }
3673 }
3674 },
David Henningsson4b527b62012-09-18 14:26:59 +02003675};
3676
3677static const struct snd_pci_quirk vt2002p_fixups[] = {
Takashi Iwaid5266122012-11-07 10:40:36 +01003678 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
David Henningsson4b527b62012-09-18 14:26:59 +02003679 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
3680 {}
3681};
3682
Takashi Iwaief4da452012-11-07 10:37:48 +01003683/* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
3684 * Replace this with mixer NID 0x1c
3685 */
3686static void fix_vt1802_connections(struct hda_codec *codec)
3687{
3688 static hda_nid_t conn_24[] = { 0x14, 0x1c };
3689 static hda_nid_t conn_33[] = { 0x1c };
3690
3691 snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
3692 snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
3693}
3694
Lydia Wang25eaba22009-10-10 19:08:43 +08003695/* patch for vt2002P */
3696static int patch_vt2002P(struct hda_codec *codec)
3697{
3698 struct via_spec *spec;
3699 int err;
3700
3701 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003702 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08003703 if (spec == NULL)
3704 return -ENOMEM;
3705
Takashi Iwai620e2b22011-06-17 17:19:19 +02003706 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003707 override_mic_boost(codec, 0x2b, 0, 3, 40);
3708 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwaief4da452012-11-07 10:37:48 +01003709 if (spec->codec_type == VT1802)
3710 fix_vt1802_connections(codec);
Takashi Iwai30b45032011-07-11 17:05:04 +02003711 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003712
David Henningsson4b527b62012-09-18 14:26:59 +02003713 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
3714 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3715
Lydia Wang25eaba22009-10-10 19:08:43 +08003716 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003717 err = via_parse_auto_config(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08003718 if (err < 0) {
3719 via_free(codec);
3720 return err;
Lydia Wang25eaba22009-10-10 19:08:43 +08003721 }
3722
Lydia Wang118909562011-03-23 17:57:34 +08003723 if (spec->codec_type == VT1802)
Takashi Iwai4a918ff2011-06-20 12:39:26 +02003724 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08003725 else
Takashi Iwai4a918ff2011-06-20 12:39:26 +02003726 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08003727
Lydia Wang25eaba22009-10-10 19:08:43 +08003728 codec->patch_ops = via_patch_ops;
3729
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003730 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08003731 return 0;
3732}
Lydia Wangab6734e2009-10-10 19:08:46 +08003733
3734/* for vt1812 */
3735
Takashi Iwai096a8852011-06-20 12:09:02 +02003736static const struct hda_verb vt1812_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08003737 /* Enable Boost Volume backdoor */
3738 {0x1, 0xfb9, 0x24},
Lydia Wangab6734e2009-10-10 19:08:46 +08003739 /* Enable AOW0 to MW9 */
3740 {0x1, 0xfb8, 0xa8},
3741 { }
3742};
3743
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003744static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3745{
3746 struct via_spec *spec = codec->spec;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003747 unsigned int parm;
3748 unsigned int present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003749 /* inputs */
3750 /* PW 5/6/7 (29h/2ah/2bh) */
3751 parm = AC_PWRST_D3;
3752 set_pin_power_state(codec, 0x29, &parm);
3753 set_pin_power_state(codec, 0x2a, &parm);
3754 set_pin_power_state(codec, 0x2b, &parm);
3755 parm = AC_PWRST_D0;
3756 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003757 update_power_state(codec, 0x1e, parm);
3758 update_power_state(codec, 0x1f, parm);
3759 update_power_state(codec, 0x10, parm);
3760 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003761
3762 /* outputs */
3763 /* AOW0 (8h)*/
Takashi Iwai054d8672012-01-24 12:25:50 +01003764 update_power_state(codec, 0x8, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003765
3766 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3767 parm = AC_PWRST_D3;
3768 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003769 update_power_state(codec, 0x18, parm);
3770 update_power_state(codec, 0x38, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003771
3772 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3773 parm = AC_PWRST_D3;
3774 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003775 update_power_state(codec, 0x15, parm);
3776 update_power_state(codec, 0x35, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003777 if (spec->hp_independent_mode)
Takashi Iwai054d8672012-01-24 12:25:50 +01003778 update_power_state(codec, 0x9, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003779
3780 /* Internal Speaker */
3781 /* PW0 (24h), MW0(14h), MUX0(34h) */
3782 present = snd_hda_jack_detect(codec, 0x25);
3783
3784 parm = AC_PWRST_D3;
3785 set_pin_power_state(codec, 0x24, &parm);
3786 if (present) {
Takashi Iwai054d8672012-01-24 12:25:50 +01003787 update_power_state(codec, 0x14, AC_PWRST_D3);
3788 update_power_state(codec, 0x34, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003789 } else {
Takashi Iwai054d8672012-01-24 12:25:50 +01003790 update_power_state(codec, 0x14, AC_PWRST_D0);
3791 update_power_state(codec, 0x34, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003792 }
3793
3794
3795 /* Mono Out */
3796 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3797 present = snd_hda_jack_detect(codec, 0x28);
3798
3799 parm = AC_PWRST_D3;
3800 set_pin_power_state(codec, 0x31, &parm);
3801 if (present) {
Takashi Iwai054d8672012-01-24 12:25:50 +01003802 update_power_state(codec, 0x1c, AC_PWRST_D3);
3803 update_power_state(codec, 0x3c, AC_PWRST_D3);
3804 update_power_state(codec, 0x3e, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003805 } else {
Takashi Iwai054d8672012-01-24 12:25:50 +01003806 update_power_state(codec, 0x1c, AC_PWRST_D0);
3807 update_power_state(codec, 0x3c, AC_PWRST_D0);
3808 update_power_state(codec, 0x3e, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003809 }
3810
3811 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3812 parm = AC_PWRST_D3;
3813 set_pin_power_state(codec, 0x33, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003814 update_power_state(codec, 0x1d, parm);
3815 update_power_state(codec, 0x3d, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003816
3817}
Lydia Wangab6734e2009-10-10 19:08:46 +08003818
3819/* patch for vt1812 */
3820static int patch_vt1812(struct hda_codec *codec)
3821{
3822 struct via_spec *spec;
3823 int err;
3824
3825 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003826 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08003827 if (spec == NULL)
3828 return -ENOMEM;
3829
Takashi Iwai620e2b22011-06-17 17:19:19 +02003830 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003831 override_mic_boost(codec, 0x2b, 0, 3, 40);
3832 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02003833 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003834
Lydia Wangab6734e2009-10-10 19:08:46 +08003835 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003836 err = via_parse_auto_config(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08003837 if (err < 0) {
3838 via_free(codec);
3839 return err;
Lydia Wangab6734e2009-10-10 19:08:46 +08003840 }
3841
Takashi Iwai096a8852011-06-20 12:09:02 +02003842 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
Lydia Wangab6734e2009-10-10 19:08:46 +08003843
Lydia Wangab6734e2009-10-10 19:08:46 +08003844 codec->patch_ops = via_patch_ops;
3845
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003846 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08003847 return 0;
3848}
3849
Lydia Wang43737e02012-12-10 18:28:11 +08003850/* patch for vt3476 */
3851
3852static const struct hda_verb vt3476_init_verbs[] = {
3853 /* Enable DMic 8/16/32K */
3854 {0x1, 0xF7B, 0x30},
3855 /* Enable Boost Volume backdoor */
3856 {0x1, 0xFB9, 0x20},
3857 /* Enable AOW-MW9 path */
3858 {0x1, 0xFB8, 0x10},
3859 { }
3860};
3861
3862static void set_widgets_power_state_vt3476(struct hda_codec *codec)
3863{
3864 struct via_spec *spec = codec->spec;
3865 int imux_is_smixer;
3866 unsigned int parm, parm2;
3867 /* MUX10 (1eh) = stereo mixer */
3868 imux_is_smixer =
3869 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
3870 /* inputs */
3871 /* PW 5/6/7 (29h/2ah/2bh) */
3872 parm = AC_PWRST_D3;
3873 set_pin_power_state(codec, 0x29, &parm);
3874 set_pin_power_state(codec, 0x2a, &parm);
3875 set_pin_power_state(codec, 0x2b, &parm);
3876 if (imux_is_smixer)
3877 parm = AC_PWRST_D0;
3878 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3879 update_power_state(codec, 0x1e, parm);
3880 update_power_state(codec, 0x1f, parm);
3881 update_power_state(codec, 0x10, parm);
3882 update_power_state(codec, 0x11, parm);
3883
3884 /* outputs */
3885 /* PW3 (27h), MW3(37h), AOW3 (bh) */
3886 if (spec->codec_type == VT1705CF) {
3887 parm = AC_PWRST_D3;
3888 update_power_state(codec, 0x27, parm);
3889 update_power_state(codec, 0x37, parm);
3890 } else {
3891 parm = AC_PWRST_D3;
3892 set_pin_power_state(codec, 0x27, &parm);
3893 update_power_state(codec, 0x37, parm);
3894 }
3895
3896 /* PW2 (26h), MW2(36h), AOW2 (ah) */
3897 parm = AC_PWRST_D3;
3898 set_pin_power_state(codec, 0x26, &parm);
3899 update_power_state(codec, 0x36, parm);
3900 if (spec->smart51_enabled) {
3901 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
3902 set_pin_power_state(codec, 0x2b, &parm);
3903 update_power_state(codec, 0x3b, parm);
3904 update_power_state(codec, 0x1b, parm);
3905 }
3906 update_conv_power_state(codec, 0xa, parm, 2);
3907
3908 /* PW1 (25h), MW1(35h), AOW1 (9h) */
3909 parm = AC_PWRST_D3;
3910 set_pin_power_state(codec, 0x25, &parm);
3911 update_power_state(codec, 0x35, parm);
3912 if (spec->smart51_enabled) {
3913 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
3914 set_pin_power_state(codec, 0x2a, &parm);
3915 update_power_state(codec, 0x3a, parm);
3916 update_power_state(codec, 0x1a, parm);
3917 }
3918 update_conv_power_state(codec, 0x9, parm, 1);
3919
3920 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
3921 parm = AC_PWRST_D3;
3922 set_pin_power_state(codec, 0x28, &parm);
3923 update_power_state(codec, 0x38, parm);
3924 update_power_state(codec, 0x18, parm);
3925 if (spec->hp_independent_mode)
3926 update_conv_power_state(codec, 0xb, parm, 3);
3927 parm2 = parm; /* for pin 0x0b */
3928
3929 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
3930 parm = AC_PWRST_D3;
3931 set_pin_power_state(codec, 0x24, &parm);
3932 update_power_state(codec, 0x34, parm);
3933 if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3)
3934 parm = parm2;
3935 update_conv_power_state(codec, 0x8, parm, 0);
3936 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3937 update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
3938}
3939
3940static int patch_vt3476(struct hda_codec *codec)
3941{
3942 struct via_spec *spec;
3943 int err;
3944
3945 /* create a codec specific record */
3946 spec = via_new_spec(codec);
3947 if (spec == NULL)
3948 return -ENOMEM;
3949
3950 spec->aa_mix_nid = 0x3f;
3951 add_secret_dac_path(codec);
3952
3953 /* automatic parse from the BIOS config */
3954 err = via_parse_auto_config(codec);
3955 if (err < 0) {
3956 via_free(codec);
3957 return err;
3958 }
3959
3960 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
3961
3962 codec->patch_ops = via_patch_ops;
3963
3964 spec->set_widgets_power_state = set_widgets_power_state_vt3476;
3965
3966 return 0;
3967}
3968
Joseph Chanc577b8a2006-11-29 15:29:40 +01003969/*
3970 * patch entries
3971 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003972static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01003973 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3974 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3975 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3976 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3977 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003978 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003979 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003980 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003981 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003982 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003983 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003984 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003985 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003986 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003987 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003988 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003989 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003990 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003991 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003992 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003993 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003994 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003995 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003996 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003997 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003998 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003999 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02004000 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01004001 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02004002 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01004003 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02004004 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01004005 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02004006 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01004007 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02004008 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01004009 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004010 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004011 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004012 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004013 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004014 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004015 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004016 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08004017 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08004018 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004019 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004020 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004021 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004022 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004023 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08004024 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01004025 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004026 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004027 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004028 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004029 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004030 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004031 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004032 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004033 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004034 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004035 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004036 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004037 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004038 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01004039 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08004040 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08004041 { .id = 0x11060428, .name = "VT1718S",
4042 .patch = patch_vt1718S},
4043 { .id = 0x11064428, .name = "VT1718S",
4044 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004045 { .id = 0x11060441, .name = "VT2020",
4046 .patch = patch_vt1718S},
4047 { .id = 0x11064441, .name = "VT1828S",
4048 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08004049 { .id = 0x11060433, .name = "VT1716S",
4050 .patch = patch_vt1716S},
4051 { .id = 0x1106a721, .name = "VT1716S",
4052 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08004053 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
4054 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08004055 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08004056 { .id = 0x11060440, .name = "VT1818S",
4057 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08004058 { .id = 0x11060446, .name = "VT1802",
4059 .patch = patch_vt2002P},
4060 { .id = 0x11068446, .name = "VT1802",
4061 .patch = patch_vt2002P},
Lydia Wang43737e02012-12-10 18:28:11 +08004062 { .id = 0x11064760, .name = "VT1705CF",
4063 .patch = patch_vt3476},
Lydia Wang6121b842012-12-10 19:03:26 +08004064 { .id = 0x11064761, .name = "VT1708SCE",
4065 .patch = patch_vt3476},
4066 { .id = 0x11064762, .name = "VT1808",
4067 .patch = patch_vt3476},
Joseph Chanc577b8a2006-11-29 15:29:40 +01004068 {} /* terminator */
4069};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004070
4071MODULE_ALIAS("snd-hda-codec-id:1106*");
4072
4073static struct hda_codec_preset_list via_list = {
4074 .preset = snd_hda_preset_via,
4075 .owner = THIS_MODULE,
4076};
4077
4078MODULE_LICENSE("GPL");
4079MODULE_DESCRIPTION("VIA HD-audio codec");
4080
4081static int __init patch_via_init(void)
4082{
4083 return snd_hda_add_codec_preset(&via_list);
4084}
4085
4086static void __exit patch_via_exit(void)
4087{
4088 snd_hda_delete_codec_preset(&via_list);
4089}
4090
4091module_init(patch_via_init)
4092module_exit(patch_via_exit)