blob: dd8cd6af5d66829090789f7bb1c5819950a544cf [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,
Harald Welted7426322008-09-15 22:43:23 +080079 CODEC_TYPES,
80};
81
Lydia Wang118909562011-03-23 17:57:34 +080082#define VT2002P_COMPATIBLE(spec) \
83 ((spec)->codec_type == VT2002P ||\
84 (spec)->codec_type == VT1812 ||\
85 (spec)->codec_type == VT1802)
86
Takashi Iwai8e3679d2011-06-21 09:01:36 +020087#define MAX_NID_PATH_DEPTH 5
88
Takashi Iwai09a9ad692011-06-21 15:57:44 +020089/* output-path: DAC -> ... -> pin
90 * idx[] contains the source index number of the next widget;
91 * e.g. idx[0] is the index of the DAC selected by path[1] widget
92 * multi[] indicates whether it's a selector widget with multi-connectors
93 * (i.e. the connection selection is mandatory)
94 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
95 */
Takashi Iwai4a796162011-06-17 17:53:38 +020096struct nid_path {
97 int depth;
Takashi Iwai8e3679d2011-06-21 09:01:36 +020098 hda_nid_t path[MAX_NID_PATH_DEPTH];
Takashi Iwai09a9ad692011-06-21 15:57:44 +020099 unsigned char idx[MAX_NID_PATH_DEPTH];
100 unsigned char multi[MAX_NID_PATH_DEPTH];
101 unsigned int vol_ctl;
102 unsigned int mute_ctl;
Takashi Iwai4a796162011-06-17 17:53:38 +0200103};
104
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200105/* input-path */
106struct via_input {
107 hda_nid_t pin; /* input-pin or aa-mix */
108 int adc_idx; /* ADC index to be used */
109 int mux_idx; /* MUX index (if any) */
110 const char *label; /* input-source label */
111};
112
Takashi Iwaide6c74f2011-07-04 14:46:42 +0200113#define VIA_MAX_ADCS 3
114
Takashi Iwai3b607e32011-07-18 16:54:40 +0200115enum {
116 STREAM_MULTI_OUT = (1 << 0),
117 STREAM_INDEP_HP = (1 << 1),
118};
119
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800120struct via_spec {
Takashi Iwai7819d1c2012-10-10 08:41:42 +0200121 struct hda_gen_spec gen;
122
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800123 /* 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);
223
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800224 struct hda_loopback_check loopback;
Takashi Iwai13af8e72011-06-20 14:05:46 +0200225 int num_loopbacks;
226 struct hda_amp_list loopback_list[8];
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200227
228 /* bind capture-volume */
229 struct hda_bind_ctls *bind_cap_vol;
230 struct hda_bind_ctls *bind_cap_sw;
Takashi Iwai3b607e32011-07-18 16:54:40 +0200231
232 struct mutex config_mutex;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800233};
234
Lydia Wang0341ccd2011-03-22 16:25:03 +0800235static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100236static struct via_spec * via_new_spec(struct hda_codec *codec)
237{
238 struct via_spec *spec;
239
240 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
241 if (spec == NULL)
242 return NULL;
243
Takashi Iwai361dab32012-05-09 14:35:27 +0200244 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
Takashi Iwai3b607e32011-07-18 16:54:40 +0200245 mutex_init(&spec->config_mutex);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100246 codec->spec = spec;
247 spec->codec = codec;
Lydia Wang0341ccd2011-03-22 16:25:03 +0800248 spec->codec_type = get_codec_type(codec);
249 /* VT1708BCE & VT1708S are almost same */
250 if (spec->codec_type == VT1708BCE)
251 spec->codec_type = VT1708S;
Takashi Iwai7819d1c2012-10-10 08:41:42 +0200252 snd_hda_gen_init(&spec->gen);
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;
Harald Welted7426322008-09-15 22:43:23 +0800299 else
300 codec_type = UNKNOWN;
301 return codec_type;
302};
303
Lydia Wangec7e7e42011-03-24 12:43:44 +0800304#define VIA_JACK_EVENT 0x20
Harald Welte69e52a82008-09-09 15:57:32 +0800305#define VIA_HP_EVENT 0x01
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200306#define VIA_LINE_EVENT 0x03
Harald Welte69e52a82008-09-09 15:57:32 +0800307
Joseph Chanc577b8a2006-11-29 15:29:40 +0100308enum {
309 VIA_CTL_WIDGET_VOL,
310 VIA_CTL_WIDGET_MUTE,
Lydia Wangf5271102009-10-10 19:07:35 +0800311 VIA_CTL_WIDGET_ANALOG_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100312};
313
Takashi Iwaiada509e2011-06-20 15:40:19 +0200314static void analog_low_current_mode(struct hda_codec *codec);
315static bool is_aa_path_mute(struct hda_codec *codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800316
Takashi Iwai187d3332011-11-24 16:33:09 +0100317#define hp_detect_with_aa(codec) \
318 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
319 !is_aa_path_mute(codec))
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800320
321static void vt1708_stop_hp_work(struct via_spec *spec)
322{
323 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
324 return;
Takashi Iwai187d3332011-11-24 16:33:09 +0100325 if (spec->hp_work_active) {
326 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 1);
327 cancel_delayed_work_sync(&spec->vt1708_hp_work);
328 spec->hp_work_active = 0;
329 }
330}
331
332static void vt1708_update_hp_work(struct via_spec *spec)
333{
334 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800335 return;
Takashi Iwai187d3332011-11-24 16:33:09 +0100336 if (spec->vt1708_jack_detect &&
337 (spec->active_streams || hp_detect_with_aa(spec->codec))) {
338 if (!spec->hp_work_active) {
339 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 0);
340 schedule_delayed_work(&spec->vt1708_hp_work,
341 msecs_to_jiffies(100));
342 spec->hp_work_active = 1;
343 }
344 } else if (!hp_detect_with_aa(spec->codec))
345 vt1708_stop_hp_work(spec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800346}
Lydia Wangf5271102009-10-10 19:07:35 +0800347
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800348static void set_widgets_power_state(struct hda_codec *codec)
349{
350 struct via_spec *spec = codec->spec;
351 if (spec->set_widgets_power_state)
352 spec->set_widgets_power_state(codec);
353}
Lydia Wang25eaba22009-10-10 19:08:43 +0800354
Lydia Wangf5271102009-10-10 19:07:35 +0800355static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
356 struct snd_ctl_elem_value *ucontrol)
357{
358 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
359 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
360
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800361 set_widgets_power_state(codec);
Takashi Iwaiada509e2011-06-20 15:40:19 +0200362 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
Takashi Iwai187d3332011-11-24 16:33:09 +0100363 vt1708_update_hp_work(codec->spec);
Lydia Wangf5271102009-10-10 19:07:35 +0800364 return change;
365}
366
367/* modify .put = snd_hda_mixer_amp_switch_put */
368#define ANALOG_INPUT_MUTE \
369 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
370 .name = NULL, \
371 .index = 0, \
372 .info = snd_hda_mixer_amp_switch_info, \
373 .get = snd_hda_mixer_amp_switch_get, \
374 .put = analog_input_switch_put, \
375 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
376
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200377static const struct snd_kcontrol_new via_control_templates[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100378 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
379 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Lydia Wangf5271102009-10-10 19:07:35 +0800380 ANALOG_INPUT_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100381};
382
Lydia Wangab6734e2009-10-10 19:08:46 +0800383
Joseph Chanc577b8a2006-11-29 15:29:40 +0100384/* add dynamic controls */
Takashi Iwai291c9e32011-06-17 16:15:26 +0200385static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
386 const struct snd_kcontrol_new *tmpl,
387 const char *name)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100388{
389 struct snd_kcontrol_new *knew;
390
Takashi Iwai603c4012008-07-30 15:01:44 +0200391 knew = snd_array_new(&spec->kctls);
392 if (!knew)
Takashi Iwai291c9e32011-06-17 16:15:26 +0200393 return NULL;
394 *knew = *tmpl;
395 if (!name)
396 name = tmpl->name;
397 if (name) {
398 knew->name = kstrdup(name, GFP_KERNEL);
399 if (!knew->name)
400 return NULL;
401 }
402 return knew;
403}
404
405static int __via_add_control(struct via_spec *spec, int type, const char *name,
406 int idx, unsigned long val)
407{
408 struct snd_kcontrol_new *knew;
409
410 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
411 if (!knew)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100412 return -ENOMEM;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +0200413 knew->index = idx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100414 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100415 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100416 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100417 return 0;
418}
419
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200420#define via_add_control(spec, type, name, val) \
421 __via_add_control(spec, type, name, 0, val)
422
Takashi Iwai291c9e32011-06-17 16:15:26 +0200423#define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100424
Takashi Iwai603c4012008-07-30 15:01:44 +0200425static void via_free_kctls(struct hda_codec *codec)
426{
427 struct via_spec *spec = codec->spec;
428
429 if (spec->kctls.list) {
430 struct snd_kcontrol_new *kctl = spec->kctls.list;
431 int i;
432 for (i = 0; i < spec->kctls.used; i++)
433 kfree(kctl[i].name);
434 }
435 snd_array_free(&spec->kctls);
436}
437
Joseph Chanc577b8a2006-11-29 15:29:40 +0100438/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800439static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200440 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100441{
442 char name[32];
443 int err;
444
445 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200446 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100447 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
448 if (err < 0)
449 return err;
450 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200451 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100452 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
453 if (err < 0)
454 return err;
455 return 0;
456}
457
Takashi Iwai5d417622011-06-20 11:32:27 +0200458#define get_connection_index(codec, mux, nid) \
Takashi Iwai8d087c72011-06-28 12:45:47 +0200459 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai5d417622011-06-20 11:32:27 +0200460
Takashi Iwai8df2a312011-06-21 11:48:29 +0200461static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
462 unsigned int mask)
463{
Takashi Iwaia934d5a2011-06-21 14:22:14 +0200464 unsigned int caps;
465 if (!nid)
466 return false;
467 caps = get_wcaps(codec, nid);
Takashi Iwai8df2a312011-06-21 11:48:29 +0200468 if (dir == HDA_INPUT)
469 caps &= AC_WCAP_IN_AMP;
470 else
471 caps &= AC_WCAP_OUT_AMP;
472 if (!caps)
473 return false;
474 if (query_amp_caps(codec, nid, dir) & mask)
475 return true;
476 return false;
477}
478
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200479#define have_mute(codec, nid, dir) \
480 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
Takashi Iwai8df2a312011-06-21 11:48:29 +0200481
Lydia Wangd69607b32011-07-08 14:02:52 +0800482/* enable/disable the output-route mixers */
483static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai3214b962011-07-18 12:49:25 +0200484 hda_nid_t mix_nid, int idx, bool enable)
Lydia Wangd69607b32011-07-08 14:02:52 +0800485{
486 int i, num, val;
Lydia Wangd69607b32011-07-08 14:02:52 +0800487
488 if (!path)
489 return;
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200490 num = snd_hda_get_num_conns(codec, mix_nid);
Lydia Wangd69607b32011-07-08 14:02:52 +0800491 for (i = 0; i < num; i++) {
Takashi Iwai3214b962011-07-18 12:49:25 +0200492 if (i == idx)
493 val = AMP_IN_UNMUTE(i);
494 else
495 val = AMP_IN_MUTE(i);
Lydia Wangd69607b32011-07-08 14:02:52 +0800496 snd_hda_codec_write(codec, mix_nid, 0,
497 AC_VERB_SET_AMP_GAIN_MUTE, val);
498 }
499}
500
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200501/* enable/disable the output-route */
502static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
503 bool enable, bool force)
Takashi Iwai5d417622011-06-20 11:32:27 +0200504{
Lydia Wangd69607b32011-07-08 14:02:52 +0800505 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200506 int i;
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200507 for (i = 0; i < path->depth; i++) {
508 hda_nid_t src, dst;
509 int idx = path->idx[i];
510 src = path->path[i];
511 if (i < path->depth - 1)
512 dst = path->path[i + 1];
513 else
514 dst = 0;
515 if (enable && path->multi[i])
516 snd_hda_codec_write(codec, dst, 0,
517 AC_VERB_SET_CONNECT_SEL, idx);
Takashi Iwai3214b962011-07-18 12:49:25 +0200518 if (!force && (dst == spec->aa_mix_nid))
Lydia Wange5e14682011-07-01 10:55:07 +0800519 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +0200520 if (have_mute(codec, dst, HDA_INPUT))
521 activate_output_mix(codec, path, dst, idx, enable);
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200522 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
523 continue;
524 if (have_mute(codec, src, HDA_OUTPUT)) {
525 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
526 snd_hda_codec_write(codec, src, 0,
527 AC_VERB_SET_AMP_GAIN_MUTE, val);
528 }
529 }
Takashi Iwai5d417622011-06-20 11:32:27 +0200530}
531
532/* set the given pin as output */
533static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
534 int pin_type)
535{
536 if (!pin)
537 return;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200538 snd_hda_set_pin_ctl(codec, pin, pin_type);
Takashi Iwai5d417622011-06-20 11:32:27 +0200539 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
540 snd_hda_codec_write(codec, pin, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200541 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100542}
543
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200544static void via_auto_init_output(struct hda_codec *codec,
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200545 struct nid_path *path, int pin_type)
Takashi Iwai5d417622011-06-20 11:32:27 +0200546{
Takashi Iwai5d417622011-06-20 11:32:27 +0200547 unsigned int caps;
Lydia Wangd69607b32011-07-08 14:02:52 +0800548 hda_nid_t pin;
Takashi Iwai5d417622011-06-20 11:32:27 +0200549
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200550 if (!path->depth)
Takashi Iwai5d417622011-06-20 11:32:27 +0200551 return;
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200552 pin = path->path[path->depth - 1];
Takashi Iwai5d417622011-06-20 11:32:27 +0200553
554 init_output_pin(codec, pin, pin_type);
Takashi Iwai77e314f2012-02-22 12:34:08 +0100555 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
556 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
557 else
558 caps = 0;
Takashi Iwai5d417622011-06-20 11:32:27 +0200559 if (caps & AC_AMPCAP_MUTE) {
560 unsigned int val;
561 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
562 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
563 AMP_OUT_MUTE | val);
564 }
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200565 activate_output_path(codec, path, true, true); /* force on */
Takashi Iwai5d417622011-06-20 11:32:27 +0200566}
567
Joseph Chanc577b8a2006-11-29 15:29:40 +0100568static void via_auto_init_multi_out(struct hda_codec *codec)
569{
570 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200571 struct nid_path *path;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100572 int i;
573
Takashi Iwai3214b962011-07-18 12:49:25 +0200574 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
575 path = &spec->out_path[i];
576 if (!i && spec->aamix_mode && spec->out_mix_path.depth)
577 path = &spec->out_mix_path;
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200578 via_auto_init_output(codec, path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200579 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100580}
581
Takashi Iwai020066d2011-07-21 13:45:56 +0200582/* deactivate the inactive headphone-paths */
583static void deactivate_hp_paths(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100584{
585 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200586 int shared = spec->hp_indep_shared;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100587
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200588 if (spec->hp_independent_mode) {
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200589 activate_output_path(codec, &spec->hp_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200590 activate_output_path(codec, &spec->hp_mix_path, false, false);
591 if (shared)
592 activate_output_path(codec, &spec->out_path[shared],
593 false, false);
Takashi Iwai020066d2011-07-21 13:45:56 +0200594 } else if (spec->aamix_mode || !spec->hp_path.depth) {
595 activate_output_path(codec, &spec->hp_indep_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200596 activate_output_path(codec, &spec->hp_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200597 } else {
Takashi Iwai020066d2011-07-21 13:45:56 +0200598 activate_output_path(codec, &spec->hp_indep_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200599 activate_output_path(codec, &spec->hp_mix_path, false, false);
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200600 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100601}
602
Takashi Iwai020066d2011-07-21 13:45:56 +0200603static void via_auto_init_hp_out(struct hda_codec *codec)
604{
605 struct via_spec *spec = codec->spec;
606
607 if (!spec->hp_path.depth) {
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200608 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200609 return;
610 }
611 deactivate_hp_paths(codec);
612 if (spec->hp_independent_mode)
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200613 via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200614 else if (spec->aamix_mode)
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200615 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200616 else
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200617 via_auto_init_output(codec, &spec->hp_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200618}
619
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200620static void via_auto_init_speaker_out(struct hda_codec *codec)
621{
622 struct via_spec *spec = codec->spec;
623
Takashi Iwai3214b962011-07-18 12:49:25 +0200624 if (!spec->autocfg.speaker_outs)
625 return;
626 if (!spec->speaker_path.depth) {
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200627 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200628 return;
629 }
630 if (!spec->aamix_mode) {
631 activate_output_path(codec, &spec->speaker_mix_path,
632 false, false);
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200633 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200634 } else {
635 activate_output_path(codec, &spec->speaker_path, false, false);
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200636 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200637 }
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200638}
639
Takashi Iwaif4a78282011-06-17 18:46:48 +0200640static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
Takashi Iwai6e969d92011-07-11 11:28:13 +0200641static void via_hp_automute(struct hda_codec *codec);
Clemens Ladisch32e01912010-07-12 16:28:50 +0200642
Joseph Chanc577b8a2006-11-29 15:29:40 +0100643static void via_auto_init_analog_input(struct hda_codec *codec)
644{
645 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200646 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai096a8852011-06-20 12:09:02 +0200647 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Clemens Ladisch32e01912010-07-12 16:28:50 +0200648 unsigned int ctl;
Takashi Iwai096a8852011-06-20 12:09:02 +0200649 int i, num_conns;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100650
Takashi Iwai096a8852011-06-20 12:09:02 +0200651 /* init ADCs */
652 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai77e314f2012-02-22 12:34:08 +0100653 hda_nid_t nid = spec->adc_nids[i];
654 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP) ||
655 !(query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE))
656 continue;
Takashi Iwai096a8852011-06-20 12:09:02 +0200657 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
658 AC_VERB_SET_AMP_GAIN_MUTE,
659 AMP_IN_UNMUTE(0));
660 }
661
662 /* init pins */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200663 for (i = 0; i < cfg->num_inputs; i++) {
664 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200665 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
Clemens Ladisch32e01912010-07-12 16:28:50 +0200666 ctl = PIN_OUT;
Takashi Iwai47408602012-04-20 13:06:53 +0200667 else {
Clemens Ladisch32e01912010-07-12 16:28:50 +0200668 ctl = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200669 if (cfg->inputs[i].type == AUTO_PIN_MIC)
670 ctl |= snd_hda_get_default_vref(codec, nid);
671 }
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200672 snd_hda_set_pin_ctl(codec, nid, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100673 }
Takashi Iwai096a8852011-06-20 12:09:02 +0200674
675 /* init input-src */
676 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200677 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
Takashi Iwaifc1156c2012-02-13 15:04:06 +0100678 /* secondary ADCs must have the unique MUX */
679 if (i > 0 && !spec->mux_nids[i])
680 break;
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200681 if (spec->mux_nids[adc_idx]) {
682 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
683 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
684 AC_VERB_SET_CONNECT_SEL,
685 mux_idx);
686 }
687 if (spec->dyn_adc_switch)
688 break; /* only one input-src */
Takashi Iwai096a8852011-06-20 12:09:02 +0200689 }
690
691 /* init aa-mixer */
692 if (!spec->aa_mix_nid)
693 return;
694 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
695 ARRAY_SIZE(conn));
696 for (i = 0; i < num_conns; i++) {
697 unsigned int caps = get_wcaps(codec, conn[i]);
698 if (get_wcaps_type(caps) == AC_WID_PIN)
699 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
700 AC_VERB_SET_AMP_GAIN_MUTE,
701 AMP_IN_MUTE(i));
702 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100703}
Lydia Wangf5271102009-10-10 19:07:35 +0800704
Takashi Iwai054d8672012-01-24 12:25:50 +0100705static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
706 unsigned int parm)
707{
708 if (snd_hda_codec_read(codec, nid, 0,
709 AC_VERB_GET_POWER_STATE, 0) == parm)
710 return;
711 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
712}
713
Lydia Wangf5271102009-10-10 19:07:35 +0800714static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
715 unsigned int *affected_parm)
716{
717 unsigned parm;
718 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
719 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
720 >> AC_DEFCFG_MISC_SHIFT
721 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800722 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200723 unsigned present = 0;
724
725 no_presence |= spec->no_pin_power_ctl;
726 if (!no_presence)
727 present = snd_hda_jack_detect(codec, nid);
Takashi Iwaif4a78282011-06-17 18:46:48 +0200728 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
Lydia Wang1564b282009-10-10 19:07:52 +0800729 || ((no_presence || present)
730 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800731 *affected_parm = AC_PWRST_D0; /* if it's connected */
732 parm = AC_PWRST_D0;
733 } else
734 parm = AC_PWRST_D3;
735
Takashi Iwai054d8672012-01-24 12:25:50 +0100736 update_power_state(codec, nid, parm);
Lydia Wangf5271102009-10-10 19:07:35 +0800737}
738
Takashi Iwai24088a52011-06-17 16:59:21 +0200739static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
740 struct snd_ctl_elem_info *uinfo)
741{
Takashi Iwaidda415d2012-11-30 18:34:38 +0100742 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai24088a52011-06-17 16:59:21 +0200743}
744
745static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
746 struct snd_ctl_elem_value *ucontrol)
747{
748 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
749 struct via_spec *spec = codec->spec;
750 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
751 return 0;
752}
753
754static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
755 struct snd_ctl_elem_value *ucontrol)
756{
757 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
758 struct via_spec *spec = codec->spec;
759 unsigned int val = !ucontrol->value.enumerated.item[0];
760
761 if (val == spec->no_pin_power_ctl)
762 return 0;
763 spec->no_pin_power_ctl = val;
764 set_widgets_power_state(codec);
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100765 analog_low_current_mode(codec);
Takashi Iwai24088a52011-06-17 16:59:21 +0200766 return 1;
767}
768
769static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
770 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
771 .name = "Dynamic Power-Control",
772 .info = via_pin_power_ctl_info,
773 .get = via_pin_power_ctl_get,
774 .put = via_pin_power_ctl_put,
775};
776
777
Harald Welte0aa62ae2008-09-09 15:58:27 +0800778static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
779 struct snd_ctl_elem_info *uinfo)
780{
Takashi Iwai8df2a312011-06-21 11:48:29 +0200781 static const char * const texts[] = { "OFF", "ON" };
782
783 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
784 uinfo->count = 1;
785 uinfo->value.enumerated.items = 2;
786 if (uinfo->value.enumerated.item >= 2)
787 uinfo->value.enumerated.item = 1;
788 strcpy(uinfo->value.enumerated.name,
789 texts[uinfo->value.enumerated.item]);
790 return 0;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800791}
792
793static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
794 struct snd_ctl_elem_value *ucontrol)
795{
796 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Lydia Wangcdc17842009-10-10 19:07:47 +0800797 struct via_spec *spec = codec->spec;
Lydia Wangcdc17842009-10-10 19:07:47 +0800798
Takashi Iwaiece8d042011-06-19 16:24:21 +0200799 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
Lydia Wangcdc17842009-10-10 19:07:47 +0800800 return 0;
801}
802
Takashi Iwai3b607e32011-07-18 16:54:40 +0200803/* adjust spec->multiout setup according to the current flags */
804static void setup_playback_multi_pcm(struct via_spec *spec)
805{
806 const struct auto_pin_cfg *cfg = &spec->autocfg;
807 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
808 spec->multiout.hp_nid = 0;
809 if (!spec->hp_independent_mode) {
810 if (!spec->hp_indep_shared)
811 spec->multiout.hp_nid = spec->hp_dac_nid;
812 } else {
813 if (spec->hp_indep_shared)
814 spec->multiout.num_dacs = cfg->line_outs - 1;
815 }
816}
817
818/* update DAC setups according to indep-HP switch;
819 * this function is called only when indep-HP is modified
820 */
821static void switch_indep_hp_dacs(struct hda_codec *codec)
822{
823 struct via_spec *spec = codec->spec;
824 int shared = spec->hp_indep_shared;
825 hda_nid_t shared_dac, hp_dac;
826
827 if (!spec->opened_streams)
828 return;
829
830 shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
831 hp_dac = spec->hp_dac_nid;
832 if (spec->hp_independent_mode) {
833 /* switch to indep-HP mode */
834 if (spec->active_streams & STREAM_MULTI_OUT) {
835 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
836 __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
837 }
838 if (spec->active_streams & STREAM_INDEP_HP)
839 snd_hda_codec_setup_stream(codec, hp_dac,
840 spec->cur_hp_stream_tag, 0,
841 spec->cur_hp_format);
842 } else {
843 /* back to HP or shared-DAC */
844 if (spec->active_streams & STREAM_INDEP_HP)
845 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
846 if (spec->active_streams & STREAM_MULTI_OUT) {
847 hda_nid_t dac;
848 int ch;
849 if (shared_dac) { /* reset mutli-ch DAC */
850 dac = shared_dac;
851 ch = shared * 2;
852 } else { /* reset HP DAC */
853 dac = hp_dac;
854 ch = 0;
855 }
856 snd_hda_codec_setup_stream(codec, dac,
857 spec->cur_dac_stream_tag, ch,
858 spec->cur_dac_format);
859 }
860 }
861 setup_playback_multi_pcm(spec);
862}
863
Harald Welte0aa62ae2008-09-09 15:58:27 +0800864static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
865 struct snd_ctl_elem_value *ucontrol)
866{
867 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
868 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200869 int cur, shared;
Takashi Iwai8df2a312011-06-21 11:48:29 +0200870
Takashi Iwai3b607e32011-07-18 16:54:40 +0200871 mutex_lock(&spec->config_mutex);
Takashi Iwai25250502011-06-30 17:24:47 +0200872 cur = !!ucontrol->value.enumerated.item[0];
Takashi Iwai3b607e32011-07-18 16:54:40 +0200873 if (spec->hp_independent_mode == cur) {
874 mutex_unlock(&spec->config_mutex);
Takashi Iwai25250502011-06-30 17:24:47 +0200875 return 0;
Takashi Iwai3b607e32011-07-18 16:54:40 +0200876 }
Takashi Iwai25250502011-06-30 17:24:47 +0200877 spec->hp_independent_mode = cur;
Takashi Iwai3214b962011-07-18 12:49:25 +0200878 shared = spec->hp_indep_shared;
Takashi Iwai020066d2011-07-21 13:45:56 +0200879 deactivate_hp_paths(codec);
880 if (cur)
881 activate_output_path(codec, &spec->hp_indep_path, true, false);
882 else {
Takashi Iwai3214b962011-07-18 12:49:25 +0200883 if (shared)
884 activate_output_path(codec, &spec->out_path[shared],
Takashi Iwai25250502011-06-30 17:24:47 +0200885 true, false);
Takashi Iwai020066d2011-07-21 13:45:56 +0200886 if (spec->aamix_mode || !spec->hp_path.depth)
887 activate_output_path(codec, &spec->hp_mix_path,
888 true, false);
889 else
890 activate_output_path(codec, &spec->hp_path,
891 true, false);
Takashi Iwai8df2a312011-06-21 11:48:29 +0200892 }
Harald Welte0aa62ae2008-09-09 15:58:27 +0800893
Takashi Iwai3b607e32011-07-18 16:54:40 +0200894 switch_indep_hp_dacs(codec);
895 mutex_unlock(&spec->config_mutex);
896
Lydia Wangce0e5a92011-03-22 16:22:37 +0800897 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800898 set_widgets_power_state(codec);
Takashi Iwai6e969d92011-07-11 11:28:13 +0200899 via_hp_automute(codec);
Takashi Iwai25250502011-06-30 17:24:47 +0200900 return 1;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800901}
902
Takashi Iwaiece8d042011-06-19 16:24:21 +0200903static const struct snd_kcontrol_new via_hp_mixer = {
904 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
905 .name = "Independent HP",
906 .info = via_independent_hp_info,
907 .get = via_independent_hp_get,
908 .put = via_independent_hp_put,
Harald Welte0aa62ae2008-09-09 15:58:27 +0800909};
910
Takashi Iwai3d83e572010-04-14 14:36:23 +0200911static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100912{
Takashi Iwai3d83e572010-04-14 14:36:23 +0200913 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100914 struct snd_kcontrol_new *knew;
915 hda_nid_t nid;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100916
Takashi Iwaiece8d042011-06-19 16:24:21 +0200917 nid = spec->autocfg.hp_pins[0];
918 knew = via_clone_control(spec, &via_hp_mixer);
Takashi Iwai3d83e572010-04-14 14:36:23 +0200919 if (knew == NULL)
920 return -ENOMEM;
921
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100922 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100923
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100924 return 0;
925}
926
Lydia Wang1564b282009-10-10 19:07:52 +0800927static void notify_aa_path_ctls(struct hda_codec *codec)
928{
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200929 struct via_spec *spec = codec->spec;
Lydia Wang1564b282009-10-10 19:07:52 +0800930 int i;
Lydia Wang1564b282009-10-10 19:07:52 +0800931
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200932 for (i = 0; i < spec->smart51_nums; i++) {
933 struct snd_kcontrol *ctl;
934 struct snd_ctl_elem_id id;
935 memset(&id, 0, sizeof(id));
936 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
937 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
Lydia Wang525566c2011-04-28 16:03:39 +0800938 ctl = snd_hda_find_mixer_ctl(codec, id.name);
939 if (ctl)
940 snd_ctl_notify(codec->bus->card,
941 SNDRV_CTL_EVENT_MASK_VALUE,
942 &ctl->id);
Lydia Wang1564b282009-10-10 19:07:52 +0800943 }
944}
945
946static void mute_aa_path(struct hda_codec *codec, int mute)
947{
948 struct via_spec *spec = codec->spec;
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200949 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
Lydia Wang1564b282009-10-10 19:07:52 +0800950 int i;
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200951
Lydia Wang1564b282009-10-10 19:07:52 +0800952 /* check AA path's mute status */
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200953 for (i = 0; i < spec->smart51_nums; i++) {
954 if (spec->smart51_idxs[i] < 0)
955 continue;
956 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
957 HDA_INPUT, spec->smart51_idxs[i],
Lydia Wang1564b282009-10-10 19:07:52 +0800958 HDA_AMP_MUTE, val);
959 }
960}
Takashi Iwaif4a78282011-06-17 18:46:48 +0200961
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200962static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
963{
964 struct via_spec *spec = codec->spec;
965 int i;
966
967 for (i = 0; i < spec->smart51_nums; i++)
968 if (spec->smart51_pins[i] == pin)
969 return true;
970 return false;
971}
972
Lydia Wang1564b282009-10-10 19:07:52 +0800973static int via_smart51_get(struct snd_kcontrol *kcontrol,
974 struct snd_ctl_elem_value *ucontrol)
975{
976 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
977 struct via_spec *spec = codec->spec;
Lydia Wang1564b282009-10-10 19:07:52 +0800978
Takashi Iwaif2b1c9f2011-06-21 16:52:39 +0200979 *ucontrol->value.integer.value = spec->smart51_enabled;
Lydia Wang1564b282009-10-10 19:07:52 +0800980 return 0;
981}
982
983static int via_smart51_put(struct snd_kcontrol *kcontrol,
984 struct snd_ctl_elem_value *ucontrol)
985{
986 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
987 struct via_spec *spec = codec->spec;
988 int out_in = *ucontrol->value.integer.value
989 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +0800990 int i;
991
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200992 for (i = 0; i < spec->smart51_nums; i++) {
993 hda_nid_t nid = spec->smart51_pins[i];
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200994 unsigned int parm;
995
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200996 parm = snd_hda_codec_read(codec, nid, 0,
997 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
998 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
999 parm |= out_in;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001000 snd_hda_set_pin_ctl(codec, nid, parm);
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001001 if (out_in == AC_PINCTL_OUT_EN) {
1002 mute_aa_path(codec, 1);
1003 notify_aa_path_ctls(codec);
1004 }
Lydia Wang1564b282009-10-10 19:07:52 +08001005 }
1006 spec->smart51_enabled = *ucontrol->value.integer.value;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001007 set_widgets_power_state(codec);
Lydia Wang1564b282009-10-10 19:07:52 +08001008 return 1;
1009}
1010
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001011static const struct snd_kcontrol_new via_smart51_mixer = {
1012 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1013 .name = "Smart 5.1",
1014 .count = 1,
Takashi Iwaif2b1c9f2011-06-21 16:52:39 +02001015 .info = snd_ctl_boolean_mono_info,
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001016 .get = via_smart51_get,
1017 .put = via_smart51_put,
Lydia Wang1564b282009-10-10 19:07:52 +08001018};
1019
Takashi Iwaif4a78282011-06-17 18:46:48 +02001020static int via_smart51_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001021{
Takashi Iwaif4a78282011-06-17 18:46:48 +02001022 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001023
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001024 if (!spec->smart51_nums)
Lydia Wangcb34c202011-04-27 17:44:16 +08001025 return 0;
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001026 if (!via_clone_control(spec, &via_smart51_mixer))
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001027 return -ENOMEM;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001028 return 0;
1029}
1030
Takashi Iwaiada509e2011-06-20 15:40:19 +02001031/* check AA path's mute status */
1032static bool is_aa_path_mute(struct hda_codec *codec)
Lydia Wangf5271102009-10-10 19:07:35 +08001033{
Lydia Wangf5271102009-10-10 19:07:35 +08001034 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001035 const struct hda_amp_list *p;
1036 int i, ch, v;
1037
1038 for (i = 0; i < spec->num_loopbacks; i++) {
1039 p = &spec->loopback_list[i];
1040 for (ch = 0; ch < 2; ch++) {
1041 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
1042 p->idx);
1043 if (!(v & HDA_AMP_MUTE) && v > 0)
1044 return false;
Lydia Wangf5271102009-10-10 19:07:35 +08001045 }
1046 }
Takashi Iwaiada509e2011-06-20 15:40:19 +02001047 return true;
Lydia Wangf5271102009-10-10 19:07:35 +08001048}
1049
1050/* enter/exit analog low-current mode */
Takashi Iwaie9d010c2012-02-01 10:33:23 +01001051static void __analog_low_current_mode(struct hda_codec *codec, bool force)
Lydia Wangf5271102009-10-10 19:07:35 +08001052{
1053 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001054 bool enable;
1055 unsigned int verb, parm;
Lydia Wangf5271102009-10-10 19:07:35 +08001056
Takashi Iwaie9d010c2012-02-01 10:33:23 +01001057 if (spec->no_pin_power_ctl)
1058 enable = false;
1059 else
1060 enable = is_aa_path_mute(codec) && !spec->opened_streams;
1061 if (enable == spec->alc_mode && !force)
1062 return;
1063 spec->alc_mode = enable;
Lydia Wangf5271102009-10-10 19:07:35 +08001064
1065 /* decide low current mode's verb & parameter */
1066 switch (spec->codec_type) {
1067 case VT1708B_8CH:
1068 case VT1708B_4CH:
1069 verb = 0xf70;
1070 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1071 break;
1072 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001073 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001074 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001075 verb = 0xf73;
1076 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1077 break;
1078 case VT1702:
1079 verb = 0xf73;
1080 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1081 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001082 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001083 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001084 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001085 verb = 0xf93;
1086 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1087 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001088 default:
1089 return; /* other codecs are not supported */
1090 }
1091 /* send verb */
1092 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1093}
1094
Takashi Iwaie9d010c2012-02-01 10:33:23 +01001095static void analog_low_current_mode(struct hda_codec *codec)
1096{
1097 return __analog_low_current_mode(codec, false);
1098}
1099
Joseph Chanc577b8a2006-11-29 15:29:40 +01001100/*
1101 * generic initialization of ADC, input mixers and output mixers
1102 */
Takashi Iwai096a8852011-06-20 12:09:02 +02001103static const struct hda_verb vt1708_init_verbs[] = {
Lydia Wangaa266fc2011-03-24 12:41:01 +08001104 /* power down jack detect function */
1105 {0x1, 0xf81, 0x1},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001106 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001107};
1108
Takashi Iwai3b607e32011-07-18 16:54:40 +02001109static void set_stream_open(struct hda_codec *codec, int bit, bool active)
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001110{
Takashi Iwaiada509e2011-06-20 15:40:19 +02001111 struct via_spec *spec = codec->spec;
1112
1113 if (active)
Takashi Iwai3b607e32011-07-18 16:54:40 +02001114 spec->opened_streams |= bit;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001115 else
Takashi Iwai3b607e32011-07-18 16:54:40 +02001116 spec->opened_streams &= ~bit;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001117 analog_low_current_mode(codec);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001118}
1119
Takashi Iwaiece8d042011-06-19 16:24:21 +02001120static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001121 struct hda_codec *codec,
1122 struct snd_pcm_substream *substream)
1123{
1124 struct via_spec *spec = codec->spec;
Takashi Iwai25250502011-06-30 17:24:47 +02001125 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001126 int err;
Takashi Iwaiece8d042011-06-19 16:24:21 +02001127
Takashi Iwai25250502011-06-30 17:24:47 +02001128 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
Takashi Iwai25250502011-06-30 17:24:47 +02001129 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai3b607e32011-07-18 16:54:40 +02001130 set_stream_open(codec, STREAM_MULTI_OUT, true);
Takashi Iwaiada509e2011-06-20 15:40:19 +02001131 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1132 hinfo);
1133 if (err < 0) {
Takashi Iwai3b607e32011-07-18 16:54:40 +02001134 set_stream_open(codec, STREAM_MULTI_OUT, false);
Takashi Iwaiada509e2011-06-20 15:40:19 +02001135 return err;
1136 }
1137 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001138}
1139
Takashi Iwaiece8d042011-06-19 16:24:21 +02001140static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
Takashi Iwai9af74212011-06-18 16:17:45 +02001141 struct hda_codec *codec,
1142 struct snd_pcm_substream *substream)
1143{
Takashi Iwai3b607e32011-07-18 16:54:40 +02001144 set_stream_open(codec, STREAM_MULTI_OUT, false);
Takashi Iwai9af74212011-06-18 16:17:45 +02001145 return 0;
1146}
1147
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001148static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1149 struct hda_codec *codec,
1150 struct snd_pcm_substream *substream)
1151{
1152 struct via_spec *spec = codec->spec;
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001153
Takashi Iwaiece8d042011-06-19 16:24:21 +02001154 if (snd_BUG_ON(!spec->hp_dac_nid))
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001155 return -EINVAL;
Takashi Iwai3b607e32011-07-18 16:54:40 +02001156 set_stream_open(codec, STREAM_INDEP_HP, true);
Takashi Iwaiece8d042011-06-19 16:24:21 +02001157 return 0;
1158}
1159
1160static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1161 struct hda_codec *codec,
1162 struct snd_pcm_substream *substream)
1163{
Takashi Iwai3b607e32011-07-18 16:54:40 +02001164 set_stream_open(codec, STREAM_INDEP_HP, false);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001165 return 0;
1166}
1167
1168static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1169 struct hda_codec *codec,
1170 unsigned int stream_tag,
1171 unsigned int format,
1172 struct snd_pcm_substream *substream)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001173{
1174 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001175
Takashi Iwai3b607e32011-07-18 16:54:40 +02001176 mutex_lock(&spec->config_mutex);
1177 setup_playback_multi_pcm(spec);
Takashi Iwaiece8d042011-06-19 16:24:21 +02001178 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1179 format, substream);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001180 /* remember for dynamic DAC switch with indep-HP */
1181 spec->active_streams |= STREAM_MULTI_OUT;
1182 spec->cur_dac_stream_tag = stream_tag;
1183 spec->cur_dac_format = format;
1184 mutex_unlock(&spec->config_mutex);
Takashi Iwai187d3332011-11-24 16:33:09 +01001185 vt1708_update_hp_work(spec);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001186 return 0;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001187}
1188
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001189static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1190 struct hda_codec *codec,
1191 unsigned int stream_tag,
1192 unsigned int format,
1193 struct snd_pcm_substream *substream)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001194{
1195 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001196
Takashi Iwai3b607e32011-07-18 16:54:40 +02001197 mutex_lock(&spec->config_mutex);
1198 if (spec->hp_independent_mode)
1199 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1200 stream_tag, 0, format);
1201 spec->active_streams |= STREAM_INDEP_HP;
1202 spec->cur_hp_stream_tag = stream_tag;
1203 spec->cur_hp_format = format;
1204 mutex_unlock(&spec->config_mutex);
Takashi Iwai187d3332011-11-24 16:33:09 +01001205 vt1708_update_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001206 return 0;
1207}
1208
1209static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1210 struct hda_codec *codec,
1211 struct snd_pcm_substream *substream)
1212{
1213 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001214
Takashi Iwai3b607e32011-07-18 16:54:40 +02001215 mutex_lock(&spec->config_mutex);
Takashi Iwaiece8d042011-06-19 16:24:21 +02001216 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001217 spec->active_streams &= ~STREAM_MULTI_OUT;
1218 mutex_unlock(&spec->config_mutex);
Takashi Iwai187d3332011-11-24 16:33:09 +01001219 vt1708_update_hp_work(spec);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001220 return 0;
1221}
1222
1223static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1224 struct hda_codec *codec,
1225 struct snd_pcm_substream *substream)
1226{
1227 struct via_spec *spec = codec->spec;
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001228
Takashi Iwai3b607e32011-07-18 16:54:40 +02001229 mutex_lock(&spec->config_mutex);
1230 if (spec->hp_independent_mode)
1231 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1232 spec->active_streams &= ~STREAM_INDEP_HP;
1233 mutex_unlock(&spec->config_mutex);
Takashi Iwai187d3332011-11-24 16:33:09 +01001234 vt1708_update_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001235 return 0;
1236}
1237
Joseph Chanc577b8a2006-11-29 15:29:40 +01001238/*
1239 * Digital out
1240 */
1241static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1242 struct hda_codec *codec,
1243 struct snd_pcm_substream *substream)
1244{
1245 struct via_spec *spec = codec->spec;
1246 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1247}
1248
1249static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1250 struct hda_codec *codec,
1251 struct snd_pcm_substream *substream)
1252{
1253 struct via_spec *spec = codec->spec;
1254 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1255}
1256
Harald Welte5691ec72008-09-15 22:42:26 +08001257static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001258 struct hda_codec *codec,
1259 unsigned int stream_tag,
1260 unsigned int format,
1261 struct snd_pcm_substream *substream)
1262{
1263 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001264 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1265 stream_tag, format, substream);
1266}
Harald Welte5691ec72008-09-15 22:42:26 +08001267
Takashi Iwai9da29272009-05-07 16:31:14 +02001268static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1269 struct hda_codec *codec,
1270 struct snd_pcm_substream *substream)
1271{
1272 struct via_spec *spec = codec->spec;
1273 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001274 return 0;
1275}
1276
Joseph Chanc577b8a2006-11-29 15:29:40 +01001277/*
1278 * Analog capture
1279 */
1280static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1281 struct hda_codec *codec,
1282 unsigned int stream_tag,
1283 unsigned int format,
1284 struct snd_pcm_substream *substream)
1285{
1286 struct via_spec *spec = codec->spec;
1287
1288 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1289 stream_tag, 0, format);
1290 return 0;
1291}
1292
1293static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1294 struct hda_codec *codec,
1295 struct snd_pcm_substream *substream)
1296{
1297 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001298 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001299 return 0;
1300}
1301
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001302/* analog capture with dynamic ADC switching */
1303static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1304 struct hda_codec *codec,
1305 unsigned int stream_tag,
1306 unsigned int format,
1307 struct snd_pcm_substream *substream)
1308{
1309 struct via_spec *spec = codec->spec;
1310 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1311
Takashi Iwai3b607e32011-07-18 16:54:40 +02001312 mutex_lock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001313 spec->cur_adc = spec->adc_nids[adc_idx];
1314 spec->cur_adc_stream_tag = stream_tag;
1315 spec->cur_adc_format = format;
1316 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001317 mutex_unlock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001318 return 0;
1319}
1320
1321static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1322 struct hda_codec *codec,
1323 struct snd_pcm_substream *substream)
1324{
1325 struct via_spec *spec = codec->spec;
1326
Takashi Iwai3b607e32011-07-18 16:54:40 +02001327 mutex_lock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001328 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1329 spec->cur_adc = 0;
Takashi Iwai3b607e32011-07-18 16:54:40 +02001330 mutex_unlock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001331 return 0;
1332}
1333
1334/* re-setup the stream if running; called from input-src put */
1335static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1336{
1337 struct via_spec *spec = codec->spec;
1338 int adc_idx = spec->inputs[cur].adc_idx;
1339 hda_nid_t adc = spec->adc_nids[adc_idx];
Takashi Iwai3b607e32011-07-18 16:54:40 +02001340 bool ret = false;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001341
Takashi Iwai3b607e32011-07-18 16:54:40 +02001342 mutex_lock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001343 if (spec->cur_adc && spec->cur_adc != adc) {
1344 /* stream is running, let's swap the current ADC */
1345 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1346 spec->cur_adc = adc;
1347 snd_hda_codec_setup_stream(codec, adc,
1348 spec->cur_adc_stream_tag, 0,
1349 spec->cur_adc_format);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001350 ret = true;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001351 }
Takashi Iwai3b607e32011-07-18 16:54:40 +02001352 mutex_unlock(&spec->config_mutex);
1353 return ret;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001354}
1355
Takashi Iwai9af74212011-06-18 16:17:45 +02001356static const struct hda_pcm_stream via_pcm_analog_playback = {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001357 .substreams = 1,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001358 .channels_min = 2,
1359 .channels_max = 8,
Takashi Iwai9af74212011-06-18 16:17:45 +02001360 /* NID is set in via_build_pcms */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001361 .ops = {
Takashi Iwaiece8d042011-06-19 16:24:21 +02001362 .open = via_playback_multi_pcm_open,
1363 .close = via_playback_multi_pcm_close,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001364 .prepare = via_playback_multi_pcm_prepare,
1365 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001366 },
1367};
1368
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001369static const struct hda_pcm_stream via_pcm_hp_playback = {
1370 .substreams = 1,
1371 .channels_min = 2,
1372 .channels_max = 2,
1373 /* NID is set in via_build_pcms */
1374 .ops = {
1375 .open = via_playback_hp_pcm_open,
Takashi Iwaiece8d042011-06-19 16:24:21 +02001376 .close = via_playback_hp_pcm_close,
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001377 .prepare = via_playback_hp_pcm_prepare,
1378 .cleanup = via_playback_hp_pcm_cleanup
1379 },
1380};
1381
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001382static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001383 .substreams = 1,
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001384 .channels_min = 2,
1385 .channels_max = 8,
Takashi Iwai9af74212011-06-18 16:17:45 +02001386 /* NID is set in via_build_pcms */
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001387 /* We got noisy outputs on the right channel on VT1708 when
1388 * 24bit samples are used. Until any workaround is found,
1389 * disable the 24bit format, so far.
1390 */
1391 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1392 .ops = {
Takashi Iwaiece8d042011-06-19 16:24:21 +02001393 .open = via_playback_multi_pcm_open,
1394 .close = via_playback_multi_pcm_close,
Lydia Wangc873cc22009-10-10 19:08:21 +08001395 .prepare = via_playback_multi_pcm_prepare,
1396 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001397 },
1398};
1399
Takashi Iwai9af74212011-06-18 16:17:45 +02001400static const struct hda_pcm_stream via_pcm_analog_capture = {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001401 .substreams = 1, /* will be changed in via_build_pcms() */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001402 .channels_min = 2,
1403 .channels_max = 2,
Takashi Iwai9af74212011-06-18 16:17:45 +02001404 /* NID is set in via_build_pcms */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001405 .ops = {
1406 .prepare = via_capture_pcm_prepare,
1407 .cleanup = via_capture_pcm_cleanup
1408 },
1409};
1410
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001411static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1412 .substreams = 1,
1413 .channels_min = 2,
1414 .channels_max = 2,
1415 /* NID is set in via_build_pcms */
1416 .ops = {
1417 .prepare = via_dyn_adc_capture_pcm_prepare,
1418 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1419 },
1420};
1421
Takashi Iwai9af74212011-06-18 16:17:45 +02001422static const struct hda_pcm_stream via_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001423 .substreams = 1,
1424 .channels_min = 2,
1425 .channels_max = 2,
1426 /* NID is set in via_build_pcms */
1427 .ops = {
1428 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001429 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001430 .prepare = via_dig_playback_pcm_prepare,
1431 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001432 },
1433};
1434
Takashi Iwai9af74212011-06-18 16:17:45 +02001435static const struct hda_pcm_stream via_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001436 .substreams = 1,
1437 .channels_min = 2,
1438 .channels_max = 2,
1439};
1440
Takashi Iwai370bafb2011-06-20 12:47:45 +02001441/*
1442 * slave controls for virtual master
1443 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001444static const char * const via_slave_pfxs[] = {
1445 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01001446 "Headphone", "Speaker", "Bass Speaker",
Takashi Iwai370bafb2011-06-20 12:47:45 +02001447 NULL,
1448};
1449
Joseph Chanc577b8a2006-11-29 15:29:40 +01001450static int via_build_controls(struct hda_codec *codec)
1451{
1452 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001453 struct snd_kcontrol *kctl;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001454 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001455
Takashi Iwaib5bcc182012-02-02 10:30:17 +01001456 spec->no_pin_power_ctl = 1;
Takashi Iwai24088a52011-06-17 16:59:21 +02001457 if (spec->set_widgets_power_state)
1458 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1459 return -ENOMEM;
1460
Joseph Chanc577b8a2006-11-29 15:29:40 +01001461 for (i = 0; i < spec->num_mixers; i++) {
1462 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1463 if (err < 0)
1464 return err;
1465 }
1466
1467 if (spec->multiout.dig_out_nid) {
1468 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001469 spec->multiout.dig_out_nid,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001470 spec->multiout.dig_out_nid);
1471 if (err < 0)
1472 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001473 err = snd_hda_create_spdif_share_sw(codec,
1474 &spec->multiout);
1475 if (err < 0)
1476 return err;
1477 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001478 }
1479 if (spec->dig_in_nid) {
1480 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1481 if (err < 0)
1482 return err;
1483 }
Lydia Wang17314372009-10-10 19:07:37 +08001484
Takashi Iwai370bafb2011-06-20 12:47:45 +02001485 /* if we have no master control, let's create it */
1486 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1487 unsigned int vmaster_tlv[4];
1488 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1489 HDA_OUTPUT, vmaster_tlv);
1490 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001491 vmaster_tlv, via_slave_pfxs,
1492 "Playback Volume");
Takashi Iwai370bafb2011-06-20 12:47:45 +02001493 if (err < 0)
1494 return err;
1495 }
1496 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1497 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001498 NULL, via_slave_pfxs,
1499 "Playback Switch");
Takashi Iwai370bafb2011-06-20 12:47:45 +02001500 if (err < 0)
1501 return err;
1502 }
1503
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001504 /* assign Capture Source enums to NID */
1505 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1506 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai77e314f2012-02-22 12:34:08 +01001507 if (!spec->mux_nids[i])
1508 continue;
Takashi Iwai21949f02009-12-23 08:31:59 +01001509 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001510 if (err < 0)
1511 return err;
1512 }
1513
Takashi Iwai603c4012008-07-30 15:01:44 +02001514 via_free_kctls(codec); /* no longer needed */
Takashi Iwai01a61e12011-10-28 00:03:22 +02001515
1516 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1517 if (err < 0)
1518 return err;
1519
Joseph Chanc577b8a2006-11-29 15:29:40 +01001520 return 0;
1521}
1522
1523static int via_build_pcms(struct hda_codec *codec)
1524{
1525 struct via_spec *spec = codec->spec;
1526 struct hda_pcm *info = spec->pcm_rec;
1527
Takashi Iwaia5973102011-09-28 16:43:36 +02001528 codec->num_pcms = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001529 codec->pcm_info = info;
1530
Takashi Iwaia5973102011-09-28 16:43:36 +02001531 if (spec->multiout.num_dacs || spec->num_adc_nids) {
1532 snprintf(spec->stream_name_analog,
1533 sizeof(spec->stream_name_analog),
1534 "%s Analog", codec->chip_name);
1535 info->name = spec->stream_name_analog;
Takashi Iwai9af74212011-06-18 16:17:45 +02001536
Takashi Iwaia5973102011-09-28 16:43:36 +02001537 if (spec->multiout.num_dacs) {
1538 if (!spec->stream_analog_playback)
1539 spec->stream_analog_playback =
1540 &via_pcm_analog_playback;
1541 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1542 *spec->stream_analog_playback;
1543 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1544 spec->multiout.dac_nids[0];
1545 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1546 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01001547 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT
1548 && spec->autocfg.line_outs == 2)
1549 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
1550 snd_pcm_2_1_chmaps;
Takashi Iwaia5973102011-09-28 16:43:36 +02001551 }
Takashi Iwai9af74212011-06-18 16:17:45 +02001552
Takashi Iwaia5973102011-09-28 16:43:36 +02001553 if (!spec->stream_analog_capture) {
1554 if (spec->dyn_adc_switch)
1555 spec->stream_analog_capture =
1556 &via_pcm_dyn_adc_analog_capture;
1557 else
1558 spec->stream_analog_capture =
1559 &via_pcm_analog_capture;
1560 }
1561 if (spec->num_adc_nids) {
1562 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1563 *spec->stream_analog_capture;
1564 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1565 spec->adc_nids[0];
1566 if (!spec->dyn_adc_switch)
1567 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1568 spec->num_adc_nids;
1569 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001570 codec->num_pcms++;
1571 info++;
Takashi Iwaia5973102011-09-28 16:43:36 +02001572 }
1573
1574 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai82673bc2011-06-17 16:24:21 +02001575 snprintf(spec->stream_name_digital,
1576 sizeof(spec->stream_name_digital),
1577 "%s Digital", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001578 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001579 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001580 if (spec->multiout.dig_out_nid) {
Takashi Iwai9af74212011-06-18 16:17:45 +02001581 if (!spec->stream_digital_playback)
1582 spec->stream_digital_playback =
1583 &via_pcm_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001584 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001585 *spec->stream_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001586 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1587 spec->multiout.dig_out_nid;
1588 }
1589 if (spec->dig_in_nid) {
Takashi Iwai9af74212011-06-18 16:17:45 +02001590 if (!spec->stream_digital_capture)
1591 spec->stream_digital_capture =
1592 &via_pcm_digital_capture;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001593 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001594 *spec->stream_digital_capture;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001595 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1596 spec->dig_in_nid;
1597 }
Takashi Iwaia5973102011-09-28 16:43:36 +02001598 codec->num_pcms++;
1599 info++;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001600 }
1601
Takashi Iwaiece8d042011-06-19 16:24:21 +02001602 if (spec->hp_dac_nid) {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001603 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1604 "%s HP", codec->chip_name);
1605 info->name = spec->stream_name_hp;
1606 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1607 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
Takashi Iwaiece8d042011-06-19 16:24:21 +02001608 spec->hp_dac_nid;
Takashi Iwaia5973102011-09-28 16:43:36 +02001609 codec->num_pcms++;
1610 info++;
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001611 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001612 return 0;
1613}
1614
1615static void via_free(struct hda_codec *codec)
1616{
1617 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001618
1619 if (!spec)
1620 return;
1621
Takashi Iwai603c4012008-07-30 15:01:44 +02001622 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001623 vt1708_stop_hp_work(spec);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001624 kfree(spec->bind_cap_vol);
1625 kfree(spec->bind_cap_sw);
Takashi Iwai7819d1c2012-10-10 08:41:42 +02001626 snd_hda_gen_free(&spec->gen);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001627 kfree(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001628}
1629
Takashi Iwai64be2852011-06-17 16:51:39 +02001630/* mute/unmute outputs */
1631static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1632 hda_nid_t *pins, bool mute)
1633{
1634 int i;
Takashi Iwai94994732011-07-11 11:36:44 +02001635 for (i = 0; i < num_pins; i++) {
1636 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1637 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1638 if (parm & AC_PINCTL_IN_EN)
1639 continue;
1640 if (mute)
1641 parm &= ~AC_PINCTL_OUT_EN;
1642 else
1643 parm |= AC_PINCTL_OUT_EN;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001644 snd_hda_set_pin_ctl(codec, pins[i], parm);
Takashi Iwai94994732011-07-11 11:36:44 +02001645 }
Takashi Iwai64be2852011-06-17 16:51:39 +02001646}
1647
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001648/* mute internal speaker if line-out is plugged */
1649static void via_line_automute(struct hda_codec *codec, int present)
1650{
1651 struct via_spec *spec = codec->spec;
1652
1653 if (!spec->autocfg.speaker_outs)
1654 return;
1655 if (!present)
1656 present = snd_hda_jack_detect(codec,
1657 spec->autocfg.line_out_pins[0]);
1658 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1659 spec->autocfg.speaker_pins,
1660 present);
1661}
1662
Harald Welte69e52a82008-09-09 15:57:32 +08001663/* mute internal speaker if HP is plugged */
1664static void via_hp_automute(struct hda_codec *codec)
1665{
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001666 int present = 0;
Takashi Iwai6e969d92011-07-11 11:28:13 +02001667 int nums;
Harald Welte69e52a82008-09-09 15:57:32 +08001668 struct via_spec *spec = codec->spec;
1669
Takashi Iwai187d3332011-11-24 16:33:09 +01001670 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0] &&
Herton Ronaldo Krzesinskicf55e902012-09-21 20:45:19 -03001671 (spec->codec_type != VT1708 || spec->vt1708_jack_detect) &&
1672 is_jack_detectable(codec, spec->autocfg.hp_pins[0]))
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001673 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Takashi Iwai6e969d92011-07-11 11:28:13 +02001674
1675 if (spec->smart51_enabled)
1676 nums = spec->autocfg.line_outs + spec->smart51_nums;
1677 else
1678 nums = spec->autocfg.line_outs;
1679 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1680
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001681 via_line_automute(codec, present);
Lydia Wangf3db4232009-10-10 19:08:41 +08001682}
1683
Takashi Iwai2a439522011-07-26 09:52:50 +02001684#ifdef CONFIG_PM
Takashi Iwai68cb2b52012-07-02 15:20:37 +02001685static int via_suspend(struct hda_codec *codec)
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001686{
1687 struct via_spec *spec = codec->spec;
1688 vt1708_stop_hp_work(spec);
David Henningsson94c142a2012-08-09 10:56:12 +02001689
1690 if (spec->codec_type == VT1802) {
1691 /* Fix pop noise on headphones */
1692 int i;
1693 for (i = 0; i < spec->autocfg.hp_outs; i++)
1694 snd_hda_set_pin_ctl(codec, spec->autocfg.hp_pins[i], 0);
1695 }
1696
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001697 return 0;
1698}
1699#endif
1700
Takashi Iwai83012a72012-08-24 18:38:08 +02001701#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001702static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1703{
1704 struct via_spec *spec = codec->spec;
1705 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1706}
1707#endif
1708
Joseph Chanc577b8a2006-11-29 15:29:40 +01001709/*
1710 */
Takashi Iwai5d417622011-06-20 11:32:27 +02001711
1712static int via_init(struct hda_codec *codec);
1713
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001714static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001715 .build_controls = via_build_controls,
1716 .build_pcms = via_build_pcms,
1717 .init = via_init,
1718 .free = via_free,
David Henningsson4e2d16d2012-10-08 15:44:14 +02001719 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02001720#ifdef CONFIG_PM
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001721 .suspend = via_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02001722 .check_power_status = via_check_power_status,
1723#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001724};
1725
Takashi Iwai4a796162011-06-17 17:53:38 +02001726static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001727{
Takashi Iwai4a796162011-06-17 17:53:38 +02001728 struct via_spec *spec = codec->spec;
1729 int i;
1730
1731 for (i = 0; i < spec->multiout.num_dacs; i++) {
1732 if (spec->multiout.dac_nids[i] == dac)
1733 return false;
1734 }
Takashi Iwaiece8d042011-06-19 16:24:21 +02001735 if (spec->hp_dac_nid == dac)
Takashi Iwai4a796162011-06-17 17:53:38 +02001736 return false;
1737 return true;
1738}
1739
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001740static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai3214b962011-07-18 12:49:25 +02001741 hda_nid_t target_dac, int with_aa_mix,
1742 struct nid_path *path, int depth)
Takashi Iwai4a796162011-06-17 17:53:38 +02001743{
Takashi Iwai3214b962011-07-18 12:49:25 +02001744 struct via_spec *spec = codec->spec;
Takashi Iwai4a796162011-06-17 17:53:38 +02001745 hda_nid_t conn[8];
1746 int i, nums;
1747
Takashi Iwai3214b962011-07-18 12:49:25 +02001748 if (nid == spec->aa_mix_nid) {
1749 if (!with_aa_mix)
1750 return false;
1751 with_aa_mix = 2; /* mark aa-mix is included */
1752 }
1753
Takashi Iwai4a796162011-06-17 17:53:38 +02001754 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1755 for (i = 0; i < nums; i++) {
1756 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1757 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +02001758 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1759 /* aa-mix is requested but not included? */
1760 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1761 goto found;
1762 }
Takashi Iwai4a796162011-06-17 17:53:38 +02001763 }
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001764 if (depth >= MAX_NID_PATH_DEPTH)
Takashi Iwai4a796162011-06-17 17:53:38 +02001765 return false;
1766 for (i = 0; i < nums; i++) {
1767 unsigned int type;
1768 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai3214b962011-07-18 12:49:25 +02001769 if (type == AC_WID_AUD_OUT)
Takashi Iwai4a796162011-06-17 17:53:38 +02001770 continue;
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001771 if (__parse_output_path(codec, conn[i], target_dac,
Takashi Iwai3214b962011-07-18 12:49:25 +02001772 with_aa_mix, path, depth + 1))
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001773 goto found;
Takashi Iwai4a796162011-06-17 17:53:38 +02001774 }
1775 return false;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001776
1777 found:
1778 path->path[path->depth] = conn[i];
1779 path->idx[path->depth] = i;
1780 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1781 path->multi[path->depth] = 1;
1782 path->depth++;
1783 return true;
Takashi Iwai4a796162011-06-17 17:53:38 +02001784}
1785
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001786static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai3214b962011-07-18 12:49:25 +02001787 hda_nid_t target_dac, int with_aa_mix,
1788 struct nid_path *path)
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001789{
Takashi Iwai3214b962011-07-18 12:49:25 +02001790 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001791 path->path[path->depth] = nid;
1792 path->depth++;
Takashi Iwai3214b962011-07-18 12:49:25 +02001793 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1794 path->depth, path->path[0], path->path[1],
1795 path->path[2], path->path[3], path->path[4]);
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001796 return true;
1797 }
1798 return false;
1799}
1800
Takashi Iwai4a796162011-06-17 17:53:38 +02001801static int via_auto_fill_dac_nids(struct hda_codec *codec)
1802{
1803 struct via_spec *spec = codec->spec;
1804 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai5b376192012-11-07 10:32:47 +01001805 int i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001806 hda_nid_t nid;
1807
Takashi Iwai5b376192012-11-07 10:32:47 +01001808 spec->multiout.num_dacs = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001809 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai4a796162011-06-17 17:53:38 +02001810 for (i = 0; i < cfg->line_outs; i++) {
Takashi Iwai3214b962011-07-18 12:49:25 +02001811 hda_nid_t dac = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001812 nid = cfg->line_out_pins[i];
Takashi Iwai4a796162011-06-17 17:53:38 +02001813 if (!nid)
1814 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +02001815 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1816 dac = spec->out_path[i].path[0];
1817 if (!i && parse_output_path(codec, nid, dac, 1,
1818 &spec->out_mix_path))
1819 dac = spec->out_mix_path.path[0];
Takashi Iwai5b376192012-11-07 10:32:47 +01001820 if (dac)
1821 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001822 }
Takashi Iwai3214b962011-07-18 12:49:25 +02001823 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1824 spec->out_path[0] = spec->out_mix_path;
1825 spec->out_mix_path.depth = 0;
1826 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001827 return 0;
1828}
1829
Takashi Iwai4a796162011-06-17 17:53:38 +02001830static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001831 int chs, bool check_dac, struct nid_path *path)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001832{
Takashi Iwai4a796162011-06-17 17:53:38 +02001833 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001834 char name[32];
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001835 hda_nid_t dac, pin, sel, nid;
1836 int err;
Takashi Iwaia934d5a2011-06-21 14:22:14 +02001837
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001838 dac = check_dac ? path->path[0] : 0;
1839 pin = path->path[path->depth - 1];
1840 sel = path->depth > 1 ? path->path[1] : 0;
Takashi Iwai4a796162011-06-17 17:53:38 +02001841
Takashi Iwai8df2a312011-06-21 11:48:29 +02001842 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
Takashi Iwai4a796162011-06-17 17:53:38 +02001843 nid = dac;
Takashi Iwai8df2a312011-06-21 11:48:29 +02001844 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
Takashi Iwai4a796162011-06-17 17:53:38 +02001845 nid = pin;
Takashi Iwaia934d5a2011-06-21 14:22:14 +02001846 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1847 nid = sel;
Takashi Iwai4a796162011-06-17 17:53:38 +02001848 else
1849 nid = 0;
1850 if (nid) {
1851 sprintf(name, "%s Playback Volume", pfx);
1852 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wanga00a5fa2011-06-21 16:11:11 +08001853 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
Takashi Iwai4a796162011-06-17 17:53:38 +02001854 if (err < 0)
1855 return err;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001856 path->vol_ctl = nid;
Takashi Iwai4a796162011-06-17 17:53:38 +02001857 }
1858
Takashi Iwai8df2a312011-06-21 11:48:29 +02001859 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
Takashi Iwai4a796162011-06-17 17:53:38 +02001860 nid = dac;
Takashi Iwai8df2a312011-06-21 11:48:29 +02001861 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
Takashi Iwai4a796162011-06-17 17:53:38 +02001862 nid = pin;
Takashi Iwaia934d5a2011-06-21 14:22:14 +02001863 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1864 nid = sel;
Takashi Iwai4a796162011-06-17 17:53:38 +02001865 else
1866 nid = 0;
1867 if (nid) {
1868 sprintf(name, "%s Playback Switch", pfx);
1869 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1870 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1871 if (err < 0)
1872 return err;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001873 path->mute_ctl = nid;
Takashi Iwai4a796162011-06-17 17:53:38 +02001874 }
1875 return 0;
1876}
1877
Takashi Iwaif4a78282011-06-17 18:46:48 +02001878static void mangle_smart51(struct hda_codec *codec)
1879{
1880 struct via_spec *spec = codec->spec;
1881 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0f98c242011-06-21 12:51:33 +02001882 struct auto_pin_cfg_item *ins = cfg->inputs;
1883 int i, j, nums, attr;
1884 int pins[AUTO_CFG_MAX_INS];
Takashi Iwaif4a78282011-06-17 18:46:48 +02001885
Takashi Iwai0f98c242011-06-21 12:51:33 +02001886 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1887 nums = 0;
1888 for (i = 0; i < cfg->num_inputs; i++) {
1889 unsigned int def;
1890 if (ins[i].type > AUTO_PIN_LINE_IN)
1891 continue;
1892 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1893 if (snd_hda_get_input_pin_attr(def) != attr)
1894 continue;
1895 for (j = 0; j < nums; j++)
1896 if (ins[pins[j]].type < ins[i].type) {
1897 memmove(pins + j + 1, pins + j,
Takashi Iwai21d45d22011-07-08 11:35:11 +02001898 (nums - j) * sizeof(int));
Takashi Iwai0f98c242011-06-21 12:51:33 +02001899 break;
1900 }
1901 pins[j] = i;
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001902 nums++;
Takashi Iwai0f98c242011-06-21 12:51:33 +02001903 }
1904 if (cfg->line_outs + nums < 3)
Takashi Iwaif4a78282011-06-17 18:46:48 +02001905 continue;
Takashi Iwai0f98c242011-06-21 12:51:33 +02001906 for (i = 0; i < nums; i++) {
1907 hda_nid_t pin = ins[pins[i]].pin;
1908 spec->smart51_pins[spec->smart51_nums++] = pin;
1909 cfg->line_out_pins[cfg->line_outs++] = pin;
1910 if (cfg->line_outs == 3)
1911 break;
1912 }
1913 return;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001914 }
1915}
1916
Takashi Iwai020066d2011-07-21 13:45:56 +02001917static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
1918{
1919 dst->vol_ctl = src->vol_ctl;
1920 dst->mute_ctl = src->mute_ctl;
1921}
1922
Takashi Iwai4a796162011-06-17 17:53:38 +02001923/* add playback controls from the parsed DAC table */
1924static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1925{
1926 struct via_spec *spec = codec->spec;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001927 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai3214b962011-07-18 12:49:25 +02001928 struct nid_path *path;
Takashi Iwaiea734962011-01-17 11:29:34 +01001929 static const char * const chname[4] = {
David Henningsson34ca8d32012-11-09 07:03:59 +01001930 "Front", "Surround", NULL /* "CLFE" */, "Side"
Takashi Iwaiea734962011-01-17 11:29:34 +01001931 };
Takashi Iwai4a796162011-06-17 17:53:38 +02001932 int i, idx, err;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001933 int old_line_outs;
1934
1935 /* check smart51 */
1936 old_line_outs = cfg->line_outs;
1937 if (cfg->line_outs == 1)
1938 mangle_smart51(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001939
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001940 err = via_auto_fill_dac_nids(codec);
1941 if (err < 0)
1942 return err;
1943
Lydia Wang5c9a5612011-07-08 14:03:43 +08001944 if (spec->multiout.num_dacs < 3) {
1945 spec->smart51_nums = 0;
1946 cfg->line_outs = old_line_outs;
1947 }
Takashi Iwai4a796162011-06-17 17:53:38 +02001948 for (i = 0; i < cfg->line_outs; i++) {
1949 hda_nid_t pin, dac;
1950 pin = cfg->line_out_pins[i];
1951 dac = spec->multiout.dac_nids[i];
1952 if (!pin || !dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001953 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +02001954 path = spec->out_path + i;
Takashi Iwai0fe0adf2011-06-19 16:27:53 +02001955 if (i == HDA_CLFE) {
Takashi Iwai3214b962011-07-18 12:49:25 +02001956 err = create_ch_ctls(codec, "Center", 1, true, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001957 if (err < 0)
1958 return err;
Takashi Iwai3214b962011-07-18 12:49:25 +02001959 err = create_ch_ctls(codec, "LFE", 2, true, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001960 if (err < 0)
1961 return err;
1962 } else {
Takashi Iwai6aadf412011-06-20 14:09:02 +02001963 const char *pfx = chname[i];
1964 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01001965 cfg->line_outs <= 2)
1966 pfx = i ? "Bass Speaker" : "Speaker";
Takashi Iwai3214b962011-07-18 12:49:25 +02001967 err = create_ch_ctls(codec, pfx, 3, true, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001968 if (err < 0)
1969 return err;
1970 }
Takashi Iwai020066d2011-07-21 13:45:56 +02001971 if (path != spec->out_path + i)
1972 copy_path_mixer_ctls(&spec->out_path[i], path);
1973 if (path == spec->out_path && spec->out_mix_path.depth)
1974 copy_path_mixer_ctls(&spec->out_mix_path, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001975 }
1976
Takashi Iwai4a796162011-06-17 17:53:38 +02001977 idx = get_connection_index(codec, spec->aa_mix_nid,
1978 spec->multiout.dac_nids[0]);
1979 if (idx >= 0) {
1980 /* add control to mixer */
Takashi Iwai3214b962011-07-18 12:49:25 +02001981 const char *name;
1982 name = spec->out_mix_path.depth ?
1983 "PCM Loopback Playback Volume" : "PCM Playback Volume";
1984 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Takashi Iwai4a796162011-06-17 17:53:38 +02001985 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1986 idx, HDA_INPUT));
1987 if (err < 0)
1988 return err;
Takashi Iwai3214b962011-07-18 12:49:25 +02001989 name = spec->out_mix_path.depth ?
1990 "PCM Loopback Playback Switch" : "PCM Playback Switch";
1991 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Takashi Iwai4a796162011-06-17 17:53:38 +02001992 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1993 idx, HDA_INPUT));
1994 if (err < 0)
1995 return err;
1996 }
1997
Takashi Iwaif4a78282011-06-17 18:46:48 +02001998 cfg->line_outs = old_line_outs;
1999
Joseph Chanc577b8a2006-11-29 15:29:40 +01002000 return 0;
2001}
2002
Takashi Iwai4a796162011-06-17 17:53:38 +02002003static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002004{
Takashi Iwai4a796162011-06-17 17:53:38 +02002005 struct via_spec *spec = codec->spec;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02002006 struct nid_path *path;
Takashi Iwai18bd2c42011-07-04 15:55:44 +02002007 bool check_dac;
Takashi Iwai3214b962011-07-18 12:49:25 +02002008 int i, err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002009
2010 if (!pin)
2011 return 0;
2012
Takashi Iwai3214b962011-07-18 12:49:25 +02002013 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
2014 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
2015 if (i < spec->multiout.num_dacs &&
2016 parse_output_path(codec, pin,
2017 spec->multiout.dac_nids[i], 0,
2018 &spec->hp_indep_path)) {
2019 spec->hp_indep_shared = i;
2020 break;
2021 }
2022 }
Takashi Iwai25250502011-06-30 17:24:47 +02002023 }
Takashi Iwai3214b962011-07-18 12:49:25 +02002024 if (spec->hp_indep_path.depth) {
2025 spec->hp_dac_nid = spec->hp_indep_path.path[0];
2026 if (!spec->hp_indep_shared)
2027 spec->hp_path = spec->hp_indep_path;
2028 }
2029 /* optionally check front-path w/o AA-mix */
2030 if (!spec->hp_path.depth)
2031 parse_output_path(codec, pin,
2032 spec->multiout.dac_nids[HDA_FRONT], 0,
2033 &spec->hp_path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002034
Takashi Iwaiece8d042011-06-19 16:24:21 +02002035 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
Takashi Iwai3214b962011-07-18 12:49:25 +02002036 1, &spec->hp_mix_path) && !spec->hp_path.depth)
Takashi Iwaiece8d042011-06-19 16:24:21 +02002037 return 0;
2038
Takashi Iwai3214b962011-07-18 12:49:25 +02002039 if (spec->hp_path.depth) {
Takashi Iwai09a9ad692011-06-21 15:57:44 +02002040 path = &spec->hp_path;
Takashi Iwai18bd2c42011-07-04 15:55:44 +02002041 check_dac = true;
2042 } else {
Takashi Iwai3214b962011-07-18 12:49:25 +02002043 path = &spec->hp_mix_path;
Takashi Iwai18bd2c42011-07-04 15:55:44 +02002044 check_dac = false;
2045 }
2046 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002047 if (err < 0)
2048 return err;
Takashi Iwai020066d2011-07-21 13:45:56 +02002049 if (check_dac)
2050 copy_path_mixer_ctls(&spec->hp_mix_path, path);
2051 else
2052 copy_path_mixer_ctls(&spec->hp_path, path);
2053 if (spec->hp_indep_path.depth)
2054 copy_path_mixer_ctls(&spec->hp_indep_path, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002055 return 0;
2056}
2057
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002058static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2059{
2060 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +02002061 struct nid_path *path;
2062 bool check_dac;
Wang Shaoyan81c0a782011-08-05 18:51:29 +08002063 hda_nid_t pin, dac = 0;
Takashi Iwai3214b962011-07-18 12:49:25 +02002064 int err;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002065
2066 pin = spec->autocfg.speaker_pins[0];
2067 if (!spec->autocfg.speaker_outs || !pin)
2068 return 0;
2069
Takashi Iwai3214b962011-07-18 12:49:25 +02002070 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
Takashi Iwai8e3679d2011-06-21 09:01:36 +02002071 dac = spec->speaker_path.path[0];
Takashi Iwai3214b962011-07-18 12:49:25 +02002072 if (!dac)
2073 parse_output_path(codec, pin,
2074 spec->multiout.dac_nids[HDA_FRONT], 0,
2075 &spec->speaker_path);
2076 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2077 1, &spec->speaker_mix_path) && !dac)
2078 return 0;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002079
Takashi Iwai3214b962011-07-18 12:49:25 +02002080 /* no AA-path for front? */
2081 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2082 dac = 0;
2083
2084 spec->speaker_dac_nid = dac;
2085 spec->multiout.extra_out_nid[0] = dac;
2086 if (dac) {
2087 path = &spec->speaker_path;
2088 check_dac = true;
2089 } else {
2090 path = &spec->speaker_mix_path;
2091 check_dac = false;
2092 }
2093 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2094 if (err < 0)
2095 return err;
Takashi Iwai020066d2011-07-21 13:45:56 +02002096 if (check_dac)
2097 copy_path_mixer_ctls(&spec->speaker_mix_path, path);
2098 else
2099 copy_path_mixer_ctls(&spec->speaker_path, path);
Takashi Iwai3214b962011-07-18 12:49:25 +02002100 return 0;
2101}
2102
2103#define via_aamix_ctl_info via_pin_power_ctl_info
2104
2105static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2106 struct snd_ctl_elem_value *ucontrol)
2107{
2108 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2109 struct via_spec *spec = codec->spec;
2110 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2111 return 0;
2112}
2113
2114static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2115 struct nid_path *nomix, struct nid_path *mix)
2116{
2117 if (do_mix) {
2118 activate_output_path(codec, nomix, false, false);
2119 activate_output_path(codec, mix, true, false);
2120 } else {
2121 activate_output_path(codec, mix, false, false);
2122 activate_output_path(codec, nomix, true, false);
2123 }
2124}
2125
2126static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2127 struct snd_ctl_elem_value *ucontrol)
2128{
2129 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2130 struct via_spec *spec = codec->spec;
2131 unsigned int val = ucontrol->value.enumerated.item[0];
2132
2133 if (val == spec->aamix_mode)
2134 return 0;
2135 spec->aamix_mode = val;
2136 /* update front path */
2137 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2138 /* update HP path */
2139 if (!spec->hp_independent_mode) {
2140 update_aamix_paths(codec, val, &spec->hp_path,
2141 &spec->hp_mix_path);
2142 }
2143 /* update speaker path */
2144 update_aamix_paths(codec, val, &spec->speaker_path,
2145 &spec->speaker_mix_path);
2146 return 1;
2147}
2148
2149static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2150 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2151 .name = "Loopback Mixing",
2152 .info = via_aamix_ctl_info,
2153 .get = via_aamix_ctl_get,
2154 .put = via_aamix_ctl_put,
2155};
2156
2157static int via_auto_create_loopback_switch(struct hda_codec *codec)
2158{
2159 struct via_spec *spec = codec->spec;
2160
Takashi Iwai4808d122012-01-10 15:16:02 +01002161 if (!spec->aa_mix_nid)
2162 return 0; /* no loopback switching available */
2163 if (!(spec->out_mix_path.depth || spec->hp_mix_path.depth ||
2164 spec->speaker_path.depth))
Takashi Iwai3214b962011-07-18 12:49:25 +02002165 return 0; /* no loopback switching available */
2166 if (!via_clone_control(spec, &via_aamix_ctl_enum))
2167 return -ENOMEM;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002168 return 0;
2169}
2170
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002171/* look for ADCs */
2172static int via_fill_adcs(struct hda_codec *codec)
2173{
2174 struct via_spec *spec = codec->spec;
2175 hda_nid_t nid = codec->start_nid;
2176 int i;
2177
2178 for (i = 0; i < codec->num_nodes; i++, nid++) {
2179 unsigned int wcaps = get_wcaps(codec, nid);
2180 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2181 continue;
2182 if (wcaps & AC_WCAP_DIGITAL)
2183 continue;
2184 if (!(wcaps & AC_WCAP_CONN_LIST))
2185 continue;
2186 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2187 return -ENOMEM;
2188 spec->adc_nids[spec->num_adc_nids++] = nid;
2189 }
2190 return 0;
2191}
2192
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002193/* input-src control */
2194static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
2195 struct snd_ctl_elem_info *uinfo)
2196{
2197 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2198 struct via_spec *spec = codec->spec;
2199
2200 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2201 uinfo->count = 1;
2202 uinfo->value.enumerated.items = spec->num_inputs;
2203 if (uinfo->value.enumerated.item >= spec->num_inputs)
2204 uinfo->value.enumerated.item = spec->num_inputs - 1;
2205 strcpy(uinfo->value.enumerated.name,
2206 spec->inputs[uinfo->value.enumerated.item].label);
2207 return 0;
2208}
2209
2210static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2211 struct snd_ctl_elem_value *ucontrol)
2212{
2213 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2214 struct via_spec *spec = codec->spec;
2215 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2216
2217 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2218 return 0;
2219}
2220
2221static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2222 struct snd_ctl_elem_value *ucontrol)
2223{
2224 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2225 struct via_spec *spec = codec->spec;
2226 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2227 hda_nid_t mux;
2228 int cur;
2229
2230 cur = ucontrol->value.enumerated.item[0];
2231 if (cur < 0 || cur >= spec->num_inputs)
2232 return -EINVAL;
2233 if (spec->cur_mux[idx] == cur)
2234 return 0;
2235 spec->cur_mux[idx] = cur;
2236 if (spec->dyn_adc_switch) {
2237 int adc_idx = spec->inputs[cur].adc_idx;
2238 mux = spec->mux_nids[adc_idx];
2239 via_dyn_adc_pcm_resetup(codec, cur);
2240 } else {
2241 mux = spec->mux_nids[idx];
2242 if (snd_BUG_ON(!mux))
2243 return -EINVAL;
2244 }
2245
2246 if (mux) {
2247 /* switch to D0 beofre change index */
Takashi Iwai054d8672012-01-24 12:25:50 +01002248 update_power_state(codec, mux, AC_PWRST_D0);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002249 snd_hda_codec_write(codec, mux, 0,
2250 AC_VERB_SET_CONNECT_SEL,
2251 spec->inputs[cur].mux_idx);
2252 }
2253
2254 /* update jack power state */
2255 set_widgets_power_state(codec);
2256 return 0;
2257}
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002258
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002259static const struct snd_kcontrol_new via_input_src_ctl = {
2260 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2261 /* The multiple "Capture Source" controls confuse alsamixer
2262 * So call somewhat different..
2263 */
2264 /* .name = "Capture Source", */
2265 .name = "Input Source",
2266 .info = via_mux_enum_info,
2267 .get = via_mux_enum_get,
2268 .put = via_mux_enum_put,
2269};
2270
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002271static int create_input_src_ctls(struct hda_codec *codec, int count)
2272{
2273 struct via_spec *spec = codec->spec;
2274 struct snd_kcontrol_new *knew;
2275
2276 if (spec->num_inputs <= 1 || !count)
2277 return 0; /* no need for single src */
2278
2279 knew = via_clone_control(spec, &via_input_src_ctl);
2280 if (!knew)
2281 return -ENOMEM;
2282 knew->count = count;
2283 return 0;
2284}
2285
2286/* add the powersave loopback-list entry */
Takashi Iwai13af8e72011-06-20 14:05:46 +02002287static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2288{
2289 struct hda_amp_list *list;
2290
2291 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2292 return;
2293 list = spec->loopback_list + spec->num_loopbacks;
2294 list->nid = mix;
2295 list->dir = HDA_INPUT;
2296 list->idx = idx;
2297 spec->num_loopbacks++;
2298 spec->loopback.amplist = spec->loopback_list;
2299}
Takashi Iwai13af8e72011-06-20 14:05:46 +02002300
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002301static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
Takashi Iwai8d087c72011-06-28 12:45:47 +02002302 hda_nid_t dst)
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002303{
Takashi Iwai8d087c72011-06-28 12:45:47 +02002304 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002305}
2306
2307/* add the input-route to the given pin */
2308static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002309{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002310 struct via_spec *spec = codec->spec;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002311 int c, idx;
2312
2313 spec->inputs[spec->num_inputs].adc_idx = -1;
2314 spec->inputs[spec->num_inputs].pin = pin;
2315 for (c = 0; c < spec->num_adc_nids; c++) {
2316 if (spec->mux_nids[c]) {
2317 idx = get_connection_index(codec, spec->mux_nids[c],
2318 pin);
2319 if (idx < 0)
2320 continue;
2321 spec->inputs[spec->num_inputs].mux_idx = idx;
2322 } else {
Takashi Iwai8d087c72011-06-28 12:45:47 +02002323 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002324 continue;
2325 }
2326 spec->inputs[spec->num_inputs].adc_idx = c;
2327 /* Can primary ADC satisfy all inputs? */
2328 if (!spec->dyn_adc_switch &&
2329 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2330 snd_printd(KERN_INFO
2331 "via: dynamic ADC switching enabled\n");
2332 spec->dyn_adc_switch = 1;
2333 }
2334 return true;
2335 }
2336 return false;
2337}
2338
2339static int get_mux_nids(struct hda_codec *codec);
2340
2341/* parse input-routes; fill ADCs, MUXs and input-src entries */
2342static int parse_analog_inputs(struct hda_codec *codec)
2343{
2344 struct via_spec *spec = codec->spec;
2345 const struct auto_pin_cfg *cfg = &spec->autocfg;
2346 int i, err;
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002347
2348 err = via_fill_adcs(codec);
2349 if (err < 0)
2350 return err;
2351 err = get_mux_nids(codec);
2352 if (err < 0)
2353 return err;
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002354
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002355 /* fill all input-routes */
2356 for (i = 0; i < cfg->num_inputs; i++) {
2357 if (add_input_route(codec, cfg->inputs[i].pin))
2358 spec->inputs[spec->num_inputs++].label =
2359 hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwaif3268512010-08-30 11:00:19 +02002360 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002361
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002362 /* check for internal loopback recording */
2363 if (spec->aa_mix_nid &&
2364 add_input_route(codec, spec->aa_mix_nid))
2365 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2366
2367 return 0;
2368}
2369
2370/* create analog-loopback volume/switch controls */
2371static int create_loopback_ctls(struct hda_codec *codec)
2372{
2373 struct via_spec *spec = codec->spec;
2374 const struct auto_pin_cfg *cfg = &spec->autocfg;
2375 const char *prev_label = NULL;
2376 int type_idx = 0;
2377 int i, j, err, idx;
2378
2379 if (!spec->aa_mix_nid)
2380 return 0;
2381
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002382 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002383 hda_nid_t pin = cfg->inputs[i].pin;
2384 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2385
Takashi Iwai1e11cae2011-06-21 12:57:22 +02002386 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002387 type_idx++;
2388 else
2389 type_idx = 0;
Takashi Iwai1e11cae2011-06-21 12:57:22 +02002390 prev_label = label;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002391 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2392 if (idx >= 0) {
Lydia Wang16922282011-03-22 16:24:10 +08002393 err = via_new_analog_input(spec, label, type_idx,
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002394 idx, spec->aa_mix_nid);
Takashi Iwai13af8e72011-06-20 14:05:46 +02002395 if (err < 0)
2396 return err;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002397 add_loopback_list(spec, spec->aa_mix_nid, idx);
Takashi Iwai13af8e72011-06-20 14:05:46 +02002398 }
Takashi Iwaie3d7a142011-06-20 13:52:33 +02002399
2400 /* remember the label for smart51 control */
2401 for (j = 0; j < spec->smart51_nums; j++) {
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002402 if (spec->smart51_pins[j] == pin) {
Takashi Iwaie3d7a142011-06-20 13:52:33 +02002403 spec->smart51_idxs[j] = idx;
2404 spec->smart51_labels[j] = label;
2405 break;
2406 }
2407 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002408 }
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002409 return 0;
2410}
2411
2412/* create mic-boost controls (if present) */
2413static int create_mic_boost_ctls(struct hda_codec *codec)
2414{
2415 struct via_spec *spec = codec->spec;
2416 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8d8bbc62012-02-22 12:26:38 +01002417 const char *prev_label = NULL;
2418 int type_idx = 0;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002419 int i, err;
2420
2421 for (i = 0; i < cfg->num_inputs; i++) {
2422 hda_nid_t pin = cfg->inputs[i].pin;
2423 unsigned int caps;
2424 const char *label;
2425 char name[32];
2426
2427 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2428 continue;
2429 caps = query_amp_caps(codec, pin, HDA_INPUT);
2430 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2431 continue;
2432 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai8d8bbc62012-02-22 12:26:38 +01002433 if (prev_label && !strcmp(label, prev_label))
2434 type_idx++;
2435 else
2436 type_idx = 0;
2437 prev_label = label;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002438 snprintf(name, sizeof(name), "%s Boost Volume", label);
Takashi Iwai8d8bbc62012-02-22 12:26:38 +01002439 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002440 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2441 if (err < 0)
2442 return err;
2443 }
2444 return 0;
2445}
2446
2447/* create capture and input-src controls for multiple streams */
2448static int create_multi_adc_ctls(struct hda_codec *codec)
2449{
2450 struct via_spec *spec = codec->spec;
2451 int i, err;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002452
2453 /* create capture mixer elements */
2454 for (i = 0; i < spec->num_adc_nids; i++) {
2455 hda_nid_t adc = spec->adc_nids[i];
2456 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2457 "Capture Volume", i,
2458 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2459 HDA_INPUT));
2460 if (err < 0)
2461 return err;
2462 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2463 "Capture Switch", i,
2464 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2465 HDA_INPUT));
2466 if (err < 0)
2467 return err;
2468 }
2469
2470 /* input-source control */
2471 for (i = 0; i < spec->num_adc_nids; i++)
2472 if (!spec->mux_nids[i])
2473 break;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002474 err = create_input_src_ctls(codec, i);
2475 if (err < 0)
2476 return err;
2477 return 0;
2478}
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002479
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002480/* bind capture volume/switch */
2481static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2482 HDA_BIND_VOL("Capture Volume", 0);
2483static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2484 HDA_BIND_SW("Capture Switch", 0);
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002485
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002486static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2487 struct hda_ctl_ops *ops)
2488{
2489 struct hda_bind_ctls *ctl;
2490 int i;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002491
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002492 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2493 if (!ctl)
2494 return -ENOMEM;
2495 ctl->ops = ops;
2496 for (i = 0; i < spec->num_adc_nids; i++)
2497 ctl->values[i] =
2498 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2499 *ctl_ret = ctl;
2500 return 0;
2501}
2502
2503/* create capture and input-src controls for dynamic ADC-switch case */
2504static int create_dyn_adc_ctls(struct hda_codec *codec)
2505{
2506 struct via_spec *spec = codec->spec;
2507 struct snd_kcontrol_new *knew;
2508 int err;
2509
2510 /* set up the bind capture ctls */
2511 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2512 if (err < 0)
2513 return err;
2514 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2515 if (err < 0)
2516 return err;
2517
2518 /* create capture mixer elements */
2519 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2520 if (!knew)
2521 return -ENOMEM;
2522 knew->private_value = (long)spec->bind_cap_vol;
2523
2524 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2525 if (!knew)
2526 return -ENOMEM;
2527 knew->private_value = (long)spec->bind_cap_sw;
2528
2529 /* input-source control */
2530 err = create_input_src_ctls(codec, 1);
2531 if (err < 0)
2532 return err;
2533 return 0;
2534}
2535
2536/* parse and create capture-related stuff */
2537static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2538{
2539 struct via_spec *spec = codec->spec;
2540 int err;
2541
2542 err = parse_analog_inputs(codec);
2543 if (err < 0)
2544 return err;
2545 if (spec->dyn_adc_switch)
2546 err = create_dyn_adc_ctls(codec);
2547 else
2548 err = create_multi_adc_ctls(codec);
2549 if (err < 0)
2550 return err;
2551 err = create_loopback_ctls(codec);
2552 if (err < 0)
2553 return err;
2554 err = create_mic_boost_ctls(codec);
2555 if (err < 0)
2556 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002557 return 0;
2558}
2559
Harald Welte76d9b0d2008-09-09 15:50:37 +08002560static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2561{
2562 unsigned int def_conf;
2563 unsigned char seqassoc;
2564
Takashi Iwai2f334f92009-02-20 14:37:42 +01002565 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002566 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2567 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002568 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2569 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2570 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2571 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002572 }
2573
2574 return;
2575}
2576
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002577static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002578 struct snd_ctl_elem_value *ucontrol)
2579{
2580 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2581 struct via_spec *spec = codec->spec;
2582
2583 if (spec->codec_type != VT1708)
2584 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002585 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002586 return 0;
2587}
2588
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002589static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002590 struct snd_ctl_elem_value *ucontrol)
2591{
2592 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2593 struct via_spec *spec = codec->spec;
Takashi Iwai187d3332011-11-24 16:33:09 +01002594 int val;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002595
2596 if (spec->codec_type != VT1708)
2597 return 0;
Takashi Iwai187d3332011-11-24 16:33:09 +01002598 val = !!ucontrol->value.integer.value[0];
2599 if (spec->vt1708_jack_detect == val)
2600 return 0;
2601 spec->vt1708_jack_detect = val;
2602 if (spec->vt1708_jack_detect &&
2603 snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002604 mute_aa_path(codec, 1);
2605 notify_aa_path_ctls(codec);
2606 }
Takashi Iwai187d3332011-11-24 16:33:09 +01002607 via_hp_automute(codec);
2608 vt1708_update_hp_work(spec);
2609 return 1;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002610}
2611
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002612static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2613 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2614 .name = "Jack Detect",
2615 .count = 1,
2616 .info = snd_ctl_boolean_mono_info,
2617 .get = vt1708_jack_detect_get,
2618 .put = vt1708_jack_detect_put,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002619};
2620
Takashi Iwai12daef62011-06-18 17:45:49 +02002621static void fill_dig_outs(struct hda_codec *codec);
2622static void fill_dig_in(struct hda_codec *codec);
2623
2624static int via_parse_auto_config(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002625{
2626 struct via_spec *spec = codec->spec;
2627 int err;
2628
2629 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2630 if (err < 0)
2631 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002632 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
Takashi Iwai7f0df882011-06-18 17:33:34 +02002633 return -EINVAL;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002634
Takashi Iwai4a796162011-06-17 17:53:38 +02002635 err = via_auto_create_multi_out_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002636 if (err < 0)
2637 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002638 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002639 if (err < 0)
2640 return err;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002641 err = via_auto_create_speaker_ctls(codec);
2642 if (err < 0)
2643 return err;
Takashi Iwai3214b962011-07-18 12:49:25 +02002644 err = via_auto_create_loopback_switch(codec);
2645 if (err < 0)
2646 return err;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002647 err = via_auto_create_analog_input_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002648 if (err < 0)
2649 return err;
2650
2651 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2652
Takashi Iwai12daef62011-06-18 17:45:49 +02002653 fill_dig_outs(codec);
2654 fill_dig_in(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002655
Takashi Iwai603c4012008-07-30 15:01:44 +02002656 if (spec->kctls.list)
2657 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002658
Joseph Chanc577b8a2006-11-29 15:29:40 +01002659
Takashi Iwai3214b962011-07-18 12:49:25 +02002660 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
Takashi Iwaiece8d042011-06-19 16:24:21 +02002661 err = via_hp_build(codec);
2662 if (err < 0)
2663 return err;
2664 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002665
Takashi Iwaif4a78282011-06-17 18:46:48 +02002666 err = via_smart51_build(codec);
2667 if (err < 0)
2668 return err;
2669
Takashi Iwai5d417622011-06-20 11:32:27 +02002670 /* assign slave outs */
2671 if (spec->slave_dig_outs[0])
2672 codec->slave_dig_outs = spec->slave_dig_outs;
2673
Joseph Chanc577b8a2006-11-29 15:29:40 +01002674 return 1;
2675}
2676
Takashi Iwai5d417622011-06-20 11:32:27 +02002677static void via_auto_init_dig_outs(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002678{
Lydia Wang25eaba22009-10-10 19:08:43 +08002679 struct via_spec *spec = codec->spec;
Takashi Iwai5d417622011-06-20 11:32:27 +02002680 if (spec->multiout.dig_out_nid)
2681 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2682 if (spec->slave_dig_outs[0])
2683 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2684}
Lydia Wang25eaba22009-10-10 19:08:43 +08002685
Takashi Iwai5d417622011-06-20 11:32:27 +02002686static void via_auto_init_dig_in(struct hda_codec *codec)
2687{
2688 struct via_spec *spec = codec->spec;
2689 if (!spec->dig_in_nid)
2690 return;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002691 snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN);
Takashi Iwai5d417622011-06-20 11:32:27 +02002692}
2693
David Henningsson4e2d16d2012-10-08 15:44:14 +02002694static void via_jack_output_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2695{
2696 set_widgets_power_state(codec);
2697 via_hp_automute(codec);
2698}
2699
2700static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2701{
2702 set_widgets_power_state(codec);
2703}
2704
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002705/* initialize the unsolicited events */
2706static void via_auto_init_unsol_event(struct hda_codec *codec)
2707{
2708 struct via_spec *spec = codec->spec;
2709 struct auto_pin_cfg *cfg = &spec->autocfg;
2710 unsigned int ev;
2711 int i;
David Henningsson4e2d16d2012-10-08 15:44:14 +02002712 hda_jack_callback cb;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002713
2714 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
David Henningsson4e2d16d2012-10-08 15:44:14 +02002715 snd_hda_jack_detect_enable_callback(codec, cfg->hp_pins[0],
2716 VIA_HP_EVENT | VIA_JACK_EVENT,
2717 via_jack_output_event);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002718
2719 if (cfg->speaker_pins[0])
2720 ev = VIA_LINE_EVENT;
2721 else
2722 ev = 0;
David Henningsson4e2d16d2012-10-08 15:44:14 +02002723 cb = ev ? via_jack_output_event : via_jack_powerstate_event;
2724
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002725 for (i = 0; i < cfg->line_outs; i++) {
2726 if (cfg->line_out_pins[i] &&
2727 is_jack_detectable(codec, cfg->line_out_pins[i]))
David Henningsson4e2d16d2012-10-08 15:44:14 +02002728 snd_hda_jack_detect_enable_callback(codec, cfg->line_out_pins[i],
2729 ev | VIA_JACK_EVENT, cb);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002730 }
2731
2732 for (i = 0; i < cfg->num_inputs; i++) {
2733 if (is_jack_detectable(codec, cfg->inputs[i].pin))
David Henningsson4e2d16d2012-10-08 15:44:14 +02002734 snd_hda_jack_detect_enable_callback(codec, cfg->inputs[i].pin,
2735 VIA_JACK_EVENT,
2736 via_jack_powerstate_event);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002737 }
2738}
2739
Takashi Iwai5d417622011-06-20 11:32:27 +02002740static int via_init(struct hda_codec *codec)
2741{
2742 struct via_spec *spec = codec->spec;
2743 int i;
2744
2745 for (i = 0; i < spec->num_iverbs; i++)
2746 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2747
Takashi Iwaie9d010c2012-02-01 10:33:23 +01002748 /* init power states */
2749 set_widgets_power_state(codec);
2750 __analog_low_current_mode(codec, true);
2751
Joseph Chanc577b8a2006-11-29 15:29:40 +01002752 via_auto_init_multi_out(codec);
2753 via_auto_init_hp_out(codec);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002754 via_auto_init_speaker_out(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002755 via_auto_init_analog_input(codec);
Takashi Iwai5d417622011-06-20 11:32:27 +02002756 via_auto_init_dig_outs(codec);
2757 via_auto_init_dig_in(codec);
Lydia Wang118909562011-03-23 17:57:34 +08002758
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002759 via_auto_init_unsol_event(codec);
2760
2761 via_hp_automute(codec);
Takashi Iwai187d3332011-11-24 16:33:09 +01002762 vt1708_update_hp_work(spec);
Lydia Wang25eaba22009-10-10 19:08:43 +08002763
Joseph Chanc577b8a2006-11-29 15:29:40 +01002764 return 0;
2765}
2766
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002767static void vt1708_update_hp_jack_state(struct work_struct *work)
2768{
2769 struct via_spec *spec = container_of(work, struct via_spec,
2770 vt1708_hp_work.work);
2771 if (spec->codec_type != VT1708)
2772 return;
Takashi Iwai1835a0f2011-10-27 22:12:46 +02002773 snd_hda_jack_set_dirty_all(spec->codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002774 /* if jack state toggled */
2775 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002776 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002777 spec->vt1708_hp_present ^= 1;
2778 via_hp_automute(spec->codec);
2779 }
Takashi Iwai187d3332011-11-24 16:33:09 +01002780 if (spec->vt1708_jack_detect)
2781 schedule_delayed_work(&spec->vt1708_hp_work,
2782 msecs_to_jiffies(100));
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002783}
2784
Takashi Iwai337b9d02009-07-07 18:18:59 +02002785static int get_mux_nids(struct hda_codec *codec)
2786{
2787 struct via_spec *spec = codec->spec;
2788 hda_nid_t nid, conn[8];
2789 unsigned int type;
2790 int i, n;
2791
2792 for (i = 0; i < spec->num_adc_nids; i++) {
2793 nid = spec->adc_nids[i];
2794 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002795 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002796 if (type == AC_WID_PIN)
2797 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002798 n = snd_hda_get_connections(codec, nid, conn,
2799 ARRAY_SIZE(conn));
2800 if (n <= 0)
2801 break;
2802 if (n > 1) {
2803 spec->mux_nids[i] = nid;
2804 break;
2805 }
2806 nid = conn[0];
2807 }
2808 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002809 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002810}
2811
Joseph Chanc577b8a2006-11-29 15:29:40 +01002812static int patch_vt1708(struct hda_codec *codec)
2813{
2814 struct via_spec *spec;
2815 int err;
2816
2817 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002818 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002819 if (spec == NULL)
2820 return -ENOMEM;
2821
Takashi Iwai620e2b22011-06-17 17:19:19 +02002822 spec->aa_mix_nid = 0x17;
2823
Takashi Iwai12daef62011-06-18 17:45:49 +02002824 /* Add HP and CD pin config connect bit re-config action */
2825 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2826 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2827
Joseph Chanc577b8a2006-11-29 15:29:40 +01002828 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002829 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002830 if (err < 0) {
2831 via_free(codec);
2832 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002833 }
2834
Takashi Iwai12daef62011-06-18 17:45:49 +02002835 /* add jack detect on/off control */
2836 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2837 return -ENOMEM;
2838
Takashi Iwaibc9b5622008-05-23 17:50:27 +02002839 /* disable 32bit format on VT1708 */
2840 if (codec->vendor_id == 0x11061708)
2841 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002842
Lydia Wange322a362011-06-29 13:52:02 +08002843 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2844
Joseph Chanc577b8a2006-11-29 15:29:40 +01002845 codec->patch_ops = via_patch_ops;
2846
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002847 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002848 return 0;
2849}
2850
Takashi Iwaiddd304d2011-06-21 16:33:55 +02002851static int patch_vt1709(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002852{
2853 struct via_spec *spec;
2854 int err;
2855
2856 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002857 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002858 if (spec == NULL)
2859 return -ENOMEM;
2860
Takashi Iwai620e2b22011-06-17 17:19:19 +02002861 spec->aa_mix_nid = 0x18;
2862
Takashi Iwai12daef62011-06-18 17:45:49 +02002863 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002864 if (err < 0) {
2865 via_free(codec);
2866 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002867 }
2868
Joseph Chanc577b8a2006-11-29 15:29:40 +01002869 codec->patch_ops = via_patch_ops;
2870
Josepch Chanf7278fd2007-12-13 16:40:40 +01002871 return 0;
2872}
2873
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002874static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2875{
2876 struct via_spec *spec = codec->spec;
2877 int imux_is_smixer;
2878 unsigned int parm;
2879 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +08002880 if ((spec->codec_type != VT1708B_4CH) &&
2881 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002882 is_8ch = 1;
2883
2884 /* SW0 (17h) = stereo mixer */
2885 imux_is_smixer =
2886 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2887 == ((spec->codec_type == VT1708S) ? 5 : 0));
2888 /* inputs */
2889 /* PW 1/2/5 (1ah/1bh/1eh) */
2890 parm = AC_PWRST_D3;
2891 set_pin_power_state(codec, 0x1a, &parm);
2892 set_pin_power_state(codec, 0x1b, &parm);
2893 set_pin_power_state(codec, 0x1e, &parm);
2894 if (imux_is_smixer)
2895 parm = AC_PWRST_D0;
2896 /* SW0 (17h), AIW 0/1 (13h/14h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01002897 update_power_state(codec, 0x17, parm);
2898 update_power_state(codec, 0x13, parm);
2899 update_power_state(codec, 0x14, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002900
2901 /* outputs */
2902 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2903 parm = AC_PWRST_D3;
2904 set_pin_power_state(codec, 0x19, &parm);
2905 if (spec->smart51_enabled)
2906 set_pin_power_state(codec, 0x1b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01002907 update_power_state(codec, 0x18, parm);
2908 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002909
2910 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2911 if (is_8ch) {
2912 parm = AC_PWRST_D3;
2913 set_pin_power_state(codec, 0x22, &parm);
2914 if (spec->smart51_enabled)
2915 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01002916 update_power_state(codec, 0x26, parm);
2917 update_power_state(codec, 0x24, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002918 } else if (codec->vendor_id == 0x11064397) {
2919 /* PW7(23h), SW2(27h), AOW2(25h) */
2920 parm = AC_PWRST_D3;
2921 set_pin_power_state(codec, 0x23, &parm);
2922 if (spec->smart51_enabled)
2923 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01002924 update_power_state(codec, 0x27, parm);
2925 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002926 }
2927
2928 /* PW 3/4/7 (1ch/1dh/23h) */
2929 parm = AC_PWRST_D3;
2930 /* force to D0 for internal Speaker */
2931 set_pin_power_state(codec, 0x1c, &parm);
2932 set_pin_power_state(codec, 0x1d, &parm);
2933 if (is_8ch)
2934 set_pin_power_state(codec, 0x23, &parm);
2935
2936 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01002937 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
2938 update_power_state(codec, 0x10, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002939 if (is_8ch) {
Takashi Iwai054d8672012-01-24 12:25:50 +01002940 update_power_state(codec, 0x25, parm);
2941 update_power_state(codec, 0x27, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002942 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
Takashi Iwai054d8672012-01-24 12:25:50 +01002943 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002944}
2945
Lydia Wang518bf3b2009-10-10 19:07:29 +08002946static int patch_vt1708S(struct hda_codec *codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +02002947static int patch_vt1708B(struct hda_codec *codec)
Josepch Chanf7278fd2007-12-13 16:40:40 +01002948{
2949 struct via_spec *spec;
2950 int err;
2951
Lydia Wang518bf3b2009-10-10 19:07:29 +08002952 if (get_codec_type(codec) == VT1708BCE)
2953 return patch_vt1708S(codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +02002954
Josepch Chanf7278fd2007-12-13 16:40:40 +01002955 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002956 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002957 if (spec == NULL)
2958 return -ENOMEM;
2959
Takashi Iwai620e2b22011-06-17 17:19:19 +02002960 spec->aa_mix_nid = 0x16;
2961
Josepch Chanf7278fd2007-12-13 16:40:40 +01002962 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002963 err = via_parse_auto_config(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002964 if (err < 0) {
2965 via_free(codec);
2966 return err;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002967 }
2968
Josepch Chanf7278fd2007-12-13 16:40:40 +01002969 codec->patch_ops = via_patch_ops;
2970
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002971 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2972
Josepch Chanf7278fd2007-12-13 16:40:40 +01002973 return 0;
2974}
2975
Harald Welted949cac2008-09-09 15:56:01 +08002976/* Patch for VT1708S */
Takashi Iwai096a8852011-06-20 12:09:02 +02002977static const struct hda_verb vt1708S_init_verbs[] = {
Harald Welted7426322008-09-15 22:43:23 +08002978 /* Enable Mic Boost Volume backdoor */
2979 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08002980 /* don't bybass mixer */
2981 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08002982 { }
2983};
2984
Takashi Iwai9da29272009-05-07 16:31:14 +02002985/* fill out digital output widgets; one for master and one for slave outputs */
2986static void fill_dig_outs(struct hda_codec *codec)
2987{
2988 struct via_spec *spec = codec->spec;
2989 int i;
2990
2991 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2992 hda_nid_t nid;
2993 int conn;
2994
2995 nid = spec->autocfg.dig_out_pins[i];
2996 if (!nid)
2997 continue;
2998 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2999 if (conn < 1)
3000 continue;
3001 if (!spec->multiout.dig_out_nid)
3002 spec->multiout.dig_out_nid = nid;
3003 else {
3004 spec->slave_dig_outs[0] = nid;
3005 break; /* at most two dig outs */
3006 }
3007 }
3008}
3009
Takashi Iwai12daef62011-06-18 17:45:49 +02003010static void fill_dig_in(struct hda_codec *codec)
Harald Welted949cac2008-09-09 15:56:01 +08003011{
3012 struct via_spec *spec = codec->spec;
Takashi Iwai12daef62011-06-18 17:45:49 +02003013 hda_nid_t dig_nid;
3014 int i, err;
Harald Welted949cac2008-09-09 15:56:01 +08003015
Takashi Iwai12daef62011-06-18 17:45:49 +02003016 if (!spec->autocfg.dig_in_pin)
3017 return;
Harald Welted949cac2008-09-09 15:56:01 +08003018
Takashi Iwai12daef62011-06-18 17:45:49 +02003019 dig_nid = codec->start_nid;
3020 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3021 unsigned int wcaps = get_wcaps(codec, dig_nid);
3022 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3023 continue;
3024 if (!(wcaps & AC_WCAP_DIGITAL))
3025 continue;
3026 if (!(wcaps & AC_WCAP_CONN_LIST))
3027 continue;
3028 err = get_connection_index(codec, dig_nid,
3029 spec->autocfg.dig_in_pin);
3030 if (err >= 0) {
3031 spec->dig_in_nid = dig_nid;
3032 break;
3033 }
3034 }
Harald Welted949cac2008-09-09 15:56:01 +08003035}
3036
Lydia Wang6369bcf2009-10-10 19:08:31 +08003037static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3038 int offset, int num_steps, int step_size)
3039{
3040 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3041 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3042 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3043 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3044 (0 << AC_AMPCAP_MUTE_SHIFT));
3045}
3046
Harald Welted949cac2008-09-09 15:56:01 +08003047static int patch_vt1708S(struct hda_codec *codec)
3048{
3049 struct via_spec *spec;
3050 int err;
3051
3052 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003053 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003054 if (spec == NULL)
3055 return -ENOMEM;
3056
Takashi Iwai620e2b22011-06-17 17:19:19 +02003057 spec->aa_mix_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003058 override_mic_boost(codec, 0x1a, 0, 3, 40);
3059 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003060
Harald Welted949cac2008-09-09 15:56:01 +08003061 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003062 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003063 if (err < 0) {
3064 via_free(codec);
3065 return err;
Harald Welted949cac2008-09-09 15:56:01 +08003066 }
3067
Takashi Iwai096a8852011-06-20 12:09:02 +02003068 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003069
Harald Welted949cac2008-09-09 15:56:01 +08003070 codec->patch_ops = via_patch_ops;
3071
Lydia Wang518bf3b2009-10-10 19:07:29 +08003072 /* correct names for VT1708BCE */
3073 if (get_codec_type(codec) == VT1708BCE) {
3074 kfree(codec->chip_name);
3075 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3076 snprintf(codec->bus->card->mixername,
3077 sizeof(codec->bus->card->mixername),
3078 "%s %s", codec->vendor_name, codec->chip_name);
Lydia Wang970f6302011-03-22 16:25:56 +08003079 }
Lydia Wangbc92df72011-03-23 17:56:05 +08003080 /* correct names for VT1705 */
3081 if (codec->vendor_id == 0x11064397) {
3082 kfree(codec->chip_name);
3083 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3084 snprintf(codec->bus->card->mixername,
3085 sizeof(codec->bus->card->mixername),
3086 "%s %s", codec->vendor_name, codec->chip_name);
3087 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003088 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +08003089 return 0;
3090}
3091
3092/* Patch for VT1702 */
3093
Takashi Iwai096a8852011-06-20 12:09:02 +02003094static const struct hda_verb vt1702_init_verbs[] = {
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003095 /* mixer enable */
3096 {0x1, 0xF88, 0x3},
3097 /* GPIO 0~2 */
3098 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08003099 { }
3100};
3101
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003102static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3103{
3104 int imux_is_smixer =
3105 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3106 unsigned int parm;
3107 /* inputs */
3108 /* PW 1/2/5 (14h/15h/18h) */
3109 parm = AC_PWRST_D3;
3110 set_pin_power_state(codec, 0x14, &parm);
3111 set_pin_power_state(codec, 0x15, &parm);
3112 set_pin_power_state(codec, 0x18, &parm);
3113 if (imux_is_smixer)
3114 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3115 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003116 update_power_state(codec, 0x13, parm);
3117 update_power_state(codec, 0x12, parm);
3118 update_power_state(codec, 0x1f, parm);
3119 update_power_state(codec, 0x20, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003120
3121 /* outputs */
3122 /* PW 3/4 (16h/17h) */
3123 parm = AC_PWRST_D3;
3124 set_pin_power_state(codec, 0x17, &parm);
3125 set_pin_power_state(codec, 0x16, &parm);
3126 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003127 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
3128 update_power_state(codec, 0x10, parm);
3129 update_power_state(codec, 0x1d, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003130}
3131
Harald Welted949cac2008-09-09 15:56:01 +08003132static int patch_vt1702(struct hda_codec *codec)
3133{
3134 struct via_spec *spec;
3135 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003136
3137 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003138 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003139 if (spec == NULL)
3140 return -ENOMEM;
3141
Takashi Iwai620e2b22011-06-17 17:19:19 +02003142 spec->aa_mix_nid = 0x1a;
3143
Takashi Iwai12daef62011-06-18 17:45:49 +02003144 /* limit AA path volume to 0 dB */
3145 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3146 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3147 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3148 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3149 (1 << AC_AMPCAP_MUTE_SHIFT));
3150
Harald Welted949cac2008-09-09 15:56:01 +08003151 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003152 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003153 if (err < 0) {
3154 via_free(codec);
3155 return err;
Harald Welted949cac2008-09-09 15:56:01 +08003156 }
3157
Takashi Iwai096a8852011-06-20 12:09:02 +02003158 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003159
Harald Welted949cac2008-09-09 15:56:01 +08003160 codec->patch_ops = via_patch_ops;
3161
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003162 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08003163 return 0;
3164}
3165
Lydia Wangeb7188c2009-10-10 19:08:34 +08003166/* Patch for VT1718S */
3167
Takashi Iwai096a8852011-06-20 12:09:02 +02003168static const struct hda_verb vt1718S_init_verbs[] = {
Lydia Wang4ab2d532011-03-24 12:42:03 +08003169 /* Enable MW0 adjust Gain 5 */
3170 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08003171 /* Enable Boost Volume backdoor */
3172 {0x1, 0xf88, 0x8},
Takashi Iwai5d417622011-06-20 11:32:27 +02003173
Lydia Wangeb7188c2009-10-10 19:08:34 +08003174 { }
3175};
3176
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003177static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3178{
3179 struct via_spec *spec = codec->spec;
3180 int imux_is_smixer;
Takashi Iwai61625522012-07-25 13:54:55 +02003181 unsigned int parm, parm2;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003182 /* MUX6 (1eh) = stereo mixer */
3183 imux_is_smixer =
3184 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3185 /* inputs */
3186 /* PW 5/6/7 (29h/2ah/2bh) */
3187 parm = AC_PWRST_D3;
3188 set_pin_power_state(codec, 0x29, &parm);
3189 set_pin_power_state(codec, 0x2a, &parm);
3190 set_pin_power_state(codec, 0x2b, &parm);
3191 if (imux_is_smixer)
3192 parm = AC_PWRST_D0;
3193 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003194 update_power_state(codec, 0x1e, parm);
3195 update_power_state(codec, 0x1f, parm);
3196 update_power_state(codec, 0x10, parm);
3197 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003198
3199 /* outputs */
3200 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3201 parm = AC_PWRST_D3;
3202 set_pin_power_state(codec, 0x27, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003203 update_power_state(codec, 0x1a, parm);
Takashi Iwai61625522012-07-25 13:54:55 +02003204 parm2 = parm; /* for pin 0x0b */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003205
3206 /* PW2 (26h), AOW2 (ah) */
3207 parm = AC_PWRST_D3;
3208 set_pin_power_state(codec, 0x26, &parm);
3209 if (spec->smart51_enabled)
3210 set_pin_power_state(codec, 0x2b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003211 update_power_state(codec, 0xa, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003212
3213 /* PW0 (24h), AOW0 (8h) */
3214 parm = AC_PWRST_D3;
3215 set_pin_power_state(codec, 0x24, &parm);
3216 if (!spec->hp_independent_mode) /* check for redirected HP */
3217 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003218 update_power_state(codec, 0x8, parm);
Takashi Iwai61625522012-07-25 13:54:55 +02003219 if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3)
3220 parm = parm2;
3221 update_power_state(codec, 0xb, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003222 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003223 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003224
3225 /* PW1 (25h), AOW1 (9h) */
3226 parm = AC_PWRST_D3;
3227 set_pin_power_state(codec, 0x25, &parm);
3228 if (spec->smart51_enabled)
3229 set_pin_power_state(codec, 0x2a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003230 update_power_state(codec, 0x9, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003231
3232 if (spec->hp_independent_mode) {
3233 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3234 parm = AC_PWRST_D3;
3235 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003236 update_power_state(codec, 0x1b, parm);
3237 update_power_state(codec, 0x34, parm);
3238 update_power_state(codec, 0xc, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003239 }
3240}
3241
Takashi Iwai30b45032011-07-11 17:05:04 +02003242/* Add a connection to the primary DAC from AA-mixer for some codecs
3243 * This isn't listed from the raw info, but the chip has a secret connection.
3244 */
3245static int add_secret_dac_path(struct hda_codec *codec)
3246{
3247 struct via_spec *spec = codec->spec;
3248 int i, nums;
3249 hda_nid_t conn[8];
3250 hda_nid_t nid;
3251
3252 if (!spec->aa_mix_nid)
3253 return 0;
3254 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
3255 ARRAY_SIZE(conn) - 1);
3256 for (i = 0; i < nums; i++) {
3257 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
3258 return 0;
3259 }
3260
3261 /* find the primary DAC and add to the connection list */
3262 nid = codec->start_nid;
3263 for (i = 0; i < codec->num_nodes; i++, nid++) {
3264 unsigned int caps = get_wcaps(codec, nid);
3265 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
3266 !(caps & AC_WCAP_DIGITAL)) {
3267 conn[nums++] = nid;
3268 return snd_hda_override_conn_list(codec,
3269 spec->aa_mix_nid,
3270 nums, conn);
3271 }
3272 }
3273 return 0;
3274}
3275
3276
Lydia Wangeb7188c2009-10-10 19:08:34 +08003277static int patch_vt1718S(struct hda_codec *codec)
3278{
3279 struct via_spec *spec;
3280 int err;
3281
3282 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003283 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003284 if (spec == NULL)
3285 return -ENOMEM;
3286
Takashi Iwai620e2b22011-06-17 17:19:19 +02003287 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003288 override_mic_boost(codec, 0x2b, 0, 3, 40);
3289 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02003290 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003291
Lydia Wangeb7188c2009-10-10 19:08:34 +08003292 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003293 err = via_parse_auto_config(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003294 if (err < 0) {
3295 via_free(codec);
3296 return err;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003297 }
3298
Takashi Iwai096a8852011-06-20 12:09:02 +02003299 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003300
Lydia Wangeb7188c2009-10-10 19:08:34 +08003301 codec->patch_ops = via_patch_ops;
3302
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003303 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3304
Lydia Wangeb7188c2009-10-10 19:08:34 +08003305 return 0;
3306}
Lydia Wangf3db4232009-10-10 19:08:41 +08003307
3308/* Patch for VT1716S */
3309
3310static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3311 struct snd_ctl_elem_info *uinfo)
3312{
3313 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3314 uinfo->count = 1;
3315 uinfo->value.integer.min = 0;
3316 uinfo->value.integer.max = 1;
3317 return 0;
3318}
3319
3320static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3321 struct snd_ctl_elem_value *ucontrol)
3322{
3323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3324 int index = 0;
3325
3326 index = snd_hda_codec_read(codec, 0x26, 0,
3327 AC_VERB_GET_CONNECT_SEL, 0);
3328 if (index != -1)
3329 *ucontrol->value.integer.value = index;
3330
3331 return 0;
3332}
3333
3334static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3335 struct snd_ctl_elem_value *ucontrol)
3336{
3337 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3338 struct via_spec *spec = codec->spec;
3339 int index = *ucontrol->value.integer.value;
3340
3341 snd_hda_codec_write(codec, 0x26, 0,
3342 AC_VERB_SET_CONNECT_SEL, index);
3343 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003344 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003345 return 1;
3346}
3347
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003348static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003349 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3350 {
3351 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3352 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003353 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08003354 .count = 1,
3355 .info = vt1716s_dmic_info,
3356 .get = vt1716s_dmic_get,
3357 .put = vt1716s_dmic_put,
3358 },
3359 {} /* end */
3360};
3361
3362
3363/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003364static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003365 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3366 { } /* end */
3367};
3368
Takashi Iwai096a8852011-06-20 12:09:02 +02003369static const struct hda_verb vt1716S_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003370 /* Enable Boost Volume backdoor */
3371 {0x1, 0xf8a, 0x80},
3372 /* don't bybass mixer */
3373 {0x1, 0xf88, 0xc0},
3374 /* Enable mono output */
3375 {0x1, 0xf90, 0x08},
3376 { }
3377};
3378
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003379static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3380{
3381 struct via_spec *spec = codec->spec;
3382 int imux_is_smixer;
3383 unsigned int parm;
3384 unsigned int mono_out, present;
3385 /* SW0 (17h) = stereo mixer */
3386 imux_is_smixer =
3387 (snd_hda_codec_read(codec, 0x17, 0,
3388 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3389 /* inputs */
3390 /* PW 1/2/5 (1ah/1bh/1eh) */
3391 parm = AC_PWRST_D3;
3392 set_pin_power_state(codec, 0x1a, &parm);
3393 set_pin_power_state(codec, 0x1b, &parm);
3394 set_pin_power_state(codec, 0x1e, &parm);
3395 if (imux_is_smixer)
3396 parm = AC_PWRST_D0;
3397 /* SW0 (17h), AIW0(13h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003398 update_power_state(codec, 0x17, parm);
3399 update_power_state(codec, 0x13, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003400
3401 parm = AC_PWRST_D3;
3402 set_pin_power_state(codec, 0x1e, &parm);
3403 /* PW11 (22h) */
3404 if (spec->dmic_enabled)
3405 set_pin_power_state(codec, 0x22, &parm);
3406 else
Takashi Iwai054d8672012-01-24 12:25:50 +01003407 update_power_state(codec, 0x22, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003408
3409 /* SW2(26h), AIW1(14h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003410 update_power_state(codec, 0x26, parm);
3411 update_power_state(codec, 0x14, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003412
3413 /* outputs */
3414 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3415 parm = AC_PWRST_D3;
3416 set_pin_power_state(codec, 0x19, &parm);
3417 /* Smart 5.1 PW2(1bh) */
3418 if (spec->smart51_enabled)
3419 set_pin_power_state(codec, 0x1b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003420 update_power_state(codec, 0x18, parm);
3421 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003422
3423 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3424 parm = AC_PWRST_D3;
3425 set_pin_power_state(codec, 0x23, &parm);
3426 /* Smart 5.1 PW1(1ah) */
3427 if (spec->smart51_enabled)
3428 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003429 update_power_state(codec, 0x27, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003430
3431 /* Smart 5.1 PW5(1eh) */
3432 if (spec->smart51_enabled)
3433 set_pin_power_state(codec, 0x1e, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003434 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003435
3436 /* Mono out */
3437 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3438 present = snd_hda_jack_detect(codec, 0x1c);
3439
3440 if (present)
3441 mono_out = 0;
3442 else {
3443 present = snd_hda_jack_detect(codec, 0x1d);
3444 if (!spec->hp_independent_mode && present)
3445 mono_out = 0;
3446 else
3447 mono_out = 1;
3448 }
3449 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
Takashi Iwai054d8672012-01-24 12:25:50 +01003450 update_power_state(codec, 0x28, parm);
3451 update_power_state(codec, 0x29, parm);
3452 update_power_state(codec, 0x2a, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003453
3454 /* PW 3/4 (1ch/1dh) */
3455 parm = AC_PWRST_D3;
3456 set_pin_power_state(codec, 0x1c, &parm);
3457 set_pin_power_state(codec, 0x1d, &parm);
3458 /* HP Independent Mode, power on AOW3 */
3459 if (spec->hp_independent_mode)
Takashi Iwai054d8672012-01-24 12:25:50 +01003460 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003461
3462 /* force to D0 for internal Speaker */
3463 /* MW0 (16h), AOW0 (10h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003464 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
3465 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003466}
3467
Lydia Wangf3db4232009-10-10 19:08:41 +08003468static int patch_vt1716S(struct hda_codec *codec)
3469{
3470 struct via_spec *spec;
3471 int err;
3472
3473 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003474 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003475 if (spec == NULL)
3476 return -ENOMEM;
3477
Takashi Iwai620e2b22011-06-17 17:19:19 +02003478 spec->aa_mix_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003479 override_mic_boost(codec, 0x1a, 0, 3, 40);
3480 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003481
Lydia Wangf3db4232009-10-10 19:08:41 +08003482 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003483 err = via_parse_auto_config(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003484 if (err < 0) {
3485 via_free(codec);
3486 return err;
Lydia Wangf3db4232009-10-10 19:08:41 +08003487 }
3488
Takashi Iwai096a8852011-06-20 12:09:02 +02003489 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
Lydia Wangf3db4232009-10-10 19:08:41 +08003490
Lydia Wangf3db4232009-10-10 19:08:41 +08003491 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3492 spec->num_mixers++;
3493
3494 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3495
3496 codec->patch_ops = via_patch_ops;
3497
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003498 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08003499 return 0;
3500}
Lydia Wang25eaba22009-10-10 19:08:43 +08003501
3502/* for vt2002P */
3503
Takashi Iwai096a8852011-06-20 12:09:02 +02003504static const struct hda_verb vt2002P_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08003505 /* Class-D speaker related verbs */
3506 {0x1, 0xfe0, 0x4},
3507 {0x1, 0xfe9, 0x80},
3508 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08003509 /* Enable Boost Volume backdoor */
3510 {0x1, 0xfb9, 0x24},
Lydia Wang25eaba22009-10-10 19:08:43 +08003511 /* Enable AOW0 to MW9 */
3512 {0x1, 0xfb8, 0x88},
3513 { }
3514};
Takashi Iwai4a918ff2011-06-20 12:39:26 +02003515
Takashi Iwai096a8852011-06-20 12:09:02 +02003516static const struct hda_verb vt1802_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08003517 /* Enable Boost Volume backdoor */
3518 {0x1, 0xfb9, 0x24},
Lydia Wang118909562011-03-23 17:57:34 +08003519 /* Enable AOW0 to MW9 */
3520 {0x1, 0xfb8, 0x88},
3521 { }
3522};
Lydia Wang25eaba22009-10-10 19:08:43 +08003523
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003524static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3525{
3526 struct via_spec *spec = codec->spec;
3527 int imux_is_smixer;
3528 unsigned int parm;
3529 unsigned int present;
3530 /* MUX9 (1eh) = stereo mixer */
3531 imux_is_smixer =
3532 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3533 /* inputs */
3534 /* PW 5/6/7 (29h/2ah/2bh) */
3535 parm = AC_PWRST_D3;
3536 set_pin_power_state(codec, 0x29, &parm);
3537 set_pin_power_state(codec, 0x2a, &parm);
3538 set_pin_power_state(codec, 0x2b, &parm);
3539 parm = AC_PWRST_D0;
3540 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003541 update_power_state(codec, 0x1e, parm);
3542 update_power_state(codec, 0x1f, parm);
3543 update_power_state(codec, 0x10, parm);
3544 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003545
3546 /* outputs */
3547 /* AOW0 (8h)*/
Takashi Iwai054d8672012-01-24 12:25:50 +01003548 update_power_state(codec, 0x8, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003549
Lydia Wang118909562011-03-23 17:57:34 +08003550 if (spec->codec_type == VT1802) {
3551 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3552 parm = AC_PWRST_D3;
3553 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003554 update_power_state(codec, 0x18, parm);
3555 update_power_state(codec, 0x38, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003556 } else {
3557 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3558 parm = AC_PWRST_D3;
3559 set_pin_power_state(codec, 0x26, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003560 update_power_state(codec, 0x1c, parm);
3561 update_power_state(codec, 0x37, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003562 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003563
Lydia Wang118909562011-03-23 17:57:34 +08003564 if (spec->codec_type == VT1802) {
3565 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3566 parm = AC_PWRST_D3;
3567 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003568 update_power_state(codec, 0x15, parm);
3569 update_power_state(codec, 0x35, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003570 } else {
3571 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3572 parm = AC_PWRST_D3;
3573 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003574 update_power_state(codec, 0x19, parm);
3575 update_power_state(codec, 0x35, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003576 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003577
3578 if (spec->hp_independent_mode)
Takashi Iwai054d8672012-01-24 12:25:50 +01003579 update_power_state(codec, 0x9, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003580
3581 /* Class-D */
3582 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3583 present = snd_hda_jack_detect(codec, 0x25);
3584
3585 parm = AC_PWRST_D3;
3586 set_pin_power_state(codec, 0x24, &parm);
3587 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08003588 if (spec->codec_type == VT1802)
Takashi Iwai054d8672012-01-24 12:25:50 +01003589 update_power_state(codec, 0x14, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003590 else
Takashi Iwai054d8672012-01-24 12:25:50 +01003591 update_power_state(codec, 0x18, parm);
3592 update_power_state(codec, 0x34, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003593
3594 /* Mono Out */
3595 present = snd_hda_jack_detect(codec, 0x26);
3596
3597 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08003598 if (spec->codec_type == VT1802) {
3599 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003600 update_power_state(codec, 0x33, parm);
3601 update_power_state(codec, 0x1c, parm);
3602 update_power_state(codec, 0x3c, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003603 } else {
3604 /* PW15 (31h), MW8(17h), MUX8(3bh) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003605 update_power_state(codec, 0x31, parm);
3606 update_power_state(codec, 0x17, parm);
3607 update_power_state(codec, 0x3b, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003608 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003609 /* MW9 (21h) */
3610 if (imux_is_smixer || !is_aa_path_mute(codec))
Takashi Iwai054d8672012-01-24 12:25:50 +01003611 update_power_state(codec, 0x21, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003612 else
Takashi Iwai054d8672012-01-24 12:25:50 +01003613 update_power_state(codec, 0x21, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003614}
Lydia Wang25eaba22009-10-10 19:08:43 +08003615
David Henningsson4b527b62012-09-18 14:26:59 +02003616/*
3617 * pin fix-up
3618 */
3619enum {
3620 VIA_FIXUP_INTMIC_BOOST,
Takashi Iwaid5266122012-11-07 10:40:36 +01003621 VIA_FIXUP_ASUS_G75,
David Henningsson4b527b62012-09-18 14:26:59 +02003622};
3623
3624static void via_fixup_intmic_boost(struct hda_codec *codec,
3625 const struct hda_fixup *fix, int action)
3626{
3627 if (action == HDA_FIXUP_ACT_PRE_PROBE)
3628 override_mic_boost(codec, 0x30, 0, 2, 40);
3629}
3630
3631static const struct hda_fixup via_fixups[] = {
3632 [VIA_FIXUP_INTMIC_BOOST] = {
3633 .type = HDA_FIXUP_FUNC,
3634 .v.func = via_fixup_intmic_boost,
3635 },
Takashi Iwaid5266122012-11-07 10:40:36 +01003636 [VIA_FIXUP_ASUS_G75] = {
3637 .type = HDA_FIXUP_PINS,
3638 .v.pins = (const struct hda_pintbl[]) {
3639 /* set 0x24 and 0x33 as speakers */
3640 { 0x24, 0x991301f0 },
3641 { 0x33, 0x991301f1 }, /* subwoofer */
3642 { }
3643 }
3644 },
David Henningsson4b527b62012-09-18 14:26:59 +02003645};
3646
3647static const struct snd_pci_quirk vt2002p_fixups[] = {
Takashi Iwaid5266122012-11-07 10:40:36 +01003648 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
David Henningsson4b527b62012-09-18 14:26:59 +02003649 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
3650 {}
3651};
3652
Takashi Iwaief4da452012-11-07 10:37:48 +01003653/* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
3654 * Replace this with mixer NID 0x1c
3655 */
3656static void fix_vt1802_connections(struct hda_codec *codec)
3657{
3658 static hda_nid_t conn_24[] = { 0x14, 0x1c };
3659 static hda_nid_t conn_33[] = { 0x1c };
3660
3661 snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
3662 snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
3663}
3664
Lydia Wang25eaba22009-10-10 19:08:43 +08003665/* patch for vt2002P */
3666static int patch_vt2002P(struct hda_codec *codec)
3667{
3668 struct via_spec *spec;
3669 int err;
3670
3671 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003672 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08003673 if (spec == NULL)
3674 return -ENOMEM;
3675
Takashi Iwai620e2b22011-06-17 17:19:19 +02003676 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003677 override_mic_boost(codec, 0x2b, 0, 3, 40);
3678 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwaief4da452012-11-07 10:37:48 +01003679 if (spec->codec_type == VT1802)
3680 fix_vt1802_connections(codec);
Takashi Iwai30b45032011-07-11 17:05:04 +02003681 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003682
David Henningsson4b527b62012-09-18 14:26:59 +02003683 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
3684 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3685
Lydia Wang25eaba22009-10-10 19:08:43 +08003686 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003687 err = via_parse_auto_config(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08003688 if (err < 0) {
3689 via_free(codec);
3690 return err;
Lydia Wang25eaba22009-10-10 19:08:43 +08003691 }
3692
Lydia Wang118909562011-03-23 17:57:34 +08003693 if (spec->codec_type == VT1802)
Takashi Iwai4a918ff2011-06-20 12:39:26 +02003694 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08003695 else
Takashi Iwai4a918ff2011-06-20 12:39:26 +02003696 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08003697
Lydia Wang25eaba22009-10-10 19:08:43 +08003698 codec->patch_ops = via_patch_ops;
3699
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003700 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08003701 return 0;
3702}
Lydia Wangab6734e2009-10-10 19:08:46 +08003703
3704/* for vt1812 */
3705
Takashi Iwai096a8852011-06-20 12:09:02 +02003706static const struct hda_verb vt1812_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08003707 /* Enable Boost Volume backdoor */
3708 {0x1, 0xfb9, 0x24},
Lydia Wangab6734e2009-10-10 19:08:46 +08003709 /* Enable AOW0 to MW9 */
3710 {0x1, 0xfb8, 0xa8},
3711 { }
3712};
3713
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003714static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3715{
3716 struct via_spec *spec = codec->spec;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003717 unsigned int parm;
3718 unsigned int present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003719 /* inputs */
3720 /* PW 5/6/7 (29h/2ah/2bh) */
3721 parm = AC_PWRST_D3;
3722 set_pin_power_state(codec, 0x29, &parm);
3723 set_pin_power_state(codec, 0x2a, &parm);
3724 set_pin_power_state(codec, 0x2b, &parm);
3725 parm = AC_PWRST_D0;
3726 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003727 update_power_state(codec, 0x1e, parm);
3728 update_power_state(codec, 0x1f, parm);
3729 update_power_state(codec, 0x10, parm);
3730 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003731
3732 /* outputs */
3733 /* AOW0 (8h)*/
Takashi Iwai054d8672012-01-24 12:25:50 +01003734 update_power_state(codec, 0x8, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003735
3736 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3737 parm = AC_PWRST_D3;
3738 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003739 update_power_state(codec, 0x18, parm);
3740 update_power_state(codec, 0x38, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003741
3742 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3743 parm = AC_PWRST_D3;
3744 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003745 update_power_state(codec, 0x15, parm);
3746 update_power_state(codec, 0x35, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003747 if (spec->hp_independent_mode)
Takashi Iwai054d8672012-01-24 12:25:50 +01003748 update_power_state(codec, 0x9, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003749
3750 /* Internal Speaker */
3751 /* PW0 (24h), MW0(14h), MUX0(34h) */
3752 present = snd_hda_jack_detect(codec, 0x25);
3753
3754 parm = AC_PWRST_D3;
3755 set_pin_power_state(codec, 0x24, &parm);
3756 if (present) {
Takashi Iwai054d8672012-01-24 12:25:50 +01003757 update_power_state(codec, 0x14, AC_PWRST_D3);
3758 update_power_state(codec, 0x34, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003759 } else {
Takashi Iwai054d8672012-01-24 12:25:50 +01003760 update_power_state(codec, 0x14, AC_PWRST_D0);
3761 update_power_state(codec, 0x34, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003762 }
3763
3764
3765 /* Mono Out */
3766 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3767 present = snd_hda_jack_detect(codec, 0x28);
3768
3769 parm = AC_PWRST_D3;
3770 set_pin_power_state(codec, 0x31, &parm);
3771 if (present) {
Takashi Iwai054d8672012-01-24 12:25:50 +01003772 update_power_state(codec, 0x1c, AC_PWRST_D3);
3773 update_power_state(codec, 0x3c, AC_PWRST_D3);
3774 update_power_state(codec, 0x3e, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003775 } else {
Takashi Iwai054d8672012-01-24 12:25:50 +01003776 update_power_state(codec, 0x1c, AC_PWRST_D0);
3777 update_power_state(codec, 0x3c, AC_PWRST_D0);
3778 update_power_state(codec, 0x3e, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003779 }
3780
3781 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3782 parm = AC_PWRST_D3;
3783 set_pin_power_state(codec, 0x33, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003784 update_power_state(codec, 0x1d, parm);
3785 update_power_state(codec, 0x3d, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003786
3787}
Lydia Wangab6734e2009-10-10 19:08:46 +08003788
3789/* patch for vt1812 */
3790static int patch_vt1812(struct hda_codec *codec)
3791{
3792 struct via_spec *spec;
3793 int err;
3794
3795 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003796 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08003797 if (spec == NULL)
3798 return -ENOMEM;
3799
Takashi Iwai620e2b22011-06-17 17:19:19 +02003800 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003801 override_mic_boost(codec, 0x2b, 0, 3, 40);
3802 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02003803 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003804
Lydia Wangab6734e2009-10-10 19:08:46 +08003805 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003806 err = via_parse_auto_config(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08003807 if (err < 0) {
3808 via_free(codec);
3809 return err;
Lydia Wangab6734e2009-10-10 19:08:46 +08003810 }
3811
Takashi Iwai096a8852011-06-20 12:09:02 +02003812 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
Lydia Wangab6734e2009-10-10 19:08:46 +08003813
Lydia Wangab6734e2009-10-10 19:08:46 +08003814 codec->patch_ops = via_patch_ops;
3815
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003816 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08003817 return 0;
3818}
3819
Joseph Chanc577b8a2006-11-29 15:29:40 +01003820/*
3821 * patch entries
3822 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003823static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01003824 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3825 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3826 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3827 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3828 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003829 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003830 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003831 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003832 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003833 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003834 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003835 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003836 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003837 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003838 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003839 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003840 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003841 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003842 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003843 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003844 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003845 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003846 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003847 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003848 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003849 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003850 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003851 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003852 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003853 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003854 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003855 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003856 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003857 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003858 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003859 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003860 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003861 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003862 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003863 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003864 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003865 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003866 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003867 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08003868 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08003869 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003870 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003871 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003872 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003873 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003874 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003875 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003876 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003877 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003878 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003879 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003880 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003881 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003882 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003883 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003884 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003885 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003886 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003887 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003888 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003889 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003890 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003891 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08003892 { .id = 0x11060428, .name = "VT1718S",
3893 .patch = patch_vt1718S},
3894 { .id = 0x11064428, .name = "VT1718S",
3895 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08003896 { .id = 0x11060441, .name = "VT2020",
3897 .patch = patch_vt1718S},
3898 { .id = 0x11064441, .name = "VT1828S",
3899 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08003900 { .id = 0x11060433, .name = "VT1716S",
3901 .patch = patch_vt1716S},
3902 { .id = 0x1106a721, .name = "VT1716S",
3903 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08003904 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3905 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08003906 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08003907 { .id = 0x11060440, .name = "VT1818S",
3908 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08003909 { .id = 0x11060446, .name = "VT1802",
3910 .patch = patch_vt2002P},
3911 { .id = 0x11068446, .name = "VT1802",
3912 .patch = patch_vt2002P},
Joseph Chanc577b8a2006-11-29 15:29:40 +01003913 {} /* terminator */
3914};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003915
3916MODULE_ALIAS("snd-hda-codec-id:1106*");
3917
3918static struct hda_codec_preset_list via_list = {
3919 .preset = snd_hda_preset_via,
3920 .owner = THIS_MODULE,
3921};
3922
3923MODULE_LICENSE("GPL");
3924MODULE_DESCRIPTION("VIA HD-audio codec");
3925
3926static int __init patch_via_init(void)
3927{
3928 return snd_hda_add_codec_preset(&via_list);
3929}
3930
3931static void __exit patch_via_exit(void)
3932{
3933 snd_hda_delete_codec_preset(&via_list);
3934}
3935
3936module_init(patch_via_init)
3937module_exit(patch_via_exit)