blob: 30d1273f3c3aa3cc7630c4b833eef51483368d89 [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
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010057#define NID_MAPPING (-1)
58
Joseph Chanc577b8a2006-11-29 15:29:40 +010059/* amp values */
60#define AMP_VAL_IDX_SHIFT 19
61#define AMP_VAL_IDX_MASK (0x0f<<19)
62
Joseph Chanc577b8a2006-11-29 15:29:40 +010063/* Pin Widget NID */
64#define VT1708_HP_NID 0x13
65#define VT1708_DIGOUT_NID 0x14
66#define VT1708_DIGIN_NID 0x16
Josepch Chanf7278fd2007-12-13 16:40:40 +010067#define VT1708_DIGIN_PIN 0x26
Harald Welted949cac2008-09-09 15:56:01 +080068#define VT1708_HP_PIN_NID 0x20
69#define VT1708_CD_PIN_NID 0x24
Joseph Chanc577b8a2006-11-29 15:29:40 +010070
71#define VT1709_HP_DAC_NID 0x28
72#define VT1709_DIGOUT_NID 0x13
73#define VT1709_DIGIN_NID 0x17
Josepch Chanf7278fd2007-12-13 16:40:40 +010074#define VT1709_DIGIN_PIN 0x25
75
76#define VT1708B_HP_NID 0x25
77#define VT1708B_DIGOUT_NID 0x12
78#define VT1708B_DIGIN_NID 0x15
79#define VT1708B_DIGIN_PIN 0x21
Joseph Chanc577b8a2006-11-29 15:29:40 +010080
Harald Welted949cac2008-09-09 15:56:01 +080081#define VT1708S_HP_NID 0x25
82#define VT1708S_DIGOUT_NID 0x12
83
84#define VT1702_HP_NID 0x17
85#define VT1702_DIGOUT_NID 0x11
86
Harald Welted7426322008-09-15 22:43:23 +080087enum VIA_HDA_CODEC {
88 UNKNOWN = -1,
89 VT1708,
90 VT1709_10CH,
91 VT1709_6CH,
92 VT1708B_8CH,
93 VT1708B_4CH,
94 VT1708S,
Lydia Wang518bf3b2009-10-10 19:07:29 +080095 VT1708BCE,
Harald Welted7426322008-09-15 22:43:23 +080096 VT1702,
Lydia Wangeb7188c2009-10-10 19:08:34 +080097 VT1718S,
Lydia Wangf3db4232009-10-10 19:08:41 +080098 VT1716S,
Lydia Wang25eaba22009-10-10 19:08:43 +080099 VT2002P,
Lydia Wangab6734e2009-10-10 19:08:46 +0800100 VT1812,
Lydia Wang118909562011-03-23 17:57:34 +0800101 VT1802,
Harald Welted7426322008-09-15 22:43:23 +0800102 CODEC_TYPES,
103};
104
Lydia Wang118909562011-03-23 17:57:34 +0800105#define VT2002P_COMPATIBLE(spec) \
106 ((spec)->codec_type == VT2002P ||\
107 (spec)->codec_type == VT1812 ||\
108 (spec)->codec_type == VT1802)
109
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800110struct via_spec {
111 /* codec parameterization */
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200112 const struct snd_kcontrol_new *mixers[6];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800113 unsigned int num_mixers;
114
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200115 const struct hda_verb *init_verbs[5];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800116 unsigned int num_iverbs;
117
118 char *stream_name_analog;
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200119 const struct hda_pcm_stream *stream_analog_playback;
120 const struct hda_pcm_stream *stream_analog_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800121
122 char *stream_name_digital;
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200123 const struct hda_pcm_stream *stream_digital_playback;
124 const struct hda_pcm_stream *stream_digital_capture;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800125
126 /* playback */
127 struct hda_multi_out multiout;
128 hda_nid_t slave_dig_outs[2];
129
130 /* capture */
131 unsigned int num_adc_nids;
Takashi Iwaia766d0d2011-06-17 09:01:29 +0200132 hda_nid_t adc_nids[3];
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800133 hda_nid_t mux_nids[3];
134 hda_nid_t dig_in_nid;
135 hda_nid_t dig_in_pin;
136
137 /* capture source */
138 const struct hda_input_mux *input_mux;
139 unsigned int cur_mux[3];
140
141 /* PCM information */
142 struct hda_pcm pcm_rec[3];
143
144 /* dynamic controls, init_verbs and input_mux */
145 struct auto_pin_cfg autocfg;
146 struct snd_array kctls;
147 struct hda_input_mux private_imux[2];
148 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
149
150 /* HP mode source */
151 const struct hda_input_mux *hp_mux;
152 unsigned int hp_independent_mode;
153 unsigned int hp_independent_mode_index;
154 unsigned int smart51_enabled;
Lydia Wangf3db4232009-10-10 19:08:41 +0800155 unsigned int dmic_enabled;
Takashi Iwai24088a52011-06-17 16:59:21 +0200156 unsigned int no_pin_power_ctl;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800157 enum VIA_HDA_CODEC codec_type;
158
159 /* work to check hp jack state */
160 struct hda_codec *codec;
161 struct delayed_work vt1708_hp_work;
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200162 int vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800163 int vt1708_hp_present;
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800164
165 void (*set_widgets_power_state)(struct hda_codec *codec);
166
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800167#ifdef CONFIG_SND_HDA_POWER_SAVE
168 struct hda_loopback_check loopback;
169#endif
170};
171
Lydia Wang0341ccd2011-03-22 16:25:03 +0800172static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100173static struct via_spec * via_new_spec(struct hda_codec *codec)
174{
175 struct via_spec *spec;
176
177 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
178 if (spec == NULL)
179 return NULL;
180
181 codec->spec = spec;
182 spec->codec = codec;
Lydia Wang0341ccd2011-03-22 16:25:03 +0800183 spec->codec_type = get_codec_type(codec);
184 /* VT1708BCE & VT1708S are almost same */
185 if (spec->codec_type == VT1708BCE)
186 spec->codec_type = VT1708S;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100187 return spec;
188}
189
Lydia Wang744ff5f2009-10-10 19:07:26 +0800190static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
Harald Welted7426322008-09-15 22:43:23 +0800191{
Lydia Wang744ff5f2009-10-10 19:07:26 +0800192 u32 vendor_id = codec->vendor_id;
Harald Welted7426322008-09-15 22:43:23 +0800193 u16 ven_id = vendor_id >> 16;
194 u16 dev_id = vendor_id & 0xffff;
195 enum VIA_HDA_CODEC codec_type;
196
197 /* get codec type */
198 if (ven_id != 0x1106)
199 codec_type = UNKNOWN;
200 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
201 codec_type = VT1708;
202 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
203 codec_type = VT1709_10CH;
204 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
205 codec_type = VT1709_6CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800206 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
Harald Welted7426322008-09-15 22:43:23 +0800207 codec_type = VT1708B_8CH;
Lydia Wang518bf3b2009-10-10 19:07:29 +0800208 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
209 codec_type = VT1708BCE;
210 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
Harald Welted7426322008-09-15 22:43:23 +0800211 codec_type = VT1708B_4CH;
212 else if ((dev_id & 0xfff) == 0x397
213 && (dev_id >> 12) < 8)
214 codec_type = VT1708S;
215 else if ((dev_id & 0xfff) == 0x398
216 && (dev_id >> 12) < 8)
217 codec_type = VT1702;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800218 else if ((dev_id & 0xfff) == 0x428
219 && (dev_id >> 12) < 8)
220 codec_type = VT1718S;
Lydia Wangf3db4232009-10-10 19:08:41 +0800221 else if (dev_id == 0x0433 || dev_id == 0xa721)
222 codec_type = VT1716S;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +0800223 else if (dev_id == 0x0441 || dev_id == 0x4441)
224 codec_type = VT1718S;
Lydia Wang25eaba22009-10-10 19:08:43 +0800225 else if (dev_id == 0x0438 || dev_id == 0x4438)
226 codec_type = VT2002P;
Lydia Wangab6734e2009-10-10 19:08:46 +0800227 else if (dev_id == 0x0448)
228 codec_type = VT1812;
Lydia Wang36dd5c42009-10-20 13:18:04 +0800229 else if (dev_id == 0x0440)
230 codec_type = VT1708S;
Lydia Wang118909562011-03-23 17:57:34 +0800231 else if ((dev_id & 0xfff) == 0x446)
232 codec_type = VT1802;
Harald Welted7426322008-09-15 22:43:23 +0800233 else
234 codec_type = UNKNOWN;
235 return codec_type;
236};
237
Lydia Wangec7e7e42011-03-24 12:43:44 +0800238#define VIA_JACK_EVENT 0x20
Harald Welte69e52a82008-09-09 15:57:32 +0800239#define VIA_HP_EVENT 0x01
240#define VIA_GPIO_EVENT 0x02
Lydia Wangec7e7e42011-03-24 12:43:44 +0800241#define VIA_MONO_EVENT 0x03
242#define VIA_SPEAKER_EVENT 0x04
243#define VIA_BIND_HP_EVENT 0x05
Harald Welte69e52a82008-09-09 15:57:32 +0800244
Joseph Chanc577b8a2006-11-29 15:29:40 +0100245enum {
246 VIA_CTL_WIDGET_VOL,
247 VIA_CTL_WIDGET_MUTE,
Lydia Wangf5271102009-10-10 19:07:35 +0800248 VIA_CTL_WIDGET_ANALOG_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800249 VIA_CTL_WIDGET_BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100250};
251
252enum {
Harald Welteeb14a462008-09-09 15:40:38 +0800253 AUTO_SEQ_FRONT = 0,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100254 AUTO_SEQ_SURROUND,
255 AUTO_SEQ_CENLFE,
256 AUTO_SEQ_SIDE
257};
258
Lydia Wangf5271102009-10-10 19:07:35 +0800259static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800260static int is_aa_path_mute(struct hda_codec *codec);
261
262static void vt1708_start_hp_work(struct via_spec *spec)
263{
264 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
265 return;
266 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200267 !spec->vt1708_jack_detect);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800268 if (!delayed_work_pending(&spec->vt1708_hp_work))
269 schedule_delayed_work(&spec->vt1708_hp_work,
270 msecs_to_jiffies(100));
271}
272
273static void vt1708_stop_hp_work(struct via_spec *spec)
274{
275 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
276 return;
277 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
278 && !is_aa_path_mute(spec->codec))
279 return;
280 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
Takashi Iwaie06e5a22011-06-17 15:46:13 +0200281 !spec->vt1708_jack_detect);
Tejun Heo5b84ba22010-12-11 17:51:26 +0100282 cancel_delayed_work_sync(&spec->vt1708_hp_work);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800283}
Lydia Wangf5271102009-10-10 19:07:35 +0800284
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800285static void set_widgets_power_state(struct hda_codec *codec)
286{
287 struct via_spec *spec = codec->spec;
288 if (spec->set_widgets_power_state)
289 spec->set_widgets_power_state(codec);
290}
Lydia Wang25eaba22009-10-10 19:08:43 +0800291
Lydia Wangf5271102009-10-10 19:07:35 +0800292static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_value *ucontrol)
294{
295 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
296 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
297
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800298 set_widgets_power_state(codec);
Lydia Wangf5271102009-10-10 19:07:35 +0800299 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
Lydia Wang1f2e99f2009-10-10 19:08:17 +0800300 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
301 if (is_aa_path_mute(codec))
302 vt1708_start_hp_work(codec->spec);
303 else
304 vt1708_stop_hp_work(codec->spec);
305 }
Lydia Wangf5271102009-10-10 19:07:35 +0800306 return change;
307}
308
309/* modify .put = snd_hda_mixer_amp_switch_put */
310#define ANALOG_INPUT_MUTE \
311 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
312 .name = NULL, \
313 .index = 0, \
314 .info = snd_hda_mixer_amp_switch_info, \
315 .get = snd_hda_mixer_amp_switch_get, \
316 .put = analog_input_switch_put, \
317 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
318
Lydia Wang25eaba22009-10-10 19:08:43 +0800319static void via_hp_bind_automute(struct hda_codec *codec);
320
321static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
322 struct snd_ctl_elem_value *ucontrol)
323{
324 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
325 struct via_spec *spec = codec->spec;
326 int i;
327 int change = 0;
328
329 long *valp = ucontrol->value.integer.value;
330 int lmute, rmute;
331 if (strstr(kcontrol->id.name, "Switch") == NULL) {
332 snd_printd("Invalid control!\n");
333 return change;
334 }
335 change = snd_hda_mixer_amp_switch_put(kcontrol,
336 ucontrol);
337 /* Get mute value */
338 lmute = *valp ? 0 : HDA_AMP_MUTE;
339 valp++;
340 rmute = *valp ? 0 : HDA_AMP_MUTE;
341
342 /* Set hp pins */
343 if (!spec->hp_independent_mode) {
344 for (i = 0; i < spec->autocfg.hp_outs; i++) {
345 snd_hda_codec_amp_update(
346 codec, spec->autocfg.hp_pins[i],
347 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
348 lmute);
349 snd_hda_codec_amp_update(
350 codec, spec->autocfg.hp_pins[i],
351 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
352 rmute);
353 }
354 }
355
356 if (!lmute && !rmute) {
357 /* Line Outs */
358 for (i = 0; i < spec->autocfg.line_outs; i++)
359 snd_hda_codec_amp_stereo(
360 codec, spec->autocfg.line_out_pins[i],
361 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
362 /* Speakers */
363 for (i = 0; i < spec->autocfg.speaker_outs; i++)
364 snd_hda_codec_amp_stereo(
365 codec, spec->autocfg.speaker_pins[i],
366 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
367 /* unmute */
368 via_hp_bind_automute(codec);
369
370 } else {
371 if (lmute) {
372 /* Mute all left channels */
373 for (i = 1; i < spec->autocfg.line_outs; i++)
374 snd_hda_codec_amp_update(
375 codec,
376 spec->autocfg.line_out_pins[i],
377 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
378 lmute);
379 for (i = 0; i < spec->autocfg.speaker_outs; i++)
380 snd_hda_codec_amp_update(
381 codec,
382 spec->autocfg.speaker_pins[i],
383 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
384 lmute);
385 }
386 if (rmute) {
387 /* mute all right channels */
388 for (i = 1; i < spec->autocfg.line_outs; i++)
389 snd_hda_codec_amp_update(
390 codec,
391 spec->autocfg.line_out_pins[i],
392 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
393 rmute);
394 for (i = 0; i < spec->autocfg.speaker_outs; i++)
395 snd_hda_codec_amp_update(
396 codec,
397 spec->autocfg.speaker_pins[i],
398 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
399 rmute);
400 }
401 }
402 return change;
403}
404
405#define BIND_PIN_MUTE \
406 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
407 .name = NULL, \
408 .index = 0, \
409 .info = snd_hda_mixer_amp_switch_info, \
410 .get = snd_hda_mixer_amp_switch_get, \
411 .put = bind_pin_switch_put, \
412 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
413
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200414static const struct snd_kcontrol_new via_control_templates[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +0100415 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
416 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Lydia Wangf5271102009-10-10 19:07:35 +0800417 ANALOG_INPUT_MUTE,
Lydia Wang25eaba22009-10-10 19:08:43 +0800418 BIND_PIN_MUTE,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100419};
420
Lydia Wangab6734e2009-10-10 19:08:46 +0800421
Joseph Chanc577b8a2006-11-29 15:29:40 +0100422/* add dynamic controls */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200423static int __via_add_control(struct via_spec *spec, int type, const char *name,
424 int idx, unsigned long val)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100425{
426 struct snd_kcontrol_new *knew;
427
Takashi Iwai603c4012008-07-30 15:01:44 +0200428 snd_array_init(&spec->kctls, sizeof(*knew), 32);
429 knew = snd_array_new(&spec->kctls);
430 if (!knew)
431 return -ENOMEM;
Lydia Wang71eb7dc2009-10-10 19:08:49 +0800432 *knew = via_control_templates[type];
Joseph Chanc577b8a2006-11-29 15:29:40 +0100433 knew->name = kstrdup(name, GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100434 if (!knew->name)
435 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100436 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100437 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100438 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100439 return 0;
440}
441
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200442#define via_add_control(spec, type, name, val) \
443 __via_add_control(spec, type, name, 0, val)
444
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100445static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200446 const struct snd_kcontrol_new *tmpl)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100447{
448 struct snd_kcontrol_new *knew;
449
450 snd_array_init(&spec->kctls, sizeof(*knew), 32);
451 knew = snd_array_new(&spec->kctls);
452 if (!knew)
453 return NULL;
454 *knew = *tmpl;
455 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
456 if (!knew->name)
457 return NULL;
Takashi Iwaib3314392010-04-14 14:33:57 +0200458 return knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100459}
460
Takashi Iwai603c4012008-07-30 15:01:44 +0200461static void via_free_kctls(struct hda_codec *codec)
462{
463 struct via_spec *spec = codec->spec;
464
465 if (spec->kctls.list) {
466 struct snd_kcontrol_new *kctl = spec->kctls.list;
467 int i;
468 for (i = 0; i < spec->kctls.used; i++)
469 kfree(kctl[i].name);
470 }
471 snd_array_free(&spec->kctls);
472}
473
Joseph Chanc577b8a2006-11-29 15:29:40 +0100474/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800475static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200476 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100477{
478 char name[32];
479 int err;
480
481 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200482 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100483 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
484 if (err < 0)
485 return err;
486 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200487 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100488 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
489 if (err < 0)
490 return err;
491 return 0;
492}
493
494static void via_auto_set_output_and_unmute(struct hda_codec *codec,
495 hda_nid_t nid, int pin_type,
496 int dac_idx)
497{
498 /* set as output */
499 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
500 pin_type);
501 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
502 AMP_OUT_UNMUTE);
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200503 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
Lydia Wang377ff312009-10-10 19:08:55 +0800504 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200505 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100506}
507
508
509static void via_auto_init_multi_out(struct hda_codec *codec)
510{
511 struct via_spec *spec = codec->spec;
512 int i;
513
514 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
515 hda_nid_t nid = spec->autocfg.line_out_pins[i];
516 if (nid)
517 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
518 }
519}
520
521static void via_auto_init_hp_out(struct hda_codec *codec)
522{
523 struct via_spec *spec = codec->spec;
524 hda_nid_t pin;
Lydia Wang25eaba22009-10-10 19:08:43 +0800525 int i;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100526
Lydia Wang25eaba22009-10-10 19:08:43 +0800527 for (i = 0; i < spec->autocfg.hp_outs; i++) {
528 pin = spec->autocfg.hp_pins[i];
529 if (pin) /* connect to front */
530 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
531 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100532}
533
Clemens Ladisch32e01912010-07-12 16:28:50 +0200534static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
535
Joseph Chanc577b8a2006-11-29 15:29:40 +0100536static void via_auto_init_analog_input(struct hda_codec *codec)
537{
538 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200539 const struct auto_pin_cfg *cfg = &spec->autocfg;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200540 unsigned int ctl;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100541 int i;
542
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200543 for (i = 0; i < cfg->num_inputs; i++) {
544 hda_nid_t nid = cfg->inputs[i].pin;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200545 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
546 ctl = PIN_OUT;
David Henningsson30649672011-02-21 10:23:18 +0100547 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
Clemens Ladisch32e01912010-07-12 16:28:50 +0200548 ctl = PIN_VREF50;
549 else
550 ctl = PIN_IN;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100551 snd_hda_codec_write(codec, nid, 0,
Clemens Ladisch32e01912010-07-12 16:28:50 +0200552 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100553 }
554}
Lydia Wangf5271102009-10-10 19:07:35 +0800555
556static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
557 unsigned int *affected_parm)
558{
559 unsigned parm;
560 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
561 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
562 >> AC_DEFCFG_MISC_SHIFT
563 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800564 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200565 unsigned present = 0;
566
567 no_presence |= spec->no_pin_power_ctl;
568 if (!no_presence)
569 present = snd_hda_jack_detect(codec, nid);
Lydia Wang1564b282009-10-10 19:07:52 +0800570 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
571 || ((no_presence || present)
572 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800573 *affected_parm = AC_PWRST_D0; /* if it's connected */
574 parm = AC_PWRST_D0;
575 } else
576 parm = AC_PWRST_D3;
577
578 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
579}
580
Takashi Iwai24088a52011-06-17 16:59:21 +0200581static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
582 struct snd_ctl_elem_info *uinfo)
583{
584 static const char * const texts[] = {
585 "Disabled", "Enabled"
586 };
587
588 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
589 uinfo->count = 1;
590 uinfo->value.enumerated.items = 2;
591 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
592 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
593 strcpy(uinfo->value.enumerated.name,
594 texts[uinfo->value.enumerated.item]);
595 return 0;
596}
597
598static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
599 struct snd_ctl_elem_value *ucontrol)
600{
601 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
602 struct via_spec *spec = codec->spec;
603 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
604 return 0;
605}
606
607static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
608 struct snd_ctl_elem_value *ucontrol)
609{
610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
611 struct via_spec *spec = codec->spec;
612 unsigned int val = !ucontrol->value.enumerated.item[0];
613
614 if (val == spec->no_pin_power_ctl)
615 return 0;
616 spec->no_pin_power_ctl = val;
617 set_widgets_power_state(codec);
618 return 1;
619}
620
621static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
622 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
623 .name = "Dynamic Power-Control",
624 .info = via_pin_power_ctl_info,
625 .get = via_pin_power_ctl_get,
626 .put = via_pin_power_ctl_put,
627};
628
629
Joseph Chanc577b8a2006-11-29 15:29:40 +0100630/*
631 * input MUX handling
632 */
633static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
634 struct snd_ctl_elem_info *uinfo)
635{
636 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
637 struct via_spec *spec = codec->spec;
638 return snd_hda_input_mux_info(spec->input_mux, uinfo);
639}
640
641static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
642 struct snd_ctl_elem_value *ucontrol)
643{
644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
645 struct via_spec *spec = codec->spec;
646 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
647
648 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
649 return 0;
650}
651
652static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
653 struct snd_ctl_elem_value *ucontrol)
654{
655 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
656 struct via_spec *spec = codec->spec;
657 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800658 int ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100659
Takashi Iwai337b9d02009-07-07 18:18:59 +0200660 if (!spec->mux_nids[adc_idx])
661 return -EINVAL;
Lydia Wanga80e6e32009-10-10 19:07:55 +0800662 /* switch to D0 beofre change index */
663 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
664 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
665 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
666 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800667
668 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
669 spec->mux_nids[adc_idx],
670 &spec->cur_mux[adc_idx]);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800671 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800672 set_widgets_power_state(codec);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800673
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800674 return ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100675}
676
Harald Welte0aa62ae2008-09-09 15:58:27 +0800677static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
678 struct snd_ctl_elem_info *uinfo)
679{
680 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
681 struct via_spec *spec = codec->spec;
682 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
683}
684
685static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
686 struct snd_ctl_elem_value *ucontrol)
687{
688 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100689 hda_nid_t nid = kcontrol->private_value;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800690 unsigned int pinsel;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800691
Lydia Wangeb7188c2009-10-10 19:08:34 +0800692 /* use !! to translate conn sel 2 for VT1718S */
693 pinsel = !!snd_hda_codec_read(codec, nid, 0,
694 AC_VERB_GET_CONNECT_SEL,
695 0x00);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800696 ucontrol->value.enumerated.item[0] = pinsel;
697
698 return 0;
699}
700
Lydia Wang0713efe2009-10-10 19:07:43 +0800701static void activate_ctl(struct hda_codec *codec, const char *name, int active)
702{
703 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
704 if (ctl) {
705 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
706 ctl->vd[0].access |= active
707 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
708 snd_ctl_notify(codec->bus->card,
709 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
710 }
711}
712
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100713static hda_nid_t side_mute_channel(struct via_spec *spec)
714{
715 switch (spec->codec_type) {
716 case VT1708: return 0x1b;
717 case VT1709_10CH: return 0x29;
718 case VT1708B_8CH: /* fall thru */
719 case VT1708S: return 0x27;
Lydia Wange87885f2011-03-24 12:39:05 +0800720 case VT2002P: return 0x19;
721 case VT1802: return 0x15;
722 case VT1812: return 0x15;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100723 default: return 0;
724 }
725}
726
Lydia Wangcdc17842009-10-10 19:07:47 +0800727static int update_side_mute_status(struct hda_codec *codec)
728{
729 /* mute side channel */
730 struct via_spec *spec = codec->spec;
Lydia Wange87885f2011-03-24 12:39:05 +0800731 unsigned int parm;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100732 hda_nid_t sw3 = side_mute_channel(spec);
Lydia Wangcdc17842009-10-10 19:07:47 +0800733
Lydia Wange87885f2011-03-24 12:39:05 +0800734 if (sw3) {
735 if (VT2002P_COMPATIBLE(spec))
736 parm = spec->hp_independent_mode ?
737 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
738 else
739 parm = spec->hp_independent_mode ?
740 AMP_OUT_MUTE : AMP_OUT_UNMUTE;
741 snd_hda_codec_write(codec, sw3, 0,
742 AC_VERB_SET_AMP_GAIN_MUTE, parm);
743 if (spec->codec_type == VT1812)
744 snd_hda_codec_write(codec, 0x1d, 0,
745 AC_VERB_SET_AMP_GAIN_MUTE, parm);
746 }
Lydia Wangcdc17842009-10-10 19:07:47 +0800747 return 0;
748}
749
Harald Welte0aa62ae2008-09-09 15:58:27 +0800750static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
751 struct snd_ctl_elem_value *ucontrol)
752{
753 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
754 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100755 hda_nid_t nid = kcontrol->private_value;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800756 unsigned int pinsel = ucontrol->value.enumerated.item[0];
Lydia Wangcdc17842009-10-10 19:07:47 +0800757 /* Get Independent Mode index of headphone pin widget */
758 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
759 ? 1 : 0;
Lydia Wangce0e5a92011-03-22 16:22:37 +0800760 if (spec->codec_type == VT1718S)
761 snd_hda_codec_write(codec, nid, 0,
762 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
763 else
764 snd_hda_codec_write(codec, nid, 0,
765 AC_VERB_SET_CONNECT_SEL, pinsel);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800766
Lydia Wangce0e5a92011-03-22 16:22:37 +0800767 if (spec->codec_type == VT1812)
768 snd_hda_codec_write(codec, 0x35, 0,
769 AC_VERB_SET_CONNECT_SEL, pinsel);
Lydia Wangcdc17842009-10-10 19:07:47 +0800770 if (spec->multiout.hp_nid && spec->multiout.hp_nid
771 != spec->multiout.dac_nids[HDA_FRONT])
772 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
773 0, 0, 0);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800774
Lydia Wangcdc17842009-10-10 19:07:47 +0800775 update_side_mute_status(codec);
Lydia Wang0713efe2009-10-10 19:07:43 +0800776 /* update HP volume/swtich active state */
777 if (spec->codec_type == VT1708S
Lydia Wangeb7188c2009-10-10 19:08:34 +0800778 || spec->codec_type == VT1702
Lydia Wangf3db4232009-10-10 19:08:41 +0800779 || spec->codec_type == VT1718S
Lydia Wang25eaba22009-10-10 19:08:43 +0800780 || spec->codec_type == VT1716S
Lydia Wang118909562011-03-23 17:57:34 +0800781 || VT2002P_COMPATIBLE(spec)) {
Lydia Wang0713efe2009-10-10 19:07:43 +0800782 activate_ctl(codec, "Headphone Playback Volume",
783 spec->hp_independent_mode);
784 activate_ctl(codec, "Headphone Playback Switch",
785 spec->hp_independent_mode);
786 }
Lydia Wangce0e5a92011-03-22 16:22:37 +0800787 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800788 set_widgets_power_state(codec);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800789 return 0;
790}
791
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200792static const struct snd_kcontrol_new via_hp_mixer[2] = {
Harald Welte0aa62ae2008-09-09 15:58:27 +0800793 {
794 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
795 .name = "Independent HP",
Harald Welte0aa62ae2008-09-09 15:58:27 +0800796 .info = via_independent_hp_info,
797 .get = via_independent_hp_get,
798 .put = via_independent_hp_put,
799 },
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100800 {
801 .iface = NID_MAPPING,
802 .name = "Independent HP",
803 },
Harald Welte0aa62ae2008-09-09 15:58:27 +0800804};
805
Takashi Iwai3d83e572010-04-14 14:36:23 +0200806static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100807{
Takashi Iwai3d83e572010-04-14 14:36:23 +0200808 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100809 struct snd_kcontrol_new *knew;
810 hda_nid_t nid;
Takashi Iwai3d83e572010-04-14 14:36:23 +0200811 int nums;
812 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100813
814 switch (spec->codec_type) {
815 case VT1718S:
816 nid = 0x34;
817 break;
818 case VT2002P:
Lydia Wang118909562011-03-23 17:57:34 +0800819 case VT1802:
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100820 nid = 0x35;
821 break;
822 case VT1812:
823 nid = 0x3d;
824 break;
825 default:
826 nid = spec->autocfg.hp_pins[0];
827 break;
828 }
829
Lydia Wangee3c35c2011-03-22 16:26:36 +0800830 if (spec->codec_type != VT1708) {
831 nums = snd_hda_get_connections(codec, nid,
832 conn, HDA_MAX_CONNECTIONS);
833 if (nums <= 1)
834 return 0;
835 }
Takashi Iwai3d83e572010-04-14 14:36:23 +0200836
837 knew = via_clone_control(spec, &via_hp_mixer[0]);
838 if (knew == NULL)
839 return -ENOMEM;
840
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100841 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
842 knew->private_value = nid;
843
844 knew = via_clone_control(spec, &via_hp_mixer[1]);
845 if (knew == NULL)
846 return -ENOMEM;
847 knew->subdevice = side_mute_channel(spec);
848
849 return 0;
850}
851
Lydia Wang1564b282009-10-10 19:07:52 +0800852static void notify_aa_path_ctls(struct hda_codec *codec)
853{
854 int i;
855 struct snd_ctl_elem_id id;
Lydia Wang525566c2011-04-28 16:03:39 +0800856 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
857 struct snd_kcontrol *ctl;
Lydia Wang1564b282009-10-10 19:07:52 +0800858
859 memset(&id, 0, sizeof(id));
860 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
861 for (i = 0; i < ARRAY_SIZE(labels); i++) {
862 sprintf(id.name, "%s Playback Volume", labels[i]);
Lydia Wang525566c2011-04-28 16:03:39 +0800863 ctl = snd_hda_find_mixer_ctl(codec, id.name);
864 if (ctl)
865 snd_ctl_notify(codec->bus->card,
866 SNDRV_CTL_EVENT_MASK_VALUE,
867 &ctl->id);
Lydia Wang1564b282009-10-10 19:07:52 +0800868 }
869}
870
871static void mute_aa_path(struct hda_codec *codec, int mute)
872{
873 struct via_spec *spec = codec->spec;
874 hda_nid_t nid_mixer;
875 int start_idx;
876 int end_idx;
877 int i;
878 /* get nid of MW0 and start & end index */
879 switch (spec->codec_type) {
880 case VT1708:
881 nid_mixer = 0x17;
882 start_idx = 2;
883 end_idx = 4;
884 break;
885 case VT1709_10CH:
886 case VT1709_6CH:
887 nid_mixer = 0x18;
888 start_idx = 2;
889 end_idx = 4;
890 break;
891 case VT1708B_8CH:
892 case VT1708B_4CH:
893 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +0800894 case VT1716S:
Lydia Wang1564b282009-10-10 19:07:52 +0800895 nid_mixer = 0x16;
896 start_idx = 2;
897 end_idx = 4;
898 break;
Lydia Wangab657e02011-03-22 16:23:23 +0800899 case VT1718S:
900 nid_mixer = 0x21;
901 start_idx = 1;
902 end_idx = 3;
903 break;
Lydia Wang1564b282009-10-10 19:07:52 +0800904 default:
905 return;
906 }
907 /* check AA path's mute status */
908 for (i = start_idx; i <= end_idx; i++) {
909 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
910 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
911 HDA_AMP_MUTE, val);
912 }
913}
914static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
915{
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200916 const struct auto_pin_cfg *cfg = &spec->autocfg;
917 int i;
918
919 for (i = 0; i < cfg->num_inputs; i++) {
920 if (pin == cfg->inputs[i].pin)
Takashi Iwai86e29592010-09-09 14:50:17 +0200921 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
Lydia Wang1564b282009-10-10 19:07:52 +0800922 }
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200923 return 0;
Lydia Wang1564b282009-10-10 19:07:52 +0800924}
925
926static int via_smart51_info(struct snd_kcontrol *kcontrol,
927 struct snd_ctl_elem_info *uinfo)
928{
929 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
930 uinfo->count = 1;
931 uinfo->value.integer.min = 0;
932 uinfo->value.integer.max = 1;
933 return 0;
934}
935
936static int via_smart51_get(struct snd_kcontrol *kcontrol,
937 struct snd_ctl_elem_value *ucontrol)
938{
939 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
940 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200941 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800942 int on = 1;
943 int i;
944
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200945 for (i = 0; i < cfg->num_inputs; i++) {
946 hda_nid_t nid = cfg->inputs[i].pin;
947 int ctl = snd_hda_codec_read(codec, nid, 0,
948 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai86e29592010-09-09 14:50:17 +0200949 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200950 continue;
Takashi Iwai86e29592010-09-09 14:50:17 +0200951 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200952 spec->hp_independent_mode && spec->codec_type != VT1718S)
953 continue; /* ignore FMic for independent HP */
954 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
955 on = 0;
Lydia Wang1564b282009-10-10 19:07:52 +0800956 }
957 *ucontrol->value.integer.value = on;
958 return 0;
959}
960
961static int via_smart51_put(struct snd_kcontrol *kcontrol,
962 struct snd_ctl_elem_value *ucontrol)
963{
964 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
965 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200966 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800967 int out_in = *ucontrol->value.integer.value
968 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +0800969 int i;
970
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200971 for (i = 0; i < cfg->num_inputs; i++) {
972 hda_nid_t nid = cfg->inputs[i].pin;
973 unsigned int parm;
974
Takashi Iwai86e29592010-09-09 14:50:17 +0200975 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200976 continue;
Takashi Iwai86e29592010-09-09 14:50:17 +0200977 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200978 spec->hp_independent_mode && spec->codec_type != VT1718S)
Lydia Wang1564b282009-10-10 19:07:52 +0800979 continue; /* don't retask FMic for independent HP */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200980
981 parm = snd_hda_codec_read(codec, nid, 0,
982 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
983 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
984 parm |= out_in;
985 snd_hda_codec_write(codec, nid, 0,
986 AC_VERB_SET_PIN_WIDGET_CONTROL,
987 parm);
988 if (out_in == AC_PINCTL_OUT_EN) {
989 mute_aa_path(codec, 1);
990 notify_aa_path_ctls(codec);
991 }
992 if (spec->codec_type == VT1718S) {
993 snd_hda_codec_amp_stereo(
Lydia Wangeb7188c2009-10-10 19:08:34 +0800994 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
995 HDA_AMP_UNMUTE);
Lydia Wang1564b282009-10-10 19:07:52 +0800996 }
Takashi Iwai86e29592010-09-09 14:50:17 +0200997 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
Lydia Wangf3db4232009-10-10 19:08:41 +0800998 if (spec->codec_type == VT1708S
999 || spec->codec_type == VT1716S) {
Lydia Wang1564b282009-10-10 19:07:52 +08001000 /* input = index 1 (AOW3) */
1001 snd_hda_codec_write(
1002 codec, nid, 0,
1003 AC_VERB_SET_CONNECT_SEL, 1);
1004 snd_hda_codec_amp_stereo(
1005 codec, nid, HDA_OUTPUT,
1006 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1007 }
1008 }
1009 }
1010 spec->smart51_enabled = *ucontrol->value.integer.value;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001011 set_widgets_power_state(codec);
Lydia Wang1564b282009-10-10 19:07:52 +08001012 return 1;
1013}
1014
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001015static const struct snd_kcontrol_new via_smart51_mixer = {
1016 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1017 .name = "Smart 5.1",
1018 .count = 1,
1019 .info = via_smart51_info,
1020 .get = via_smart51_get,
1021 .put = via_smart51_put,
Lydia Wang1564b282009-10-10 19:07:52 +08001022};
1023
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001024static int via_smart51_build(struct via_spec *spec)
1025{
1026 struct snd_kcontrol_new *knew;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001027 const struct auto_pin_cfg *cfg = &spec->autocfg;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001028 hda_nid_t nid;
1029 int i;
1030
Lydia Wangcb34c202011-04-27 17:44:16 +08001031 if (!cfg)
1032 return 0;
1033 if (cfg->line_outs > 2)
1034 return 0;
1035
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001036 knew = via_clone_control(spec, &via_smart51_mixer);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001037 if (knew == NULL)
1038 return -ENOMEM;
1039
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001040 for (i = 0; i < cfg->num_inputs; i++) {
1041 nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02001042 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001043 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001044 break;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001045 }
1046 }
1047
1048 return 0;
1049}
1050
Joseph Chanc577b8a2006-11-29 15:29:40 +01001051/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001052static const struct snd_kcontrol_new vt1708_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001053 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1054 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1055 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1056 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1057 {
1058 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1059 /* The multiple "Capture Source" controls confuse alsamixer
1060 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01001061 */
1062 /* .name = "Capture Source", */
1063 .name = "Input Source",
1064 .count = 1,
1065 .info = via_mux_enum_info,
1066 .get = via_mux_enum_get,
1067 .put = via_mux_enum_put,
1068 },
1069 { } /* end */
1070};
Lydia Wangf5271102009-10-10 19:07:35 +08001071
1072/* check AA path's mute statue */
1073static int is_aa_path_mute(struct hda_codec *codec)
1074{
1075 int mute = 1;
1076 hda_nid_t nid_mixer;
1077 int start_idx;
1078 int end_idx;
1079 int i;
1080 struct via_spec *spec = codec->spec;
1081 /* get nid of MW0 and start & end index */
1082 switch (spec->codec_type) {
1083 case VT1708B_8CH:
1084 case VT1708B_4CH:
1085 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001086 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001087 nid_mixer = 0x16;
1088 start_idx = 2;
1089 end_idx = 4;
1090 break;
1091 case VT1702:
1092 nid_mixer = 0x1a;
1093 start_idx = 1;
1094 end_idx = 3;
1095 break;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001096 case VT1718S:
1097 nid_mixer = 0x21;
1098 start_idx = 1;
1099 end_idx = 3;
1100 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001101 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001102 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001103 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001104 nid_mixer = 0x21;
1105 start_idx = 0;
1106 end_idx = 2;
1107 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001108 default:
1109 return 0;
1110 }
1111 /* check AA path's mute status */
1112 for (i = start_idx; i <= end_idx; i++) {
1113 unsigned int con_list = snd_hda_codec_read(
1114 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1115 int shift = 8 * (i % 4);
1116 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1117 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1118 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1119 /* check mute status while the pin is connected */
1120 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1121 HDA_INPUT, i) >> 7;
1122 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1123 HDA_INPUT, i) >> 7;
1124 if (!mute_l || !mute_r) {
1125 mute = 0;
1126 break;
1127 }
1128 }
1129 }
1130 return mute;
1131}
1132
1133/* enter/exit analog low-current mode */
1134static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1135{
1136 struct via_spec *spec = codec->spec;
1137 static int saved_stream_idle = 1; /* saved stream idle status */
1138 int enable = is_aa_path_mute(codec);
1139 unsigned int verb = 0;
1140 unsigned int parm = 0;
1141
1142 if (stream_idle == -1) /* stream status did not change */
1143 enable = enable && saved_stream_idle;
1144 else {
1145 enable = enable && stream_idle;
1146 saved_stream_idle = stream_idle;
1147 }
1148
1149 /* decide low current mode's verb & parameter */
1150 switch (spec->codec_type) {
1151 case VT1708B_8CH:
1152 case VT1708B_4CH:
1153 verb = 0xf70;
1154 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1155 break;
1156 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001157 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001158 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001159 verb = 0xf73;
1160 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1161 break;
1162 case VT1702:
1163 verb = 0xf73;
1164 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1165 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001166 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001167 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001168 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001169 verb = 0xf93;
1170 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1171 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001172 default:
1173 return; /* other codecs are not supported */
1174 }
1175 /* send verb */
1176 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1177}
1178
Joseph Chanc577b8a2006-11-29 15:29:40 +01001179/*
1180 * generic initialization of ADC, input mixers and output mixers
1181 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001182static const struct hda_verb vt1708_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001183 /*
1184 * Unmute ADC0-1 and set the default input to mic-in
1185 */
1186 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1187 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1188
1189
Josepch Chanf7278fd2007-12-13 16:40:40 +01001190 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01001191 * mixer widget
1192 */
1193 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01001194 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1195 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1196 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1197 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1198 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001199
1200 /*
1201 * Set up output mixers (0x19 - 0x1b)
1202 */
1203 /* set vol=0 to output mixers */
1204 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1205 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1206 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Lydia Wang377ff312009-10-10 19:08:55 +08001207
Lydia Wangbfdc6752009-10-10 19:08:50 +08001208 /* Setup default input MW0 to PW4 */
1209 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001210 /* PW9 Output enable */
1211 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangaa266fc2011-03-24 12:41:01 +08001212 /* power down jack detect function */
1213 {0x1, 0xf81, 0x1},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001214 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001215};
1216
1217static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1218 struct hda_codec *codec,
1219 struct snd_pcm_substream *substream)
1220{
1221 struct via_spec *spec = codec->spec;
Lydia Wang17314372009-10-10 19:07:37 +08001222 int idle = substream->pstr->substream_opened == 1
1223 && substream->ref_count == 0;
Lydia Wang17314372009-10-10 19:07:37 +08001224 analog_low_current_mode(codec, idle);
Takashi Iwai9a081602008-02-12 18:37:26 +01001225 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1226 hinfo);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001227}
1228
Harald Welte0aa62ae2008-09-09 15:58:27 +08001229static void playback_multi_pcm_prep_0(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;
1235 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001236 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001237 int chs = substream->runtime->channels;
1238 int i;
Stephen Warren7c935972011-06-01 11:14:17 -06001239 struct hda_spdif_out *spdif =
1240 snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001241
1242 mutex_lock(&codec->spdif_mutex);
1243 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1244 if (chs == 2 &&
1245 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1246 format) &&
Stephen Warren7c935972011-06-01 11:14:17 -06001247 !(spdif->status & IEC958_AES0_NONAUDIO)) {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001248 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1249 /* turn off SPDIF once; otherwise the IEC958 bits won't
1250 * be updated */
Stephen Warren7c935972011-06-01 11:14:17 -06001251 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001252 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1253 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001254 spdif->ctls &
Harald Welte0aa62ae2008-09-09 15:58:27 +08001255 ~AC_DIG1_ENABLE & 0xff);
1256 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1257 stream_tag, 0, format);
1258 /* turn on again (if needed) */
Stephen Warren7c935972011-06-01 11:14:17 -06001259 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001260 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1261 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001262 spdif->ctls & 0xff);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001263 } else {
1264 mout->dig_out_used = 0;
1265 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1266 0, 0, 0);
1267 }
1268 }
1269 mutex_unlock(&codec->spdif_mutex);
1270
1271 /* front */
1272 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1273 0, format);
1274
Lydia Wangeb7188c2009-10-10 19:08:34 +08001275 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1276 && !spec->hp_independent_mode)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001277 /* headphone out will just decode front left/right (stereo) */
1278 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1279 0, format);
1280
1281 /* extra outputs copied from front */
1282 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1283 if (mout->extra_out_nid[i])
1284 snd_hda_codec_setup_stream(codec,
1285 mout->extra_out_nid[i],
1286 stream_tag, 0, format);
1287
1288 /* surrounds */
1289 for (i = 1; i < mout->num_dacs; i++) {
1290 if (chs >= (i + 1) * 2) /* independent out */
1291 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1292 i * 2, format);
1293 else /* copy front */
1294 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1295 0, format);
1296 }
1297}
1298
1299static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1300 struct hda_codec *codec,
1301 unsigned int stream_tag,
1302 unsigned int format,
1303 struct snd_pcm_substream *substream)
1304{
1305 struct via_spec *spec = codec->spec;
1306 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001307 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001308
1309 if (substream->number == 0)
1310 playback_multi_pcm_prep_0(codec, stream_tag, format,
1311 substream);
1312 else {
1313 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1314 spec->hp_independent_mode)
1315 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1316 stream_tag, 0, format);
1317 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001318 vt1708_start_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001319 return 0;
1320}
1321
1322static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1323 struct hda_codec *codec,
1324 struct snd_pcm_substream *substream)
1325{
1326 struct via_spec *spec = codec->spec;
1327 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001328 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001329 int i;
1330
1331 if (substream->number == 0) {
1332 for (i = 0; i < mout->num_dacs; i++)
1333 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1334
1335 if (mout->hp_nid && !spec->hp_independent_mode)
1336 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1337 0, 0, 0);
1338
1339 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1340 if (mout->extra_out_nid[i])
1341 snd_hda_codec_setup_stream(codec,
1342 mout->extra_out_nid[i],
1343 0, 0, 0);
1344 mutex_lock(&codec->spdif_mutex);
1345 if (mout->dig_out_nid &&
1346 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1347 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1348 0, 0, 0);
1349 mout->dig_out_used = 0;
1350 }
1351 mutex_unlock(&codec->spdif_mutex);
1352 } else {
1353 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1354 spec->hp_independent_mode)
1355 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1356 0, 0, 0);
1357 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001358 vt1708_stop_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001359 return 0;
1360}
1361
Joseph Chanc577b8a2006-11-29 15:29:40 +01001362/*
1363 * Digital out
1364 */
1365static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1366 struct hda_codec *codec,
1367 struct snd_pcm_substream *substream)
1368{
1369 struct via_spec *spec = codec->spec;
1370 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1371}
1372
1373static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1374 struct hda_codec *codec,
1375 struct snd_pcm_substream *substream)
1376{
1377 struct via_spec *spec = codec->spec;
1378 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1379}
1380
Harald Welte5691ec72008-09-15 22:42:26 +08001381static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001382 struct hda_codec *codec,
1383 unsigned int stream_tag,
1384 unsigned int format,
1385 struct snd_pcm_substream *substream)
1386{
1387 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001388 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1389 stream_tag, format, substream);
1390}
Harald Welte5691ec72008-09-15 22:42:26 +08001391
Takashi Iwai9da29272009-05-07 16:31:14 +02001392static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1393 struct hda_codec *codec,
1394 struct snd_pcm_substream *substream)
1395{
1396 struct via_spec *spec = codec->spec;
1397 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001398 return 0;
1399}
1400
Joseph Chanc577b8a2006-11-29 15:29:40 +01001401/*
1402 * Analog capture
1403 */
1404static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1405 struct hda_codec *codec,
1406 unsigned int stream_tag,
1407 unsigned int format,
1408 struct snd_pcm_substream *substream)
1409{
1410 struct via_spec *spec = codec->spec;
1411
1412 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1413 stream_tag, 0, format);
1414 return 0;
1415}
1416
1417static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1418 struct hda_codec *codec,
1419 struct snd_pcm_substream *substream)
1420{
1421 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001422 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001423 return 0;
1424}
1425
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001426static const struct hda_pcm_stream vt1708_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001427 .substreams = 2,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001428 .channels_min = 2,
1429 .channels_max = 8,
1430 .nid = 0x10, /* NID to query formats and rates */
1431 .ops = {
1432 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001433 .prepare = via_playback_multi_pcm_prepare,
1434 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001435 },
1436};
1437
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001438static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Lydia Wangc873cc22009-10-10 19:08:21 +08001439 .substreams = 2,
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001440 .channels_min = 2,
1441 .channels_max = 8,
1442 .nid = 0x10, /* NID to query formats and rates */
1443 /* We got noisy outputs on the right channel on VT1708 when
1444 * 24bit samples are used. Until any workaround is found,
1445 * disable the 24bit format, so far.
1446 */
1447 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1448 .ops = {
1449 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08001450 .prepare = via_playback_multi_pcm_prepare,
1451 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001452 },
1453};
1454
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001455static const struct hda_pcm_stream vt1708_pcm_analog_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001456 .substreams = 2,
1457 .channels_min = 2,
1458 .channels_max = 2,
1459 .nid = 0x15, /* NID to query formats and rates */
1460 .ops = {
1461 .prepare = via_capture_pcm_prepare,
1462 .cleanup = via_capture_pcm_cleanup
1463 },
1464};
1465
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001466static const struct hda_pcm_stream vt1708_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001467 .substreams = 1,
1468 .channels_min = 2,
1469 .channels_max = 2,
1470 /* NID is set in via_build_pcms */
1471 .ops = {
1472 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001473 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001474 .prepare = via_dig_playback_pcm_prepare,
1475 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001476 },
1477};
1478
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001479static const struct hda_pcm_stream vt1708_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001480 .substreams = 1,
1481 .channels_min = 2,
1482 .channels_max = 2,
1483};
1484
1485static int via_build_controls(struct hda_codec *codec)
1486{
1487 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001488 struct snd_kcontrol *kctl;
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001489 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001490 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001491
Takashi Iwai24088a52011-06-17 16:59:21 +02001492 if (spec->set_widgets_power_state)
1493 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1494 return -ENOMEM;
1495
Joseph Chanc577b8a2006-11-29 15:29:40 +01001496 for (i = 0; i < spec->num_mixers; i++) {
1497 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1498 if (err < 0)
1499 return err;
1500 }
1501
1502 if (spec->multiout.dig_out_nid) {
1503 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001504 spec->multiout.dig_out_nid,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001505 spec->multiout.dig_out_nid);
1506 if (err < 0)
1507 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001508 err = snd_hda_create_spdif_share_sw(codec,
1509 &spec->multiout);
1510 if (err < 0)
1511 return err;
1512 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001513 }
1514 if (spec->dig_in_nid) {
1515 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1516 if (err < 0)
1517 return err;
1518 }
Lydia Wang17314372009-10-10 19:07:37 +08001519
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001520 /* assign Capture Source enums to NID */
1521 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1522 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +01001523 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001524 if (err < 0)
1525 return err;
1526 }
1527
1528 /* other nid->control mapping */
1529 for (i = 0; i < spec->num_mixers; i++) {
1530 for (knew = spec->mixers[i]; knew->name; knew++) {
1531 if (knew->iface != NID_MAPPING)
1532 continue;
1533 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1534 if (kctl == NULL)
1535 continue;
1536 err = snd_hda_add_nid(codec, kctl, 0,
1537 knew->subdevice);
1538 }
1539 }
1540
Lydia Wang17314372009-10-10 19:07:37 +08001541 /* init power states */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001542 set_widgets_power_state(codec);
Lydia Wang17314372009-10-10 19:07:37 +08001543 analog_low_current_mode(codec, 1);
1544
Takashi Iwai603c4012008-07-30 15:01:44 +02001545 via_free_kctls(codec); /* no longer needed */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001546 return 0;
1547}
1548
1549static int via_build_pcms(struct hda_codec *codec)
1550{
1551 struct via_spec *spec = codec->spec;
1552 struct hda_pcm *info = spec->pcm_rec;
1553
1554 codec->num_pcms = 1;
1555 codec->pcm_info = info;
1556
1557 info->name = spec->stream_name_analog;
Lydia Wang377ff312009-10-10 19:08:55 +08001558 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1559 *(spec->stream_analog_playback);
1560 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1561 spec->multiout.dac_nids[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001562 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1563 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1564
1565 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1566 spec->multiout.max_channels;
1567
1568 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1569 codec->num_pcms++;
1570 info++;
1571 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001572 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001573 if (spec->multiout.dig_out_nid) {
1574 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1575 *(spec->stream_digital_playback);
1576 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1577 spec->multiout.dig_out_nid;
1578 }
1579 if (spec->dig_in_nid) {
1580 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1581 *(spec->stream_digital_capture);
1582 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1583 spec->dig_in_nid;
1584 }
1585 }
1586
1587 return 0;
1588}
1589
1590static void via_free(struct hda_codec *codec)
1591{
1592 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001593
1594 if (!spec)
1595 return;
1596
Takashi Iwai603c4012008-07-30 15:01:44 +02001597 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001598 vt1708_stop_hp_work(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001599 kfree(codec->spec);
1600}
1601
Harald Welte69e52a82008-09-09 15:57:32 +08001602/* mute internal speaker if HP is plugged */
1603static void via_hp_automute(struct hda_codec *codec)
1604{
Lydia Wangdcf34c82009-10-10 19:08:15 +08001605 unsigned int present = 0;
Harald Welte69e52a82008-09-09 15:57:32 +08001606 struct via_spec *spec = codec->spec;
1607
Takashi Iwaid56757a2009-11-18 08:00:14 +01001608 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangdcf34c82009-10-10 19:08:15 +08001609
1610 if (!spec->hp_independent_mode) {
1611 struct snd_ctl_elem_id id;
1612 /* auto mute */
1613 snd_hda_codec_amp_stereo(
1614 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1615 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1616 /* notify change */
1617 memset(&id, 0, sizeof(id));
1618 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1619 strcpy(id.name, "Front Playback Switch");
1620 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1621 &id);
1622 }
Harald Welte69e52a82008-09-09 15:57:32 +08001623}
1624
Lydia Wangf3db4232009-10-10 19:08:41 +08001625/* mute mono out if HP or Line out is plugged */
1626static void via_mono_automute(struct hda_codec *codec)
1627{
1628 unsigned int hp_present, lineout_present;
1629 struct via_spec *spec = codec->spec;
1630
1631 if (spec->codec_type != VT1716S)
1632 return;
1633
Takashi Iwaid56757a2009-11-18 08:00:14 +01001634 lineout_present = snd_hda_jack_detect(codec,
1635 spec->autocfg.line_out_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001636
1637 /* Mute Mono Out if Line Out is plugged */
1638 if (lineout_present) {
1639 snd_hda_codec_amp_stereo(
1640 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1641 return;
1642 }
1643
Takashi Iwaid56757a2009-11-18 08:00:14 +01001644 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001645
1646 if (!spec->hp_independent_mode)
1647 snd_hda_codec_amp_stereo(
1648 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1649 hp_present ? HDA_AMP_MUTE : 0);
1650}
1651
Harald Welte69e52a82008-09-09 15:57:32 +08001652static void via_gpio_control(struct hda_codec *codec)
1653{
1654 unsigned int gpio_data;
1655 unsigned int vol_counter;
1656 unsigned int vol;
1657 unsigned int master_vol;
1658
1659 struct via_spec *spec = codec->spec;
1660
1661 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1662 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1663
1664 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1665 0xF84, 0) & 0x3F0000) >> 16;
1666
1667 vol = vol_counter & 0x1F;
1668 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1669 AC_VERB_GET_AMP_GAIN_MUTE,
1670 AC_AMP_GET_INPUT);
1671
1672 if (gpio_data == 0x02) {
1673 /* unmute line out */
1674 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1675 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1676
1677 if (vol_counter & 0x20) {
1678 /* decrease volume */
1679 if (vol > master_vol)
1680 vol = master_vol;
1681 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1682 0, HDA_AMP_VOLMASK,
1683 master_vol-vol);
1684 } else {
1685 /* increase volume */
1686 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1687 HDA_AMP_VOLMASK,
1688 ((master_vol+vol) > 0x2A) ? 0x2A :
1689 (master_vol+vol));
1690 }
1691 } else if (!(gpio_data & 0x02)) {
1692 /* mute line out */
1693 snd_hda_codec_amp_stereo(codec,
1694 spec->autocfg.line_out_pins[0],
1695 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1696 HDA_AMP_MUTE);
1697 }
1698}
1699
Lydia Wang25eaba22009-10-10 19:08:43 +08001700/* mute Internal-Speaker if HP is plugged */
1701static void via_speaker_automute(struct hda_codec *codec)
1702{
1703 unsigned int hp_present;
1704 struct via_spec *spec = codec->spec;
1705
Lydia Wang27439ce2011-03-24 12:40:10 +08001706 if (!VT2002P_COMPATIBLE(spec))
Lydia Wang25eaba22009-10-10 19:08:43 +08001707 return;
1708
Takashi Iwaid56757a2009-11-18 08:00:14 +01001709 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001710
1711 if (!spec->hp_independent_mode) {
1712 struct snd_ctl_elem_id id;
1713 snd_hda_codec_amp_stereo(
1714 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
1715 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1716 /* notify change */
1717 memset(&id, 0, sizeof(id));
1718 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1719 strcpy(id.name, "Speaker Playback Switch");
1720 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1721 &id);
1722 }
1723}
1724
1725/* mute line-out and internal speaker if HP is plugged */
1726static void via_hp_bind_automute(struct hda_codec *codec)
1727{
akpm@linux-foundation.org01a17962009-11-13 16:47:10 -08001728 /* use long instead of int below just to avoid an internal compiler
1729 * error with gcc 4.0.x
1730 */
1731 unsigned long hp_present, present = 0;
Lydia Wang25eaba22009-10-10 19:08:43 +08001732 struct via_spec *spec = codec->spec;
1733 int i;
1734
1735 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1736 return;
1737
Takashi Iwaid56757a2009-11-18 08:00:14 +01001738 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001739
Takashi Iwaid56757a2009-11-18 08:00:14 +01001740 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001741
1742 if (!spec->hp_independent_mode) {
1743 /* Mute Line-Outs */
1744 for (i = 0; i < spec->autocfg.line_outs; i++)
1745 snd_hda_codec_amp_stereo(
1746 codec, spec->autocfg.line_out_pins[i],
1747 HDA_OUTPUT, 0,
1748 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1749 if (hp_present)
1750 present = hp_present;
1751 }
1752 /* Speakers */
1753 for (i = 0; i < spec->autocfg.speaker_outs; i++)
1754 snd_hda_codec_amp_stereo(
1755 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
1756 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1757}
1758
1759
Harald Welte69e52a82008-09-09 15:57:32 +08001760/* unsolicited event for jack sensing */
1761static void via_unsol_event(struct hda_codec *codec,
1762 unsigned int res)
1763{
1764 res >>= 26;
Lydia Wangec7e7e42011-03-24 12:43:44 +08001765
Lydia Wanga34df192009-10-10 19:08:01 +08001766 if (res & VIA_JACK_EVENT)
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001767 set_widgets_power_state(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001768
1769 res &= ~VIA_JACK_EVENT;
1770
1771 if (res == VIA_HP_EVENT)
1772 via_hp_automute(codec);
1773 else if (res == VIA_GPIO_EVENT)
1774 via_gpio_control(codec);
1775 else if (res == VIA_MONO_EVENT)
Lydia Wangf3db4232009-10-10 19:08:41 +08001776 via_mono_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001777 else if (res == VIA_SPEAKER_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001778 via_speaker_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001779 else if (res == VIA_BIND_HP_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001780 via_hp_bind_automute(codec);
Harald Welte69e52a82008-09-09 15:57:32 +08001781}
1782
Joseph Chanc577b8a2006-11-29 15:29:40 +01001783static int via_init(struct hda_codec *codec)
1784{
1785 struct via_spec *spec = codec->spec;
Harald Welte69e52a82008-09-09 15:57:32 +08001786 int i;
1787 for (i = 0; i < spec->num_iverbs; i++)
1788 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1789
Josepch Chanf7278fd2007-12-13 16:40:40 +01001790 /* Lydia Add for EAPD enable */
1791 if (!spec->dig_in_nid) { /* No Digital In connection */
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001792 if (spec->dig_in_pin) {
1793 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001794 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +01001795 PIN_OUT);
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001796 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001797 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1798 }
Takashi Iwai12b74c82008-01-15 12:39:38 +01001799 } else /* enable SPDIF-input pin */
1800 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1801 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
Josepch Chanf7278fd2007-12-13 16:40:40 +01001802
Takashi Iwai9da29272009-05-07 16:31:14 +02001803 /* assign slave outs */
1804 if (spec->slave_dig_outs[0])
1805 codec->slave_dig_outs = spec->slave_dig_outs;
Harald Welte5691ec72008-09-15 22:42:26 +08001806
Lydia Wang377ff312009-10-10 19:08:55 +08001807 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001808}
1809
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001810#ifdef SND_HDA_NEEDS_RESUME
1811static int via_suspend(struct hda_codec *codec, pm_message_t state)
1812{
1813 struct via_spec *spec = codec->spec;
1814 vt1708_stop_hp_work(spec);
1815 return 0;
1816}
1817#endif
1818
Takashi Iwaicb53c622007-08-10 17:21:45 +02001819#ifdef CONFIG_SND_HDA_POWER_SAVE
1820static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1821{
1822 struct via_spec *spec = codec->spec;
1823 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1824}
1825#endif
1826
Joseph Chanc577b8a2006-11-29 15:29:40 +01001827/*
1828 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001829static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001830 .build_controls = via_build_controls,
1831 .build_pcms = via_build_pcms,
1832 .init = via_init,
1833 .free = via_free,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001834#ifdef SND_HDA_NEEDS_RESUME
1835 .suspend = via_suspend,
1836#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02001837#ifdef CONFIG_SND_HDA_POWER_SAVE
1838 .check_power_status = via_check_power_status,
1839#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001840};
1841
1842/* fill in the dac_nids table from the parsed pin configuration */
1843static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1844 const struct auto_pin_cfg *cfg)
1845{
1846 int i;
1847 hda_nid_t nid;
1848
1849 spec->multiout.num_dacs = cfg->line_outs;
1850
1851 spec->multiout.dac_nids = spec->private_dac_nids;
Lydia Wang377ff312009-10-10 19:08:55 +08001852
1853 for (i = 0; i < 4; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001854 nid = cfg->line_out_pins[i];
1855 if (nid) {
1856 /* config dac list */
1857 switch (i) {
1858 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02001859 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001860 break;
1861 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02001862 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001863 break;
1864 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02001865 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001866 break;
1867 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02001868 spec->private_dac_nids[i] = 0x13;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001869 break;
1870 }
1871 }
1872 }
1873
1874 return 0;
1875}
1876
1877/* add playback controls from the parsed DAC table */
1878static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1879 const struct auto_pin_cfg *cfg)
1880{
1881 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01001882 static const char * const chname[4] = {
1883 "Front", "Surround", "C/LFE", "Side"
1884 };
Lydia Wang9645c202009-10-10 19:08:27 +08001885 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
Joseph Chanc577b8a2006-11-29 15:29:40 +01001886 int i, err;
1887
1888 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1889 nid = cfg->line_out_pins[i];
1890
1891 if (!nid)
1892 continue;
Lydia Wang377ff312009-10-10 19:08:55 +08001893
Lydia Wang9645c202009-10-10 19:08:27 +08001894 nid_vol = nid_vols[i];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001895
1896 if (i == AUTO_SEQ_CENLFE) {
1897 /* Center/LFE */
1898 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001899 "Center Playback Volume",
1900 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1901 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001902 if (err < 0)
1903 return err;
1904 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1905 "LFE Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001906 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1907 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001908 if (err < 0)
1909 return err;
1910 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1911 "Center Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001912 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1913 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001914 if (err < 0)
1915 return err;
1916 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1917 "LFE Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001918 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1919 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001920 if (err < 0)
1921 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08001922 } else if (i == AUTO_SEQ_FRONT) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001923 /* add control to mixer index 0 */
1924 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1925 "Master Front Playback Volume",
Lydia Wang9645c202009-10-10 19:08:27 +08001926 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001927 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001928 if (err < 0)
1929 return err;
1930 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1931 "Master Front Playback Switch",
Lydia Wang9645c202009-10-10 19:08:27 +08001932 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001933 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001934 if (err < 0)
1935 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08001936
Joseph Chanc577b8a2006-11-29 15:29:40 +01001937 /* add control to PW3 */
1938 sprintf(name, "%s Playback Volume", chname[i]);
1939 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001940 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1941 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001942 if (err < 0)
1943 return err;
1944 sprintf(name, "%s Playback Switch", chname[i]);
1945 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001946 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1947 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001948 if (err < 0)
1949 return err;
1950 } else {
1951 sprintf(name, "%s Playback Volume", chname[i]);
1952 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001953 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1954 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001955 if (err < 0)
1956 return err;
1957 sprintf(name, "%s Playback Switch", chname[i]);
1958 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001959 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1960 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001961 if (err < 0)
1962 return err;
1963 }
1964 }
1965
1966 return 0;
1967}
1968
Harald Welte0aa62ae2008-09-09 15:58:27 +08001969static void create_hp_imux(struct via_spec *spec)
1970{
1971 int i;
1972 struct hda_input_mux *imux = &spec->private_imux[1];
Takashi Iwaiea734962011-01-17 11:29:34 +01001973 static const char * const texts[] = { "OFF", "ON", NULL};
Harald Welte0aa62ae2008-09-09 15:58:27 +08001974
1975 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02001976 for (i = 0; texts[i]; i++)
1977 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001978
1979 spec->hp_mux = &spec->private_imux[1];
1980}
1981
Joseph Chanc577b8a2006-11-29 15:29:40 +01001982static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1983{
1984 int err;
1985
1986 if (!pin)
1987 return 0;
1988
1989 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08001990 spec->hp_independent_mode_index = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001991
1992 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1993 "Headphone Playback Volume",
1994 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1995 if (err < 0)
1996 return err;
1997 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1998 "Headphone Playback Switch",
1999 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2000 if (err < 0)
2001 return err;
2002
Harald Welte0aa62ae2008-09-09 15:58:27 +08002003 create_hp_imux(spec);
2004
Joseph Chanc577b8a2006-11-29 15:29:40 +01002005 return 0;
2006}
2007
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002008static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
2009 hda_nid_t nid)
2010{
2011 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
2012 int i, nums;
2013
2014 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
2015 for (i = 0; i < nums; i++)
2016 if (conn[i] == nid)
2017 return i;
2018 return -1;
2019}
2020
2021/* look for ADCs */
2022static int via_fill_adcs(struct hda_codec *codec)
2023{
2024 struct via_spec *spec = codec->spec;
2025 hda_nid_t nid = codec->start_nid;
2026 int i;
2027
2028 for (i = 0; i < codec->num_nodes; i++, nid++) {
2029 unsigned int wcaps = get_wcaps(codec, nid);
2030 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2031 continue;
2032 if (wcaps & AC_WCAP_DIGITAL)
2033 continue;
2034 if (!(wcaps & AC_WCAP_CONN_LIST))
2035 continue;
2036 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2037 return -ENOMEM;
2038 spec->adc_nids[spec->num_adc_nids++] = nid;
2039 }
2040 return 0;
2041}
2042
2043static int get_mux_nids(struct hda_codec *codec);
2044
Joseph Chanc577b8a2006-11-29 15:29:40 +01002045/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002046static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaif3268512010-08-30 11:00:19 +02002047 const struct auto_pin_cfg *cfg,
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002048 hda_nid_t mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002049{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002050 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08002051 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002052 int i, err, idx, idx2, type, type_idx = 0;
2053 hda_nid_t cap_nid;
2054 hda_nid_t pin_idxs[8];
2055 int num_idxs;
2056
2057 err = via_fill_adcs(codec);
2058 if (err < 0)
2059 return err;
2060 err = get_mux_nids(codec);
2061 if (err < 0)
2062 return err;
2063 cap_nid = spec->mux_nids[0];
2064
2065 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
2066 ARRAY_SIZE(pin_idxs));
2067 if (num_idxs <= 0)
2068 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002069
2070 /* for internal loopback recording select */
Takashi Iwaif3268512010-08-30 11:00:19 +02002071 for (idx = 0; idx < num_idxs; idx++) {
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002072 if (pin_idxs[idx] == mix_nid) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002073 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
Takashi Iwaif3268512010-08-30 11:00:19 +02002074 break;
2075 }
2076 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002077
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002078 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002079 const char *label;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002080 type = cfg->inputs[i].type;
Takashi Iwaif3268512010-08-30 11:00:19 +02002081 for (idx = 0; idx < num_idxs; idx++)
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002082 if (pin_idxs[idx] == cfg->inputs[i].pin)
Takashi Iwaif3268512010-08-30 11:00:19 +02002083 break;
2084 if (idx >= num_idxs)
2085 continue;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002086 if (i > 0 && type == cfg->inputs[i - 1].type)
2087 type_idx++;
2088 else
2089 type_idx = 0;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002090 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002091 idx2 = get_connection_index(codec, mix_nid, pin_idxs[idx]);
2092 if (idx2 >= 0)
Lydia Wang16922282011-03-22 16:24:10 +08002093 err = via_new_analog_input(spec, label, type_idx,
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002094 idx2, mix_nid);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002095 if (err < 0)
2096 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002097 snd_hda_add_imux_item(imux, label, idx, NULL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002098 }
2099 return 0;
2100}
2101
Takashi Iwaif3268512010-08-30 11:00:19 +02002102/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002103static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaif3268512010-08-30 11:00:19 +02002104 const struct auto_pin_cfg *cfg)
2105{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002106 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17);
Takashi Iwaif3268512010-08-30 11:00:19 +02002107}
2108
Takashi Iwaicb53c622007-08-10 17:21:45 +02002109#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002110static const struct hda_amp_list vt1708_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002111 { 0x17, HDA_INPUT, 1 },
2112 { 0x17, HDA_INPUT, 2 },
2113 { 0x17, HDA_INPUT, 3 },
2114 { 0x17, HDA_INPUT, 4 },
2115 { } /* end */
2116};
2117#endif
2118
Harald Welte76d9b0d2008-09-09 15:50:37 +08002119static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2120{
2121 unsigned int def_conf;
2122 unsigned char seqassoc;
2123
Takashi Iwai2f334f92009-02-20 14:37:42 +01002124 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002125 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2126 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002127 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2128 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2129 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2130 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002131 }
2132
2133 return;
2134}
2135
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002136static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002137 struct snd_ctl_elem_value *ucontrol)
2138{
2139 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2140 struct via_spec *spec = codec->spec;
2141
2142 if (spec->codec_type != VT1708)
2143 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002144 spec->vt1708_jack_detect =
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002145 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002146 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002147 return 0;
2148}
2149
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002150static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002151 struct snd_ctl_elem_value *ucontrol)
2152{
2153 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2154 struct via_spec *spec = codec->spec;
2155 int change;
2156
2157 if (spec->codec_type != VT1708)
2158 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002159 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002160 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002161 == !spec->vt1708_jack_detect;
2162 if (spec->vt1708_jack_detect) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002163 mute_aa_path(codec, 1);
2164 notify_aa_path_ctls(codec);
2165 }
2166 return change;
2167}
2168
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002169static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2170 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2171 .name = "Jack Detect",
2172 .count = 1,
2173 .info = snd_ctl_boolean_mono_info,
2174 .get = vt1708_jack_detect_get,
2175 .put = vt1708_jack_detect_put,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002176};
2177
Joseph Chanc577b8a2006-11-29 15:29:40 +01002178static int vt1708_parse_auto_config(struct hda_codec *codec)
2179{
2180 struct via_spec *spec = codec->spec;
2181 int err;
2182
Harald Welte76d9b0d2008-09-09 15:50:37 +08002183 /* Add HP and CD pin config connect bit re-config action */
2184 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2185 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2186
Joseph Chanc577b8a2006-11-29 15:29:40 +01002187 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2188 if (err < 0)
2189 return err;
2190 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2191 if (err < 0)
2192 return err;
2193 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2194 return 0; /* can't find valid BIOS pin config */
2195
2196 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2197 if (err < 0)
2198 return err;
2199 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2200 if (err < 0)
2201 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002202 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002203 if (err < 0)
2204 return err;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002205 /* add jack detect on/off control */
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002206 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2207 return -ENOMEM;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002208
2209 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2210
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002211 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002212 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002213 spec->dig_in_pin = VT1708_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002214 if (spec->autocfg.dig_in_pin)
2215 spec->dig_in_nid = VT1708_DIGIN_NID;
2216
Takashi Iwai603c4012008-07-30 15:01:44 +02002217 if (spec->kctls.list)
2218 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002219
Harald Welte69e52a82008-09-09 15:57:32 +08002220 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002221
Harald Welte0aa62ae2008-09-09 15:58:27 +08002222 spec->input_mux = &spec->private_imux[0];
2223
Harald Weltef8fdd492008-09-15 22:41:31 +08002224 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002225 via_hp_build(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002226
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002227 via_smart51_build(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002228 return 1;
2229}
2230
2231/* init callback for auto-configuration model -- overriding the default init */
2232static int via_auto_init(struct hda_codec *codec)
2233{
Lydia Wang25eaba22009-10-10 19:08:43 +08002234 struct via_spec *spec = codec->spec;
2235
Joseph Chanc577b8a2006-11-29 15:29:40 +01002236 via_init(codec);
2237 via_auto_init_multi_out(codec);
2238 via_auto_init_hp_out(codec);
2239 via_auto_init_analog_input(codec);
Lydia Wang118909562011-03-23 17:57:34 +08002240
2241 if (VT2002P_COMPATIBLE(spec)) {
Lydia Wang25eaba22009-10-10 19:08:43 +08002242 via_hp_bind_automute(codec);
2243 } else {
2244 via_hp_automute(codec);
2245 via_speaker_automute(codec);
2246 }
2247
Joseph Chanc577b8a2006-11-29 15:29:40 +01002248 return 0;
2249}
2250
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002251static void vt1708_update_hp_jack_state(struct work_struct *work)
2252{
2253 struct via_spec *spec = container_of(work, struct via_spec,
2254 vt1708_hp_work.work);
2255 if (spec->codec_type != VT1708)
2256 return;
2257 /* if jack state toggled */
2258 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002259 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002260 spec->vt1708_hp_present ^= 1;
2261 via_hp_automute(spec->codec);
2262 }
2263 vt1708_start_hp_work(spec);
2264}
2265
Takashi Iwai337b9d02009-07-07 18:18:59 +02002266static int get_mux_nids(struct hda_codec *codec)
2267{
2268 struct via_spec *spec = codec->spec;
2269 hda_nid_t nid, conn[8];
2270 unsigned int type;
2271 int i, n;
2272
2273 for (i = 0; i < spec->num_adc_nids; i++) {
2274 nid = spec->adc_nids[i];
2275 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002276 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002277 if (type == AC_WID_PIN)
2278 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002279 n = snd_hda_get_connections(codec, nid, conn,
2280 ARRAY_SIZE(conn));
2281 if (n <= 0)
2282 break;
2283 if (n > 1) {
2284 spec->mux_nids[i] = nid;
2285 break;
2286 }
2287 nid = conn[0];
2288 }
2289 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002290 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002291}
2292
Joseph Chanc577b8a2006-11-29 15:29:40 +01002293static int patch_vt1708(struct hda_codec *codec)
2294{
2295 struct via_spec *spec;
2296 int err;
2297
2298 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002299 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002300 if (spec == NULL)
2301 return -ENOMEM;
2302
Joseph Chanc577b8a2006-11-29 15:29:40 +01002303 /* automatic parse from the BIOS config */
2304 err = vt1708_parse_auto_config(codec);
2305 if (err < 0) {
2306 via_free(codec);
2307 return err;
2308 } else if (!err) {
2309 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2310 "from BIOS. Using genenic mode...\n");
2311 }
2312
Lydia Wang377ff312009-10-10 19:08:55 +08002313
Joseph Chanc577b8a2006-11-29 15:29:40 +01002314 spec->stream_name_analog = "VT1708 Analog";
2315 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
Takashi Iwaibc9b562382008-05-23 17:50:27 +02002316 /* disable 32bit format on VT1708 */
2317 if (codec->vendor_id == 0x11061708)
2318 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002319 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2320
2321 spec->stream_name_digital = "VT1708 Digital";
2322 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2323 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2324
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002325 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002326 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2327 spec->num_mixers++;
2328 }
2329
2330 codec->patch_ops = via_patch_ops;
2331
2332 codec->patch_ops.init = via_auto_init;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002333#ifdef CONFIG_SND_HDA_POWER_SAVE
2334 spec->loopback.amplist = vt1708_loopbacks;
2335#endif
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002336 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002337 return 0;
2338}
2339
2340/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002341static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002342 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2343 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2344 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2345 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2346 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2347 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2348 {
2349 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2350 /* The multiple "Capture Source" controls confuse alsamixer
2351 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01002352 */
2353 /* .name = "Capture Source", */
2354 .name = "Input Source",
2355 .count = 1,
2356 .info = via_mux_enum_info,
2357 .get = via_mux_enum_get,
2358 .put = via_mux_enum_put,
2359 },
2360 { } /* end */
2361};
2362
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002363static const struct hda_verb vt1709_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002364 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2365 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002366 { }
2367};
2368
Joseph Chanc577b8a2006-11-29 15:29:40 +01002369/*
2370 * generic initialization of ADC, input mixers and output mixers
2371 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002372static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002373 /*
2374 * Unmute ADC0-2 and set the default input to mic-in
2375 */
2376 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2377 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2378 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2379
2380
Josepch Chanf7278fd2007-12-13 16:40:40 +01002381 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01002382 * mixer widget
2383 */
2384 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01002385 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2386 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2387 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2388 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2389 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002390
2391 /*
2392 * Set up output selector (0x1a, 0x1b, 0x29)
2393 */
2394 /* set vol=0 to output mixers */
2395 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2396 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2397 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2398
2399 /*
2400 * Unmute PW3 and PW4
2401 */
2402 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2403 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2404
Lydia Wangbfdc6752009-10-10 19:08:50 +08002405 /* Set input of PW4 as MW0 */
2406 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002407 /* PW9 Output enable */
2408 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2409 { }
2410};
2411
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002412static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002413 .substreams = 1,
2414 .channels_min = 2,
2415 .channels_max = 10,
2416 .nid = 0x10, /* NID to query formats and rates */
2417 .ops = {
2418 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002419 .prepare = via_playback_multi_pcm_prepare,
2420 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002421 },
2422};
2423
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002424static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002425 .substreams = 1,
2426 .channels_min = 2,
2427 .channels_max = 6,
2428 .nid = 0x10, /* NID to query formats and rates */
2429 .ops = {
2430 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002431 .prepare = via_playback_multi_pcm_prepare,
2432 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002433 },
2434};
2435
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002436static const struct hda_pcm_stream vt1709_pcm_analog_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002437 .substreams = 2,
2438 .channels_min = 2,
2439 .channels_max = 2,
2440 .nid = 0x14, /* NID to query formats and rates */
2441 .ops = {
2442 .prepare = via_capture_pcm_prepare,
2443 .cleanup = via_capture_pcm_cleanup
2444 },
2445};
2446
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002447static const struct hda_pcm_stream vt1709_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002448 .substreams = 1,
2449 .channels_min = 2,
2450 .channels_max = 2,
2451 /* NID is set in via_build_pcms */
2452 .ops = {
2453 .open = via_dig_playback_pcm_open,
2454 .close = via_dig_playback_pcm_close
2455 },
2456};
2457
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002458static const struct hda_pcm_stream vt1709_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002459 .substreams = 1,
2460 .channels_min = 2,
2461 .channels_max = 2,
2462};
2463
2464static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2465 const struct auto_pin_cfg *cfg)
2466{
2467 int i;
2468 hda_nid_t nid;
2469
2470 if (cfg->line_outs == 4) /* 10 channels */
2471 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2472 else if (cfg->line_outs == 3) /* 6 channels */
2473 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2474
2475 spec->multiout.dac_nids = spec->private_dac_nids;
2476
2477 if (cfg->line_outs == 4) { /* 10 channels */
2478 for (i = 0; i < cfg->line_outs; i++) {
2479 nid = cfg->line_out_pins[i];
2480 if (nid) {
2481 /* config dac list */
2482 switch (i) {
2483 case AUTO_SEQ_FRONT:
2484 /* AOW0 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002485 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002486 break;
2487 case AUTO_SEQ_CENLFE:
2488 /* AOW2 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002489 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002490 break;
2491 case AUTO_SEQ_SURROUND:
2492 /* AOW3 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002493 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002494 break;
2495 case AUTO_SEQ_SIDE:
2496 /* AOW1 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002497 spec->private_dac_nids[i] = 0x27;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002498 break;
2499 default:
2500 break;
2501 }
2502 }
2503 }
Takashi Iwaidda14412011-05-02 11:29:30 +02002504 spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
Joseph Chanc577b8a2006-11-29 15:29:40 +01002505
2506 } else if (cfg->line_outs == 3) { /* 6 channels */
Lydia Wang377ff312009-10-10 19:08:55 +08002507 for (i = 0; i < cfg->line_outs; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002508 nid = cfg->line_out_pins[i];
2509 if (nid) {
2510 /* config dac list */
Lydia Wang377ff312009-10-10 19:08:55 +08002511 switch (i) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002512 case AUTO_SEQ_FRONT:
2513 /* AOW0 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002514 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002515 break;
2516 case AUTO_SEQ_CENLFE:
2517 /* AOW2 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002518 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002519 break;
2520 case AUTO_SEQ_SURROUND:
2521 /* AOW1 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002522 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002523 break;
2524 default:
2525 break;
2526 }
2527 }
2528 }
2529 }
2530
2531 return 0;
2532}
2533
2534/* add playback controls from the parsed DAC table */
2535static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2536 const struct auto_pin_cfg *cfg)
2537{
2538 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01002539 static const char * const chname[4] = {
2540 "Front", "Surround", "C/LFE", "Side"
2541 };
Lydia Wang4483a2f2009-10-10 19:08:29 +08002542 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
Joseph Chanc577b8a2006-11-29 15:29:40 +01002543 int i, err;
2544
2545 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2546 nid = cfg->line_out_pins[i];
2547
Lydia Wang377ff312009-10-10 19:08:55 +08002548 if (!nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002549 continue;
2550
Lydia Wang4483a2f2009-10-10 19:08:29 +08002551 nid_vol = nid_vols[i];
2552
Joseph Chanc577b8a2006-11-29 15:29:40 +01002553 if (i == AUTO_SEQ_CENLFE) {
2554 /* Center/LFE */
2555 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2556 "Center Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002557 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002558 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002559 if (err < 0)
2560 return err;
2561 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2562 "LFE Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002563 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002564 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002565 if (err < 0)
2566 return err;
2567 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2568 "Center Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002569 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002570 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002571 if (err < 0)
2572 return err;
2573 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2574 "LFE Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002575 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002576 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002577 if (err < 0)
2578 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002579 } else if (i == AUTO_SEQ_FRONT) {
Lydia Wang4483a2f2009-10-10 19:08:29 +08002580 /* ADD control to mixer index 0 */
Joseph Chanc577b8a2006-11-29 15:29:40 +01002581 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2582 "Master Front Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002583 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002584 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002585 if (err < 0)
2586 return err;
2587 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2588 "Master Front Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002589 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002590 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002591 if (err < 0)
2592 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002593
Joseph Chanc577b8a2006-11-29 15:29:40 +01002594 /* add control to PW3 */
2595 sprintf(name, "%s Playback Volume", chname[i]);
2596 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002597 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2598 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002599 if (err < 0)
2600 return err;
2601 sprintf(name, "%s Playback Switch", chname[i]);
2602 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002603 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2604 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002605 if (err < 0)
2606 return err;
2607 } else if (i == AUTO_SEQ_SURROUND) {
2608 sprintf(name, "%s Playback Volume", chname[i]);
2609 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002610 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002611 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002612 if (err < 0)
2613 return err;
2614 sprintf(name, "%s Playback Switch", chname[i]);
2615 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002616 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002617 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002618 if (err < 0)
2619 return err;
2620 } else if (i == AUTO_SEQ_SIDE) {
2621 sprintf(name, "%s Playback Volume", chname[i]);
2622 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002623 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002624 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002625 if (err < 0)
2626 return err;
2627 sprintf(name, "%s Playback Switch", chname[i]);
2628 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002629 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002630 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002631 if (err < 0)
2632 return err;
2633 }
2634 }
2635
2636 return 0;
2637}
2638
2639static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2640{
2641 int err;
2642
2643 if (!pin)
2644 return 0;
2645
2646 if (spec->multiout.num_dacs == 5) /* 10 channels */
2647 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2648 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2649 spec->multiout.hp_nid = 0;
Lydia Wangcdc17842009-10-10 19:07:47 +08002650 spec->hp_independent_mode_index = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002651
2652 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2653 "Headphone Playback Volume",
2654 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2655 if (err < 0)
2656 return err;
2657 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2658 "Headphone Playback Switch",
2659 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2660 if (err < 0)
2661 return err;
2662
2663 return 0;
2664}
2665
2666/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002667static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002668 const struct auto_pin_cfg *cfg)
2669{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002670 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002671}
2672
2673static int vt1709_parse_auto_config(struct hda_codec *codec)
2674{
2675 struct via_spec *spec = codec->spec;
2676 int err;
2677
2678 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2679 if (err < 0)
2680 return err;
2681 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2682 if (err < 0)
2683 return err;
2684 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2685 return 0; /* can't find valid BIOS pin config */
2686
2687 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2688 if (err < 0)
2689 return err;
2690 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2691 if (err < 0)
2692 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002693 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002694 if (err < 0)
2695 return err;
2696
2697 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2698
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002699 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002700 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002701 spec->dig_in_pin = VT1709_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002702 if (spec->autocfg.dig_in_pin)
2703 spec->dig_in_nid = VT1709_DIGIN_NID;
2704
Takashi Iwai603c4012008-07-30 15:01:44 +02002705 if (spec->kctls.list)
2706 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002707
Harald Welte0aa62ae2008-09-09 15:58:27 +08002708 spec->input_mux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01002709
Harald Weltef8fdd492008-09-15 22:41:31 +08002710 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002711 via_hp_build(codec);
Harald Weltef8fdd492008-09-15 22:41:31 +08002712
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002713 via_smart51_build(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002714 return 1;
2715}
2716
Takashi Iwaicb53c622007-08-10 17:21:45 +02002717#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002718static const struct hda_amp_list vt1709_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002719 { 0x18, HDA_INPUT, 1 },
2720 { 0x18, HDA_INPUT, 2 },
2721 { 0x18, HDA_INPUT, 3 },
2722 { 0x18, HDA_INPUT, 4 },
2723 { } /* end */
2724};
2725#endif
2726
Joseph Chanc577b8a2006-11-29 15:29:40 +01002727static int patch_vt1709_10ch(struct hda_codec *codec)
2728{
2729 struct via_spec *spec;
2730 int err;
2731
2732 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002733 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002734 if (spec == NULL)
2735 return -ENOMEM;
2736
Joseph Chanc577b8a2006-11-29 15:29:40 +01002737 err = vt1709_parse_auto_config(codec);
2738 if (err < 0) {
2739 via_free(codec);
2740 return err;
2741 } else if (!err) {
2742 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2743 "Using genenic mode...\n");
2744 }
2745
Harald Welte69e52a82008-09-09 15:57:32 +08002746 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2747 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002748
2749 spec->stream_name_analog = "VT1709 Analog";
2750 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2751 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2752
2753 spec->stream_name_digital = "VT1709 Digital";
2754 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2755 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2756
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002757 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002758 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2759 spec->num_mixers++;
2760 }
2761
2762 codec->patch_ops = via_patch_ops;
2763
2764 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002765 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002766#ifdef CONFIG_SND_HDA_POWER_SAVE
2767 spec->loopback.amplist = vt1709_loopbacks;
2768#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002769
2770 return 0;
2771}
2772/*
2773 * generic initialization of ADC, input mixers and output mixers
2774 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002775static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002776 /*
2777 * Unmute ADC0-2 and set the default input to mic-in
2778 */
2779 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2780 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2781 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2782
2783
2784 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2785 * mixer widget
2786 */
2787 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2788 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2789 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2790 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2791 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2792 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2793
2794 /*
2795 * Set up output selector (0x1a, 0x1b, 0x29)
2796 */
2797 /* set vol=0 to output mixers */
2798 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2799 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2800 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2801
2802 /*
2803 * Unmute PW3 and PW4
2804 */
2805 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2806 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2807
2808 /* Set input of PW4 as MW0 */
2809 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002810 /* PW9 Output enable */
2811 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2812 { }
2813};
2814
2815static int patch_vt1709_6ch(struct hda_codec *codec)
2816{
2817 struct via_spec *spec;
2818 int err;
2819
2820 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002821 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002822 if (spec == NULL)
2823 return -ENOMEM;
2824
Joseph Chanc577b8a2006-11-29 15:29:40 +01002825 err = vt1709_parse_auto_config(codec);
2826 if (err < 0) {
2827 via_free(codec);
2828 return err;
2829 } else if (!err) {
2830 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2831 "Using genenic mode...\n");
2832 }
2833
Harald Welte69e52a82008-09-09 15:57:32 +08002834 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2835 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002836
2837 spec->stream_name_analog = "VT1709 Analog";
2838 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2839 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2840
2841 spec->stream_name_digital = "VT1709 Digital";
2842 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2843 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2844
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002845 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002846 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2847 spec->num_mixers++;
2848 }
2849
2850 codec->patch_ops = via_patch_ops;
2851
2852 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002853 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002854#ifdef CONFIG_SND_HDA_POWER_SAVE
2855 spec->loopback.amplist = vt1709_loopbacks;
2856#endif
Josepch Chanf7278fd2007-12-13 16:40:40 +01002857 return 0;
2858}
2859
2860/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002861static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002862 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2863 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2864 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2865 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2866 {
2867 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2868 /* The multiple "Capture Source" controls confuse alsamixer
2869 * So call somewhat different..
Josepch Chanf7278fd2007-12-13 16:40:40 +01002870 */
2871 /* .name = "Capture Source", */
2872 .name = "Input Source",
2873 .count = 1,
2874 .info = via_mux_enum_info,
2875 .get = via_mux_enum_get,
2876 .put = via_mux_enum_put,
2877 },
2878 { } /* end */
2879};
2880/*
2881 * generic initialization of ADC, input mixers and output mixers
2882 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002883static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002884 /*
2885 * Unmute ADC0-1 and set the default input to mic-in
2886 */
2887 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2888 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2889
2890
2891 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2892 * mixer widget
2893 */
2894 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2895 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2896 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2897 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2898 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2899 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2900
2901 /*
2902 * Set up output mixers
2903 */
2904 /* set vol=0 to output mixers */
2905 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2906 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2907 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2908
2909 /* Setup default input to PW4 */
Lydia Wangbfdc6752009-10-10 19:08:50 +08002910 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
Josepch Chanf7278fd2007-12-13 16:40:40 +01002911 /* PW9 Output enable */
2912 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2913 /* PW10 Input enable */
2914 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2915 { }
2916};
2917
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002918static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002919 /*
2920 * Unmute ADC0-1 and set the default input to mic-in
2921 */
2922 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2923 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2924
2925
2926 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2927 * mixer widget
2928 */
2929 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2930 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2931 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2932 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2933 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2934 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2935
2936 /*
2937 * Set up output mixers
2938 */
2939 /* set vol=0 to output mixers */
2940 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2941 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2942 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2943
2944 /* Setup default input of PW4 to MW0 */
2945 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2946 /* PW9 Output enable */
2947 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2948 /* PW10 Input enable */
2949 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2950 { }
2951};
2952
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002953static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002954 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2955 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2956 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2957 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2958 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2959 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2960 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2961 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2962 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002963 { }
2964};
2965
Lydia Wang17314372009-10-10 19:07:37 +08002966static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2967 struct hda_codec *codec,
2968 struct snd_pcm_substream *substream)
2969{
2970 int idle = substream->pstr->substream_opened == 1
2971 && substream->ref_count == 0;
2972
2973 analog_low_current_mode(codec, idle);
2974 return 0;
2975}
2976
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002977static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002978 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002979 .channels_min = 2,
2980 .channels_max = 8,
2981 .nid = 0x10, /* NID to query formats and rates */
2982 .ops = {
2983 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002984 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08002985 .cleanup = via_playback_multi_pcm_cleanup,
2986 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01002987 },
2988};
2989
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002990static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002991 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002992 .channels_min = 2,
2993 .channels_max = 4,
2994 .nid = 0x10, /* NID to query formats and rates */
2995 .ops = {
2996 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002997 .prepare = via_playback_multi_pcm_prepare,
2998 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002999 },
3000};
3001
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003002static const struct hda_pcm_stream vt1708B_pcm_analog_capture = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003003 .substreams = 2,
3004 .channels_min = 2,
3005 .channels_max = 2,
3006 .nid = 0x13, /* NID to query formats and rates */
3007 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003008 .open = via_pcm_open_close,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003009 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003010 .cleanup = via_capture_pcm_cleanup,
3011 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01003012 },
3013};
3014
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003015static const struct hda_pcm_stream vt1708B_pcm_digital_playback = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003016 .substreams = 1,
3017 .channels_min = 2,
3018 .channels_max = 2,
3019 /* NID is set in via_build_pcms */
3020 .ops = {
3021 .open = via_dig_playback_pcm_open,
3022 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003023 .prepare = via_dig_playback_pcm_prepare,
3024 .cleanup = via_dig_playback_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01003025 },
3026};
3027
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003028static const struct hda_pcm_stream vt1708B_pcm_digital_capture = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003029 .substreams = 1,
3030 .channels_min = 2,
3031 .channels_max = 2,
3032};
3033
3034/* fill in the dac_nids table from the parsed pin configuration */
3035static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3036 const struct auto_pin_cfg *cfg)
3037{
3038 int i;
3039 hda_nid_t nid;
3040
3041 spec->multiout.num_dacs = cfg->line_outs;
3042
3043 spec->multiout.dac_nids = spec->private_dac_nids;
3044
3045 for (i = 0; i < 4; i++) {
3046 nid = cfg->line_out_pins[i];
3047 if (nid) {
3048 /* config dac list */
3049 switch (i) {
3050 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02003051 spec->private_dac_nids[i] = 0x10;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003052 break;
3053 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003054 spec->private_dac_nids[i] = 0x24;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003055 break;
3056 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02003057 spec->private_dac_nids[i] = 0x11;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003058 break;
3059 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003060 spec->private_dac_nids[i] = 0x25;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003061 break;
3062 }
3063 }
3064 }
3065
3066 return 0;
3067}
3068
3069/* add playback controls from the parsed DAC table */
3070static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3071 const struct auto_pin_cfg *cfg)
3072{
3073 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01003074 static const char * const chname[4] = {
3075 "Front", "Surround", "C/LFE", "Side"
3076 };
Harald Weltefb4cb772008-09-09 15:53:36 +08003077 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
Josepch Chanf7278fd2007-12-13 16:40:40 +01003078 hda_nid_t nid, nid_vol = 0;
3079 int i, err;
3080
3081 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3082 nid = cfg->line_out_pins[i];
3083
3084 if (!nid)
3085 continue;
3086
3087 nid_vol = nid_vols[i];
3088
3089 if (i == AUTO_SEQ_CENLFE) {
3090 /* Center/LFE */
3091 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3092 "Center Playback Volume",
3093 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3094 HDA_OUTPUT));
3095 if (err < 0)
3096 return err;
3097 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3098 "LFE Playback Volume",
3099 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3100 HDA_OUTPUT));
3101 if (err < 0)
3102 return err;
3103 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3104 "Center Playback Switch",
3105 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3106 HDA_OUTPUT));
3107 if (err < 0)
3108 return err;
3109 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3110 "LFE Playback Switch",
3111 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3112 HDA_OUTPUT));
3113 if (err < 0)
3114 return err;
3115 } else if (i == AUTO_SEQ_FRONT) {
3116 /* add control to mixer index 0 */
3117 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3118 "Master Front Playback Volume",
3119 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3120 HDA_INPUT));
3121 if (err < 0)
3122 return err;
3123 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3124 "Master Front Playback Switch",
3125 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3126 HDA_INPUT));
3127 if (err < 0)
3128 return err;
3129
3130 /* add control to PW3 */
3131 sprintf(name, "%s Playback Volume", chname[i]);
3132 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3133 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3134 HDA_OUTPUT));
3135 if (err < 0)
3136 return err;
3137 sprintf(name, "%s Playback Switch", chname[i]);
3138 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3139 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3140 HDA_OUTPUT));
3141 if (err < 0)
3142 return err;
3143 } else {
3144 sprintf(name, "%s Playback Volume", chname[i]);
3145 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3146 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3147 HDA_OUTPUT));
3148 if (err < 0)
3149 return err;
3150 sprintf(name, "%s Playback Switch", chname[i]);
3151 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3152 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3153 HDA_OUTPUT));
3154 if (err < 0)
3155 return err;
3156 }
3157 }
3158
3159 return 0;
3160}
3161
3162static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3163{
3164 int err;
3165
3166 if (!pin)
3167 return 0;
3168
3169 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08003170 spec->hp_independent_mode_index = 1;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003171
3172 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3173 "Headphone Playback Volume",
3174 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3175 if (err < 0)
3176 return err;
3177 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3178 "Headphone Playback Switch",
3179 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3180 if (err < 0)
3181 return err;
3182
Harald Welte0aa62ae2008-09-09 15:58:27 +08003183 create_hp_imux(spec);
3184
Josepch Chanf7278fd2007-12-13 16:40:40 +01003185 return 0;
3186}
3187
3188/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003189static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003190 const struct auto_pin_cfg *cfg)
3191{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003192 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003193}
3194
3195static int vt1708B_parse_auto_config(struct hda_codec *codec)
3196{
3197 struct via_spec *spec = codec->spec;
3198 int err;
3199
3200 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3201 if (err < 0)
3202 return err;
3203 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3204 if (err < 0)
3205 return err;
3206 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3207 return 0; /* can't find valid BIOS pin config */
3208
3209 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3210 if (err < 0)
3211 return err;
3212 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3213 if (err < 0)
3214 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003215 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003216 if (err < 0)
3217 return err;
3218
3219 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3220
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003221 if (spec->autocfg.dig_outs)
Josepch Chanf7278fd2007-12-13 16:40:40 +01003222 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02003223 spec->dig_in_pin = VT1708B_DIGIN_PIN;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003224 if (spec->autocfg.dig_in_pin)
3225 spec->dig_in_nid = VT1708B_DIGIN_NID;
3226
Takashi Iwai603c4012008-07-30 15:01:44 +02003227 if (spec->kctls.list)
3228 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003229
Harald Welte0aa62ae2008-09-09 15:58:27 +08003230 spec->input_mux = &spec->private_imux[0];
3231
Harald Weltef8fdd492008-09-15 22:41:31 +08003232 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003233 via_hp_build(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003234
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003235 via_smart51_build(spec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003236 return 1;
3237}
3238
3239#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003240static const struct hda_amp_list vt1708B_loopbacks[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003241 { 0x16, HDA_INPUT, 1 },
3242 { 0x16, HDA_INPUT, 2 },
3243 { 0x16, HDA_INPUT, 3 },
3244 { 0x16, HDA_INPUT, 4 },
3245 { } /* end */
3246};
3247#endif
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003248
3249static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3250{
3251 struct via_spec *spec = codec->spec;
3252 int imux_is_smixer;
3253 unsigned int parm;
3254 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +08003255 if ((spec->codec_type != VT1708B_4CH) &&
3256 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003257 is_8ch = 1;
3258
3259 /* SW0 (17h) = stereo mixer */
3260 imux_is_smixer =
3261 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3262 == ((spec->codec_type == VT1708S) ? 5 : 0));
3263 /* inputs */
3264 /* PW 1/2/5 (1ah/1bh/1eh) */
3265 parm = AC_PWRST_D3;
3266 set_pin_power_state(codec, 0x1a, &parm);
3267 set_pin_power_state(codec, 0x1b, &parm);
3268 set_pin_power_state(codec, 0x1e, &parm);
3269 if (imux_is_smixer)
3270 parm = AC_PWRST_D0;
3271 /* SW0 (17h), AIW 0/1 (13h/14h) */
3272 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3273 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3274 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3275
3276 /* outputs */
3277 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3278 parm = AC_PWRST_D3;
3279 set_pin_power_state(codec, 0x19, &parm);
3280 if (spec->smart51_enabled)
3281 set_pin_power_state(codec, 0x1b, &parm);
3282 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3283 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3284
3285 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3286 if (is_8ch) {
3287 parm = AC_PWRST_D3;
3288 set_pin_power_state(codec, 0x22, &parm);
3289 if (spec->smart51_enabled)
3290 set_pin_power_state(codec, 0x1a, &parm);
3291 snd_hda_codec_write(codec, 0x26, 0,
3292 AC_VERB_SET_POWER_STATE, parm);
3293 snd_hda_codec_write(codec, 0x24, 0,
3294 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08003295 } else if (codec->vendor_id == 0x11064397) {
3296 /* PW7(23h), SW2(27h), AOW2(25h) */
3297 parm = AC_PWRST_D3;
3298 set_pin_power_state(codec, 0x23, &parm);
3299 if (spec->smart51_enabled)
3300 set_pin_power_state(codec, 0x1a, &parm);
3301 snd_hda_codec_write(codec, 0x27, 0,
3302 AC_VERB_SET_POWER_STATE, parm);
3303 snd_hda_codec_write(codec, 0x25, 0,
3304 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003305 }
3306
3307 /* PW 3/4/7 (1ch/1dh/23h) */
3308 parm = AC_PWRST_D3;
3309 /* force to D0 for internal Speaker */
3310 set_pin_power_state(codec, 0x1c, &parm);
3311 set_pin_power_state(codec, 0x1d, &parm);
3312 if (is_8ch)
3313 set_pin_power_state(codec, 0x23, &parm);
3314
3315 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3316 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3317 imux_is_smixer ? AC_PWRST_D0 : parm);
3318 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3319 if (is_8ch) {
3320 snd_hda_codec_write(codec, 0x25, 0,
3321 AC_VERB_SET_POWER_STATE, parm);
3322 snd_hda_codec_write(codec, 0x27, 0,
3323 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08003324 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3325 snd_hda_codec_write(codec, 0x25, 0,
3326 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003327}
3328
Lydia Wang518bf3b2009-10-10 19:07:29 +08003329static int patch_vt1708S(struct hda_codec *codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003330static int patch_vt1708B_8ch(struct hda_codec *codec)
3331{
3332 struct via_spec *spec;
3333 int err;
3334
Lydia Wang518bf3b2009-10-10 19:07:29 +08003335 if (get_codec_type(codec) == VT1708BCE)
3336 return patch_vt1708S(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003337 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003338 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003339 if (spec == NULL)
3340 return -ENOMEM;
3341
Josepch Chanf7278fd2007-12-13 16:40:40 +01003342 /* automatic parse from the BIOS config */
3343 err = vt1708B_parse_auto_config(codec);
3344 if (err < 0) {
3345 via_free(codec);
3346 return err;
3347 } else if (!err) {
3348 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3349 "from BIOS. Using genenic mode...\n");
3350 }
3351
Harald Welte69e52a82008-09-09 15:57:32 +08003352 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3353 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003354
3355 spec->stream_name_analog = "VT1708B Analog";
3356 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3357 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3358
3359 spec->stream_name_digital = "VT1708B Digital";
3360 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3361 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3362
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003363 if (spec->adc_nids && spec->input_mux) {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003364 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3365 spec->num_mixers++;
3366 }
3367
3368 codec->patch_ops = via_patch_ops;
3369
3370 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003371 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003372#ifdef CONFIG_SND_HDA_POWER_SAVE
3373 spec->loopback.amplist = vt1708B_loopbacks;
3374#endif
3375
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003376 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3377
Josepch Chanf7278fd2007-12-13 16:40:40 +01003378 return 0;
3379}
3380
3381static int patch_vt1708B_4ch(struct hda_codec *codec)
3382{
3383 struct via_spec *spec;
3384 int err;
3385
3386 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003387 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003388 if (spec == NULL)
3389 return -ENOMEM;
3390
Josepch Chanf7278fd2007-12-13 16:40:40 +01003391 /* automatic parse from the BIOS config */
3392 err = vt1708B_parse_auto_config(codec);
3393 if (err < 0) {
3394 via_free(codec);
3395 return err;
3396 } else if (!err) {
3397 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3398 "from BIOS. Using genenic mode...\n");
3399 }
3400
Harald Welte69e52a82008-09-09 15:57:32 +08003401 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3402 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003403
3404 spec->stream_name_analog = "VT1708B Analog";
3405 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3406 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3407
3408 spec->stream_name_digital = "VT1708B Digital";
3409 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3410 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3411
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003412 if (spec->adc_nids && spec->input_mux) {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003413 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3414 spec->num_mixers++;
3415 }
3416
3417 codec->patch_ops = via_patch_ops;
3418
3419 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003420 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003421#ifdef CONFIG_SND_HDA_POWER_SAVE
3422 spec->loopback.amplist = vt1708B_loopbacks;
3423#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01003424
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003425 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3426
Joseph Chanc577b8a2006-11-29 15:29:40 +01003427 return 0;
3428}
3429
Harald Welted949cac2008-09-09 15:56:01 +08003430/* Patch for VT1708S */
3431
3432/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003433static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003434 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3435 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3436 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3437 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
Lydia Wang6369bcf2009-10-10 19:08:31 +08003438 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3439 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3440 HDA_INPUT),
Harald Welted949cac2008-09-09 15:56:01 +08003441 {
3442 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3443 /* The multiple "Capture Source" controls confuse alsamixer
3444 * So call somewhat different..
3445 */
3446 /* .name = "Capture Source", */
3447 .name = "Input Source",
3448 .count = 1,
3449 .info = via_mux_enum_info,
3450 .get = via_mux_enum_get,
3451 .put = via_mux_enum_put,
3452 },
3453 { } /* end */
3454};
3455
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003456static const struct hda_verb vt1708S_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003457 /* Unmute ADC0-1 and set the default input to mic-in */
3458 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3459 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3460
3461 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3462 * analog-loopback mixer widget */
3463 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3464 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3465 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3466 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3467 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3468 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3469
3470 /* Setup default input of PW4 to MW0 */
3471 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
Harald Welte5691ec72008-09-15 22:42:26 +08003472 /* PW9, PW10 Output enable */
Harald Welted949cac2008-09-09 15:56:01 +08003473 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welte5691ec72008-09-15 22:42:26 +08003474 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welted7426322008-09-15 22:43:23 +08003475 /* Enable Mic Boost Volume backdoor */
3476 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003477 /* don't bybass mixer */
3478 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08003479 { }
3480};
3481
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003482static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003483 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3484 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3485 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3486 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3487 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3488 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3489 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3490 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3491 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003492 { }
3493};
3494
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003495static const struct hda_verb vt1705_uniwill_init_verbs[] = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003496 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3497 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3498 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3499 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3500 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3501 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3502 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3503 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3504 { }
3505};
3506
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003507static const struct hda_pcm_stream vt1708S_pcm_analog_playback = {
Harald Welted949cac2008-09-09 15:56:01 +08003508 .substreams = 2,
3509 .channels_min = 2,
3510 .channels_max = 8,
3511 .nid = 0x10, /* NID to query formats and rates */
3512 .ops = {
3513 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08003514 .prepare = via_playback_multi_pcm_prepare,
3515 .cleanup = via_playback_multi_pcm_cleanup,
Lydia Wang17314372009-10-10 19:07:37 +08003516 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003517 },
3518};
3519
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003520static const struct hda_pcm_stream vt1705_pcm_analog_playback = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003521 .substreams = 2,
3522 .channels_min = 2,
3523 .channels_max = 6,
3524 .nid = 0x10, /* NID to query formats and rates */
3525 .ops = {
3526 .open = via_playback_pcm_open,
3527 .prepare = via_playback_multi_pcm_prepare,
3528 .cleanup = via_playback_multi_pcm_cleanup,
3529 .close = via_pcm_open_close
3530 },
3531};
3532
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003533static const struct hda_pcm_stream vt1708S_pcm_analog_capture = {
Harald Welted949cac2008-09-09 15:56:01 +08003534 .substreams = 2,
3535 .channels_min = 2,
3536 .channels_max = 2,
3537 .nid = 0x13, /* NID to query formats and rates */
3538 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003539 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08003540 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003541 .cleanup = via_capture_pcm_cleanup,
3542 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003543 },
3544};
3545
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003546static const struct hda_pcm_stream vt1708S_pcm_digital_playback = {
Takashi Iwai9da29272009-05-07 16:31:14 +02003547 .substreams = 1,
Harald Welted949cac2008-09-09 15:56:01 +08003548 .channels_min = 2,
3549 .channels_max = 2,
3550 /* NID is set in via_build_pcms */
3551 .ops = {
3552 .open = via_dig_playback_pcm_open,
3553 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003554 .prepare = via_dig_playback_pcm_prepare,
3555 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08003556 },
3557};
3558
3559/* fill in the dac_nids table from the parsed pin configuration */
3560static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3561 const struct auto_pin_cfg *cfg)
3562{
3563 int i;
3564 hda_nid_t nid;
3565
3566 spec->multiout.num_dacs = cfg->line_outs;
3567
3568 spec->multiout.dac_nids = spec->private_dac_nids;
3569
3570 for (i = 0; i < 4; i++) {
3571 nid = cfg->line_out_pins[i];
3572 if (nid) {
3573 /* config dac list */
3574 switch (i) {
3575 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02003576 spec->private_dac_nids[i] = 0x10;
Harald Welted949cac2008-09-09 15:56:01 +08003577 break;
3578 case AUTO_SEQ_CENLFE:
Lydia Wangbc92df72011-03-23 17:56:05 +08003579 if (spec->codec->vendor_id == 0x11064397)
Takashi Iwaidda14412011-05-02 11:29:30 +02003580 spec->private_dac_nids[i] = 0x25;
Lydia Wangbc92df72011-03-23 17:56:05 +08003581 else
Takashi Iwaidda14412011-05-02 11:29:30 +02003582 spec->private_dac_nids[i] = 0x24;
Harald Welted949cac2008-09-09 15:56:01 +08003583 break;
3584 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02003585 spec->private_dac_nids[i] = 0x11;
Harald Welted949cac2008-09-09 15:56:01 +08003586 break;
3587 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003588 spec->private_dac_nids[i] = 0x25;
Harald Welted949cac2008-09-09 15:56:01 +08003589 break;
3590 }
3591 }
3592 }
3593
Clemens Ladisch32e01912010-07-12 16:28:50 +02003594 /* for Smart 5.1, line/mic inputs double as output pins */
3595 if (cfg->line_outs == 1) {
3596 spec->multiout.num_dacs = 3;
Takashi Iwaidda14412011-05-02 11:29:30 +02003597 spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11;
Lydia Wangbc92df72011-03-23 17:56:05 +08003598 if (spec->codec->vendor_id == 0x11064397)
Takashi Iwaidda14412011-05-02 11:29:30 +02003599 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25;
Lydia Wangbc92df72011-03-23 17:56:05 +08003600 else
Takashi Iwaidda14412011-05-02 11:29:30 +02003601 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24;
Clemens Ladisch32e01912010-07-12 16:28:50 +02003602 }
3603
Harald Welted949cac2008-09-09 15:56:01 +08003604 return 0;
3605}
3606
3607/* add playback controls from the parsed DAC table */
Lydia Wangbc92df72011-03-23 17:56:05 +08003608static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08003609 const struct auto_pin_cfg *cfg)
3610{
Lydia Wangbc92df72011-03-23 17:56:05 +08003611 struct via_spec *spec = codec->spec;
Harald Welted949cac2008-09-09 15:56:01 +08003612 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01003613 static const char * const chname[4] = {
3614 "Front", "Surround", "C/LFE", "Side"
3615 };
Lydia Wangbc92df72011-03-23 17:56:05 +08003616 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3617 {0x10, 0x11, 0x25, 0} };
3618 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3619 {0x1C, 0x18, 0x27, 0} };
Harald Welted949cac2008-09-09 15:56:01 +08003620 hda_nid_t nid, nid_vol, nid_mute;
3621 int i, err;
3622
3623 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3624 nid = cfg->line_out_pins[i];
3625
Clemens Ladisch32e01912010-07-12 16:28:50 +02003626 /* for Smart 5.1, there are always at least six channels */
3627 if (!nid && i > AUTO_SEQ_CENLFE)
Harald Welted949cac2008-09-09 15:56:01 +08003628 continue;
3629
Lydia Wangbc92df72011-03-23 17:56:05 +08003630 if (codec->vendor_id == 0x11064397) {
3631 nid_vol = nid_vols[1][i];
3632 nid_mute = nid_mutes[1][i];
3633 } else {
3634 nid_vol = nid_vols[0][i];
3635 nid_mute = nid_mutes[0][i];
3636 }
3637 if (!nid_vol && !nid_mute)
3638 continue;
Harald Welted949cac2008-09-09 15:56:01 +08003639
3640 if (i == AUTO_SEQ_CENLFE) {
3641 /* Center/LFE */
3642 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3643 "Center Playback Volume",
3644 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3645 HDA_OUTPUT));
3646 if (err < 0)
3647 return err;
3648 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3649 "LFE Playback Volume",
3650 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3651 HDA_OUTPUT));
3652 if (err < 0)
3653 return err;
3654 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3655 "Center Playback Switch",
3656 HDA_COMPOSE_AMP_VAL(nid_mute,
3657 1, 0,
3658 HDA_OUTPUT));
3659 if (err < 0)
3660 return err;
3661 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3662 "LFE Playback Switch",
3663 HDA_COMPOSE_AMP_VAL(nid_mute,
3664 2, 0,
3665 HDA_OUTPUT));
3666 if (err < 0)
3667 return err;
3668 } else if (i == AUTO_SEQ_FRONT) {
3669 /* add control to mixer index 0 */
3670 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3671 "Master Front Playback Volume",
3672 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3673 HDA_INPUT));
3674 if (err < 0)
3675 return err;
3676 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3677 "Master Front Playback Switch",
3678 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3679 HDA_INPUT));
3680 if (err < 0)
3681 return err;
3682
3683 /* Front */
3684 sprintf(name, "%s Playback Volume", chname[i]);
3685 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3686 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3687 HDA_OUTPUT));
3688 if (err < 0)
3689 return err;
3690 sprintf(name, "%s Playback Switch", chname[i]);
3691 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3692 HDA_COMPOSE_AMP_VAL(nid_mute,
3693 3, 0,
3694 HDA_OUTPUT));
3695 if (err < 0)
3696 return err;
3697 } else {
3698 sprintf(name, "%s Playback Volume", chname[i]);
3699 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3700 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3701 HDA_OUTPUT));
3702 if (err < 0)
3703 return err;
3704 sprintf(name, "%s Playback Switch", chname[i]);
3705 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3706 HDA_COMPOSE_AMP_VAL(nid_mute,
3707 3, 0,
3708 HDA_OUTPUT));
3709 if (err < 0)
3710 return err;
3711 }
3712 }
3713
3714 return 0;
3715}
3716
3717static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3718{
3719 int err;
3720
3721 if (!pin)
3722 return 0;
3723
3724 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08003725 spec->hp_independent_mode_index = 1;
Harald Welted949cac2008-09-09 15:56:01 +08003726
3727 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3728 "Headphone Playback Volume",
3729 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3730 if (err < 0)
3731 return err;
3732
3733 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3734 "Headphone Playback Switch",
3735 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3736 if (err < 0)
3737 return err;
3738
Harald Welte0aa62ae2008-09-09 15:58:27 +08003739 create_hp_imux(spec);
3740
Harald Welted949cac2008-09-09 15:56:01 +08003741 return 0;
3742}
3743
3744/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003745static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08003746 const struct auto_pin_cfg *cfg)
3747{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003748 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
Harald Welted949cac2008-09-09 15:56:01 +08003749}
3750
Takashi Iwai9da29272009-05-07 16:31:14 +02003751/* fill out digital output widgets; one for master and one for slave outputs */
3752static void fill_dig_outs(struct hda_codec *codec)
3753{
3754 struct via_spec *spec = codec->spec;
3755 int i;
3756
3757 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3758 hda_nid_t nid;
3759 int conn;
3760
3761 nid = spec->autocfg.dig_out_pins[i];
3762 if (!nid)
3763 continue;
3764 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3765 if (conn < 1)
3766 continue;
3767 if (!spec->multiout.dig_out_nid)
3768 spec->multiout.dig_out_nid = nid;
3769 else {
3770 spec->slave_dig_outs[0] = nid;
3771 break; /* at most two dig outs */
3772 }
3773 }
3774}
3775
Harald Welted949cac2008-09-09 15:56:01 +08003776static int vt1708S_parse_auto_config(struct hda_codec *codec)
3777{
3778 struct via_spec *spec = codec->spec;
3779 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003780
Takashi Iwai9da29272009-05-07 16:31:14 +02003781 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08003782 if (err < 0)
3783 return err;
3784 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3785 if (err < 0)
3786 return err;
3787 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3788 return 0; /* can't find valid BIOS pin config */
3789
Lydia Wangbc92df72011-03-23 17:56:05 +08003790 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003791 if (err < 0)
3792 return err;
3793 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3794 if (err < 0)
3795 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003796 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003797 if (err < 0)
3798 return err;
3799
3800 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3801
Takashi Iwai9da29272009-05-07 16:31:14 +02003802 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08003803
Takashi Iwai603c4012008-07-30 15:01:44 +02003804 if (spec->kctls.list)
3805 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08003806
Harald Welte0aa62ae2008-09-09 15:58:27 +08003807 spec->input_mux = &spec->private_imux[0];
3808
Harald Weltef8fdd492008-09-15 22:41:31 +08003809 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003810 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003811
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003812 via_smart51_build(spec);
Harald Welted949cac2008-09-09 15:56:01 +08003813 return 1;
3814}
3815
3816#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003817static const struct hda_amp_list vt1708S_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003818 { 0x16, HDA_INPUT, 1 },
3819 { 0x16, HDA_INPUT, 2 },
3820 { 0x16, HDA_INPUT, 3 },
3821 { 0x16, HDA_INPUT, 4 },
3822 { } /* end */
3823};
3824#endif
3825
Lydia Wang6369bcf2009-10-10 19:08:31 +08003826static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3827 int offset, int num_steps, int step_size)
3828{
3829 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3830 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3831 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3832 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3833 (0 << AC_AMPCAP_MUTE_SHIFT));
3834}
3835
Harald Welted949cac2008-09-09 15:56:01 +08003836static int patch_vt1708S(struct hda_codec *codec)
3837{
3838 struct via_spec *spec;
3839 int err;
3840
3841 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003842 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003843 if (spec == NULL)
3844 return -ENOMEM;
3845
Harald Welted949cac2008-09-09 15:56:01 +08003846 /* automatic parse from the BIOS config */
3847 err = vt1708S_parse_auto_config(codec);
3848 if (err < 0) {
3849 via_free(codec);
3850 return err;
3851 } else if (!err) {
3852 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3853 "from BIOS. Using genenic mode...\n");
3854 }
3855
Harald Welte69e52a82008-09-09 15:57:32 +08003856 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
Lydia Wangbc92df72011-03-23 17:56:05 +08003857 if (codec->vendor_id == 0x11064397)
3858 spec->init_verbs[spec->num_iverbs++] =
3859 vt1705_uniwill_init_verbs;
3860 else
3861 spec->init_verbs[spec->num_iverbs++] =
3862 vt1708S_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003863
Lydia Wang36dd5c42009-10-20 13:18:04 +08003864 if (codec->vendor_id == 0x11060440)
3865 spec->stream_name_analog = "VT1818S Analog";
Lydia Wangbc92df72011-03-23 17:56:05 +08003866 else if (codec->vendor_id == 0x11064397)
3867 spec->stream_name_analog = "VT1705 Analog";
Lydia Wang36dd5c42009-10-20 13:18:04 +08003868 else
3869 spec->stream_name_analog = "VT1708S Analog";
Lydia Wangbc92df72011-03-23 17:56:05 +08003870 if (codec->vendor_id == 0x11064397)
3871 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3872 else
3873 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
Harald Welted949cac2008-09-09 15:56:01 +08003874 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3875
Lydia Wang36dd5c42009-10-20 13:18:04 +08003876 if (codec->vendor_id == 0x11060440)
3877 spec->stream_name_digital = "VT1818S Digital";
Lydia Wangbc92df72011-03-23 17:56:05 +08003878 else if (codec->vendor_id == 0x11064397)
3879 spec->stream_name_digital = "VT1705 Digital";
Lydia Wang36dd5c42009-10-20 13:18:04 +08003880 else
3881 spec->stream_name_digital = "VT1708S Digital";
Harald Welted949cac2008-09-09 15:56:01 +08003882 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3883
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003884 if (spec->adc_nids && spec->input_mux) {
Lydia Wang6369bcf2009-10-10 19:08:31 +08003885 override_mic_boost(codec, 0x1a, 0, 3, 40);
3886 override_mic_boost(codec, 0x1e, 0, 3, 40);
Harald Welted949cac2008-09-09 15:56:01 +08003887 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3888 spec->num_mixers++;
3889 }
3890
3891 codec->patch_ops = via_patch_ops;
3892
3893 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003894 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08003895#ifdef CONFIG_SND_HDA_POWER_SAVE
3896 spec->loopback.amplist = vt1708S_loopbacks;
3897#endif
3898
Lydia Wang518bf3b2009-10-10 19:07:29 +08003899 /* correct names for VT1708BCE */
3900 if (get_codec_type(codec) == VT1708BCE) {
3901 kfree(codec->chip_name);
3902 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3903 snprintf(codec->bus->card->mixername,
3904 sizeof(codec->bus->card->mixername),
3905 "%s %s", codec->vendor_name, codec->chip_name);
3906 spec->stream_name_analog = "VT1708BCE Analog";
3907 spec->stream_name_digital = "VT1708BCE Digital";
3908 }
Lydia Wang970f630f2011-03-22 16:25:56 +08003909 /* correct names for VT1818S */
3910 if (codec->vendor_id == 0x11060440) {
3911 spec->stream_name_analog = "VT1818S Analog";
3912 spec->stream_name_digital = "VT1818S Digital";
3913 }
Lydia Wangbc92df72011-03-23 17:56:05 +08003914 /* correct names for VT1705 */
3915 if (codec->vendor_id == 0x11064397) {
3916 kfree(codec->chip_name);
3917 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3918 snprintf(codec->bus->card->mixername,
3919 sizeof(codec->bus->card->mixername),
3920 "%s %s", codec->vendor_name, codec->chip_name);
3921 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003922 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +08003923 return 0;
3924}
3925
3926/* Patch for VT1702 */
3927
3928/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003929static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003930 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3931 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3932 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3933 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3934 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3935 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3936 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3937 HDA_INPUT),
3938 {
3939 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3940 /* The multiple "Capture Source" controls confuse alsamixer
3941 * So call somewhat different..
3942 */
3943 /* .name = "Capture Source", */
3944 .name = "Input Source",
3945 .count = 1,
3946 .info = via_mux_enum_info,
3947 .get = via_mux_enum_get,
3948 .put = via_mux_enum_put,
3949 },
3950 { } /* end */
3951};
3952
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003953static const struct hda_verb vt1702_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003954 /*
3955 * Unmute ADC0-1 and set the default input to mic-in
3956 */
3957 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3958 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3959 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3960
3961
3962 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3963 * mixer widget
3964 */
3965 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3966 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3967 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3968 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3969 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3970 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3971
3972 /* Setup default input of PW4 to MW0 */
3973 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3974 /* PW6 PW7 Output enable */
3975 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3976 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003977 /* mixer enable */
3978 {0x1, 0xF88, 0x3},
3979 /* GPIO 0~2 */
3980 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08003981 { }
3982};
3983
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003984static const struct hda_verb vt1702_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003985 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3986 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3987 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3988 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3989 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3990 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003991 { }
3992};
3993
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003994static const struct hda_pcm_stream vt1702_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08003995 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08003996 .channels_min = 2,
3997 .channels_max = 2,
3998 .nid = 0x10, /* NID to query formats and rates */
3999 .ops = {
4000 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08004001 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08004002 .cleanup = via_playback_multi_pcm_cleanup,
4003 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08004004 },
4005};
4006
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004007static const struct hda_pcm_stream vt1702_pcm_analog_capture = {
Harald Welted949cac2008-09-09 15:56:01 +08004008 .substreams = 3,
4009 .channels_min = 2,
4010 .channels_max = 2,
4011 .nid = 0x12, /* NID to query formats and rates */
4012 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08004013 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08004014 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08004015 .cleanup = via_capture_pcm_cleanup,
4016 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08004017 },
4018};
4019
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004020static const struct hda_pcm_stream vt1702_pcm_digital_playback = {
Harald Welte5691ec72008-09-15 22:42:26 +08004021 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08004022 .channels_min = 2,
4023 .channels_max = 2,
4024 /* NID is set in via_build_pcms */
4025 .ops = {
4026 .open = via_dig_playback_pcm_open,
4027 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02004028 .prepare = via_dig_playback_pcm_prepare,
4029 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08004030 },
4031};
4032
4033/* fill in the dac_nids table from the parsed pin configuration */
4034static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4035 const struct auto_pin_cfg *cfg)
4036{
4037 spec->multiout.num_dacs = 1;
4038 spec->multiout.dac_nids = spec->private_dac_nids;
4039
4040 if (cfg->line_out_pins[0]) {
4041 /* config dac list */
Takashi Iwaidda14412011-05-02 11:29:30 +02004042 spec->private_dac_nids[0] = 0x10;
Harald Welted949cac2008-09-09 15:56:01 +08004043 }
4044
4045 return 0;
4046}
4047
4048/* add playback controls from the parsed DAC table */
4049static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4050 const struct auto_pin_cfg *cfg)
4051{
4052 int err;
4053
4054 if (!cfg->line_out_pins[0])
4055 return -1;
4056
4057 /* add control to mixer index 0 */
4058 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4059 "Master Front Playback Volume",
4060 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4061 if (err < 0)
4062 return err;
4063 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4064 "Master Front Playback Switch",
4065 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4066 if (err < 0)
4067 return err;
4068
4069 /* Front */
4070 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4071 "Front Playback Volume",
4072 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4073 if (err < 0)
4074 return err;
4075 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4076 "Front Playback Switch",
4077 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4078 if (err < 0)
4079 return err;
4080
4081 return 0;
4082}
4083
4084static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4085{
Lydia Wang0713efe2009-10-10 19:07:43 +08004086 int err, i;
4087 struct hda_input_mux *imux;
Takashi Iwaiea734962011-01-17 11:29:34 +01004088 static const char * const texts[] = { "ON", "OFF", NULL};
Harald Welted949cac2008-09-09 15:56:01 +08004089 if (!pin)
4090 return 0;
Harald Welted949cac2008-09-09 15:56:01 +08004091 spec->multiout.hp_nid = 0x1D;
Lydia Wangcdc17842009-10-10 19:07:47 +08004092 spec->hp_independent_mode_index = 0;
Harald Welted949cac2008-09-09 15:56:01 +08004093
4094 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4095 "Headphone Playback Volume",
4096 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4097 if (err < 0)
4098 return err;
4099
4100 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4101 "Headphone Playback Switch",
4102 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4103 if (err < 0)
4104 return err;
4105
Lydia Wang0713efe2009-10-10 19:07:43 +08004106 imux = &spec->private_imux[1];
Harald Welte0aa62ae2008-09-09 15:58:27 +08004107
Lydia Wang0713efe2009-10-10 19:07:43 +08004108 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004109 for (i = 0; texts[i]; i++)
4110 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Lydia Wang0713efe2009-10-10 19:07:43 +08004111
4112 spec->hp_mux = &spec->private_imux[1];
Harald Welted949cac2008-09-09 15:56:01 +08004113 return 0;
4114}
4115
4116/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004117static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08004118 const struct auto_pin_cfg *cfg)
4119{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004120 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a);
Harald Welted949cac2008-09-09 15:56:01 +08004121}
4122
4123static int vt1702_parse_auto_config(struct hda_codec *codec)
4124{
4125 struct via_spec *spec = codec->spec;
4126 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004127
Takashi Iwai9da29272009-05-07 16:31:14 +02004128 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08004129 if (err < 0)
4130 return err;
4131 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4132 if (err < 0)
4133 return err;
4134 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4135 return 0; /* can't find valid BIOS pin config */
4136
4137 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4138 if (err < 0)
4139 return err;
4140 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4141 if (err < 0)
4142 return err;
Lydia Wangc2c02ea2009-10-10 19:07:32 +08004143 /* limit AA path volume to 0 dB */
4144 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4145 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4146 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4147 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4148 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai10a20af2010-09-09 16:28:02 +02004149 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08004150 if (err < 0)
4151 return err;
4152
4153 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4154
Takashi Iwai9da29272009-05-07 16:31:14 +02004155 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08004156
Takashi Iwai603c4012008-07-30 15:01:44 +02004157 if (spec->kctls.list)
4158 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08004159
Harald Welte0aa62ae2008-09-09 15:58:27 +08004160 spec->input_mux = &spec->private_imux[0];
4161
Harald Weltef8fdd492008-09-15 22:41:31 +08004162 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004163 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004164
4165 return 1;
4166}
4167
4168#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004169static const struct hda_amp_list vt1702_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08004170 { 0x1A, HDA_INPUT, 1 },
4171 { 0x1A, HDA_INPUT, 2 },
4172 { 0x1A, HDA_INPUT, 3 },
4173 { 0x1A, HDA_INPUT, 4 },
4174 { } /* end */
4175};
4176#endif
4177
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004178static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4179{
4180 int imux_is_smixer =
4181 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4182 unsigned int parm;
4183 /* inputs */
4184 /* PW 1/2/5 (14h/15h/18h) */
4185 parm = AC_PWRST_D3;
4186 set_pin_power_state(codec, 0x14, &parm);
4187 set_pin_power_state(codec, 0x15, &parm);
4188 set_pin_power_state(codec, 0x18, &parm);
4189 if (imux_is_smixer)
4190 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4191 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4192 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4193 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4194 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4195 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4196
4197 /* outputs */
4198 /* PW 3/4 (16h/17h) */
4199 parm = AC_PWRST_D3;
4200 set_pin_power_state(codec, 0x17, &parm);
4201 set_pin_power_state(codec, 0x16, &parm);
4202 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4203 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4204 imux_is_smixer ? AC_PWRST_D0 : parm);
4205 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4206 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4207}
4208
Harald Welted949cac2008-09-09 15:56:01 +08004209static int patch_vt1702(struct hda_codec *codec)
4210{
4211 struct via_spec *spec;
4212 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004213
4214 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004215 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004216 if (spec == NULL)
4217 return -ENOMEM;
4218
Harald Welted949cac2008-09-09 15:56:01 +08004219 /* automatic parse from the BIOS config */
4220 err = vt1702_parse_auto_config(codec);
4221 if (err < 0) {
4222 via_free(codec);
4223 return err;
4224 } else if (!err) {
4225 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4226 "from BIOS. Using genenic mode...\n");
4227 }
4228
Harald Welte69e52a82008-09-09 15:57:32 +08004229 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4230 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08004231
4232 spec->stream_name_analog = "VT1702 Analog";
4233 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4234 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4235
4236 spec->stream_name_digital = "VT1702 Digital";
4237 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4238
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004239 if (spec->adc_nids && spec->input_mux) {
Harald Welted949cac2008-09-09 15:56:01 +08004240 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4241 spec->num_mixers++;
4242 }
4243
4244 codec->patch_ops = via_patch_ops;
4245
4246 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08004247 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08004248#ifdef CONFIG_SND_HDA_POWER_SAVE
4249 spec->loopback.amplist = vt1702_loopbacks;
4250#endif
4251
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004252 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08004253 return 0;
4254}
4255
Lydia Wangeb7188c2009-10-10 19:08:34 +08004256/* Patch for VT1718S */
4257
4258/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004259static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004260 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4261 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4262 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4263 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4264 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4265 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4266 HDA_INPUT),
4267 {
4268 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4269 /* The multiple "Capture Source" controls confuse alsamixer
4270 * So call somewhat different..
4271 */
4272 .name = "Input Source",
4273 .count = 2,
4274 .info = via_mux_enum_info,
4275 .get = via_mux_enum_get,
4276 .put = via_mux_enum_put,
4277 },
4278 { } /* end */
4279};
4280
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004281static const struct hda_verb vt1718S_volume_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004282 /*
4283 * Unmute ADC0-1 and set the default input to mic-in
4284 */
4285 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4286 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4287
Lydia Wang4ab2d532011-03-24 12:42:03 +08004288 /* Enable MW0 adjust Gain 5 */
4289 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08004290 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4291 * mixer widget
4292 */
4293 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4294 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4295 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4296 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4297 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
Lydia Wang4ab2d532011-03-24 12:42:03 +08004298 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
Lydia Wangeb7188c2009-10-10 19:08:34 +08004299
4300 /* Setup default input of Front HP to MW9 */
4301 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4302 /* PW9 PW10 Output enable */
4303 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4304 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4305 /* PW11 Input enable */
4306 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4307 /* Enable Boost Volume backdoor */
4308 {0x1, 0xf88, 0x8},
4309 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4310 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4311 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4312 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4313 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4314 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4315 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4316 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4317 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4318 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4319 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4320 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4321 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4322 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4323 /* Unmute MW4's index 0 */
4324 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4325 { }
4326};
4327
4328
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004329static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004330 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4331 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4332 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4333 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4334 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4335 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4336 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4337 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4338 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4339 { }
4340};
4341
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004342static const struct hda_pcm_stream vt1718S_pcm_analog_playback = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004343 .substreams = 2,
4344 .channels_min = 2,
4345 .channels_max = 10,
4346 .nid = 0x8, /* NID to query formats and rates */
4347 .ops = {
4348 .open = via_playback_pcm_open,
4349 .prepare = via_playback_multi_pcm_prepare,
4350 .cleanup = via_playback_multi_pcm_cleanup,
4351 .close = via_pcm_open_close,
4352 },
4353};
4354
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004355static const struct hda_pcm_stream vt1718S_pcm_analog_capture = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004356 .substreams = 2,
4357 .channels_min = 2,
4358 .channels_max = 2,
4359 .nid = 0x10, /* NID to query formats and rates */
4360 .ops = {
4361 .open = via_pcm_open_close,
4362 .prepare = via_capture_pcm_prepare,
4363 .cleanup = via_capture_pcm_cleanup,
4364 .close = via_pcm_open_close,
4365 },
4366};
4367
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004368static const struct hda_pcm_stream vt1718S_pcm_digital_playback = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004369 .substreams = 2,
4370 .channels_min = 2,
4371 .channels_max = 2,
Lydia Wangeb7188c2009-10-10 19:08:34 +08004372 /* NID is set in via_build_pcms */
4373 .ops = {
4374 .open = via_dig_playback_pcm_open,
4375 .close = via_dig_playback_pcm_close,
4376 .prepare = via_dig_playback_pcm_prepare,
4377 .cleanup = via_dig_playback_pcm_cleanup
4378 },
4379};
4380
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004381static const struct hda_pcm_stream vt1718S_pcm_digital_capture = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004382 .substreams = 1,
4383 .channels_min = 2,
4384 .channels_max = 2,
4385};
4386
4387/* fill in the dac_nids table from the parsed pin configuration */
4388static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4389 const struct auto_pin_cfg *cfg)
4390{
4391 int i;
4392 hda_nid_t nid;
4393
4394 spec->multiout.num_dacs = cfg->line_outs;
4395
4396 spec->multiout.dac_nids = spec->private_dac_nids;
4397
4398 for (i = 0; i < 4; i++) {
4399 nid = cfg->line_out_pins[i];
4400 if (nid) {
4401 /* config dac list */
4402 switch (i) {
4403 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02004404 spec->private_dac_nids[i] = 0x8;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004405 break;
4406 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004407 spec->private_dac_nids[i] = 0xa;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004408 break;
4409 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02004410 spec->private_dac_nids[i] = 0x9;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004411 break;
4412 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004413 spec->private_dac_nids[i] = 0xb;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004414 break;
4415 }
4416 }
4417 }
4418
4419 return 0;
4420}
4421
4422/* add playback controls from the parsed DAC table */
4423static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4424 const struct auto_pin_cfg *cfg)
4425{
4426 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01004427 static const char * const chname[4] = {
4428 "Front", "Surround", "C/LFE", "Side"
4429 };
Lydia Wangeb7188c2009-10-10 19:08:34 +08004430 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4431 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4432 hda_nid_t nid, nid_vol, nid_mute = 0;
4433 int i, err;
4434
4435 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4436 nid = cfg->line_out_pins[i];
4437
4438 if (!nid)
4439 continue;
4440 nid_vol = nid_vols[i];
4441 nid_mute = nid_mutes[i];
4442
4443 if (i == AUTO_SEQ_CENLFE) {
4444 /* Center/LFE */
4445 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4446 "Center Playback Volume",
4447 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4448 HDA_OUTPUT));
4449 if (err < 0)
4450 return err;
4451 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4452 "LFE Playback Volume",
4453 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4454 HDA_OUTPUT));
4455 if (err < 0)
4456 return err;
4457 err = via_add_control(
4458 spec, VIA_CTL_WIDGET_MUTE,
4459 "Center Playback Switch",
4460 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4461 HDA_OUTPUT));
4462 if (err < 0)
4463 return err;
4464 err = via_add_control(
4465 spec, VIA_CTL_WIDGET_MUTE,
4466 "LFE Playback Switch",
4467 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4468 HDA_OUTPUT));
4469 if (err < 0)
4470 return err;
4471 } else if (i == AUTO_SEQ_FRONT) {
4472 /* Front */
4473 sprintf(name, "%s Playback Volume", chname[i]);
4474 err = via_add_control(
4475 spec, VIA_CTL_WIDGET_VOL, name,
4476 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4477 if (err < 0)
4478 return err;
4479 sprintf(name, "%s Playback Switch", chname[i]);
4480 err = via_add_control(
4481 spec, VIA_CTL_WIDGET_MUTE, name,
4482 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4483 HDA_OUTPUT));
4484 if (err < 0)
4485 return err;
4486 } else {
4487 sprintf(name, "%s Playback Volume", chname[i]);
4488 err = via_add_control(
4489 spec, VIA_CTL_WIDGET_VOL, name,
4490 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4491 if (err < 0)
4492 return err;
4493 sprintf(name, "%s Playback Switch", chname[i]);
4494 err = via_add_control(
4495 spec, VIA_CTL_WIDGET_MUTE, name,
4496 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4497 HDA_OUTPUT));
4498 if (err < 0)
4499 return err;
4500 }
4501 }
4502 return 0;
4503}
4504
4505static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4506{
4507 int err;
4508
4509 if (!pin)
4510 return 0;
4511
4512 spec->multiout.hp_nid = 0xc; /* AOW4 */
4513 spec->hp_independent_mode_index = 1;
4514
4515 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4516 "Headphone Playback Volume",
4517 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4518 if (err < 0)
4519 return err;
4520
4521 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4522 "Headphone Playback Switch",
4523 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4524 if (err < 0)
4525 return err;
4526
4527 create_hp_imux(spec);
4528 return 0;
4529}
4530
4531/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004532static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangeb7188c2009-10-10 19:08:34 +08004533 const struct auto_pin_cfg *cfg)
4534{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004535 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004536}
4537
4538static int vt1718S_parse_auto_config(struct hda_codec *codec)
4539{
4540 struct via_spec *spec = codec->spec;
4541 int err;
4542
4543 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4544
4545 if (err < 0)
4546 return err;
4547 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4548 if (err < 0)
4549 return err;
4550 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4551 return 0; /* can't find valid BIOS pin config */
4552
4553 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4554 if (err < 0)
4555 return err;
4556 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4557 if (err < 0)
4558 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02004559 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004560 if (err < 0)
4561 return err;
4562
4563 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4564
4565 fill_dig_outs(codec);
4566
4567 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4568 spec->dig_in_nid = 0x13;
4569
4570 if (spec->kctls.list)
4571 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4572
4573 spec->input_mux = &spec->private_imux[0];
4574
4575 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004576 via_hp_build(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004577
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004578 via_smart51_build(spec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004579
4580 return 1;
4581}
4582
4583#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004584static const struct hda_amp_list vt1718S_loopbacks[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004585 { 0x21, HDA_INPUT, 1 },
4586 { 0x21, HDA_INPUT, 2 },
4587 { 0x21, HDA_INPUT, 3 },
4588 { 0x21, HDA_INPUT, 4 },
4589 { } /* end */
4590};
4591#endif
4592
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004593static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4594{
4595 struct via_spec *spec = codec->spec;
4596 int imux_is_smixer;
4597 unsigned int parm;
4598 /* MUX6 (1eh) = stereo mixer */
4599 imux_is_smixer =
4600 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4601 /* inputs */
4602 /* PW 5/6/7 (29h/2ah/2bh) */
4603 parm = AC_PWRST_D3;
4604 set_pin_power_state(codec, 0x29, &parm);
4605 set_pin_power_state(codec, 0x2a, &parm);
4606 set_pin_power_state(codec, 0x2b, &parm);
4607 if (imux_is_smixer)
4608 parm = AC_PWRST_D0;
4609 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4610 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4611 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4612 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4613 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4614
4615 /* outputs */
4616 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4617 parm = AC_PWRST_D3;
4618 set_pin_power_state(codec, 0x27, &parm);
4619 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4620 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4621
4622 /* PW2 (26h), AOW2 (ah) */
4623 parm = AC_PWRST_D3;
4624 set_pin_power_state(codec, 0x26, &parm);
4625 if (spec->smart51_enabled)
4626 set_pin_power_state(codec, 0x2b, &parm);
4627 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4628
4629 /* PW0 (24h), AOW0 (8h) */
4630 parm = AC_PWRST_D3;
4631 set_pin_power_state(codec, 0x24, &parm);
4632 if (!spec->hp_independent_mode) /* check for redirected HP */
4633 set_pin_power_state(codec, 0x28, &parm);
4634 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4635 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4636 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4637 imux_is_smixer ? AC_PWRST_D0 : parm);
4638
4639 /* PW1 (25h), AOW1 (9h) */
4640 parm = AC_PWRST_D3;
4641 set_pin_power_state(codec, 0x25, &parm);
4642 if (spec->smart51_enabled)
4643 set_pin_power_state(codec, 0x2a, &parm);
4644 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4645
4646 if (spec->hp_independent_mode) {
4647 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4648 parm = AC_PWRST_D3;
4649 set_pin_power_state(codec, 0x28, &parm);
4650 snd_hda_codec_write(codec, 0x1b, 0,
4651 AC_VERB_SET_POWER_STATE, parm);
4652 snd_hda_codec_write(codec, 0x34, 0,
4653 AC_VERB_SET_POWER_STATE, parm);
4654 snd_hda_codec_write(codec, 0xc, 0,
4655 AC_VERB_SET_POWER_STATE, parm);
4656 }
4657}
4658
Lydia Wangeb7188c2009-10-10 19:08:34 +08004659static int patch_vt1718S(struct hda_codec *codec)
4660{
4661 struct via_spec *spec;
4662 int err;
4663
4664 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004665 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004666 if (spec == NULL)
4667 return -ENOMEM;
4668
Lydia Wangeb7188c2009-10-10 19:08:34 +08004669 /* automatic parse from the BIOS config */
4670 err = vt1718S_parse_auto_config(codec);
4671 if (err < 0) {
4672 via_free(codec);
4673 return err;
4674 } else if (!err) {
4675 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4676 "from BIOS. Using genenic mode...\n");
4677 }
4678
4679 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4680 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4681
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004682 if (codec->vendor_id == 0x11060441)
4683 spec->stream_name_analog = "VT2020 Analog";
4684 else if (codec->vendor_id == 0x11064441)
4685 spec->stream_name_analog = "VT1828S Analog";
4686 else
4687 spec->stream_name_analog = "VT1718S Analog";
Lydia Wangeb7188c2009-10-10 19:08:34 +08004688 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4689 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4690
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004691 if (codec->vendor_id == 0x11060441)
4692 spec->stream_name_digital = "VT2020 Digital";
4693 else if (codec->vendor_id == 0x11064441)
4694 spec->stream_name_digital = "VT1828S Digital";
4695 else
4696 spec->stream_name_digital = "VT1718S Digital";
Lydia Wangeb7188c2009-10-10 19:08:34 +08004697 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004698 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
Lydia Wangeb7188c2009-10-10 19:08:34 +08004699 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4700
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004701 if (spec->adc_nids && spec->input_mux) {
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004702 override_mic_boost(codec, 0x2b, 0, 3, 40);
4703 override_mic_boost(codec, 0x29, 0, 3, 40);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004704 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4705 spec->num_mixers++;
4706 }
4707
4708 codec->patch_ops = via_patch_ops;
4709
4710 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11004711 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004712
4713#ifdef CONFIG_SND_HDA_POWER_SAVE
4714 spec->loopback.amplist = vt1718S_loopbacks;
4715#endif
4716
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004717 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4718
Lydia Wangeb7188c2009-10-10 19:08:34 +08004719 return 0;
4720}
Lydia Wangf3db4232009-10-10 19:08:41 +08004721
4722/* Patch for VT1716S */
4723
4724static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4725 struct snd_ctl_elem_info *uinfo)
4726{
4727 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4728 uinfo->count = 1;
4729 uinfo->value.integer.min = 0;
4730 uinfo->value.integer.max = 1;
4731 return 0;
4732}
4733
4734static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4735 struct snd_ctl_elem_value *ucontrol)
4736{
4737 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4738 int index = 0;
4739
4740 index = snd_hda_codec_read(codec, 0x26, 0,
4741 AC_VERB_GET_CONNECT_SEL, 0);
4742 if (index != -1)
4743 *ucontrol->value.integer.value = index;
4744
4745 return 0;
4746}
4747
4748static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4749 struct snd_ctl_elem_value *ucontrol)
4750{
4751 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4752 struct via_spec *spec = codec->spec;
4753 int index = *ucontrol->value.integer.value;
4754
4755 snd_hda_codec_write(codec, 0x26, 0,
4756 AC_VERB_SET_CONNECT_SEL, index);
4757 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004758 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08004759 return 1;
4760}
4761
4762/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004763static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004764 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4765 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4766 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4767 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4768 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4769 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4770 HDA_INPUT),
4771 {
4772 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4773 .name = "Input Source",
4774 .count = 1,
4775 .info = via_mux_enum_info,
4776 .get = via_mux_enum_get,
4777 .put = via_mux_enum_put,
4778 },
4779 { } /* end */
4780};
4781
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004782static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004783 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4784 {
4785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4786 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004787 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08004788 .count = 1,
4789 .info = vt1716s_dmic_info,
4790 .get = vt1716s_dmic_get,
4791 .put = vt1716s_dmic_put,
4792 },
4793 {} /* end */
4794};
4795
4796
4797/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004798static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004799 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4800 { } /* end */
4801};
4802
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004803static const struct hda_verb vt1716S_volume_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004804 /*
4805 * Unmute ADC0-1 and set the default input to mic-in
4806 */
4807 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4808 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4809
4810
4811 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4812 * mixer widget
4813 */
4814 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4815 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4816 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4817 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4818 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4819 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4820
4821 /* MUX Indices: Stereo Mixer = 5 */
4822 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4823
4824 /* Setup default input of PW4 to MW0 */
4825 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4826
4827 /* Setup default input of SW1 as MW0 */
4828 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4829
4830 /* Setup default input of SW4 as AOW0 */
4831 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4832
4833 /* PW9 PW10 Output enable */
4834 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4835 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4836
4837 /* Unmute SW1, PW12 */
4838 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4839 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4840 /* PW12 Output enable */
4841 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4842 /* Enable Boost Volume backdoor */
4843 {0x1, 0xf8a, 0x80},
4844 /* don't bybass mixer */
4845 {0x1, 0xf88, 0xc0},
4846 /* Enable mono output */
4847 {0x1, 0xf90, 0x08},
4848 { }
4849};
4850
4851
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004852static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004853 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4854 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4855 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4856 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4857 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4858 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4859 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4860 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4861 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4862 { }
4863};
4864
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004865static const struct hda_pcm_stream vt1716S_pcm_analog_playback = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004866 .substreams = 2,
4867 .channels_min = 2,
4868 .channels_max = 6,
4869 .nid = 0x10, /* NID to query formats and rates */
4870 .ops = {
4871 .open = via_playback_pcm_open,
4872 .prepare = via_playback_multi_pcm_prepare,
4873 .cleanup = via_playback_multi_pcm_cleanup,
4874 .close = via_pcm_open_close,
4875 },
4876};
4877
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004878static const struct hda_pcm_stream vt1716S_pcm_analog_capture = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004879 .substreams = 2,
4880 .channels_min = 2,
4881 .channels_max = 2,
4882 .nid = 0x13, /* NID to query formats and rates */
4883 .ops = {
4884 .open = via_pcm_open_close,
4885 .prepare = via_capture_pcm_prepare,
4886 .cleanup = via_capture_pcm_cleanup,
4887 .close = via_pcm_open_close,
4888 },
4889};
4890
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004891static const struct hda_pcm_stream vt1716S_pcm_digital_playback = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004892 .substreams = 2,
4893 .channels_min = 2,
4894 .channels_max = 2,
Lydia Wangf3db4232009-10-10 19:08:41 +08004895 /* NID is set in via_build_pcms */
4896 .ops = {
4897 .open = via_dig_playback_pcm_open,
4898 .close = via_dig_playback_pcm_close,
4899 .prepare = via_dig_playback_pcm_prepare,
4900 .cleanup = via_dig_playback_pcm_cleanup
4901 },
4902};
4903
4904/* fill in the dac_nids table from the parsed pin configuration */
4905static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4906 const struct auto_pin_cfg *cfg)
4907{ int i;
4908 hda_nid_t nid;
4909
4910 spec->multiout.num_dacs = cfg->line_outs;
4911
4912 spec->multiout.dac_nids = spec->private_dac_nids;
4913
4914 for (i = 0; i < 3; i++) {
4915 nid = cfg->line_out_pins[i];
4916 if (nid) {
4917 /* config dac list */
4918 switch (i) {
4919 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02004920 spec->private_dac_nids[i] = 0x10;
Lydia Wangf3db4232009-10-10 19:08:41 +08004921 break;
4922 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004923 spec->private_dac_nids[i] = 0x25;
Lydia Wangf3db4232009-10-10 19:08:41 +08004924 break;
4925 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02004926 spec->private_dac_nids[i] = 0x11;
Lydia Wangf3db4232009-10-10 19:08:41 +08004927 break;
4928 }
4929 }
4930 }
4931
4932 return 0;
4933}
4934
4935/* add playback controls from the parsed DAC table */
4936static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4937 const struct auto_pin_cfg *cfg)
4938{
4939 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01004940 static const char * const chname[3] = {
4941 "Front", "Surround", "C/LFE"
4942 };
Lydia Wangf3db4232009-10-10 19:08:41 +08004943 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4944 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4945 hda_nid_t nid, nid_vol, nid_mute;
4946 int i, err;
4947
4948 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4949 nid = cfg->line_out_pins[i];
4950
4951 if (!nid)
4952 continue;
4953
4954 nid_vol = nid_vols[i];
4955 nid_mute = nid_mutes[i];
4956
4957 if (i == AUTO_SEQ_CENLFE) {
4958 err = via_add_control(
4959 spec, VIA_CTL_WIDGET_VOL,
4960 "Center Playback Volume",
4961 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
4962 if (err < 0)
4963 return err;
4964 err = via_add_control(
4965 spec, VIA_CTL_WIDGET_VOL,
4966 "LFE Playback Volume",
4967 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
4968 if (err < 0)
4969 return err;
4970 err = via_add_control(
4971 spec, VIA_CTL_WIDGET_MUTE,
4972 "Center Playback Switch",
4973 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4974 HDA_OUTPUT));
4975 if (err < 0)
4976 return err;
4977 err = via_add_control(
4978 spec, VIA_CTL_WIDGET_MUTE,
4979 "LFE Playback Switch",
4980 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4981 HDA_OUTPUT));
4982 if (err < 0)
4983 return err;
4984 } else if (i == AUTO_SEQ_FRONT) {
4985
4986 err = via_add_control(
4987 spec, VIA_CTL_WIDGET_VOL,
4988 "Master Front Playback Volume",
4989 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4990 if (err < 0)
4991 return err;
4992 err = via_add_control(
4993 spec, VIA_CTL_WIDGET_MUTE,
4994 "Master Front Playback Switch",
4995 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4996 if (err < 0)
4997 return err;
4998
4999 sprintf(name, "%s Playback Volume", chname[i]);
5000 err = via_add_control(
5001 spec, VIA_CTL_WIDGET_VOL, name,
5002 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5003 if (err < 0)
5004 return err;
5005 sprintf(name, "%s Playback Switch", chname[i]);
5006 err = via_add_control(
5007 spec, VIA_CTL_WIDGET_MUTE, name,
5008 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5009 HDA_OUTPUT));
5010 if (err < 0)
5011 return err;
5012 } else {
5013 sprintf(name, "%s Playback Volume", chname[i]);
5014 err = via_add_control(
5015 spec, VIA_CTL_WIDGET_VOL, name,
5016 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5017 if (err < 0)
5018 return err;
5019 sprintf(name, "%s Playback Switch", chname[i]);
5020 err = via_add_control(
5021 spec, VIA_CTL_WIDGET_MUTE, name,
5022 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5023 HDA_OUTPUT));
5024 if (err < 0)
5025 return err;
5026 }
5027 }
5028 return 0;
5029}
5030
5031static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5032{
5033 int err;
5034
5035 if (!pin)
5036 return 0;
5037
5038 spec->multiout.hp_nid = 0x25; /* AOW3 */
5039 spec->hp_independent_mode_index = 1;
5040
5041 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5042 "Headphone Playback Volume",
5043 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5044 if (err < 0)
5045 return err;
5046
5047 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5048 "Headphone Playback Switch",
5049 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5050 if (err < 0)
5051 return err;
5052
5053 create_hp_imux(spec);
5054 return 0;
5055}
5056
5057/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005058static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangf3db4232009-10-10 19:08:41 +08005059 const struct auto_pin_cfg *cfg)
5060{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005061 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
Lydia Wangf3db4232009-10-10 19:08:41 +08005062}
5063
5064static int vt1716S_parse_auto_config(struct hda_codec *codec)
5065{
5066 struct via_spec *spec = codec->spec;
5067 int err;
5068
5069 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5070 if (err < 0)
5071 return err;
5072 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5073 if (err < 0)
5074 return err;
5075 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5076 return 0; /* can't find valid BIOS pin config */
5077
5078 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5079 if (err < 0)
5080 return err;
5081 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5082 if (err < 0)
5083 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005084 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangf3db4232009-10-10 19:08:41 +08005085 if (err < 0)
5086 return err;
5087
5088 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5089
5090 fill_dig_outs(codec);
5091
5092 if (spec->kctls.list)
5093 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5094
5095 spec->input_mux = &spec->private_imux[0];
5096
5097 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005098 via_hp_build(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005099
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005100 via_smart51_build(spec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005101
5102 return 1;
5103}
5104
5105#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005106static const struct hda_amp_list vt1716S_loopbacks[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08005107 { 0x16, HDA_INPUT, 1 },
5108 { 0x16, HDA_INPUT, 2 },
5109 { 0x16, HDA_INPUT, 3 },
5110 { 0x16, HDA_INPUT, 4 },
5111 { } /* end */
5112};
5113#endif
5114
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005115static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5116{
5117 struct via_spec *spec = codec->spec;
5118 int imux_is_smixer;
5119 unsigned int parm;
5120 unsigned int mono_out, present;
5121 /* SW0 (17h) = stereo mixer */
5122 imux_is_smixer =
5123 (snd_hda_codec_read(codec, 0x17, 0,
5124 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5125 /* inputs */
5126 /* PW 1/2/5 (1ah/1bh/1eh) */
5127 parm = AC_PWRST_D3;
5128 set_pin_power_state(codec, 0x1a, &parm);
5129 set_pin_power_state(codec, 0x1b, &parm);
5130 set_pin_power_state(codec, 0x1e, &parm);
5131 if (imux_is_smixer)
5132 parm = AC_PWRST_D0;
5133 /* SW0 (17h), AIW0(13h) */
5134 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5135 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5136
5137 parm = AC_PWRST_D3;
5138 set_pin_power_state(codec, 0x1e, &parm);
5139 /* PW11 (22h) */
5140 if (spec->dmic_enabled)
5141 set_pin_power_state(codec, 0x22, &parm);
5142 else
5143 snd_hda_codec_write(codec, 0x22, 0,
5144 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5145
5146 /* SW2(26h), AIW1(14h) */
5147 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5148 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5149
5150 /* outputs */
5151 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5152 parm = AC_PWRST_D3;
5153 set_pin_power_state(codec, 0x19, &parm);
5154 /* Smart 5.1 PW2(1bh) */
5155 if (spec->smart51_enabled)
5156 set_pin_power_state(codec, 0x1b, &parm);
5157 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5158 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5159
5160 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5161 parm = AC_PWRST_D3;
5162 set_pin_power_state(codec, 0x23, &parm);
5163 /* Smart 5.1 PW1(1ah) */
5164 if (spec->smart51_enabled)
5165 set_pin_power_state(codec, 0x1a, &parm);
5166 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5167
5168 /* Smart 5.1 PW5(1eh) */
5169 if (spec->smart51_enabled)
5170 set_pin_power_state(codec, 0x1e, &parm);
5171 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5172
5173 /* Mono out */
5174 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5175 present = snd_hda_jack_detect(codec, 0x1c);
5176
5177 if (present)
5178 mono_out = 0;
5179 else {
5180 present = snd_hda_jack_detect(codec, 0x1d);
5181 if (!spec->hp_independent_mode && present)
5182 mono_out = 0;
5183 else
5184 mono_out = 1;
5185 }
5186 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5187 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5188 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5189 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5190
5191 /* PW 3/4 (1ch/1dh) */
5192 parm = AC_PWRST_D3;
5193 set_pin_power_state(codec, 0x1c, &parm);
5194 set_pin_power_state(codec, 0x1d, &parm);
5195 /* HP Independent Mode, power on AOW3 */
5196 if (spec->hp_independent_mode)
5197 snd_hda_codec_write(codec, 0x25, 0,
5198 AC_VERB_SET_POWER_STATE, parm);
5199
5200 /* force to D0 for internal Speaker */
5201 /* MW0 (16h), AOW0 (10h) */
5202 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5203 imux_is_smixer ? AC_PWRST_D0 : parm);
5204 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5205 mono_out ? AC_PWRST_D0 : parm);
5206}
5207
Lydia Wangf3db4232009-10-10 19:08:41 +08005208static int patch_vt1716S(struct hda_codec *codec)
5209{
5210 struct via_spec *spec;
5211 int err;
5212
5213 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005214 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005215 if (spec == NULL)
5216 return -ENOMEM;
5217
Lydia Wangf3db4232009-10-10 19:08:41 +08005218 /* automatic parse from the BIOS config */
5219 err = vt1716S_parse_auto_config(codec);
5220 if (err < 0) {
5221 via_free(codec);
5222 return err;
5223 } else if (!err) {
5224 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5225 "from BIOS. Using genenic mode...\n");
5226 }
5227
5228 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5229 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5230
5231 spec->stream_name_analog = "VT1716S Analog";
5232 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5233 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5234
5235 spec->stream_name_digital = "VT1716S Digital";
5236 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5237
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005238 if (spec->adc_nids && spec->input_mux) {
Lydia Wangf3db4232009-10-10 19:08:41 +08005239 override_mic_boost(codec, 0x1a, 0, 3, 40);
5240 override_mic_boost(codec, 0x1e, 0, 3, 40);
5241 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5242 spec->num_mixers++;
5243 }
5244
5245 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5246 spec->num_mixers++;
5247
5248 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5249
5250 codec->patch_ops = via_patch_ops;
5251
5252 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005253 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangf3db4232009-10-10 19:08:41 +08005254
5255#ifdef CONFIG_SND_HDA_POWER_SAVE
5256 spec->loopback.amplist = vt1716S_loopbacks;
5257#endif
5258
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005259 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08005260 return 0;
5261}
Lydia Wang25eaba22009-10-10 19:08:43 +08005262
5263/* for vt2002P */
5264
5265/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005266static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005267 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5268 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5269 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5270 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5271 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5272 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5273 HDA_INPUT),
5274 {
5275 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5276 /* The multiple "Capture Source" controls confuse alsamixer
5277 * So call somewhat different..
5278 */
5279 /* .name = "Capture Source", */
5280 .name = "Input Source",
5281 .count = 2,
5282 .info = via_mux_enum_info,
5283 .get = via_mux_enum_get,
5284 .put = via_mux_enum_put,
5285 },
5286 { } /* end */
5287};
5288
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005289static const struct hda_verb vt2002P_volume_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08005290 /* Class-D speaker related verbs */
5291 {0x1, 0xfe0, 0x4},
5292 {0x1, 0xfe9, 0x80},
5293 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08005294 /*
5295 * Unmute ADC0-1 and set the default input to mic-in
5296 */
5297 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5298 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5299
5300
5301 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5302 * mixer widget
5303 */
5304 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5305 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5306 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5307 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5308 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5309 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5310
5311 /* MUX Indices: Mic = 0 */
5312 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5313 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5314
5315 /* PW9 Output enable */
5316 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5317
5318 /* Enable Boost Volume backdoor */
5319 {0x1, 0xfb9, 0x24},
5320
5321 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5322 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5323 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5324 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5325 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5326 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5327 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5328 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5329 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5330
5331 /* set MUX0/1/4/8 = 0 (AOW0) */
5332 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5333 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5334 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5335 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5336
5337 /* set PW0 index=0 (MW0) */
5338 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5339
5340 /* Enable AOW0 to MW9 */
5341 {0x1, 0xfb8, 0x88},
5342 { }
5343};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005344static const struct hda_verb vt1802_volume_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08005345 /*
5346 * Unmute ADC0-1 and set the default input to mic-in
5347 */
5348 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5349 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5350
5351
5352 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5353 * mixer widget
5354 */
5355 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5356 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5357 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5358 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5359 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5360 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5361
5362 /* MUX Indices: Mic = 0 */
5363 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5364 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5365
5366 /* PW9 Output enable */
5367 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5368
5369 /* Enable Boost Volume backdoor */
5370 {0x1, 0xfb9, 0x24},
5371
5372 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5373 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5374 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5375 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5376 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5377 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5378 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5379 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5380 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5381
5382 /* set MUX0/1/4/8 = 0 (AOW0) */
5383 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5384 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5385 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5386 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5387
5388 /* set PW0 index=0 (MW0) */
5389 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5390
5391 /* Enable AOW0 to MW9 */
5392 {0x1, 0xfb8, 0x88},
5393 { }
5394};
Lydia Wang25eaba22009-10-10 19:08:43 +08005395
5396
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005397static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005398 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5399 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5400 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5401 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5402 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5403 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5404 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5405 { }
5406};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005407static const struct hda_verb vt1802_uniwill_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08005408 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5409 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5410 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5411 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5412 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5413 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5414 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5415 { }
5416};
Lydia Wang25eaba22009-10-10 19:08:43 +08005417
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005418static const struct hda_pcm_stream vt2002P_pcm_analog_playback = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005419 .substreams = 2,
5420 .channels_min = 2,
5421 .channels_max = 2,
5422 .nid = 0x8, /* NID to query formats and rates */
5423 .ops = {
5424 .open = via_playback_pcm_open,
5425 .prepare = via_playback_multi_pcm_prepare,
5426 .cleanup = via_playback_multi_pcm_cleanup,
5427 .close = via_pcm_open_close,
5428 },
5429};
5430
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005431static const struct hda_pcm_stream vt2002P_pcm_analog_capture = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005432 .substreams = 2,
5433 .channels_min = 2,
5434 .channels_max = 2,
5435 .nid = 0x10, /* NID to query formats and rates */
5436 .ops = {
5437 .open = via_pcm_open_close,
5438 .prepare = via_capture_pcm_prepare,
5439 .cleanup = via_capture_pcm_cleanup,
5440 .close = via_pcm_open_close,
5441 },
5442};
5443
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005444static const struct hda_pcm_stream vt2002P_pcm_digital_playback = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005445 .substreams = 1,
5446 .channels_min = 2,
5447 .channels_max = 2,
Lydia Wang25eaba22009-10-10 19:08:43 +08005448 /* NID is set in via_build_pcms */
5449 .ops = {
5450 .open = via_dig_playback_pcm_open,
5451 .close = via_dig_playback_pcm_close,
5452 .prepare = via_dig_playback_pcm_prepare,
5453 .cleanup = via_dig_playback_pcm_cleanup
5454 },
5455};
5456
5457/* fill in the dac_nids table from the parsed pin configuration */
5458static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5459 const struct auto_pin_cfg *cfg)
5460{
5461 spec->multiout.num_dacs = 1;
5462 spec->multiout.dac_nids = spec->private_dac_nids;
5463 if (cfg->line_out_pins[0])
Takashi Iwaidda14412011-05-02 11:29:30 +02005464 spec->private_dac_nids[0] = 0x8;
Lydia Wang25eaba22009-10-10 19:08:43 +08005465 return 0;
5466}
5467
5468/* add playback controls from the parsed DAC table */
5469static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5470 const struct auto_pin_cfg *cfg)
5471{
5472 int err;
Lydia Wang118909562011-03-23 17:57:34 +08005473 hda_nid_t sw_nid;
Lydia Wang25eaba22009-10-10 19:08:43 +08005474
5475 if (!cfg->line_out_pins[0])
5476 return -1;
5477
Lydia Wang118909562011-03-23 17:57:34 +08005478 if (spec->codec_type == VT1802)
5479 sw_nid = 0x28;
5480 else
5481 sw_nid = 0x26;
Lydia Wang25eaba22009-10-10 19:08:43 +08005482
5483 /* Line-Out: PortE */
5484 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5485 "Master Front Playback Volume",
5486 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5487 if (err < 0)
5488 return err;
5489 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5490 "Master Front Playback Switch",
Lydia Wang118909562011-03-23 17:57:34 +08005491 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
Lydia Wang25eaba22009-10-10 19:08:43 +08005492 if (err < 0)
5493 return err;
5494
5495 return 0;
5496}
5497
5498static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5499{
5500 int err;
5501
5502 if (!pin)
5503 return 0;
5504
5505 spec->multiout.hp_nid = 0x9;
5506 spec->hp_independent_mode_index = 1;
5507
5508 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5509 "Headphone Playback Volume",
5510 HDA_COMPOSE_AMP_VAL(
5511 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5512 if (err < 0)
5513 return err;
5514
5515 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5516 "Headphone Playback Switch",
5517 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5518 if (err < 0)
5519 return err;
5520
5521 create_hp_imux(spec);
5522 return 0;
5523}
5524
5525/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005526static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wang25eaba22009-10-10 19:08:43 +08005527 const struct auto_pin_cfg *cfg)
5528{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005529 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
Lydia Wang25eaba22009-10-10 19:08:43 +08005530}
5531
5532static int vt2002P_parse_auto_config(struct hda_codec *codec)
5533{
5534 struct via_spec *spec = codec->spec;
5535 int err;
5536
5537
5538 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5539 if (err < 0)
5540 return err;
5541
5542 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5543 if (err < 0)
5544 return err;
5545
5546 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5547 return 0; /* can't find valid BIOS pin config */
5548
5549 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5550 if (err < 0)
5551 return err;
5552 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5553 if (err < 0)
5554 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005555 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wang25eaba22009-10-10 19:08:43 +08005556 if (err < 0)
5557 return err;
5558
5559 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5560
5561 fill_dig_outs(codec);
5562
5563 if (spec->kctls.list)
5564 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5565
5566 spec->input_mux = &spec->private_imux[0];
5567
5568 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005569 via_hp_build(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08005570
5571 return 1;
5572}
5573
5574#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005575static const struct hda_amp_list vt2002P_loopbacks[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005576 { 0x21, HDA_INPUT, 0 },
5577 { 0x21, HDA_INPUT, 1 },
5578 { 0x21, HDA_INPUT, 2 },
5579 { } /* end */
5580};
5581#endif
5582
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005583static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5584{
5585 struct via_spec *spec = codec->spec;
5586 int imux_is_smixer;
5587 unsigned int parm;
5588 unsigned int present;
5589 /* MUX9 (1eh) = stereo mixer */
5590 imux_is_smixer =
5591 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5592 /* inputs */
5593 /* PW 5/6/7 (29h/2ah/2bh) */
5594 parm = AC_PWRST_D3;
5595 set_pin_power_state(codec, 0x29, &parm);
5596 set_pin_power_state(codec, 0x2a, &parm);
5597 set_pin_power_state(codec, 0x2b, &parm);
5598 parm = AC_PWRST_D0;
5599 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5600 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5601 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5602 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5603 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5604
5605 /* outputs */
5606 /* AOW0 (8h)*/
5607 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5608
Lydia Wang118909562011-03-23 17:57:34 +08005609 if (spec->codec_type == VT1802) {
5610 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5611 parm = AC_PWRST_D3;
5612 set_pin_power_state(codec, 0x28, &parm);
5613 snd_hda_codec_write(codec, 0x18, 0,
5614 AC_VERB_SET_POWER_STATE, parm);
5615 snd_hda_codec_write(codec, 0x38, 0,
5616 AC_VERB_SET_POWER_STATE, parm);
5617 } else {
5618 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5619 parm = AC_PWRST_D3;
5620 set_pin_power_state(codec, 0x26, &parm);
5621 snd_hda_codec_write(codec, 0x1c, 0,
5622 AC_VERB_SET_POWER_STATE, parm);
5623 snd_hda_codec_write(codec, 0x37, 0,
5624 AC_VERB_SET_POWER_STATE, parm);
5625 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005626
Lydia Wang118909562011-03-23 17:57:34 +08005627 if (spec->codec_type == VT1802) {
5628 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5629 parm = AC_PWRST_D3;
5630 set_pin_power_state(codec, 0x25, &parm);
5631 snd_hda_codec_write(codec, 0x15, 0,
5632 AC_VERB_SET_POWER_STATE, parm);
5633 snd_hda_codec_write(codec, 0x35, 0,
5634 AC_VERB_SET_POWER_STATE, parm);
5635 } else {
5636 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5637 parm = AC_PWRST_D3;
5638 set_pin_power_state(codec, 0x25, &parm);
5639 snd_hda_codec_write(codec, 0x19, 0,
5640 AC_VERB_SET_POWER_STATE, parm);
5641 snd_hda_codec_write(codec, 0x35, 0,
5642 AC_VERB_SET_POWER_STATE, parm);
5643 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005644
5645 if (spec->hp_independent_mode)
5646 snd_hda_codec_write(codec, 0x9, 0,
5647 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5648
5649 /* Class-D */
5650 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5651 present = snd_hda_jack_detect(codec, 0x25);
5652
5653 parm = AC_PWRST_D3;
5654 set_pin_power_state(codec, 0x24, &parm);
5655 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08005656 if (spec->codec_type == VT1802)
5657 snd_hda_codec_write(codec, 0x14, 0,
5658 AC_VERB_SET_POWER_STATE, parm);
5659 else
5660 snd_hda_codec_write(codec, 0x18, 0,
5661 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005662 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5663
5664 /* Mono Out */
5665 present = snd_hda_jack_detect(codec, 0x26);
5666
5667 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08005668 if (spec->codec_type == VT1802) {
5669 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5670 snd_hda_codec_write(codec, 0x33, 0,
5671 AC_VERB_SET_POWER_STATE, parm);
5672 snd_hda_codec_write(codec, 0x1c, 0,
5673 AC_VERB_SET_POWER_STATE, parm);
5674 snd_hda_codec_write(codec, 0x3c, 0,
5675 AC_VERB_SET_POWER_STATE, parm);
5676 } else {
5677 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5678 snd_hda_codec_write(codec, 0x31, 0,
5679 AC_VERB_SET_POWER_STATE, parm);
5680 snd_hda_codec_write(codec, 0x17, 0,
5681 AC_VERB_SET_POWER_STATE, parm);
5682 snd_hda_codec_write(codec, 0x3b, 0,
5683 AC_VERB_SET_POWER_STATE, parm);
5684 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005685 /* MW9 (21h) */
5686 if (imux_is_smixer || !is_aa_path_mute(codec))
5687 snd_hda_codec_write(codec, 0x21, 0,
5688 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5689 else
5690 snd_hda_codec_write(codec, 0x21, 0,
5691 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5692}
Lydia Wang25eaba22009-10-10 19:08:43 +08005693
5694/* patch for vt2002P */
5695static int patch_vt2002P(struct hda_codec *codec)
5696{
5697 struct via_spec *spec;
5698 int err;
5699
5700 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005701 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08005702 if (spec == NULL)
5703 return -ENOMEM;
5704
Lydia Wang25eaba22009-10-10 19:08:43 +08005705 /* automatic parse from the BIOS config */
5706 err = vt2002P_parse_auto_config(codec);
5707 if (err < 0) {
5708 via_free(codec);
5709 return err;
5710 } else if (!err) {
5711 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5712 "from BIOS. Using genenic mode...\n");
5713 }
5714
Lydia Wang118909562011-03-23 17:57:34 +08005715 if (spec->codec_type == VT1802)
5716 spec->init_verbs[spec->num_iverbs++] =
5717 vt1802_volume_init_verbs;
5718 else
5719 spec->init_verbs[spec->num_iverbs++] =
5720 vt2002P_volume_init_verbs;
Lydia Wang25eaba22009-10-10 19:08:43 +08005721
Lydia Wang118909562011-03-23 17:57:34 +08005722 if (spec->codec_type == VT1802)
5723 spec->init_verbs[spec->num_iverbs++] =
5724 vt1802_uniwill_init_verbs;
5725 else
5726 spec->init_verbs[spec->num_iverbs++] =
5727 vt2002P_uniwill_init_verbs;
5728
5729 if (spec->codec_type == VT1802)
5730 spec->stream_name_analog = "VT1802 Analog";
5731 else
5732 spec->stream_name_analog = "VT2002P Analog";
Lydia Wang25eaba22009-10-10 19:08:43 +08005733 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5734 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5735
Lydia Wang118909562011-03-23 17:57:34 +08005736 if (spec->codec_type == VT1802)
5737 spec->stream_name_digital = "VT1802 Digital";
5738 else
5739 spec->stream_name_digital = "VT2002P Digital";
Lydia Wang25eaba22009-10-10 19:08:43 +08005740 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5741
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005742 if (spec->adc_nids && spec->input_mux) {
Lydia Wang25eaba22009-10-10 19:08:43 +08005743 override_mic_boost(codec, 0x2b, 0, 3, 40);
5744 override_mic_boost(codec, 0x29, 0, 3, 40);
5745 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5746 spec->num_mixers++;
5747 }
5748
5749 codec->patch_ops = via_patch_ops;
5750
5751 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005752 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wang25eaba22009-10-10 19:08:43 +08005753
5754#ifdef CONFIG_SND_HDA_POWER_SAVE
5755 spec->loopback.amplist = vt2002P_loopbacks;
5756#endif
5757
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005758 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08005759 return 0;
5760}
Lydia Wangab6734e2009-10-10 19:08:46 +08005761
5762/* for vt1812 */
5763
5764/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005765static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005766 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5767 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5768 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5769 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5770 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5771 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5772 HDA_INPUT),
5773 {
5774 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5775 /* The multiple "Capture Source" controls confuse alsamixer
5776 * So call somewhat different..
5777 */
5778 .name = "Input Source",
5779 .count = 2,
5780 .info = via_mux_enum_info,
5781 .get = via_mux_enum_get,
5782 .put = via_mux_enum_put,
5783 },
5784 { } /* end */
5785};
5786
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005787static const struct hda_verb vt1812_volume_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005788 /*
5789 * Unmute ADC0-1 and set the default input to mic-in
5790 */
5791 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5792 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5793
5794
5795 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5796 * mixer widget
5797 */
5798 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5799 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5800 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5801 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5802 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5803 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5804
5805 /* MUX Indices: Mic = 0 */
5806 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5807 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5808
5809 /* PW9 Output enable */
5810 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5811
5812 /* Enable Boost Volume backdoor */
5813 {0x1, 0xfb9, 0x24},
5814
5815 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5816 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5817 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5818 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5819 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5820 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5821 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5822 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5823 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5824 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5825 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5826
5827 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5828 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5829 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5830 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5831 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5832 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5833
5834 /* Enable AOW0 to MW9 */
5835 {0x1, 0xfb8, 0xa8},
5836 { }
5837};
5838
5839
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005840static const struct hda_verb vt1812_uniwill_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005841 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5842 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5843 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5844 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5845 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5846 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5847 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5848 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5849 { }
5850};
5851
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005852static const struct hda_pcm_stream vt1812_pcm_analog_playback = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005853 .substreams = 2,
5854 .channels_min = 2,
5855 .channels_max = 2,
5856 .nid = 0x8, /* NID to query formats and rates */
5857 .ops = {
5858 .open = via_playback_pcm_open,
5859 .prepare = via_playback_multi_pcm_prepare,
5860 .cleanup = via_playback_multi_pcm_cleanup,
5861 .close = via_pcm_open_close,
5862 },
5863};
5864
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005865static const struct hda_pcm_stream vt1812_pcm_analog_capture = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005866 .substreams = 2,
5867 .channels_min = 2,
5868 .channels_max = 2,
5869 .nid = 0x10, /* NID to query formats and rates */
5870 .ops = {
5871 .open = via_pcm_open_close,
5872 .prepare = via_capture_pcm_prepare,
5873 .cleanup = via_capture_pcm_cleanup,
5874 .close = via_pcm_open_close,
5875 },
5876};
5877
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005878static const struct hda_pcm_stream vt1812_pcm_digital_playback = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005879 .substreams = 1,
5880 .channels_min = 2,
5881 .channels_max = 2,
Lydia Wangab6734e2009-10-10 19:08:46 +08005882 /* NID is set in via_build_pcms */
5883 .ops = {
5884 .open = via_dig_playback_pcm_open,
5885 .close = via_dig_playback_pcm_close,
5886 .prepare = via_dig_playback_pcm_prepare,
5887 .cleanup = via_dig_playback_pcm_cleanup
5888 },
5889};
5890/* fill in the dac_nids table from the parsed pin configuration */
5891static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5892 const struct auto_pin_cfg *cfg)
5893{
5894 spec->multiout.num_dacs = 1;
5895 spec->multiout.dac_nids = spec->private_dac_nids;
5896 if (cfg->line_out_pins[0])
Takashi Iwaidda14412011-05-02 11:29:30 +02005897 spec->private_dac_nids[0] = 0x8;
Lydia Wangab6734e2009-10-10 19:08:46 +08005898 return 0;
5899}
5900
5901
5902/* add playback controls from the parsed DAC table */
5903static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5904 const struct auto_pin_cfg *cfg)
5905{
5906 int err;
5907
5908 if (!cfg->line_out_pins[0])
5909 return -1;
5910
5911 /* Line-Out: PortE */
5912 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Takashi Iwai3d83e572010-04-14 14:36:23 +02005913 "Front Playback Volume",
Lydia Wangab6734e2009-10-10 19:08:46 +08005914 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5915 if (err < 0)
5916 return err;
5917 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
Takashi Iwai3d83e572010-04-14 14:36:23 +02005918 "Front Playback Switch",
Lydia Wangab6734e2009-10-10 19:08:46 +08005919 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5920 if (err < 0)
5921 return err;
5922
5923 return 0;
5924}
5925
5926static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5927{
5928 int err;
5929
5930 if (!pin)
5931 return 0;
5932
5933 spec->multiout.hp_nid = 0x9;
5934 spec->hp_independent_mode_index = 1;
5935
5936
5937 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5938 "Headphone Playback Volume",
5939 HDA_COMPOSE_AMP_VAL(
5940 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5941 if (err < 0)
5942 return err;
5943
5944 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5945 "Headphone Playback Switch",
5946 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5947 if (err < 0)
5948 return err;
5949
5950 create_hp_imux(spec);
5951 return 0;
5952}
5953
5954/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005955static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangab6734e2009-10-10 19:08:46 +08005956 const struct auto_pin_cfg *cfg)
5957{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005958 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
Lydia Wangab6734e2009-10-10 19:08:46 +08005959}
5960
5961static int vt1812_parse_auto_config(struct hda_codec *codec)
5962{
5963 struct via_spec *spec = codec->spec;
5964 int err;
5965
5966
5967 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5968 if (err < 0)
5969 return err;
5970 fill_dig_outs(codec);
5971 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5972 if (err < 0)
5973 return err;
5974
5975 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5976 return 0; /* can't find valid BIOS pin config */
5977
5978 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5979 if (err < 0)
5980 return err;
5981 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5982 if (err < 0)
5983 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005984 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangab6734e2009-10-10 19:08:46 +08005985 if (err < 0)
5986 return err;
5987
5988 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5989
5990 fill_dig_outs(codec);
5991
5992 if (spec->kctls.list)
5993 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5994
5995 spec->input_mux = &spec->private_imux[0];
5996
5997 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005998 via_hp_build(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08005999
6000 return 1;
6001}
6002
6003#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02006004static const struct hda_amp_list vt1812_loopbacks[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08006005 { 0x21, HDA_INPUT, 0 },
6006 { 0x21, HDA_INPUT, 1 },
6007 { 0x21, HDA_INPUT, 2 },
6008 { } /* end */
6009};
6010#endif
6011
Lydia Wang3e95b9a2011-03-23 15:13:28 +08006012static void set_widgets_power_state_vt1812(struct hda_codec *codec)
6013{
6014 struct via_spec *spec = codec->spec;
6015 int imux_is_smixer =
6016 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
6017 unsigned int parm;
6018 unsigned int present;
6019 /* MUX10 (1eh) = stereo mixer */
6020 imux_is_smixer =
6021 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
6022 /* inputs */
6023 /* PW 5/6/7 (29h/2ah/2bh) */
6024 parm = AC_PWRST_D3;
6025 set_pin_power_state(codec, 0x29, &parm);
6026 set_pin_power_state(codec, 0x2a, &parm);
6027 set_pin_power_state(codec, 0x2b, &parm);
6028 parm = AC_PWRST_D0;
6029 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
6030 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
6031 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
6032 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
6033 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
6034
6035 /* outputs */
6036 /* AOW0 (8h)*/
6037 snd_hda_codec_write(codec, 0x8, 0,
6038 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6039
6040 /* PW4 (28h), MW4 (18h), MUX4(38h) */
6041 parm = AC_PWRST_D3;
6042 set_pin_power_state(codec, 0x28, &parm);
6043 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
6044 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
6045
6046 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
6047 parm = AC_PWRST_D3;
6048 set_pin_power_state(codec, 0x25, &parm);
6049 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
6050 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
6051 if (spec->hp_independent_mode)
6052 snd_hda_codec_write(codec, 0x9, 0,
6053 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6054
6055 /* Internal Speaker */
6056 /* PW0 (24h), MW0(14h), MUX0(34h) */
6057 present = snd_hda_jack_detect(codec, 0x25);
6058
6059 parm = AC_PWRST_D3;
6060 set_pin_power_state(codec, 0x24, &parm);
6061 if (present) {
6062 snd_hda_codec_write(codec, 0x14, 0,
6063 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6064 snd_hda_codec_write(codec, 0x34, 0,
6065 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6066 } else {
6067 snd_hda_codec_write(codec, 0x14, 0,
6068 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6069 snd_hda_codec_write(codec, 0x34, 0,
6070 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6071 }
6072
6073
6074 /* Mono Out */
6075 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6076 present = snd_hda_jack_detect(codec, 0x28);
6077
6078 parm = AC_PWRST_D3;
6079 set_pin_power_state(codec, 0x31, &parm);
6080 if (present) {
6081 snd_hda_codec_write(codec, 0x1c, 0,
6082 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6083 snd_hda_codec_write(codec, 0x3c, 0,
6084 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6085 snd_hda_codec_write(codec, 0x3e, 0,
6086 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6087 } else {
6088 snd_hda_codec_write(codec, 0x1c, 0,
6089 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6090 snd_hda_codec_write(codec, 0x3c, 0,
6091 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6092 snd_hda_codec_write(codec, 0x3e, 0,
6093 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6094 }
6095
6096 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6097 parm = AC_PWRST_D3;
6098 set_pin_power_state(codec, 0x33, &parm);
6099 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6100 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6101
6102}
Lydia Wangab6734e2009-10-10 19:08:46 +08006103
6104/* patch for vt1812 */
6105static int patch_vt1812(struct hda_codec *codec)
6106{
6107 struct via_spec *spec;
6108 int err;
6109
6110 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01006111 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08006112 if (spec == NULL)
6113 return -ENOMEM;
6114
Lydia Wangab6734e2009-10-10 19:08:46 +08006115 /* automatic parse from the BIOS config */
6116 err = vt1812_parse_auto_config(codec);
6117 if (err < 0) {
6118 via_free(codec);
6119 return err;
6120 } else if (!err) {
6121 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6122 "from BIOS. Using genenic mode...\n");
6123 }
6124
6125
6126 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6127 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6128
6129 spec->stream_name_analog = "VT1812 Analog";
6130 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6131 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6132
6133 spec->stream_name_digital = "VT1812 Digital";
6134 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6135
Takashi Iwaia766d0d2011-06-17 09:01:29 +02006136 if (spec->adc_nids && spec->input_mux) {
Lydia Wangab6734e2009-10-10 19:08:46 +08006137 override_mic_boost(codec, 0x2b, 0, 3, 40);
6138 override_mic_boost(codec, 0x29, 0, 3, 40);
6139 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6140 spec->num_mixers++;
6141 }
6142
6143 codec->patch_ops = via_patch_ops;
6144
6145 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11006146 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangab6734e2009-10-10 19:08:46 +08006147
6148#ifdef CONFIG_SND_HDA_POWER_SAVE
6149 spec->loopback.amplist = vt1812_loopbacks;
6150#endif
6151
Lydia Wang3e95b9a2011-03-23 15:13:28 +08006152 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08006153 return 0;
6154}
6155
Joseph Chanc577b8a2006-11-29 15:29:40 +01006156/*
6157 * patch entries
6158 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02006159static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01006160 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6161 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6162 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6163 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6164 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006165 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006166 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006167 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006168 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006169 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006170 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006171 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006172 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006173 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006174 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006175 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006176 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006177 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006178 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006179 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006180 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006181 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006182 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006183 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006184 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006185 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006186 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006187 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006188 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006189 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006190 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006191 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006192 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006193 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006194 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006195 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006196 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006197 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006198 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006199 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006200 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006201 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006202 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006203 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08006204 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08006205 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006206 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006207 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006208 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006209 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006210 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006211 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006212 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006213 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006214 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006215 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006216 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006217 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006218 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006219 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006220 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006221 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006222 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006223 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006224 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006225 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006226 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006227 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08006228 { .id = 0x11060428, .name = "VT1718S",
6229 .patch = patch_vt1718S},
6230 { .id = 0x11064428, .name = "VT1718S",
6231 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08006232 { .id = 0x11060441, .name = "VT2020",
6233 .patch = patch_vt1718S},
6234 { .id = 0x11064441, .name = "VT1828S",
6235 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08006236 { .id = 0x11060433, .name = "VT1716S",
6237 .patch = patch_vt1716S},
6238 { .id = 0x1106a721, .name = "VT1716S",
6239 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08006240 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6241 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08006242 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08006243 { .id = 0x11060440, .name = "VT1818S",
6244 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08006245 { .id = 0x11060446, .name = "VT1802",
6246 .patch = patch_vt2002P},
6247 { .id = 0x11068446, .name = "VT1802",
6248 .patch = patch_vt2002P},
Joseph Chanc577b8a2006-11-29 15:29:40 +01006249 {} /* terminator */
6250};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006251
6252MODULE_ALIAS("snd-hda-codec-id:1106*");
6253
6254static struct hda_codec_preset_list via_list = {
6255 .preset = snd_hda_preset_via,
6256 .owner = THIS_MODULE,
6257};
6258
6259MODULE_LICENSE("GPL");
6260MODULE_DESCRIPTION("VIA HD-audio codec");
6261
6262static int __init patch_via_init(void)
6263{
6264 return snd_hda_add_codec_preset(&via_list);
6265}
6266
6267static void __exit patch_via_exit(void)
6268{
6269 snd_hda_delete_codec_preset(&via_list);
6270}
6271
6272module_init(patch_via_init)
6273module_exit(patch_via_exit)