blob: 4ebfbd874c9a81db01fe3961c5d1c65656735ab5 [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>
Joseph Chanc577b8a2006-11-29 15:29:40 +010052#include <sound/core.h>
Harald Welte0aa62ae2008-09-09 15:58:27 +080053#include <sound/asoundef.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010054#include "hda_codec.h"
55#include "hda_local.h"
Joseph Chanc577b8a2006-11-29 15:29:40 +010056
Joseph Chanc577b8a2006-11-29 15:29:40 +010057/* Pin Widget NID */
Harald Welted949cac2008-09-09 15:56:01 +080058#define VT1708_HP_PIN_NID 0x20
59#define VT1708_CD_PIN_NID 0x24
Joseph Chanc577b8a2006-11-29 15:29:40 +010060
Harald Welted7426322008-09-15 22:43:23 +080061enum VIA_HDA_CODEC {
62 UNKNOWN = -1,
63 VT1708,
64 VT1709_10CH,
65 VT1709_6CH,
66 VT1708B_8CH,
67 VT1708B_4CH,
68 VT1708S,
Lydia Wang518bf3b2009-10-10 19:07:29 +080069 VT1708BCE,
Harald Welted7426322008-09-15 22:43:23 +080070 VT1702,
Lydia Wangeb7188c2009-10-10 19:08:34 +080071 VT1718S,
Lydia Wangf3db4232009-10-10 19:08:41 +080072 VT1716S,
Lydia Wang25eaba22009-10-10 19:08:43 +080073 VT2002P,
Lydia Wangab6734e2009-10-10 19:08:46 +080074 VT1812,
Lydia Wang118909562011-03-23 17:57:34 +080075 VT1802,
Harald Welted7426322008-09-15 22:43:23 +080076 CODEC_TYPES,
77};
78
Lydia Wang118909562011-03-23 17:57:34 +080079#define VT2002P_COMPATIBLE(spec) \
80 ((spec)->codec_type == VT2002P ||\
81 (spec)->codec_type == VT1812 ||\
82 (spec)->codec_type == VT1802)
83
Takashi Iwai8e3679d2011-06-21 09:01:36 +020084#define MAX_NID_PATH_DEPTH 5
85
Takashi Iwai09a9ad692011-06-21 15:57:44 +020086/* output-path: DAC -> ... -> pin
87 * idx[] contains the source index number of the next widget;
88 * e.g. idx[0] is the index of the DAC selected by path[1] widget
89 * multi[] indicates whether it's a selector widget with multi-connectors
90 * (i.e. the connection selection is mandatory)
91 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
92 */
Takashi Iwai4a796162011-06-17 17:53:38 +020093struct nid_path {
94 int depth;
Takashi Iwai8e3679d2011-06-21 09:01:36 +020095 hda_nid_t path[MAX_NID_PATH_DEPTH];
Takashi Iwai09a9ad692011-06-21 15:57:44 +020096 unsigned char idx[MAX_NID_PATH_DEPTH];
97 unsigned char multi[MAX_NID_PATH_DEPTH];
98 unsigned int vol_ctl;
99 unsigned int mute_ctl;
Takashi Iwai4a796162011-06-17 17:53:38 +0200100};
101
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200102/* input-path */
103struct via_input {
104 hda_nid_t pin; /* input-pin or aa-mix */
105 int adc_idx; /* ADC index to be used */
106 int mux_idx; /* MUX index (if any) */
107 const char *label; /* input-source label */
108};
109
Takashi Iwaide6c74f2011-07-04 14:46:42 +0200110#define VIA_MAX_ADCS 3
111
Takashi Iwai3b607e32011-07-18 16:54:40 +0200112enum {
113 STREAM_MULTI_OUT = (1 << 0),
114 STREAM_INDEP_HP = (1 << 1),
115};
116
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800117struct via_spec {
118 /* codec parameterization */
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200119 const struct snd_kcontrol_new *mixers[6];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800120 unsigned int num_mixers;
121
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200122 const struct hda_verb *init_verbs[5];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800123 unsigned int num_iverbs;
124
Takashi Iwai82673bc2011-06-17 16:24:21 +0200125 char stream_name_analog[32];
Takashi Iwai7eb56e82011-06-18 16:40:14 +0200126 char stream_name_hp[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200127 const struct hda_pcm_stream *stream_analog_playback;
128 const struct hda_pcm_stream *stream_analog_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800129
Takashi Iwai82673bc2011-06-17 16:24:21 +0200130 char stream_name_digital[32];
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200131 const struct hda_pcm_stream *stream_digital_playback;
132 const struct hda_pcm_stream *stream_digital_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800133
134 /* playback */
135 struct hda_multi_out multiout;
136 hda_nid_t slave_dig_outs[2];
Takashi Iwaiece8d042011-06-19 16:24:21 +0200137 hda_nid_t hp_dac_nid;
Takashi Iwai3214b962011-07-18 12:49:25 +0200138 hda_nid_t speaker_dac_nid;
139 int hp_indep_shared; /* indep HP-DAC is shared with side ch */
Takashi Iwai3b607e32011-07-18 16:54:40 +0200140 int opened_streams; /* STREAM_* bits */
141 int active_streams; /* STREAM_* bits */
Takashi Iwai3214b962011-07-18 12:49:25 +0200142 int aamix_mode; /* loopback is enabled for output-path? */
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800143
Takashi Iwai3214b962011-07-18 12:49:25 +0200144 /* Output-paths:
145 * There are different output-paths depending on the setup.
146 * out_path, hp_path and speaker_path are primary paths. If both
147 * direct DAC and aa-loopback routes are available, these contain
148 * the former paths. Meanwhile *_mix_path contain the paths with
149 * loopback mixer. (Since the loopback is only for front channel,
150 * no out_mix_path for surround channels.)
151 * The HP output has another path, hp_indep_path, which is used in
152 * the independent-HP mode.
153 */
Takashi Iwaide6c74f2011-07-04 14:46:42 +0200154 struct nid_path out_path[HDA_SIDE + 1];
Takashi Iwai3214b962011-07-18 12:49:25 +0200155 struct nid_path out_mix_path;
Takashi Iwai4a796162011-06-17 17:53:38 +0200156 struct nid_path hp_path;
Takashi Iwai3214b962011-07-18 12:49:25 +0200157 struct nid_path hp_mix_path;
158 struct nid_path hp_indep_path;
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200159 struct nid_path speaker_path;
Takashi Iwai3214b962011-07-18 12:49:25 +0200160 struct nid_path speaker_mix_path;
Takashi Iwai4a796162011-06-17 17:53:38 +0200161
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800162 /* capture */
163 unsigned int num_adc_nids;
Takashi Iwaide6c74f2011-07-04 14:46:42 +0200164 hda_nid_t adc_nids[VIA_MAX_ADCS];
165 hda_nid_t mux_nids[VIA_MAX_ADCS];
Takashi Iwai620e2b22011-06-17 17:19:19 +0200166 hda_nid_t aa_mix_nid;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800167 hda_nid_t dig_in_nid;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800168
169 /* capture source */
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200170 bool dyn_adc_switch;
171 int num_inputs;
172 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
Takashi Iwaide6c74f2011-07-04 14:46:42 +0200173 unsigned int cur_mux[VIA_MAX_ADCS];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800174
Takashi Iwai3b607e32011-07-18 16:54:40 +0200175 /* dynamic DAC switching */
176 unsigned int cur_dac_stream_tag;
177 unsigned int cur_dac_format;
178 unsigned int cur_hp_stream_tag;
179 unsigned int cur_hp_format;
180
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200181 /* dynamic ADC switching */
182 hda_nid_t cur_adc;
183 unsigned int cur_adc_stream_tag;
184 unsigned int cur_adc_format;
185
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800186 /* PCM information */
187 struct hda_pcm pcm_rec[3];
188
189 /* dynamic controls, init_verbs and input_mux */
190 struct auto_pin_cfg autocfg;
191 struct snd_array kctls;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800192 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
193
194 /* HP mode source */
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800195 unsigned int hp_independent_mode;
Lydia Wangf3db4232009-10-10 19:08:41 +0800196 unsigned int dmic_enabled;
Takashi Iwai24088a52011-06-17 16:59:21 +0200197 unsigned int no_pin_power_ctl;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800198 enum VIA_HDA_CODEC codec_type;
199
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200200 /* smart51 setup */
201 unsigned int smart51_nums;
202 hda_nid_t smart51_pins[2];
203 int smart51_idxs[2];
204 const char *smart51_labels[2];
205 unsigned int smart51_enabled;
206
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800207 /* work to check hp jack state */
208 struct hda_codec *codec;
209 struct delayed_work vt1708_hp_work;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200210 int vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800211 int vt1708_hp_present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800212
213 void (*set_widgets_power_state)(struct hda_codec *codec);
214
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800215 struct hda_loopback_check loopback;
Takashi Iwai13af8e72011-06-20 14:05:46 +0200216 int num_loopbacks;
217 struct hda_amp_list loopback_list[8];
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200218
219 /* bind capture-volume */
220 struct hda_bind_ctls *bind_cap_vol;
221 struct hda_bind_ctls *bind_cap_sw;
Takashi Iwai3b607e32011-07-18 16:54:40 +0200222
223 struct mutex config_mutex;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800224};
225
Lydia Wang0341ccd2011-03-22 16:25:03 +0800226static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100227static struct via_spec * via_new_spec(struct hda_codec *codec)
228{
229 struct via_spec *spec;
230
231 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
232 if (spec == NULL)
233 return NULL;
234
Takashi Iwai3b607e32011-07-18 16:54:40 +0200235 mutex_init(&spec->config_mutex);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100236 codec->spec = spec;
237 spec->codec = codec;
Lydia Wang0341ccd2011-03-22 16:25:03 +0800238 spec->codec_type = get_codec_type(codec);
239 /* VT1708BCE & VT1708S are almost same */
240 if (spec->codec_type == VT1708BCE)
241 spec->codec_type = VT1708S;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100242 return spec;
243}
244
Lydia Wang744ff5f2009-10-10 19:07:26 +0800245static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800246{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800247 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800248 u16 ven_id = vendor_id >> 16;
249 u16 dev_id = vendor_id & 0xffff;
250 enum VIA_HDA_CODEC codec_type;
251
252 /* get codec type */
253 if (ven_id != 0x1106)
254 codec_type = UNKNOWN;
255 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
256 codec_type = VT1708;
257 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
258 codec_type = VT1709_10CH;
259 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
260 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800261 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800262 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800263 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
264 codec_type = VT1708BCE;
265 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800266 codec_type = VT1708B_4CH;
267 else if ((dev_id & 0xfff) == 0x397
268 && (dev_id >> 12) < 8)
269 codec_type = VT1708S;
270 else if ((dev_id & 0xfff) == 0x398
271 && (dev_id >> 12) < 8)
272 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800273 else if ((dev_id & 0xfff) == 0x428
274 && (dev_id >> 12) < 8)
275 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800276 else if (dev_id == 0x0433 || dev_id == 0xa721)
277 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800278 else if (dev_id == 0x0441 || dev_id == 0x4441)
279 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800280 else if (dev_id == 0x0438 || dev_id == 0x4438)
281 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800282 else if (dev_id == 0x0448)
283 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800284 else if (dev_id == 0x0440)
285 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800286 else if ((dev_id & 0xfff) == 0x446)
287 codec_type = VT1802;
Harald Welted7426322008-09-15 22:43:23 +0800288 else
289 codec_type = UNKNOWN;
290 return codec_type;
291};
292
Lydia Wangec7e7e42011-03-24 12:43:44 +0800293#define VIA_JACK_EVENT 0x20
Harald Welte69e52a82008-09-09 15:57:32 +0800294#define VIA_HP_EVENT 0x01
295#define VIA_GPIO_EVENT 0x02
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200296#define VIA_LINE_EVENT 0x03
Harald Welte69e52a82008-09-09 15:57:32 +0800297
Joseph Chanc577b8a2006-11-29 15:29:40 +0100298enum {
299 VIA_CTL_WIDGET_VOL,
300 VIA_CTL_WIDGET_MUTE,
Lydia Wangf5271102009-10-10 19:07:35 +0800301 VIA_CTL_WIDGET_ANALOG_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100302};
303
Takashi Iwaiada509e2011-06-20 15:40:19 +0200304static void analog_low_current_mode(struct hda_codec *codec);
305static bool is_aa_path_mute(struct hda_codec *codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800306
307static void vt1708_start_hp_work(struct via_spec *spec)
308{
309 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
310 return;
311 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200312 !spec->vt1708_jack_detect);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800313 if (!delayed_work_pending(&spec->vt1708_hp_work))
314 schedule_delayed_work(&spec->vt1708_hp_work,
315 msecs_to_jiffies(100));
316}
317
318static void vt1708_stop_hp_work(struct via_spec *spec)
319{
320 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
321 return;
322 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
323 && !is_aa_path_mute(spec->codec))
324 return;
325 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200326 !spec->vt1708_jack_detect);
Tejun Heo5b84ba22010-12-11 17:51:26 +0100327 cancel_delayed_work_sync(&spec->vt1708_hp_work);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800328}
Lydia Wangf5271102009-10-10 19:07:35 +0800329
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800330static void set_widgets_power_state(struct hda_codec *codec)
331{
332 struct via_spec *spec = codec->spec;
333 if (spec->set_widgets_power_state)
334 spec->set_widgets_power_state(codec);
335}
Lydia Wang25eaba22009-10-10 19:08:43 +0800336
Lydia Wangf5271102009-10-10 19:07:35 +0800337static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
338 struct snd_ctl_elem_value *ucontrol)
339{
340 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
341 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
342
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800343 set_widgets_power_state(codec);
Takashi Iwaiada509e2011-06-20 15:40:19 +0200344 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800345 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
346 if (is_aa_path_mute(codec))
347 vt1708_start_hp_work(codec->spec);
348 else
349 vt1708_stop_hp_work(codec->spec);
350 }
Lydia Wangf5271102009-10-10 19:07:35 +0800351 return change;
352}
353
354/* modify .put = snd_hda_mixer_amp_switch_put */
355#define ANALOG_INPUT_MUTE \
356 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
357 .name = NULL, \
358 .index = 0, \
359 .info = snd_hda_mixer_amp_switch_info, \
360 .get = snd_hda_mixer_amp_switch_get, \
361 .put = analog_input_switch_put, \
362 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
363
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200364static const struct snd_kcontrol_new via_control_templates[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100365 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
366 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Lydia Wangf5271102009-10-10 19:07:35 +0800367 ANALOG_INPUT_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100368};
369
Lydia Wangab6734e2009-10-10 19:08:46 +0800370
Joseph Chanc577b8a2006-11-29 15:29:40 +0100371/* add dynamic controls */
Takashi Iwai291c9e32011-06-17 16:15:26 +0200372static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
373 const struct snd_kcontrol_new *tmpl,
374 const char *name)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100375{
376 struct snd_kcontrol_new *knew;
377
Takashi Iwai603c4012008-07-30 15:01:44 +0200378 snd_array_init(&spec->kctls, sizeof(*knew), 32);
379 knew = snd_array_new(&spec->kctls);
380 if (!knew)
Takashi Iwai291c9e32011-06-17 16:15:26 +0200381 return NULL;
382 *knew = *tmpl;
383 if (!name)
384 name = tmpl->name;
385 if (name) {
386 knew->name = kstrdup(name, GFP_KERNEL);
387 if (!knew->name)
388 return NULL;
389 }
390 return knew;
391}
392
393static int __via_add_control(struct via_spec *spec, int type, const char *name,
394 int idx, unsigned long val)
395{
396 struct snd_kcontrol_new *knew;
397
398 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
399 if (!knew)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100400 return -ENOMEM;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +0200401 knew->index = idx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100402 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100403 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100404 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100405 return 0;
406}
407
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200408#define via_add_control(spec, type, name, val) \
409 __via_add_control(spec, type, name, 0, val)
410
Takashi Iwai291c9e32011-06-17 16:15:26 +0200411#define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100412
Takashi Iwai603c4012008-07-30 15:01:44 +0200413static void via_free_kctls(struct hda_codec *codec)
414{
415 struct via_spec *spec = codec->spec;
416
417 if (spec->kctls.list) {
418 struct snd_kcontrol_new *kctl = spec->kctls.list;
419 int i;
420 for (i = 0; i < spec->kctls.used; i++)
421 kfree(kctl[i].name);
422 }
423 snd_array_free(&spec->kctls);
424}
425
Joseph Chanc577b8a2006-11-29 15:29:40 +0100426/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800427static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200428 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100429{
430 char name[32];
431 int err;
432
433 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200434 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100435 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
436 if (err < 0)
437 return err;
438 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200439 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100440 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
441 if (err < 0)
442 return err;
443 return 0;
444}
445
Takashi Iwai5d417622011-06-20 11:32:27 +0200446#define get_connection_index(codec, mux, nid) \
Takashi Iwai8d087c72011-06-28 12:45:47 +0200447 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai5d417622011-06-20 11:32:27 +0200448
Takashi Iwai8df2a312011-06-21 11:48:29 +0200449static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
450 unsigned int mask)
451{
Takashi Iwaia934d5a2011-06-21 14:22:14 +0200452 unsigned int caps;
453 if (!nid)
454 return false;
455 caps = get_wcaps(codec, nid);
Takashi Iwai8df2a312011-06-21 11:48:29 +0200456 if (dir == HDA_INPUT)
457 caps &= AC_WCAP_IN_AMP;
458 else
459 caps &= AC_WCAP_OUT_AMP;
460 if (!caps)
461 return false;
462 if (query_amp_caps(codec, nid, dir) & mask)
463 return true;
464 return false;
465}
466
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200467#define have_mute(codec, nid, dir) \
468 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
Takashi Iwai8df2a312011-06-21 11:48:29 +0200469
Lydia Wangd69607b2011-07-08 14:02:52 +0800470/* enable/disable the output-route mixers */
471static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
Takashi Iwai3214b962011-07-18 12:49:25 +0200472 hda_nid_t mix_nid, int idx, bool enable)
Lydia Wangd69607b2011-07-08 14:02:52 +0800473{
474 int i, num, val;
Lydia Wangd69607b2011-07-08 14:02:52 +0800475
476 if (!path)
477 return;
478 num = snd_hda_get_conn_list(codec, mix_nid, NULL);
Lydia Wangd69607b2011-07-08 14:02:52 +0800479 for (i = 0; i < num; i++) {
Takashi Iwai3214b962011-07-18 12:49:25 +0200480 if (i == idx)
481 val = AMP_IN_UNMUTE(i);
482 else
483 val = AMP_IN_MUTE(i);
Lydia Wangd69607b2011-07-08 14:02:52 +0800484 snd_hda_codec_write(codec, mix_nid, 0,
485 AC_VERB_SET_AMP_GAIN_MUTE, val);
486 }
487}
488
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200489/* enable/disable the output-route */
490static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
491 bool enable, bool force)
Takashi Iwai5d417622011-06-20 11:32:27 +0200492{
Lydia Wangd69607b2011-07-08 14:02:52 +0800493 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200494 int i;
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200495 for (i = 0; i < path->depth; i++) {
496 hda_nid_t src, dst;
497 int idx = path->idx[i];
498 src = path->path[i];
499 if (i < path->depth - 1)
500 dst = path->path[i + 1];
501 else
502 dst = 0;
503 if (enable && path->multi[i])
504 snd_hda_codec_write(codec, dst, 0,
505 AC_VERB_SET_CONNECT_SEL, idx);
Takashi Iwai3214b962011-07-18 12:49:25 +0200506 if (!force && (dst == spec->aa_mix_nid))
Lydia Wange5e14682011-07-01 10:55:07 +0800507 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +0200508 if (have_mute(codec, dst, HDA_INPUT))
509 activate_output_mix(codec, path, dst, idx, enable);
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200510 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
511 continue;
512 if (have_mute(codec, src, HDA_OUTPUT)) {
513 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
514 snd_hda_codec_write(codec, src, 0,
515 AC_VERB_SET_AMP_GAIN_MUTE, val);
516 }
517 }
Takashi Iwai5d417622011-06-20 11:32:27 +0200518}
519
520/* set the given pin as output */
521static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
522 int pin_type)
523{
524 if (!pin)
525 return;
526 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
527 pin_type);
528 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
529 snd_hda_codec_write(codec, pin, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200530 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100531}
532
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200533static void via_auto_init_output(struct hda_codec *codec,
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200534 struct nid_path *path, int pin_type)
Takashi Iwai5d417622011-06-20 11:32:27 +0200535{
Takashi Iwai5d417622011-06-20 11:32:27 +0200536 unsigned int caps;
Lydia Wangd69607b2011-07-08 14:02:52 +0800537 hda_nid_t pin;
Takashi Iwai5d417622011-06-20 11:32:27 +0200538
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200539 if (!path->depth)
Takashi Iwai5d417622011-06-20 11:32:27 +0200540 return;
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200541 pin = path->path[path->depth - 1];
Takashi Iwai5d417622011-06-20 11:32:27 +0200542
543 init_output_pin(codec, pin, pin_type);
544 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
545 if (caps & AC_AMPCAP_MUTE) {
546 unsigned int val;
547 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
548 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
549 AMP_OUT_MUTE | val);
550 }
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200551 activate_output_path(codec, path, true, true); /* force on */
Takashi Iwai5d417622011-06-20 11:32:27 +0200552}
553
Joseph Chanc577b8a2006-11-29 15:29:40 +0100554static void via_auto_init_multi_out(struct hda_codec *codec)
555{
556 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200557 struct nid_path *path;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100558 int i;
559
Takashi Iwai3214b962011-07-18 12:49:25 +0200560 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
561 path = &spec->out_path[i];
562 if (!i && spec->aamix_mode && spec->out_mix_path.depth)
563 path = &spec->out_mix_path;
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200564 via_auto_init_output(codec, path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200565 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100566}
567
Takashi Iwai020066d2011-07-21 13:45:56 +0200568/* deactivate the inactive headphone-paths */
569static void deactivate_hp_paths(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100570{
571 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200572 int shared = spec->hp_indep_shared;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100573
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200574 if (spec->hp_independent_mode) {
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200575 activate_output_path(codec, &spec->hp_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200576 activate_output_path(codec, &spec->hp_mix_path, false, false);
577 if (shared)
578 activate_output_path(codec, &spec->out_path[shared],
579 false, false);
Takashi Iwai020066d2011-07-21 13:45:56 +0200580 } else if (spec->aamix_mode || !spec->hp_path.depth) {
581 activate_output_path(codec, &spec->hp_indep_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200582 activate_output_path(codec, &spec->hp_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200583 } else {
Takashi Iwai020066d2011-07-21 13:45:56 +0200584 activate_output_path(codec, &spec->hp_indep_path, false, false);
Takashi Iwai3214b962011-07-18 12:49:25 +0200585 activate_output_path(codec, &spec->hp_mix_path, false, false);
Takashi Iwai09a9ad692011-06-21 15:57:44 +0200586 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100587}
588
Takashi Iwai020066d2011-07-21 13:45:56 +0200589static void via_auto_init_hp_out(struct hda_codec *codec)
590{
591 struct via_spec *spec = codec->spec;
592
593 if (!spec->hp_path.depth) {
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200594 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200595 return;
596 }
597 deactivate_hp_paths(codec);
598 if (spec->hp_independent_mode)
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200599 via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200600 else if (spec->aamix_mode)
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200601 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200602 else
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200603 via_auto_init_output(codec, &spec->hp_path, PIN_HP);
Takashi Iwai020066d2011-07-21 13:45:56 +0200604}
605
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200606static void via_auto_init_speaker_out(struct hda_codec *codec)
607{
608 struct via_spec *spec = codec->spec;
609
Takashi Iwai3214b962011-07-18 12:49:25 +0200610 if (!spec->autocfg.speaker_outs)
611 return;
612 if (!spec->speaker_path.depth) {
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200613 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200614 return;
615 }
616 if (!spec->aamix_mode) {
617 activate_output_path(codec, &spec->speaker_mix_path,
618 false, false);
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200619 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200620 } else {
621 activate_output_path(codec, &spec->speaker_path, false, false);
Takashi Iwaia353fbb2011-07-21 14:23:35 +0200622 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
Takashi Iwai3214b962011-07-18 12:49:25 +0200623 }
Takashi Iwai4a918ff2011-06-20 12:39:26 +0200624}
625
Takashi Iwaif4a78282011-06-17 18:46:48 +0200626static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
Takashi Iwai6e969d92011-07-11 11:28:13 +0200627static void via_hp_automute(struct hda_codec *codec);
Clemens Ladisch32e01912010-07-12 16:28:50 +0200628
Joseph Chanc577b8a2006-11-29 15:29:40 +0100629static void via_auto_init_analog_input(struct hda_codec *codec)
630{
631 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200632 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai096a8852011-06-20 12:09:02 +0200633 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Clemens Ladisch32e01912010-07-12 16:28:50 +0200634 unsigned int ctl;
Takashi Iwai096a8852011-06-20 12:09:02 +0200635 int i, num_conns;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100636
Takashi Iwai096a8852011-06-20 12:09:02 +0200637 /* init ADCs */
638 for (i = 0; i < spec->num_adc_nids; i++) {
639 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
640 AC_VERB_SET_AMP_GAIN_MUTE,
641 AMP_IN_UNMUTE(0));
642 }
643
644 /* init pins */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200645 for (i = 0; i < cfg->num_inputs; i++) {
646 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwaif4a78282011-06-17 18:46:48 +0200647 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
Clemens Ladisch32e01912010-07-12 16:28:50 +0200648 ctl = PIN_OUT;
David Henningsson30649672011-02-21 10:23:18 +0100649 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
Clemens Ladisch32e01912010-07-12 16:28:50 +0200650 ctl = PIN_VREF50;
651 else
652 ctl = PIN_IN;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100653 snd_hda_codec_write(codec, nid, 0,
Clemens Ladisch32e01912010-07-12 16:28:50 +0200654 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100655 }
Takashi Iwai096a8852011-06-20 12:09:02 +0200656
657 /* init input-src */
658 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwaia86a88e2011-06-22 15:23:25 +0200659 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
660 if (spec->mux_nids[adc_idx]) {
661 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
662 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
663 AC_VERB_SET_CONNECT_SEL,
664 mux_idx);
665 }
666 if (spec->dyn_adc_switch)
667 break; /* only one input-src */
Takashi Iwai096a8852011-06-20 12:09:02 +0200668 }
669
670 /* init aa-mixer */
671 if (!spec->aa_mix_nid)
672 return;
673 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
674 ARRAY_SIZE(conn));
675 for (i = 0; i < num_conns; i++) {
676 unsigned int caps = get_wcaps(codec, conn[i]);
677 if (get_wcaps_type(caps) == AC_WID_PIN)
678 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
679 AC_VERB_SET_AMP_GAIN_MUTE,
680 AMP_IN_MUTE(i));
681 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100682}
Lydia Wangf5271102009-10-10 19:07:35 +0800683
684static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
685 unsigned int *affected_parm)
686{
687 unsigned parm;
688 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
689 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
690 >> AC_DEFCFG_MISC_SHIFT
691 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800692 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200693 unsigned present = 0;
694
695 no_presence |= spec->no_pin_power_ctl;
696 if (!no_presence)
697 present = snd_hda_jack_detect(codec, nid);
Takashi Iwaif4a78282011-06-17 18:46:48 +0200698 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
Lydia Wang1564b282009-10-10 19:07:52 +0800699 || ((no_presence || present)
700 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800701 *affected_parm = AC_PWRST_D0; /* if it's connected */
702 parm = AC_PWRST_D0;
703 } else
704 parm = AC_PWRST_D3;
705
706 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
707}
708
Takashi Iwai24088a52011-06-17 16:59:21 +0200709static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
710 struct snd_ctl_elem_info *uinfo)
711{
712 static const char * const texts[] = {
713 "Disabled", "Enabled"
714 };
715
716 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
717 uinfo->count = 1;
718 uinfo->value.enumerated.items = 2;
719 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
720 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
721 strcpy(uinfo->value.enumerated.name,
722 texts[uinfo->value.enumerated.item]);
723 return 0;
724}
725
726static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
727 struct snd_ctl_elem_value *ucontrol)
728{
729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
730 struct via_spec *spec = codec->spec;
731 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
732 return 0;
733}
734
735static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
736 struct snd_ctl_elem_value *ucontrol)
737{
738 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
739 struct via_spec *spec = codec->spec;
740 unsigned int val = !ucontrol->value.enumerated.item[0];
741
742 if (val == spec->no_pin_power_ctl)
743 return 0;
744 spec->no_pin_power_ctl = val;
745 set_widgets_power_state(codec);
746 return 1;
747}
748
749static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
751 .name = "Dynamic Power-Control",
752 .info = via_pin_power_ctl_info,
753 .get = via_pin_power_ctl_get,
754 .put = via_pin_power_ctl_put,
755};
756
757
Harald Welte0aa62ae2008-09-09 15:58:27 +0800758static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
759 struct snd_ctl_elem_info *uinfo)
760{
Takashi Iwai8df2a312011-06-21 11:48:29 +0200761 static const char * const texts[] = { "OFF", "ON" };
762
763 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
764 uinfo->count = 1;
765 uinfo->value.enumerated.items = 2;
766 if (uinfo->value.enumerated.item >= 2)
767 uinfo->value.enumerated.item = 1;
768 strcpy(uinfo->value.enumerated.name,
769 texts[uinfo->value.enumerated.item]);
770 return 0;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800771}
772
773static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
774 struct snd_ctl_elem_value *ucontrol)
775{
776 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Lydia Wangcdc17842009-10-10 19:07:47 +0800777 struct via_spec *spec = codec->spec;
Lydia Wangcdc17842009-10-10 19:07:47 +0800778
Takashi Iwaiece8d042011-06-19 16:24:21 +0200779 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
Lydia Wangcdc17842009-10-10 19:07:47 +0800780 return 0;
781}
782
Takashi Iwai3b607e32011-07-18 16:54:40 +0200783/* adjust spec->multiout setup according to the current flags */
784static void setup_playback_multi_pcm(struct via_spec *spec)
785{
786 const struct auto_pin_cfg *cfg = &spec->autocfg;
787 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
788 spec->multiout.hp_nid = 0;
789 if (!spec->hp_independent_mode) {
790 if (!spec->hp_indep_shared)
791 spec->multiout.hp_nid = spec->hp_dac_nid;
792 } else {
793 if (spec->hp_indep_shared)
794 spec->multiout.num_dacs = cfg->line_outs - 1;
795 }
796}
797
798/* update DAC setups according to indep-HP switch;
799 * this function is called only when indep-HP is modified
800 */
801static void switch_indep_hp_dacs(struct hda_codec *codec)
802{
803 struct via_spec *spec = codec->spec;
804 int shared = spec->hp_indep_shared;
805 hda_nid_t shared_dac, hp_dac;
806
807 if (!spec->opened_streams)
808 return;
809
810 shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
811 hp_dac = spec->hp_dac_nid;
812 if (spec->hp_independent_mode) {
813 /* switch to indep-HP mode */
814 if (spec->active_streams & STREAM_MULTI_OUT) {
815 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
816 __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
817 }
818 if (spec->active_streams & STREAM_INDEP_HP)
819 snd_hda_codec_setup_stream(codec, hp_dac,
820 spec->cur_hp_stream_tag, 0,
821 spec->cur_hp_format);
822 } else {
823 /* back to HP or shared-DAC */
824 if (spec->active_streams & STREAM_INDEP_HP)
825 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
826 if (spec->active_streams & STREAM_MULTI_OUT) {
827 hda_nid_t dac;
828 int ch;
829 if (shared_dac) { /* reset mutli-ch DAC */
830 dac = shared_dac;
831 ch = shared * 2;
832 } else { /* reset HP DAC */
833 dac = hp_dac;
834 ch = 0;
835 }
836 snd_hda_codec_setup_stream(codec, dac,
837 spec->cur_dac_stream_tag, ch,
838 spec->cur_dac_format);
839 }
840 }
841 setup_playback_multi_pcm(spec);
842}
843
Harald Welte0aa62ae2008-09-09 15:58:27 +0800844static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
845 struct snd_ctl_elem_value *ucontrol)
846{
847 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
848 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +0200849 int cur, shared;
Takashi Iwai8df2a312011-06-21 11:48:29 +0200850
Takashi Iwai3b607e32011-07-18 16:54:40 +0200851 mutex_lock(&spec->config_mutex);
Takashi Iwai25250502011-06-30 17:24:47 +0200852 cur = !!ucontrol->value.enumerated.item[0];
Takashi Iwai3b607e32011-07-18 16:54:40 +0200853 if (spec->hp_independent_mode == cur) {
854 mutex_unlock(&spec->config_mutex);
Takashi Iwai25250502011-06-30 17:24:47 +0200855 return 0;
Takashi Iwai3b607e32011-07-18 16:54:40 +0200856 }
Takashi Iwai25250502011-06-30 17:24:47 +0200857 spec->hp_independent_mode = cur;
Takashi Iwai3214b962011-07-18 12:49:25 +0200858 shared = spec->hp_indep_shared;
Takashi Iwai020066d2011-07-21 13:45:56 +0200859 deactivate_hp_paths(codec);
860 if (cur)
861 activate_output_path(codec, &spec->hp_indep_path, true, false);
862 else {
Takashi Iwai3214b962011-07-18 12:49:25 +0200863 if (shared)
864 activate_output_path(codec, &spec->out_path[shared],
Takashi Iwai25250502011-06-30 17:24:47 +0200865 true, false);
Takashi Iwai020066d2011-07-21 13:45:56 +0200866 if (spec->aamix_mode || !spec->hp_path.depth)
867 activate_output_path(codec, &spec->hp_mix_path,
868 true, false);
869 else
870 activate_output_path(codec, &spec->hp_path,
871 true, false);
Takashi Iwai8df2a312011-06-21 11:48:29 +0200872 }
Harald Welte0aa62ae2008-09-09 15:58:27 +0800873
Takashi Iwai3b607e32011-07-18 16:54:40 +0200874 switch_indep_hp_dacs(codec);
875 mutex_unlock(&spec->config_mutex);
876
Lydia Wangce0e5a92011-03-22 16:22:37 +0800877 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800878 set_widgets_power_state(codec);
Takashi Iwai6e969d92011-07-11 11:28:13 +0200879 via_hp_automute(codec);
Takashi Iwai25250502011-06-30 17:24:47 +0200880 return 1;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800881}
882
Takashi Iwaiece8d042011-06-19 16:24:21 +0200883static const struct snd_kcontrol_new via_hp_mixer = {
884 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
885 .name = "Independent HP",
886 .info = via_independent_hp_info,
887 .get = via_independent_hp_get,
888 .put = via_independent_hp_put,
Harald Welte0aa62ae2008-09-09 15:58:27 +0800889};
890
Takashi Iwai3d83e572010-04-14 14:36:23 +0200891static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100892{
Takashi Iwai3d83e572010-04-14 14:36:23 +0200893 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100894 struct snd_kcontrol_new *knew;
895 hda_nid_t nid;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100896
Takashi Iwaiece8d042011-06-19 16:24:21 +0200897 nid = spec->autocfg.hp_pins[0];
898 knew = via_clone_control(spec, &via_hp_mixer);
Takashi Iwai3d83e572010-04-14 14:36:23 +0200899 if (knew == NULL)
900 return -ENOMEM;
901
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100902 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100903
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100904 return 0;
905}
906
Lydia Wang1564b282009-10-10 19:07:52 +0800907static void notify_aa_path_ctls(struct hda_codec *codec)
908{
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200909 struct via_spec *spec = codec->spec;
Lydia Wang1564b282009-10-10 19:07:52 +0800910 int i;
Lydia Wang1564b282009-10-10 19:07:52 +0800911
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200912 for (i = 0; i < spec->smart51_nums; i++) {
913 struct snd_kcontrol *ctl;
914 struct snd_ctl_elem_id id;
915 memset(&id, 0, sizeof(id));
916 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
917 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
Lydia Wang525566c2011-04-28 16:03:39 +0800918 ctl = snd_hda_find_mixer_ctl(codec, id.name);
919 if (ctl)
920 snd_ctl_notify(codec->bus->card,
921 SNDRV_CTL_EVENT_MASK_VALUE,
922 &ctl->id);
Lydia Wang1564b282009-10-10 19:07:52 +0800923 }
924}
925
926static void mute_aa_path(struct hda_codec *codec, int mute)
927{
928 struct via_spec *spec = codec->spec;
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200929 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
Lydia Wang1564b282009-10-10 19:07:52 +0800930 int i;
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200931
Lydia Wang1564b282009-10-10 19:07:52 +0800932 /* check AA path's mute status */
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200933 for (i = 0; i < spec->smart51_nums; i++) {
934 if (spec->smart51_idxs[i] < 0)
935 continue;
936 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
937 HDA_INPUT, spec->smart51_idxs[i],
Lydia Wang1564b282009-10-10 19:07:52 +0800938 HDA_AMP_MUTE, val);
939 }
940}
Takashi Iwaif4a78282011-06-17 18:46:48 +0200941
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200942static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
943{
944 struct via_spec *spec = codec->spec;
945 int i;
946
947 for (i = 0; i < spec->smart51_nums; i++)
948 if (spec->smart51_pins[i] == pin)
949 return true;
950 return false;
951}
952
Lydia Wang1564b282009-10-10 19:07:52 +0800953static int via_smart51_get(struct snd_kcontrol *kcontrol,
954 struct snd_ctl_elem_value *ucontrol)
955{
956 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
957 struct via_spec *spec = codec->spec;
Lydia Wang1564b282009-10-10 19:07:52 +0800958
Takashi Iwaif2b1c9f2011-06-21 16:52:39 +0200959 *ucontrol->value.integer.value = spec->smart51_enabled;
Lydia Wang1564b282009-10-10 19:07:52 +0800960 return 0;
961}
962
963static int via_smart51_put(struct snd_kcontrol *kcontrol,
964 struct snd_ctl_elem_value *ucontrol)
965{
966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
967 struct via_spec *spec = codec->spec;
968 int out_in = *ucontrol->value.integer.value
969 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +0800970 int i;
971
Takashi Iwaie3d7a142011-06-20 13:52:33 +0200972 for (i = 0; i < spec->smart51_nums; i++) {
973 hda_nid_t nid = spec->smart51_pins[i];
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200974 unsigned int parm;
975
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200976 parm = snd_hda_codec_read(codec, nid, 0,
977 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
978 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
979 parm |= out_in;
980 snd_hda_codec_write(codec, nid, 0,
981 AC_VERB_SET_PIN_WIDGET_CONTROL,
982 parm);
983 if (out_in == AC_PINCTL_OUT_EN) {
984 mute_aa_path(codec, 1);
985 notify_aa_path_ctls(codec);
986 }
Lydia Wang1564b282009-10-10 19:07:52 +0800987 }
988 spec->smart51_enabled = *ucontrol->value.integer.value;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800989 set_widgets_power_state(codec);
Lydia Wang1564b282009-10-10 19:07:52 +0800990 return 1;
991}
992
Takashi Iwai5f4b36d2011-06-17 14:55:02 +0200993static const struct snd_kcontrol_new via_smart51_mixer = {
994 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
995 .name = "Smart 5.1",
996 .count = 1,
Takashi Iwaif2b1c9f2011-06-21 16:52:39 +0200997 .info = snd_ctl_boolean_mono_info,
Takashi Iwai5f4b36d2011-06-17 14:55:02 +0200998 .get = via_smart51_get,
999 .put = via_smart51_put,
Lydia Wang1564b282009-10-10 19:07:52 +08001000};
1001
Takashi Iwaif4a78282011-06-17 18:46:48 +02001002static int via_smart51_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001003{
Takashi Iwaif4a78282011-06-17 18:46:48 +02001004 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001005
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001006 if (!spec->smart51_nums)
Lydia Wangcb34c202011-04-27 17:44:16 +08001007 return 0;
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001008 if (!via_clone_control(spec, &via_smart51_mixer))
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001009 return -ENOMEM;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001010 return 0;
1011}
1012
Takashi Iwaiada509e2011-06-20 15:40:19 +02001013/* check AA path's mute status */
1014static bool is_aa_path_mute(struct hda_codec *codec)
Lydia Wangf5271102009-10-10 19:07:35 +08001015{
Lydia Wangf5271102009-10-10 19:07:35 +08001016 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001017 const struct hda_amp_list *p;
1018 int i, ch, v;
1019
1020 for (i = 0; i < spec->num_loopbacks; i++) {
1021 p = &spec->loopback_list[i];
1022 for (ch = 0; ch < 2; ch++) {
1023 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
1024 p->idx);
1025 if (!(v & HDA_AMP_MUTE) && v > 0)
1026 return false;
Lydia Wangf5271102009-10-10 19:07:35 +08001027 }
1028 }
Takashi Iwaiada509e2011-06-20 15:40:19 +02001029 return true;
Lydia Wangf5271102009-10-10 19:07:35 +08001030}
1031
1032/* enter/exit analog low-current mode */
Takashi Iwaiada509e2011-06-20 15:40:19 +02001033static void analog_low_current_mode(struct hda_codec *codec)
Lydia Wangf5271102009-10-10 19:07:35 +08001034{
1035 struct via_spec *spec = codec->spec;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001036 bool enable;
1037 unsigned int verb, parm;
Lydia Wangf5271102009-10-10 19:07:35 +08001038
Takashi Iwai3b607e32011-07-18 16:54:40 +02001039 enable = is_aa_path_mute(codec) && (spec->opened_streams != 0);
Lydia Wangf5271102009-10-10 19:07:35 +08001040
1041 /* decide low current mode's verb & parameter */
1042 switch (spec->codec_type) {
1043 case VT1708B_8CH:
1044 case VT1708B_4CH:
1045 verb = 0xf70;
1046 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1047 break;
1048 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001049 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001050 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001051 verb = 0xf73;
1052 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1053 break;
1054 case VT1702:
1055 verb = 0xf73;
1056 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1057 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001058 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001059 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001060 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001061 verb = 0xf93;
1062 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1063 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001064 default:
1065 return; /* other codecs are not supported */
1066 }
1067 /* send verb */
1068 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1069}
1070
Joseph Chanc577b8a2006-11-29 15:29:40 +01001071/*
1072 * generic initialization of ADC, input mixers and output mixers
1073 */
Takashi Iwai096a8852011-06-20 12:09:02 +02001074static const struct hda_verb vt1708_init_verbs[] = {
Lydia Wangaa266fc2011-03-24 12:41:01 +08001075 /* power down jack detect function */
1076 {0x1, 0xf81, 0x1},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001077 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001078};
1079
Takashi Iwai3b607e32011-07-18 16:54:40 +02001080static void set_stream_open(struct hda_codec *codec, int bit, bool active)
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001081{
Takashi Iwaiada509e2011-06-20 15:40:19 +02001082 struct via_spec *spec = codec->spec;
1083
1084 if (active)
Takashi Iwai3b607e32011-07-18 16:54:40 +02001085 spec->opened_streams |= bit;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001086 else
Takashi Iwai3b607e32011-07-18 16:54:40 +02001087 spec->opened_streams &= ~bit;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001088 analog_low_current_mode(codec);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001089}
1090
Takashi Iwaiece8d042011-06-19 16:24:21 +02001091static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001092 struct hda_codec *codec,
1093 struct snd_pcm_substream *substream)
1094{
1095 struct via_spec *spec = codec->spec;
Takashi Iwai25250502011-06-30 17:24:47 +02001096 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaiada509e2011-06-20 15:40:19 +02001097 int err;
Takashi Iwaiece8d042011-06-19 16:24:21 +02001098
Takashi Iwai25250502011-06-30 17:24:47 +02001099 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
Takashi Iwai25250502011-06-30 17:24:47 +02001100 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai3b607e32011-07-18 16:54:40 +02001101 set_stream_open(codec, STREAM_MULTI_OUT, true);
Takashi Iwaiada509e2011-06-20 15:40:19 +02001102 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1103 hinfo);
1104 if (err < 0) {
Takashi Iwai3b607e32011-07-18 16:54:40 +02001105 set_stream_open(codec, STREAM_MULTI_OUT, false);
Takashi Iwaiada509e2011-06-20 15:40:19 +02001106 return err;
1107 }
1108 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001109}
1110
Takashi Iwaiece8d042011-06-19 16:24:21 +02001111static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
Takashi Iwai9af74212011-06-18 16:17:45 +02001112 struct hda_codec *codec,
1113 struct snd_pcm_substream *substream)
1114{
Takashi Iwai3b607e32011-07-18 16:54:40 +02001115 set_stream_open(codec, STREAM_MULTI_OUT, false);
Takashi Iwai9af74212011-06-18 16:17:45 +02001116 return 0;
1117}
1118
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001119static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1120 struct hda_codec *codec,
1121 struct snd_pcm_substream *substream)
1122{
1123 struct via_spec *spec = codec->spec;
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001124
Takashi Iwaiece8d042011-06-19 16:24:21 +02001125 if (snd_BUG_ON(!spec->hp_dac_nid))
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001126 return -EINVAL;
Takashi Iwai3b607e32011-07-18 16:54:40 +02001127 set_stream_open(codec, STREAM_INDEP_HP, true);
Takashi Iwaiece8d042011-06-19 16:24:21 +02001128 return 0;
1129}
1130
1131static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1132 struct hda_codec *codec,
1133 struct snd_pcm_substream *substream)
1134{
Takashi Iwai3b607e32011-07-18 16:54:40 +02001135 set_stream_open(codec, STREAM_INDEP_HP, false);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001136 return 0;
1137}
1138
1139static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1140 struct hda_codec *codec,
1141 unsigned int stream_tag,
1142 unsigned int format,
1143 struct snd_pcm_substream *substream)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001144{
1145 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001146
Takashi Iwai3b607e32011-07-18 16:54:40 +02001147 mutex_lock(&spec->config_mutex);
1148 setup_playback_multi_pcm(spec);
Takashi Iwaiece8d042011-06-19 16:24:21 +02001149 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1150 format, substream);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001151 /* remember for dynamic DAC switch with indep-HP */
1152 spec->active_streams |= STREAM_MULTI_OUT;
1153 spec->cur_dac_stream_tag = stream_tag;
1154 spec->cur_dac_format = format;
1155 mutex_unlock(&spec->config_mutex);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001156 vt1708_start_hp_work(spec);
1157 return 0;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001158}
1159
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001160static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1161 struct hda_codec *codec,
1162 unsigned int stream_tag,
1163 unsigned int format,
1164 struct snd_pcm_substream *substream)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001165{
1166 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001167
Takashi Iwai3b607e32011-07-18 16:54:40 +02001168 mutex_lock(&spec->config_mutex);
1169 if (spec->hp_independent_mode)
1170 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1171 stream_tag, 0, format);
1172 spec->active_streams |= STREAM_INDEP_HP;
1173 spec->cur_hp_stream_tag = stream_tag;
1174 spec->cur_hp_format = format;
1175 mutex_unlock(&spec->config_mutex);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001176 vt1708_start_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001177 return 0;
1178}
1179
1180static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1181 struct hda_codec *codec,
1182 struct snd_pcm_substream *substream)
1183{
1184 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001185
Takashi Iwai3b607e32011-07-18 16:54:40 +02001186 mutex_lock(&spec->config_mutex);
Takashi Iwaiece8d042011-06-19 16:24:21 +02001187 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001188 spec->active_streams &= ~STREAM_MULTI_OUT;
1189 mutex_unlock(&spec->config_mutex);
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001190 vt1708_stop_hp_work(spec);
1191 return 0;
1192}
1193
1194static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1195 struct hda_codec *codec,
1196 struct snd_pcm_substream *substream)
1197{
1198 struct via_spec *spec = codec->spec;
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001199
Takashi Iwai3b607e32011-07-18 16:54:40 +02001200 mutex_lock(&spec->config_mutex);
1201 if (spec->hp_independent_mode)
1202 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1203 spec->active_streams &= ~STREAM_INDEP_HP;
1204 mutex_unlock(&spec->config_mutex);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001205 vt1708_stop_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001206 return 0;
1207}
1208
Joseph Chanc577b8a2006-11-29 15:29:40 +01001209/*
1210 * Digital out
1211 */
1212static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1213 struct hda_codec *codec,
1214 struct snd_pcm_substream *substream)
1215{
1216 struct via_spec *spec = codec->spec;
1217 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1218}
1219
1220static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1221 struct hda_codec *codec,
1222 struct snd_pcm_substream *substream)
1223{
1224 struct via_spec *spec = codec->spec;
1225 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1226}
1227
Harald Welte5691ec72008-09-15 22:42:26 +08001228static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001229 struct hda_codec *codec,
1230 unsigned int stream_tag,
1231 unsigned int format,
1232 struct snd_pcm_substream *substream)
1233{
1234 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001235 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1236 stream_tag, format, substream);
1237}
Harald Welte5691ec72008-09-15 22:42:26 +08001238
Takashi Iwai9da29272009-05-07 16:31:14 +02001239static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1240 struct hda_codec *codec,
1241 struct snd_pcm_substream *substream)
1242{
1243 struct via_spec *spec = codec->spec;
1244 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001245 return 0;
1246}
1247
Joseph Chanc577b8a2006-11-29 15:29:40 +01001248/*
1249 * Analog capture
1250 */
1251static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1252 struct hda_codec *codec,
1253 unsigned int stream_tag,
1254 unsigned int format,
1255 struct snd_pcm_substream *substream)
1256{
1257 struct via_spec *spec = codec->spec;
1258
1259 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1260 stream_tag, 0, format);
1261 return 0;
1262}
1263
1264static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1265 struct hda_codec *codec,
1266 struct snd_pcm_substream *substream)
1267{
1268 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001269 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001270 return 0;
1271}
1272
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001273/* analog capture with dynamic ADC switching */
1274static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1275 struct hda_codec *codec,
1276 unsigned int stream_tag,
1277 unsigned int format,
1278 struct snd_pcm_substream *substream)
1279{
1280 struct via_spec *spec = codec->spec;
1281 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1282
Takashi Iwai3b607e32011-07-18 16:54:40 +02001283 mutex_lock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001284 spec->cur_adc = spec->adc_nids[adc_idx];
1285 spec->cur_adc_stream_tag = stream_tag;
1286 spec->cur_adc_format = format;
1287 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001288 mutex_unlock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001289 return 0;
1290}
1291
1292static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1293 struct hda_codec *codec,
1294 struct snd_pcm_substream *substream)
1295{
1296 struct via_spec *spec = codec->spec;
1297
Takashi Iwai3b607e32011-07-18 16:54:40 +02001298 mutex_lock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001299 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1300 spec->cur_adc = 0;
Takashi Iwai3b607e32011-07-18 16:54:40 +02001301 mutex_unlock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001302 return 0;
1303}
1304
1305/* re-setup the stream if running; called from input-src put */
1306static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1307{
1308 struct via_spec *spec = codec->spec;
1309 int adc_idx = spec->inputs[cur].adc_idx;
1310 hda_nid_t adc = spec->adc_nids[adc_idx];
Takashi Iwai3b607e32011-07-18 16:54:40 +02001311 bool ret = false;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001312
Takashi Iwai3b607e32011-07-18 16:54:40 +02001313 mutex_lock(&spec->config_mutex);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001314 if (spec->cur_adc && spec->cur_adc != adc) {
1315 /* stream is running, let's swap the current ADC */
1316 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1317 spec->cur_adc = adc;
1318 snd_hda_codec_setup_stream(codec, adc,
1319 spec->cur_adc_stream_tag, 0,
1320 spec->cur_adc_format);
Takashi Iwai3b607e32011-07-18 16:54:40 +02001321 ret = true;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001322 }
Takashi Iwai3b607e32011-07-18 16:54:40 +02001323 mutex_unlock(&spec->config_mutex);
1324 return ret;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001325}
1326
Takashi Iwai9af74212011-06-18 16:17:45 +02001327static const struct hda_pcm_stream via_pcm_analog_playback = {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001328 .substreams = 1,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001329 .channels_min = 2,
1330 .channels_max = 8,
Takashi Iwai9af74212011-06-18 16:17:45 +02001331 /* NID is set in via_build_pcms */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001332 .ops = {
Takashi Iwaiece8d042011-06-19 16:24:21 +02001333 .open = via_playback_multi_pcm_open,
1334 .close = via_playback_multi_pcm_close,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001335 .prepare = via_playback_multi_pcm_prepare,
1336 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001337 },
1338};
1339
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001340static const struct hda_pcm_stream via_pcm_hp_playback = {
1341 .substreams = 1,
1342 .channels_min = 2,
1343 .channels_max = 2,
1344 /* NID is set in via_build_pcms */
1345 .ops = {
1346 .open = via_playback_hp_pcm_open,
Takashi Iwaiece8d042011-06-19 16:24:21 +02001347 .close = via_playback_hp_pcm_close,
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001348 .prepare = via_playback_hp_pcm_prepare,
1349 .cleanup = via_playback_hp_pcm_cleanup
1350 },
1351};
1352
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001353static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001354 .substreams = 1,
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001355 .channels_min = 2,
1356 .channels_max = 8,
Takashi Iwai9af74212011-06-18 16:17:45 +02001357 /* NID is set in via_build_pcms */
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001358 /* We got noisy outputs on the right channel on VT1708 when
1359 * 24bit samples are used. Until any workaround is found,
1360 * disable the 24bit format, so far.
1361 */
1362 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1363 .ops = {
Takashi Iwaiece8d042011-06-19 16:24:21 +02001364 .open = via_playback_multi_pcm_open,
1365 .close = via_playback_multi_pcm_close,
Lydia Wangc873cc22009-10-10 19:08:21 +08001366 .prepare = via_playback_multi_pcm_prepare,
1367 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001368 },
1369};
1370
Takashi Iwai9af74212011-06-18 16:17:45 +02001371static const struct hda_pcm_stream via_pcm_analog_capture = {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001372 .substreams = 1, /* will be changed in via_build_pcms() */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001373 .channels_min = 2,
1374 .channels_max = 2,
Takashi Iwai9af74212011-06-18 16:17:45 +02001375 /* NID is set in via_build_pcms */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001376 .ops = {
1377 .prepare = via_capture_pcm_prepare,
1378 .cleanup = via_capture_pcm_cleanup
1379 },
1380};
1381
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001382static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1383 .substreams = 1,
1384 .channels_min = 2,
1385 .channels_max = 2,
1386 /* NID is set in via_build_pcms */
1387 .ops = {
1388 .prepare = via_dyn_adc_capture_pcm_prepare,
1389 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1390 },
1391};
1392
Takashi Iwai9af74212011-06-18 16:17:45 +02001393static const struct hda_pcm_stream via_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001394 .substreams = 1,
1395 .channels_min = 2,
1396 .channels_max = 2,
1397 /* NID is set in via_build_pcms */
1398 .ops = {
1399 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001400 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001401 .prepare = via_dig_playback_pcm_prepare,
1402 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001403 },
1404};
1405
Takashi Iwai9af74212011-06-18 16:17:45 +02001406static const struct hda_pcm_stream via_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001407 .substreams = 1,
1408 .channels_min = 2,
1409 .channels_max = 2,
1410};
1411
Takashi Iwai370bafb2011-06-20 12:47:45 +02001412/*
1413 * slave controls for virtual master
1414 */
1415static const char * const via_slave_vols[] = {
1416 "Front Playback Volume",
1417 "Surround Playback Volume",
1418 "Center Playback Volume",
1419 "LFE Playback Volume",
1420 "Side Playback Volume",
1421 "Headphone Playback Volume",
1422 "Speaker Playback Volume",
1423 NULL,
1424};
1425
1426static const char * const via_slave_sws[] = {
1427 "Front Playback Switch",
1428 "Surround Playback Switch",
1429 "Center Playback Switch",
1430 "LFE Playback Switch",
1431 "Side Playback Switch",
1432 "Headphone Playback Switch",
1433 "Speaker Playback Switch",
1434 NULL,
1435};
1436
Joseph Chanc577b8a2006-11-29 15:29:40 +01001437static int via_build_controls(struct hda_codec *codec)
1438{
1439 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001440 struct snd_kcontrol *kctl;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001441 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001442
Takashi Iwai24088a52011-06-17 16:59:21 +02001443 if (spec->set_widgets_power_state)
1444 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1445 return -ENOMEM;
1446
Joseph Chanc577b8a2006-11-29 15:29:40 +01001447 for (i = 0; i < spec->num_mixers; i++) {
1448 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1449 if (err < 0)
1450 return err;
1451 }
1452
1453 if (spec->multiout.dig_out_nid) {
1454 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001455 spec->multiout.dig_out_nid,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001456 spec->multiout.dig_out_nid);
1457 if (err < 0)
1458 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001459 err = snd_hda_create_spdif_share_sw(codec,
1460 &spec->multiout);
1461 if (err < 0)
1462 return err;
1463 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001464 }
1465 if (spec->dig_in_nid) {
1466 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1467 if (err < 0)
1468 return err;
1469 }
Lydia Wang17314372009-10-10 19:07:37 +08001470
Takashi Iwai370bafb2011-06-20 12:47:45 +02001471 /* if we have no master control, let's create it */
1472 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1473 unsigned int vmaster_tlv[4];
1474 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1475 HDA_OUTPUT, vmaster_tlv);
1476 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1477 vmaster_tlv, via_slave_vols);
1478 if (err < 0)
1479 return err;
1480 }
1481 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1482 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1483 NULL, via_slave_sws);
1484 if (err < 0)
1485 return err;
1486 }
1487
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001488 /* assign Capture Source enums to NID */
1489 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1490 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +01001491 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001492 if (err < 0)
1493 return err;
1494 }
1495
Lydia Wang17314372009-10-10 19:07:37 +08001496 /* init power states */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001497 set_widgets_power_state(codec);
Takashi Iwaiada509e2011-06-20 15:40:19 +02001498 analog_low_current_mode(codec);
Lydia Wang17314372009-10-10 19:07:37 +08001499
Takashi Iwai603c4012008-07-30 15:01:44 +02001500 via_free_kctls(codec); /* no longer needed */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001501 return 0;
1502}
1503
1504static int via_build_pcms(struct hda_codec *codec)
1505{
1506 struct via_spec *spec = codec->spec;
1507 struct hda_pcm *info = spec->pcm_rec;
1508
1509 codec->num_pcms = 1;
1510 codec->pcm_info = info;
1511
Takashi Iwai82673bc2011-06-17 16:24:21 +02001512 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1513 "%s Analog", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001514 info->name = spec->stream_name_analog;
Takashi Iwai9af74212011-06-18 16:17:45 +02001515
1516 if (!spec->stream_analog_playback)
1517 spec->stream_analog_playback = &via_pcm_analog_playback;
Lydia Wang377ff312009-10-10 19:08:55 +08001518 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001519 *spec->stream_analog_playback;
Lydia Wang377ff312009-10-10 19:08:55 +08001520 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1521 spec->multiout.dac_nids[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001522 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1523 spec->multiout.max_channels;
Takashi Iwai9af74212011-06-18 16:17:45 +02001524
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001525 if (!spec->stream_analog_capture) {
1526 if (spec->dyn_adc_switch)
1527 spec->stream_analog_capture =
1528 &via_pcm_dyn_adc_analog_capture;
1529 else
1530 spec->stream_analog_capture = &via_pcm_analog_capture;
1531 }
Takashi Iwai9af74212011-06-18 16:17:45 +02001532 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1533 *spec->stream_analog_capture;
1534 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001535 if (!spec->dyn_adc_switch)
1536 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1537 spec->num_adc_nids;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001538
1539 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1540 codec->num_pcms++;
1541 info++;
Takashi Iwai82673bc2011-06-17 16:24:21 +02001542 snprintf(spec->stream_name_digital,
1543 sizeof(spec->stream_name_digital),
1544 "%s Digital", codec->chip_name);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001545 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001546 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001547 if (spec->multiout.dig_out_nid) {
Takashi Iwai9af74212011-06-18 16:17:45 +02001548 if (!spec->stream_digital_playback)
1549 spec->stream_digital_playback =
1550 &via_pcm_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001551 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001552 *spec->stream_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001553 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1554 spec->multiout.dig_out_nid;
1555 }
1556 if (spec->dig_in_nid) {
Takashi Iwai9af74212011-06-18 16:17:45 +02001557 if (!spec->stream_digital_capture)
1558 spec->stream_digital_capture =
1559 &via_pcm_digital_capture;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001560 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
Takashi Iwai9af74212011-06-18 16:17:45 +02001561 *spec->stream_digital_capture;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001562 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1563 spec->dig_in_nid;
1564 }
1565 }
1566
Takashi Iwaiece8d042011-06-19 16:24:21 +02001567 if (spec->hp_dac_nid) {
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001568 codec->num_pcms++;
1569 info++;
1570 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1571 "%s HP", codec->chip_name);
1572 info->name = spec->stream_name_hp;
1573 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1574 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
Takashi Iwaiece8d042011-06-19 16:24:21 +02001575 spec->hp_dac_nid;
Takashi Iwai7eb56e82011-06-18 16:40:14 +02001576 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001577 return 0;
1578}
1579
1580static void via_free(struct hda_codec *codec)
1581{
1582 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001583
1584 if (!spec)
1585 return;
1586
Takashi Iwai603c4012008-07-30 15:01:44 +02001587 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001588 vt1708_stop_hp_work(spec);
Takashi Iwaia86a88e2011-06-22 15:23:25 +02001589 kfree(spec->bind_cap_vol);
1590 kfree(spec->bind_cap_sw);
1591 kfree(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001592}
1593
Takashi Iwai64be2852011-06-17 16:51:39 +02001594/* mute/unmute outputs */
1595static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1596 hda_nid_t *pins, bool mute)
1597{
1598 int i;
Takashi Iwai94994732011-07-11 11:36:44 +02001599 for (i = 0; i < num_pins; i++) {
1600 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1601 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1602 if (parm & AC_PINCTL_IN_EN)
1603 continue;
1604 if (mute)
1605 parm &= ~AC_PINCTL_OUT_EN;
1606 else
1607 parm |= AC_PINCTL_OUT_EN;
Takashi Iwai64be2852011-06-17 16:51:39 +02001608 snd_hda_codec_write(codec, pins[i], 0,
Takashi Iwai94994732011-07-11 11:36:44 +02001609 AC_VERB_SET_PIN_WIDGET_CONTROL, parm);
1610 }
Takashi Iwai64be2852011-06-17 16:51:39 +02001611}
1612
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001613/* mute internal speaker if line-out is plugged */
1614static void via_line_automute(struct hda_codec *codec, int present)
1615{
1616 struct via_spec *spec = codec->spec;
1617
1618 if (!spec->autocfg.speaker_outs)
1619 return;
1620 if (!present)
1621 present = snd_hda_jack_detect(codec,
1622 spec->autocfg.line_out_pins[0]);
1623 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1624 spec->autocfg.speaker_pins,
1625 present);
1626}
1627
Harald Welte69e52a82008-09-09 15:57:32 +08001628/* mute internal speaker if HP is plugged */
1629static void via_hp_automute(struct hda_codec *codec)
1630{
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001631 int present = 0;
Takashi Iwai6e969d92011-07-11 11:28:13 +02001632 int nums;
Harald Welte69e52a82008-09-09 15:57:32 +08001633 struct via_spec *spec = codec->spec;
1634
Takashi Iwai6e969d92011-07-11 11:28:13 +02001635 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0])
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001636 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Takashi Iwai6e969d92011-07-11 11:28:13 +02001637
1638 if (spec->smart51_enabled)
1639 nums = spec->autocfg.line_outs + spec->smart51_nums;
1640 else
1641 nums = spec->autocfg.line_outs;
1642 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1643
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001644 via_line_automute(codec, present);
Lydia Wangf3db4232009-10-10 19:08:41 +08001645}
1646
Harald Welte69e52a82008-09-09 15:57:32 +08001647static void via_gpio_control(struct hda_codec *codec)
1648{
1649 unsigned int gpio_data;
1650 unsigned int vol_counter;
1651 unsigned int vol;
1652 unsigned int master_vol;
1653
1654 struct via_spec *spec = codec->spec;
1655
1656 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1657 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1658
1659 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1660 0xF84, 0) & 0x3F0000) >> 16;
1661
1662 vol = vol_counter & 0x1F;
1663 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1664 AC_VERB_GET_AMP_GAIN_MUTE,
1665 AC_AMP_GET_INPUT);
1666
1667 if (gpio_data == 0x02) {
1668 /* unmute line out */
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001669 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1670 AC_VERB_SET_PIN_WIDGET_CONTROL,
1671 PIN_OUT);
Harald Welte69e52a82008-09-09 15:57:32 +08001672 if (vol_counter & 0x20) {
1673 /* decrease volume */
1674 if (vol > master_vol)
1675 vol = master_vol;
1676 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1677 0, HDA_AMP_VOLMASK,
1678 master_vol-vol);
1679 } else {
1680 /* increase volume */
1681 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1682 HDA_AMP_VOLMASK,
1683 ((master_vol+vol) > 0x2A) ? 0x2A :
1684 (master_vol+vol));
1685 }
1686 } else if (!(gpio_data & 0x02)) {
1687 /* mute line out */
Takashi Iwai3e0693e2011-06-17 16:37:45 +02001688 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1689 AC_VERB_SET_PIN_WIDGET_CONTROL,
1690 0);
Harald Welte69e52a82008-09-09 15:57:32 +08001691 }
1692}
1693
1694/* unsolicited event for jack sensing */
1695static void via_unsol_event(struct hda_codec *codec,
1696 unsigned int res)
1697{
1698 res >>= 26;
Lydia Wangec7e7e42011-03-24 12:43:44 +08001699
Lydia Wanga34df192009-10-10 19:08:01 +08001700 if (res & VIA_JACK_EVENT)
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001701 set_widgets_power_state(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001702
1703 res &= ~VIA_JACK_EVENT;
1704
Takashi Iwai21ce0b62011-07-11 10:33:47 +02001705 if (res == VIA_HP_EVENT || res == VIA_LINE_EVENT)
Lydia Wangec7e7e42011-03-24 12:43:44 +08001706 via_hp_automute(codec);
1707 else if (res == VIA_GPIO_EVENT)
1708 via_gpio_control(codec);
Harald Welte69e52a82008-09-09 15:57:32 +08001709}
1710
Takashi Iwai2a439522011-07-26 09:52:50 +02001711#ifdef CONFIG_PM
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001712static int via_suspend(struct hda_codec *codec, pm_message_t state)
1713{
1714 struct via_spec *spec = codec->spec;
1715 vt1708_stop_hp_work(spec);
1716 return 0;
1717}
1718#endif
1719
Takashi Iwaicb53c622007-08-10 17:21:45 +02001720#ifdef CONFIG_SND_HDA_POWER_SAVE
1721static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1722{
1723 struct via_spec *spec = codec->spec;
1724 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1725}
1726#endif
1727
Joseph Chanc577b8a2006-11-29 15:29:40 +01001728/*
1729 */
Takashi Iwai5d417622011-06-20 11:32:27 +02001730
1731static int via_init(struct hda_codec *codec);
1732
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001733static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001734 .build_controls = via_build_controls,
1735 .build_pcms = via_build_pcms,
1736 .init = via_init,
1737 .free = via_free,
Takashi Iwai4a918ff2011-06-20 12:39:26 +02001738 .unsol_event = via_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02001739#ifdef CONFIG_PM
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001740 .suspend = via_suspend,
1741#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02001742#ifdef CONFIG_SND_HDA_POWER_SAVE
1743 .check_power_status = via_check_power_status,
1744#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001745};
1746
Takashi Iwai4a796162011-06-17 17:53:38 +02001747static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001748{
Takashi Iwai4a796162011-06-17 17:53:38 +02001749 struct via_spec *spec = codec->spec;
1750 int i;
1751
1752 for (i = 0; i < spec->multiout.num_dacs; i++) {
1753 if (spec->multiout.dac_nids[i] == dac)
1754 return false;
1755 }
Takashi Iwaiece8d042011-06-19 16:24:21 +02001756 if (spec->hp_dac_nid == dac)
Takashi Iwai4a796162011-06-17 17:53:38 +02001757 return false;
1758 return true;
1759}
1760
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001761static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai3214b962011-07-18 12:49:25 +02001762 hda_nid_t target_dac, int with_aa_mix,
1763 struct nid_path *path, int depth)
Takashi Iwai4a796162011-06-17 17:53:38 +02001764{
Takashi Iwai3214b962011-07-18 12:49:25 +02001765 struct via_spec *spec = codec->spec;
Takashi Iwai4a796162011-06-17 17:53:38 +02001766 hda_nid_t conn[8];
1767 int i, nums;
1768
Takashi Iwai3214b962011-07-18 12:49:25 +02001769 if (nid == spec->aa_mix_nid) {
1770 if (!with_aa_mix)
1771 return false;
1772 with_aa_mix = 2; /* mark aa-mix is included */
1773 }
1774
Takashi Iwai4a796162011-06-17 17:53:38 +02001775 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1776 for (i = 0; i < nums; i++) {
1777 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1778 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +02001779 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1780 /* aa-mix is requested but not included? */
1781 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1782 goto found;
1783 }
Takashi Iwai4a796162011-06-17 17:53:38 +02001784 }
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001785 if (depth >= MAX_NID_PATH_DEPTH)
Takashi Iwai4a796162011-06-17 17:53:38 +02001786 return false;
1787 for (i = 0; i < nums; i++) {
1788 unsigned int type;
1789 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai3214b962011-07-18 12:49:25 +02001790 if (type == AC_WID_AUD_OUT)
Takashi Iwai4a796162011-06-17 17:53:38 +02001791 continue;
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001792 if (__parse_output_path(codec, conn[i], target_dac,
Takashi Iwai3214b962011-07-18 12:49:25 +02001793 with_aa_mix, path, depth + 1))
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001794 goto found;
Takashi Iwai4a796162011-06-17 17:53:38 +02001795 }
1796 return false;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001797
1798 found:
1799 path->path[path->depth] = conn[i];
1800 path->idx[path->depth] = i;
1801 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1802 path->multi[path->depth] = 1;
1803 path->depth++;
1804 return true;
Takashi Iwai4a796162011-06-17 17:53:38 +02001805}
1806
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001807static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai3214b962011-07-18 12:49:25 +02001808 hda_nid_t target_dac, int with_aa_mix,
1809 struct nid_path *path)
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001810{
Takashi Iwai3214b962011-07-18 12:49:25 +02001811 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001812 path->path[path->depth] = nid;
1813 path->depth++;
Takashi Iwai3214b962011-07-18 12:49:25 +02001814 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1815 path->depth, path->path[0], path->path[1],
1816 path->path[2], path->path[3], path->path[4]);
Takashi Iwai8e3679d2011-06-21 09:01:36 +02001817 return true;
1818 }
1819 return false;
1820}
1821
Takashi Iwai4a796162011-06-17 17:53:38 +02001822static int via_auto_fill_dac_nids(struct hda_codec *codec)
1823{
1824 struct via_spec *spec = codec->spec;
1825 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang5c9a5612011-07-08 14:03:43 +08001826 int i, dac_num;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001827 hda_nid_t nid;
1828
Joseph Chanc577b8a2006-11-29 15:29:40 +01001829 spec->multiout.dac_nids = spec->private_dac_nids;
Lydia Wang5c9a5612011-07-08 14:03:43 +08001830 dac_num = 0;
Takashi Iwai4a796162011-06-17 17:53:38 +02001831 for (i = 0; i < cfg->line_outs; i++) {
Takashi Iwai3214b962011-07-18 12:49:25 +02001832 hda_nid_t dac = 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001833 nid = cfg->line_out_pins[i];
Takashi Iwai4a796162011-06-17 17:53:38 +02001834 if (!nid)
1835 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +02001836 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1837 dac = spec->out_path[i].path[0];
1838 if (!i && parse_output_path(codec, nid, dac, 1,
1839 &spec->out_mix_path))
1840 dac = spec->out_mix_path.path[0];
1841 if (dac) {
1842 spec->private_dac_nids[i] = dac;
Lydia Wang5c9a5612011-07-08 14:03:43 +08001843 dac_num++;
1844 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001845 }
Takashi Iwai3214b962011-07-18 12:49:25 +02001846 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1847 spec->out_path[0] = spec->out_mix_path;
1848 spec->out_mix_path.depth = 0;
1849 }
Lydia Wang5c9a5612011-07-08 14:03:43 +08001850 spec->multiout.num_dacs = dac_num;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001851 return 0;
1852}
1853
Takashi Iwai4a796162011-06-17 17:53:38 +02001854static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001855 int chs, bool check_dac, struct nid_path *path)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001856{
Takashi Iwai4a796162011-06-17 17:53:38 +02001857 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001858 char name[32];
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001859 hda_nid_t dac, pin, sel, nid;
1860 int err;
Takashi Iwaia934d5a2011-06-21 14:22:14 +02001861
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001862 dac = check_dac ? path->path[0] : 0;
1863 pin = path->path[path->depth - 1];
1864 sel = path->depth > 1 ? path->path[1] : 0;
Takashi Iwai4a796162011-06-17 17:53:38 +02001865
Takashi Iwai8df2a312011-06-21 11:48:29 +02001866 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
Takashi Iwai4a796162011-06-17 17:53:38 +02001867 nid = dac;
Takashi Iwai8df2a312011-06-21 11:48:29 +02001868 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
Takashi Iwai4a796162011-06-17 17:53:38 +02001869 nid = pin;
Takashi Iwaia934d5a2011-06-21 14:22:14 +02001870 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1871 nid = sel;
Takashi Iwai4a796162011-06-17 17:53:38 +02001872 else
1873 nid = 0;
1874 if (nid) {
1875 sprintf(name, "%s Playback Volume", pfx);
1876 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wanga00a5fa2011-06-21 16:11:11 +08001877 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
Takashi Iwai4a796162011-06-17 17:53:38 +02001878 if (err < 0)
1879 return err;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001880 path->vol_ctl = nid;
Takashi Iwai4a796162011-06-17 17:53:38 +02001881 }
1882
Takashi Iwai8df2a312011-06-21 11:48:29 +02001883 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
Takashi Iwai4a796162011-06-17 17:53:38 +02001884 nid = dac;
Takashi Iwai8df2a312011-06-21 11:48:29 +02001885 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
Takashi Iwai4a796162011-06-17 17:53:38 +02001886 nid = pin;
Takashi Iwaia934d5a2011-06-21 14:22:14 +02001887 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1888 nid = sel;
Takashi Iwai4a796162011-06-17 17:53:38 +02001889 else
1890 nid = 0;
1891 if (nid) {
1892 sprintf(name, "%s Playback Switch", pfx);
1893 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1894 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1895 if (err < 0)
1896 return err;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02001897 path->mute_ctl = nid;
Takashi Iwai4a796162011-06-17 17:53:38 +02001898 }
1899 return 0;
1900}
1901
Takashi Iwaif4a78282011-06-17 18:46:48 +02001902static void mangle_smart51(struct hda_codec *codec)
1903{
1904 struct via_spec *spec = codec->spec;
1905 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai0f98c242011-06-21 12:51:33 +02001906 struct auto_pin_cfg_item *ins = cfg->inputs;
1907 int i, j, nums, attr;
1908 int pins[AUTO_CFG_MAX_INS];
Takashi Iwaif4a78282011-06-17 18:46:48 +02001909
Takashi Iwai0f98c242011-06-21 12:51:33 +02001910 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1911 nums = 0;
1912 for (i = 0; i < cfg->num_inputs; i++) {
1913 unsigned int def;
1914 if (ins[i].type > AUTO_PIN_LINE_IN)
1915 continue;
1916 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1917 if (snd_hda_get_input_pin_attr(def) != attr)
1918 continue;
1919 for (j = 0; j < nums; j++)
1920 if (ins[pins[j]].type < ins[i].type) {
1921 memmove(pins + j + 1, pins + j,
Takashi Iwai21d45d22011-07-08 11:35:11 +02001922 (nums - j) * sizeof(int));
Takashi Iwai0f98c242011-06-21 12:51:33 +02001923 break;
1924 }
1925 pins[j] = i;
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001926 nums++;
Takashi Iwai0f98c242011-06-21 12:51:33 +02001927 }
1928 if (cfg->line_outs + nums < 3)
Takashi Iwaif4a78282011-06-17 18:46:48 +02001929 continue;
Takashi Iwai0f98c242011-06-21 12:51:33 +02001930 for (i = 0; i < nums; i++) {
1931 hda_nid_t pin = ins[pins[i]].pin;
1932 spec->smart51_pins[spec->smart51_nums++] = pin;
1933 cfg->line_out_pins[cfg->line_outs++] = pin;
1934 if (cfg->line_outs == 3)
1935 break;
1936 }
1937 return;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001938 }
1939}
1940
Takashi Iwai020066d2011-07-21 13:45:56 +02001941static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
1942{
1943 dst->vol_ctl = src->vol_ctl;
1944 dst->mute_ctl = src->mute_ctl;
1945}
1946
Takashi Iwai4a796162011-06-17 17:53:38 +02001947/* add playback controls from the parsed DAC table */
1948static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1949{
1950 struct via_spec *spec = codec->spec;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001951 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai3214b962011-07-18 12:49:25 +02001952 struct nid_path *path;
Takashi Iwaiea734962011-01-17 11:29:34 +01001953 static const char * const chname[4] = {
1954 "Front", "Surround", "C/LFE", "Side"
1955 };
Takashi Iwai4a796162011-06-17 17:53:38 +02001956 int i, idx, err;
Takashi Iwaif4a78282011-06-17 18:46:48 +02001957 int old_line_outs;
1958
1959 /* check smart51 */
1960 old_line_outs = cfg->line_outs;
1961 if (cfg->line_outs == 1)
1962 mangle_smart51(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001963
Takashi Iwaie3d7a142011-06-20 13:52:33 +02001964 err = via_auto_fill_dac_nids(codec);
1965 if (err < 0)
1966 return err;
1967
Lydia Wang5c9a5612011-07-08 14:03:43 +08001968 if (spec->multiout.num_dacs < 3) {
1969 spec->smart51_nums = 0;
1970 cfg->line_outs = old_line_outs;
1971 }
Takashi Iwai4a796162011-06-17 17:53:38 +02001972 for (i = 0; i < cfg->line_outs; i++) {
1973 hda_nid_t pin, dac;
1974 pin = cfg->line_out_pins[i];
1975 dac = spec->multiout.dac_nids[i];
1976 if (!pin || !dac)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001977 continue;
Takashi Iwai3214b962011-07-18 12:49:25 +02001978 path = spec->out_path + i;
Takashi Iwai0fe0adf2011-06-19 16:27:53 +02001979 if (i == HDA_CLFE) {
Takashi Iwai3214b962011-07-18 12:49:25 +02001980 err = create_ch_ctls(codec, "Center", 1, true, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001981 if (err < 0)
1982 return err;
Takashi Iwai3214b962011-07-18 12:49:25 +02001983 err = create_ch_ctls(codec, "LFE", 2, true, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001984 if (err < 0)
1985 return err;
1986 } else {
Takashi Iwai6aadf412011-06-20 14:09:02 +02001987 const char *pfx = chname[i];
1988 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1989 cfg->line_outs == 1)
1990 pfx = "Speaker";
Takashi Iwai3214b962011-07-18 12:49:25 +02001991 err = create_ch_ctls(codec, pfx, 3, true, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001992 if (err < 0)
1993 return err;
1994 }
Takashi Iwai020066d2011-07-21 13:45:56 +02001995 if (path != spec->out_path + i)
1996 copy_path_mixer_ctls(&spec->out_path[i], path);
1997 if (path == spec->out_path && spec->out_mix_path.depth)
1998 copy_path_mixer_ctls(&spec->out_mix_path, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001999 }
2000
Takashi Iwai4a796162011-06-17 17:53:38 +02002001 idx = get_connection_index(codec, spec->aa_mix_nid,
2002 spec->multiout.dac_nids[0]);
2003 if (idx >= 0) {
2004 /* add control to mixer */
Takashi Iwai3214b962011-07-18 12:49:25 +02002005 const char *name;
2006 name = spec->out_mix_path.depth ?
2007 "PCM Loopback Playback Volume" : "PCM Playback Volume";
2008 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Takashi Iwai4a796162011-06-17 17:53:38 +02002009 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2010 idx, HDA_INPUT));
2011 if (err < 0)
2012 return err;
Takashi Iwai3214b962011-07-18 12:49:25 +02002013 name = spec->out_mix_path.depth ?
2014 "PCM Loopback Playback Switch" : "PCM Playback Switch";
2015 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Takashi Iwai4a796162011-06-17 17:53:38 +02002016 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2017 idx, HDA_INPUT));
2018 if (err < 0)
2019 return err;
2020 }
2021
Takashi Iwaif4a78282011-06-17 18:46:48 +02002022 cfg->line_outs = old_line_outs;
2023
Joseph Chanc577b8a2006-11-29 15:29:40 +01002024 return 0;
2025}
2026
Takashi Iwai4a796162011-06-17 17:53:38 +02002027static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002028{
Takashi Iwai4a796162011-06-17 17:53:38 +02002029 struct via_spec *spec = codec->spec;
Takashi Iwai09a9ad692011-06-21 15:57:44 +02002030 struct nid_path *path;
Takashi Iwai18bd2c42011-07-04 15:55:44 +02002031 bool check_dac;
Takashi Iwai3214b962011-07-18 12:49:25 +02002032 int i, err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002033
2034 if (!pin)
2035 return 0;
2036
Takashi Iwai3214b962011-07-18 12:49:25 +02002037 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
2038 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
2039 if (i < spec->multiout.num_dacs &&
2040 parse_output_path(codec, pin,
2041 spec->multiout.dac_nids[i], 0,
2042 &spec->hp_indep_path)) {
2043 spec->hp_indep_shared = i;
2044 break;
2045 }
2046 }
Takashi Iwai25250502011-06-30 17:24:47 +02002047 }
Takashi Iwai3214b962011-07-18 12:49:25 +02002048 if (spec->hp_indep_path.depth) {
2049 spec->hp_dac_nid = spec->hp_indep_path.path[0];
2050 if (!spec->hp_indep_shared)
2051 spec->hp_path = spec->hp_indep_path;
2052 }
2053 /* optionally check front-path w/o AA-mix */
2054 if (!spec->hp_path.depth)
2055 parse_output_path(codec, pin,
2056 spec->multiout.dac_nids[HDA_FRONT], 0,
2057 &spec->hp_path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002058
Takashi Iwaiece8d042011-06-19 16:24:21 +02002059 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
Takashi Iwai3214b962011-07-18 12:49:25 +02002060 1, &spec->hp_mix_path) && !spec->hp_path.depth)
Takashi Iwaiece8d042011-06-19 16:24:21 +02002061 return 0;
2062
Takashi Iwai3214b962011-07-18 12:49:25 +02002063 if (spec->hp_path.depth) {
Takashi Iwai09a9ad692011-06-21 15:57:44 +02002064 path = &spec->hp_path;
Takashi Iwai18bd2c42011-07-04 15:55:44 +02002065 check_dac = true;
2066 } else {
Takashi Iwai3214b962011-07-18 12:49:25 +02002067 path = &spec->hp_mix_path;
Takashi Iwai18bd2c42011-07-04 15:55:44 +02002068 check_dac = false;
2069 }
2070 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002071 if (err < 0)
2072 return err;
Takashi Iwai020066d2011-07-21 13:45:56 +02002073 if (check_dac)
2074 copy_path_mixer_ctls(&spec->hp_mix_path, path);
2075 else
2076 copy_path_mixer_ctls(&spec->hp_path, path);
2077 if (spec->hp_indep_path.depth)
2078 copy_path_mixer_ctls(&spec->hp_indep_path, path);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002079 return 0;
2080}
2081
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002082static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2083{
2084 struct via_spec *spec = codec->spec;
Takashi Iwai3214b962011-07-18 12:49:25 +02002085 struct nid_path *path;
2086 bool check_dac;
Wang Shaoyan81c0a782011-08-05 18:51:29 +08002087 hda_nid_t pin, dac = 0;
Takashi Iwai3214b962011-07-18 12:49:25 +02002088 int err;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002089
2090 pin = spec->autocfg.speaker_pins[0];
2091 if (!spec->autocfg.speaker_outs || !pin)
2092 return 0;
2093
Takashi Iwai3214b962011-07-18 12:49:25 +02002094 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
Takashi Iwai8e3679d2011-06-21 09:01:36 +02002095 dac = spec->speaker_path.path[0];
Takashi Iwai3214b962011-07-18 12:49:25 +02002096 if (!dac)
2097 parse_output_path(codec, pin,
2098 spec->multiout.dac_nids[HDA_FRONT], 0,
2099 &spec->speaker_path);
2100 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2101 1, &spec->speaker_mix_path) && !dac)
2102 return 0;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002103
Takashi Iwai3214b962011-07-18 12:49:25 +02002104 /* no AA-path for front? */
2105 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2106 dac = 0;
2107
2108 spec->speaker_dac_nid = dac;
2109 spec->multiout.extra_out_nid[0] = dac;
2110 if (dac) {
2111 path = &spec->speaker_path;
2112 check_dac = true;
2113 } else {
2114 path = &spec->speaker_mix_path;
2115 check_dac = false;
2116 }
2117 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2118 if (err < 0)
2119 return err;
Takashi Iwai020066d2011-07-21 13:45:56 +02002120 if (check_dac)
2121 copy_path_mixer_ctls(&spec->speaker_mix_path, path);
2122 else
2123 copy_path_mixer_ctls(&spec->speaker_path, path);
Takashi Iwai3214b962011-07-18 12:49:25 +02002124 return 0;
2125}
2126
2127#define via_aamix_ctl_info via_pin_power_ctl_info
2128
2129static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2130 struct snd_ctl_elem_value *ucontrol)
2131{
2132 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2133 struct via_spec *spec = codec->spec;
2134 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2135 return 0;
2136}
2137
2138static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2139 struct nid_path *nomix, struct nid_path *mix)
2140{
2141 if (do_mix) {
2142 activate_output_path(codec, nomix, false, false);
2143 activate_output_path(codec, mix, true, false);
2144 } else {
2145 activate_output_path(codec, mix, false, false);
2146 activate_output_path(codec, nomix, true, false);
2147 }
2148}
2149
2150static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2151 struct snd_ctl_elem_value *ucontrol)
2152{
2153 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2154 struct via_spec *spec = codec->spec;
2155 unsigned int val = ucontrol->value.enumerated.item[0];
2156
2157 if (val == spec->aamix_mode)
2158 return 0;
2159 spec->aamix_mode = val;
2160 /* update front path */
2161 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2162 /* update HP path */
2163 if (!spec->hp_independent_mode) {
2164 update_aamix_paths(codec, val, &spec->hp_path,
2165 &spec->hp_mix_path);
2166 }
2167 /* update speaker path */
2168 update_aamix_paths(codec, val, &spec->speaker_path,
2169 &spec->speaker_mix_path);
2170 return 1;
2171}
2172
2173static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2174 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2175 .name = "Loopback Mixing",
2176 .info = via_aamix_ctl_info,
2177 .get = via_aamix_ctl_get,
2178 .put = via_aamix_ctl_put,
2179};
2180
2181static int via_auto_create_loopback_switch(struct hda_codec *codec)
2182{
2183 struct via_spec *spec = codec->spec;
2184
2185 if (!spec->aa_mix_nid || !spec->out_mix_path.depth)
2186 return 0; /* no loopback switching available */
2187 if (!via_clone_control(spec, &via_aamix_ctl_enum))
2188 return -ENOMEM;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002189 return 0;
2190}
2191
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002192/* look for ADCs */
2193static int via_fill_adcs(struct hda_codec *codec)
2194{
2195 struct via_spec *spec = codec->spec;
2196 hda_nid_t nid = codec->start_nid;
2197 int i;
2198
2199 for (i = 0; i < codec->num_nodes; i++, nid++) {
2200 unsigned int wcaps = get_wcaps(codec, nid);
2201 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2202 continue;
2203 if (wcaps & AC_WCAP_DIGITAL)
2204 continue;
2205 if (!(wcaps & AC_WCAP_CONN_LIST))
2206 continue;
2207 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2208 return -ENOMEM;
2209 spec->adc_nids[spec->num_adc_nids++] = nid;
2210 }
2211 return 0;
2212}
2213
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002214/* input-src control */
2215static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
2216 struct snd_ctl_elem_info *uinfo)
2217{
2218 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2219 struct via_spec *spec = codec->spec;
2220
2221 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2222 uinfo->count = 1;
2223 uinfo->value.enumerated.items = spec->num_inputs;
2224 if (uinfo->value.enumerated.item >= spec->num_inputs)
2225 uinfo->value.enumerated.item = spec->num_inputs - 1;
2226 strcpy(uinfo->value.enumerated.name,
2227 spec->inputs[uinfo->value.enumerated.item].label);
2228 return 0;
2229}
2230
2231static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2232 struct snd_ctl_elem_value *ucontrol)
2233{
2234 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2235 struct via_spec *spec = codec->spec;
2236 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2237
2238 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2239 return 0;
2240}
2241
2242static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2243 struct snd_ctl_elem_value *ucontrol)
2244{
2245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2246 struct via_spec *spec = codec->spec;
2247 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2248 hda_nid_t mux;
2249 int cur;
2250
2251 cur = ucontrol->value.enumerated.item[0];
2252 if (cur < 0 || cur >= spec->num_inputs)
2253 return -EINVAL;
2254 if (spec->cur_mux[idx] == cur)
2255 return 0;
2256 spec->cur_mux[idx] = cur;
2257 if (spec->dyn_adc_switch) {
2258 int adc_idx = spec->inputs[cur].adc_idx;
2259 mux = spec->mux_nids[adc_idx];
2260 via_dyn_adc_pcm_resetup(codec, cur);
2261 } else {
2262 mux = spec->mux_nids[idx];
2263 if (snd_BUG_ON(!mux))
2264 return -EINVAL;
2265 }
2266
2267 if (mux) {
2268 /* switch to D0 beofre change index */
2269 if (snd_hda_codec_read(codec, mux, 0,
2270 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
2271 snd_hda_codec_write(codec, mux, 0,
2272 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2273 snd_hda_codec_write(codec, mux, 0,
2274 AC_VERB_SET_CONNECT_SEL,
2275 spec->inputs[cur].mux_idx);
2276 }
2277
2278 /* update jack power state */
2279 set_widgets_power_state(codec);
2280 return 0;
2281}
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002282
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002283static const struct snd_kcontrol_new via_input_src_ctl = {
2284 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2285 /* The multiple "Capture Source" controls confuse alsamixer
2286 * So call somewhat different..
2287 */
2288 /* .name = "Capture Source", */
2289 .name = "Input Source",
2290 .info = via_mux_enum_info,
2291 .get = via_mux_enum_get,
2292 .put = via_mux_enum_put,
2293};
2294
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002295static int create_input_src_ctls(struct hda_codec *codec, int count)
2296{
2297 struct via_spec *spec = codec->spec;
2298 struct snd_kcontrol_new *knew;
2299
2300 if (spec->num_inputs <= 1 || !count)
2301 return 0; /* no need for single src */
2302
2303 knew = via_clone_control(spec, &via_input_src_ctl);
2304 if (!knew)
2305 return -ENOMEM;
2306 knew->count = count;
2307 return 0;
2308}
2309
2310/* add the powersave loopback-list entry */
Takashi Iwai13af8e72011-06-20 14:05:46 +02002311static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2312{
2313 struct hda_amp_list *list;
2314
2315 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2316 return;
2317 list = spec->loopback_list + spec->num_loopbacks;
2318 list->nid = mix;
2319 list->dir = HDA_INPUT;
2320 list->idx = idx;
2321 spec->num_loopbacks++;
2322 spec->loopback.amplist = spec->loopback_list;
2323}
Takashi Iwai13af8e72011-06-20 14:05:46 +02002324
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002325static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
Takashi Iwai8d087c72011-06-28 12:45:47 +02002326 hda_nid_t dst)
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002327{
Takashi Iwai8d087c72011-06-28 12:45:47 +02002328 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002329}
2330
2331/* add the input-route to the given pin */
2332static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002333{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002334 struct via_spec *spec = codec->spec;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002335 int c, idx;
2336
2337 spec->inputs[spec->num_inputs].adc_idx = -1;
2338 spec->inputs[spec->num_inputs].pin = pin;
2339 for (c = 0; c < spec->num_adc_nids; c++) {
2340 if (spec->mux_nids[c]) {
2341 idx = get_connection_index(codec, spec->mux_nids[c],
2342 pin);
2343 if (idx < 0)
2344 continue;
2345 spec->inputs[spec->num_inputs].mux_idx = idx;
2346 } else {
Takashi Iwai8d087c72011-06-28 12:45:47 +02002347 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002348 continue;
2349 }
2350 spec->inputs[spec->num_inputs].adc_idx = c;
2351 /* Can primary ADC satisfy all inputs? */
2352 if (!spec->dyn_adc_switch &&
2353 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2354 snd_printd(KERN_INFO
2355 "via: dynamic ADC switching enabled\n");
2356 spec->dyn_adc_switch = 1;
2357 }
2358 return true;
2359 }
2360 return false;
2361}
2362
2363static int get_mux_nids(struct hda_codec *codec);
2364
2365/* parse input-routes; fill ADCs, MUXs and input-src entries */
2366static int parse_analog_inputs(struct hda_codec *codec)
2367{
2368 struct via_spec *spec = codec->spec;
2369 const struct auto_pin_cfg *cfg = &spec->autocfg;
2370 int i, err;
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002371
2372 err = via_fill_adcs(codec);
2373 if (err < 0)
2374 return err;
2375 err = get_mux_nids(codec);
2376 if (err < 0)
2377 return err;
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002378
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002379 /* fill all input-routes */
2380 for (i = 0; i < cfg->num_inputs; i++) {
2381 if (add_input_route(codec, cfg->inputs[i].pin))
2382 spec->inputs[spec->num_inputs++].label =
2383 hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwaif3268512010-08-30 11:00:19 +02002384 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002385
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002386 /* check for internal loopback recording */
2387 if (spec->aa_mix_nid &&
2388 add_input_route(codec, spec->aa_mix_nid))
2389 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2390
2391 return 0;
2392}
2393
2394/* create analog-loopback volume/switch controls */
2395static int create_loopback_ctls(struct hda_codec *codec)
2396{
2397 struct via_spec *spec = codec->spec;
2398 const struct auto_pin_cfg *cfg = &spec->autocfg;
2399 const char *prev_label = NULL;
2400 int type_idx = 0;
2401 int i, j, err, idx;
2402
2403 if (!spec->aa_mix_nid)
2404 return 0;
2405
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002406 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002407 hda_nid_t pin = cfg->inputs[i].pin;
2408 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2409
Takashi Iwai1e11cae2011-06-21 12:57:22 +02002410 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002411 type_idx++;
2412 else
2413 type_idx = 0;
Takashi Iwai1e11cae2011-06-21 12:57:22 +02002414 prev_label = label;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002415 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2416 if (idx >= 0) {
Lydia Wang16922282011-03-22 16:24:10 +08002417 err = via_new_analog_input(spec, label, type_idx,
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002418 idx, spec->aa_mix_nid);
Takashi Iwai13af8e72011-06-20 14:05:46 +02002419 if (err < 0)
2420 return err;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002421 add_loopback_list(spec, spec->aa_mix_nid, idx);
Takashi Iwai13af8e72011-06-20 14:05:46 +02002422 }
Takashi Iwaie3d7a142011-06-20 13:52:33 +02002423
2424 /* remember the label for smart51 control */
2425 for (j = 0; j < spec->smart51_nums; j++) {
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002426 if (spec->smart51_pins[j] == pin) {
Takashi Iwaie3d7a142011-06-20 13:52:33 +02002427 spec->smart51_idxs[j] = idx;
2428 spec->smart51_labels[j] = label;
2429 break;
2430 }
2431 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002432 }
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002433 return 0;
2434}
2435
2436/* create mic-boost controls (if present) */
2437static int create_mic_boost_ctls(struct hda_codec *codec)
2438{
2439 struct via_spec *spec = codec->spec;
2440 const struct auto_pin_cfg *cfg = &spec->autocfg;
2441 int i, err;
2442
2443 for (i = 0; i < cfg->num_inputs; i++) {
2444 hda_nid_t pin = cfg->inputs[i].pin;
2445 unsigned int caps;
2446 const char *label;
2447 char name[32];
2448
2449 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2450 continue;
2451 caps = query_amp_caps(codec, pin, HDA_INPUT);
2452 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2453 continue;
2454 label = hda_get_autocfg_input_label(codec, cfg, i);
2455 snprintf(name, sizeof(name), "%s Boost Volume", label);
2456 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2457 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2458 if (err < 0)
2459 return err;
2460 }
2461 return 0;
2462}
2463
2464/* create capture and input-src controls for multiple streams */
2465static int create_multi_adc_ctls(struct hda_codec *codec)
2466{
2467 struct via_spec *spec = codec->spec;
2468 int i, err;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002469
2470 /* create capture mixer elements */
2471 for (i = 0; i < spec->num_adc_nids; i++) {
2472 hda_nid_t adc = spec->adc_nids[i];
2473 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2474 "Capture Volume", i,
2475 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2476 HDA_INPUT));
2477 if (err < 0)
2478 return err;
2479 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2480 "Capture Switch", i,
2481 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2482 HDA_INPUT));
2483 if (err < 0)
2484 return err;
2485 }
2486
2487 /* input-source control */
2488 for (i = 0; i < spec->num_adc_nids; i++)
2489 if (!spec->mux_nids[i])
2490 break;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002491 err = create_input_src_ctls(codec, i);
2492 if (err < 0)
2493 return err;
2494 return 0;
2495}
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002496
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002497/* bind capture volume/switch */
2498static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2499 HDA_BIND_VOL("Capture Volume", 0);
2500static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2501 HDA_BIND_SW("Capture Switch", 0);
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002502
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002503static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2504 struct hda_ctl_ops *ops)
2505{
2506 struct hda_bind_ctls *ctl;
2507 int i;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02002508
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002509 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2510 if (!ctl)
2511 return -ENOMEM;
2512 ctl->ops = ops;
2513 for (i = 0; i < spec->num_adc_nids; i++)
2514 ctl->values[i] =
2515 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2516 *ctl_ret = ctl;
2517 return 0;
2518}
2519
2520/* create capture and input-src controls for dynamic ADC-switch case */
2521static int create_dyn_adc_ctls(struct hda_codec *codec)
2522{
2523 struct via_spec *spec = codec->spec;
2524 struct snd_kcontrol_new *knew;
2525 int err;
2526
2527 /* set up the bind capture ctls */
2528 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2529 if (err < 0)
2530 return err;
2531 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2532 if (err < 0)
2533 return err;
2534
2535 /* create capture mixer elements */
2536 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2537 if (!knew)
2538 return -ENOMEM;
2539 knew->private_value = (long)spec->bind_cap_vol;
2540
2541 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2542 if (!knew)
2543 return -ENOMEM;
2544 knew->private_value = (long)spec->bind_cap_sw;
2545
2546 /* input-source control */
2547 err = create_input_src_ctls(codec, 1);
2548 if (err < 0)
2549 return err;
2550 return 0;
2551}
2552
2553/* parse and create capture-related stuff */
2554static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2555{
2556 struct via_spec *spec = codec->spec;
2557 int err;
2558
2559 err = parse_analog_inputs(codec);
2560 if (err < 0)
2561 return err;
2562 if (spec->dyn_adc_switch)
2563 err = create_dyn_adc_ctls(codec);
2564 else
2565 err = create_multi_adc_ctls(codec);
2566 if (err < 0)
2567 return err;
2568 err = create_loopback_ctls(codec);
2569 if (err < 0)
2570 return err;
2571 err = create_mic_boost_ctls(codec);
2572 if (err < 0)
2573 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002574 return 0;
2575}
2576
Harald Welte76d9b0d2008-09-09 15:50:37 +08002577static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2578{
2579 unsigned int def_conf;
2580 unsigned char seqassoc;
2581
Takashi Iwai2f334f92009-02-20 14:37:42 +01002582 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002583 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2584 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002585 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2586 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2587 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2588 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002589 }
2590
2591 return;
2592}
2593
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002594static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002595 struct snd_ctl_elem_value *ucontrol)
2596{
2597 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2598 struct via_spec *spec = codec->spec;
2599
2600 if (spec->codec_type != VT1708)
2601 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002602 spec->vt1708_jack_detect =
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002603 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002604 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002605 return 0;
2606}
2607
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002608static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002609 struct snd_ctl_elem_value *ucontrol)
2610{
2611 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2612 struct via_spec *spec = codec->spec;
2613 int change;
2614
2615 if (spec->codec_type != VT1708)
2616 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002617 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002618 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002619 == !spec->vt1708_jack_detect;
2620 if (spec->vt1708_jack_detect) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002621 mute_aa_path(codec, 1);
2622 notify_aa_path_ctls(codec);
2623 }
2624 return change;
2625}
2626
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002627static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2628 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2629 .name = "Jack Detect",
2630 .count = 1,
2631 .info = snd_ctl_boolean_mono_info,
2632 .get = vt1708_jack_detect_get,
2633 .put = vt1708_jack_detect_put,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002634};
2635
Takashi Iwai12daef62011-06-18 17:45:49 +02002636static void fill_dig_outs(struct hda_codec *codec);
2637static void fill_dig_in(struct hda_codec *codec);
2638
2639static int via_parse_auto_config(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002640{
2641 struct via_spec *spec = codec->spec;
2642 int err;
2643
2644 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2645 if (err < 0)
2646 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002647 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
Takashi Iwai7f0df882011-06-18 17:33:34 +02002648 return -EINVAL;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002649
Takashi Iwai4a796162011-06-17 17:53:38 +02002650 err = via_auto_create_multi_out_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002651 if (err < 0)
2652 return err;
Takashi Iwai4a796162011-06-17 17:53:38 +02002653 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002654 if (err < 0)
2655 return err;
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002656 err = via_auto_create_speaker_ctls(codec);
2657 if (err < 0)
2658 return err;
Takashi Iwai3214b962011-07-18 12:49:25 +02002659 err = via_auto_create_loopback_switch(codec);
2660 if (err < 0)
2661 return err;
Takashi Iwaia86a88e2011-06-22 15:23:25 +02002662 err = via_auto_create_analog_input_ctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002663 if (err < 0)
2664 return err;
2665
2666 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2667
Takashi Iwai12daef62011-06-18 17:45:49 +02002668 fill_dig_outs(codec);
2669 fill_dig_in(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002670
Takashi Iwai603c4012008-07-30 15:01:44 +02002671 if (spec->kctls.list)
2672 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002673
Joseph Chanc577b8a2006-11-29 15:29:40 +01002674
Takashi Iwai3214b962011-07-18 12:49:25 +02002675 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
Takashi Iwaiece8d042011-06-19 16:24:21 +02002676 err = via_hp_build(codec);
2677 if (err < 0)
2678 return err;
2679 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002680
Takashi Iwaif4a78282011-06-17 18:46:48 +02002681 err = via_smart51_build(codec);
2682 if (err < 0)
2683 return err;
2684
Takashi Iwai5d417622011-06-20 11:32:27 +02002685 /* assign slave outs */
2686 if (spec->slave_dig_outs[0])
2687 codec->slave_dig_outs = spec->slave_dig_outs;
2688
Joseph Chanc577b8a2006-11-29 15:29:40 +01002689 return 1;
2690}
2691
Takashi Iwai5d417622011-06-20 11:32:27 +02002692static void via_auto_init_dig_outs(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002693{
Lydia Wang25eaba22009-10-10 19:08:43 +08002694 struct via_spec *spec = codec->spec;
Takashi Iwai5d417622011-06-20 11:32:27 +02002695 if (spec->multiout.dig_out_nid)
2696 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2697 if (spec->slave_dig_outs[0])
2698 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2699}
Lydia Wang25eaba22009-10-10 19:08:43 +08002700
Takashi Iwai5d417622011-06-20 11:32:27 +02002701static void via_auto_init_dig_in(struct hda_codec *codec)
2702{
2703 struct via_spec *spec = codec->spec;
2704 if (!spec->dig_in_nid)
2705 return;
2706 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2707 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2708}
2709
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002710/* initialize the unsolicited events */
2711static void via_auto_init_unsol_event(struct hda_codec *codec)
2712{
2713 struct via_spec *spec = codec->spec;
2714 struct auto_pin_cfg *cfg = &spec->autocfg;
2715 unsigned int ev;
2716 int i;
2717
2718 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2719 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2720 AC_VERB_SET_UNSOLICITED_ENABLE,
2721 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2722
2723 if (cfg->speaker_pins[0])
2724 ev = VIA_LINE_EVENT;
2725 else
2726 ev = 0;
2727 for (i = 0; i < cfg->line_outs; i++) {
2728 if (cfg->line_out_pins[i] &&
2729 is_jack_detectable(codec, cfg->line_out_pins[i]))
Lydia Wang63f10d22011-06-28 17:29:10 +08002730 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002731 AC_VERB_SET_UNSOLICITED_ENABLE,
2732 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2733 }
2734
2735 for (i = 0; i < cfg->num_inputs; i++) {
2736 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2737 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2738 AC_VERB_SET_UNSOLICITED_ENABLE,
2739 AC_USRSP_EN | VIA_JACK_EVENT);
2740 }
2741}
2742
Takashi Iwai5d417622011-06-20 11:32:27 +02002743static int via_init(struct hda_codec *codec)
2744{
2745 struct via_spec *spec = codec->spec;
2746 int i;
2747
2748 for (i = 0; i < spec->num_iverbs; i++)
2749 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2750
Joseph Chanc577b8a2006-11-29 15:29:40 +01002751 via_auto_init_multi_out(codec);
2752 via_auto_init_hp_out(codec);
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002753 via_auto_init_speaker_out(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002754 via_auto_init_analog_input(codec);
Takashi Iwai5d417622011-06-20 11:32:27 +02002755 via_auto_init_dig_outs(codec);
2756 via_auto_init_dig_in(codec);
Lydia Wang118909562011-03-23 17:57:34 +08002757
Takashi Iwai4a918ff2011-06-20 12:39:26 +02002758 via_auto_init_unsol_event(codec);
2759
2760 via_hp_automute(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08002761
Joseph Chanc577b8a2006-11-29 15:29:40 +01002762 return 0;
2763}
2764
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002765static void vt1708_update_hp_jack_state(struct work_struct *work)
2766{
2767 struct via_spec *spec = container_of(work, struct via_spec,
2768 vt1708_hp_work.work);
2769 if (spec->codec_type != VT1708)
2770 return;
2771 /* if jack state toggled */
2772 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002773 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002774 spec->vt1708_hp_present ^= 1;
2775 via_hp_automute(spec->codec);
2776 }
2777 vt1708_start_hp_work(spec);
2778}
2779
Takashi Iwai337b9d02009-07-07 18:18:59 +02002780static int get_mux_nids(struct hda_codec *codec)
2781{
2782 struct via_spec *spec = codec->spec;
2783 hda_nid_t nid, conn[8];
2784 unsigned int type;
2785 int i, n;
2786
2787 for (i = 0; i < spec->num_adc_nids; i++) {
2788 nid = spec->adc_nids[i];
2789 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002790 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002791 if (type == AC_WID_PIN)
2792 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002793 n = snd_hda_get_connections(codec, nid, conn,
2794 ARRAY_SIZE(conn));
2795 if (n <= 0)
2796 break;
2797 if (n > 1) {
2798 spec->mux_nids[i] = nid;
2799 break;
2800 }
2801 nid = conn[0];
2802 }
2803 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002804 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002805}
2806
Joseph Chanc577b8a2006-11-29 15:29:40 +01002807static int patch_vt1708(struct hda_codec *codec)
2808{
2809 struct via_spec *spec;
2810 int err;
2811
2812 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002813 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002814 if (spec == NULL)
2815 return -ENOMEM;
2816
Takashi Iwai620e2b22011-06-17 17:19:19 +02002817 spec->aa_mix_nid = 0x17;
2818
Takashi Iwai12daef62011-06-18 17:45:49 +02002819 /* Add HP and CD pin config connect bit re-config action */
2820 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2821 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2822
Joseph Chanc577b8a2006-11-29 15:29:40 +01002823 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002824 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002825 if (err < 0) {
2826 via_free(codec);
2827 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002828 }
2829
Takashi Iwai12daef62011-06-18 17:45:49 +02002830 /* add jack detect on/off control */
2831 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2832 return -ENOMEM;
2833
Takashi Iwaibc9b5622008-05-23 17:50:27 +02002834 /* disable 32bit format on VT1708 */
2835 if (codec->vendor_id == 0x11061708)
2836 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002837
Lydia Wange322a362011-06-29 13:52:02 +08002838 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2839
Joseph Chanc577b8a2006-11-29 15:29:40 +01002840 codec->patch_ops = via_patch_ops;
2841
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002842 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002843 return 0;
2844}
2845
Takashi Iwaiddd304d2011-06-21 16:33:55 +02002846static int patch_vt1709(struct hda_codec *codec)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002847{
2848 struct via_spec *spec;
2849 int err;
2850
2851 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002852 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002853 if (spec == NULL)
2854 return -ENOMEM;
2855
Takashi Iwai620e2b22011-06-17 17:19:19 +02002856 spec->aa_mix_nid = 0x18;
2857
Takashi Iwai12daef62011-06-18 17:45:49 +02002858 err = via_parse_auto_config(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002859 if (err < 0) {
2860 via_free(codec);
2861 return err;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002862 }
2863
Joseph Chanc577b8a2006-11-29 15:29:40 +01002864 codec->patch_ops = via_patch_ops;
2865
Josepch Chanf7278fd2007-12-13 16:40:40 +01002866 return 0;
2867}
2868
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002869static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2870{
2871 struct via_spec *spec = codec->spec;
2872 int imux_is_smixer;
2873 unsigned int parm;
2874 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +08002875 if ((spec->codec_type != VT1708B_4CH) &&
2876 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002877 is_8ch = 1;
2878
2879 /* SW0 (17h) = stereo mixer */
2880 imux_is_smixer =
2881 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2882 == ((spec->codec_type == VT1708S) ? 5 : 0));
2883 /* inputs */
2884 /* PW 1/2/5 (1ah/1bh/1eh) */
2885 parm = AC_PWRST_D3;
2886 set_pin_power_state(codec, 0x1a, &parm);
2887 set_pin_power_state(codec, 0x1b, &parm);
2888 set_pin_power_state(codec, 0x1e, &parm);
2889 if (imux_is_smixer)
2890 parm = AC_PWRST_D0;
2891 /* SW0 (17h), AIW 0/1 (13h/14h) */
2892 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2893 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2894 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2895
2896 /* outputs */
2897 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2898 parm = AC_PWRST_D3;
2899 set_pin_power_state(codec, 0x19, &parm);
2900 if (spec->smart51_enabled)
2901 set_pin_power_state(codec, 0x1b, &parm);
2902 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2903 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2904
2905 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2906 if (is_8ch) {
2907 parm = AC_PWRST_D3;
2908 set_pin_power_state(codec, 0x22, &parm);
2909 if (spec->smart51_enabled)
2910 set_pin_power_state(codec, 0x1a, &parm);
2911 snd_hda_codec_write(codec, 0x26, 0,
2912 AC_VERB_SET_POWER_STATE, parm);
2913 snd_hda_codec_write(codec, 0x24, 0,
2914 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002915 } else if (codec->vendor_id == 0x11064397) {
2916 /* PW7(23h), SW2(27h), AOW2(25h) */
2917 parm = AC_PWRST_D3;
2918 set_pin_power_state(codec, 0x23, &parm);
2919 if (spec->smart51_enabled)
2920 set_pin_power_state(codec, 0x1a, &parm);
2921 snd_hda_codec_write(codec, 0x27, 0,
2922 AC_VERB_SET_POWER_STATE, parm);
2923 snd_hda_codec_write(codec, 0x25, 0,
2924 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002925 }
2926
2927 /* PW 3/4/7 (1ch/1dh/23h) */
2928 parm = AC_PWRST_D3;
2929 /* force to D0 for internal Speaker */
2930 set_pin_power_state(codec, 0x1c, &parm);
2931 set_pin_power_state(codec, 0x1d, &parm);
2932 if (is_8ch)
2933 set_pin_power_state(codec, 0x23, &parm);
2934
2935 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2936 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2937 imux_is_smixer ? AC_PWRST_D0 : parm);
2938 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2939 if (is_8ch) {
2940 snd_hda_codec_write(codec, 0x25, 0,
2941 AC_VERB_SET_POWER_STATE, parm);
2942 snd_hda_codec_write(codec, 0x27, 0,
2943 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08002944 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2945 snd_hda_codec_write(codec, 0x25, 0,
2946 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002947}
2948
Lydia Wang518bf3b2009-10-10 19:07:29 +08002949static int patch_vt1708S(struct hda_codec *codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +02002950static int patch_vt1708B(struct hda_codec *codec)
Josepch Chanf7278fd2007-12-13 16:40:40 +01002951{
2952 struct via_spec *spec;
2953 int err;
2954
Lydia Wang518bf3b2009-10-10 19:07:29 +08002955 if (get_codec_type(codec) == VT1708BCE)
2956 return patch_vt1708S(codec);
Takashi Iwaiddd304d2011-06-21 16:33:55 +02002957
Josepch Chanf7278fd2007-12-13 16:40:40 +01002958 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002959 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002960 if (spec == NULL)
2961 return -ENOMEM;
2962
Takashi Iwai620e2b22011-06-17 17:19:19 +02002963 spec->aa_mix_nid = 0x16;
2964
Josepch Chanf7278fd2007-12-13 16:40:40 +01002965 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02002966 err = via_parse_auto_config(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002967 if (err < 0) {
2968 via_free(codec);
2969 return err;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002970 }
2971
Josepch Chanf7278fd2007-12-13 16:40:40 +01002972 codec->patch_ops = via_patch_ops;
2973
Lydia Wang3e95b9a2011-03-23 15:13:28 +08002974 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2975
Josepch Chanf7278fd2007-12-13 16:40:40 +01002976 return 0;
2977}
2978
Harald Welted949cac2008-09-09 15:56:01 +08002979/* Patch for VT1708S */
Takashi Iwai096a8852011-06-20 12:09:02 +02002980static const struct hda_verb vt1708S_init_verbs[] = {
Harald Welted7426322008-09-15 22:43:23 +08002981 /* Enable Mic Boost Volume backdoor */
2982 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08002983 /* don't bybass mixer */
2984 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08002985 { }
2986};
2987
Takashi Iwai9da29272009-05-07 16:31:14 +02002988/* fill out digital output widgets; one for master and one for slave outputs */
2989static void fill_dig_outs(struct hda_codec *codec)
2990{
2991 struct via_spec *spec = codec->spec;
2992 int i;
2993
2994 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2995 hda_nid_t nid;
2996 int conn;
2997
2998 nid = spec->autocfg.dig_out_pins[i];
2999 if (!nid)
3000 continue;
3001 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3002 if (conn < 1)
3003 continue;
3004 if (!spec->multiout.dig_out_nid)
3005 spec->multiout.dig_out_nid = nid;
3006 else {
3007 spec->slave_dig_outs[0] = nid;
3008 break; /* at most two dig outs */
3009 }
3010 }
3011}
3012
Takashi Iwai12daef62011-06-18 17:45:49 +02003013static void fill_dig_in(struct hda_codec *codec)
Harald Welted949cac2008-09-09 15:56:01 +08003014{
3015 struct via_spec *spec = codec->spec;
Takashi Iwai12daef62011-06-18 17:45:49 +02003016 hda_nid_t dig_nid;
3017 int i, err;
Harald Welted949cac2008-09-09 15:56:01 +08003018
Takashi Iwai12daef62011-06-18 17:45:49 +02003019 if (!spec->autocfg.dig_in_pin)
3020 return;
Harald Welted949cac2008-09-09 15:56:01 +08003021
Takashi Iwai12daef62011-06-18 17:45:49 +02003022 dig_nid = codec->start_nid;
3023 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3024 unsigned int wcaps = get_wcaps(codec, dig_nid);
3025 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3026 continue;
3027 if (!(wcaps & AC_WCAP_DIGITAL))
3028 continue;
3029 if (!(wcaps & AC_WCAP_CONN_LIST))
3030 continue;
3031 err = get_connection_index(codec, dig_nid,
3032 spec->autocfg.dig_in_pin);
3033 if (err >= 0) {
3034 spec->dig_in_nid = dig_nid;
3035 break;
3036 }
3037 }
Harald Welted949cac2008-09-09 15:56:01 +08003038}
3039
Lydia Wang6369bcf2009-10-10 19:08:31 +08003040static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3041 int offset, int num_steps, int step_size)
3042{
3043 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3044 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3045 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3046 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3047 (0 << AC_AMPCAP_MUTE_SHIFT));
3048}
3049
Harald Welted949cac2008-09-09 15:56:01 +08003050static int patch_vt1708S(struct hda_codec *codec)
3051{
3052 struct via_spec *spec;
3053 int err;
3054
3055 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003056 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003057 if (spec == NULL)
3058 return -ENOMEM;
3059
Takashi Iwai620e2b22011-06-17 17:19:19 +02003060 spec->aa_mix_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003061 override_mic_boost(codec, 0x1a, 0, 3, 40);
3062 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003063
Harald Welted949cac2008-09-09 15:56:01 +08003064 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003065 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003066 if (err < 0) {
3067 via_free(codec);
3068 return err;
Harald Welted949cac2008-09-09 15:56:01 +08003069 }
3070
Takashi Iwai096a8852011-06-20 12:09:02 +02003071 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003072
Harald Welted949cac2008-09-09 15:56:01 +08003073 codec->patch_ops = via_patch_ops;
3074
Lydia Wang518bf3b2009-10-10 19:07:29 +08003075 /* correct names for VT1708BCE */
3076 if (get_codec_type(codec) == VT1708BCE) {
3077 kfree(codec->chip_name);
3078 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3079 snprintf(codec->bus->card->mixername,
3080 sizeof(codec->bus->card->mixername),
3081 "%s %s", codec->vendor_name, codec->chip_name);
Lydia Wang970f6302011-03-22 16:25:56 +08003082 }
Lydia Wangbc92df72011-03-23 17:56:05 +08003083 /* correct names for VT1705 */
3084 if (codec->vendor_id == 0x11064397) {
3085 kfree(codec->chip_name);
3086 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3087 snprintf(codec->bus->card->mixername,
3088 sizeof(codec->bus->card->mixername),
3089 "%s %s", codec->vendor_name, codec->chip_name);
3090 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003091 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +08003092 return 0;
3093}
3094
3095/* Patch for VT1702 */
3096
Takashi Iwai096a8852011-06-20 12:09:02 +02003097static const struct hda_verb vt1702_init_verbs[] = {
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003098 /* mixer enable */
3099 {0x1, 0xF88, 0x3},
3100 /* GPIO 0~2 */
3101 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08003102 { }
3103};
3104
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003105static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3106{
3107 int imux_is_smixer =
3108 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3109 unsigned int parm;
3110 /* inputs */
3111 /* PW 1/2/5 (14h/15h/18h) */
3112 parm = AC_PWRST_D3;
3113 set_pin_power_state(codec, 0x14, &parm);
3114 set_pin_power_state(codec, 0x15, &parm);
3115 set_pin_power_state(codec, 0x18, &parm);
3116 if (imux_is_smixer)
3117 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3118 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3119 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3120 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
3121 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3122 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
3123
3124 /* outputs */
3125 /* PW 3/4 (16h/17h) */
3126 parm = AC_PWRST_D3;
3127 set_pin_power_state(codec, 0x17, &parm);
3128 set_pin_power_state(codec, 0x16, &parm);
3129 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3130 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
3131 imux_is_smixer ? AC_PWRST_D0 : parm);
3132 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3133 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3134}
3135
Harald Welted949cac2008-09-09 15:56:01 +08003136static int patch_vt1702(struct hda_codec *codec)
3137{
3138 struct via_spec *spec;
3139 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003140
3141 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003142 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003143 if (spec == NULL)
3144 return -ENOMEM;
3145
Takashi Iwai620e2b22011-06-17 17:19:19 +02003146 spec->aa_mix_nid = 0x1a;
3147
Takashi Iwai12daef62011-06-18 17:45:49 +02003148 /* limit AA path volume to 0 dB */
3149 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3150 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3151 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3152 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3153 (1 << AC_AMPCAP_MUTE_SHIFT));
3154
Harald Welted949cac2008-09-09 15:56:01 +08003155 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003156 err = via_parse_auto_config(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003157 if (err < 0) {
3158 via_free(codec);
3159 return err;
Harald Welted949cac2008-09-09 15:56:01 +08003160 }
3161
Takashi Iwai096a8852011-06-20 12:09:02 +02003162 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003163
Harald Welted949cac2008-09-09 15:56:01 +08003164 codec->patch_ops = via_patch_ops;
3165
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003166 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08003167 return 0;
3168}
3169
Lydia Wangeb7188c2009-10-10 19:08:34 +08003170/* Patch for VT1718S */
3171
Takashi Iwai096a8852011-06-20 12:09:02 +02003172static const struct hda_verb vt1718S_init_verbs[] = {
Lydia Wang4ab2d532011-03-24 12:42:03 +08003173 /* Enable MW0 adjust Gain 5 */
3174 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08003175 /* Enable Boost Volume backdoor */
3176 {0x1, 0xf88, 0x8},
Takashi Iwai5d417622011-06-20 11:32:27 +02003177
Lydia Wangeb7188c2009-10-10 19:08:34 +08003178 { }
3179};
3180
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003181static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3182{
3183 struct via_spec *spec = codec->spec;
3184 int imux_is_smixer;
3185 unsigned int parm;
3186 /* MUX6 (1eh) = stereo mixer */
3187 imux_is_smixer =
3188 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3189 /* inputs */
3190 /* PW 5/6/7 (29h/2ah/2bh) */
3191 parm = AC_PWRST_D3;
3192 set_pin_power_state(codec, 0x29, &parm);
3193 set_pin_power_state(codec, 0x2a, &parm);
3194 set_pin_power_state(codec, 0x2b, &parm);
3195 if (imux_is_smixer)
3196 parm = AC_PWRST_D0;
3197 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3198 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3199 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3200 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3201 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3202
3203 /* outputs */
3204 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3205 parm = AC_PWRST_D3;
3206 set_pin_power_state(codec, 0x27, &parm);
3207 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
3208 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
3209
3210 /* PW2 (26h), AOW2 (ah) */
3211 parm = AC_PWRST_D3;
3212 set_pin_power_state(codec, 0x26, &parm);
3213 if (spec->smart51_enabled)
3214 set_pin_power_state(codec, 0x2b, &parm);
3215 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
3216
3217 /* PW0 (24h), AOW0 (8h) */
3218 parm = AC_PWRST_D3;
3219 set_pin_power_state(codec, 0x24, &parm);
3220 if (!spec->hp_independent_mode) /* check for redirected HP */
3221 set_pin_power_state(codec, 0x28, &parm);
3222 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3223 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3224 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
3225 imux_is_smixer ? AC_PWRST_D0 : parm);
3226
3227 /* PW1 (25h), AOW1 (9h) */
3228 parm = AC_PWRST_D3;
3229 set_pin_power_state(codec, 0x25, &parm);
3230 if (spec->smart51_enabled)
3231 set_pin_power_state(codec, 0x2a, &parm);
3232 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
3233
3234 if (spec->hp_independent_mode) {
3235 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3236 parm = AC_PWRST_D3;
3237 set_pin_power_state(codec, 0x28, &parm);
3238 snd_hda_codec_write(codec, 0x1b, 0,
3239 AC_VERB_SET_POWER_STATE, parm);
3240 snd_hda_codec_write(codec, 0x34, 0,
3241 AC_VERB_SET_POWER_STATE, parm);
3242 snd_hda_codec_write(codec, 0xc, 0,
3243 AC_VERB_SET_POWER_STATE, parm);
3244 }
3245}
3246
Takashi Iwai30b45032011-07-11 17:05:04 +02003247/* Add a connection to the primary DAC from AA-mixer for some codecs
3248 * This isn't listed from the raw info, but the chip has a secret connection.
3249 */
3250static int add_secret_dac_path(struct hda_codec *codec)
3251{
3252 struct via_spec *spec = codec->spec;
3253 int i, nums;
3254 hda_nid_t conn[8];
3255 hda_nid_t nid;
3256
3257 if (!spec->aa_mix_nid)
3258 return 0;
3259 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
3260 ARRAY_SIZE(conn) - 1);
3261 for (i = 0; i < nums; i++) {
3262 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
3263 return 0;
3264 }
3265
3266 /* find the primary DAC and add to the connection list */
3267 nid = codec->start_nid;
3268 for (i = 0; i < codec->num_nodes; i++, nid++) {
3269 unsigned int caps = get_wcaps(codec, nid);
3270 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
3271 !(caps & AC_WCAP_DIGITAL)) {
3272 conn[nums++] = nid;
3273 return snd_hda_override_conn_list(codec,
3274 spec->aa_mix_nid,
3275 nums, conn);
3276 }
3277 }
3278 return 0;
3279}
3280
3281
Lydia Wangeb7188c2009-10-10 19:08:34 +08003282static int patch_vt1718S(struct hda_codec *codec)
3283{
3284 struct via_spec *spec;
3285 int err;
3286
3287 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003288 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003289 if (spec == NULL)
3290 return -ENOMEM;
3291
Takashi Iwai620e2b22011-06-17 17:19:19 +02003292 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003293 override_mic_boost(codec, 0x2b, 0, 3, 40);
3294 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02003295 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003296
Lydia Wangeb7188c2009-10-10 19:08:34 +08003297 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003298 err = via_parse_auto_config(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08003299 if (err < 0) {
3300 via_free(codec);
3301 return err;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003302 }
3303
Takashi Iwai096a8852011-06-20 12:09:02 +02003304 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
Lydia Wangeb7188c2009-10-10 19:08:34 +08003305
Lydia Wangeb7188c2009-10-10 19:08:34 +08003306 codec->patch_ops = via_patch_ops;
3307
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003308 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3309
Lydia Wangeb7188c2009-10-10 19:08:34 +08003310 return 0;
3311}
Lydia Wangf3db4232009-10-10 19:08:41 +08003312
3313/* Patch for VT1716S */
3314
3315static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3316 struct snd_ctl_elem_info *uinfo)
3317{
3318 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3319 uinfo->count = 1;
3320 uinfo->value.integer.min = 0;
3321 uinfo->value.integer.max = 1;
3322 return 0;
3323}
3324
3325static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3326 struct snd_ctl_elem_value *ucontrol)
3327{
3328 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3329 int index = 0;
3330
3331 index = snd_hda_codec_read(codec, 0x26, 0,
3332 AC_VERB_GET_CONNECT_SEL, 0);
3333 if (index != -1)
3334 *ucontrol->value.integer.value = index;
3335
3336 return 0;
3337}
3338
3339static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3340 struct snd_ctl_elem_value *ucontrol)
3341{
3342 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3343 struct via_spec *spec = codec->spec;
3344 int index = *ucontrol->value.integer.value;
3345
3346 snd_hda_codec_write(codec, 0x26, 0,
3347 AC_VERB_SET_CONNECT_SEL, index);
3348 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003349 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003350 return 1;
3351}
3352
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003353static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003354 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3355 {
3356 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3357 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003358 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08003359 .count = 1,
3360 .info = vt1716s_dmic_info,
3361 .get = vt1716s_dmic_get,
3362 .put = vt1716s_dmic_put,
3363 },
3364 {} /* end */
3365};
3366
3367
3368/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003369static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003370 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3371 { } /* end */
3372};
3373
Takashi Iwai096a8852011-06-20 12:09:02 +02003374static const struct hda_verb vt1716S_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08003375 /* Enable Boost Volume backdoor */
3376 {0x1, 0xf8a, 0x80},
3377 /* don't bybass mixer */
3378 {0x1, 0xf88, 0xc0},
3379 /* Enable mono output */
3380 {0x1, 0xf90, 0x08},
3381 { }
3382};
3383
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003384static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3385{
3386 struct via_spec *spec = codec->spec;
3387 int imux_is_smixer;
3388 unsigned int parm;
3389 unsigned int mono_out, present;
3390 /* SW0 (17h) = stereo mixer */
3391 imux_is_smixer =
3392 (snd_hda_codec_read(codec, 0x17, 0,
3393 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3394 /* inputs */
3395 /* PW 1/2/5 (1ah/1bh/1eh) */
3396 parm = AC_PWRST_D3;
3397 set_pin_power_state(codec, 0x1a, &parm);
3398 set_pin_power_state(codec, 0x1b, &parm);
3399 set_pin_power_state(codec, 0x1e, &parm);
3400 if (imux_is_smixer)
3401 parm = AC_PWRST_D0;
3402 /* SW0 (17h), AIW0(13h) */
3403 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3404 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3405
3406 parm = AC_PWRST_D3;
3407 set_pin_power_state(codec, 0x1e, &parm);
3408 /* PW11 (22h) */
3409 if (spec->dmic_enabled)
3410 set_pin_power_state(codec, 0x22, &parm);
3411 else
3412 snd_hda_codec_write(codec, 0x22, 0,
3413 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3414
3415 /* SW2(26h), AIW1(14h) */
3416 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3417 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3418
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);
3426 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3427 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3428
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);
3435 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3436
3437 /* Smart 5.1 PW5(1eh) */
3438 if (spec->smart51_enabled)
3439 set_pin_power_state(codec, 0x1e, &parm);
3440 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3441
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;
3456 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3457 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3458 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3459
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)
3466 snd_hda_codec_write(codec, 0x25, 0,
3467 AC_VERB_SET_POWER_STATE, parm);
3468
3469 /* force to D0 for internal Speaker */
3470 /* MW0 (16h), AOW0 (10h) */
3471 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3472 imux_is_smixer ? AC_PWRST_D0 : parm);
3473 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3474 mono_out ? AC_PWRST_D0 : parm);
3475}
3476
Lydia Wangf3db4232009-10-10 19:08:41 +08003477static int patch_vt1716S(struct hda_codec *codec)
3478{
3479 struct via_spec *spec;
3480 int err;
3481
3482 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003483 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003484 if (spec == NULL)
3485 return -ENOMEM;
3486
Takashi Iwai620e2b22011-06-17 17:19:19 +02003487 spec->aa_mix_nid = 0x16;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003488 override_mic_boost(codec, 0x1a, 0, 3, 40);
3489 override_mic_boost(codec, 0x1e, 0, 3, 40);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003490
Lydia Wangf3db4232009-10-10 19:08:41 +08003491 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003492 err = via_parse_auto_config(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08003493 if (err < 0) {
3494 via_free(codec);
3495 return err;
Lydia Wangf3db4232009-10-10 19:08:41 +08003496 }
3497
Takashi Iwai096a8852011-06-20 12:09:02 +02003498 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
Lydia Wangf3db4232009-10-10 19:08:41 +08003499
Lydia Wangf3db4232009-10-10 19:08:41 +08003500 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3501 spec->num_mixers++;
3502
3503 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3504
3505 codec->patch_ops = via_patch_ops;
3506
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003507 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08003508 return 0;
3509}
Lydia Wang25eaba22009-10-10 19:08:43 +08003510
3511/* for vt2002P */
3512
Takashi Iwai096a8852011-06-20 12:09:02 +02003513static const struct hda_verb vt2002P_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08003514 /* Class-D speaker related verbs */
3515 {0x1, 0xfe0, 0x4},
3516 {0x1, 0xfe9, 0x80},
3517 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08003518 /* Enable Boost Volume backdoor */
3519 {0x1, 0xfb9, 0x24},
Lydia Wang25eaba22009-10-10 19:08:43 +08003520 /* Enable AOW0 to MW9 */
3521 {0x1, 0xfb8, 0x88},
3522 { }
3523};
Takashi Iwai4a918ff2011-06-20 12:39:26 +02003524
Takashi Iwai096a8852011-06-20 12:09:02 +02003525static const struct hda_verb vt1802_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08003526 /* Enable Boost Volume backdoor */
3527 {0x1, 0xfb9, 0x24},
Lydia Wang118909562011-03-23 17:57:34 +08003528 /* Enable AOW0 to MW9 */
3529 {0x1, 0xfb8, 0x88},
3530 { }
3531};
Lydia Wang25eaba22009-10-10 19:08:43 +08003532
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003533static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3534{
3535 struct via_spec *spec = codec->spec;
3536 int imux_is_smixer;
3537 unsigned int parm;
3538 unsigned int present;
3539 /* MUX9 (1eh) = stereo mixer */
3540 imux_is_smixer =
3541 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3542 /* inputs */
3543 /* PW 5/6/7 (29h/2ah/2bh) */
3544 parm = AC_PWRST_D3;
3545 set_pin_power_state(codec, 0x29, &parm);
3546 set_pin_power_state(codec, 0x2a, &parm);
3547 set_pin_power_state(codec, 0x2b, &parm);
3548 parm = AC_PWRST_D0;
3549 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3550 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3551 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3552 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3553 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3554
3555 /* outputs */
3556 /* AOW0 (8h)*/
3557 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3558
Lydia Wang118909562011-03-23 17:57:34 +08003559 if (spec->codec_type == VT1802) {
3560 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3561 parm = AC_PWRST_D3;
3562 set_pin_power_state(codec, 0x28, &parm);
3563 snd_hda_codec_write(codec, 0x18, 0,
3564 AC_VERB_SET_POWER_STATE, parm);
3565 snd_hda_codec_write(codec, 0x38, 0,
3566 AC_VERB_SET_POWER_STATE, parm);
3567 } else {
3568 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3569 parm = AC_PWRST_D3;
3570 set_pin_power_state(codec, 0x26, &parm);
3571 snd_hda_codec_write(codec, 0x1c, 0,
3572 AC_VERB_SET_POWER_STATE, parm);
3573 snd_hda_codec_write(codec, 0x37, 0,
3574 AC_VERB_SET_POWER_STATE, parm);
3575 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003576
Lydia Wang118909562011-03-23 17:57:34 +08003577 if (spec->codec_type == VT1802) {
3578 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3579 parm = AC_PWRST_D3;
3580 set_pin_power_state(codec, 0x25, &parm);
3581 snd_hda_codec_write(codec, 0x15, 0,
3582 AC_VERB_SET_POWER_STATE, parm);
3583 snd_hda_codec_write(codec, 0x35, 0,
3584 AC_VERB_SET_POWER_STATE, parm);
3585 } else {
3586 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3587 parm = AC_PWRST_D3;
3588 set_pin_power_state(codec, 0x25, &parm);
3589 snd_hda_codec_write(codec, 0x19, 0,
3590 AC_VERB_SET_POWER_STATE, parm);
3591 snd_hda_codec_write(codec, 0x35, 0,
3592 AC_VERB_SET_POWER_STATE, parm);
3593 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003594
3595 if (spec->hp_independent_mode)
3596 snd_hda_codec_write(codec, 0x9, 0,
3597 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3598
3599 /* Class-D */
3600 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3601 present = snd_hda_jack_detect(codec, 0x25);
3602
3603 parm = AC_PWRST_D3;
3604 set_pin_power_state(codec, 0x24, &parm);
3605 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08003606 if (spec->codec_type == VT1802)
3607 snd_hda_codec_write(codec, 0x14, 0,
3608 AC_VERB_SET_POWER_STATE, parm);
3609 else
3610 snd_hda_codec_write(codec, 0x18, 0,
3611 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003612 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3613
3614 /* Mono Out */
3615 present = snd_hda_jack_detect(codec, 0x26);
3616
3617 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08003618 if (spec->codec_type == VT1802) {
3619 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3620 snd_hda_codec_write(codec, 0x33, 0,
3621 AC_VERB_SET_POWER_STATE, parm);
3622 snd_hda_codec_write(codec, 0x1c, 0,
3623 AC_VERB_SET_POWER_STATE, parm);
3624 snd_hda_codec_write(codec, 0x3c, 0,
3625 AC_VERB_SET_POWER_STATE, parm);
3626 } else {
3627 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3628 snd_hda_codec_write(codec, 0x31, 0,
3629 AC_VERB_SET_POWER_STATE, parm);
3630 snd_hda_codec_write(codec, 0x17, 0,
3631 AC_VERB_SET_POWER_STATE, parm);
3632 snd_hda_codec_write(codec, 0x3b, 0,
3633 AC_VERB_SET_POWER_STATE, parm);
3634 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003635 /* MW9 (21h) */
3636 if (imux_is_smixer || !is_aa_path_mute(codec))
3637 snd_hda_codec_write(codec, 0x21, 0,
3638 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3639 else
3640 snd_hda_codec_write(codec, 0x21, 0,
3641 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3642}
Lydia Wang25eaba22009-10-10 19:08:43 +08003643
3644/* patch for vt2002P */
3645static int patch_vt2002P(struct hda_codec *codec)
3646{
3647 struct via_spec *spec;
3648 int err;
3649
3650 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003651 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08003652 if (spec == NULL)
3653 return -ENOMEM;
3654
Takashi Iwai620e2b22011-06-17 17:19:19 +02003655 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003656 override_mic_boost(codec, 0x2b, 0, 3, 40);
3657 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02003658 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003659
Lydia Wang25eaba22009-10-10 19:08:43 +08003660 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003661 err = via_parse_auto_config(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08003662 if (err < 0) {
3663 via_free(codec);
3664 return err;
Lydia Wang25eaba22009-10-10 19:08:43 +08003665 }
3666
Lydia Wang118909562011-03-23 17:57:34 +08003667 if (spec->codec_type == VT1802)
Takashi Iwai4a918ff2011-06-20 12:39:26 +02003668 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08003669 else
Takashi Iwai4a918ff2011-06-20 12:39:26 +02003670 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
Lydia Wang118909562011-03-23 17:57:34 +08003671
Lydia Wang25eaba22009-10-10 19:08:43 +08003672 codec->patch_ops = via_patch_ops;
3673
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003674 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08003675 return 0;
3676}
Lydia Wangab6734e2009-10-10 19:08:46 +08003677
3678/* for vt1812 */
3679
Takashi Iwai096a8852011-06-20 12:09:02 +02003680static const struct hda_verb vt1812_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08003681 /* Enable Boost Volume backdoor */
3682 {0x1, 0xfb9, 0x24},
Lydia Wangab6734e2009-10-10 19:08:46 +08003683 /* Enable AOW0 to MW9 */
3684 {0x1, 0xfb8, 0xa8},
3685 { }
3686};
3687
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003688static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3689{
3690 struct via_spec *spec = codec->spec;
3691 int imux_is_smixer =
3692 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3693 unsigned int parm;
3694 unsigned int present;
3695 /* MUX10 (1eh) = stereo mixer */
3696 imux_is_smixer =
3697 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3698 /* inputs */
3699 /* PW 5/6/7 (29h/2ah/2bh) */
3700 parm = AC_PWRST_D3;
3701 set_pin_power_state(codec, 0x29, &parm);
3702 set_pin_power_state(codec, 0x2a, &parm);
3703 set_pin_power_state(codec, 0x2b, &parm);
3704 parm = AC_PWRST_D0;
3705 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3706 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3707 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3708 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3709 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3710
3711 /* outputs */
3712 /* AOW0 (8h)*/
3713 snd_hda_codec_write(codec, 0x8, 0,
3714 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3715
3716 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3717 parm = AC_PWRST_D3;
3718 set_pin_power_state(codec, 0x28, &parm);
3719 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3720 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3721
3722 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3723 parm = AC_PWRST_D3;
3724 set_pin_power_state(codec, 0x25, &parm);
3725 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3726 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3727 if (spec->hp_independent_mode)
3728 snd_hda_codec_write(codec, 0x9, 0,
3729 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3730
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) {
3738 snd_hda_codec_write(codec, 0x14, 0,
3739 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3740 snd_hda_codec_write(codec, 0x34, 0,
3741 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3742 } else {
3743 snd_hda_codec_write(codec, 0x14, 0,
3744 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3745 snd_hda_codec_write(codec, 0x34, 0,
3746 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3747 }
3748
3749
3750 /* Mono Out */
3751 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3752 present = snd_hda_jack_detect(codec, 0x28);
3753
3754 parm = AC_PWRST_D3;
3755 set_pin_power_state(codec, 0x31, &parm);
3756 if (present) {
3757 snd_hda_codec_write(codec, 0x1c, 0,
3758 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3759 snd_hda_codec_write(codec, 0x3c, 0,
3760 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3761 snd_hda_codec_write(codec, 0x3e, 0,
3762 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3763 } else {
3764 snd_hda_codec_write(codec, 0x1c, 0,
3765 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3766 snd_hda_codec_write(codec, 0x3c, 0,
3767 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3768 snd_hda_codec_write(codec, 0x3e, 0,
3769 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3770 }
3771
3772 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3773 parm = AC_PWRST_D3;
3774 set_pin_power_state(codec, 0x33, &parm);
3775 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3776 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3777
3778}
Lydia Wangab6734e2009-10-10 19:08:46 +08003779
3780/* patch for vt1812 */
3781static int patch_vt1812(struct hda_codec *codec)
3782{
3783 struct via_spec *spec;
3784 int err;
3785
3786 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003787 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08003788 if (spec == NULL)
3789 return -ENOMEM;
3790
Takashi Iwai620e2b22011-06-17 17:19:19 +02003791 spec->aa_mix_nid = 0x21;
Takashi Iwaid7a99cc2011-06-18 17:24:46 +02003792 override_mic_boost(codec, 0x2b, 0, 3, 40);
3793 override_mic_boost(codec, 0x29, 0, 3, 40);
Takashi Iwai30b45032011-07-11 17:05:04 +02003794 add_secret_dac_path(codec);
Takashi Iwai620e2b22011-06-17 17:19:19 +02003795
Lydia Wangab6734e2009-10-10 19:08:46 +08003796 /* automatic parse from the BIOS config */
Takashi Iwai12daef62011-06-18 17:45:49 +02003797 err = via_parse_auto_config(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08003798 if (err < 0) {
3799 via_free(codec);
3800 return err;
Lydia Wangab6734e2009-10-10 19:08:46 +08003801 }
3802
Takashi Iwai096a8852011-06-20 12:09:02 +02003803 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
Lydia Wangab6734e2009-10-10 19:08:46 +08003804
Lydia Wangab6734e2009-10-10 19:08:46 +08003805 codec->patch_ops = via_patch_ops;
3806
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003807 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08003808 return 0;
3809}
3810
Joseph Chanc577b8a2006-11-29 15:29:40 +01003811/*
3812 * patch entries
3813 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003814static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01003815 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3816 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3817 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3818 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3819 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003820 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003821 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003822 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003823 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003824 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003825 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003826 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003827 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003828 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003829 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003830 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003831 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003832 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003833 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003834 .patch = patch_vt1709},
Takashi Iwai3218c172008-12-18 09:17:56 +01003835 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003836 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003837 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003838 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003839 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003840 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003841 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003842 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003843 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003844 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003845 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003846 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003847 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003848 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003849 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Takashi Iwaiddd304d2011-06-21 16:33:55 +02003850 .patch = patch_vt1708B},
Takashi Iwai3218c172008-12-18 09:17:56 +01003851 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003852 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003853 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003854 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003855 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003856 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003857 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003858 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08003859 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08003860 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003861 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003862 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003863 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003864 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003865 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003866 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003867 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003868 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003869 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003870 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003871 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003872 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003873 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003874 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003875 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003876 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003877 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003878 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003879 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003880 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003881 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003882 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08003883 { .id = 0x11060428, .name = "VT1718S",
3884 .patch = patch_vt1718S},
3885 { .id = 0x11064428, .name = "VT1718S",
3886 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08003887 { .id = 0x11060441, .name = "VT2020",
3888 .patch = patch_vt1718S},
3889 { .id = 0x11064441, .name = "VT1828S",
3890 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08003891 { .id = 0x11060433, .name = "VT1716S",
3892 .patch = patch_vt1716S},
3893 { .id = 0x1106a721, .name = "VT1716S",
3894 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08003895 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3896 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08003897 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08003898 { .id = 0x11060440, .name = "VT1818S",
3899 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08003900 { .id = 0x11060446, .name = "VT1802",
3901 .patch = patch_vt2002P},
3902 { .id = 0x11068446, .name = "VT1802",
3903 .patch = patch_vt2002P},
Joseph Chanc577b8a2006-11-29 15:29:40 +01003904 {} /* terminator */
3905};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003906
3907MODULE_ALIAS("snd-hda-codec-id:1106*");
3908
3909static struct hda_codec_preset_list via_list = {
3910 .preset = snd_hda_preset_via,
3911 .owner = THIS_MODULE,
3912};
3913
3914MODULE_LICENSE("GPL");
3915MODULE_DESCRIPTION("VIA HD-audio codec");
3916
3917static int __init patch_via_init(void)
3918{
3919 return snd_hda_add_codec_preset(&via_list);
3920}
3921
3922static void __exit patch_via_exit(void)
3923{
3924 snd_hda_delete_codec_preset(&via_list);
3925}
3926
3927module_init(patch_via_init)
3928module_exit(patch_via_exit)