blob: eae466a6a987d347cf04a157bfe51c7b802d84b7 [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 {
121 /* codec parameterization */
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200122 const struct snd_kcontrol_new *mixers[6];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800123 unsigned int num_mixers;
124
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200125 const struct hda_verb *init_verbs[5];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800126 unsigned int num_iverbs;
127
Takashi Iwai82673bc2011-06-17 16:24:21 +0200128 char stream_name_analog[32];
Takashi Iwai7eb56e82011-06-18 16:40:14 +0200129 char stream_name_hp[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200130 const struct hda_pcm_stream *stream_analog_playback;
131 const struct hda_pcm_stream *stream_analog_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800132
Takashi Iwai82673bc2011-06-17 16:24:21 +0200133 char stream_name_digital[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200134 const struct hda_pcm_stream *stream_digital_playback;
135 const struct hda_pcm_stream *stream_digital_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800136
137 /* playback */
138 struct hda_multi_out multiout;
139 hda_nid_t slave_dig_outs[2];
Takashi Iwaiece8d042011-06-19 16:24:21 +0200140 hda_nid_t hp_dac_nid;
Takashi Iwai3214b962011-07-18 12:49:25 +0200141 hda_nid_t speaker_dac_nid;
142 int hp_indep_shared; /* indep HP-DAC is shared with side ch */
Takashi Iwai3b607e32011-07-18 16:54:40 +0200143 int opened_streams; /* STREAM_* bits */
144 int active_streams; /* STREAM_* bits */
Takashi Iwai3214b962011-07-18 12:49:25 +0200145 int aamix_mode; /* loopback is enabled for output-path? */
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800146
Takashi Iwai3214b962011-07-18 12:49:25 +0200147 /* Output-paths:
148 * There are different output-paths depending on the setup.
149 * out_path, hp_path and speaker_path are primary paths. If both
150 * direct DAC and aa-loopback routes are available, these contain
151 * the former paths. Meanwhile *_mix_path contain the paths with
152 * loopback mixer. (Since the loopback is only for front channel,
153 * no out_mix_path for surround channels.)
154 * The HP output has another path, hp_indep_path, which is used in
155 * the independent-HP mode.
156 */
Takashi Iwaide6c74f2011-07-04 14:46:42 +0200157 struct nid_path out_path[HDA_SIDE + 1];
Takashi Iwai3214b962011-07-18 12:49:25 +0200158 struct nid_path out_mix_path;
Takashi Iwai4a796162011-06-17 17:53:38 +0200159 struct nid_path hp_path;
Takashi Iwai3214b962011-07-18 12:49:25 +0200160 struct nid_path hp_mix_path;
161 struct nid_path hp_indep_path;
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200162 struct nid_path speaker_path;
Takashi Iwai3214b962011-07-18 12:49:25 +0200163 struct nid_path speaker_mix_path;
Takashi Iwai4a796162011-06-17 17:53:38 +0200164
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800165 /* capture */
166 unsigned int num_adc_nids;
Takashi Iwaide6c74f2011-07-04 14:46:42 +0200167 hda_nid_t adc_nids[VIA_MAX_ADCS];
168 hda_nid_t mux_nids[VIA_MAX_ADCS];
Takashi Iwai620e2b22011-06-17 17:19:19 +0200169 hda_nid_t aa_mix_nid;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800170 hda_nid_t dig_in_nid;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800171
172 /* capture source */
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200173 bool dyn_adc_switch;
174 int num_inputs;
175 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
Takashi Iwaide6c74f2011-07-04 14:46:42 +0200176 unsigned int cur_mux[VIA_MAX_ADCS];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800177
Takashi Iwai3b607e32011-07-18 16:54:40 +0200178 /* dynamic DAC switching */
179 unsigned int cur_dac_stream_tag;
180 unsigned int cur_dac_format;
181 unsigned int cur_hp_stream_tag;
182 unsigned int cur_hp_format;
183
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200184 /* dynamic ADC switching */
185 hda_nid_t cur_adc;
186 unsigned int cur_adc_stream_tag;
187 unsigned int cur_adc_format;
188
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800189 /* PCM information */
190 struct hda_pcm pcm_rec[3];
191
192 /* dynamic controls, init_verbs and input_mux */
193 struct auto_pin_cfg autocfg;
194 struct snd_array kctls;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800195 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
196
197 /* HP mode source */
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800198 unsigned int hp_independent_mode;
Lydia Wangf3db4232009-10-10 19:08:41 +0800199 unsigned int dmic_enabled;
Takashi Iwai24088a52011-06-17 16:59:21 +0200200 unsigned int no_pin_power_ctl;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800201 enum VIA_HDA_CODEC codec_type;
202
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100203 /* analog low-power control */
204 bool alc_mode;
205
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200206 /* smart51 setup */
207 unsigned int smart51_nums;
208 hda_nid_t smart51_pins[2];
209 int smart51_idxs[2];
210 const char *smart51_labels[2];
211 unsigned int smart51_enabled;
212
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800213 /* work to check hp jack state */
214 struct hda_codec *codec;
215 struct delayed_work vt1708_hp_work;
Takashi Iwai187d3332011-11-24 16:33:09 +0100216 int hp_work_active;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200217 int vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800218 int vt1708_hp_present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800219
220 void (*set_widgets_power_state)(struct hda_codec *codec);
221
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800222 struct hda_loopback_check loopback;
Takashi Iwai13af8e72011-06-20 14:05:46 +0200223 int num_loopbacks;
224 struct hda_amp_list loopback_list[8];
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200225
226 /* bind capture-volume */
227 struct hda_bind_ctls *bind_cap_vol;
228 struct hda_bind_ctls *bind_cap_sw;
Takashi Iwai3b607e32011-07-18 16:54:40 +0200229
230 struct mutex config_mutex;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800231};
232
Lydia Wang0341ccd2011-03-22 16:25:03 +0800233static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100234static struct via_spec * via_new_spec(struct hda_codec *codec)
235{
236 struct via_spec *spec;
237
238 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
239 if (spec == NULL)
240 return NULL;
241
Takashi Iwai3b607e32011-07-18 16:54:40 +0200242 mutex_init(&spec->config_mutex);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100243 codec->spec = spec;
244 spec->codec = codec;
Lydia Wang0341ccd2011-03-22 16:25:03 +0800245 spec->codec_type = get_codec_type(codec);
246 /* VT1708BCE & VT1708S are almost same */
247 if (spec->codec_type == VT1708BCE)
248 spec->codec_type = VT1708S;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100249 return spec;
250}
251
Lydia Wang744ff5f2009-10-10 19:07:26 +0800252static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800253{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800254 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800255 u16 ven_id = vendor_id >> 16;
256 u16 dev_id = vendor_id & 0xffff;
257 enum VIA_HDA_CODEC codec_type;
258
259 /* get codec type */
260 if (ven_id != 0x1106)
261 codec_type = UNKNOWN;
262 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
263 codec_type = VT1708;
264 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
265 codec_type = VT1709_10CH;
266 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
267 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800268 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800269 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800270 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
271 codec_type = VT1708BCE;
272 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800273 codec_type = VT1708B_4CH;
274 else if ((dev_id & 0xfff) == 0x397
275 && (dev_id >> 12) < 8)
276 codec_type = VT1708S;
277 else if ((dev_id & 0xfff) == 0x398
278 && (dev_id >> 12) < 8)
279 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800280 else if ((dev_id & 0xfff) == 0x428
281 && (dev_id >> 12) < 8)
282 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800283 else if (dev_id == 0x0433 || dev_id == 0xa721)
284 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800285 else if (dev_id == 0x0441 || dev_id == 0x4441)
286 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800287 else if (dev_id == 0x0438 || dev_id == 0x4438)
288 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800289 else if (dev_id == 0x0448)
290 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800291 else if (dev_id == 0x0440)
292 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800293 else if ((dev_id & 0xfff) == 0x446)
294 codec_type = VT1802;
Harald Welted7426322008-09-15 22:43:23 +0800295 else
296 codec_type = UNKNOWN;
297 return codec_type;
298};
299
Lydia Wangec7e7e42011-03-24 12:43:44 +0800300#define VIA_JACK_EVENT 0x20
Harald Welte69e52a82008-09-09 15:57:32 +0800301#define VIA_HP_EVENT 0x01
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200302#define VIA_LINE_EVENT 0x03
Harald Welte69e52a82008-09-09 15:57:32 +0800303
Joseph Chanc577b8a2006-11-29 15:29:40 +0100304enum {
305 VIA_CTL_WIDGET_VOL,
306 VIA_CTL_WIDGET_MUTE,
Lydia Wangf5271102009-10-10 19:07:35 +0800307 VIA_CTL_WIDGET_ANALOG_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100308};
309
Takashi Iwaiada509e2011-06-20 15:40:19 +0200310static void analog_low_current_mode(struct hda_codec *codec);
311static bool is_aa_path_mute(struct hda_codec *codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800312
Takashi Iwai187d3332011-11-24 16:33:09 +0100313#define hp_detect_with_aa(codec) \
314 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
315 !is_aa_path_mute(codec))
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800316
317static void vt1708_stop_hp_work(struct via_spec *spec)
318{
319 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
320 return;
Takashi Iwai187d3332011-11-24 16:33:09 +0100321 if (spec->hp_work_active) {
322 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 1);
323 cancel_delayed_work_sync(&spec->vt1708_hp_work);
324 spec->hp_work_active = 0;
325 }
326}
327
328static void vt1708_update_hp_work(struct via_spec *spec)
329{
330 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800331 return;
Takashi Iwai187d3332011-11-24 16:33:09 +0100332 if (spec->vt1708_jack_detect &&
333 (spec->active_streams || hp_detect_with_aa(spec->codec))) {
334 if (!spec->hp_work_active) {
335 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 0);
336 schedule_delayed_work(&spec->vt1708_hp_work,
337 msecs_to_jiffies(100));
338 spec->hp_work_active = 1;
339 }
340 } else if (!hp_detect_with_aa(spec->codec))
341 vt1708_stop_hp_work(spec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800342}
Lydia Wangf5271102009-10-10 19:07:35 +0800343
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800344static void set_widgets_power_state(struct hda_codec *codec)
345{
346 struct via_spec *spec = codec->spec;
347 if (spec->set_widgets_power_state)
348 spec->set_widgets_power_state(codec);
349}
Lydia Wang25eaba22009-10-10 19:08:43 +0800350
Lydia Wangf5271102009-10-10 19:07:35 +0800351static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
352 struct snd_ctl_elem_value *ucontrol)
353{
354 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
355 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
356
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800357 set_widgets_power_state(codec);
Takashi Iwaiada509e2011-06-20 15:40:19 +0200358 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
Takashi Iwai187d3332011-11-24 16:33:09 +0100359 vt1708_update_hp_work(codec->spec);
Lydia Wangf5271102009-10-10 19:07:35 +0800360 return change;
361}
362
363/* modify .put = snd_hda_mixer_amp_switch_put */
364#define ANALOG_INPUT_MUTE \
365 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
366 .name = NULL, \
367 .index = 0, \
368 .info = snd_hda_mixer_amp_switch_info, \
369 .get = snd_hda_mixer_amp_switch_get, \
370 .put = analog_input_switch_put, \
371 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
372
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200373static const struct snd_kcontrol_new via_control_templates[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100374 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
375 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Lydia Wangf5271102009-10-10 19:07:35 +0800376 ANALOG_INPUT_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100377};
378
Lydia Wangab6734e2009-10-10 19:08:46 +0800379
Joseph Chanc577b8a2006-11-29 15:29:40 +0100380/* add dynamic controls */
Takashi Iwai291c9e32011-06-17 16:15:26 +0200381static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
382 const struct snd_kcontrol_new *tmpl,
383 const char *name)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100384{
385 struct snd_kcontrol_new *knew;
386
Takashi Iwai603c4012008-07-30 15:01:44 +0200387 snd_array_init(&spec->kctls, sizeof(*knew), 32);
388 knew = snd_array_new(&spec->kctls);
389 if (!knew)
Takashi Iwai291c9e32011-06-17 16:15:26 +0200390 return NULL;
391 *knew = *tmpl;
392 if (!name)
393 name = tmpl->name;
394 if (name) {
395 knew->name = kstrdup(name, GFP_KERNEL);
396 if (!knew->name)
397 return NULL;
398 }
399 return knew;
400}
401
402static int __via_add_control(struct via_spec *spec, int type, const char *name,
403 int idx, unsigned long val)
404{
405 struct snd_kcontrol_new *knew;
406
407 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
408 if (!knew)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100409 return -ENOMEM;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +0200410 knew->index = idx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100411 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100412 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100413 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100414 return 0;
415}
416
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200417#define via_add_control(spec, type, name, val) \
418 __via_add_control(spec, type, name, 0, val)
419
Takashi Iwai291c9e32011-06-17 16:15:26 +0200420#define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100421
Takashi Iwai603c4012008-07-30 15:01:44 +0200422static void via_free_kctls(struct hda_codec *codec)
423{
424 struct via_spec *spec = codec->spec;
425
426 if (spec->kctls.list) {
427 struct snd_kcontrol_new *kctl = spec->kctls.list;
428 int i;
429 for (i = 0; i < spec->kctls.used; i++)
430 kfree(kctl[i].name);
431 }
432 snd_array_free(&spec->kctls);
433}
434
Joseph Chanc577b8a2006-11-29 15:29:40 +0100435/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800436static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200437 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100438{
439 char name[32];
440 int err;
441
442 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200443 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100444 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
445 if (err < 0)
446 return err;
447 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200448 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100449 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
450 if (err < 0)
451 return err;
452 return 0;
453}
454
Takashi Iwai5d417622011-06-20 11:32:27 +0200455#define get_connection_index(codec, mux, nid) \
Takashi Iwai8d087c72011-06-28 12:45:47 +0200456 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai5d417622011-06-20 11:32:27 +0200457
Takashi Iwai8df2a312011-06-21 11:48:29 +0200458static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
459 unsigned int mask)
460{
Takashi Iwaia934d5a2011-06-21 14:22:14 +0200461 unsigned int caps;
462 if (!nid)
463 return false;
464 caps = get_wcaps(codec, nid);
Takashi Iwai8df2a312011-06-21 11:48:29 +0200465 if (dir == HDA_INPUT)
466 caps &= AC_WCAP_IN_AMP;
467 else
468 caps &= AC_WCAP_OUT_AMP;
469 if (!caps)
470 return false;
471 if (query_amp_caps(codec, nid, dir) & mask)
472 return true;
473 return false;
474}
475
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200476#define have_mute(codec, nid, dir) \
477 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
Takashi Iwai8df2a312011-06-21 11:48:29 +0200478
Lydia Wangd69607b32011-07-08 14:02:52 +0800479/* enable/disable the output-route mixers */
480static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai3214b962011-07-18 12:49:25 +0200481 hda_nid_t mix_nid, int idx, bool enable)
Lydia Wangd69607b32011-07-08 14:02:52 +0800482{
483 int i, num, val;
Lydia Wangd69607b32011-07-08 14:02:52 +0800484
485 if (!path)
486 return;
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200487 num = snd_hda_get_num_conns(codec, mix_nid);
Lydia Wangd69607b32011-07-08 14:02:52 +0800488 for (i = 0; i < num; i++) {
Takashi Iwai3214b962011-07-18 12:49:25 +0200489 if (i == idx)
490 val = AMP_IN_UNMUTE(i);
491 else
492 val = AMP_IN_MUTE(i);
Lydia Wangd69607b32011-07-08 14:02:52 +0800493 snd_hda_codec_write(codec, mix_nid, 0,
494 AC_VERB_SET_AMP_GAIN_MUTE, val);
495 }
496}
497
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200498/* enable/disable the output-route */
499static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
500 bool enable, bool force)
Takashi Iwai5d417622011-06-20 11:32:27 +0200501{
Lydia Wangd69607b32011-07-08 14:02:52 +0800502 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200503 int i;
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200504 for (i = 0; i < path->depth; i++) {
505 hda_nid_t src, dst;
506 int idx = path->idx[i];
507 src = path->path[i];
508 if (i < path->depth - 1)
509 dst = path->path[i + 1];
510 else
511 dst = 0;
512 if (enable && path->multi[i])
513 snd_hda_codec_write(codec, dst, 0,
514 AC_VERB_SET_CONNECT_SEL, idx);
Takashi Iwai3214b962011-07-18 12:49:25 +0200515 if (!force && (dst == spec->aa_mix_nid))
Lydia Wange5e14682011-07-01 10:55:07 +0800516 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +0200517 if (have_mute(codec, dst, HDA_INPUT))
518 activate_output_mix(codec, path, dst, idx, enable);
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200519 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
520 continue;
521 if (have_mute(codec, src, HDA_OUTPUT)) {
522 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
523 snd_hda_codec_write(codec, src, 0,
524 AC_VERB_SET_AMP_GAIN_MUTE, val);
525 }
526 }
Takashi Iwai5d417622011-06-20 11:32:27 +0200527}
528
529/* set the given pin as output */
530static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
531 int pin_type)
532{
533 if (!pin)
534 return;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200535 snd_hda_set_pin_ctl(codec, pin, pin_type);
Takashi Iwai5d417622011-06-20 11:32:27 +0200536 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
537 snd_hda_codec_write(codec, pin, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200538 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100539}
540
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200541static void via_auto_init_output(struct hda_codec *codec,
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200542 struct nid_path *path, int pin_type)
Takashi Iwai5d417622011-06-20 11:32:27 +0200543{
Takashi Iwai5d417622011-06-20 11:32:27 +0200544 unsigned int caps;
Lydia Wangd69607b32011-07-08 14:02:52 +0800545 hda_nid_t pin;
Takashi Iwai5d417622011-06-20 11:32:27 +0200546
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200547 if (!path->depth)
Takashi Iwai5d417622011-06-20 11:32:27 +0200548 return;
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200549 pin = path->path[path->depth - 1];
Takashi Iwai5d417622011-06-20 11:32:27 +0200550
551 init_output_pin(codec, pin, pin_type);
Takashi Iwai77e314f2012-02-22 12:34:08 +0100552 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
553 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
554 else
555 caps = 0;
Takashi Iwai5d417622011-06-20 11:32:27 +0200556 if (caps & AC_AMPCAP_MUTE) {
557 unsigned int val;
558 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
559 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
560 AMP_OUT_MUTE | val);
561 }
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200562 activate_output_path(codec, path, true, true); /* force on */
Takashi Iwai5d417622011-06-20 11:32:27 +0200563}
564
Joseph Chanc577b8a2006-11-29 15:29:40 +0100565static void via_auto_init_multi_out(struct hda_codec *codec)
566{
567 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200568 struct nid_path *path;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100569 int i;
570
Takashi Iwai3214b962011-07-18 12:49:25 +0200571 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
572 path = &spec->out_path[i];
573 if (!i && spec->aamix_mode && spec->out_mix_path.depth)
574 path = &spec->out_mix_path;
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200575 via_auto_init_output(codec, path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200576 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100577}
578
Takashi Iwai020066d2011-07-21 13:45:56 +0200579/* deactivate the inactive headphone-paths */
580static void deactivate_hp_paths(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100581{
582 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200583 int shared = spec->hp_indep_shared;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100584
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200585 if (spec->hp_independent_mode) {
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200586 activate_output_path(codec, &spec->hp_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200587 activate_output_path(codec, &spec->hp_mix_path, false, false);
588 if (shared)
589 activate_output_path(codec, &spec->out_path[shared],
590 false, false);
Takashi Iwai020066d2011-07-21 13:45:56 +0200591 } else if (spec->aamix_mode || !spec->hp_path.depth) {
592 activate_output_path(codec, &spec->hp_indep_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200593 activate_output_path(codec, &spec->hp_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200594 } else {
Takashi Iwai020066d2011-07-21 13:45:56 +0200595 activate_output_path(codec, &spec->hp_indep_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200596 activate_output_path(codec, &spec->hp_mix_path, false, false);
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200597 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100598}
599
Takashi Iwai020066d2011-07-21 13:45:56 +0200600static void via_auto_init_hp_out(struct hda_codec *codec)
601{
602 struct via_spec *spec = codec->spec;
603
604 if (!spec->hp_path.depth) {
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200605 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200606 return;
607 }
608 deactivate_hp_paths(codec);
609 if (spec->hp_independent_mode)
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200610 via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200611 else if (spec->aamix_mode)
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200612 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200613 else
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200614 via_auto_init_output(codec, &spec->hp_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200615}
616
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200617static void via_auto_init_speaker_out(struct hda_codec *codec)
618{
619 struct via_spec *spec = codec->spec;
620
Takashi Iwai3214b962011-07-18 12:49:25 +0200621 if (!spec->autocfg.speaker_outs)
622 return;
623 if (!spec->speaker_path.depth) {
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200624 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200625 return;
626 }
627 if (!spec->aamix_mode) {
628 activate_output_path(codec, &spec->speaker_mix_path,
629 false, false);
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200630 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200631 } else {
632 activate_output_path(codec, &spec->speaker_path, false, false);
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200633 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200634 }
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200635}
636
Takashi Iwaif4a78282011-06-17 18:46:48 +0200637static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
Takashi Iwai6e969d92011-07-11 11:28:13 +0200638static void via_hp_automute(struct hda_codec *codec);
Clemens Ladisch32e01912010-07-12 16:28:50 +0200639
Joseph Chanc577b8a2006-11-29 15:29:40 +0100640static void via_auto_init_analog_input(struct hda_codec *codec)
641{
642 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200643 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai096a8852011-06-20 12:09:02 +0200644 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Clemens Ladisch32e01912010-07-12 16:28:50 +0200645 unsigned int ctl;
Takashi Iwai096a8852011-06-20 12:09:02 +0200646 int i, num_conns;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100647
Takashi Iwai096a8852011-06-20 12:09:02 +0200648 /* init ADCs */
649 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai77e314f2012-02-22 12:34:08 +0100650 hda_nid_t nid = spec->adc_nids[i];
651 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP) ||
652 !(query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE))
653 continue;
Takashi Iwai096a8852011-06-20 12:09:02 +0200654 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
655 AC_VERB_SET_AMP_GAIN_MUTE,
656 AMP_IN_UNMUTE(0));
657 }
658
659 /* init pins */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200660 for (i = 0; i < cfg->num_inputs; i++) {
661 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200662 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
Clemens Ladisch32e01912010-07-12 16:28:50 +0200663 ctl = PIN_OUT;
Takashi Iwai47408602012-04-20 13:06:53 +0200664 else {
Clemens Ladisch32e01912010-07-12 16:28:50 +0200665 ctl = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200666 if (cfg->inputs[i].type == AUTO_PIN_MIC)
667 ctl |= snd_hda_get_default_vref(codec, nid);
668 }
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200669 snd_hda_set_pin_ctl(codec, nid, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100670 }
Takashi Iwai096a8852011-06-20 12:09:02 +0200671
672 /* init input-src */
673 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200674 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
Takashi Iwaifc1156c2012-02-13 15:04:06 +0100675 /* secondary ADCs must have the unique MUX */
676 if (i > 0 && !spec->mux_nids[i])
677 break;
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200678 if (spec->mux_nids[adc_idx]) {
679 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
680 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
681 AC_VERB_SET_CONNECT_SEL,
682 mux_idx);
683 }
684 if (spec->dyn_adc_switch)
685 break; /* only one input-src */
Takashi Iwai096a8852011-06-20 12:09:02 +0200686 }
687
688 /* init aa-mixer */
689 if (!spec->aa_mix_nid)
690 return;
691 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
692 ARRAY_SIZE(conn));
693 for (i = 0; i < num_conns; i++) {
694 unsigned int caps = get_wcaps(codec, conn[i]);
695 if (get_wcaps_type(caps) == AC_WID_PIN)
696 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
697 AC_VERB_SET_AMP_GAIN_MUTE,
698 AMP_IN_MUTE(i));
699 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100700}
Lydia Wangf5271102009-10-10 19:07:35 +0800701
Takashi Iwai054d8672012-01-24 12:25:50 +0100702static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
703 unsigned int parm)
704{
705 if (snd_hda_codec_read(codec, nid, 0,
706 AC_VERB_GET_POWER_STATE, 0) == parm)
707 return;
708 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
709}
710
Lydia Wangf5271102009-10-10 19:07:35 +0800711static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
712 unsigned int *affected_parm)
713{
714 unsigned parm;
715 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
716 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
717 >> AC_DEFCFG_MISC_SHIFT
718 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800719 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200720 unsigned present = 0;
721
722 no_presence |= spec->no_pin_power_ctl;
723 if (!no_presence)
724 present = snd_hda_jack_detect(codec, nid);
Takashi Iwaif4a78282011-06-17 18:46:48 +0200725 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
Lydia Wang1564b282009-10-10 19:07:52 +0800726 || ((no_presence || present)
727 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800728 *affected_parm = AC_PWRST_D0; /* if it's connected */
729 parm = AC_PWRST_D0;
730 } else
731 parm = AC_PWRST_D3;
732
Takashi Iwai054d8672012-01-24 12:25:50 +0100733 update_power_state(codec, nid, parm);
Lydia Wangf5271102009-10-10 19:07:35 +0800734}
735
Takashi Iwai24088a52011-06-17 16:59:21 +0200736static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
737 struct snd_ctl_elem_info *uinfo)
738{
739 static const char * const texts[] = {
740 "Disabled", "Enabled"
741 };
742
743 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
744 uinfo->count = 1;
745 uinfo->value.enumerated.items = 2;
746 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
747 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
748 strcpy(uinfo->value.enumerated.name,
749 texts[uinfo->value.enumerated.item]);
750 return 0;
751}
752
753static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
754 struct snd_ctl_elem_value *ucontrol)
755{
756 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
757 struct via_spec *spec = codec->spec;
758 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
759 return 0;
760}
761
762static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
763 struct snd_ctl_elem_value *ucontrol)
764{
765 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
766 struct via_spec *spec = codec->spec;
767 unsigned int val = !ucontrol->value.enumerated.item[0];
768
769 if (val == spec->no_pin_power_ctl)
770 return 0;
771 spec->no_pin_power_ctl = val;
772 set_widgets_power_state(codec);
Takashi Iwaie9d010c2012-02-01 10:33:23 +0100773 analog_low_current_mode(codec);
Takashi Iwai24088a52011-06-17 16:59:21 +0200774 return 1;
775}
776
777static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
778 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
779 .name = "Dynamic Power-Control",
780 .info = via_pin_power_ctl_info,
781 .get = via_pin_power_ctl_get,
782 .put = via_pin_power_ctl_put,
783};
784
785
Harald Welte0aa62ae2008-09-09 15:58:27 +0800786static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
787 struct snd_ctl_elem_info *uinfo)
788{
Takashi Iwai8df2a312011-06-21 11:48:29 +0200789 static const char * const texts[] = { "OFF", "ON" };
790
791 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
792 uinfo->count = 1;
793 uinfo->value.enumerated.items = 2;
794 if (uinfo->value.enumerated.item >= 2)
795 uinfo->value.enumerated.item = 1;
796 strcpy(uinfo->value.enumerated.name,
797 texts[uinfo->value.enumerated.item]);
798 return 0;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800799}
800
801static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
802 struct snd_ctl_elem_value *ucontrol)
803{
804 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Lydia Wangcdc17842009-10-10 19:07:47 +0800805 struct via_spec *spec = codec->spec;
Lydia Wangcdc17842009-10-10 19:07:47 +0800806
Takashi Iwaiece8d042011-06-19 16:24:21 +0200807 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
Lydia Wangcdc17842009-10-10 19:07:47 +0800808 return 0;
809}
810
Takashi Iwai3b607e32011-07-18 16:54:40 +0200811/* adjust spec->multiout setup according to the current flags */
812static void setup_playback_multi_pcm(struct via_spec *spec)
813{
814 const struct auto_pin_cfg *cfg = &spec->autocfg;
815 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
816 spec->multiout.hp_nid = 0;
817 if (!spec->hp_independent_mode) {
818 if (!spec->hp_indep_shared)
819 spec->multiout.hp_nid = spec->hp_dac_nid;
820 } else {
821 if (spec->hp_indep_shared)
822 spec->multiout.num_dacs = cfg->line_outs - 1;
823 }
824}
825
826/* update DAC setups according to indep-HP switch;
827 * this function is called only when indep-HP is modified
828 */
829static void switch_indep_hp_dacs(struct hda_codec *codec)
830{
831 struct via_spec *spec = codec->spec;
832 int shared = spec->hp_indep_shared;
833 hda_nid_t shared_dac, hp_dac;
834
835 if (!spec->opened_streams)
836 return;
837
838 shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
839 hp_dac = spec->hp_dac_nid;
840 if (spec->hp_independent_mode) {
841 /* switch to indep-HP mode */
842 if (spec->active_streams & STREAM_MULTI_OUT) {
843 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
844 __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
845 }
846 if (spec->active_streams & STREAM_INDEP_HP)
847 snd_hda_codec_setup_stream(codec, hp_dac,
848 spec->cur_hp_stream_tag, 0,
849 spec->cur_hp_format);
850 } else {
851 /* back to HP or shared-DAC */
852 if (spec->active_streams & STREAM_INDEP_HP)
853 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
854 if (spec->active_streams & STREAM_MULTI_OUT) {
855 hda_nid_t dac;
856 int ch;
857 if (shared_dac) { /* reset mutli-ch DAC */
858 dac = shared_dac;
859 ch = shared * 2;
860 } else { /* reset HP DAC */
861 dac = hp_dac;
862 ch = 0;
863 }
864 snd_hda_codec_setup_stream(codec, dac,
865 spec->cur_dac_stream_tag, ch,
866 spec->cur_dac_format);
867 }
868 }
869 setup_playback_multi_pcm(spec);
870}
871
Harald Welte0aa62ae2008-09-09 15:58:27 +0800872static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
873 struct snd_ctl_elem_value *ucontrol)
874{
875 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
876 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200877 int cur, shared;
Takashi Iwai8df2a312011-06-21 11:48:29 +0200878
Takashi Iwai3b607e32011-07-18 16:54:40 +0200879 mutex_lock(&spec->config_mutex);
Takashi Iwai25250502011-06-30 17:24:47 +0200880 cur = !!ucontrol->value.enumerated.item[0];
Takashi Iwai3b607e32011-07-18 16:54:40 +0200881 if (spec->hp_independent_mode == cur) {
882 mutex_unlock(&spec->config_mutex);
Takashi Iwai25250502011-06-30 17:24:47 +0200883 return 0;
Takashi Iwai3b607e32011-07-18 16:54:40 +0200884 }
Takashi Iwai25250502011-06-30 17:24:47 +0200885 spec->hp_independent_mode = cur;
Takashi Iwai3214b962011-07-18 12:49:25 +0200886 shared = spec->hp_indep_shared;
Takashi Iwai020066d2011-07-21 13:45:56 +0200887 deactivate_hp_paths(codec);
888 if (cur)
889 activate_output_path(codec, &spec->hp_indep_path, true, false);
890 else {
Takashi Iwai3214b962011-07-18 12:49:25 +0200891 if (shared)
892 activate_output_path(codec, &spec->out_path[shared],
Takashi Iwai25250502011-06-30 17:24:47 +0200893 true, false);
Takashi Iwai020066d2011-07-21 13:45:56 +0200894 if (spec->aamix_mode || !spec->hp_path.depth)
895 activate_output_path(codec, &spec->hp_mix_path,
896 true, false);
897 else
898 activate_output_path(codec, &spec->hp_path,
899 true, false);
Takashi Iwai8df2a312011-06-21 11:48:29 +0200900 }
Harald Welte0aa62ae2008-09-09 15:58:27 +0800901
Takashi Iwai3b607e32011-07-18 16:54:40 +0200902 switch_indep_hp_dacs(codec);
903 mutex_unlock(&spec->config_mutex);
904
Lydia Wangce0e5a92011-03-22 16:22:37 +0800905 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800906 set_widgets_power_state(codec);
Takashi Iwai6e969d92011-07-11 11:28:13 +0200907 via_hp_automute(codec);
Takashi Iwai25250502011-06-30 17:24:47 +0200908 return 1;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800909}
910
Takashi Iwaiece8d042011-06-19 16:24:21 +0200911static const struct snd_kcontrol_new via_hp_mixer = {
912 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
913 .name = "Independent HP",
914 .info = via_independent_hp_info,
915 .get = via_independent_hp_get,
916 .put = via_independent_hp_put,
Harald Welte0aa62ae2008-09-09 15:58:27 +0800917};
918
Takashi Iwai3d83e572010-04-14 14:36:23 +0200919static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100920{
Takashi Iwai3d83e572010-04-14 14:36:23 +0200921 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100922 struct snd_kcontrol_new *knew;
923 hda_nid_t nid;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100924
Takashi Iwaiece8d042011-06-19 16:24:21 +0200925 nid = spec->autocfg.hp_pins[0];
926 knew = via_clone_control(spec, &via_hp_mixer);
Takashi Iwai3d83e572010-04-14 14:36:23 +0200927 if (knew == NULL)
928 return -ENOMEM;
929
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100930 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100931
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100932 return 0;
933}
934
Lydia Wang1564b282009-10-10 19:07:52 +0800935static void notify_aa_path_ctls(struct hda_codec *codec)
936{
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200937 struct via_spec *spec = codec->spec;
Lydia Wang1564b282009-10-10 19:07:52 +0800938 int i;
Lydia Wang1564b282009-10-10 19:07:52 +0800939
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200940 for (i = 0; i < spec->smart51_nums; i++) {
941 struct snd_kcontrol *ctl;
942 struct snd_ctl_elem_id id;
943 memset(&id, 0, sizeof(id));
944 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
945 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
Lydia Wang525566c2011-04-28 16:03:39 +0800946 ctl = snd_hda_find_mixer_ctl(codec, id.name);
947 if (ctl)
948 snd_ctl_notify(codec->bus->card,
949 SNDRV_CTL_EVENT_MASK_VALUE,
950 &ctl->id);
Lydia Wang1564b282009-10-10 19:07:52 +0800951 }
952}
953
954static void mute_aa_path(struct hda_codec *codec, int mute)
955{
956 struct via_spec *spec = codec->spec;
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200957 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
Lydia Wang1564b282009-10-10 19:07:52 +0800958 int i;
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200959
Lydia Wang1564b282009-10-10 19:07:52 +0800960 /* check AA path's mute status */
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200961 for (i = 0; i < spec->smart51_nums; i++) {
962 if (spec->smart51_idxs[i] < 0)
963 continue;
964 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
965 HDA_INPUT, spec->smart51_idxs[i],
Lydia Wang1564b282009-10-10 19:07:52 +0800966 HDA_AMP_MUTE, val);
967 }
968}
Takashi Iwaif4a78282011-06-17 18:46:48 +0200969
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200970static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
971{
972 struct via_spec *spec = codec->spec;
973 int i;
974
975 for (i = 0; i < spec->smart51_nums; i++)
976 if (spec->smart51_pins[i] == pin)
977 return true;
978 return false;
979}
980
Lydia Wang1564b282009-10-10 19:07:52 +0800981static int via_smart51_get(struct snd_kcontrol *kcontrol,
982 struct snd_ctl_elem_value *ucontrol)
983{
984 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
985 struct via_spec *spec = codec->spec;
Lydia Wang1564b282009-10-10 19:07:52 +0800986
Takashi Iwaif2b1c9f2011-06-21 16:52:39 +0200987 *ucontrol->value.integer.value = spec->smart51_enabled;
Lydia Wang1564b282009-10-10 19:07:52 +0800988 return 0;
989}
990
991static int via_smart51_put(struct snd_kcontrol *kcontrol,
992 struct snd_ctl_elem_value *ucontrol)
993{
994 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
995 struct via_spec *spec = codec->spec;
996 int out_in = *ucontrol->value.integer.value
997 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +0800998 int i;
999
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001000 for (i = 0; i < spec->smart51_nums; i++) {
1001 hda_nid_t nid = spec->smart51_pins[i];
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001002 unsigned int parm;
1003
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001004 parm = snd_hda_codec_read(codec, nid, 0,
1005 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1006 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1007 parm |= out_in;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001008 snd_hda_set_pin_ctl(codec, nid, parm);
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001009 if (out_in == AC_PINCTL_OUT_EN) {
1010 mute_aa_path(codec, 1);
1011 notify_aa_path_ctls(codec);
1012 }
Lydia Wang1564b282009-10-10 19:07:52 +08001013 }
1014 spec->smart51_enabled = *ucontrol->value.integer.value;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001015 set_widgets_power_state(codec);
Lydia Wang1564b282009-10-10 19:07:52 +08001016 return 1;
1017}
1018
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001019static const struct snd_kcontrol_new via_smart51_mixer = {
1020 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1021 .name = "Smart 5.1",
1022 .count = 1,
Takashi Iwaif2b1c9f2011-06-21 16:52:39 +02001023 .info = snd_ctl_boolean_mono_info,
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001024 .get = via_smart51_get,
1025 .put = via_smart51_put,
Lydia Wang1564b282009-10-10 19:07:52 +08001026};
1027
Takashi Iwaif4a78282011-06-17 18:46:48 +02001028static int via_smart51_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001029{
Takashi Iwaif4a78282011-06-17 18:46:48 +02001030 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001031
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001032 if (!spec->smart51_nums)
Lydia Wangcb34c202011-04-27 17:44:16 +08001033 return 0;
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001034 if (!via_clone_control(spec, &via_smart51_mixer))
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001035 return -ENOMEM;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001036 return 0;
1037}
1038
Takashi Iwaiada509e2011-06-20 15:40:19 +02001039/* check AA path's mute status */
1040static bool is_aa_path_mute(struct hda_codec *codec)
Lydia Wangf5271102009-10-10 19:07:35 +08001041{
Lydia Wangf5271102009-10-10 19:07:35 +08001042 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001043 const struct hda_amp_list *p;
1044 int i, ch, v;
1045
1046 for (i = 0; i < spec->num_loopbacks; i++) {
1047 p = &spec->loopback_list[i];
1048 for (ch = 0; ch < 2; ch++) {
1049 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
1050 p->idx);
1051 if (!(v & HDA_AMP_MUTE) && v > 0)
1052 return false;
Lydia Wangf5271102009-10-10 19:07:35 +08001053 }
1054 }
Takashi Iwaiada509e2011-06-20 15:40:19 +02001055 return true;
Lydia Wangf5271102009-10-10 19:07:35 +08001056}
1057
1058/* enter/exit analog low-current mode */
Takashi Iwaie9d010c2012-02-01 10:33:23 +01001059static void __analog_low_current_mode(struct hda_codec *codec, bool force)
Lydia Wangf5271102009-10-10 19:07:35 +08001060{
1061 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001062 bool enable;
1063 unsigned int verb, parm;
Lydia Wangf5271102009-10-10 19:07:35 +08001064
Takashi Iwaie9d010c2012-02-01 10:33:23 +01001065 if (spec->no_pin_power_ctl)
1066 enable = false;
1067 else
1068 enable = is_aa_path_mute(codec) && !spec->opened_streams;
1069 if (enable == spec->alc_mode && !force)
1070 return;
1071 spec->alc_mode = enable;
Lydia Wangf5271102009-10-10 19:07:35 +08001072
1073 /* decide low current mode's verb & parameter */
1074 switch (spec->codec_type) {
1075 case VT1708B_8CH:
1076 case VT1708B_4CH:
1077 verb = 0xf70;
1078 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1079 break;
1080 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001081 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001082 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001083 verb = 0xf73;
1084 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1085 break;
1086 case VT1702:
1087 verb = 0xf73;
1088 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1089 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001090 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001091 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001092 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001093 verb = 0xf93;
1094 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1095 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001096 default:
1097 return; /* other codecs are not supported */
1098 }
1099 /* send verb */
1100 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1101}
1102
Takashi Iwaie9d010c2012-02-01 10:33:23 +01001103static void analog_low_current_mode(struct hda_codec *codec)
1104{
1105 return __analog_low_current_mode(codec, false);
1106}
1107
Joseph Chanc577b8a2006-11-29 15:29:40 +01001108/*
1109 * generic initialization of ADC, input mixers and output mixers
1110 */
Takashi Iwai096a8852011-06-20 12:09:02 +02001111static const struct hda_verb vt1708_init_verbs[] = {
Lydia Wangaa266fc2011-03-24 12:41:01 +08001112 /* power down jack detect function */
1113 {0x1, 0xf81, 0x1},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001114 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001115};
1116
Takashi Iwai3b607e32011-07-18 16:54:40 +02001117static void set_stream_open(struct hda_codec *codec, int bit, bool active)
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001118{
Takashi Iwaiada509e2011-06-20 15:40:19 +02001119 struct via_spec *spec = codec->spec;
1120
1121 if (active)
Takashi Iwai3b607e32011-07-18 16:54:40 +02001122 spec->opened_streams |= bit;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001123 else
Takashi Iwai3b607e32011-07-18 16:54:40 +02001124 spec->opened_streams &= ~bit;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001125 analog_low_current_mode(codec);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001126}
1127
Takashi Iwaiece8d042011-06-19 16:24:21 +02001128static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001129 struct hda_codec *codec,
1130 struct snd_pcm_substream *substream)
1131{
1132 struct via_spec *spec = codec->spec;
Takashi Iwai25250502011-06-30 17:24:47 +02001133 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001134 int err;
Takashi Iwaiece8d042011-06-19 16:24:21 +02001135
Takashi Iwai25250502011-06-30 17:24:47 +02001136 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
Takashi Iwai25250502011-06-30 17:24:47 +02001137 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai3b607e32011-07-18 16:54:40 +02001138 set_stream_open(codec, STREAM_MULTI_OUT, true);
Takashi Iwaiada509e2011-06-20 15:40:19 +02001139 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1140 hinfo);
1141 if (err < 0) {
Takashi Iwai3b607e32011-07-18 16:54:40 +02001142 set_stream_open(codec, STREAM_MULTI_OUT, false);
Takashi Iwaiada509e2011-06-20 15:40:19 +02001143 return err;
1144 }
1145 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001146}
1147
Takashi Iwaiece8d042011-06-19 16:24:21 +02001148static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
Takashi Iwai9af74212011-06-18 16:17:45 +02001149 struct hda_codec *codec,
1150 struct snd_pcm_substream *substream)
1151{
Takashi Iwai3b607e32011-07-18 16:54:40 +02001152 set_stream_open(codec, STREAM_MULTI_OUT, false);
Takashi Iwai9af74212011-06-18 16:17:45 +02001153 return 0;
1154}
1155
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001156static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1157 struct hda_codec *codec,
1158 struct snd_pcm_substream *substream)
1159{
1160 struct via_spec *spec = codec->spec;
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001161
Takashi Iwaiece8d042011-06-19 16:24:21 +02001162 if (snd_BUG_ON(!spec->hp_dac_nid))
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001163 return -EINVAL;
Takashi Iwai3b607e32011-07-18 16:54:40 +02001164 set_stream_open(codec, STREAM_INDEP_HP, true);
Takashi Iwaiece8d042011-06-19 16:24:21 +02001165 return 0;
1166}
1167
1168static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1169 struct hda_codec *codec,
1170 struct snd_pcm_substream *substream)
1171{
Takashi Iwai3b607e32011-07-18 16:54:40 +02001172 set_stream_open(codec, STREAM_INDEP_HP, false);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001173 return 0;
1174}
1175
1176static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1177 struct hda_codec *codec,
1178 unsigned int stream_tag,
1179 unsigned int format,
1180 struct snd_pcm_substream *substream)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001181{
1182 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001183
Takashi Iwai3b607e32011-07-18 16:54:40 +02001184 mutex_lock(&spec->config_mutex);
1185 setup_playback_multi_pcm(spec);
Takashi Iwaiece8d042011-06-19 16:24:21 +02001186 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1187 format, substream);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001188 /* remember for dynamic DAC switch with indep-HP */
1189 spec->active_streams |= STREAM_MULTI_OUT;
1190 spec->cur_dac_stream_tag = stream_tag;
1191 spec->cur_dac_format = format;
1192 mutex_unlock(&spec->config_mutex);
Takashi Iwai187d3332011-11-24 16:33:09 +01001193 vt1708_update_hp_work(spec);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001194 return 0;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001195}
1196
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001197static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1198 struct hda_codec *codec,
1199 unsigned int stream_tag,
1200 unsigned int format,
1201 struct snd_pcm_substream *substream)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001202{
1203 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001204
Takashi Iwai3b607e32011-07-18 16:54:40 +02001205 mutex_lock(&spec->config_mutex);
1206 if (spec->hp_independent_mode)
1207 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1208 stream_tag, 0, format);
1209 spec->active_streams |= STREAM_INDEP_HP;
1210 spec->cur_hp_stream_tag = stream_tag;
1211 spec->cur_hp_format = format;
1212 mutex_unlock(&spec->config_mutex);
Takashi Iwai187d3332011-11-24 16:33:09 +01001213 vt1708_update_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001214 return 0;
1215}
1216
1217static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1218 struct hda_codec *codec,
1219 struct snd_pcm_substream *substream)
1220{
1221 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001222
Takashi Iwai3b607e32011-07-18 16:54:40 +02001223 mutex_lock(&spec->config_mutex);
Takashi Iwaiece8d042011-06-19 16:24:21 +02001224 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001225 spec->active_streams &= ~STREAM_MULTI_OUT;
1226 mutex_unlock(&spec->config_mutex);
Takashi Iwai187d3332011-11-24 16:33:09 +01001227 vt1708_update_hp_work(spec);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001228 return 0;
1229}
1230
1231static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1232 struct hda_codec *codec,
1233 struct snd_pcm_substream *substream)
1234{
1235 struct via_spec *spec = codec->spec;
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001236
Takashi Iwai3b607e32011-07-18 16:54:40 +02001237 mutex_lock(&spec->config_mutex);
1238 if (spec->hp_independent_mode)
1239 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1240 spec->active_streams &= ~STREAM_INDEP_HP;
1241 mutex_unlock(&spec->config_mutex);
Takashi Iwai187d3332011-11-24 16:33:09 +01001242 vt1708_update_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001243 return 0;
1244}
1245
Joseph Chanc577b8a2006-11-29 15:29:40 +01001246/*
1247 * Digital out
1248 */
1249static int via_dig_playback_pcm_open(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_open(codec, &spec->multiout);
1255}
1256
1257static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1258 struct hda_codec *codec,
1259 struct snd_pcm_substream *substream)
1260{
1261 struct via_spec *spec = codec->spec;
1262 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1263}
1264
Harald Welte5691ec72008-09-15 22:42:26 +08001265static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001266 struct hda_codec *codec,
1267 unsigned int stream_tag,
1268 unsigned int format,
1269 struct snd_pcm_substream *substream)
1270{
1271 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001272 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1273 stream_tag, format, substream);
1274}
Harald Welte5691ec72008-09-15 22:42:26 +08001275
Takashi Iwai9da29272009-05-07 16:31:14 +02001276static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1277 struct hda_codec *codec,
1278 struct snd_pcm_substream *substream)
1279{
1280 struct via_spec *spec = codec->spec;
1281 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001282 return 0;
1283}
1284
Joseph Chanc577b8a2006-11-29 15:29:40 +01001285/*
1286 * Analog capture
1287 */
1288static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1289 struct hda_codec *codec,
1290 unsigned int stream_tag,
1291 unsigned int format,
1292 struct snd_pcm_substream *substream)
1293{
1294 struct via_spec *spec = codec->spec;
1295
1296 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1297 stream_tag, 0, format);
1298 return 0;
1299}
1300
1301static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1302 struct hda_codec *codec,
1303 struct snd_pcm_substream *substream)
1304{
1305 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001306 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001307 return 0;
1308}
1309
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001310/* analog capture with dynamic ADC switching */
1311static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1312 struct hda_codec *codec,
1313 unsigned int stream_tag,
1314 unsigned int format,
1315 struct snd_pcm_substream *substream)
1316{
1317 struct via_spec *spec = codec->spec;
1318 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1319
Takashi Iwai3b607e32011-07-18 16:54:40 +02001320 mutex_lock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001321 spec->cur_adc = spec->adc_nids[adc_idx];
1322 spec->cur_adc_stream_tag = stream_tag;
1323 spec->cur_adc_format = format;
1324 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001325 mutex_unlock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001326 return 0;
1327}
1328
1329static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1330 struct hda_codec *codec,
1331 struct snd_pcm_substream *substream)
1332{
1333 struct via_spec *spec = codec->spec;
1334
Takashi Iwai3b607e32011-07-18 16:54:40 +02001335 mutex_lock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001336 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1337 spec->cur_adc = 0;
Takashi Iwai3b607e32011-07-18 16:54:40 +02001338 mutex_unlock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001339 return 0;
1340}
1341
1342/* re-setup the stream if running; called from input-src put */
1343static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1344{
1345 struct via_spec *spec = codec->spec;
1346 int adc_idx = spec->inputs[cur].adc_idx;
1347 hda_nid_t adc = spec->adc_nids[adc_idx];
Takashi Iwai3b607e32011-07-18 16:54:40 +02001348 bool ret = false;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001349
Takashi Iwai3b607e32011-07-18 16:54:40 +02001350 mutex_lock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001351 if (spec->cur_adc && spec->cur_adc != adc) {
1352 /* stream is running, let's swap the current ADC */
1353 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1354 spec->cur_adc = adc;
1355 snd_hda_codec_setup_stream(codec, adc,
1356 spec->cur_adc_stream_tag, 0,
1357 spec->cur_adc_format);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001358 ret = true;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001359 }
Takashi Iwai3b607e32011-07-18 16:54:40 +02001360 mutex_unlock(&spec->config_mutex);
1361 return ret;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001362}
1363
Takashi Iwai9af74212011-06-18 16:17:45 +02001364static const struct hda_pcm_stream via_pcm_analog_playback = {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001365 .substreams = 1,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001366 .channels_min = 2,
1367 .channels_max = 8,
Takashi Iwai9af74212011-06-18 16:17:45 +02001368 /* NID is set in via_build_pcms */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001369 .ops = {
Takashi Iwaiece8d042011-06-19 16:24:21 +02001370 .open = via_playback_multi_pcm_open,
1371 .close = via_playback_multi_pcm_close,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001372 .prepare = via_playback_multi_pcm_prepare,
1373 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001374 },
1375};
1376
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001377static const struct hda_pcm_stream via_pcm_hp_playback = {
1378 .substreams = 1,
1379 .channels_min = 2,
1380 .channels_max = 2,
1381 /* NID is set in via_build_pcms */
1382 .ops = {
1383 .open = via_playback_hp_pcm_open,
Takashi Iwaiece8d042011-06-19 16:24:21 +02001384 .close = via_playback_hp_pcm_close,
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001385 .prepare = via_playback_hp_pcm_prepare,
1386 .cleanup = via_playback_hp_pcm_cleanup
1387 },
1388};
1389
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001390static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001391 .substreams = 1,
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001392 .channels_min = 2,
1393 .channels_max = 8,
Takashi Iwai9af74212011-06-18 16:17:45 +02001394 /* NID is set in via_build_pcms */
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001395 /* We got noisy outputs on the right channel on VT1708 when
1396 * 24bit samples are used. Until any workaround is found,
1397 * disable the 24bit format, so far.
1398 */
1399 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1400 .ops = {
Takashi Iwaiece8d042011-06-19 16:24:21 +02001401 .open = via_playback_multi_pcm_open,
1402 .close = via_playback_multi_pcm_close,
Lydia Wangc873cc22009-10-10 19:08:21 +08001403 .prepare = via_playback_multi_pcm_prepare,
1404 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001405 },
1406};
1407
Takashi Iwai9af74212011-06-18 16:17:45 +02001408static const struct hda_pcm_stream via_pcm_analog_capture = {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001409 .substreams = 1, /* will be changed in via_build_pcms() */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001410 .channels_min = 2,
1411 .channels_max = 2,
Takashi Iwai9af74212011-06-18 16:17:45 +02001412 /* NID is set in via_build_pcms */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001413 .ops = {
1414 .prepare = via_capture_pcm_prepare,
1415 .cleanup = via_capture_pcm_cleanup
1416 },
1417};
1418
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001419static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1420 .substreams = 1,
1421 .channels_min = 2,
1422 .channels_max = 2,
1423 /* NID is set in via_build_pcms */
1424 .ops = {
1425 .prepare = via_dyn_adc_capture_pcm_prepare,
1426 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1427 },
1428};
1429
Takashi Iwai9af74212011-06-18 16:17:45 +02001430static const struct hda_pcm_stream via_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001431 .substreams = 1,
1432 .channels_min = 2,
1433 .channels_max = 2,
1434 /* NID is set in via_build_pcms */
1435 .ops = {
1436 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001437 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001438 .prepare = via_dig_playback_pcm_prepare,
1439 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001440 },
1441};
1442
Takashi Iwai9af74212011-06-18 16:17:45 +02001443static const struct hda_pcm_stream via_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001444 .substreams = 1,
1445 .channels_min = 2,
1446 .channels_max = 2,
1447};
1448
Takashi Iwai370bafb2011-06-20 12:47:45 +02001449/*
1450 * slave controls for virtual master
1451 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001452static const char * const via_slave_pfxs[] = {
1453 "Front", "Surround", "Center", "LFE", "Side",
1454 "Headphone", "Speaker",
Takashi Iwai370bafb2011-06-20 12:47:45 +02001455 NULL,
1456};
1457
Joseph Chanc577b8a2006-11-29 15:29:40 +01001458static int via_build_controls(struct hda_codec *codec)
1459{
1460 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001461 struct snd_kcontrol *kctl;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001462 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001463
Takashi Iwaib5bcc182012-02-02 10:30:17 +01001464 spec->no_pin_power_ctl = 1;
Takashi Iwai24088a52011-06-17 16:59:21 +02001465 if (spec->set_widgets_power_state)
1466 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1467 return -ENOMEM;
1468
Joseph Chanc577b8a2006-11-29 15:29:40 +01001469 for (i = 0; i < spec->num_mixers; i++) {
1470 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1471 if (err < 0)
1472 return err;
1473 }
1474
1475 if (spec->multiout.dig_out_nid) {
1476 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001477 spec->multiout.dig_out_nid,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001478 spec->multiout.dig_out_nid);
1479 if (err < 0)
1480 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001481 err = snd_hda_create_spdif_share_sw(codec,
1482 &spec->multiout);
1483 if (err < 0)
1484 return err;
1485 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001486 }
1487 if (spec->dig_in_nid) {
1488 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1489 if (err < 0)
1490 return err;
1491 }
Lydia Wang17314372009-10-10 19:07:37 +08001492
Takashi Iwai370bafb2011-06-20 12:47:45 +02001493 /* if we have no master control, let's create it */
1494 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1495 unsigned int vmaster_tlv[4];
1496 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1497 HDA_OUTPUT, vmaster_tlv);
1498 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001499 vmaster_tlv, via_slave_pfxs,
1500 "Playback Volume");
Takashi Iwai370bafb2011-06-20 12:47:45 +02001501 if (err < 0)
1502 return err;
1503 }
1504 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1505 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001506 NULL, via_slave_pfxs,
1507 "Playback Switch");
Takashi Iwai370bafb2011-06-20 12:47:45 +02001508 if (err < 0)
1509 return err;
1510 }
1511
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001512 /* assign Capture Source enums to NID */
1513 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1514 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai77e314f2012-02-22 12:34:08 +01001515 if (!spec->mux_nids[i])
1516 continue;
Takashi Iwai21949f02009-12-23 08:31:59 +01001517 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001518 if (err < 0)
1519 return err;
1520 }
1521
Takashi Iwai603c4012008-07-30 15:01:44 +02001522 via_free_kctls(codec); /* no longer needed */
Takashi Iwai01a61e12011-10-28 00:03:22 +02001523
1524 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1525 if (err < 0)
1526 return err;
1527
Joseph Chanc577b8a2006-11-29 15:29:40 +01001528 return 0;
1529}
1530
1531static int via_build_pcms(struct hda_codec *codec)
1532{
1533 struct via_spec *spec = codec->spec;
1534 struct hda_pcm *info = spec->pcm_rec;
1535
Takashi Iwaia5973102011-09-28 16:43:36 +02001536 codec->num_pcms = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001537 codec->pcm_info = info;
1538
Takashi Iwaia5973102011-09-28 16:43:36 +02001539 if (spec->multiout.num_dacs || spec->num_adc_nids) {
1540 snprintf(spec->stream_name_analog,
1541 sizeof(spec->stream_name_analog),
1542 "%s Analog", codec->chip_name);
1543 info->name = spec->stream_name_analog;
Takashi Iwai9af74212011-06-18 16:17:45 +02001544
Takashi Iwaia5973102011-09-28 16:43:36 +02001545 if (spec->multiout.num_dacs) {
1546 if (!spec->stream_analog_playback)
1547 spec->stream_analog_playback =
1548 &via_pcm_analog_playback;
1549 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1550 *spec->stream_analog_playback;
1551 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1552 spec->multiout.dac_nids[0];
1553 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1554 spec->multiout.max_channels;
1555 }
Takashi Iwai9af74212011-06-18 16:17:45 +02001556
Takashi Iwaia5973102011-09-28 16:43:36 +02001557 if (!spec->stream_analog_capture) {
1558 if (spec->dyn_adc_switch)
1559 spec->stream_analog_capture =
1560 &via_pcm_dyn_adc_analog_capture;
1561 else
1562 spec->stream_analog_capture =
1563 &via_pcm_analog_capture;
1564 }
1565 if (spec->num_adc_nids) {
1566 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1567 *spec->stream_analog_capture;
1568 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1569 spec->adc_nids[0];
1570 if (!spec->dyn_adc_switch)
1571 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1572 spec->num_adc_nids;
1573 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001574 codec->num_pcms++;
1575 info++;
Takashi Iwaia5973102011-09-28 16:43:36 +02001576 }
1577
1578 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai82673bc2011-06-17 16:24:21 +02001579 snprintf(spec->stream_name_digital,
1580 sizeof(spec->stream_name_digital),
1581 "%s Digital", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001582 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001583 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001584 if (spec->multiout.dig_out_nid) {
Takashi Iwai9af74212011-06-18 16:17:45 +02001585 if (!spec->stream_digital_playback)
1586 spec->stream_digital_playback =
1587 &via_pcm_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001588 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001589 *spec->stream_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001590 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1591 spec->multiout.dig_out_nid;
1592 }
1593 if (spec->dig_in_nid) {
Takashi Iwai9af74212011-06-18 16:17:45 +02001594 if (!spec->stream_digital_capture)
1595 spec->stream_digital_capture =
1596 &via_pcm_digital_capture;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001597 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001598 *spec->stream_digital_capture;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001599 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1600 spec->dig_in_nid;
1601 }
Takashi Iwaia5973102011-09-28 16:43:36 +02001602 codec->num_pcms++;
1603 info++;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001604 }
1605
Takashi Iwaiece8d042011-06-19 16:24:21 +02001606 if (spec->hp_dac_nid) {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001607 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1608 "%s HP", codec->chip_name);
1609 info->name = spec->stream_name_hp;
1610 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1611 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
Takashi Iwaiece8d042011-06-19 16:24:21 +02001612 spec->hp_dac_nid;
Takashi Iwaia5973102011-09-28 16:43:36 +02001613 codec->num_pcms++;
1614 info++;
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001615 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001616 return 0;
1617}
1618
1619static void via_free(struct hda_codec *codec)
1620{
1621 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001622
1623 if (!spec)
1624 return;
1625
Takashi Iwai603c4012008-07-30 15:01:44 +02001626 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001627 vt1708_stop_hp_work(spec);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001628 kfree(spec->bind_cap_vol);
1629 kfree(spec->bind_cap_sw);
1630 kfree(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001631}
1632
Takashi Iwai64be2852011-06-17 16:51:39 +02001633/* mute/unmute outputs */
1634static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1635 hda_nid_t *pins, bool mute)
1636{
1637 int i;
Takashi Iwai94994732011-07-11 11:36:44 +02001638 for (i = 0; i < num_pins; i++) {
1639 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1640 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1641 if (parm & AC_PINCTL_IN_EN)
1642 continue;
1643 if (mute)
1644 parm &= ~AC_PINCTL_OUT_EN;
1645 else
1646 parm |= AC_PINCTL_OUT_EN;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001647 snd_hda_set_pin_ctl(codec, pins[i], parm);
Takashi Iwai94994732011-07-11 11:36:44 +02001648 }
Takashi Iwai64be2852011-06-17 16:51:39 +02001649}
1650
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001651/* mute internal speaker if line-out is plugged */
1652static void via_line_automute(struct hda_codec *codec, int present)
1653{
1654 struct via_spec *spec = codec->spec;
1655
1656 if (!spec->autocfg.speaker_outs)
1657 return;
1658 if (!present)
1659 present = snd_hda_jack_detect(codec,
1660 spec->autocfg.line_out_pins[0]);
1661 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1662 spec->autocfg.speaker_pins,
1663 present);
1664}
1665
Harald Welte69e52a82008-09-09 15:57:32 +08001666/* mute internal speaker if HP is plugged */
1667static void via_hp_automute(struct hda_codec *codec)
1668{
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001669 int present = 0;
Takashi Iwai6e969d92011-07-11 11:28:13 +02001670 int nums;
Harald Welte69e52a82008-09-09 15:57:32 +08001671 struct via_spec *spec = codec->spec;
1672
Takashi Iwai187d3332011-11-24 16:33:09 +01001673 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0] &&
Herton Ronaldo Krzesinskicf55e902012-09-21 20:45:19 -03001674 (spec->codec_type != VT1708 || spec->vt1708_jack_detect) &&
1675 is_jack_detectable(codec, spec->autocfg.hp_pins[0]))
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001676 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Takashi Iwai6e969d92011-07-11 11:28:13 +02001677
1678 if (spec->smart51_enabled)
1679 nums = spec->autocfg.line_outs + spec->smart51_nums;
1680 else
1681 nums = spec->autocfg.line_outs;
1682 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1683
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001684 via_line_automute(codec, present);
Lydia Wangf3db4232009-10-10 19:08:41 +08001685}
1686
Takashi Iwai2a439522011-07-26 09:52:50 +02001687#ifdef CONFIG_PM
Takashi Iwai68cb2b52012-07-02 15:20:37 +02001688static int via_suspend(struct hda_codec *codec)
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001689{
1690 struct via_spec *spec = codec->spec;
1691 vt1708_stop_hp_work(spec);
David Henningsson94c142a2012-08-09 10:56:12 +02001692
1693 if (spec->codec_type == VT1802) {
1694 /* Fix pop noise on headphones */
1695 int i;
1696 for (i = 0; i < spec->autocfg.hp_outs; i++)
1697 snd_hda_set_pin_ctl(codec, spec->autocfg.hp_pins[i], 0);
1698 }
1699
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001700 return 0;
1701}
1702#endif
1703
Takashi Iwai83012a72012-08-24 18:38:08 +02001704#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001705static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1706{
1707 struct via_spec *spec = codec->spec;
1708 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1709}
1710#endif
1711
Joseph Chanc577b8a2006-11-29 15:29:40 +01001712/*
1713 */
Takashi Iwai5d417622011-06-20 11:32:27 +02001714
1715static int via_init(struct hda_codec *codec);
1716
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001717static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001718 .build_controls = via_build_controls,
1719 .build_pcms = via_build_pcms,
1720 .init = via_init,
1721 .free = via_free,
David Henningsson4e2d16d2012-10-08 15:44:14 +02001722 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02001723#ifdef CONFIG_PM
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001724 .suspend = via_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02001725 .check_power_status = via_check_power_status,
1726#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001727};
1728
Takashi Iwai4a796162011-06-17 17:53:38 +02001729static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001730{
Takashi Iwai4a796162011-06-17 17:53:38 +02001731 struct via_spec *spec = codec->spec;
1732 int i;
1733
1734 for (i = 0; i < spec->multiout.num_dacs; i++) {
1735 if (spec->multiout.dac_nids[i] == dac)
1736 return false;
1737 }
Takashi Iwaiece8d042011-06-19 16:24:21 +02001738 if (spec->hp_dac_nid == dac)
Takashi Iwai4a796162011-06-17 17:53:38 +02001739 return false;
1740 return true;
1741}
1742
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001743static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai3214b962011-07-18 12:49:25 +02001744 hda_nid_t target_dac, int with_aa_mix,
1745 struct nid_path *path, int depth)
Takashi Iwai4a796162011-06-17 17:53:38 +02001746{
Takashi Iwai3214b962011-07-18 12:49:25 +02001747 struct via_spec *spec = codec->spec;
Takashi Iwai4a796162011-06-17 17:53:38 +02001748 hda_nid_t conn[8];
1749 int i, nums;
1750
Takashi Iwai3214b962011-07-18 12:49:25 +02001751 if (nid == spec->aa_mix_nid) {
1752 if (!with_aa_mix)
1753 return false;
1754 with_aa_mix = 2; /* mark aa-mix is included */
1755 }
1756
Takashi Iwai4a796162011-06-17 17:53:38 +02001757 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1758 for (i = 0; i < nums; i++) {
1759 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1760 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +02001761 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1762 /* aa-mix is requested but not included? */
1763 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1764 goto found;
1765 }
Takashi Iwai4a796162011-06-17 17:53:38 +02001766 }
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001767 if (depth >= MAX_NID_PATH_DEPTH)
Takashi Iwai4a796162011-06-17 17:53:38 +02001768 return false;
1769 for (i = 0; i < nums; i++) {
1770 unsigned int type;
1771 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai3214b962011-07-18 12:49:25 +02001772 if (type == AC_WID_AUD_OUT)
Takashi Iwai4a796162011-06-17 17:53:38 +02001773 continue;
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001774 if (__parse_output_path(codec, conn[i], target_dac,
Takashi Iwai3214b962011-07-18 12:49:25 +02001775 with_aa_mix, path, depth + 1))
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001776 goto found;
Takashi Iwai4a796162011-06-17 17:53:38 +02001777 }
1778 return false;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001779
1780 found:
1781 path->path[path->depth] = conn[i];
1782 path->idx[path->depth] = i;
1783 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1784 path->multi[path->depth] = 1;
1785 path->depth++;
1786 return true;
Takashi Iwai4a796162011-06-17 17:53:38 +02001787}
1788
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001789static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai3214b962011-07-18 12:49:25 +02001790 hda_nid_t target_dac, int with_aa_mix,
1791 struct nid_path *path)
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001792{
Takashi Iwai3214b962011-07-18 12:49:25 +02001793 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001794 path->path[path->depth] = nid;
1795 path->depth++;
Takashi Iwai3214b962011-07-18 12:49:25 +02001796 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1797 path->depth, path->path[0], path->path[1],
1798 path->path[2], path->path[3], path->path[4]);
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001799 return true;
1800 }
1801 return false;
1802}
1803
Takashi Iwai4a796162011-06-17 17:53:38 +02001804static int via_auto_fill_dac_nids(struct hda_codec *codec)
1805{
1806 struct via_spec *spec = codec->spec;
1807 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang5c9a5612011-07-08 14:03:43 +08001808 int i, dac_num;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001809 hda_nid_t nid;
1810
Joseph Chanc577b8a2006-11-29 15:29:40 +01001811 spec->multiout.dac_nids = spec->private_dac_nids;
Lydia Wang5c9a5612011-07-08 14:03:43 +08001812 dac_num = 0;
Takashi Iwai4a796162011-06-17 17:53:38 +02001813 for (i = 0; i < cfg->line_outs; i++) {
Takashi Iwai3214b962011-07-18 12:49:25 +02001814 hda_nid_t dac = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001815 nid = cfg->line_out_pins[i];
Takashi Iwai4a796162011-06-17 17:53:38 +02001816 if (!nid)
1817 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +02001818 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1819 dac = spec->out_path[i].path[0];
1820 if (!i && parse_output_path(codec, nid, dac, 1,
1821 &spec->out_mix_path))
1822 dac = spec->out_mix_path.path[0];
1823 if (dac) {
1824 spec->private_dac_nids[i] = dac;
Lydia Wang5c9a5612011-07-08 14:03:43 +08001825 dac_num++;
1826 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001827 }
Takashi Iwai3214b962011-07-18 12:49:25 +02001828 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1829 spec->out_path[0] = spec->out_mix_path;
1830 spec->out_mix_path.depth = 0;
1831 }
Lydia Wang5c9a5612011-07-08 14:03:43 +08001832 spec->multiout.num_dacs = dac_num;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001833 return 0;
1834}
1835
Takashi Iwai4a796162011-06-17 17:53:38 +02001836static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001837 int chs, bool check_dac, struct nid_path *path)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001838{
Takashi Iwai4a796162011-06-17 17:53:38 +02001839 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001840 char name[32];
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001841 hda_nid_t dac, pin, sel, nid;
1842 int err;
Takashi Iwaia934d5a2011-06-21 14:22:14 +02001843
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001844 dac = check_dac ? path->path[0] : 0;
1845 pin = path->path[path->depth - 1];
1846 sel = path->depth > 1 ? path->path[1] : 0;
Takashi Iwai4a796162011-06-17 17:53:38 +02001847
Takashi Iwai8df2a312011-06-21 11:48:29 +02001848 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
Takashi Iwai4a796162011-06-17 17:53:38 +02001849 nid = dac;
Takashi Iwai8df2a312011-06-21 11:48:29 +02001850 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
Takashi Iwai4a796162011-06-17 17:53:38 +02001851 nid = pin;
Takashi Iwaia934d5a2011-06-21 14:22:14 +02001852 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1853 nid = sel;
Takashi Iwai4a796162011-06-17 17:53:38 +02001854 else
1855 nid = 0;
1856 if (nid) {
1857 sprintf(name, "%s Playback Volume", pfx);
1858 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wanga00a5fa2011-06-21 16:11:11 +08001859 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
Takashi Iwai4a796162011-06-17 17:53:38 +02001860 if (err < 0)
1861 return err;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001862 path->vol_ctl = nid;
Takashi Iwai4a796162011-06-17 17:53:38 +02001863 }
1864
Takashi Iwai8df2a312011-06-21 11:48:29 +02001865 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
Takashi Iwai4a796162011-06-17 17:53:38 +02001866 nid = dac;
Takashi Iwai8df2a312011-06-21 11:48:29 +02001867 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
Takashi Iwai4a796162011-06-17 17:53:38 +02001868 nid = pin;
Takashi Iwaia934d5a2011-06-21 14:22:14 +02001869 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1870 nid = sel;
Takashi Iwai4a796162011-06-17 17:53:38 +02001871 else
1872 nid = 0;
1873 if (nid) {
1874 sprintf(name, "%s Playback Switch", pfx);
1875 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1876 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1877 if (err < 0)
1878 return err;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001879 path->mute_ctl = nid;
Takashi Iwai4a796162011-06-17 17:53:38 +02001880 }
1881 return 0;
1882}
1883
Takashi Iwaif4a78282011-06-17 18:46:48 +02001884static void mangle_smart51(struct hda_codec *codec)
1885{
1886 struct via_spec *spec = codec->spec;
1887 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0f98c242011-06-21 12:51:33 +02001888 struct auto_pin_cfg_item *ins = cfg->inputs;
1889 int i, j, nums, attr;
1890 int pins[AUTO_CFG_MAX_INS];
Takashi Iwaif4a78282011-06-17 18:46:48 +02001891
Takashi Iwai0f98c242011-06-21 12:51:33 +02001892 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1893 nums = 0;
1894 for (i = 0; i < cfg->num_inputs; i++) {
1895 unsigned int def;
1896 if (ins[i].type > AUTO_PIN_LINE_IN)
1897 continue;
1898 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1899 if (snd_hda_get_input_pin_attr(def) != attr)
1900 continue;
1901 for (j = 0; j < nums; j++)
1902 if (ins[pins[j]].type < ins[i].type) {
1903 memmove(pins + j + 1, pins + j,
Takashi Iwai21d45d22011-07-08 11:35:11 +02001904 (nums - j) * sizeof(int));
Takashi Iwai0f98c242011-06-21 12:51:33 +02001905 break;
1906 }
1907 pins[j] = i;
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001908 nums++;
Takashi Iwai0f98c242011-06-21 12:51:33 +02001909 }
1910 if (cfg->line_outs + nums < 3)
Takashi Iwaif4a78282011-06-17 18:46:48 +02001911 continue;
Takashi Iwai0f98c242011-06-21 12:51:33 +02001912 for (i = 0; i < nums; i++) {
1913 hda_nid_t pin = ins[pins[i]].pin;
1914 spec->smart51_pins[spec->smart51_nums++] = pin;
1915 cfg->line_out_pins[cfg->line_outs++] = pin;
1916 if (cfg->line_outs == 3)
1917 break;
1918 }
1919 return;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001920 }
1921}
1922
Takashi Iwai020066d2011-07-21 13:45:56 +02001923static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
1924{
1925 dst->vol_ctl = src->vol_ctl;
1926 dst->mute_ctl = src->mute_ctl;
1927}
1928
Takashi Iwai4a796162011-06-17 17:53:38 +02001929/* add playback controls from the parsed DAC table */
1930static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1931{
1932 struct via_spec *spec = codec->spec;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001933 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai3214b962011-07-18 12:49:25 +02001934 struct nid_path *path;
Takashi Iwaiea734962011-01-17 11:29:34 +01001935 static const char * const chname[4] = {
1936 "Front", "Surround", "C/LFE", "Side"
1937 };
Takashi Iwai4a796162011-06-17 17:53:38 +02001938 int i, idx, err;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001939 int old_line_outs;
1940
1941 /* check smart51 */
1942 old_line_outs = cfg->line_outs;
1943 if (cfg->line_outs == 1)
1944 mangle_smart51(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001945
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001946 err = via_auto_fill_dac_nids(codec);
1947 if (err < 0)
1948 return err;
1949
Lydia Wang5c9a5612011-07-08 14:03:43 +08001950 if (spec->multiout.num_dacs < 3) {
1951 spec->smart51_nums = 0;
1952 cfg->line_outs = old_line_outs;
1953 }
Takashi Iwai4a796162011-06-17 17:53:38 +02001954 for (i = 0; i < cfg->line_outs; i++) {
1955 hda_nid_t pin, dac;
1956 pin = cfg->line_out_pins[i];
1957 dac = spec->multiout.dac_nids[i];
1958 if (!pin || !dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001959 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +02001960 path = spec->out_path + i;
Takashi Iwai0fe0adf2011-06-19 16:27:53 +02001961 if (i == HDA_CLFE) {
Takashi Iwai3214b962011-07-18 12:49:25 +02001962 err = create_ch_ctls(codec, "Center", 1, true, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001963 if (err < 0)
1964 return err;
Takashi Iwai3214b962011-07-18 12:49:25 +02001965 err = create_ch_ctls(codec, "LFE", 2, true, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001966 if (err < 0)
1967 return err;
1968 } else {
Takashi Iwai6aadf412011-06-20 14:09:02 +02001969 const char *pfx = chname[i];
1970 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1971 cfg->line_outs == 1)
1972 pfx = "Speaker";
Takashi Iwai3214b962011-07-18 12:49:25 +02001973 err = create_ch_ctls(codec, pfx, 3, true, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001974 if (err < 0)
1975 return err;
1976 }
Takashi Iwai020066d2011-07-21 13:45:56 +02001977 if (path != spec->out_path + i)
1978 copy_path_mixer_ctls(&spec->out_path[i], path);
1979 if (path == spec->out_path && spec->out_mix_path.depth)
1980 copy_path_mixer_ctls(&spec->out_mix_path, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001981 }
1982
Takashi Iwai4a796162011-06-17 17:53:38 +02001983 idx = get_connection_index(codec, spec->aa_mix_nid,
1984 spec->multiout.dac_nids[0]);
1985 if (idx >= 0) {
1986 /* add control to mixer */
Takashi Iwai3214b962011-07-18 12:49:25 +02001987 const char *name;
1988 name = spec->out_mix_path.depth ?
1989 "PCM Loopback Playback Volume" : "PCM Playback Volume";
1990 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Takashi Iwai4a796162011-06-17 17:53:38 +02001991 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1992 idx, HDA_INPUT));
1993 if (err < 0)
1994 return err;
Takashi Iwai3214b962011-07-18 12:49:25 +02001995 name = spec->out_mix_path.depth ?
1996 "PCM Loopback Playback Switch" : "PCM Playback Switch";
1997 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Takashi Iwai4a796162011-06-17 17:53:38 +02001998 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1999 idx, HDA_INPUT));
2000 if (err < 0)
2001 return err;
2002 }
2003
Takashi Iwaif4a78282011-06-17 18:46:48 +02002004 cfg->line_outs = old_line_outs;
2005
Joseph Chanc577b8a2006-11-29 15:29:40 +01002006 return 0;
2007}
2008
Takashi Iwai4a796162011-06-17 17:53:38 +02002009static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002010{
Takashi Iwai4a796162011-06-17 17:53:38 +02002011 struct via_spec *spec = codec->spec;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02002012 struct nid_path *path;
Takashi Iwai18bd2c42011-07-04 15:55:44 +02002013 bool check_dac;
Takashi Iwai3214b962011-07-18 12:49:25 +02002014 int i, err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002015
2016 if (!pin)
2017 return 0;
2018
Takashi Iwai3214b962011-07-18 12:49:25 +02002019 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
2020 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
2021 if (i < spec->multiout.num_dacs &&
2022 parse_output_path(codec, pin,
2023 spec->multiout.dac_nids[i], 0,
2024 &spec->hp_indep_path)) {
2025 spec->hp_indep_shared = i;
2026 break;
2027 }
2028 }
Takashi Iwai25250502011-06-30 17:24:47 +02002029 }
Takashi Iwai3214b962011-07-18 12:49:25 +02002030 if (spec->hp_indep_path.depth) {
2031 spec->hp_dac_nid = spec->hp_indep_path.path[0];
2032 if (!spec->hp_indep_shared)
2033 spec->hp_path = spec->hp_indep_path;
2034 }
2035 /* optionally check front-path w/o AA-mix */
2036 if (!spec->hp_path.depth)
2037 parse_output_path(codec, pin,
2038 spec->multiout.dac_nids[HDA_FRONT], 0,
2039 &spec->hp_path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002040
Takashi Iwaiece8d042011-06-19 16:24:21 +02002041 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
Takashi Iwai3214b962011-07-18 12:49:25 +02002042 1, &spec->hp_mix_path) && !spec->hp_path.depth)
Takashi Iwaiece8d042011-06-19 16:24:21 +02002043 return 0;
2044
Takashi Iwai3214b962011-07-18 12:49:25 +02002045 if (spec->hp_path.depth) {
Takashi Iwai09a9ad692011-06-21 15:57:44 +02002046 path = &spec->hp_path;
Takashi Iwai18bd2c42011-07-04 15:55:44 +02002047 check_dac = true;
2048 } else {
Takashi Iwai3214b962011-07-18 12:49:25 +02002049 path = &spec->hp_mix_path;
Takashi Iwai18bd2c42011-07-04 15:55:44 +02002050 check_dac = false;
2051 }
2052 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002053 if (err < 0)
2054 return err;
Takashi Iwai020066d2011-07-21 13:45:56 +02002055 if (check_dac)
2056 copy_path_mixer_ctls(&spec->hp_mix_path, path);
2057 else
2058 copy_path_mixer_ctls(&spec->hp_path, path);
2059 if (spec->hp_indep_path.depth)
2060 copy_path_mixer_ctls(&spec->hp_indep_path, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002061 return 0;
2062}
2063
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002064static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2065{
2066 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +02002067 struct nid_path *path;
2068 bool check_dac;
Wang Shaoyan81c0a782011-08-05 18:51:29 +08002069 hda_nid_t pin, dac = 0;
Takashi Iwai3214b962011-07-18 12:49:25 +02002070 int err;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002071
2072 pin = spec->autocfg.speaker_pins[0];
2073 if (!spec->autocfg.speaker_outs || !pin)
2074 return 0;
2075
Takashi Iwai3214b962011-07-18 12:49:25 +02002076 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
Takashi Iwai8e3679d2011-06-21 09:01:36 +02002077 dac = spec->speaker_path.path[0];
Takashi Iwai3214b962011-07-18 12:49:25 +02002078 if (!dac)
2079 parse_output_path(codec, pin,
2080 spec->multiout.dac_nids[HDA_FRONT], 0,
2081 &spec->speaker_path);
2082 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2083 1, &spec->speaker_mix_path) && !dac)
2084 return 0;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002085
Takashi Iwai3214b962011-07-18 12:49:25 +02002086 /* no AA-path for front? */
2087 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2088 dac = 0;
2089
2090 spec->speaker_dac_nid = dac;
2091 spec->multiout.extra_out_nid[0] = dac;
2092 if (dac) {
2093 path = &spec->speaker_path;
2094 check_dac = true;
2095 } else {
2096 path = &spec->speaker_mix_path;
2097 check_dac = false;
2098 }
2099 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2100 if (err < 0)
2101 return err;
Takashi Iwai020066d2011-07-21 13:45:56 +02002102 if (check_dac)
2103 copy_path_mixer_ctls(&spec->speaker_mix_path, path);
2104 else
2105 copy_path_mixer_ctls(&spec->speaker_path, path);
Takashi Iwai3214b962011-07-18 12:49:25 +02002106 return 0;
2107}
2108
2109#define via_aamix_ctl_info via_pin_power_ctl_info
2110
2111static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2112 struct snd_ctl_elem_value *ucontrol)
2113{
2114 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2115 struct via_spec *spec = codec->spec;
2116 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2117 return 0;
2118}
2119
2120static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2121 struct nid_path *nomix, struct nid_path *mix)
2122{
2123 if (do_mix) {
2124 activate_output_path(codec, nomix, false, false);
2125 activate_output_path(codec, mix, true, false);
2126 } else {
2127 activate_output_path(codec, mix, false, false);
2128 activate_output_path(codec, nomix, true, false);
2129 }
2130}
2131
2132static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2133 struct snd_ctl_elem_value *ucontrol)
2134{
2135 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2136 struct via_spec *spec = codec->spec;
2137 unsigned int val = ucontrol->value.enumerated.item[0];
2138
2139 if (val == spec->aamix_mode)
2140 return 0;
2141 spec->aamix_mode = val;
2142 /* update front path */
2143 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2144 /* update HP path */
2145 if (!spec->hp_independent_mode) {
2146 update_aamix_paths(codec, val, &spec->hp_path,
2147 &spec->hp_mix_path);
2148 }
2149 /* update speaker path */
2150 update_aamix_paths(codec, val, &spec->speaker_path,
2151 &spec->speaker_mix_path);
2152 return 1;
2153}
2154
2155static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2156 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2157 .name = "Loopback Mixing",
2158 .info = via_aamix_ctl_info,
2159 .get = via_aamix_ctl_get,
2160 .put = via_aamix_ctl_put,
2161};
2162
2163static int via_auto_create_loopback_switch(struct hda_codec *codec)
2164{
2165 struct via_spec *spec = codec->spec;
2166
Takashi Iwai4808d122012-01-10 15:16:02 +01002167 if (!spec->aa_mix_nid)
2168 return 0; /* no loopback switching available */
2169 if (!(spec->out_mix_path.depth || spec->hp_mix_path.depth ||
2170 spec->speaker_path.depth))
Takashi Iwai3214b962011-07-18 12:49:25 +02002171 return 0; /* no loopback switching available */
2172 if (!via_clone_control(spec, &via_aamix_ctl_enum))
2173 return -ENOMEM;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002174 return 0;
2175}
2176
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002177/* look for ADCs */
2178static int via_fill_adcs(struct hda_codec *codec)
2179{
2180 struct via_spec *spec = codec->spec;
2181 hda_nid_t nid = codec->start_nid;
2182 int i;
2183
2184 for (i = 0; i < codec->num_nodes; i++, nid++) {
2185 unsigned int wcaps = get_wcaps(codec, nid);
2186 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2187 continue;
2188 if (wcaps & AC_WCAP_DIGITAL)
2189 continue;
2190 if (!(wcaps & AC_WCAP_CONN_LIST))
2191 continue;
2192 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2193 return -ENOMEM;
2194 spec->adc_nids[spec->num_adc_nids++] = nid;
2195 }
2196 return 0;
2197}
2198
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002199/* input-src control */
2200static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
2201 struct snd_ctl_elem_info *uinfo)
2202{
2203 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2204 struct via_spec *spec = codec->spec;
2205
2206 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2207 uinfo->count = 1;
2208 uinfo->value.enumerated.items = spec->num_inputs;
2209 if (uinfo->value.enumerated.item >= spec->num_inputs)
2210 uinfo->value.enumerated.item = spec->num_inputs - 1;
2211 strcpy(uinfo->value.enumerated.name,
2212 spec->inputs[uinfo->value.enumerated.item].label);
2213 return 0;
2214}
2215
2216static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2217 struct snd_ctl_elem_value *ucontrol)
2218{
2219 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2220 struct via_spec *spec = codec->spec;
2221 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2222
2223 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2224 return 0;
2225}
2226
2227static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2228 struct snd_ctl_elem_value *ucontrol)
2229{
2230 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2231 struct via_spec *spec = codec->spec;
2232 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2233 hda_nid_t mux;
2234 int cur;
2235
2236 cur = ucontrol->value.enumerated.item[0];
2237 if (cur < 0 || cur >= spec->num_inputs)
2238 return -EINVAL;
2239 if (spec->cur_mux[idx] == cur)
2240 return 0;
2241 spec->cur_mux[idx] = cur;
2242 if (spec->dyn_adc_switch) {
2243 int adc_idx = spec->inputs[cur].adc_idx;
2244 mux = spec->mux_nids[adc_idx];
2245 via_dyn_adc_pcm_resetup(codec, cur);
2246 } else {
2247 mux = spec->mux_nids[idx];
2248 if (snd_BUG_ON(!mux))
2249 return -EINVAL;
2250 }
2251
2252 if (mux) {
2253 /* switch to D0 beofre change index */
Takashi Iwai054d8672012-01-24 12:25:50 +01002254 update_power_state(codec, mux, AC_PWRST_D0);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002255 snd_hda_codec_write(codec, mux, 0,
2256 AC_VERB_SET_CONNECT_SEL,
2257 spec->inputs[cur].mux_idx);
2258 }
2259
2260 /* update jack power state */
2261 set_widgets_power_state(codec);
2262 return 0;
2263}
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002264
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002265static const struct snd_kcontrol_new via_input_src_ctl = {
2266 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2267 /* The multiple "Capture Source" controls confuse alsamixer
2268 * So call somewhat different..
2269 */
2270 /* .name = "Capture Source", */
2271 .name = "Input Source",
2272 .info = via_mux_enum_info,
2273 .get = via_mux_enum_get,
2274 .put = via_mux_enum_put,
2275};
2276
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002277static int create_input_src_ctls(struct hda_codec *codec, int count)
2278{
2279 struct via_spec *spec = codec->spec;
2280 struct snd_kcontrol_new *knew;
2281
2282 if (spec->num_inputs <= 1 || !count)
2283 return 0; /* no need for single src */
2284
2285 knew = via_clone_control(spec, &via_input_src_ctl);
2286 if (!knew)
2287 return -ENOMEM;
2288 knew->count = count;
2289 return 0;
2290}
2291
2292/* add the powersave loopback-list entry */
Takashi Iwai13af8e72011-06-20 14:05:46 +02002293static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2294{
2295 struct hda_amp_list *list;
2296
2297 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2298 return;
2299 list = spec->loopback_list + spec->num_loopbacks;
2300 list->nid = mix;
2301 list->dir = HDA_INPUT;
2302 list->idx = idx;
2303 spec->num_loopbacks++;
2304 spec->loopback.amplist = spec->loopback_list;
2305}
Takashi Iwai13af8e72011-06-20 14:05:46 +02002306
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002307static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
Takashi Iwai8d087c72011-06-28 12:45:47 +02002308 hda_nid_t dst)
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002309{
Takashi Iwai8d087c72011-06-28 12:45:47 +02002310 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002311}
2312
2313/* add the input-route to the given pin */
2314static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002315{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002316 struct via_spec *spec = codec->spec;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002317 int c, idx;
2318
2319 spec->inputs[spec->num_inputs].adc_idx = -1;
2320 spec->inputs[spec->num_inputs].pin = pin;
2321 for (c = 0; c < spec->num_adc_nids; c++) {
2322 if (spec->mux_nids[c]) {
2323 idx = get_connection_index(codec, spec->mux_nids[c],
2324 pin);
2325 if (idx < 0)
2326 continue;
2327 spec->inputs[spec->num_inputs].mux_idx = idx;
2328 } else {
Takashi Iwai8d087c72011-06-28 12:45:47 +02002329 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002330 continue;
2331 }
2332 spec->inputs[spec->num_inputs].adc_idx = c;
2333 /* Can primary ADC satisfy all inputs? */
2334 if (!spec->dyn_adc_switch &&
2335 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2336 snd_printd(KERN_INFO
2337 "via: dynamic ADC switching enabled\n");
2338 spec->dyn_adc_switch = 1;
2339 }
2340 return true;
2341 }
2342 return false;
2343}
2344
2345static int get_mux_nids(struct hda_codec *codec);
2346
2347/* parse input-routes; fill ADCs, MUXs and input-src entries */
2348static int parse_analog_inputs(struct hda_codec *codec)
2349{
2350 struct via_spec *spec = codec->spec;
2351 const struct auto_pin_cfg *cfg = &spec->autocfg;
2352 int i, err;
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002353
2354 err = via_fill_adcs(codec);
2355 if (err < 0)
2356 return err;
2357 err = get_mux_nids(codec);
2358 if (err < 0)
2359 return err;
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002360
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002361 /* fill all input-routes */
2362 for (i = 0; i < cfg->num_inputs; i++) {
2363 if (add_input_route(codec, cfg->inputs[i].pin))
2364 spec->inputs[spec->num_inputs++].label =
2365 hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwaif3268512010-08-30 11:00:19 +02002366 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002367
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002368 /* check for internal loopback recording */
2369 if (spec->aa_mix_nid &&
2370 add_input_route(codec, spec->aa_mix_nid))
2371 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2372
2373 return 0;
2374}
2375
2376/* create analog-loopback volume/switch controls */
2377static int create_loopback_ctls(struct hda_codec *codec)
2378{
2379 struct via_spec *spec = codec->spec;
2380 const struct auto_pin_cfg *cfg = &spec->autocfg;
2381 const char *prev_label = NULL;
2382 int type_idx = 0;
2383 int i, j, err, idx;
2384
2385 if (!spec->aa_mix_nid)
2386 return 0;
2387
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002388 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002389 hda_nid_t pin = cfg->inputs[i].pin;
2390 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2391
Takashi Iwai1e11cae2011-06-21 12:57:22 +02002392 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002393 type_idx++;
2394 else
2395 type_idx = 0;
Takashi Iwai1e11cae2011-06-21 12:57:22 +02002396 prev_label = label;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002397 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2398 if (idx >= 0) {
Lydia Wang16922282011-03-22 16:24:10 +08002399 err = via_new_analog_input(spec, label, type_idx,
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002400 idx, spec->aa_mix_nid);
Takashi Iwai13af8e72011-06-20 14:05:46 +02002401 if (err < 0)
2402 return err;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002403 add_loopback_list(spec, spec->aa_mix_nid, idx);
Takashi Iwai13af8e72011-06-20 14:05:46 +02002404 }
Takashi Iwaie3d7a142011-06-20 13:52:33 +02002405
2406 /* remember the label for smart51 control */
2407 for (j = 0; j < spec->smart51_nums; j++) {
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002408 if (spec->smart51_pins[j] == pin) {
Takashi Iwaie3d7a142011-06-20 13:52:33 +02002409 spec->smart51_idxs[j] = idx;
2410 spec->smart51_labels[j] = label;
2411 break;
2412 }
2413 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002414 }
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002415 return 0;
2416}
2417
2418/* create mic-boost controls (if present) */
2419static int create_mic_boost_ctls(struct hda_codec *codec)
2420{
2421 struct via_spec *spec = codec->spec;
2422 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8d8bbc62012-02-22 12:26:38 +01002423 const char *prev_label = NULL;
2424 int type_idx = 0;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002425 int i, err;
2426
2427 for (i = 0; i < cfg->num_inputs; i++) {
2428 hda_nid_t pin = cfg->inputs[i].pin;
2429 unsigned int caps;
2430 const char *label;
2431 char name[32];
2432
2433 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2434 continue;
2435 caps = query_amp_caps(codec, pin, HDA_INPUT);
2436 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2437 continue;
2438 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai8d8bbc62012-02-22 12:26:38 +01002439 if (prev_label && !strcmp(label, prev_label))
2440 type_idx++;
2441 else
2442 type_idx = 0;
2443 prev_label = label;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002444 snprintf(name, sizeof(name), "%s Boost Volume", label);
Takashi Iwai8d8bbc62012-02-22 12:26:38 +01002445 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002446 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2447 if (err < 0)
2448 return err;
2449 }
2450 return 0;
2451}
2452
2453/* create capture and input-src controls for multiple streams */
2454static int create_multi_adc_ctls(struct hda_codec *codec)
2455{
2456 struct via_spec *spec = codec->spec;
2457 int i, err;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002458
2459 /* create capture mixer elements */
2460 for (i = 0; i < spec->num_adc_nids; i++) {
2461 hda_nid_t adc = spec->adc_nids[i];
2462 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2463 "Capture Volume", i,
2464 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2465 HDA_INPUT));
2466 if (err < 0)
2467 return err;
2468 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2469 "Capture Switch", i,
2470 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2471 HDA_INPUT));
2472 if (err < 0)
2473 return err;
2474 }
2475
2476 /* input-source control */
2477 for (i = 0; i < spec->num_adc_nids; i++)
2478 if (!spec->mux_nids[i])
2479 break;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002480 err = create_input_src_ctls(codec, i);
2481 if (err < 0)
2482 return err;
2483 return 0;
2484}
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002485
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002486/* bind capture volume/switch */
2487static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2488 HDA_BIND_VOL("Capture Volume", 0);
2489static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2490 HDA_BIND_SW("Capture Switch", 0);
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002491
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002492static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2493 struct hda_ctl_ops *ops)
2494{
2495 struct hda_bind_ctls *ctl;
2496 int i;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002497
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002498 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2499 if (!ctl)
2500 return -ENOMEM;
2501 ctl->ops = ops;
2502 for (i = 0; i < spec->num_adc_nids; i++)
2503 ctl->values[i] =
2504 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2505 *ctl_ret = ctl;
2506 return 0;
2507}
2508
2509/* create capture and input-src controls for dynamic ADC-switch case */
2510static int create_dyn_adc_ctls(struct hda_codec *codec)
2511{
2512 struct via_spec *spec = codec->spec;
2513 struct snd_kcontrol_new *knew;
2514 int err;
2515
2516 /* set up the bind capture ctls */
2517 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2518 if (err < 0)
2519 return err;
2520 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2521 if (err < 0)
2522 return err;
2523
2524 /* create capture mixer elements */
2525 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2526 if (!knew)
2527 return -ENOMEM;
2528 knew->private_value = (long)spec->bind_cap_vol;
2529
2530 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2531 if (!knew)
2532 return -ENOMEM;
2533 knew->private_value = (long)spec->bind_cap_sw;
2534
2535 /* input-source control */
2536 err = create_input_src_ctls(codec, 1);
2537 if (err < 0)
2538 return err;
2539 return 0;
2540}
2541
2542/* parse and create capture-related stuff */
2543static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2544{
2545 struct via_spec *spec = codec->spec;
2546 int err;
2547
2548 err = parse_analog_inputs(codec);
2549 if (err < 0)
2550 return err;
2551 if (spec->dyn_adc_switch)
2552 err = create_dyn_adc_ctls(codec);
2553 else
2554 err = create_multi_adc_ctls(codec);
2555 if (err < 0)
2556 return err;
2557 err = create_loopback_ctls(codec);
2558 if (err < 0)
2559 return err;
2560 err = create_mic_boost_ctls(codec);
2561 if (err < 0)
2562 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002563 return 0;
2564}
2565
Harald Welte76d9b0d2008-09-09 15:50:37 +08002566static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2567{
2568 unsigned int def_conf;
2569 unsigned char seqassoc;
2570
Takashi Iwai2f334f92009-02-20 14:37:42 +01002571 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002572 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2573 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002574 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2575 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2576 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2577 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002578 }
2579
2580 return;
2581}
2582
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002583static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002584 struct snd_ctl_elem_value *ucontrol)
2585{
2586 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2587 struct via_spec *spec = codec->spec;
2588
2589 if (spec->codec_type != VT1708)
2590 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002591 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002592 return 0;
2593}
2594
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002595static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002596 struct snd_ctl_elem_value *ucontrol)
2597{
2598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2599 struct via_spec *spec = codec->spec;
Takashi Iwai187d3332011-11-24 16:33:09 +01002600 int val;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002601
2602 if (spec->codec_type != VT1708)
2603 return 0;
Takashi Iwai187d3332011-11-24 16:33:09 +01002604 val = !!ucontrol->value.integer.value[0];
2605 if (spec->vt1708_jack_detect == val)
2606 return 0;
2607 spec->vt1708_jack_detect = val;
2608 if (spec->vt1708_jack_detect &&
2609 snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002610 mute_aa_path(codec, 1);
2611 notify_aa_path_ctls(codec);
2612 }
Takashi Iwai187d3332011-11-24 16:33:09 +01002613 via_hp_automute(codec);
2614 vt1708_update_hp_work(spec);
2615 return 1;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002616}
2617
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002618static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2619 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2620 .name = "Jack Detect",
2621 .count = 1,
2622 .info = snd_ctl_boolean_mono_info,
2623 .get = vt1708_jack_detect_get,
2624 .put = vt1708_jack_detect_put,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002625};
2626
Takashi Iwai12daef62011-06-18 17:45:49 +02002627static void fill_dig_outs(struct hda_codec *codec);
2628static void fill_dig_in(struct hda_codec *codec);
2629
2630static int via_parse_auto_config(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002631{
2632 struct via_spec *spec = codec->spec;
2633 int err;
2634
2635 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2636 if (err < 0)
2637 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002638 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
Takashi Iwai7f0df882011-06-18 17:33:34 +02002639 return -EINVAL;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002640
Takashi Iwai4a796162011-06-17 17:53:38 +02002641 err = via_auto_create_multi_out_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002642 if (err < 0)
2643 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002644 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002645 if (err < 0)
2646 return err;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002647 err = via_auto_create_speaker_ctls(codec);
2648 if (err < 0)
2649 return err;
Takashi Iwai3214b962011-07-18 12:49:25 +02002650 err = via_auto_create_loopback_switch(codec);
2651 if (err < 0)
2652 return err;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002653 err = via_auto_create_analog_input_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002654 if (err < 0)
2655 return err;
2656
2657 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2658
Takashi Iwai12daef62011-06-18 17:45:49 +02002659 fill_dig_outs(codec);
2660 fill_dig_in(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002661
Takashi Iwai603c4012008-07-30 15:01:44 +02002662 if (spec->kctls.list)
2663 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002664
Joseph Chanc577b8a2006-11-29 15:29:40 +01002665
Takashi Iwai3214b962011-07-18 12:49:25 +02002666 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
Takashi Iwaiece8d042011-06-19 16:24:21 +02002667 err = via_hp_build(codec);
2668 if (err < 0)
2669 return err;
2670 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002671
Takashi Iwaif4a78282011-06-17 18:46:48 +02002672 err = via_smart51_build(codec);
2673 if (err < 0)
2674 return err;
2675
Takashi Iwai5d417622011-06-20 11:32:27 +02002676 /* assign slave outs */
2677 if (spec->slave_dig_outs[0])
2678 codec->slave_dig_outs = spec->slave_dig_outs;
2679
Joseph Chanc577b8a2006-11-29 15:29:40 +01002680 return 1;
2681}
2682
Takashi Iwai5d417622011-06-20 11:32:27 +02002683static void via_auto_init_dig_outs(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002684{
Lydia Wang25eaba22009-10-10 19:08:43 +08002685 struct via_spec *spec = codec->spec;
Takashi Iwai5d417622011-06-20 11:32:27 +02002686 if (spec->multiout.dig_out_nid)
2687 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2688 if (spec->slave_dig_outs[0])
2689 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2690}
Lydia Wang25eaba22009-10-10 19:08:43 +08002691
Takashi Iwai5d417622011-06-20 11:32:27 +02002692static void via_auto_init_dig_in(struct hda_codec *codec)
2693{
2694 struct via_spec *spec = codec->spec;
2695 if (!spec->dig_in_nid)
2696 return;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002697 snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN);
Takashi Iwai5d417622011-06-20 11:32:27 +02002698}
2699
David Henningsson4e2d16d2012-10-08 15:44:14 +02002700static void via_jack_output_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2701{
2702 set_widgets_power_state(codec);
2703 via_hp_automute(codec);
2704}
2705
2706static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2707{
2708 set_widgets_power_state(codec);
2709}
2710
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002711/* initialize the unsolicited events */
2712static void via_auto_init_unsol_event(struct hda_codec *codec)
2713{
2714 struct via_spec *spec = codec->spec;
2715 struct auto_pin_cfg *cfg = &spec->autocfg;
2716 unsigned int ev;
2717 int i;
David Henningsson4e2d16d2012-10-08 15:44:14 +02002718 hda_jack_callback cb;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002719
2720 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
David Henningsson4e2d16d2012-10-08 15:44:14 +02002721 snd_hda_jack_detect_enable_callback(codec, cfg->hp_pins[0],
2722 VIA_HP_EVENT | VIA_JACK_EVENT,
2723 via_jack_output_event);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002724
2725 if (cfg->speaker_pins[0])
2726 ev = VIA_LINE_EVENT;
2727 else
2728 ev = 0;
David Henningsson4e2d16d2012-10-08 15:44:14 +02002729 cb = ev ? via_jack_output_event : via_jack_powerstate_event;
2730
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002731 for (i = 0; i < cfg->line_outs; i++) {
2732 if (cfg->line_out_pins[i] &&
2733 is_jack_detectable(codec, cfg->line_out_pins[i]))
David Henningsson4e2d16d2012-10-08 15:44:14 +02002734 snd_hda_jack_detect_enable_callback(codec, cfg->line_out_pins[i],
2735 ev | VIA_JACK_EVENT, cb);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002736 }
2737
2738 for (i = 0; i < cfg->num_inputs; i++) {
2739 if (is_jack_detectable(codec, cfg->inputs[i].pin))
David Henningsson4e2d16d2012-10-08 15:44:14 +02002740 snd_hda_jack_detect_enable_callback(codec, cfg->inputs[i].pin,
2741 VIA_JACK_EVENT,
2742 via_jack_powerstate_event);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002743 }
2744}
2745
Takashi Iwai5d417622011-06-20 11:32:27 +02002746static int via_init(struct hda_codec *codec)
2747{
2748 struct via_spec *spec = codec->spec;
2749 int i;
2750
2751 for (i = 0; i < spec->num_iverbs; i++)
2752 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2753
Takashi Iwaie9d010c2012-02-01 10:33:23 +01002754 /* init power states */
2755 set_widgets_power_state(codec);
2756 __analog_low_current_mode(codec, true);
2757
Joseph Chanc577b8a2006-11-29 15:29:40 +01002758 via_auto_init_multi_out(codec);
2759 via_auto_init_hp_out(codec);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002760 via_auto_init_speaker_out(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002761 via_auto_init_analog_input(codec);
Takashi Iwai5d417622011-06-20 11:32:27 +02002762 via_auto_init_dig_outs(codec);
2763 via_auto_init_dig_in(codec);
Lydia Wang118909562011-03-23 17:57:34 +08002764
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002765 via_auto_init_unsol_event(codec);
2766
2767 via_hp_automute(codec);
Takashi Iwai187d3332011-11-24 16:33:09 +01002768 vt1708_update_hp_work(spec);
Lydia Wang25eaba22009-10-10 19:08:43 +08002769
Joseph Chanc577b8a2006-11-29 15:29:40 +01002770 return 0;
2771}
2772
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002773static void vt1708_update_hp_jack_state(struct work_struct *work)
2774{
2775 struct via_spec *spec = container_of(work, struct via_spec,
2776 vt1708_hp_work.work);
2777 if (spec->codec_type != VT1708)
2778 return;
Takashi Iwai1835a0f2011-10-27 22:12:46 +02002779 snd_hda_jack_set_dirty_all(spec->codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002780 /* if jack state toggled */
2781 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002782 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002783 spec->vt1708_hp_present ^= 1;
2784 via_hp_automute(spec->codec);
2785 }
Takashi Iwai187d3332011-11-24 16:33:09 +01002786 if (spec->vt1708_jack_detect)
2787 schedule_delayed_work(&spec->vt1708_hp_work,
2788 msecs_to_jiffies(100));
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002789}
2790
Takashi Iwai337b9d02009-07-07 18:18:59 +02002791static int get_mux_nids(struct hda_codec *codec)
2792{
2793 struct via_spec *spec = codec->spec;
2794 hda_nid_t nid, conn[8];
2795 unsigned int type;
2796 int i, n;
2797
2798 for (i = 0; i < spec->num_adc_nids; i++) {
2799 nid = spec->adc_nids[i];
2800 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002801 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002802 if (type == AC_WID_PIN)
2803 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002804 n = snd_hda_get_connections(codec, nid, conn,
2805 ARRAY_SIZE(conn));
2806 if (n <= 0)
2807 break;
2808 if (n > 1) {
2809 spec->mux_nids[i] = nid;
2810 break;
2811 }
2812 nid = conn[0];
2813 }
2814 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002815 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002816}
2817
Joseph Chanc577b8a2006-11-29 15:29:40 +01002818static int patch_vt1708(struct hda_codec *codec)
2819{
2820 struct via_spec *spec;
2821 int err;
2822
2823 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002824 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002825 if (spec == NULL)
2826 return -ENOMEM;
2827
Takashi Iwai620e2b22011-06-17 17:19:19 +02002828 spec->aa_mix_nid = 0x17;
2829
Takashi Iwai12daef62011-06-18 17:45:49 +02002830 /* Add HP and CD pin config connect bit re-config action */
2831 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2832 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2833
Joseph Chanc577b8a2006-11-29 15:29:40 +01002834 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002835 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002836 if (err < 0) {
2837 via_free(codec);
2838 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002839 }
2840
Takashi Iwai12daef62011-06-18 17:45:49 +02002841 /* add jack detect on/off control */
2842 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2843 return -ENOMEM;
2844
Takashi Iwaibc9b5622008-05-23 17:50:27 +02002845 /* disable 32bit format on VT1708 */
2846 if (codec->vendor_id == 0x11061708)
2847 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002848
Lydia Wange322a362011-06-29 13:52:02 +08002849 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2850
Joseph Chanc577b8a2006-11-29 15:29:40 +01002851 codec->patch_ops = via_patch_ops;
2852
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002853 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002854 return 0;
2855}
2856
Takashi Iwaiddd304d2011-06-21 16:33:55 +02002857static int patch_vt1709(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002858{
2859 struct via_spec *spec;
2860 int err;
2861
2862 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002863 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002864 if (spec == NULL)
2865 return -ENOMEM;
2866
Takashi Iwai620e2b22011-06-17 17:19:19 +02002867 spec->aa_mix_nid = 0x18;
2868
Takashi Iwai12daef62011-06-18 17:45:49 +02002869 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002870 if (err < 0) {
2871 via_free(codec);
2872 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002873 }
2874
Joseph Chanc577b8a2006-11-29 15:29:40 +01002875 codec->patch_ops = via_patch_ops;
2876
Josepch Chanf7278fd2007-12-13 16:40:40 +01002877 return 0;
2878}
2879
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002880static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2881{
2882 struct via_spec *spec = codec->spec;
2883 int imux_is_smixer;
2884 unsigned int parm;
2885 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +08002886 if ((spec->codec_type != VT1708B_4CH) &&
2887 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002888 is_8ch = 1;
2889
2890 /* SW0 (17h) = stereo mixer */
2891 imux_is_smixer =
2892 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2893 == ((spec->codec_type == VT1708S) ? 5 : 0));
2894 /* inputs */
2895 /* PW 1/2/5 (1ah/1bh/1eh) */
2896 parm = AC_PWRST_D3;
2897 set_pin_power_state(codec, 0x1a, &parm);
2898 set_pin_power_state(codec, 0x1b, &parm);
2899 set_pin_power_state(codec, 0x1e, &parm);
2900 if (imux_is_smixer)
2901 parm = AC_PWRST_D0;
2902 /* SW0 (17h), AIW 0/1 (13h/14h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01002903 update_power_state(codec, 0x17, parm);
2904 update_power_state(codec, 0x13, parm);
2905 update_power_state(codec, 0x14, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002906
2907 /* outputs */
2908 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2909 parm = AC_PWRST_D3;
2910 set_pin_power_state(codec, 0x19, &parm);
2911 if (spec->smart51_enabled)
2912 set_pin_power_state(codec, 0x1b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01002913 update_power_state(codec, 0x18, parm);
2914 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002915
2916 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2917 if (is_8ch) {
2918 parm = AC_PWRST_D3;
2919 set_pin_power_state(codec, 0x22, &parm);
2920 if (spec->smart51_enabled)
2921 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01002922 update_power_state(codec, 0x26, parm);
2923 update_power_state(codec, 0x24, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002924 } else if (codec->vendor_id == 0x11064397) {
2925 /* PW7(23h), SW2(27h), AOW2(25h) */
2926 parm = AC_PWRST_D3;
2927 set_pin_power_state(codec, 0x23, &parm);
2928 if (spec->smart51_enabled)
2929 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01002930 update_power_state(codec, 0x27, parm);
2931 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002932 }
2933
2934 /* PW 3/4/7 (1ch/1dh/23h) */
2935 parm = AC_PWRST_D3;
2936 /* force to D0 for internal Speaker */
2937 set_pin_power_state(codec, 0x1c, &parm);
2938 set_pin_power_state(codec, 0x1d, &parm);
2939 if (is_8ch)
2940 set_pin_power_state(codec, 0x23, &parm);
2941
2942 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01002943 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
2944 update_power_state(codec, 0x10, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002945 if (is_8ch) {
Takashi Iwai054d8672012-01-24 12:25:50 +01002946 update_power_state(codec, 0x25, parm);
2947 update_power_state(codec, 0x27, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002948 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
Takashi Iwai054d8672012-01-24 12:25:50 +01002949 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002950}
2951
Lydia Wang518bf3b2009-10-10 19:07:29 +08002952static int patch_vt1708S(struct hda_codec *codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +02002953static int patch_vt1708B(struct hda_codec *codec)
Josepch Chanf7278fd2007-12-13 16:40:40 +01002954{
2955 struct via_spec *spec;
2956 int err;
2957
Lydia Wang518bf3b2009-10-10 19:07:29 +08002958 if (get_codec_type(codec) == VT1708BCE)
2959 return patch_vt1708S(codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +02002960
Josepch Chanf7278fd2007-12-13 16:40:40 +01002961 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002962 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002963 if (spec == NULL)
2964 return -ENOMEM;
2965
Takashi Iwai620e2b22011-06-17 17:19:19 +02002966 spec->aa_mix_nid = 0x16;
2967
Josepch Chanf7278fd2007-12-13 16:40:40 +01002968 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002969 err = via_parse_auto_config(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002970 if (err < 0) {
2971 via_free(codec);
2972 return err;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002973 }
2974
Josepch Chanf7278fd2007-12-13 16:40:40 +01002975 codec->patch_ops = via_patch_ops;
2976
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002977 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2978
Josepch Chanf7278fd2007-12-13 16:40:40 +01002979 return 0;
2980}
2981
Harald Welted949cac2008-09-09 15:56:01 +08002982/* Patch for VT1708S */
Takashi Iwai096a8852011-06-20 12:09:02 +02002983static const struct hda_verb vt1708S_init_verbs[] = {
Harald Welted7426322008-09-15 22:43:23 +08002984 /* Enable Mic Boost Volume backdoor */
2985 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08002986 /* don't bybass mixer */
2987 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08002988 { }
2989};
2990
Takashi Iwai9da29272009-05-07 16:31:14 +02002991/* fill out digital output widgets; one for master and one for slave outputs */
2992static void fill_dig_outs(struct hda_codec *codec)
2993{
2994 struct via_spec *spec = codec->spec;
2995 int i;
2996
2997 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2998 hda_nid_t nid;
2999 int conn;
3000
3001 nid = spec->autocfg.dig_out_pins[i];
3002 if (!nid)
3003 continue;
3004 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3005 if (conn < 1)
3006 continue;
3007 if (!spec->multiout.dig_out_nid)
3008 spec->multiout.dig_out_nid = nid;
3009 else {
3010 spec->slave_dig_outs[0] = nid;
3011 break; /* at most two dig outs */
3012 }
3013 }
3014}
3015
Takashi Iwai12daef62011-06-18 17:45:49 +02003016static void fill_dig_in(struct hda_codec *codec)
Harald Welted949cac2008-09-09 15:56:01 +08003017{
3018 struct via_spec *spec = codec->spec;
Takashi Iwai12daef62011-06-18 17:45:49 +02003019 hda_nid_t dig_nid;
3020 int i, err;
Harald Welted949cac2008-09-09 15:56:01 +08003021
Takashi Iwai12daef62011-06-18 17:45:49 +02003022 if (!spec->autocfg.dig_in_pin)
3023 return;
Harald Welted949cac2008-09-09 15:56:01 +08003024
Takashi Iwai12daef62011-06-18 17:45:49 +02003025 dig_nid = codec->start_nid;
3026 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3027 unsigned int wcaps = get_wcaps(codec, dig_nid);
3028 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3029 continue;
3030 if (!(wcaps & AC_WCAP_DIGITAL))
3031 continue;
3032 if (!(wcaps & AC_WCAP_CONN_LIST))
3033 continue;
3034 err = get_connection_index(codec, dig_nid,
3035 spec->autocfg.dig_in_pin);
3036 if (err >= 0) {
3037 spec->dig_in_nid = dig_nid;
3038 break;
3039 }
3040 }
Harald Welted949cac2008-09-09 15:56:01 +08003041}
3042
Lydia Wang6369bcf2009-10-10 19:08:31 +08003043static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3044 int offset, int num_steps, int step_size)
3045{
3046 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3047 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3048 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3049 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3050 (0 << AC_AMPCAP_MUTE_SHIFT));
3051}
3052
Harald Welted949cac2008-09-09 15:56:01 +08003053static int patch_vt1708S(struct hda_codec *codec)
3054{
3055 struct via_spec *spec;
3056 int err;
3057
3058 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003059 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003060 if (spec == NULL)
3061 return -ENOMEM;
3062
Takashi Iwai620e2b22011-06-17 17:19:19 +02003063 spec->aa_mix_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003064 override_mic_boost(codec, 0x1a, 0, 3, 40);
3065 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003066
Harald Welted949cac2008-09-09 15:56:01 +08003067 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003068 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003069 if (err < 0) {
3070 via_free(codec);
3071 return err;
Harald Welted949cac2008-09-09 15:56:01 +08003072 }
3073
Takashi Iwai096a8852011-06-20 12:09:02 +02003074 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003075
Harald Welted949cac2008-09-09 15:56:01 +08003076 codec->patch_ops = via_patch_ops;
3077
Lydia Wang518bf3b2009-10-10 19:07:29 +08003078 /* correct names for VT1708BCE */
3079 if (get_codec_type(codec) == VT1708BCE) {
3080 kfree(codec->chip_name);
3081 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3082 snprintf(codec->bus->card->mixername,
3083 sizeof(codec->bus->card->mixername),
3084 "%s %s", codec->vendor_name, codec->chip_name);
Lydia Wang970f6302011-03-22 16:25:56 +08003085 }
Lydia Wangbc92df72011-03-23 17:56:05 +08003086 /* correct names for VT1705 */
3087 if (codec->vendor_id == 0x11064397) {
3088 kfree(codec->chip_name);
3089 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3090 snprintf(codec->bus->card->mixername,
3091 sizeof(codec->bus->card->mixername),
3092 "%s %s", codec->vendor_name, codec->chip_name);
3093 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003094 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +08003095 return 0;
3096}
3097
3098/* Patch for VT1702 */
3099
Takashi Iwai096a8852011-06-20 12:09:02 +02003100static const struct hda_verb vt1702_init_verbs[] = {
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003101 /* mixer enable */
3102 {0x1, 0xF88, 0x3},
3103 /* GPIO 0~2 */
3104 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08003105 { }
3106};
3107
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003108static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3109{
3110 int imux_is_smixer =
3111 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3112 unsigned int parm;
3113 /* inputs */
3114 /* PW 1/2/5 (14h/15h/18h) */
3115 parm = AC_PWRST_D3;
3116 set_pin_power_state(codec, 0x14, &parm);
3117 set_pin_power_state(codec, 0x15, &parm);
3118 set_pin_power_state(codec, 0x18, &parm);
3119 if (imux_is_smixer)
3120 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3121 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003122 update_power_state(codec, 0x13, parm);
3123 update_power_state(codec, 0x12, parm);
3124 update_power_state(codec, 0x1f, parm);
3125 update_power_state(codec, 0x20, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003126
3127 /* outputs */
3128 /* PW 3/4 (16h/17h) */
3129 parm = AC_PWRST_D3;
3130 set_pin_power_state(codec, 0x17, &parm);
3131 set_pin_power_state(codec, 0x16, &parm);
3132 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003133 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
3134 update_power_state(codec, 0x10, parm);
3135 update_power_state(codec, 0x1d, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003136}
3137
Harald Welted949cac2008-09-09 15:56:01 +08003138static int patch_vt1702(struct hda_codec *codec)
3139{
3140 struct via_spec *spec;
3141 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003142
3143 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003144 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003145 if (spec == NULL)
3146 return -ENOMEM;
3147
Takashi Iwai620e2b22011-06-17 17:19:19 +02003148 spec->aa_mix_nid = 0x1a;
3149
Takashi Iwai12daef62011-06-18 17:45:49 +02003150 /* limit AA path volume to 0 dB */
3151 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3152 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3153 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3154 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3155 (1 << AC_AMPCAP_MUTE_SHIFT));
3156
Harald Welted949cac2008-09-09 15:56:01 +08003157 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003158 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003159 if (err < 0) {
3160 via_free(codec);
3161 return err;
Harald Welted949cac2008-09-09 15:56:01 +08003162 }
3163
Takashi Iwai096a8852011-06-20 12:09:02 +02003164 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003165
Harald Welted949cac2008-09-09 15:56:01 +08003166 codec->patch_ops = via_patch_ops;
3167
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003168 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08003169 return 0;
3170}
3171
Lydia Wangeb7188c2009-10-10 19:08:34 +08003172/* Patch for VT1718S */
3173
Takashi Iwai096a8852011-06-20 12:09:02 +02003174static const struct hda_verb vt1718S_init_verbs[] = {
Lydia Wang4ab2d532011-03-24 12:42:03 +08003175 /* Enable MW0 adjust Gain 5 */
3176 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08003177 /* Enable Boost Volume backdoor */
3178 {0x1, 0xf88, 0x8},
Takashi Iwai5d417622011-06-20 11:32:27 +02003179
Lydia Wangeb7188c2009-10-10 19:08:34 +08003180 { }
3181};
3182
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003183static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3184{
3185 struct via_spec *spec = codec->spec;
3186 int imux_is_smixer;
Takashi Iwai61625522012-07-25 13:54:55 +02003187 unsigned int parm, parm2;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003188 /* MUX6 (1eh) = stereo mixer */
3189 imux_is_smixer =
3190 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3191 /* inputs */
3192 /* PW 5/6/7 (29h/2ah/2bh) */
3193 parm = AC_PWRST_D3;
3194 set_pin_power_state(codec, 0x29, &parm);
3195 set_pin_power_state(codec, 0x2a, &parm);
3196 set_pin_power_state(codec, 0x2b, &parm);
3197 if (imux_is_smixer)
3198 parm = AC_PWRST_D0;
3199 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003200 update_power_state(codec, 0x1e, parm);
3201 update_power_state(codec, 0x1f, parm);
3202 update_power_state(codec, 0x10, parm);
3203 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003204
3205 /* outputs */
3206 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3207 parm = AC_PWRST_D3;
3208 set_pin_power_state(codec, 0x27, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003209 update_power_state(codec, 0x1a, parm);
Takashi Iwai61625522012-07-25 13:54:55 +02003210 parm2 = parm; /* for pin 0x0b */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003211
3212 /* PW2 (26h), AOW2 (ah) */
3213 parm = AC_PWRST_D3;
3214 set_pin_power_state(codec, 0x26, &parm);
3215 if (spec->smart51_enabled)
3216 set_pin_power_state(codec, 0x2b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003217 update_power_state(codec, 0xa, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003218
3219 /* PW0 (24h), AOW0 (8h) */
3220 parm = AC_PWRST_D3;
3221 set_pin_power_state(codec, 0x24, &parm);
3222 if (!spec->hp_independent_mode) /* check for redirected HP */
3223 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003224 update_power_state(codec, 0x8, parm);
Takashi Iwai61625522012-07-25 13:54:55 +02003225 if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3)
3226 parm = parm2;
3227 update_power_state(codec, 0xb, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003228 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003229 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003230
3231 /* PW1 (25h), AOW1 (9h) */
3232 parm = AC_PWRST_D3;
3233 set_pin_power_state(codec, 0x25, &parm);
3234 if (spec->smart51_enabled)
3235 set_pin_power_state(codec, 0x2a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003236 update_power_state(codec, 0x9, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003237
3238 if (spec->hp_independent_mode) {
3239 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3240 parm = AC_PWRST_D3;
3241 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003242 update_power_state(codec, 0x1b, parm);
3243 update_power_state(codec, 0x34, parm);
3244 update_power_state(codec, 0xc, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003245 }
3246}
3247
Takashi Iwai30b45032011-07-11 17:05:04 +02003248/* Add a connection to the primary DAC from AA-mixer for some codecs
3249 * This isn't listed from the raw info, but the chip has a secret connection.
3250 */
3251static int add_secret_dac_path(struct hda_codec *codec)
3252{
3253 struct via_spec *spec = codec->spec;
3254 int i, nums;
3255 hda_nid_t conn[8];
3256 hda_nid_t nid;
3257
3258 if (!spec->aa_mix_nid)
3259 return 0;
3260 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
3261 ARRAY_SIZE(conn) - 1);
3262 for (i = 0; i < nums; i++) {
3263 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
3264 return 0;
3265 }
3266
3267 /* find the primary DAC and add to the connection list */
3268 nid = codec->start_nid;
3269 for (i = 0; i < codec->num_nodes; i++, nid++) {
3270 unsigned int caps = get_wcaps(codec, nid);
3271 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
3272 !(caps & AC_WCAP_DIGITAL)) {
3273 conn[nums++] = nid;
3274 return snd_hda_override_conn_list(codec,
3275 spec->aa_mix_nid,
3276 nums, conn);
3277 }
3278 }
3279 return 0;
3280}
3281
3282
Lydia Wangeb7188c2009-10-10 19:08:34 +08003283static int patch_vt1718S(struct hda_codec *codec)
3284{
3285 struct via_spec *spec;
3286 int err;
3287
3288 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003289 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003290 if (spec == NULL)
3291 return -ENOMEM;
3292
Takashi Iwai620e2b22011-06-17 17:19:19 +02003293 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003294 override_mic_boost(codec, 0x2b, 0, 3, 40);
3295 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02003296 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003297
Lydia Wangeb7188c2009-10-10 19:08:34 +08003298 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003299 err = via_parse_auto_config(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003300 if (err < 0) {
3301 via_free(codec);
3302 return err;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003303 }
3304
Takashi Iwai096a8852011-06-20 12:09:02 +02003305 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003306
Lydia Wangeb7188c2009-10-10 19:08:34 +08003307 codec->patch_ops = via_patch_ops;
3308
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003309 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3310
Lydia Wangeb7188c2009-10-10 19:08:34 +08003311 return 0;
3312}
Lydia Wangf3db4232009-10-10 19:08:41 +08003313
3314/* Patch for VT1716S */
3315
3316static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3317 struct snd_ctl_elem_info *uinfo)
3318{
3319 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3320 uinfo->count = 1;
3321 uinfo->value.integer.min = 0;
3322 uinfo->value.integer.max = 1;
3323 return 0;
3324}
3325
3326static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3327 struct snd_ctl_elem_value *ucontrol)
3328{
3329 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3330 int index = 0;
3331
3332 index = snd_hda_codec_read(codec, 0x26, 0,
3333 AC_VERB_GET_CONNECT_SEL, 0);
3334 if (index != -1)
3335 *ucontrol->value.integer.value = index;
3336
3337 return 0;
3338}
3339
3340static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3341 struct snd_ctl_elem_value *ucontrol)
3342{
3343 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3344 struct via_spec *spec = codec->spec;
3345 int index = *ucontrol->value.integer.value;
3346
3347 snd_hda_codec_write(codec, 0x26, 0,
3348 AC_VERB_SET_CONNECT_SEL, index);
3349 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003350 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003351 return 1;
3352}
3353
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003354static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003355 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3356 {
3357 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3358 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003359 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08003360 .count = 1,
3361 .info = vt1716s_dmic_info,
3362 .get = vt1716s_dmic_get,
3363 .put = vt1716s_dmic_put,
3364 },
3365 {} /* end */
3366};
3367
3368
3369/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003370static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003371 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3372 { } /* end */
3373};
3374
Takashi Iwai096a8852011-06-20 12:09:02 +02003375static const struct hda_verb vt1716S_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003376 /* Enable Boost Volume backdoor */
3377 {0x1, 0xf8a, 0x80},
3378 /* don't bybass mixer */
3379 {0x1, 0xf88, 0xc0},
3380 /* Enable mono output */
3381 {0x1, 0xf90, 0x08},
3382 { }
3383};
3384
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003385static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3386{
3387 struct via_spec *spec = codec->spec;
3388 int imux_is_smixer;
3389 unsigned int parm;
3390 unsigned int mono_out, present;
3391 /* SW0 (17h) = stereo mixer */
3392 imux_is_smixer =
3393 (snd_hda_codec_read(codec, 0x17, 0,
3394 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3395 /* inputs */
3396 /* PW 1/2/5 (1ah/1bh/1eh) */
3397 parm = AC_PWRST_D3;
3398 set_pin_power_state(codec, 0x1a, &parm);
3399 set_pin_power_state(codec, 0x1b, &parm);
3400 set_pin_power_state(codec, 0x1e, &parm);
3401 if (imux_is_smixer)
3402 parm = AC_PWRST_D0;
3403 /* SW0 (17h), AIW0(13h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003404 update_power_state(codec, 0x17, parm);
3405 update_power_state(codec, 0x13, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003406
3407 parm = AC_PWRST_D3;
3408 set_pin_power_state(codec, 0x1e, &parm);
3409 /* PW11 (22h) */
3410 if (spec->dmic_enabled)
3411 set_pin_power_state(codec, 0x22, &parm);
3412 else
Takashi Iwai054d8672012-01-24 12:25:50 +01003413 update_power_state(codec, 0x22, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003414
3415 /* SW2(26h), AIW1(14h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003416 update_power_state(codec, 0x26, parm);
3417 update_power_state(codec, 0x14, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003418
3419 /* outputs */
3420 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3421 parm = AC_PWRST_D3;
3422 set_pin_power_state(codec, 0x19, &parm);
3423 /* Smart 5.1 PW2(1bh) */
3424 if (spec->smart51_enabled)
3425 set_pin_power_state(codec, 0x1b, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003426 update_power_state(codec, 0x18, parm);
3427 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003428
3429 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3430 parm = AC_PWRST_D3;
3431 set_pin_power_state(codec, 0x23, &parm);
3432 /* Smart 5.1 PW1(1ah) */
3433 if (spec->smart51_enabled)
3434 set_pin_power_state(codec, 0x1a, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003435 update_power_state(codec, 0x27, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003436
3437 /* Smart 5.1 PW5(1eh) */
3438 if (spec->smart51_enabled)
3439 set_pin_power_state(codec, 0x1e, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003440 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003441
3442 /* Mono out */
3443 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3444 present = snd_hda_jack_detect(codec, 0x1c);
3445
3446 if (present)
3447 mono_out = 0;
3448 else {
3449 present = snd_hda_jack_detect(codec, 0x1d);
3450 if (!spec->hp_independent_mode && present)
3451 mono_out = 0;
3452 else
3453 mono_out = 1;
3454 }
3455 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
Takashi Iwai054d8672012-01-24 12:25:50 +01003456 update_power_state(codec, 0x28, parm);
3457 update_power_state(codec, 0x29, parm);
3458 update_power_state(codec, 0x2a, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003459
3460 /* PW 3/4 (1ch/1dh) */
3461 parm = AC_PWRST_D3;
3462 set_pin_power_state(codec, 0x1c, &parm);
3463 set_pin_power_state(codec, 0x1d, &parm);
3464 /* HP Independent Mode, power on AOW3 */
3465 if (spec->hp_independent_mode)
Takashi Iwai054d8672012-01-24 12:25:50 +01003466 update_power_state(codec, 0x25, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003467
3468 /* force to D0 for internal Speaker */
3469 /* MW0 (16h), AOW0 (10h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003470 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
3471 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003472}
3473
Lydia Wangf3db4232009-10-10 19:08:41 +08003474static int patch_vt1716S(struct hda_codec *codec)
3475{
3476 struct via_spec *spec;
3477 int err;
3478
3479 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003480 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003481 if (spec == NULL)
3482 return -ENOMEM;
3483
Takashi Iwai620e2b22011-06-17 17:19:19 +02003484 spec->aa_mix_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003485 override_mic_boost(codec, 0x1a, 0, 3, 40);
3486 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003487
Lydia Wangf3db4232009-10-10 19:08:41 +08003488 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003489 err = via_parse_auto_config(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003490 if (err < 0) {
3491 via_free(codec);
3492 return err;
Lydia Wangf3db4232009-10-10 19:08:41 +08003493 }
3494
Takashi Iwai096a8852011-06-20 12:09:02 +02003495 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
Lydia Wangf3db4232009-10-10 19:08:41 +08003496
Lydia Wangf3db4232009-10-10 19:08:41 +08003497 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3498 spec->num_mixers++;
3499
3500 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3501
3502 codec->patch_ops = via_patch_ops;
3503
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003504 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08003505 return 0;
3506}
Lydia Wang25eaba22009-10-10 19:08:43 +08003507
3508/* for vt2002P */
3509
Takashi Iwai096a8852011-06-20 12:09:02 +02003510static const struct hda_verb vt2002P_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08003511 /* Class-D speaker related verbs */
3512 {0x1, 0xfe0, 0x4},
3513 {0x1, 0xfe9, 0x80},
3514 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08003515 /* Enable Boost Volume backdoor */
3516 {0x1, 0xfb9, 0x24},
Lydia Wang25eaba22009-10-10 19:08:43 +08003517 /* Enable AOW0 to MW9 */
3518 {0x1, 0xfb8, 0x88},
3519 { }
3520};
Takashi Iwai4a918ff2011-06-20 12:39:26 +02003521
Takashi Iwai096a8852011-06-20 12:09:02 +02003522static const struct hda_verb vt1802_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08003523 /* Enable Boost Volume backdoor */
3524 {0x1, 0xfb9, 0x24},
Lydia Wang118909562011-03-23 17:57:34 +08003525 /* Enable AOW0 to MW9 */
3526 {0x1, 0xfb8, 0x88},
3527 { }
3528};
Lydia Wang25eaba22009-10-10 19:08:43 +08003529
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003530static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3531{
3532 struct via_spec *spec = codec->spec;
3533 int imux_is_smixer;
3534 unsigned int parm;
3535 unsigned int present;
3536 /* MUX9 (1eh) = stereo mixer */
3537 imux_is_smixer =
3538 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3539 /* inputs */
3540 /* PW 5/6/7 (29h/2ah/2bh) */
3541 parm = AC_PWRST_D3;
3542 set_pin_power_state(codec, 0x29, &parm);
3543 set_pin_power_state(codec, 0x2a, &parm);
3544 set_pin_power_state(codec, 0x2b, &parm);
3545 parm = AC_PWRST_D0;
3546 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003547 update_power_state(codec, 0x1e, parm);
3548 update_power_state(codec, 0x1f, parm);
3549 update_power_state(codec, 0x10, parm);
3550 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003551
3552 /* outputs */
3553 /* AOW0 (8h)*/
Takashi Iwai054d8672012-01-24 12:25:50 +01003554 update_power_state(codec, 0x8, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003555
Lydia Wang118909562011-03-23 17:57:34 +08003556 if (spec->codec_type == VT1802) {
3557 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3558 parm = AC_PWRST_D3;
3559 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003560 update_power_state(codec, 0x18, parm);
3561 update_power_state(codec, 0x38, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003562 } else {
3563 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3564 parm = AC_PWRST_D3;
3565 set_pin_power_state(codec, 0x26, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003566 update_power_state(codec, 0x1c, parm);
3567 update_power_state(codec, 0x37, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003568 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003569
Lydia Wang118909562011-03-23 17:57:34 +08003570 if (spec->codec_type == VT1802) {
3571 /* PW1 (25h), MW1 (15h), 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, 0x15, parm);
3575 update_power_state(codec, 0x35, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003576 } else {
3577 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3578 parm = AC_PWRST_D3;
3579 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003580 update_power_state(codec, 0x19, parm);
3581 update_power_state(codec, 0x35, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003582 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003583
3584 if (spec->hp_independent_mode)
Takashi Iwai054d8672012-01-24 12:25:50 +01003585 update_power_state(codec, 0x9, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003586
3587 /* Class-D */
3588 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3589 present = snd_hda_jack_detect(codec, 0x25);
3590
3591 parm = AC_PWRST_D3;
3592 set_pin_power_state(codec, 0x24, &parm);
3593 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08003594 if (spec->codec_type == VT1802)
Takashi Iwai054d8672012-01-24 12:25:50 +01003595 update_power_state(codec, 0x14, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003596 else
Takashi Iwai054d8672012-01-24 12:25:50 +01003597 update_power_state(codec, 0x18, parm);
3598 update_power_state(codec, 0x34, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003599
3600 /* Mono Out */
3601 present = snd_hda_jack_detect(codec, 0x26);
3602
3603 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08003604 if (spec->codec_type == VT1802) {
3605 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003606 update_power_state(codec, 0x33, parm);
3607 update_power_state(codec, 0x1c, parm);
3608 update_power_state(codec, 0x3c, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003609 } else {
3610 /* PW15 (31h), MW8(17h), MUX8(3bh) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003611 update_power_state(codec, 0x31, parm);
3612 update_power_state(codec, 0x17, parm);
3613 update_power_state(codec, 0x3b, parm);
Lydia Wang118909562011-03-23 17:57:34 +08003614 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003615 /* MW9 (21h) */
3616 if (imux_is_smixer || !is_aa_path_mute(codec))
Takashi Iwai054d8672012-01-24 12:25:50 +01003617 update_power_state(codec, 0x21, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003618 else
Takashi Iwai054d8672012-01-24 12:25:50 +01003619 update_power_state(codec, 0x21, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003620}
Lydia Wang25eaba22009-10-10 19:08:43 +08003621
David Henningsson4b527b62012-09-18 14:26:59 +02003622/*
3623 * pin fix-up
3624 */
3625enum {
3626 VIA_FIXUP_INTMIC_BOOST,
3627};
3628
3629static void via_fixup_intmic_boost(struct hda_codec *codec,
3630 const struct hda_fixup *fix, int action)
3631{
3632 if (action == HDA_FIXUP_ACT_PRE_PROBE)
3633 override_mic_boost(codec, 0x30, 0, 2, 40);
3634}
3635
3636static const struct hda_fixup via_fixups[] = {
3637 [VIA_FIXUP_INTMIC_BOOST] = {
3638 .type = HDA_FIXUP_FUNC,
3639 .v.func = via_fixup_intmic_boost,
3640 },
3641};
3642
3643static const struct snd_pci_quirk vt2002p_fixups[] = {
3644 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
3645 {}
3646};
3647
Lydia Wang25eaba22009-10-10 19:08:43 +08003648/* patch for vt2002P */
3649static int patch_vt2002P(struct hda_codec *codec)
3650{
3651 struct via_spec *spec;
3652 int err;
3653
3654 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003655 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08003656 if (spec == NULL)
3657 return -ENOMEM;
3658
Takashi Iwai620e2b22011-06-17 17:19:19 +02003659 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003660 override_mic_boost(codec, 0x2b, 0, 3, 40);
3661 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02003662 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003663
David Henningsson4b527b62012-09-18 14:26:59 +02003664 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
3665 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3666
Lydia Wang25eaba22009-10-10 19:08:43 +08003667 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003668 err = via_parse_auto_config(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08003669 if (err < 0) {
3670 via_free(codec);
3671 return err;
Lydia Wang25eaba22009-10-10 19:08:43 +08003672 }
3673
Lydia Wang118909562011-03-23 17:57:34 +08003674 if (spec->codec_type == VT1802)
Takashi Iwai4a918ff2011-06-20 12:39:26 +02003675 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08003676 else
Takashi Iwai4a918ff2011-06-20 12:39:26 +02003677 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08003678
Lydia Wang25eaba22009-10-10 19:08:43 +08003679 codec->patch_ops = via_patch_ops;
3680
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003681 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08003682 return 0;
3683}
Lydia Wangab6734e2009-10-10 19:08:46 +08003684
3685/* for vt1812 */
3686
Takashi Iwai096a8852011-06-20 12:09:02 +02003687static const struct hda_verb vt1812_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08003688 /* Enable Boost Volume backdoor */
3689 {0x1, 0xfb9, 0x24},
Lydia Wangab6734e2009-10-10 19:08:46 +08003690 /* Enable AOW0 to MW9 */
3691 {0x1, 0xfb8, 0xa8},
3692 { }
3693};
3694
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003695static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3696{
3697 struct via_spec *spec = codec->spec;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003698 unsigned int parm;
3699 unsigned int present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003700 /* inputs */
3701 /* PW 5/6/7 (29h/2ah/2bh) */
3702 parm = AC_PWRST_D3;
3703 set_pin_power_state(codec, 0x29, &parm);
3704 set_pin_power_state(codec, 0x2a, &parm);
3705 set_pin_power_state(codec, 0x2b, &parm);
3706 parm = AC_PWRST_D0;
3707 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
Takashi Iwai054d8672012-01-24 12:25:50 +01003708 update_power_state(codec, 0x1e, parm);
3709 update_power_state(codec, 0x1f, parm);
3710 update_power_state(codec, 0x10, parm);
3711 update_power_state(codec, 0x11, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003712
3713 /* outputs */
3714 /* AOW0 (8h)*/
Takashi Iwai054d8672012-01-24 12:25:50 +01003715 update_power_state(codec, 0x8, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003716
3717 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3718 parm = AC_PWRST_D3;
3719 set_pin_power_state(codec, 0x28, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003720 update_power_state(codec, 0x18, parm);
3721 update_power_state(codec, 0x38, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003722
3723 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3724 parm = AC_PWRST_D3;
3725 set_pin_power_state(codec, 0x25, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003726 update_power_state(codec, 0x15, parm);
3727 update_power_state(codec, 0x35, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003728 if (spec->hp_independent_mode)
Takashi Iwai054d8672012-01-24 12:25:50 +01003729 update_power_state(codec, 0x9, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003730
3731 /* Internal Speaker */
3732 /* PW0 (24h), MW0(14h), MUX0(34h) */
3733 present = snd_hda_jack_detect(codec, 0x25);
3734
3735 parm = AC_PWRST_D3;
3736 set_pin_power_state(codec, 0x24, &parm);
3737 if (present) {
Takashi Iwai054d8672012-01-24 12:25:50 +01003738 update_power_state(codec, 0x14, AC_PWRST_D3);
3739 update_power_state(codec, 0x34, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003740 } else {
Takashi Iwai054d8672012-01-24 12:25:50 +01003741 update_power_state(codec, 0x14, AC_PWRST_D0);
3742 update_power_state(codec, 0x34, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003743 }
3744
3745
3746 /* Mono Out */
3747 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3748 present = snd_hda_jack_detect(codec, 0x28);
3749
3750 parm = AC_PWRST_D3;
3751 set_pin_power_state(codec, 0x31, &parm);
3752 if (present) {
Takashi Iwai054d8672012-01-24 12:25:50 +01003753 update_power_state(codec, 0x1c, AC_PWRST_D3);
3754 update_power_state(codec, 0x3c, AC_PWRST_D3);
3755 update_power_state(codec, 0x3e, AC_PWRST_D3);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003756 } else {
Takashi Iwai054d8672012-01-24 12:25:50 +01003757 update_power_state(codec, 0x1c, AC_PWRST_D0);
3758 update_power_state(codec, 0x3c, AC_PWRST_D0);
3759 update_power_state(codec, 0x3e, AC_PWRST_D0);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003760 }
3761
3762 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3763 parm = AC_PWRST_D3;
3764 set_pin_power_state(codec, 0x33, &parm);
Takashi Iwai054d8672012-01-24 12:25:50 +01003765 update_power_state(codec, 0x1d, parm);
3766 update_power_state(codec, 0x3d, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003767
3768}
Lydia Wangab6734e2009-10-10 19:08:46 +08003769
3770/* patch for vt1812 */
3771static int patch_vt1812(struct hda_codec *codec)
3772{
3773 struct via_spec *spec;
3774 int err;
3775
3776 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003777 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08003778 if (spec == NULL)
3779 return -ENOMEM;
3780
Takashi Iwai620e2b22011-06-17 17:19:19 +02003781 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003782 override_mic_boost(codec, 0x2b, 0, 3, 40);
3783 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02003784 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003785
Lydia Wangab6734e2009-10-10 19:08:46 +08003786 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003787 err = via_parse_auto_config(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08003788 if (err < 0) {
3789 via_free(codec);
3790 return err;
Lydia Wangab6734e2009-10-10 19:08:46 +08003791 }
3792
Takashi Iwai096a8852011-06-20 12:09:02 +02003793 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
Lydia Wangab6734e2009-10-10 19:08:46 +08003794
Lydia Wangab6734e2009-10-10 19:08:46 +08003795 codec->patch_ops = via_patch_ops;
3796
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003797 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08003798 return 0;
3799}
3800
Joseph Chanc577b8a2006-11-29 15:29:40 +01003801/*
3802 * patch entries
3803 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003804static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01003805 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3806 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3807 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3808 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3809 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003810 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003811 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003812 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003813 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003814 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003815 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003816 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003817 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003818 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003819 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003820 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003821 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003822 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003823 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003824 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003825 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003826 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003827 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003828 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003829 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003830 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003831 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003832 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003833 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003834 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003835 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003836 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003837 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003838 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003839 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003840 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003841 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003842 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003843 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003844 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003845 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003846 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003847 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003848 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08003849 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08003850 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003851 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003852 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003853 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003854 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003855 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003856 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003857 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003858 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003859 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003860 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003861 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003862 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003863 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003864 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003865 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003866 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003867 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003868 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003869 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003870 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003871 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003872 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08003873 { .id = 0x11060428, .name = "VT1718S",
3874 .patch = patch_vt1718S},
3875 { .id = 0x11064428, .name = "VT1718S",
3876 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08003877 { .id = 0x11060441, .name = "VT2020",
3878 .patch = patch_vt1718S},
3879 { .id = 0x11064441, .name = "VT1828S",
3880 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08003881 { .id = 0x11060433, .name = "VT1716S",
3882 .patch = patch_vt1716S},
3883 { .id = 0x1106a721, .name = "VT1716S",
3884 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08003885 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3886 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08003887 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08003888 { .id = 0x11060440, .name = "VT1818S",
3889 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08003890 { .id = 0x11060446, .name = "VT1802",
3891 .patch = patch_vt2002P},
3892 { .id = 0x11068446, .name = "VT1802",
3893 .patch = patch_vt2002P},
Joseph Chanc577b8a2006-11-29 15:29:40 +01003894 {} /* terminator */
3895};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003896
3897MODULE_ALIAS("snd-hda-codec-id:1106*");
3898
3899static struct hda_codec_preset_list via_list = {
3900 .preset = snd_hda_preset_via,
3901 .owner = THIS_MODULE,
3902};
3903
3904MODULE_LICENSE("GPL");
3905MODULE_DESCRIPTION("VIA HD-audio codec");
3906
3907static int __init patch_via_init(void)
3908{
3909 return snd_hda_add_codec_preset(&via_list);
3910}
3911
3912static void __exit patch_via_exit(void)
3913{
3914 snd_hda_delete_codec_preset(&via_list);
3915}
3916
3917module_init(patch_via_init)
3918module_exit(patch_via_exit)