blob: 41398b07ba8b414b254e0bc5cbb734a42378b227 [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 Iwai291c9e32011-06-17 16:15:26 +0200423static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
424 const struct snd_kcontrol_new *tmpl,
425 const char *name)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100426{
427 struct snd_kcontrol_new *knew;
428
Takashi Iwai603c4012008-07-30 15:01:44 +0200429 snd_array_init(&spec->kctls, sizeof(*knew), 32);
430 knew = snd_array_new(&spec->kctls);
431 if (!knew)
Takashi Iwai291c9e32011-06-17 16:15:26 +0200432 return NULL;
433 *knew = *tmpl;
434 if (!name)
435 name = tmpl->name;
436 if (name) {
437 knew->name = kstrdup(name, GFP_KERNEL);
438 if (!knew->name)
439 return NULL;
440 }
441 return knew;
442}
443
444static int __via_add_control(struct via_spec *spec, int type, const char *name,
445 int idx, unsigned long val)
446{
447 struct snd_kcontrol_new *knew;
448
449 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
450 if (!knew)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100451 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +0100452 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100453 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100454 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100455 return 0;
456}
457
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200458#define via_add_control(spec, type, name, val) \
459 __via_add_control(spec, type, name, 0, val)
460
Takashi Iwai291c9e32011-06-17 16:15:26 +0200461#define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100462
Takashi Iwai603c4012008-07-30 15:01:44 +0200463static void via_free_kctls(struct hda_codec *codec)
464{
465 struct via_spec *spec = codec->spec;
466
467 if (spec->kctls.list) {
468 struct snd_kcontrol_new *kctl = spec->kctls.list;
469 int i;
470 for (i = 0; i < spec->kctls.used; i++)
471 kfree(kctl[i].name);
472 }
473 snd_array_free(&spec->kctls);
474}
475
Joseph Chanc577b8a2006-11-29 15:29:40 +0100476/* create input playback/capture controls for the given pin */
Lydia Wang9510e8d2009-10-10 19:07:39 +0800477static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200478 int type_idx, int idx, int mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +0100479{
480 char name[32];
481 int err;
482
483 sprintf(name, "%s Playback Volume", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200484 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100485 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
486 if (err < 0)
487 return err;
488 sprintf(name, "%s Playback Switch", ctlname);
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200489 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100490 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
491 if (err < 0)
492 return err;
493 return 0;
494}
495
496static void via_auto_set_output_and_unmute(struct hda_codec *codec,
497 hda_nid_t nid, int pin_type,
498 int dac_idx)
499{
500 /* set as output */
501 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
502 pin_type);
503 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
504 AMP_OUT_UNMUTE);
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200505 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
Lydia Wang377ff312009-10-10 19:08:55 +0800506 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200507 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100508}
509
510
511static void via_auto_init_multi_out(struct hda_codec *codec)
512{
513 struct via_spec *spec = codec->spec;
514 int i;
515
516 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
517 hda_nid_t nid = spec->autocfg.line_out_pins[i];
518 if (nid)
519 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
520 }
521}
522
523static void via_auto_init_hp_out(struct hda_codec *codec)
524{
525 struct via_spec *spec = codec->spec;
526 hda_nid_t pin;
Lydia Wang25eaba22009-10-10 19:08:43 +0800527 int i;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100528
Lydia Wang25eaba22009-10-10 19:08:43 +0800529 for (i = 0; i < spec->autocfg.hp_outs; i++) {
530 pin = spec->autocfg.hp_pins[i];
531 if (pin) /* connect to front */
532 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
533 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100534}
535
Clemens Ladisch32e01912010-07-12 16:28:50 +0200536static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
537
Joseph Chanc577b8a2006-11-29 15:29:40 +0100538static void via_auto_init_analog_input(struct hda_codec *codec)
539{
540 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200541 const struct auto_pin_cfg *cfg = &spec->autocfg;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200542 unsigned int ctl;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100543 int i;
544
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200545 for (i = 0; i < cfg->num_inputs; i++) {
546 hda_nid_t nid = cfg->inputs[i].pin;
Clemens Ladisch32e01912010-07-12 16:28:50 +0200547 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
548 ctl = PIN_OUT;
David Henningsson30649672011-02-21 10:23:18 +0100549 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
Clemens Ladisch32e01912010-07-12 16:28:50 +0200550 ctl = PIN_VREF50;
551 else
552 ctl = PIN_IN;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100553 snd_hda_codec_write(codec, nid, 0,
Clemens Ladisch32e01912010-07-12 16:28:50 +0200554 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100555 }
556}
Lydia Wangf5271102009-10-10 19:07:35 +0800557
558static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
559 unsigned int *affected_parm)
560{
561 unsigned parm;
562 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
563 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
564 >> AC_DEFCFG_MISC_SHIFT
565 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
Lydia Wang1564b282009-10-10 19:07:52 +0800566 struct via_spec *spec = codec->spec;
Takashi Iwai24088a52011-06-17 16:59:21 +0200567 unsigned present = 0;
568
569 no_presence |= spec->no_pin_power_ctl;
570 if (!no_presence)
571 present = snd_hda_jack_detect(codec, nid);
Lydia Wang1564b282009-10-10 19:07:52 +0800572 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
573 || ((no_presence || present)
574 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
Lydia Wangf5271102009-10-10 19:07:35 +0800575 *affected_parm = AC_PWRST_D0; /* if it's connected */
576 parm = AC_PWRST_D0;
577 } else
578 parm = AC_PWRST_D3;
579
580 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
581}
582
Takashi Iwai24088a52011-06-17 16:59:21 +0200583static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
584 struct snd_ctl_elem_info *uinfo)
585{
586 static const char * const texts[] = {
587 "Disabled", "Enabled"
588 };
589
590 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
591 uinfo->count = 1;
592 uinfo->value.enumerated.items = 2;
593 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
594 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
595 strcpy(uinfo->value.enumerated.name,
596 texts[uinfo->value.enumerated.item]);
597 return 0;
598}
599
600static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
601 struct snd_ctl_elem_value *ucontrol)
602{
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 struct via_spec *spec = codec->spec;
605 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
606 return 0;
607}
608
609static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
610 struct snd_ctl_elem_value *ucontrol)
611{
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613 struct via_spec *spec = codec->spec;
614 unsigned int val = !ucontrol->value.enumerated.item[0];
615
616 if (val == spec->no_pin_power_ctl)
617 return 0;
618 spec->no_pin_power_ctl = val;
619 set_widgets_power_state(codec);
620 return 1;
621}
622
623static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
625 .name = "Dynamic Power-Control",
626 .info = via_pin_power_ctl_info,
627 .get = via_pin_power_ctl_get,
628 .put = via_pin_power_ctl_put,
629};
630
631
Joseph Chanc577b8a2006-11-29 15:29:40 +0100632/*
633 * input MUX handling
634 */
635static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
636 struct snd_ctl_elem_info *uinfo)
637{
638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639 struct via_spec *spec = codec->spec;
640 return snd_hda_input_mux_info(spec->input_mux, uinfo);
641}
642
643static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_value *ucontrol)
645{
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct via_spec *spec = codec->spec;
648 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
649
650 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
651 return 0;
652}
653
654static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
655 struct snd_ctl_elem_value *ucontrol)
656{
657 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
658 struct via_spec *spec = codec->spec;
659 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800660 int ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100661
Takashi Iwai337b9d02009-07-07 18:18:59 +0200662 if (!spec->mux_nids[adc_idx])
663 return -EINVAL;
Lydia Wanga80e6e32009-10-10 19:07:55 +0800664 /* switch to D0 beofre change index */
665 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
666 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
667 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
668 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800669
670 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
671 spec->mux_nids[adc_idx],
672 &spec->cur_mux[adc_idx]);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800673 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800674 set_widgets_power_state(codec);
Lydia Wanga80e6e32009-10-10 19:07:55 +0800675
Lydia Wangbff5fbf2011-03-22 16:21:38 +0800676 return ret;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100677}
678
Harald Welte0aa62ae2008-09-09 15:58:27 +0800679static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
680 struct snd_ctl_elem_info *uinfo)
681{
682 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
683 struct via_spec *spec = codec->spec;
684 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
685}
686
687static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
688 struct snd_ctl_elem_value *ucontrol)
689{
690 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100691 hda_nid_t nid = kcontrol->private_value;
Lydia Wangeb7188c2009-10-10 19:08:34 +0800692 unsigned int pinsel;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800693
Lydia Wangeb7188c2009-10-10 19:08:34 +0800694 /* use !! to translate conn sel 2 for VT1718S */
695 pinsel = !!snd_hda_codec_read(codec, nid, 0,
696 AC_VERB_GET_CONNECT_SEL,
697 0x00);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800698 ucontrol->value.enumerated.item[0] = pinsel;
699
700 return 0;
701}
702
Lydia Wang0713efe2009-10-10 19:07:43 +0800703static void activate_ctl(struct hda_codec *codec, const char *name, int active)
704{
705 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
706 if (ctl) {
707 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
708 ctl->vd[0].access |= active
709 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
710 snd_ctl_notify(codec->bus->card,
711 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
712 }
713}
714
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100715static hda_nid_t side_mute_channel(struct via_spec *spec)
716{
717 switch (spec->codec_type) {
718 case VT1708: return 0x1b;
719 case VT1709_10CH: return 0x29;
720 case VT1708B_8CH: /* fall thru */
721 case VT1708S: return 0x27;
Lydia Wange87885f2011-03-24 12:39:05 +0800722 case VT2002P: return 0x19;
723 case VT1802: return 0x15;
724 case VT1812: return 0x15;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100725 default: return 0;
726 }
727}
728
Lydia Wangcdc17842009-10-10 19:07:47 +0800729static int update_side_mute_status(struct hda_codec *codec)
730{
731 /* mute side channel */
732 struct via_spec *spec = codec->spec;
Lydia Wange87885f2011-03-24 12:39:05 +0800733 unsigned int parm;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100734 hda_nid_t sw3 = side_mute_channel(spec);
Lydia Wangcdc17842009-10-10 19:07:47 +0800735
Lydia Wange87885f2011-03-24 12:39:05 +0800736 if (sw3) {
737 if (VT2002P_COMPATIBLE(spec))
738 parm = spec->hp_independent_mode ?
739 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
740 else
741 parm = spec->hp_independent_mode ?
742 AMP_OUT_MUTE : AMP_OUT_UNMUTE;
743 snd_hda_codec_write(codec, sw3, 0,
744 AC_VERB_SET_AMP_GAIN_MUTE, parm);
745 if (spec->codec_type == VT1812)
746 snd_hda_codec_write(codec, 0x1d, 0,
747 AC_VERB_SET_AMP_GAIN_MUTE, parm);
748 }
Lydia Wangcdc17842009-10-10 19:07:47 +0800749 return 0;
750}
751
Harald Welte0aa62ae2008-09-09 15:58:27 +0800752static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
753 struct snd_ctl_elem_value *ucontrol)
754{
755 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
756 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100757 hda_nid_t nid = kcontrol->private_value;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800758 unsigned int pinsel = ucontrol->value.enumerated.item[0];
Lydia Wangcdc17842009-10-10 19:07:47 +0800759 /* Get Independent Mode index of headphone pin widget */
760 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
761 ? 1 : 0;
Lydia Wangce0e5a92011-03-22 16:22:37 +0800762 if (spec->codec_type == VT1718S)
763 snd_hda_codec_write(codec, nid, 0,
764 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
765 else
766 snd_hda_codec_write(codec, nid, 0,
767 AC_VERB_SET_CONNECT_SEL, pinsel);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800768
Lydia Wangce0e5a92011-03-22 16:22:37 +0800769 if (spec->codec_type == VT1812)
770 snd_hda_codec_write(codec, 0x35, 0,
771 AC_VERB_SET_CONNECT_SEL, pinsel);
Lydia Wangcdc17842009-10-10 19:07:47 +0800772 if (spec->multiout.hp_nid && spec->multiout.hp_nid
773 != spec->multiout.dac_nids[HDA_FRONT])
774 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
775 0, 0, 0);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800776
Lydia Wangcdc17842009-10-10 19:07:47 +0800777 update_side_mute_status(codec);
Lydia Wang0713efe2009-10-10 19:07:43 +0800778 /* update HP volume/swtich active state */
779 if (spec->codec_type == VT1708S
Lydia Wangeb7188c2009-10-10 19:08:34 +0800780 || spec->codec_type == VT1702
Lydia Wangf3db4232009-10-10 19:08:41 +0800781 || spec->codec_type == VT1718S
Lydia Wang25eaba22009-10-10 19:08:43 +0800782 || spec->codec_type == VT1716S
Lydia Wang118909562011-03-23 17:57:34 +0800783 || VT2002P_COMPATIBLE(spec)) {
Lydia Wang0713efe2009-10-10 19:07:43 +0800784 activate_ctl(codec, "Headphone Playback Volume",
785 spec->hp_independent_mode);
786 activate_ctl(codec, "Headphone Playback Switch",
787 spec->hp_independent_mode);
788 }
Lydia Wangce0e5a92011-03-22 16:22:37 +0800789 /* update jack power state */
Lydia Wang3e95b9a2011-03-23 15:13:28 +0800790 set_widgets_power_state(codec);
Harald Welte0aa62ae2008-09-09 15:58:27 +0800791 return 0;
792}
793
Takashi Iwai90dd48a2011-05-02 12:38:19 +0200794static const struct snd_kcontrol_new via_hp_mixer[2] = {
Harald Welte0aa62ae2008-09-09 15:58:27 +0800795 {
796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
797 .name = "Independent HP",
Harald Welte0aa62ae2008-09-09 15:58:27 +0800798 .info = via_independent_hp_info,
799 .get = via_independent_hp_get,
800 .put = via_independent_hp_put,
801 },
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100802 {
803 .iface = NID_MAPPING,
804 .name = "Independent HP",
805 },
Harald Welte0aa62ae2008-09-09 15:58:27 +0800806};
807
Takashi Iwai3d83e572010-04-14 14:36:23 +0200808static int via_hp_build(struct hda_codec *codec)
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100809{
Takashi Iwai3d83e572010-04-14 14:36:23 +0200810 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100811 struct snd_kcontrol_new *knew;
812 hda_nid_t nid;
Takashi Iwai3d83e572010-04-14 14:36:23 +0200813 int nums;
814 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100815
816 switch (spec->codec_type) {
817 case VT1718S:
818 nid = 0x34;
819 break;
820 case VT2002P:
Lydia Wang118909562011-03-23 17:57:34 +0800821 case VT1802:
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100822 nid = 0x35;
823 break;
824 case VT1812:
825 nid = 0x3d;
826 break;
827 default:
828 nid = spec->autocfg.hp_pins[0];
829 break;
830 }
831
Lydia Wangee3c35c2011-03-22 16:26:36 +0800832 if (spec->codec_type != VT1708) {
833 nums = snd_hda_get_connections(codec, nid,
834 conn, HDA_MAX_CONNECTIONS);
835 if (nums <= 1)
836 return 0;
837 }
Takashi Iwai3d83e572010-04-14 14:36:23 +0200838
839 knew = via_clone_control(spec, &via_hp_mixer[0]);
840 if (knew == NULL)
841 return -ENOMEM;
842
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100843 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
844 knew->private_value = nid;
845
846 knew = via_clone_control(spec, &via_hp_mixer[1]);
847 if (knew == NULL)
848 return -ENOMEM;
849 knew->subdevice = side_mute_channel(spec);
850
851 return 0;
852}
853
Lydia Wang1564b282009-10-10 19:07:52 +0800854static void notify_aa_path_ctls(struct hda_codec *codec)
855{
856 int i;
857 struct snd_ctl_elem_id id;
Lydia Wang525566c2011-04-28 16:03:39 +0800858 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
859 struct snd_kcontrol *ctl;
Lydia Wang1564b282009-10-10 19:07:52 +0800860
861 memset(&id, 0, sizeof(id));
862 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
863 for (i = 0; i < ARRAY_SIZE(labels); i++) {
864 sprintf(id.name, "%s Playback Volume", labels[i]);
Lydia Wang525566c2011-04-28 16:03:39 +0800865 ctl = snd_hda_find_mixer_ctl(codec, id.name);
866 if (ctl)
867 snd_ctl_notify(codec->bus->card,
868 SNDRV_CTL_EVENT_MASK_VALUE,
869 &ctl->id);
Lydia Wang1564b282009-10-10 19:07:52 +0800870 }
871}
872
873static void mute_aa_path(struct hda_codec *codec, int mute)
874{
875 struct via_spec *spec = codec->spec;
876 hda_nid_t nid_mixer;
877 int start_idx;
878 int end_idx;
879 int i;
880 /* get nid of MW0 and start & end index */
881 switch (spec->codec_type) {
882 case VT1708:
883 nid_mixer = 0x17;
884 start_idx = 2;
885 end_idx = 4;
886 break;
887 case VT1709_10CH:
888 case VT1709_6CH:
889 nid_mixer = 0x18;
890 start_idx = 2;
891 end_idx = 4;
892 break;
893 case VT1708B_8CH:
894 case VT1708B_4CH:
895 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +0800896 case VT1716S:
Lydia Wang1564b282009-10-10 19:07:52 +0800897 nid_mixer = 0x16;
898 start_idx = 2;
899 end_idx = 4;
900 break;
Lydia Wangab657e02011-03-22 16:23:23 +0800901 case VT1718S:
902 nid_mixer = 0x21;
903 start_idx = 1;
904 end_idx = 3;
905 break;
Lydia Wang1564b282009-10-10 19:07:52 +0800906 default:
907 return;
908 }
909 /* check AA path's mute status */
910 for (i = start_idx; i <= end_idx; i++) {
911 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
912 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
913 HDA_AMP_MUTE, val);
914 }
915}
916static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
917{
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200918 const struct auto_pin_cfg *cfg = &spec->autocfg;
919 int i;
920
921 for (i = 0; i < cfg->num_inputs; i++) {
922 if (pin == cfg->inputs[i].pin)
Takashi Iwai86e29592010-09-09 14:50:17 +0200923 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
Lydia Wang1564b282009-10-10 19:07:52 +0800924 }
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200925 return 0;
Lydia Wang1564b282009-10-10 19:07:52 +0800926}
927
928static int via_smart51_info(struct snd_kcontrol *kcontrol,
929 struct snd_ctl_elem_info *uinfo)
930{
931 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
932 uinfo->count = 1;
933 uinfo->value.integer.min = 0;
934 uinfo->value.integer.max = 1;
935 return 0;
936}
937
938static int via_smart51_get(struct snd_kcontrol *kcontrol,
939 struct snd_ctl_elem_value *ucontrol)
940{
941 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
942 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200943 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800944 int on = 1;
945 int i;
946
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200947 for (i = 0; i < cfg->num_inputs; i++) {
948 hda_nid_t nid = cfg->inputs[i].pin;
949 int ctl = snd_hda_codec_read(codec, nid, 0,
950 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai86e29592010-09-09 14:50:17 +0200951 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200952 continue;
Takashi Iwai86e29592010-09-09 14:50:17 +0200953 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200954 spec->hp_independent_mode && spec->codec_type != VT1718S)
955 continue; /* ignore FMic for independent HP */
956 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
957 on = 0;
Lydia Wang1564b282009-10-10 19:07:52 +0800958 }
959 *ucontrol->value.integer.value = on;
960 return 0;
961}
962
963static int via_smart51_put(struct snd_kcontrol *kcontrol,
964 struct snd_ctl_elem_value *ucontrol)
965{
966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
967 struct via_spec *spec = codec->spec;
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200968 const struct auto_pin_cfg *cfg = &spec->autocfg;
Lydia Wang1564b282009-10-10 19:07:52 +0800969 int out_in = *ucontrol->value.integer.value
970 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
Lydia Wang1564b282009-10-10 19:07:52 +0800971 int i;
972
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200973 for (i = 0; i < cfg->num_inputs; i++) {
974 hda_nid_t nid = cfg->inputs[i].pin;
975 unsigned int parm;
976
Takashi Iwai86e29592010-09-09 14:50:17 +0200977 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200978 continue;
Takashi Iwai86e29592010-09-09 14:50:17 +0200979 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200980 spec->hp_independent_mode && spec->codec_type != VT1718S)
Lydia Wang1564b282009-10-10 19:07:52 +0800981 continue; /* don't retask FMic for independent HP */
Takashi Iwai7b315bb2010-08-30 13:06:30 +0200982
983 parm = snd_hda_codec_read(codec, nid, 0,
984 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
985 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
986 parm |= out_in;
987 snd_hda_codec_write(codec, nid, 0,
988 AC_VERB_SET_PIN_WIDGET_CONTROL,
989 parm);
990 if (out_in == AC_PINCTL_OUT_EN) {
991 mute_aa_path(codec, 1);
992 notify_aa_path_ctls(codec);
993 }
994 if (spec->codec_type == VT1718S) {
995 snd_hda_codec_amp_stereo(
Lydia Wangeb7188c2009-10-10 19:08:34 +0800996 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
997 HDA_AMP_UNMUTE);
Lydia Wang1564b282009-10-10 19:07:52 +0800998 }
Takashi Iwai86e29592010-09-09 14:50:17 +0200999 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
Lydia Wangf3db4232009-10-10 19:08:41 +08001000 if (spec->codec_type == VT1708S
1001 || spec->codec_type == VT1716S) {
Lydia Wang1564b282009-10-10 19:07:52 +08001002 /* input = index 1 (AOW3) */
1003 snd_hda_codec_write(
1004 codec, nid, 0,
1005 AC_VERB_SET_CONNECT_SEL, 1);
1006 snd_hda_codec_amp_stereo(
1007 codec, nid, HDA_OUTPUT,
1008 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1009 }
1010 }
1011 }
1012 spec->smart51_enabled = *ucontrol->value.integer.value;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001013 set_widgets_power_state(codec);
Lydia Wang1564b282009-10-10 19:07:52 +08001014 return 1;
1015}
1016
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001017static const struct snd_kcontrol_new via_smart51_mixer = {
1018 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1019 .name = "Smart 5.1",
1020 .count = 1,
1021 .info = via_smart51_info,
1022 .get = via_smart51_get,
1023 .put = via_smart51_put,
Lydia Wang1564b282009-10-10 19:07:52 +08001024};
1025
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001026static int via_smart51_build(struct via_spec *spec)
1027{
1028 struct snd_kcontrol_new *knew;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001029 const struct auto_pin_cfg *cfg = &spec->autocfg;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001030 hda_nid_t nid;
1031 int i;
1032
Lydia Wangcb34c202011-04-27 17:44:16 +08001033 if (!cfg)
1034 return 0;
1035 if (cfg->line_outs > 2)
1036 return 0;
1037
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001038 knew = via_clone_control(spec, &via_smart51_mixer);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001039 if (knew == NULL)
1040 return -ENOMEM;
1041
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001042 for (i = 0; i < cfg->num_inputs; i++) {
1043 nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02001044 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
Takashi Iwai5f4b36d2011-06-17 14:55:02 +02001045 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02001046 break;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001047 }
1048 }
1049
1050 return 0;
1051}
1052
Joseph Chanc577b8a2006-11-29 15:29:40 +01001053/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001054static const struct snd_kcontrol_new vt1708_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001055 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1056 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1057 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1058 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1059 {
1060 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1061 /* The multiple "Capture Source" controls confuse alsamixer
1062 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01001063 */
1064 /* .name = "Capture Source", */
1065 .name = "Input Source",
1066 .count = 1,
1067 .info = via_mux_enum_info,
1068 .get = via_mux_enum_get,
1069 .put = via_mux_enum_put,
1070 },
1071 { } /* end */
1072};
Lydia Wangf5271102009-10-10 19:07:35 +08001073
1074/* check AA path's mute statue */
1075static int is_aa_path_mute(struct hda_codec *codec)
1076{
1077 int mute = 1;
1078 hda_nid_t nid_mixer;
1079 int start_idx;
1080 int end_idx;
1081 int i;
1082 struct via_spec *spec = codec->spec;
1083 /* get nid of MW0 and start & end index */
1084 switch (spec->codec_type) {
1085 case VT1708B_8CH:
1086 case VT1708B_4CH:
1087 case VT1708S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001088 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001089 nid_mixer = 0x16;
1090 start_idx = 2;
1091 end_idx = 4;
1092 break;
1093 case VT1702:
1094 nid_mixer = 0x1a;
1095 start_idx = 1;
1096 end_idx = 3;
1097 break;
Lydia Wangeb7188c2009-10-10 19:08:34 +08001098 case VT1718S:
1099 nid_mixer = 0x21;
1100 start_idx = 1;
1101 end_idx = 3;
1102 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001103 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001104 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001105 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001106 nid_mixer = 0x21;
1107 start_idx = 0;
1108 end_idx = 2;
1109 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001110 default:
1111 return 0;
1112 }
1113 /* check AA path's mute status */
1114 for (i = start_idx; i <= end_idx; i++) {
1115 unsigned int con_list = snd_hda_codec_read(
1116 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1117 int shift = 8 * (i % 4);
1118 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1119 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1120 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1121 /* check mute status while the pin is connected */
1122 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1123 HDA_INPUT, i) >> 7;
1124 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1125 HDA_INPUT, i) >> 7;
1126 if (!mute_l || !mute_r) {
1127 mute = 0;
1128 break;
1129 }
1130 }
1131 }
1132 return mute;
1133}
1134
1135/* enter/exit analog low-current mode */
1136static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1137{
1138 struct via_spec *spec = codec->spec;
1139 static int saved_stream_idle = 1; /* saved stream idle status */
1140 int enable = is_aa_path_mute(codec);
1141 unsigned int verb = 0;
1142 unsigned int parm = 0;
1143
1144 if (stream_idle == -1) /* stream status did not change */
1145 enable = enable && saved_stream_idle;
1146 else {
1147 enable = enable && stream_idle;
1148 saved_stream_idle = stream_idle;
1149 }
1150
1151 /* decide low current mode's verb & parameter */
1152 switch (spec->codec_type) {
1153 case VT1708B_8CH:
1154 case VT1708B_4CH:
1155 verb = 0xf70;
1156 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1157 break;
1158 case VT1708S:
Lydia Wangeb7188c2009-10-10 19:08:34 +08001159 case VT1718S:
Lydia Wangf3db4232009-10-10 19:08:41 +08001160 case VT1716S:
Lydia Wangf5271102009-10-10 19:07:35 +08001161 verb = 0xf73;
1162 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1163 break;
1164 case VT1702:
1165 verb = 0xf73;
1166 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1167 break;
Lydia Wang25eaba22009-10-10 19:08:43 +08001168 case VT2002P:
Lydia Wangab6734e2009-10-10 19:08:46 +08001169 case VT1812:
Lydia Wang118909562011-03-23 17:57:34 +08001170 case VT1802:
Lydia Wang25eaba22009-10-10 19:08:43 +08001171 verb = 0xf93;
1172 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1173 break;
Lydia Wangf5271102009-10-10 19:07:35 +08001174 default:
1175 return; /* other codecs are not supported */
1176 }
1177 /* send verb */
1178 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1179}
1180
Joseph Chanc577b8a2006-11-29 15:29:40 +01001181/*
1182 * generic initialization of ADC, input mixers and output mixers
1183 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001184static const struct hda_verb vt1708_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001185 /*
1186 * Unmute ADC0-1 and set the default input to mic-in
1187 */
1188 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1189 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1190
1191
Josepch Chanf7278fd2007-12-13 16:40:40 +01001192 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01001193 * mixer widget
1194 */
1195 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01001196 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1197 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1198 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1199 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1200 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001201
1202 /*
1203 * Set up output mixers (0x19 - 0x1b)
1204 */
1205 /* set vol=0 to output mixers */
1206 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1207 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1208 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Lydia Wang377ff312009-10-10 19:08:55 +08001209
Lydia Wangbfdc6752009-10-10 19:08:50 +08001210 /* Setup default input MW0 to PW4 */
1211 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001212 /* PW9 Output enable */
1213 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangaa266fc2011-03-24 12:41:01 +08001214 /* power down jack detect function */
1215 {0x1, 0xf81, 0x1},
Josepch Chanf7278fd2007-12-13 16:40:40 +01001216 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +01001217};
1218
1219static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1220 struct hda_codec *codec,
1221 struct snd_pcm_substream *substream)
1222{
1223 struct via_spec *spec = codec->spec;
Lydia Wang17314372009-10-10 19:07:37 +08001224 int idle = substream->pstr->substream_opened == 1
1225 && substream->ref_count == 0;
Lydia Wang17314372009-10-10 19:07:37 +08001226 analog_low_current_mode(codec, idle);
Takashi Iwai9a081602008-02-12 18:37:26 +01001227 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1228 hinfo);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001229}
1230
Harald Welte0aa62ae2008-09-09 15:58:27 +08001231static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1232 unsigned int stream_tag,
1233 unsigned int format,
1234 struct snd_pcm_substream *substream)
1235{
1236 struct via_spec *spec = codec->spec;
1237 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001238 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001239 int chs = substream->runtime->channels;
1240 int i;
Stephen Warren7c935972011-06-01 11:14:17 -06001241 struct hda_spdif_out *spdif =
1242 snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001243
1244 mutex_lock(&codec->spdif_mutex);
1245 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1246 if (chs == 2 &&
1247 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1248 format) &&
Stephen Warren7c935972011-06-01 11:14:17 -06001249 !(spdif->status & IEC958_AES0_NONAUDIO)) {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001250 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1251 /* turn off SPDIF once; otherwise the IEC958 bits won't
1252 * be updated */
Stephen Warren7c935972011-06-01 11:14:17 -06001253 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001254 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1255 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001256 spdif->ctls &
Harald Welte0aa62ae2008-09-09 15:58:27 +08001257 ~AC_DIG1_ENABLE & 0xff);
1258 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1259 stream_tag, 0, format);
1260 /* turn on again (if needed) */
Stephen Warren7c935972011-06-01 11:14:17 -06001261 if (spdif->ctls & AC_DIG1_ENABLE)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001262 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1263 AC_VERB_SET_DIGI_CONVERT_1,
Stephen Warren7c935972011-06-01 11:14:17 -06001264 spdif->ctls & 0xff);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001265 } else {
1266 mout->dig_out_used = 0;
1267 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1268 0, 0, 0);
1269 }
1270 }
1271 mutex_unlock(&codec->spdif_mutex);
1272
1273 /* front */
1274 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1275 0, format);
1276
Lydia Wangeb7188c2009-10-10 19:08:34 +08001277 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1278 && !spec->hp_independent_mode)
Harald Welte0aa62ae2008-09-09 15:58:27 +08001279 /* headphone out will just decode front left/right (stereo) */
1280 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1281 0, format);
1282
1283 /* extra outputs copied from front */
1284 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1285 if (mout->extra_out_nid[i])
1286 snd_hda_codec_setup_stream(codec,
1287 mout->extra_out_nid[i],
1288 stream_tag, 0, format);
1289
1290 /* surrounds */
1291 for (i = 1; i < mout->num_dacs; i++) {
1292 if (chs >= (i + 1) * 2) /* independent out */
1293 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1294 i * 2, format);
1295 else /* copy front */
1296 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1297 0, format);
1298 }
1299}
1300
1301static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1302 struct hda_codec *codec,
1303 unsigned int stream_tag,
1304 unsigned int format,
1305 struct snd_pcm_substream *substream)
1306{
1307 struct via_spec *spec = codec->spec;
1308 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001309 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001310
1311 if (substream->number == 0)
1312 playback_multi_pcm_prep_0(codec, stream_tag, format,
1313 substream);
1314 else {
1315 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1316 spec->hp_independent_mode)
1317 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1318 stream_tag, 0, format);
1319 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001320 vt1708_start_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001321 return 0;
1322}
1323
1324static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1325 struct hda_codec *codec,
1326 struct snd_pcm_substream *substream)
1327{
1328 struct via_spec *spec = codec->spec;
1329 struct hda_multi_out *mout = &spec->multiout;
Takashi Iwaidda14412011-05-02 11:29:30 +02001330 const hda_nid_t *nids = mout->dac_nids;
Harald Welte0aa62ae2008-09-09 15:58:27 +08001331 int i;
1332
1333 if (substream->number == 0) {
1334 for (i = 0; i < mout->num_dacs; i++)
1335 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1336
1337 if (mout->hp_nid && !spec->hp_independent_mode)
1338 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1339 0, 0, 0);
1340
1341 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1342 if (mout->extra_out_nid[i])
1343 snd_hda_codec_setup_stream(codec,
1344 mout->extra_out_nid[i],
1345 0, 0, 0);
1346 mutex_lock(&codec->spdif_mutex);
1347 if (mout->dig_out_nid &&
1348 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1349 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1350 0, 0, 0);
1351 mout->dig_out_used = 0;
1352 }
1353 mutex_unlock(&codec->spdif_mutex);
1354 } else {
1355 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1356 spec->hp_independent_mode)
1357 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1358 0, 0, 0);
1359 }
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001360 vt1708_stop_hp_work(spec);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001361 return 0;
1362}
1363
Joseph Chanc577b8a2006-11-29 15:29:40 +01001364/*
1365 * Digital out
1366 */
1367static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1368 struct hda_codec *codec,
1369 struct snd_pcm_substream *substream)
1370{
1371 struct via_spec *spec = codec->spec;
1372 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1373}
1374
1375static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1376 struct hda_codec *codec,
1377 struct snd_pcm_substream *substream)
1378{
1379 struct via_spec *spec = codec->spec;
1380 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1381}
1382
Harald Welte5691ec72008-09-15 22:42:26 +08001383static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +08001384 struct hda_codec *codec,
1385 unsigned int stream_tag,
1386 unsigned int format,
1387 struct snd_pcm_substream *substream)
1388{
1389 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +02001390 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1391 stream_tag, format, substream);
1392}
Harald Welte5691ec72008-09-15 22:42:26 +08001393
Takashi Iwai9da29272009-05-07 16:31:14 +02001394static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1395 struct hda_codec *codec,
1396 struct snd_pcm_substream *substream)
1397{
1398 struct via_spec *spec = codec->spec;
1399 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +08001400 return 0;
1401}
1402
Joseph Chanc577b8a2006-11-29 15:29:40 +01001403/*
1404 * Analog capture
1405 */
1406static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1407 struct hda_codec *codec,
1408 unsigned int stream_tag,
1409 unsigned int format,
1410 struct snd_pcm_substream *substream)
1411{
1412 struct via_spec *spec = codec->spec;
1413
1414 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1415 stream_tag, 0, format);
1416 return 0;
1417}
1418
1419static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1420 struct hda_codec *codec,
1421 struct snd_pcm_substream *substream)
1422{
1423 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +01001424 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001425 return 0;
1426}
1427
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001428static const struct hda_pcm_stream vt1708_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08001429 .substreams = 2,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001430 .channels_min = 2,
1431 .channels_max = 8,
1432 .nid = 0x10, /* NID to query formats and rates */
1433 .ops = {
1434 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08001435 .prepare = via_playback_multi_pcm_prepare,
1436 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001437 },
1438};
1439
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001440static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
Lydia Wangc873cc22009-10-10 19:08:21 +08001441 .substreams = 2,
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001442 .channels_min = 2,
1443 .channels_max = 8,
1444 .nid = 0x10, /* NID to query formats and rates */
1445 /* We got noisy outputs on the right channel on VT1708 when
1446 * 24bit samples are used. Until any workaround is found,
1447 * disable the 24bit format, so far.
1448 */
1449 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1450 .ops = {
1451 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08001452 .prepare = via_playback_multi_pcm_prepare,
1453 .cleanup = via_playback_multi_pcm_cleanup
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001454 },
1455};
1456
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001457static const struct hda_pcm_stream vt1708_pcm_analog_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001458 .substreams = 2,
1459 .channels_min = 2,
1460 .channels_max = 2,
1461 .nid = 0x15, /* NID to query formats and rates */
1462 .ops = {
1463 .prepare = via_capture_pcm_prepare,
1464 .cleanup = via_capture_pcm_cleanup
1465 },
1466};
1467
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001468static const struct hda_pcm_stream vt1708_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001469 .substreams = 1,
1470 .channels_min = 2,
1471 .channels_max = 2,
1472 /* NID is set in via_build_pcms */
1473 .ops = {
1474 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001475 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02001476 .prepare = via_dig_playback_pcm_prepare,
1477 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +01001478 },
1479};
1480
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001481static const struct hda_pcm_stream vt1708_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001482 .substreams = 1,
1483 .channels_min = 2,
1484 .channels_max = 2,
1485};
1486
1487static int via_build_controls(struct hda_codec *codec)
1488{
1489 struct via_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001490 struct snd_kcontrol *kctl;
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001491 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001492 int err, i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001493
Takashi Iwai24088a52011-06-17 16:59:21 +02001494 if (spec->set_widgets_power_state)
1495 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1496 return -ENOMEM;
1497
Joseph Chanc577b8a2006-11-29 15:29:40 +01001498 for (i = 0; i < spec->num_mixers; i++) {
1499 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1500 if (err < 0)
1501 return err;
1502 }
1503
1504 if (spec->multiout.dig_out_nid) {
1505 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001506 spec->multiout.dig_out_nid,
Joseph Chanc577b8a2006-11-29 15:29:40 +01001507 spec->multiout.dig_out_nid);
1508 if (err < 0)
1509 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001510 err = snd_hda_create_spdif_share_sw(codec,
1511 &spec->multiout);
1512 if (err < 0)
1513 return err;
1514 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001515 }
1516 if (spec->dig_in_nid) {
1517 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1518 if (err < 0)
1519 return err;
1520 }
Lydia Wang17314372009-10-10 19:07:37 +08001521
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001522 /* assign Capture Source enums to NID */
1523 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1524 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +01001525 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001526 if (err < 0)
1527 return err;
1528 }
1529
1530 /* other nid->control mapping */
1531 for (i = 0; i < spec->num_mixers; i++) {
1532 for (knew = spec->mixers[i]; knew->name; knew++) {
1533 if (knew->iface != NID_MAPPING)
1534 continue;
1535 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1536 if (kctl == NULL)
1537 continue;
1538 err = snd_hda_add_nid(codec, kctl, 0,
1539 knew->subdevice);
1540 }
1541 }
1542
Lydia Wang17314372009-10-10 19:07:37 +08001543 /* init power states */
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001544 set_widgets_power_state(codec);
Lydia Wang17314372009-10-10 19:07:37 +08001545 analog_low_current_mode(codec, 1);
1546
Takashi Iwai603c4012008-07-30 15:01:44 +02001547 via_free_kctls(codec); /* no longer needed */
Joseph Chanc577b8a2006-11-29 15:29:40 +01001548 return 0;
1549}
1550
1551static int via_build_pcms(struct hda_codec *codec)
1552{
1553 struct via_spec *spec = codec->spec;
1554 struct hda_pcm *info = spec->pcm_rec;
1555
1556 codec->num_pcms = 1;
1557 codec->pcm_info = info;
1558
1559 info->name = spec->stream_name_analog;
Lydia Wang377ff312009-10-10 19:08:55 +08001560 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1561 *(spec->stream_analog_playback);
1562 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1563 spec->multiout.dac_nids[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001564 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1565 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1566
1567 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1568 spec->multiout.max_channels;
1569
1570 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1571 codec->num_pcms++;
1572 info++;
1573 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001574 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001575 if (spec->multiout.dig_out_nid) {
1576 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1577 *(spec->stream_digital_playback);
1578 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1579 spec->multiout.dig_out_nid;
1580 }
1581 if (spec->dig_in_nid) {
1582 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1583 *(spec->stream_digital_capture);
1584 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1585 spec->dig_in_nid;
1586 }
1587 }
1588
1589 return 0;
1590}
1591
1592static void via_free(struct hda_codec *codec)
1593{
1594 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001595
1596 if (!spec)
1597 return;
1598
Takashi Iwai603c4012008-07-30 15:01:44 +02001599 via_free_kctls(codec);
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001600 vt1708_stop_hp_work(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001601 kfree(codec->spec);
1602}
1603
Harald Welte69e52a82008-09-09 15:57:32 +08001604/* mute internal speaker if HP is plugged */
1605static void via_hp_automute(struct hda_codec *codec)
1606{
Lydia Wangdcf34c82009-10-10 19:08:15 +08001607 unsigned int present = 0;
Harald Welte69e52a82008-09-09 15:57:32 +08001608 struct via_spec *spec = codec->spec;
1609
Takashi Iwaid56757a2009-11-18 08:00:14 +01001610 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangdcf34c82009-10-10 19:08:15 +08001611
1612 if (!spec->hp_independent_mode) {
1613 struct snd_ctl_elem_id id;
1614 /* auto mute */
1615 snd_hda_codec_amp_stereo(
1616 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1617 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1618 /* notify change */
1619 memset(&id, 0, sizeof(id));
1620 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1621 strcpy(id.name, "Front Playback Switch");
1622 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1623 &id);
1624 }
Harald Welte69e52a82008-09-09 15:57:32 +08001625}
1626
Lydia Wangf3db4232009-10-10 19:08:41 +08001627/* mute mono out if HP or Line out is plugged */
1628static void via_mono_automute(struct hda_codec *codec)
1629{
1630 unsigned int hp_present, lineout_present;
1631 struct via_spec *spec = codec->spec;
1632
1633 if (spec->codec_type != VT1716S)
1634 return;
1635
Takashi Iwaid56757a2009-11-18 08:00:14 +01001636 lineout_present = snd_hda_jack_detect(codec,
1637 spec->autocfg.line_out_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001638
1639 /* Mute Mono Out if Line Out is plugged */
1640 if (lineout_present) {
1641 snd_hda_codec_amp_stereo(
1642 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1643 return;
1644 }
1645
Takashi Iwaid56757a2009-11-18 08:00:14 +01001646 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wangf3db4232009-10-10 19:08:41 +08001647
1648 if (!spec->hp_independent_mode)
1649 snd_hda_codec_amp_stereo(
1650 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1651 hp_present ? HDA_AMP_MUTE : 0);
1652}
1653
Harald Welte69e52a82008-09-09 15:57:32 +08001654static void via_gpio_control(struct hda_codec *codec)
1655{
1656 unsigned int gpio_data;
1657 unsigned int vol_counter;
1658 unsigned int vol;
1659 unsigned int master_vol;
1660
1661 struct via_spec *spec = codec->spec;
1662
1663 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1664 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1665
1666 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1667 0xF84, 0) & 0x3F0000) >> 16;
1668
1669 vol = vol_counter & 0x1F;
1670 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1671 AC_VERB_GET_AMP_GAIN_MUTE,
1672 AC_AMP_GET_INPUT);
1673
1674 if (gpio_data == 0x02) {
1675 /* unmute line out */
1676 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1677 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1678
1679 if (vol_counter & 0x20) {
1680 /* decrease volume */
1681 if (vol > master_vol)
1682 vol = master_vol;
1683 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1684 0, HDA_AMP_VOLMASK,
1685 master_vol-vol);
1686 } else {
1687 /* increase volume */
1688 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1689 HDA_AMP_VOLMASK,
1690 ((master_vol+vol) > 0x2A) ? 0x2A :
1691 (master_vol+vol));
1692 }
1693 } else if (!(gpio_data & 0x02)) {
1694 /* mute line out */
1695 snd_hda_codec_amp_stereo(codec,
1696 spec->autocfg.line_out_pins[0],
1697 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1698 HDA_AMP_MUTE);
1699 }
1700}
1701
Lydia Wang25eaba22009-10-10 19:08:43 +08001702/* mute Internal-Speaker if HP is plugged */
1703static void via_speaker_automute(struct hda_codec *codec)
1704{
1705 unsigned int hp_present;
1706 struct via_spec *spec = codec->spec;
1707
Lydia Wang27439ce2011-03-24 12:40:10 +08001708 if (!VT2002P_COMPATIBLE(spec))
Lydia Wang25eaba22009-10-10 19:08:43 +08001709 return;
1710
Takashi Iwaid56757a2009-11-18 08:00:14 +01001711 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001712
1713 if (!spec->hp_independent_mode) {
1714 struct snd_ctl_elem_id id;
1715 snd_hda_codec_amp_stereo(
1716 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
1717 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1718 /* notify change */
1719 memset(&id, 0, sizeof(id));
1720 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1721 strcpy(id.name, "Speaker Playback Switch");
1722 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1723 &id);
1724 }
1725}
1726
1727/* mute line-out and internal speaker if HP is plugged */
1728static void via_hp_bind_automute(struct hda_codec *codec)
1729{
akpm@linux-foundation.org01a17962009-11-13 16:47:10 -08001730 /* use long instead of int below just to avoid an internal compiler
1731 * error with gcc 4.0.x
1732 */
1733 unsigned long hp_present, present = 0;
Lydia Wang25eaba22009-10-10 19:08:43 +08001734 struct via_spec *spec = codec->spec;
1735 int i;
1736
1737 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1738 return;
1739
Takashi Iwaid56757a2009-11-18 08:00:14 +01001740 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001741
Takashi Iwaid56757a2009-11-18 08:00:14 +01001742 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
Lydia Wang25eaba22009-10-10 19:08:43 +08001743
1744 if (!spec->hp_independent_mode) {
1745 /* Mute Line-Outs */
1746 for (i = 0; i < spec->autocfg.line_outs; i++)
1747 snd_hda_codec_amp_stereo(
1748 codec, spec->autocfg.line_out_pins[i],
1749 HDA_OUTPUT, 0,
1750 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1751 if (hp_present)
1752 present = hp_present;
1753 }
1754 /* Speakers */
1755 for (i = 0; i < spec->autocfg.speaker_outs; i++)
1756 snd_hda_codec_amp_stereo(
1757 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
1758 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1759}
1760
1761
Harald Welte69e52a82008-09-09 15:57:32 +08001762/* unsolicited event for jack sensing */
1763static void via_unsol_event(struct hda_codec *codec,
1764 unsigned int res)
1765{
1766 res >>= 26;
Lydia Wangec7e7e42011-03-24 12:43:44 +08001767
Lydia Wanga34df192009-10-10 19:08:01 +08001768 if (res & VIA_JACK_EVENT)
Lydia Wang3e95b9a2011-03-23 15:13:28 +08001769 set_widgets_power_state(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001770
1771 res &= ~VIA_JACK_EVENT;
1772
1773 if (res == VIA_HP_EVENT)
1774 via_hp_automute(codec);
1775 else if (res == VIA_GPIO_EVENT)
1776 via_gpio_control(codec);
1777 else if (res == VIA_MONO_EVENT)
Lydia Wangf3db4232009-10-10 19:08:41 +08001778 via_mono_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001779 else if (res == VIA_SPEAKER_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001780 via_speaker_automute(codec);
Lydia Wangec7e7e42011-03-24 12:43:44 +08001781 else if (res == VIA_BIND_HP_EVENT)
Lydia Wang25eaba22009-10-10 19:08:43 +08001782 via_hp_bind_automute(codec);
Harald Welte69e52a82008-09-09 15:57:32 +08001783}
1784
Joseph Chanc577b8a2006-11-29 15:29:40 +01001785static int via_init(struct hda_codec *codec)
1786{
1787 struct via_spec *spec = codec->spec;
Harald Welte69e52a82008-09-09 15:57:32 +08001788 int i;
1789 for (i = 0; i < spec->num_iverbs; i++)
1790 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1791
Josepch Chanf7278fd2007-12-13 16:40:40 +01001792 /* Lydia Add for EAPD enable */
1793 if (!spec->dig_in_nid) { /* No Digital In connection */
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001794 if (spec->dig_in_pin) {
1795 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001796 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +01001797 PIN_OUT);
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001798 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001799 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1800 }
Takashi Iwai12b74c82008-01-15 12:39:38 +01001801 } else /* enable SPDIF-input pin */
1802 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1803 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
Josepch Chanf7278fd2007-12-13 16:40:40 +01001804
Takashi Iwai9da29272009-05-07 16:31:14 +02001805 /* assign slave outs */
1806 if (spec->slave_dig_outs[0])
1807 codec->slave_dig_outs = spec->slave_dig_outs;
Harald Welte5691ec72008-09-15 22:42:26 +08001808
Lydia Wang377ff312009-10-10 19:08:55 +08001809 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001810}
1811
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001812#ifdef SND_HDA_NEEDS_RESUME
1813static int via_suspend(struct hda_codec *codec, pm_message_t state)
1814{
1815 struct via_spec *spec = codec->spec;
1816 vt1708_stop_hp_work(spec);
1817 return 0;
1818}
1819#endif
1820
Takashi Iwaicb53c622007-08-10 17:21:45 +02001821#ifdef CONFIG_SND_HDA_POWER_SAVE
1822static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1823{
1824 struct via_spec *spec = codec->spec;
1825 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1826}
1827#endif
1828
Joseph Chanc577b8a2006-11-29 15:29:40 +01001829/*
1830 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02001831static const struct hda_codec_ops via_patch_ops = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001832 .build_controls = via_build_controls,
1833 .build_pcms = via_build_pcms,
1834 .init = via_init,
1835 .free = via_free,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08001836#ifdef SND_HDA_NEEDS_RESUME
1837 .suspend = via_suspend,
1838#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02001839#ifdef CONFIG_SND_HDA_POWER_SAVE
1840 .check_power_status = via_check_power_status,
1841#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001842};
1843
1844/* fill in the dac_nids table from the parsed pin configuration */
1845static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1846 const struct auto_pin_cfg *cfg)
1847{
1848 int i;
1849 hda_nid_t nid;
1850
1851 spec->multiout.num_dacs = cfg->line_outs;
1852
1853 spec->multiout.dac_nids = spec->private_dac_nids;
Lydia Wang377ff312009-10-10 19:08:55 +08001854
1855 for (i = 0; i < 4; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001856 nid = cfg->line_out_pins[i];
1857 if (nid) {
1858 /* config dac list */
1859 switch (i) {
1860 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02001861 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001862 break;
1863 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02001864 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001865 break;
1866 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02001867 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001868 break;
1869 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02001870 spec->private_dac_nids[i] = 0x13;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001871 break;
1872 }
1873 }
1874 }
1875
1876 return 0;
1877}
1878
1879/* add playback controls from the parsed DAC table */
1880static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1881 const struct auto_pin_cfg *cfg)
1882{
1883 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01001884 static const char * const chname[4] = {
1885 "Front", "Surround", "C/LFE", "Side"
1886 };
Lydia Wang9645c202009-10-10 19:08:27 +08001887 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
Joseph Chanc577b8a2006-11-29 15:29:40 +01001888 int i, err;
1889
1890 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1891 nid = cfg->line_out_pins[i];
1892
1893 if (!nid)
1894 continue;
Lydia Wang377ff312009-10-10 19:08:55 +08001895
Lydia Wang9645c202009-10-10 19:08:27 +08001896 nid_vol = nid_vols[i];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001897
1898 if (i == AUTO_SEQ_CENLFE) {
1899 /* Center/LFE */
1900 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001901 "Center Playback Volume",
1902 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1903 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001904 if (err < 0)
1905 return err;
1906 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1907 "LFE Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001908 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1909 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001910 if (err < 0)
1911 return err;
1912 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1913 "Center Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001914 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1915 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001916 if (err < 0)
1917 return err;
1918 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1919 "LFE Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001920 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1921 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001922 if (err < 0)
1923 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08001924 } else if (i == AUTO_SEQ_FRONT) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01001925 /* add control to mixer index 0 */
1926 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1927 "Master Front Playback Volume",
Lydia Wang9645c202009-10-10 19:08:27 +08001928 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001929 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001930 if (err < 0)
1931 return err;
1932 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1933 "Master Front Playback Switch",
Lydia Wang9645c202009-10-10 19:08:27 +08001934 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001935 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001936 if (err < 0)
1937 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08001938
Joseph Chanc577b8a2006-11-29 15:29:40 +01001939 /* add control to PW3 */
1940 sprintf(name, "%s Playback Volume", chname[i]);
1941 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001942 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1943 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001944 if (err < 0)
1945 return err;
1946 sprintf(name, "%s Playback Switch", chname[i]);
1947 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001948 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1949 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001950 if (err < 0)
1951 return err;
1952 } else {
1953 sprintf(name, "%s Playback Volume", chname[i]);
1954 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001955 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1956 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001957 if (err < 0)
1958 return err;
1959 sprintf(name, "%s Playback Switch", chname[i]);
1960 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001961 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1962 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001963 if (err < 0)
1964 return err;
1965 }
1966 }
1967
1968 return 0;
1969}
1970
Harald Welte0aa62ae2008-09-09 15:58:27 +08001971static void create_hp_imux(struct via_spec *spec)
1972{
1973 int i;
1974 struct hda_input_mux *imux = &spec->private_imux[1];
Takashi Iwaiea734962011-01-17 11:29:34 +01001975 static const char * const texts[] = { "OFF", "ON", NULL};
Harald Welte0aa62ae2008-09-09 15:58:27 +08001976
1977 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02001978 for (i = 0; texts[i]; i++)
1979 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Harald Welte0aa62ae2008-09-09 15:58:27 +08001980
1981 spec->hp_mux = &spec->private_imux[1];
1982}
1983
Joseph Chanc577b8a2006-11-29 15:29:40 +01001984static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1985{
1986 int err;
1987
1988 if (!pin)
1989 return 0;
1990
1991 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08001992 spec->hp_independent_mode_index = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001993
1994 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1995 "Headphone Playback Volume",
1996 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1997 if (err < 0)
1998 return err;
1999 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2000 "Headphone Playback Switch",
2001 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2002 if (err < 0)
2003 return err;
2004
Harald Welte0aa62ae2008-09-09 15:58:27 +08002005 create_hp_imux(spec);
2006
Joseph Chanc577b8a2006-11-29 15:29:40 +01002007 return 0;
2008}
2009
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002010static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
2011 hda_nid_t nid)
2012{
2013 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
2014 int i, nums;
2015
2016 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
2017 for (i = 0; i < nums; i++)
2018 if (conn[i] == nid)
2019 return i;
2020 return -1;
2021}
2022
2023/* look for ADCs */
2024static int via_fill_adcs(struct hda_codec *codec)
2025{
2026 struct via_spec *spec = codec->spec;
2027 hda_nid_t nid = codec->start_nid;
2028 int i;
2029
2030 for (i = 0; i < codec->num_nodes; i++, nid++) {
2031 unsigned int wcaps = get_wcaps(codec, nid);
2032 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2033 continue;
2034 if (wcaps & AC_WCAP_DIGITAL)
2035 continue;
2036 if (!(wcaps & AC_WCAP_CONN_LIST))
2037 continue;
2038 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2039 return -ENOMEM;
2040 spec->adc_nids[spec->num_adc_nids++] = nid;
2041 }
2042 return 0;
2043}
2044
2045static int get_mux_nids(struct hda_codec *codec);
2046
Joseph Chanc577b8a2006-11-29 15:29:40 +01002047/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002048static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaif3268512010-08-30 11:00:19 +02002049 const struct auto_pin_cfg *cfg,
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002050 hda_nid_t mix_nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002051{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002052 struct via_spec *spec = codec->spec;
Harald Welte0aa62ae2008-09-09 15:58:27 +08002053 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002054 int i, err, idx, idx2, type, type_idx = 0;
2055 hda_nid_t cap_nid;
2056 hda_nid_t pin_idxs[8];
2057 int num_idxs;
2058
2059 err = via_fill_adcs(codec);
2060 if (err < 0)
2061 return err;
2062 err = get_mux_nids(codec);
2063 if (err < 0)
2064 return err;
2065 cap_nid = spec->mux_nids[0];
2066
2067 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
2068 ARRAY_SIZE(pin_idxs));
2069 if (num_idxs <= 0)
2070 return 0;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002071
2072 /* for internal loopback recording select */
Takashi Iwaif3268512010-08-30 11:00:19 +02002073 for (idx = 0; idx < num_idxs; idx++) {
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002074 if (pin_idxs[idx] == mix_nid) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002075 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
Takashi Iwaif3268512010-08-30 11:00:19 +02002076 break;
2077 }
2078 }
Joseph Chanc577b8a2006-11-29 15:29:40 +01002079
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002080 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002081 const char *label;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002082 type = cfg->inputs[i].type;
Takashi Iwaif3268512010-08-30 11:00:19 +02002083 for (idx = 0; idx < num_idxs; idx++)
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002084 if (pin_idxs[idx] == cfg->inputs[i].pin)
Takashi Iwaif3268512010-08-30 11:00:19 +02002085 break;
2086 if (idx >= num_idxs)
2087 continue;
Takashi Iwai7b315bb2010-08-30 13:06:30 +02002088 if (i > 0 && type == cfg->inputs[i - 1].type)
2089 type_idx++;
2090 else
2091 type_idx = 0;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002092 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002093 idx2 = get_connection_index(codec, mix_nid, pin_idxs[idx]);
2094 if (idx2 >= 0)
Lydia Wang16922282011-03-22 16:24:10 +08002095 err = via_new_analog_input(spec, label, type_idx,
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002096 idx2, mix_nid);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002097 if (err < 0)
2098 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002099 snd_hda_add_imux_item(imux, label, idx, NULL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002100 }
2101 return 0;
2102}
2103
Takashi Iwaif3268512010-08-30 11:00:19 +02002104/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002105static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaif3268512010-08-30 11:00:19 +02002106 const struct auto_pin_cfg *cfg)
2107{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002108 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17);
Takashi Iwaif3268512010-08-30 11:00:19 +02002109}
2110
Takashi Iwaicb53c622007-08-10 17:21:45 +02002111#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002112static const struct hda_amp_list vt1708_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002113 { 0x17, HDA_INPUT, 1 },
2114 { 0x17, HDA_INPUT, 2 },
2115 { 0x17, HDA_INPUT, 3 },
2116 { 0x17, HDA_INPUT, 4 },
2117 { } /* end */
2118};
2119#endif
2120
Harald Welte76d9b0d2008-09-09 15:50:37 +08002121static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2122{
2123 unsigned int def_conf;
2124 unsigned char seqassoc;
2125
Takashi Iwai2f334f92009-02-20 14:37:42 +01002126 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002127 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2128 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
Lydia Wang82ef9e42009-10-10 19:08:19 +08002129 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2130 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2131 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2132 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08002133 }
2134
2135 return;
2136}
2137
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002138static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002139 struct snd_ctl_elem_value *ucontrol)
2140{
2141 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2142 struct via_spec *spec = codec->spec;
2143
2144 if (spec->codec_type != VT1708)
2145 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002146 spec->vt1708_jack_detect =
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002147 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002148 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002149 return 0;
2150}
2151
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002152static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002153 struct snd_ctl_elem_value *ucontrol)
2154{
2155 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2156 struct via_spec *spec = codec->spec;
2157 int change;
2158
2159 if (spec->codec_type != VT1708)
2160 return 0;
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002161 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002162 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002163 == !spec->vt1708_jack_detect;
2164 if (spec->vt1708_jack_detect) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002165 mute_aa_path(codec, 1);
2166 notify_aa_path_ctls(codec);
2167 }
2168 return change;
2169}
2170
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002171static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2172 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2173 .name = "Jack Detect",
2174 .count = 1,
2175 .info = snd_ctl_boolean_mono_info,
2176 .get = vt1708_jack_detect_get,
2177 .put = vt1708_jack_detect_put,
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002178};
2179
Joseph Chanc577b8a2006-11-29 15:29:40 +01002180static int vt1708_parse_auto_config(struct hda_codec *codec)
2181{
2182 struct via_spec *spec = codec->spec;
2183 int err;
2184
Harald Welte76d9b0d2008-09-09 15:50:37 +08002185 /* Add HP and CD pin config connect bit re-config action */
2186 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2187 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2188
Joseph Chanc577b8a2006-11-29 15:29:40 +01002189 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2190 if (err < 0)
2191 return err;
2192 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2193 if (err < 0)
2194 return err;
2195 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2196 return 0; /* can't find valid BIOS pin config */
2197
2198 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2199 if (err < 0)
2200 return err;
2201 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2202 if (err < 0)
2203 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002204 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002205 if (err < 0)
2206 return err;
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002207 /* add jack detect on/off control */
Takashi Iwaie06e5a22011-06-17 15:46:13 +02002208 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2209 return -ENOMEM;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002210
2211 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2212
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002213 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002214 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002215 spec->dig_in_pin = VT1708_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002216 if (spec->autocfg.dig_in_pin)
2217 spec->dig_in_nid = VT1708_DIGIN_NID;
2218
Takashi Iwai603c4012008-07-30 15:01:44 +02002219 if (spec->kctls.list)
2220 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002221
Harald Welte69e52a82008-09-09 15:57:32 +08002222 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002223
Harald Welte0aa62ae2008-09-09 15:58:27 +08002224 spec->input_mux = &spec->private_imux[0];
2225
Harald Weltef8fdd492008-09-15 22:41:31 +08002226 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002227 via_hp_build(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002228
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002229 via_smart51_build(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002230 return 1;
2231}
2232
2233/* init callback for auto-configuration model -- overriding the default init */
2234static int via_auto_init(struct hda_codec *codec)
2235{
Lydia Wang25eaba22009-10-10 19:08:43 +08002236 struct via_spec *spec = codec->spec;
2237
Joseph Chanc577b8a2006-11-29 15:29:40 +01002238 via_init(codec);
2239 via_auto_init_multi_out(codec);
2240 via_auto_init_hp_out(codec);
2241 via_auto_init_analog_input(codec);
Lydia Wang118909562011-03-23 17:57:34 +08002242
2243 if (VT2002P_COMPATIBLE(spec)) {
Lydia Wang25eaba22009-10-10 19:08:43 +08002244 via_hp_bind_automute(codec);
2245 } else {
2246 via_hp_automute(codec);
2247 via_speaker_automute(codec);
2248 }
2249
Joseph Chanc577b8a2006-11-29 15:29:40 +01002250 return 0;
2251}
2252
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002253static void vt1708_update_hp_jack_state(struct work_struct *work)
2254{
2255 struct via_spec *spec = container_of(work, struct via_spec,
2256 vt1708_hp_work.work);
2257 if (spec->codec_type != VT1708)
2258 return;
2259 /* if jack state toggled */
2260 if (spec->vt1708_hp_present
Takashi Iwaid56757a2009-11-18 08:00:14 +01002261 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002262 spec->vt1708_hp_present ^= 1;
2263 via_hp_automute(spec->codec);
2264 }
2265 vt1708_start_hp_work(spec);
2266}
2267
Takashi Iwai337b9d02009-07-07 18:18:59 +02002268static int get_mux_nids(struct hda_codec *codec)
2269{
2270 struct via_spec *spec = codec->spec;
2271 hda_nid_t nid, conn[8];
2272 unsigned int type;
2273 int i, n;
2274
2275 for (i = 0; i < spec->num_adc_nids; i++) {
2276 nid = spec->adc_nids[i];
2277 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02002278 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02002279 if (type == AC_WID_PIN)
2280 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002281 n = snd_hda_get_connections(codec, nid, conn,
2282 ARRAY_SIZE(conn));
2283 if (n <= 0)
2284 break;
2285 if (n > 1) {
2286 spec->mux_nids[i] = nid;
2287 break;
2288 }
2289 nid = conn[0];
2290 }
2291 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02002292 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02002293}
2294
Joseph Chanc577b8a2006-11-29 15:29:40 +01002295static int patch_vt1708(struct hda_codec *codec)
2296{
2297 struct via_spec *spec;
2298 int err;
2299
2300 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002301 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002302 if (spec == NULL)
2303 return -ENOMEM;
2304
Joseph Chanc577b8a2006-11-29 15:29:40 +01002305 /* automatic parse from the BIOS config */
2306 err = vt1708_parse_auto_config(codec);
2307 if (err < 0) {
2308 via_free(codec);
2309 return err;
2310 } else if (!err) {
2311 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2312 "from BIOS. Using genenic mode...\n");
2313 }
2314
Lydia Wang377ff312009-10-10 19:08:55 +08002315
Joseph Chanc577b8a2006-11-29 15:29:40 +01002316 spec->stream_name_analog = "VT1708 Analog";
2317 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
Takashi Iwaibc9b562382008-05-23 17:50:27 +02002318 /* disable 32bit format on VT1708 */
2319 if (codec->vendor_id == 0x11061708)
2320 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002321 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2322
2323 spec->stream_name_digital = "VT1708 Digital";
2324 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2325 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2326
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002327 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002328 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2329 spec->num_mixers++;
2330 }
2331
2332 codec->patch_ops = via_patch_ops;
2333
2334 codec->patch_ops.init = via_auto_init;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002335#ifdef CONFIG_SND_HDA_POWER_SAVE
2336 spec->loopback.amplist = vt1708_loopbacks;
2337#endif
Lydia Wang1f2e99f2009-10-10 19:08:17 +08002338 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002339 return 0;
2340}
2341
2342/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002343static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002344 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2345 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2346 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2347 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2348 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2349 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2350 {
2351 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2352 /* The multiple "Capture Source" controls confuse alsamixer
2353 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01002354 */
2355 /* .name = "Capture Source", */
2356 .name = "Input Source",
2357 .count = 1,
2358 .info = via_mux_enum_info,
2359 .get = via_mux_enum_get,
2360 .put = via_mux_enum_put,
2361 },
2362 { } /* end */
2363};
2364
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002365static const struct hda_verb vt1709_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002366 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2367 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002368 { }
2369};
2370
Joseph Chanc577b8a2006-11-29 15:29:40 +01002371/*
2372 * generic initialization of ADC, input mixers and output mixers
2373 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002374static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002375 /*
2376 * Unmute ADC0-2 and set the default input to mic-in
2377 */
2378 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2379 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2380 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2381
2382
Josepch Chanf7278fd2007-12-13 16:40:40 +01002383 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01002384 * mixer widget
2385 */
2386 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01002387 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2388 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2389 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2390 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2391 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002392
2393 /*
2394 * Set up output selector (0x1a, 0x1b, 0x29)
2395 */
2396 /* set vol=0 to output mixers */
2397 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2398 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2399 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2400
2401 /*
2402 * Unmute PW3 and PW4
2403 */
2404 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2405 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2406
Lydia Wangbfdc6752009-10-10 19:08:50 +08002407 /* Set input of PW4 as MW0 */
2408 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002409 /* PW9 Output enable */
2410 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2411 { }
2412};
2413
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002414static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002415 .substreams = 1,
2416 .channels_min = 2,
2417 .channels_max = 10,
2418 .nid = 0x10, /* NID to query formats and rates */
2419 .ops = {
2420 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002421 .prepare = via_playback_multi_pcm_prepare,
2422 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002423 },
2424};
2425
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002426static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002427 .substreams = 1,
2428 .channels_min = 2,
2429 .channels_max = 6,
2430 .nid = 0x10, /* NID to query formats and rates */
2431 .ops = {
2432 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08002433 .prepare = via_playback_multi_pcm_prepare,
2434 .cleanup = via_playback_multi_pcm_cleanup,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002435 },
2436};
2437
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002438static const struct hda_pcm_stream vt1709_pcm_analog_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002439 .substreams = 2,
2440 .channels_min = 2,
2441 .channels_max = 2,
2442 .nid = 0x14, /* NID to query formats and rates */
2443 .ops = {
2444 .prepare = via_capture_pcm_prepare,
2445 .cleanup = via_capture_pcm_cleanup
2446 },
2447};
2448
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002449static const struct hda_pcm_stream vt1709_pcm_digital_playback = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002450 .substreams = 1,
2451 .channels_min = 2,
2452 .channels_max = 2,
2453 /* NID is set in via_build_pcms */
2454 .ops = {
2455 .open = via_dig_playback_pcm_open,
2456 .close = via_dig_playback_pcm_close
2457 },
2458};
2459
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002460static const struct hda_pcm_stream vt1709_pcm_digital_capture = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002461 .substreams = 1,
2462 .channels_min = 2,
2463 .channels_max = 2,
2464};
2465
2466static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2467 const struct auto_pin_cfg *cfg)
2468{
2469 int i;
2470 hda_nid_t nid;
2471
2472 if (cfg->line_outs == 4) /* 10 channels */
2473 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2474 else if (cfg->line_outs == 3) /* 6 channels */
2475 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2476
2477 spec->multiout.dac_nids = spec->private_dac_nids;
2478
2479 if (cfg->line_outs == 4) { /* 10 channels */
2480 for (i = 0; i < cfg->line_outs; i++) {
2481 nid = cfg->line_out_pins[i];
2482 if (nid) {
2483 /* config dac list */
2484 switch (i) {
2485 case AUTO_SEQ_FRONT:
2486 /* AOW0 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002487 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002488 break;
2489 case AUTO_SEQ_CENLFE:
2490 /* AOW2 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002491 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002492 break;
2493 case AUTO_SEQ_SURROUND:
2494 /* AOW3 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002495 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002496 break;
2497 case AUTO_SEQ_SIDE:
2498 /* AOW1 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002499 spec->private_dac_nids[i] = 0x27;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002500 break;
2501 default:
2502 break;
2503 }
2504 }
2505 }
Takashi Iwaidda14412011-05-02 11:29:30 +02002506 spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
Joseph Chanc577b8a2006-11-29 15:29:40 +01002507
2508 } else if (cfg->line_outs == 3) { /* 6 channels */
Lydia Wang377ff312009-10-10 19:08:55 +08002509 for (i = 0; i < cfg->line_outs; i++) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002510 nid = cfg->line_out_pins[i];
2511 if (nid) {
2512 /* config dac list */
Lydia Wang377ff312009-10-10 19:08:55 +08002513 switch (i) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002514 case AUTO_SEQ_FRONT:
2515 /* AOW0 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002516 spec->private_dac_nids[i] = 0x10;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002517 break;
2518 case AUTO_SEQ_CENLFE:
2519 /* AOW2 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002520 spec->private_dac_nids[i] = 0x12;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002521 break;
2522 case AUTO_SEQ_SURROUND:
2523 /* AOW1 */
Takashi Iwaidda14412011-05-02 11:29:30 +02002524 spec->private_dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002525 break;
2526 default:
2527 break;
2528 }
2529 }
2530 }
2531 }
2532
2533 return 0;
2534}
2535
2536/* add playback controls from the parsed DAC table */
2537static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2538 const struct auto_pin_cfg *cfg)
2539{
2540 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01002541 static const char * const chname[4] = {
2542 "Front", "Surround", "C/LFE", "Side"
2543 };
Lydia Wang4483a2f2009-10-10 19:08:29 +08002544 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
Joseph Chanc577b8a2006-11-29 15:29:40 +01002545 int i, err;
2546
2547 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2548 nid = cfg->line_out_pins[i];
2549
Lydia Wang377ff312009-10-10 19:08:55 +08002550 if (!nid)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002551 continue;
2552
Lydia Wang4483a2f2009-10-10 19:08:29 +08002553 nid_vol = nid_vols[i];
2554
Joseph Chanc577b8a2006-11-29 15:29:40 +01002555 if (i == AUTO_SEQ_CENLFE) {
2556 /* Center/LFE */
2557 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2558 "Center Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002559 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002560 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002561 if (err < 0)
2562 return err;
2563 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2564 "LFE Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002565 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002566 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002567 if (err < 0)
2568 return err;
2569 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2570 "Center Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002571 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002572 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002573 if (err < 0)
2574 return err;
2575 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2576 "LFE Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002577 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002578 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002579 if (err < 0)
2580 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002581 } else if (i == AUTO_SEQ_FRONT) {
Lydia Wang4483a2f2009-10-10 19:08:29 +08002582 /* ADD control to mixer index 0 */
Joseph Chanc577b8a2006-11-29 15:29:40 +01002583 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2584 "Master Front Playback Volume",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002585 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002586 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002587 if (err < 0)
2588 return err;
2589 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2590 "Master Front Playback Switch",
Lydia Wang4483a2f2009-10-10 19:08:29 +08002591 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002592 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002593 if (err < 0)
2594 return err;
Lydia Wang377ff312009-10-10 19:08:55 +08002595
Joseph Chanc577b8a2006-11-29 15:29:40 +01002596 /* add control to PW3 */
2597 sprintf(name, "%s Playback Volume", chname[i]);
2598 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002599 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2600 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002601 if (err < 0)
2602 return err;
2603 sprintf(name, "%s Playback Switch", chname[i]);
2604 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002605 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2606 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002607 if (err < 0)
2608 return err;
2609 } else if (i == AUTO_SEQ_SURROUND) {
2610 sprintf(name, "%s Playback Volume", chname[i]);
2611 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002612 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002613 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002614 if (err < 0)
2615 return err;
2616 sprintf(name, "%s Playback Switch", chname[i]);
2617 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002618 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002619 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002620 if (err < 0)
2621 return err;
2622 } else if (i == AUTO_SEQ_SIDE) {
2623 sprintf(name, "%s Playback Volume", chname[i]);
2624 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002625 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002626 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002627 if (err < 0)
2628 return err;
2629 sprintf(name, "%s Playback Switch", chname[i]);
2630 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Lydia Wang4483a2f2009-10-10 19:08:29 +08002631 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002632 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01002633 if (err < 0)
2634 return err;
2635 }
2636 }
2637
2638 return 0;
2639}
2640
2641static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2642{
2643 int err;
2644
2645 if (!pin)
2646 return 0;
2647
2648 if (spec->multiout.num_dacs == 5) /* 10 channels */
2649 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2650 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2651 spec->multiout.hp_nid = 0;
Lydia Wangcdc17842009-10-10 19:07:47 +08002652 spec->hp_independent_mode_index = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002653
2654 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2655 "Headphone Playback Volume",
2656 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2657 if (err < 0)
2658 return err;
2659 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2660 "Headphone Playback Switch",
2661 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2662 if (err < 0)
2663 return err;
2664
2665 return 0;
2666}
2667
2668/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002669static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
Joseph Chanc577b8a2006-11-29 15:29:40 +01002670 const struct auto_pin_cfg *cfg)
2671{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002672 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002673}
2674
2675static int vt1709_parse_auto_config(struct hda_codec *codec)
2676{
2677 struct via_spec *spec = codec->spec;
2678 int err;
2679
2680 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2681 if (err < 0)
2682 return err;
2683 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2684 if (err < 0)
2685 return err;
2686 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2687 return 0; /* can't find valid BIOS pin config */
2688
2689 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2690 if (err < 0)
2691 return err;
2692 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2693 if (err < 0)
2694 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002695 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002696 if (err < 0)
2697 return err;
2698
2699 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2700
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002701 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01002702 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002703 spec->dig_in_pin = VT1709_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002704 if (spec->autocfg.dig_in_pin)
2705 spec->dig_in_nid = VT1709_DIGIN_NID;
2706
Takashi Iwai603c4012008-07-30 15:01:44 +02002707 if (spec->kctls.list)
2708 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002709
Harald Welte0aa62ae2008-09-09 15:58:27 +08002710 spec->input_mux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01002711
Harald Weltef8fdd492008-09-15 22:41:31 +08002712 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02002713 via_hp_build(codec);
Harald Weltef8fdd492008-09-15 22:41:31 +08002714
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002715 via_smart51_build(spec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002716 return 1;
2717}
2718
Takashi Iwaicb53c622007-08-10 17:21:45 +02002719#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002720static const struct hda_amp_list vt1709_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002721 { 0x18, HDA_INPUT, 1 },
2722 { 0x18, HDA_INPUT, 2 },
2723 { 0x18, HDA_INPUT, 3 },
2724 { 0x18, HDA_INPUT, 4 },
2725 { } /* end */
2726};
2727#endif
2728
Joseph Chanc577b8a2006-11-29 15:29:40 +01002729static int patch_vt1709_10ch(struct hda_codec *codec)
2730{
2731 struct via_spec *spec;
2732 int err;
2733
2734 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002735 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002736 if (spec == NULL)
2737 return -ENOMEM;
2738
Joseph Chanc577b8a2006-11-29 15:29:40 +01002739 err = vt1709_parse_auto_config(codec);
2740 if (err < 0) {
2741 via_free(codec);
2742 return err;
2743 } else if (!err) {
2744 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2745 "Using genenic mode...\n");
2746 }
2747
Harald Welte69e52a82008-09-09 15:57:32 +08002748 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2749 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002750
2751 spec->stream_name_analog = "VT1709 Analog";
2752 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2753 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2754
2755 spec->stream_name_digital = "VT1709 Digital";
2756 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2757 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2758
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002759 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002760 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2761 spec->num_mixers++;
2762 }
2763
2764 codec->patch_ops = via_patch_ops;
2765
2766 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002767 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002768#ifdef CONFIG_SND_HDA_POWER_SAVE
2769 spec->loopback.amplist = vt1709_loopbacks;
2770#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002771
2772 return 0;
2773}
2774/*
2775 * generic initialization of ADC, input mixers and output mixers
2776 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002777static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002778 /*
2779 * Unmute ADC0-2 and set the default input to mic-in
2780 */
2781 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2782 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2783 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2784
2785
2786 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2787 * mixer widget
2788 */
2789 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2790 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2791 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2792 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2793 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2794 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2795
2796 /*
2797 * Set up output selector (0x1a, 0x1b, 0x29)
2798 */
2799 /* set vol=0 to output mixers */
2800 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2801 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2802 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2803
2804 /*
2805 * Unmute PW3 and PW4
2806 */
2807 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2808 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2809
2810 /* Set input of PW4 as MW0 */
2811 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01002812 /* PW9 Output enable */
2813 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2814 { }
2815};
2816
2817static int patch_vt1709_6ch(struct hda_codec *codec)
2818{
2819 struct via_spec *spec;
2820 int err;
2821
2822 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002823 spec = via_new_spec(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01002824 if (spec == NULL)
2825 return -ENOMEM;
2826
Joseph Chanc577b8a2006-11-29 15:29:40 +01002827 err = vt1709_parse_auto_config(codec);
2828 if (err < 0) {
2829 via_free(codec);
2830 return err;
2831 } else if (!err) {
2832 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2833 "Using genenic mode...\n");
2834 }
2835
Harald Welte69e52a82008-09-09 15:57:32 +08002836 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2837 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01002838
2839 spec->stream_name_analog = "VT1709 Analog";
2840 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2841 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2842
2843 spec->stream_name_digital = "VT1709 Digital";
2844 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2845 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2846
Takashi Iwaia766d0d2011-06-17 09:01:29 +02002847 if (spec->adc_nids && spec->input_mux) {
Joseph Chanc577b8a2006-11-29 15:29:40 +01002848 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2849 spec->num_mixers++;
2850 }
2851
2852 codec->patch_ops = via_patch_ops;
2853
2854 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002855 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02002856#ifdef CONFIG_SND_HDA_POWER_SAVE
2857 spec->loopback.amplist = vt1709_loopbacks;
2858#endif
Josepch Chanf7278fd2007-12-13 16:40:40 +01002859 return 0;
2860}
2861
2862/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002863static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002864 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2865 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2866 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2867 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2868 {
2869 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2870 /* The multiple "Capture Source" controls confuse alsamixer
2871 * So call somewhat different..
Josepch Chanf7278fd2007-12-13 16:40:40 +01002872 */
2873 /* .name = "Capture Source", */
2874 .name = "Input Source",
2875 .count = 1,
2876 .info = via_mux_enum_info,
2877 .get = via_mux_enum_get,
2878 .put = via_mux_enum_put,
2879 },
2880 { } /* end */
2881};
2882/*
2883 * generic initialization of ADC, input mixers and output mixers
2884 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002885static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002886 /*
2887 * Unmute ADC0-1 and set the default input to mic-in
2888 */
2889 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2890 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2891
2892
2893 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2894 * mixer widget
2895 */
2896 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2897 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2898 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2899 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2900 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2901 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2902
2903 /*
2904 * Set up output mixers
2905 */
2906 /* set vol=0 to output mixers */
2907 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2908 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2909 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2910
2911 /* Setup default input to PW4 */
Lydia Wangbfdc6752009-10-10 19:08:50 +08002912 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
Josepch Chanf7278fd2007-12-13 16:40:40 +01002913 /* PW9 Output enable */
2914 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2915 /* PW10 Input enable */
2916 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2917 { }
2918};
2919
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002920static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01002921 /*
2922 * Unmute ADC0-1 and set the default input to mic-in
2923 */
2924 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2925 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2926
2927
2928 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2929 * mixer widget
2930 */
2931 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2932 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2933 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2934 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2935 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2936 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2937
2938 /*
2939 * Set up output mixers
2940 */
2941 /* set vol=0 to output mixers */
2942 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2943 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2944 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2945
2946 /* Setup default input of PW4 to MW0 */
2947 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2948 /* PW9 Output enable */
2949 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2950 /* PW10 Input enable */
2951 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2952 { }
2953};
2954
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002955static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08002956 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2957 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2958 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2959 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2960 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2961 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2962 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2963 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2964 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08002965 { }
2966};
2967
Lydia Wang17314372009-10-10 19:07:37 +08002968static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2969 struct hda_codec *codec,
2970 struct snd_pcm_substream *substream)
2971{
2972 int idle = substream->pstr->substream_opened == 1
2973 && substream->ref_count == 0;
2974
2975 analog_low_current_mode(codec, idle);
2976 return 0;
2977}
2978
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002979static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002980 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002981 .channels_min = 2,
2982 .channels_max = 8,
2983 .nid = 0x10, /* NID to query formats and rates */
2984 .ops = {
2985 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002986 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08002987 .cleanup = via_playback_multi_pcm_cleanup,
2988 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01002989 },
2990};
2991
Takashi Iwai90dd48a2011-05-02 12:38:19 +02002992static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002993 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002994 .channels_min = 2,
2995 .channels_max = 4,
2996 .nid = 0x10, /* NID to query formats and rates */
2997 .ops = {
2998 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002999 .prepare = via_playback_multi_pcm_prepare,
3000 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01003001 },
3002};
3003
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003004static const struct hda_pcm_stream vt1708B_pcm_analog_capture = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003005 .substreams = 2,
3006 .channels_min = 2,
3007 .channels_max = 2,
3008 .nid = 0x13, /* NID to query formats and rates */
3009 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003010 .open = via_pcm_open_close,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003011 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003012 .cleanup = via_capture_pcm_cleanup,
3013 .close = via_pcm_open_close
Josepch Chanf7278fd2007-12-13 16:40:40 +01003014 },
3015};
3016
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003017static const struct hda_pcm_stream vt1708B_pcm_digital_playback = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003018 .substreams = 1,
3019 .channels_min = 2,
3020 .channels_max = 2,
3021 /* NID is set in via_build_pcms */
3022 .ops = {
3023 .open = via_dig_playback_pcm_open,
3024 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003025 .prepare = via_dig_playback_pcm_prepare,
3026 .cleanup = via_dig_playback_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01003027 },
3028};
3029
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003030static const struct hda_pcm_stream vt1708B_pcm_digital_capture = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003031 .substreams = 1,
3032 .channels_min = 2,
3033 .channels_max = 2,
3034};
3035
3036/* fill in the dac_nids table from the parsed pin configuration */
3037static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3038 const struct auto_pin_cfg *cfg)
3039{
3040 int i;
3041 hda_nid_t nid;
3042
3043 spec->multiout.num_dacs = cfg->line_outs;
3044
3045 spec->multiout.dac_nids = spec->private_dac_nids;
3046
3047 for (i = 0; i < 4; i++) {
3048 nid = cfg->line_out_pins[i];
3049 if (nid) {
3050 /* config dac list */
3051 switch (i) {
3052 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02003053 spec->private_dac_nids[i] = 0x10;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003054 break;
3055 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003056 spec->private_dac_nids[i] = 0x24;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003057 break;
3058 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02003059 spec->private_dac_nids[i] = 0x11;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003060 break;
3061 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003062 spec->private_dac_nids[i] = 0x25;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003063 break;
3064 }
3065 }
3066 }
3067
3068 return 0;
3069}
3070
3071/* add playback controls from the parsed DAC table */
3072static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3073 const struct auto_pin_cfg *cfg)
3074{
3075 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01003076 static const char * const chname[4] = {
3077 "Front", "Surround", "C/LFE", "Side"
3078 };
Harald Weltefb4cb772008-09-09 15:53:36 +08003079 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
Josepch Chanf7278fd2007-12-13 16:40:40 +01003080 hda_nid_t nid, nid_vol = 0;
3081 int i, err;
3082
3083 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3084 nid = cfg->line_out_pins[i];
3085
3086 if (!nid)
3087 continue;
3088
3089 nid_vol = nid_vols[i];
3090
3091 if (i == AUTO_SEQ_CENLFE) {
3092 /* Center/LFE */
3093 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3094 "Center Playback Volume",
3095 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3096 HDA_OUTPUT));
3097 if (err < 0)
3098 return err;
3099 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3100 "LFE Playback Volume",
3101 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3102 HDA_OUTPUT));
3103 if (err < 0)
3104 return err;
3105 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3106 "Center Playback Switch",
3107 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3108 HDA_OUTPUT));
3109 if (err < 0)
3110 return err;
3111 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3112 "LFE Playback Switch",
3113 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3114 HDA_OUTPUT));
3115 if (err < 0)
3116 return err;
3117 } else if (i == AUTO_SEQ_FRONT) {
3118 /* add control to mixer index 0 */
3119 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3120 "Master Front Playback Volume",
3121 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3122 HDA_INPUT));
3123 if (err < 0)
3124 return err;
3125 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3126 "Master Front Playback Switch",
3127 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3128 HDA_INPUT));
3129 if (err < 0)
3130 return err;
3131
3132 /* add control to PW3 */
3133 sprintf(name, "%s Playback Volume", chname[i]);
3134 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3135 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3136 HDA_OUTPUT));
3137 if (err < 0)
3138 return err;
3139 sprintf(name, "%s Playback Switch", chname[i]);
3140 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3141 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3142 HDA_OUTPUT));
3143 if (err < 0)
3144 return err;
3145 } else {
3146 sprintf(name, "%s Playback Volume", chname[i]);
3147 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3148 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3149 HDA_OUTPUT));
3150 if (err < 0)
3151 return err;
3152 sprintf(name, "%s Playback Switch", chname[i]);
3153 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3154 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3155 HDA_OUTPUT));
3156 if (err < 0)
3157 return err;
3158 }
3159 }
3160
3161 return 0;
3162}
3163
3164static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3165{
3166 int err;
3167
3168 if (!pin)
3169 return 0;
3170
3171 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08003172 spec->hp_independent_mode_index = 1;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003173
3174 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3175 "Headphone Playback Volume",
3176 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3177 if (err < 0)
3178 return err;
3179 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3180 "Headphone Playback Switch",
3181 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3182 if (err < 0)
3183 return err;
3184
Harald Welte0aa62ae2008-09-09 15:58:27 +08003185 create_hp_imux(spec);
3186
Josepch Chanf7278fd2007-12-13 16:40:40 +01003187 return 0;
3188}
3189
3190/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003191static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
Josepch Chanf7278fd2007-12-13 16:40:40 +01003192 const struct auto_pin_cfg *cfg)
3193{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003194 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003195}
3196
3197static int vt1708B_parse_auto_config(struct hda_codec *codec)
3198{
3199 struct via_spec *spec = codec->spec;
3200 int err;
3201
3202 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3203 if (err < 0)
3204 return err;
3205 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3206 if (err < 0)
3207 return err;
3208 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3209 return 0; /* can't find valid BIOS pin config */
3210
3211 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3212 if (err < 0)
3213 return err;
3214 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3215 if (err < 0)
3216 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003217 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003218 if (err < 0)
3219 return err;
3220
3221 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3222
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003223 if (spec->autocfg.dig_outs)
Josepch Chanf7278fd2007-12-13 16:40:40 +01003224 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02003225 spec->dig_in_pin = VT1708B_DIGIN_PIN;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003226 if (spec->autocfg.dig_in_pin)
3227 spec->dig_in_nid = VT1708B_DIGIN_NID;
3228
Takashi Iwai603c4012008-07-30 15:01:44 +02003229 if (spec->kctls.list)
3230 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003231
Harald Welte0aa62ae2008-09-09 15:58:27 +08003232 spec->input_mux = &spec->private_imux[0];
3233
Harald Weltef8fdd492008-09-15 22:41:31 +08003234 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003235 via_hp_build(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003236
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003237 via_smart51_build(spec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003238 return 1;
3239}
3240
3241#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003242static const struct hda_amp_list vt1708B_loopbacks[] = {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003243 { 0x16, HDA_INPUT, 1 },
3244 { 0x16, HDA_INPUT, 2 },
3245 { 0x16, HDA_INPUT, 3 },
3246 { 0x16, HDA_INPUT, 4 },
3247 { } /* end */
3248};
3249#endif
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003250
3251static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3252{
3253 struct via_spec *spec = codec->spec;
3254 int imux_is_smixer;
3255 unsigned int parm;
3256 int is_8ch = 0;
Lydia Wangbc92df72011-03-23 17:56:05 +08003257 if ((spec->codec_type != VT1708B_4CH) &&
3258 (codec->vendor_id != 0x11064397))
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003259 is_8ch = 1;
3260
3261 /* SW0 (17h) = stereo mixer */
3262 imux_is_smixer =
3263 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3264 == ((spec->codec_type == VT1708S) ? 5 : 0));
3265 /* inputs */
3266 /* PW 1/2/5 (1ah/1bh/1eh) */
3267 parm = AC_PWRST_D3;
3268 set_pin_power_state(codec, 0x1a, &parm);
3269 set_pin_power_state(codec, 0x1b, &parm);
3270 set_pin_power_state(codec, 0x1e, &parm);
3271 if (imux_is_smixer)
3272 parm = AC_PWRST_D0;
3273 /* SW0 (17h), AIW 0/1 (13h/14h) */
3274 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3275 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3276 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3277
3278 /* outputs */
3279 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3280 parm = AC_PWRST_D3;
3281 set_pin_power_state(codec, 0x19, &parm);
3282 if (spec->smart51_enabled)
3283 set_pin_power_state(codec, 0x1b, &parm);
3284 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3285 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3286
3287 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3288 if (is_8ch) {
3289 parm = AC_PWRST_D3;
3290 set_pin_power_state(codec, 0x22, &parm);
3291 if (spec->smart51_enabled)
3292 set_pin_power_state(codec, 0x1a, &parm);
3293 snd_hda_codec_write(codec, 0x26, 0,
3294 AC_VERB_SET_POWER_STATE, parm);
3295 snd_hda_codec_write(codec, 0x24, 0,
3296 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08003297 } else if (codec->vendor_id == 0x11064397) {
3298 /* PW7(23h), SW2(27h), AOW2(25h) */
3299 parm = AC_PWRST_D3;
3300 set_pin_power_state(codec, 0x23, &parm);
3301 if (spec->smart51_enabled)
3302 set_pin_power_state(codec, 0x1a, &parm);
3303 snd_hda_codec_write(codec, 0x27, 0,
3304 AC_VERB_SET_POWER_STATE, parm);
3305 snd_hda_codec_write(codec, 0x25, 0,
3306 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003307 }
3308
3309 /* PW 3/4/7 (1ch/1dh/23h) */
3310 parm = AC_PWRST_D3;
3311 /* force to D0 for internal Speaker */
3312 set_pin_power_state(codec, 0x1c, &parm);
3313 set_pin_power_state(codec, 0x1d, &parm);
3314 if (is_8ch)
3315 set_pin_power_state(codec, 0x23, &parm);
3316
3317 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3318 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3319 imux_is_smixer ? AC_PWRST_D0 : parm);
3320 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3321 if (is_8ch) {
3322 snd_hda_codec_write(codec, 0x25, 0,
3323 AC_VERB_SET_POWER_STATE, parm);
3324 snd_hda_codec_write(codec, 0x27, 0,
3325 AC_VERB_SET_POWER_STATE, parm);
Lydia Wangbc92df72011-03-23 17:56:05 +08003326 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3327 snd_hda_codec_write(codec, 0x25, 0,
3328 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003329}
3330
Lydia Wang518bf3b2009-10-10 19:07:29 +08003331static int patch_vt1708S(struct hda_codec *codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003332static int patch_vt1708B_8ch(struct hda_codec *codec)
3333{
3334 struct via_spec *spec;
3335 int err;
3336
Lydia Wang518bf3b2009-10-10 19:07:29 +08003337 if (get_codec_type(codec) == VT1708BCE)
3338 return patch_vt1708S(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003339 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003340 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003341 if (spec == NULL)
3342 return -ENOMEM;
3343
Josepch Chanf7278fd2007-12-13 16:40:40 +01003344 /* automatic parse from the BIOS config */
3345 err = vt1708B_parse_auto_config(codec);
3346 if (err < 0) {
3347 via_free(codec);
3348 return err;
3349 } else if (!err) {
3350 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3351 "from BIOS. Using genenic mode...\n");
3352 }
3353
Harald Welte69e52a82008-09-09 15:57:32 +08003354 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3355 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003356
3357 spec->stream_name_analog = "VT1708B Analog";
3358 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3359 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3360
3361 spec->stream_name_digital = "VT1708B Digital";
3362 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3363 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3364
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003365 if (spec->adc_nids && spec->input_mux) {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003366 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3367 spec->num_mixers++;
3368 }
3369
3370 codec->patch_ops = via_patch_ops;
3371
3372 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003373 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003374#ifdef CONFIG_SND_HDA_POWER_SAVE
3375 spec->loopback.amplist = vt1708B_loopbacks;
3376#endif
3377
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003378 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3379
Josepch Chanf7278fd2007-12-13 16:40:40 +01003380 return 0;
3381}
3382
3383static int patch_vt1708B_4ch(struct hda_codec *codec)
3384{
3385 struct via_spec *spec;
3386 int err;
3387
3388 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003389 spec = via_new_spec(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01003390 if (spec == NULL)
3391 return -ENOMEM;
3392
Josepch Chanf7278fd2007-12-13 16:40:40 +01003393 /* automatic parse from the BIOS config */
3394 err = vt1708B_parse_auto_config(codec);
3395 if (err < 0) {
3396 via_free(codec);
3397 return err;
3398 } else if (!err) {
3399 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3400 "from BIOS. Using genenic mode...\n");
3401 }
3402
Harald Welte69e52a82008-09-09 15:57:32 +08003403 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3404 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003405
3406 spec->stream_name_analog = "VT1708B Analog";
3407 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3408 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3409
3410 spec->stream_name_digital = "VT1708B Digital";
3411 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3412 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3413
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003414 if (spec->adc_nids && spec->input_mux) {
Josepch Chanf7278fd2007-12-13 16:40:40 +01003415 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3416 spec->num_mixers++;
3417 }
3418
3419 codec->patch_ops = via_patch_ops;
3420
3421 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003422 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01003423#ifdef CONFIG_SND_HDA_POWER_SAVE
3424 spec->loopback.amplist = vt1708B_loopbacks;
3425#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01003426
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003427 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3428
Joseph Chanc577b8a2006-11-29 15:29:40 +01003429 return 0;
3430}
3431
Harald Welted949cac2008-09-09 15:56:01 +08003432/* Patch for VT1708S */
3433
3434/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003435static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003436 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3437 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3438 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3439 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
Lydia Wang6369bcf2009-10-10 19:08:31 +08003440 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3441 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3442 HDA_INPUT),
Harald Welted949cac2008-09-09 15:56:01 +08003443 {
3444 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3445 /* The multiple "Capture Source" controls confuse alsamixer
3446 * So call somewhat different..
3447 */
3448 /* .name = "Capture Source", */
3449 .name = "Input Source",
3450 .count = 1,
3451 .info = via_mux_enum_info,
3452 .get = via_mux_enum_get,
3453 .put = via_mux_enum_put,
3454 },
3455 { } /* end */
3456};
3457
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003458static const struct hda_verb vt1708S_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003459 /* Unmute ADC0-1 and set the default input to mic-in */
3460 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3461 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3462
3463 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3464 * analog-loopback mixer widget */
3465 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3466 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3467 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3468 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3469 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3470 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3471
3472 /* Setup default input of PW4 to MW0 */
3473 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
Harald Welte5691ec72008-09-15 22:42:26 +08003474 /* PW9, PW10 Output enable */
Harald Welted949cac2008-09-09 15:56:01 +08003475 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welte5691ec72008-09-15 22:42:26 +08003476 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welted7426322008-09-15 22:43:23 +08003477 /* Enable Mic Boost Volume backdoor */
3478 {0x1, 0xf98, 0x1},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003479 /* don't bybass mixer */
3480 {0x1, 0xf88, 0xc0},
Harald Welted949cac2008-09-09 15:56:01 +08003481 { }
3482};
3483
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003484static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003485 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3486 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3487 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3488 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3489 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3490 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3491 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3492 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3493 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003494 { }
3495};
3496
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003497static const struct hda_verb vt1705_uniwill_init_verbs[] = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003498 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3499 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3500 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3501 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3502 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3503 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3504 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3505 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3506 { }
3507};
3508
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003509static const struct hda_pcm_stream vt1708S_pcm_analog_playback = {
Harald Welted949cac2008-09-09 15:56:01 +08003510 .substreams = 2,
3511 .channels_min = 2,
3512 .channels_max = 8,
3513 .nid = 0x10, /* NID to query formats and rates */
3514 .ops = {
3515 .open = via_playback_pcm_open,
Lydia Wangc873cc22009-10-10 19:08:21 +08003516 .prepare = via_playback_multi_pcm_prepare,
3517 .cleanup = via_playback_multi_pcm_cleanup,
Lydia Wang17314372009-10-10 19:07:37 +08003518 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003519 },
3520};
3521
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003522static const struct hda_pcm_stream vt1705_pcm_analog_playback = {
Lydia Wangbc92df72011-03-23 17:56:05 +08003523 .substreams = 2,
3524 .channels_min = 2,
3525 .channels_max = 6,
3526 .nid = 0x10, /* NID to query formats and rates */
3527 .ops = {
3528 .open = via_playback_pcm_open,
3529 .prepare = via_playback_multi_pcm_prepare,
3530 .cleanup = via_playback_multi_pcm_cleanup,
3531 .close = via_pcm_open_close
3532 },
3533};
3534
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003535static const struct hda_pcm_stream vt1708S_pcm_analog_capture = {
Harald Welted949cac2008-09-09 15:56:01 +08003536 .substreams = 2,
3537 .channels_min = 2,
3538 .channels_max = 2,
3539 .nid = 0x13, /* NID to query formats and rates */
3540 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08003541 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08003542 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08003543 .cleanup = via_capture_pcm_cleanup,
3544 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08003545 },
3546};
3547
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003548static const struct hda_pcm_stream vt1708S_pcm_digital_playback = {
Takashi Iwai9da29272009-05-07 16:31:14 +02003549 .substreams = 1,
Harald Welted949cac2008-09-09 15:56:01 +08003550 .channels_min = 2,
3551 .channels_max = 2,
3552 /* NID is set in via_build_pcms */
3553 .ops = {
3554 .open = via_dig_playback_pcm_open,
3555 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003556 .prepare = via_dig_playback_pcm_prepare,
3557 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08003558 },
3559};
3560
3561/* fill in the dac_nids table from the parsed pin configuration */
3562static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3563 const struct auto_pin_cfg *cfg)
3564{
3565 int i;
3566 hda_nid_t nid;
3567
3568 spec->multiout.num_dacs = cfg->line_outs;
3569
3570 spec->multiout.dac_nids = spec->private_dac_nids;
3571
3572 for (i = 0; i < 4; i++) {
3573 nid = cfg->line_out_pins[i];
3574 if (nid) {
3575 /* config dac list */
3576 switch (i) {
3577 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02003578 spec->private_dac_nids[i] = 0x10;
Harald Welted949cac2008-09-09 15:56:01 +08003579 break;
3580 case AUTO_SEQ_CENLFE:
Lydia Wangbc92df72011-03-23 17:56:05 +08003581 if (spec->codec->vendor_id == 0x11064397)
Takashi Iwaidda14412011-05-02 11:29:30 +02003582 spec->private_dac_nids[i] = 0x25;
Lydia Wangbc92df72011-03-23 17:56:05 +08003583 else
Takashi Iwaidda14412011-05-02 11:29:30 +02003584 spec->private_dac_nids[i] = 0x24;
Harald Welted949cac2008-09-09 15:56:01 +08003585 break;
3586 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02003587 spec->private_dac_nids[i] = 0x11;
Harald Welted949cac2008-09-09 15:56:01 +08003588 break;
3589 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02003590 spec->private_dac_nids[i] = 0x25;
Harald Welted949cac2008-09-09 15:56:01 +08003591 break;
3592 }
3593 }
3594 }
3595
Clemens Ladisch32e01912010-07-12 16:28:50 +02003596 /* for Smart 5.1, line/mic inputs double as output pins */
3597 if (cfg->line_outs == 1) {
3598 spec->multiout.num_dacs = 3;
Takashi Iwaidda14412011-05-02 11:29:30 +02003599 spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11;
Lydia Wangbc92df72011-03-23 17:56:05 +08003600 if (spec->codec->vendor_id == 0x11064397)
Takashi Iwaidda14412011-05-02 11:29:30 +02003601 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25;
Lydia Wangbc92df72011-03-23 17:56:05 +08003602 else
Takashi Iwaidda14412011-05-02 11:29:30 +02003603 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24;
Clemens Ladisch32e01912010-07-12 16:28:50 +02003604 }
3605
Harald Welted949cac2008-09-09 15:56:01 +08003606 return 0;
3607}
3608
3609/* add playback controls from the parsed DAC table */
Lydia Wangbc92df72011-03-23 17:56:05 +08003610static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08003611 const struct auto_pin_cfg *cfg)
3612{
Lydia Wangbc92df72011-03-23 17:56:05 +08003613 struct via_spec *spec = codec->spec;
Harald Welted949cac2008-09-09 15:56:01 +08003614 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01003615 static const char * const chname[4] = {
3616 "Front", "Surround", "C/LFE", "Side"
3617 };
Lydia Wangbc92df72011-03-23 17:56:05 +08003618 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3619 {0x10, 0x11, 0x25, 0} };
3620 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3621 {0x1C, 0x18, 0x27, 0} };
Harald Welted949cac2008-09-09 15:56:01 +08003622 hda_nid_t nid, nid_vol, nid_mute;
3623 int i, err;
3624
3625 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3626 nid = cfg->line_out_pins[i];
3627
Clemens Ladisch32e01912010-07-12 16:28:50 +02003628 /* for Smart 5.1, there are always at least six channels */
3629 if (!nid && i > AUTO_SEQ_CENLFE)
Harald Welted949cac2008-09-09 15:56:01 +08003630 continue;
3631
Lydia Wangbc92df72011-03-23 17:56:05 +08003632 if (codec->vendor_id == 0x11064397) {
3633 nid_vol = nid_vols[1][i];
3634 nid_mute = nid_mutes[1][i];
3635 } else {
3636 nid_vol = nid_vols[0][i];
3637 nid_mute = nid_mutes[0][i];
3638 }
3639 if (!nid_vol && !nid_mute)
3640 continue;
Harald Welted949cac2008-09-09 15:56:01 +08003641
3642 if (i == AUTO_SEQ_CENLFE) {
3643 /* Center/LFE */
3644 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3645 "Center Playback Volume",
3646 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3647 HDA_OUTPUT));
3648 if (err < 0)
3649 return err;
3650 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3651 "LFE Playback Volume",
3652 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3653 HDA_OUTPUT));
3654 if (err < 0)
3655 return err;
3656 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3657 "Center Playback Switch",
3658 HDA_COMPOSE_AMP_VAL(nid_mute,
3659 1, 0,
3660 HDA_OUTPUT));
3661 if (err < 0)
3662 return err;
3663 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3664 "LFE Playback Switch",
3665 HDA_COMPOSE_AMP_VAL(nid_mute,
3666 2, 0,
3667 HDA_OUTPUT));
3668 if (err < 0)
3669 return err;
3670 } else if (i == AUTO_SEQ_FRONT) {
3671 /* add control to mixer index 0 */
3672 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3673 "Master Front Playback Volume",
3674 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3675 HDA_INPUT));
3676 if (err < 0)
3677 return err;
3678 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3679 "Master Front Playback Switch",
3680 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3681 HDA_INPUT));
3682 if (err < 0)
3683 return err;
3684
3685 /* Front */
3686 sprintf(name, "%s Playback Volume", chname[i]);
3687 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3688 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3689 HDA_OUTPUT));
3690 if (err < 0)
3691 return err;
3692 sprintf(name, "%s Playback Switch", chname[i]);
3693 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3694 HDA_COMPOSE_AMP_VAL(nid_mute,
3695 3, 0,
3696 HDA_OUTPUT));
3697 if (err < 0)
3698 return err;
3699 } else {
3700 sprintf(name, "%s Playback Volume", chname[i]);
3701 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3702 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3703 HDA_OUTPUT));
3704 if (err < 0)
3705 return err;
3706 sprintf(name, "%s Playback Switch", chname[i]);
3707 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3708 HDA_COMPOSE_AMP_VAL(nid_mute,
3709 3, 0,
3710 HDA_OUTPUT));
3711 if (err < 0)
3712 return err;
3713 }
3714 }
3715
3716 return 0;
3717}
3718
3719static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3720{
3721 int err;
3722
3723 if (!pin)
3724 return 0;
3725
3726 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
Lydia Wangcdc17842009-10-10 19:07:47 +08003727 spec->hp_independent_mode_index = 1;
Harald Welted949cac2008-09-09 15:56:01 +08003728
3729 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3730 "Headphone Playback Volume",
3731 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3732 if (err < 0)
3733 return err;
3734
3735 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3736 "Headphone Playback Switch",
3737 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3738 if (err < 0)
3739 return err;
3740
Harald Welte0aa62ae2008-09-09 15:58:27 +08003741 create_hp_imux(spec);
3742
Harald Welted949cac2008-09-09 15:56:01 +08003743 return 0;
3744}
3745
3746/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003747static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08003748 const struct auto_pin_cfg *cfg)
3749{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003750 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
Harald Welted949cac2008-09-09 15:56:01 +08003751}
3752
Takashi Iwai9da29272009-05-07 16:31:14 +02003753/* fill out digital output widgets; one for master and one for slave outputs */
3754static void fill_dig_outs(struct hda_codec *codec)
3755{
3756 struct via_spec *spec = codec->spec;
3757 int i;
3758
3759 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3760 hda_nid_t nid;
3761 int conn;
3762
3763 nid = spec->autocfg.dig_out_pins[i];
3764 if (!nid)
3765 continue;
3766 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3767 if (conn < 1)
3768 continue;
3769 if (!spec->multiout.dig_out_nid)
3770 spec->multiout.dig_out_nid = nid;
3771 else {
3772 spec->slave_dig_outs[0] = nid;
3773 break; /* at most two dig outs */
3774 }
3775 }
3776}
3777
Harald Welted949cac2008-09-09 15:56:01 +08003778static int vt1708S_parse_auto_config(struct hda_codec *codec)
3779{
3780 struct via_spec *spec = codec->spec;
3781 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003782
Takashi Iwai9da29272009-05-07 16:31:14 +02003783 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08003784 if (err < 0)
3785 return err;
3786 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3787 if (err < 0)
3788 return err;
3789 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3790 return 0; /* can't find valid BIOS pin config */
3791
Lydia Wangbc92df72011-03-23 17:56:05 +08003792 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003793 if (err < 0)
3794 return err;
3795 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3796 if (err < 0)
3797 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003798 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08003799 if (err < 0)
3800 return err;
3801
3802 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3803
Takashi Iwai9da29272009-05-07 16:31:14 +02003804 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08003805
Takashi Iwai603c4012008-07-30 15:01:44 +02003806 if (spec->kctls.list)
3807 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08003808
Harald Welte0aa62ae2008-09-09 15:58:27 +08003809 spec->input_mux = &spec->private_imux[0];
3810
Harald Weltef8fdd492008-09-15 22:41:31 +08003811 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02003812 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003813
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003814 via_smart51_build(spec);
Harald Welted949cac2008-09-09 15:56:01 +08003815 return 1;
3816}
3817
3818#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003819static const struct hda_amp_list vt1708S_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003820 { 0x16, HDA_INPUT, 1 },
3821 { 0x16, HDA_INPUT, 2 },
3822 { 0x16, HDA_INPUT, 3 },
3823 { 0x16, HDA_INPUT, 4 },
3824 { } /* end */
3825};
3826#endif
3827
Lydia Wang6369bcf2009-10-10 19:08:31 +08003828static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3829 int offset, int num_steps, int step_size)
3830{
3831 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3832 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3833 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3834 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3835 (0 << AC_AMPCAP_MUTE_SHIFT));
3836}
3837
Harald Welted949cac2008-09-09 15:56:01 +08003838static int patch_vt1708S(struct hda_codec *codec)
3839{
3840 struct via_spec *spec;
3841 int err;
3842
3843 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01003844 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003845 if (spec == NULL)
3846 return -ENOMEM;
3847
Harald Welted949cac2008-09-09 15:56:01 +08003848 /* automatic parse from the BIOS config */
3849 err = vt1708S_parse_auto_config(codec);
3850 if (err < 0) {
3851 via_free(codec);
3852 return err;
3853 } else if (!err) {
3854 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3855 "from BIOS. Using genenic mode...\n");
3856 }
3857
Harald Welte69e52a82008-09-09 15:57:32 +08003858 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
Lydia Wangbc92df72011-03-23 17:56:05 +08003859 if (codec->vendor_id == 0x11064397)
3860 spec->init_verbs[spec->num_iverbs++] =
3861 vt1705_uniwill_init_verbs;
3862 else
3863 spec->init_verbs[spec->num_iverbs++] =
3864 vt1708S_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003865
Lydia Wang36dd5c42009-10-20 13:18:04 +08003866 if (codec->vendor_id == 0x11060440)
3867 spec->stream_name_analog = "VT1818S Analog";
Lydia Wangbc92df72011-03-23 17:56:05 +08003868 else if (codec->vendor_id == 0x11064397)
3869 spec->stream_name_analog = "VT1705 Analog";
Lydia Wang36dd5c42009-10-20 13:18:04 +08003870 else
3871 spec->stream_name_analog = "VT1708S Analog";
Lydia Wangbc92df72011-03-23 17:56:05 +08003872 if (codec->vendor_id == 0x11064397)
3873 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3874 else
3875 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
Harald Welted949cac2008-09-09 15:56:01 +08003876 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3877
Lydia Wang36dd5c42009-10-20 13:18:04 +08003878 if (codec->vendor_id == 0x11060440)
3879 spec->stream_name_digital = "VT1818S Digital";
Lydia Wangbc92df72011-03-23 17:56:05 +08003880 else if (codec->vendor_id == 0x11064397)
3881 spec->stream_name_digital = "VT1705 Digital";
Lydia Wang36dd5c42009-10-20 13:18:04 +08003882 else
3883 spec->stream_name_digital = "VT1708S Digital";
Harald Welted949cac2008-09-09 15:56:01 +08003884 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3885
Takashi Iwaia766d0d2011-06-17 09:01:29 +02003886 if (spec->adc_nids && spec->input_mux) {
Lydia Wang6369bcf2009-10-10 19:08:31 +08003887 override_mic_boost(codec, 0x1a, 0, 3, 40);
3888 override_mic_boost(codec, 0x1e, 0, 3, 40);
Harald Welted949cac2008-09-09 15:56:01 +08003889 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3890 spec->num_mixers++;
3891 }
3892
3893 codec->patch_ops = via_patch_ops;
3894
3895 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003896 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08003897#ifdef CONFIG_SND_HDA_POWER_SAVE
3898 spec->loopback.amplist = vt1708S_loopbacks;
3899#endif
3900
Lydia Wang518bf3b2009-10-10 19:07:29 +08003901 /* correct names for VT1708BCE */
3902 if (get_codec_type(codec) == VT1708BCE) {
3903 kfree(codec->chip_name);
3904 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3905 snprintf(codec->bus->card->mixername,
3906 sizeof(codec->bus->card->mixername),
3907 "%s %s", codec->vendor_name, codec->chip_name);
3908 spec->stream_name_analog = "VT1708BCE Analog";
3909 spec->stream_name_digital = "VT1708BCE Digital";
3910 }
Lydia Wang970f630f2011-03-22 16:25:56 +08003911 /* correct names for VT1818S */
3912 if (codec->vendor_id == 0x11060440) {
3913 spec->stream_name_analog = "VT1818S Analog";
3914 spec->stream_name_digital = "VT1818S Digital";
3915 }
Lydia Wangbc92df72011-03-23 17:56:05 +08003916 /* correct names for VT1705 */
3917 if (codec->vendor_id == 0x11064397) {
3918 kfree(codec->chip_name);
3919 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3920 snprintf(codec->bus->card->mixername,
3921 sizeof(codec->bus->card->mixername),
3922 "%s %s", codec->vendor_name, codec->chip_name);
3923 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08003924 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
Harald Welted949cac2008-09-09 15:56:01 +08003925 return 0;
3926}
3927
3928/* Patch for VT1702 */
3929
3930/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003931static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003932 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3933 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3934 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3935 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3936 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3937 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3938 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3939 HDA_INPUT),
3940 {
3941 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3942 /* The multiple "Capture Source" controls confuse alsamixer
3943 * So call somewhat different..
3944 */
3945 /* .name = "Capture Source", */
3946 .name = "Input Source",
3947 .count = 1,
3948 .info = via_mux_enum_info,
3949 .get = via_mux_enum_get,
3950 .put = via_mux_enum_put,
3951 },
3952 { } /* end */
3953};
3954
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003955static const struct hda_verb vt1702_volume_init_verbs[] = {
Harald Welted949cac2008-09-09 15:56:01 +08003956 /*
3957 * Unmute ADC0-1 and set the default input to mic-in
3958 */
3959 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3960 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3961 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3962
3963
3964 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3965 * mixer widget
3966 */
3967 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3968 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3969 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3970 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3971 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3972 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3973
3974 /* Setup default input of PW4 to MW0 */
3975 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3976 /* PW6 PW7 Output enable */
3977 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3978 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Lydia Wangbc7e7e52009-10-10 19:08:32 +08003979 /* mixer enable */
3980 {0x1, 0xF88, 0x3},
3981 /* GPIO 0~2 */
3982 {0x1, 0xF82, 0x3F},
Harald Welted949cac2008-09-09 15:56:01 +08003983 { }
3984};
3985
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003986static const struct hda_verb vt1702_uniwill_init_verbs[] = {
Lydia Wanga34df192009-10-10 19:08:01 +08003987 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3988 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3989 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3990 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3991 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3992 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
Harald Welte69e52a82008-09-09 15:57:32 +08003993 { }
3994};
3995
Takashi Iwai90dd48a2011-05-02 12:38:19 +02003996static const struct hda_pcm_stream vt1702_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08003997 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08003998 .channels_min = 2,
3999 .channels_max = 2,
4000 .nid = 0x10, /* NID to query formats and rates */
4001 .ops = {
4002 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08004003 .prepare = via_playback_multi_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08004004 .cleanup = via_playback_multi_pcm_cleanup,
4005 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08004006 },
4007};
4008
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004009static const struct hda_pcm_stream vt1702_pcm_analog_capture = {
Harald Welted949cac2008-09-09 15:56:01 +08004010 .substreams = 3,
4011 .channels_min = 2,
4012 .channels_max = 2,
4013 .nid = 0x12, /* NID to query formats and rates */
4014 .ops = {
Lydia Wang17314372009-10-10 19:07:37 +08004015 .open = via_pcm_open_close,
Harald Welted949cac2008-09-09 15:56:01 +08004016 .prepare = via_capture_pcm_prepare,
Lydia Wang17314372009-10-10 19:07:37 +08004017 .cleanup = via_capture_pcm_cleanup,
4018 .close = via_pcm_open_close
Harald Welted949cac2008-09-09 15:56:01 +08004019 },
4020};
4021
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004022static const struct hda_pcm_stream vt1702_pcm_digital_playback = {
Harald Welte5691ec72008-09-15 22:42:26 +08004023 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08004024 .channels_min = 2,
4025 .channels_max = 2,
4026 /* NID is set in via_build_pcms */
4027 .ops = {
4028 .open = via_dig_playback_pcm_open,
4029 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02004030 .prepare = via_dig_playback_pcm_prepare,
4031 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08004032 },
4033};
4034
4035/* fill in the dac_nids table from the parsed pin configuration */
4036static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4037 const struct auto_pin_cfg *cfg)
4038{
4039 spec->multiout.num_dacs = 1;
4040 spec->multiout.dac_nids = spec->private_dac_nids;
4041
4042 if (cfg->line_out_pins[0]) {
4043 /* config dac list */
Takashi Iwaidda14412011-05-02 11:29:30 +02004044 spec->private_dac_nids[0] = 0x10;
Harald Welted949cac2008-09-09 15:56:01 +08004045 }
4046
4047 return 0;
4048}
4049
4050/* add playback controls from the parsed DAC table */
4051static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4052 const struct auto_pin_cfg *cfg)
4053{
4054 int err;
4055
4056 if (!cfg->line_out_pins[0])
4057 return -1;
4058
4059 /* add control to mixer index 0 */
4060 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4061 "Master Front Playback Volume",
4062 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4063 if (err < 0)
4064 return err;
4065 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4066 "Master Front Playback Switch",
4067 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4068 if (err < 0)
4069 return err;
4070
4071 /* Front */
4072 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4073 "Front Playback Volume",
4074 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4075 if (err < 0)
4076 return err;
4077 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4078 "Front Playback Switch",
4079 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4080 if (err < 0)
4081 return err;
4082
4083 return 0;
4084}
4085
4086static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4087{
Lydia Wang0713efe2009-10-10 19:07:43 +08004088 int err, i;
4089 struct hda_input_mux *imux;
Takashi Iwaiea734962011-01-17 11:29:34 +01004090 static const char * const texts[] = { "ON", "OFF", NULL};
Harald Welted949cac2008-09-09 15:56:01 +08004091 if (!pin)
4092 return 0;
Harald Welted949cac2008-09-09 15:56:01 +08004093 spec->multiout.hp_nid = 0x1D;
Lydia Wangcdc17842009-10-10 19:07:47 +08004094 spec->hp_independent_mode_index = 0;
Harald Welted949cac2008-09-09 15:56:01 +08004095
4096 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4097 "Headphone Playback Volume",
4098 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4099 if (err < 0)
4100 return err;
4101
4102 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4103 "Headphone Playback Switch",
4104 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4105 if (err < 0)
4106 return err;
4107
Lydia Wang0713efe2009-10-10 19:07:43 +08004108 imux = &spec->private_imux[1];
Harald Welte0aa62ae2008-09-09 15:58:27 +08004109
Lydia Wang0713efe2009-10-10 19:07:43 +08004110 /* for hp mode select */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004111 for (i = 0; texts[i]; i++)
4112 snd_hda_add_imux_item(imux, texts[i], i, NULL);
Lydia Wang0713efe2009-10-10 19:07:43 +08004113
4114 spec->hp_mux = &spec->private_imux[1];
Harald Welted949cac2008-09-09 15:56:01 +08004115 return 0;
4116}
4117
4118/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004119static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
Harald Welted949cac2008-09-09 15:56:01 +08004120 const struct auto_pin_cfg *cfg)
4121{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004122 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a);
Harald Welted949cac2008-09-09 15:56:01 +08004123}
4124
4125static int vt1702_parse_auto_config(struct hda_codec *codec)
4126{
4127 struct via_spec *spec = codec->spec;
4128 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004129
Takashi Iwai9da29272009-05-07 16:31:14 +02004130 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08004131 if (err < 0)
4132 return err;
4133 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4134 if (err < 0)
4135 return err;
4136 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4137 return 0; /* can't find valid BIOS pin config */
4138
4139 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4140 if (err < 0)
4141 return err;
4142 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4143 if (err < 0)
4144 return err;
Lydia Wangc2c02ea2009-10-10 19:07:32 +08004145 /* limit AA path volume to 0 dB */
4146 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4147 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4148 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4149 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4150 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai10a20af2010-09-09 16:28:02 +02004151 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
Harald Welted949cac2008-09-09 15:56:01 +08004152 if (err < 0)
4153 return err;
4154
4155 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4156
Takashi Iwai9da29272009-05-07 16:31:14 +02004157 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08004158
Takashi Iwai603c4012008-07-30 15:01:44 +02004159 if (spec->kctls.list)
4160 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08004161
Harald Welte0aa62ae2008-09-09 15:58:27 +08004162 spec->input_mux = &spec->private_imux[0];
4163
Harald Weltef8fdd492008-09-15 22:41:31 +08004164 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004165 via_hp_build(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004166
4167 return 1;
4168}
4169
4170#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004171static const struct hda_amp_list vt1702_loopbacks[] = {
Harald Welted949cac2008-09-09 15:56:01 +08004172 { 0x1A, HDA_INPUT, 1 },
4173 { 0x1A, HDA_INPUT, 2 },
4174 { 0x1A, HDA_INPUT, 3 },
4175 { 0x1A, HDA_INPUT, 4 },
4176 { } /* end */
4177};
4178#endif
4179
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004180static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4181{
4182 int imux_is_smixer =
4183 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4184 unsigned int parm;
4185 /* inputs */
4186 /* PW 1/2/5 (14h/15h/18h) */
4187 parm = AC_PWRST_D3;
4188 set_pin_power_state(codec, 0x14, &parm);
4189 set_pin_power_state(codec, 0x15, &parm);
4190 set_pin_power_state(codec, 0x18, &parm);
4191 if (imux_is_smixer)
4192 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4193 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4194 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4195 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4196 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4197 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4198
4199 /* outputs */
4200 /* PW 3/4 (16h/17h) */
4201 parm = AC_PWRST_D3;
4202 set_pin_power_state(codec, 0x17, &parm);
4203 set_pin_power_state(codec, 0x16, &parm);
4204 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4205 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4206 imux_is_smixer ? AC_PWRST_D0 : parm);
4207 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4208 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4209}
4210
Harald Welted949cac2008-09-09 15:56:01 +08004211static int patch_vt1702(struct hda_codec *codec)
4212{
4213 struct via_spec *spec;
4214 int err;
Harald Welted949cac2008-09-09 15:56:01 +08004215
4216 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004217 spec = via_new_spec(codec);
Harald Welted949cac2008-09-09 15:56:01 +08004218 if (spec == NULL)
4219 return -ENOMEM;
4220
Harald Welted949cac2008-09-09 15:56:01 +08004221 /* automatic parse from the BIOS config */
4222 err = vt1702_parse_auto_config(codec);
4223 if (err < 0) {
4224 via_free(codec);
4225 return err;
4226 } else if (!err) {
4227 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4228 "from BIOS. Using genenic mode...\n");
4229 }
4230
Harald Welte69e52a82008-09-09 15:57:32 +08004231 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4232 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08004233
4234 spec->stream_name_analog = "VT1702 Analog";
4235 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4236 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4237
4238 spec->stream_name_digital = "VT1702 Digital";
4239 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4240
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004241 if (spec->adc_nids && spec->input_mux) {
Harald Welted949cac2008-09-09 15:56:01 +08004242 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4243 spec->num_mixers++;
4244 }
4245
4246 codec->patch_ops = via_patch_ops;
4247
4248 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08004249 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08004250#ifdef CONFIG_SND_HDA_POWER_SAVE
4251 spec->loopback.amplist = vt1702_loopbacks;
4252#endif
4253
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004254 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
Harald Welted949cac2008-09-09 15:56:01 +08004255 return 0;
4256}
4257
Lydia Wangeb7188c2009-10-10 19:08:34 +08004258/* Patch for VT1718S */
4259
4260/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004261static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004262 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4263 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4264 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4265 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4266 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4267 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4268 HDA_INPUT),
4269 {
4270 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4271 /* The multiple "Capture Source" controls confuse alsamixer
4272 * So call somewhat different..
4273 */
4274 .name = "Input Source",
4275 .count = 2,
4276 .info = via_mux_enum_info,
4277 .get = via_mux_enum_get,
4278 .put = via_mux_enum_put,
4279 },
4280 { } /* end */
4281};
4282
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004283static const struct hda_verb vt1718S_volume_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004284 /*
4285 * Unmute ADC0-1 and set the default input to mic-in
4286 */
4287 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4288 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4289
Lydia Wang4ab2d532011-03-24 12:42:03 +08004290 /* Enable MW0 adjust Gain 5 */
4291 {0x1, 0xfb2, 0x10},
Lydia Wangeb7188c2009-10-10 19:08:34 +08004292 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4293 * mixer widget
4294 */
4295 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4296 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4297 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4298 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4299 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
Lydia Wang4ab2d532011-03-24 12:42:03 +08004300 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
Lydia Wangeb7188c2009-10-10 19:08:34 +08004301
4302 /* Setup default input of Front HP to MW9 */
4303 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4304 /* PW9 PW10 Output enable */
4305 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4306 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4307 /* PW11 Input enable */
4308 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4309 /* Enable Boost Volume backdoor */
4310 {0x1, 0xf88, 0x8},
4311 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4312 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4313 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4314 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4315 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4316 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4317 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4318 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4319 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4320 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4321 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4322 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4323 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4324 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4325 /* Unmute MW4's index 0 */
4326 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4327 { }
4328};
4329
4330
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004331static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004332 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4333 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4334 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4335 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4336 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4337 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4338 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4339 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4340 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4341 { }
4342};
4343
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004344static const struct hda_pcm_stream vt1718S_pcm_analog_playback = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004345 .substreams = 2,
4346 .channels_min = 2,
4347 .channels_max = 10,
4348 .nid = 0x8, /* NID to query formats and rates */
4349 .ops = {
4350 .open = via_playback_pcm_open,
4351 .prepare = via_playback_multi_pcm_prepare,
4352 .cleanup = via_playback_multi_pcm_cleanup,
4353 .close = via_pcm_open_close,
4354 },
4355};
4356
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004357static const struct hda_pcm_stream vt1718S_pcm_analog_capture = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004358 .substreams = 2,
4359 .channels_min = 2,
4360 .channels_max = 2,
4361 .nid = 0x10, /* NID to query formats and rates */
4362 .ops = {
4363 .open = via_pcm_open_close,
4364 .prepare = via_capture_pcm_prepare,
4365 .cleanup = via_capture_pcm_cleanup,
4366 .close = via_pcm_open_close,
4367 },
4368};
4369
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004370static const struct hda_pcm_stream vt1718S_pcm_digital_playback = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004371 .substreams = 2,
4372 .channels_min = 2,
4373 .channels_max = 2,
Lydia Wangeb7188c2009-10-10 19:08:34 +08004374 /* NID is set in via_build_pcms */
4375 .ops = {
4376 .open = via_dig_playback_pcm_open,
4377 .close = via_dig_playback_pcm_close,
4378 .prepare = via_dig_playback_pcm_prepare,
4379 .cleanup = via_dig_playback_pcm_cleanup
4380 },
4381};
4382
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004383static const struct hda_pcm_stream vt1718S_pcm_digital_capture = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004384 .substreams = 1,
4385 .channels_min = 2,
4386 .channels_max = 2,
4387};
4388
4389/* fill in the dac_nids table from the parsed pin configuration */
4390static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4391 const struct auto_pin_cfg *cfg)
4392{
4393 int i;
4394 hda_nid_t nid;
4395
4396 spec->multiout.num_dacs = cfg->line_outs;
4397
4398 spec->multiout.dac_nids = spec->private_dac_nids;
4399
4400 for (i = 0; i < 4; i++) {
4401 nid = cfg->line_out_pins[i];
4402 if (nid) {
4403 /* config dac list */
4404 switch (i) {
4405 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02004406 spec->private_dac_nids[i] = 0x8;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004407 break;
4408 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004409 spec->private_dac_nids[i] = 0xa;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004410 break;
4411 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02004412 spec->private_dac_nids[i] = 0x9;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004413 break;
4414 case AUTO_SEQ_SIDE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004415 spec->private_dac_nids[i] = 0xb;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004416 break;
4417 }
4418 }
4419 }
4420
4421 return 0;
4422}
4423
4424/* add playback controls from the parsed DAC table */
4425static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4426 const struct auto_pin_cfg *cfg)
4427{
4428 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01004429 static const char * const chname[4] = {
4430 "Front", "Surround", "C/LFE", "Side"
4431 };
Lydia Wangeb7188c2009-10-10 19:08:34 +08004432 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4433 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4434 hda_nid_t nid, nid_vol, nid_mute = 0;
4435 int i, err;
4436
4437 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4438 nid = cfg->line_out_pins[i];
4439
4440 if (!nid)
4441 continue;
4442 nid_vol = nid_vols[i];
4443 nid_mute = nid_mutes[i];
4444
4445 if (i == AUTO_SEQ_CENLFE) {
4446 /* Center/LFE */
4447 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4448 "Center Playback Volume",
4449 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4450 HDA_OUTPUT));
4451 if (err < 0)
4452 return err;
4453 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4454 "LFE Playback Volume",
4455 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4456 HDA_OUTPUT));
4457 if (err < 0)
4458 return err;
4459 err = via_add_control(
4460 spec, VIA_CTL_WIDGET_MUTE,
4461 "Center Playback Switch",
4462 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4463 HDA_OUTPUT));
4464 if (err < 0)
4465 return err;
4466 err = via_add_control(
4467 spec, VIA_CTL_WIDGET_MUTE,
4468 "LFE Playback Switch",
4469 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4470 HDA_OUTPUT));
4471 if (err < 0)
4472 return err;
4473 } else if (i == AUTO_SEQ_FRONT) {
4474 /* Front */
4475 sprintf(name, "%s Playback Volume", chname[i]);
4476 err = via_add_control(
4477 spec, VIA_CTL_WIDGET_VOL, name,
4478 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4479 if (err < 0)
4480 return err;
4481 sprintf(name, "%s Playback Switch", chname[i]);
4482 err = via_add_control(
4483 spec, VIA_CTL_WIDGET_MUTE, name,
4484 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4485 HDA_OUTPUT));
4486 if (err < 0)
4487 return err;
4488 } else {
4489 sprintf(name, "%s Playback Volume", chname[i]);
4490 err = via_add_control(
4491 spec, VIA_CTL_WIDGET_VOL, name,
4492 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4493 if (err < 0)
4494 return err;
4495 sprintf(name, "%s Playback Switch", chname[i]);
4496 err = via_add_control(
4497 spec, VIA_CTL_WIDGET_MUTE, name,
4498 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4499 HDA_OUTPUT));
4500 if (err < 0)
4501 return err;
4502 }
4503 }
4504 return 0;
4505}
4506
4507static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4508{
4509 int err;
4510
4511 if (!pin)
4512 return 0;
4513
4514 spec->multiout.hp_nid = 0xc; /* AOW4 */
4515 spec->hp_independent_mode_index = 1;
4516
4517 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4518 "Headphone Playback Volume",
4519 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4520 if (err < 0)
4521 return err;
4522
4523 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4524 "Headphone Playback Switch",
4525 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4526 if (err < 0)
4527 return err;
4528
4529 create_hp_imux(spec);
4530 return 0;
4531}
4532
4533/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02004534static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangeb7188c2009-10-10 19:08:34 +08004535 const struct auto_pin_cfg *cfg)
4536{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004537 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004538}
4539
4540static int vt1718S_parse_auto_config(struct hda_codec *codec)
4541{
4542 struct via_spec *spec = codec->spec;
4543 int err;
4544
4545 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4546
4547 if (err < 0)
4548 return err;
4549 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4550 if (err < 0)
4551 return err;
4552 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4553 return 0; /* can't find valid BIOS pin config */
4554
4555 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4556 if (err < 0)
4557 return err;
4558 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4559 if (err < 0)
4560 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02004561 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004562 if (err < 0)
4563 return err;
4564
4565 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4566
4567 fill_dig_outs(codec);
4568
4569 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4570 spec->dig_in_nid = 0x13;
4571
4572 if (spec->kctls.list)
4573 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4574
4575 spec->input_mux = &spec->private_imux[0];
4576
4577 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02004578 via_hp_build(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004579
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004580 via_smart51_build(spec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004581
4582 return 1;
4583}
4584
4585#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004586static const struct hda_amp_list vt1718S_loopbacks[] = {
Lydia Wangeb7188c2009-10-10 19:08:34 +08004587 { 0x21, HDA_INPUT, 1 },
4588 { 0x21, HDA_INPUT, 2 },
4589 { 0x21, HDA_INPUT, 3 },
4590 { 0x21, HDA_INPUT, 4 },
4591 { } /* end */
4592};
4593#endif
4594
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004595static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4596{
4597 struct via_spec *spec = codec->spec;
4598 int imux_is_smixer;
4599 unsigned int parm;
4600 /* MUX6 (1eh) = stereo mixer */
4601 imux_is_smixer =
4602 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4603 /* inputs */
4604 /* PW 5/6/7 (29h/2ah/2bh) */
4605 parm = AC_PWRST_D3;
4606 set_pin_power_state(codec, 0x29, &parm);
4607 set_pin_power_state(codec, 0x2a, &parm);
4608 set_pin_power_state(codec, 0x2b, &parm);
4609 if (imux_is_smixer)
4610 parm = AC_PWRST_D0;
4611 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4612 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4613 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4614 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4615 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4616
4617 /* outputs */
4618 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4619 parm = AC_PWRST_D3;
4620 set_pin_power_state(codec, 0x27, &parm);
4621 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4622 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4623
4624 /* PW2 (26h), AOW2 (ah) */
4625 parm = AC_PWRST_D3;
4626 set_pin_power_state(codec, 0x26, &parm);
4627 if (spec->smart51_enabled)
4628 set_pin_power_state(codec, 0x2b, &parm);
4629 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4630
4631 /* PW0 (24h), AOW0 (8h) */
4632 parm = AC_PWRST_D3;
4633 set_pin_power_state(codec, 0x24, &parm);
4634 if (!spec->hp_independent_mode) /* check for redirected HP */
4635 set_pin_power_state(codec, 0x28, &parm);
4636 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4637 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4638 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4639 imux_is_smixer ? AC_PWRST_D0 : parm);
4640
4641 /* PW1 (25h), AOW1 (9h) */
4642 parm = AC_PWRST_D3;
4643 set_pin_power_state(codec, 0x25, &parm);
4644 if (spec->smart51_enabled)
4645 set_pin_power_state(codec, 0x2a, &parm);
4646 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4647
4648 if (spec->hp_independent_mode) {
4649 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4650 parm = AC_PWRST_D3;
4651 set_pin_power_state(codec, 0x28, &parm);
4652 snd_hda_codec_write(codec, 0x1b, 0,
4653 AC_VERB_SET_POWER_STATE, parm);
4654 snd_hda_codec_write(codec, 0x34, 0,
4655 AC_VERB_SET_POWER_STATE, parm);
4656 snd_hda_codec_write(codec, 0xc, 0,
4657 AC_VERB_SET_POWER_STATE, parm);
4658 }
4659}
4660
Lydia Wangeb7188c2009-10-10 19:08:34 +08004661static int patch_vt1718S(struct hda_codec *codec)
4662{
4663 struct via_spec *spec;
4664 int err;
4665
4666 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004667 spec = via_new_spec(codec);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004668 if (spec == NULL)
4669 return -ENOMEM;
4670
Lydia Wangeb7188c2009-10-10 19:08:34 +08004671 /* automatic parse from the BIOS config */
4672 err = vt1718S_parse_auto_config(codec);
4673 if (err < 0) {
4674 via_free(codec);
4675 return err;
4676 } else if (!err) {
4677 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4678 "from BIOS. Using genenic mode...\n");
4679 }
4680
4681 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4682 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4683
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004684 if (codec->vendor_id == 0x11060441)
4685 spec->stream_name_analog = "VT2020 Analog";
4686 else if (codec->vendor_id == 0x11064441)
4687 spec->stream_name_analog = "VT1828S Analog";
4688 else
4689 spec->stream_name_analog = "VT1718S Analog";
Lydia Wangeb7188c2009-10-10 19:08:34 +08004690 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4691 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4692
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004693 if (codec->vendor_id == 0x11060441)
4694 spec->stream_name_digital = "VT2020 Digital";
4695 else if (codec->vendor_id == 0x11064441)
4696 spec->stream_name_digital = "VT1828S Digital";
4697 else
4698 spec->stream_name_digital = "VT1718S Digital";
Lydia Wangeb7188c2009-10-10 19:08:34 +08004699 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004700 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
Lydia Wangeb7188c2009-10-10 19:08:34 +08004701 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4702
Takashi Iwaia766d0d2011-06-17 09:01:29 +02004703 if (spec->adc_nids && spec->input_mux) {
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08004704 override_mic_boost(codec, 0x2b, 0, 3, 40);
4705 override_mic_boost(codec, 0x29, 0, 3, 40);
Lydia Wangeb7188c2009-10-10 19:08:34 +08004706 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4707 spec->num_mixers++;
4708 }
4709
4710 codec->patch_ops = via_patch_ops;
4711
4712 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11004713 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangeb7188c2009-10-10 19:08:34 +08004714
4715#ifdef CONFIG_SND_HDA_POWER_SAVE
4716 spec->loopback.amplist = vt1718S_loopbacks;
4717#endif
4718
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004719 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4720
Lydia Wangeb7188c2009-10-10 19:08:34 +08004721 return 0;
4722}
Lydia Wangf3db4232009-10-10 19:08:41 +08004723
4724/* Patch for VT1716S */
4725
4726static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4727 struct snd_ctl_elem_info *uinfo)
4728{
4729 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4730 uinfo->count = 1;
4731 uinfo->value.integer.min = 0;
4732 uinfo->value.integer.max = 1;
4733 return 0;
4734}
4735
4736static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4737 struct snd_ctl_elem_value *ucontrol)
4738{
4739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4740 int index = 0;
4741
4742 index = snd_hda_codec_read(codec, 0x26, 0,
4743 AC_VERB_GET_CONNECT_SEL, 0);
4744 if (index != -1)
4745 *ucontrol->value.integer.value = index;
4746
4747 return 0;
4748}
4749
4750static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4751 struct snd_ctl_elem_value *ucontrol)
4752{
4753 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4754 struct via_spec *spec = codec->spec;
4755 int index = *ucontrol->value.integer.value;
4756
4757 snd_hda_codec_write(codec, 0x26, 0,
4758 AC_VERB_SET_CONNECT_SEL, index);
4759 spec->dmic_enabled = index;
Lydia Wang3e95b9a2011-03-23 15:13:28 +08004760 set_widgets_power_state(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08004761 return 1;
4762}
4763
4764/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004765static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004766 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4767 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4768 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4769 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4770 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4771 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4772 HDA_INPUT),
4773 {
4774 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4775 .name = "Input Source",
4776 .count = 1,
4777 .info = via_mux_enum_info,
4778 .get = via_mux_enum_get,
4779 .put = via_mux_enum_put,
4780 },
4781 { } /* end */
4782};
4783
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004784static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004785 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4786 {
4787 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4788 .name = "Digital Mic Capture Switch",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01004789 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
Lydia Wangf3db4232009-10-10 19:08:41 +08004790 .count = 1,
4791 .info = vt1716s_dmic_info,
4792 .get = vt1716s_dmic_get,
4793 .put = vt1716s_dmic_put,
4794 },
4795 {} /* end */
4796};
4797
4798
4799/* mono-out mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004800static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004801 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4802 { } /* end */
4803};
4804
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004805static const struct hda_verb vt1716S_volume_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004806 /*
4807 * Unmute ADC0-1 and set the default input to mic-in
4808 */
4809 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4810 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4811
4812
4813 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4814 * mixer widget
4815 */
4816 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4817 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4818 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4819 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4820 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4821 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4822
4823 /* MUX Indices: Stereo Mixer = 5 */
4824 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4825
4826 /* Setup default input of PW4 to MW0 */
4827 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4828
4829 /* Setup default input of SW1 as MW0 */
4830 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4831
4832 /* Setup default input of SW4 as AOW0 */
4833 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4834
4835 /* PW9 PW10 Output enable */
4836 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4837 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4838
4839 /* Unmute SW1, PW12 */
4840 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4841 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4842 /* PW12 Output enable */
4843 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4844 /* Enable Boost Volume backdoor */
4845 {0x1, 0xf8a, 0x80},
4846 /* don't bybass mixer */
4847 {0x1, 0xf88, 0xc0},
4848 /* Enable mono output */
4849 {0x1, 0xf90, 0x08},
4850 { }
4851};
4852
4853
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004854static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004855 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4856 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4857 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4858 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4859 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4860 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4861 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4862 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4863 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4864 { }
4865};
4866
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004867static const struct hda_pcm_stream vt1716S_pcm_analog_playback = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004868 .substreams = 2,
4869 .channels_min = 2,
4870 .channels_max = 6,
4871 .nid = 0x10, /* NID to query formats and rates */
4872 .ops = {
4873 .open = via_playback_pcm_open,
4874 .prepare = via_playback_multi_pcm_prepare,
4875 .cleanup = via_playback_multi_pcm_cleanup,
4876 .close = via_pcm_open_close,
4877 },
4878};
4879
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004880static const struct hda_pcm_stream vt1716S_pcm_analog_capture = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004881 .substreams = 2,
4882 .channels_min = 2,
4883 .channels_max = 2,
4884 .nid = 0x13, /* NID to query formats and rates */
4885 .ops = {
4886 .open = via_pcm_open_close,
4887 .prepare = via_capture_pcm_prepare,
4888 .cleanup = via_capture_pcm_cleanup,
4889 .close = via_pcm_open_close,
4890 },
4891};
4892
Takashi Iwai90dd48a2011-05-02 12:38:19 +02004893static const struct hda_pcm_stream vt1716S_pcm_digital_playback = {
Lydia Wangf3db4232009-10-10 19:08:41 +08004894 .substreams = 2,
4895 .channels_min = 2,
4896 .channels_max = 2,
Lydia Wangf3db4232009-10-10 19:08:41 +08004897 /* NID is set in via_build_pcms */
4898 .ops = {
4899 .open = via_dig_playback_pcm_open,
4900 .close = via_dig_playback_pcm_close,
4901 .prepare = via_dig_playback_pcm_prepare,
4902 .cleanup = via_dig_playback_pcm_cleanup
4903 },
4904};
4905
4906/* fill in the dac_nids table from the parsed pin configuration */
4907static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4908 const struct auto_pin_cfg *cfg)
4909{ int i;
4910 hda_nid_t nid;
4911
4912 spec->multiout.num_dacs = cfg->line_outs;
4913
4914 spec->multiout.dac_nids = spec->private_dac_nids;
4915
4916 for (i = 0; i < 3; i++) {
4917 nid = cfg->line_out_pins[i];
4918 if (nid) {
4919 /* config dac list */
4920 switch (i) {
4921 case AUTO_SEQ_FRONT:
Takashi Iwaidda14412011-05-02 11:29:30 +02004922 spec->private_dac_nids[i] = 0x10;
Lydia Wangf3db4232009-10-10 19:08:41 +08004923 break;
4924 case AUTO_SEQ_CENLFE:
Takashi Iwaidda14412011-05-02 11:29:30 +02004925 spec->private_dac_nids[i] = 0x25;
Lydia Wangf3db4232009-10-10 19:08:41 +08004926 break;
4927 case AUTO_SEQ_SURROUND:
Takashi Iwaidda14412011-05-02 11:29:30 +02004928 spec->private_dac_nids[i] = 0x11;
Lydia Wangf3db4232009-10-10 19:08:41 +08004929 break;
4930 }
4931 }
4932 }
4933
4934 return 0;
4935}
4936
4937/* add playback controls from the parsed DAC table */
4938static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4939 const struct auto_pin_cfg *cfg)
4940{
4941 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01004942 static const char * const chname[3] = {
4943 "Front", "Surround", "C/LFE"
4944 };
Lydia Wangf3db4232009-10-10 19:08:41 +08004945 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4946 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4947 hda_nid_t nid, nid_vol, nid_mute;
4948 int i, err;
4949
4950 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4951 nid = cfg->line_out_pins[i];
4952
4953 if (!nid)
4954 continue;
4955
4956 nid_vol = nid_vols[i];
4957 nid_mute = nid_mutes[i];
4958
4959 if (i == AUTO_SEQ_CENLFE) {
4960 err = via_add_control(
4961 spec, VIA_CTL_WIDGET_VOL,
4962 "Center Playback Volume",
4963 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
4964 if (err < 0)
4965 return err;
4966 err = via_add_control(
4967 spec, VIA_CTL_WIDGET_VOL,
4968 "LFE Playback Volume",
4969 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
4970 if (err < 0)
4971 return err;
4972 err = via_add_control(
4973 spec, VIA_CTL_WIDGET_MUTE,
4974 "Center Playback Switch",
4975 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4976 HDA_OUTPUT));
4977 if (err < 0)
4978 return err;
4979 err = via_add_control(
4980 spec, VIA_CTL_WIDGET_MUTE,
4981 "LFE Playback Switch",
4982 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4983 HDA_OUTPUT));
4984 if (err < 0)
4985 return err;
4986 } else if (i == AUTO_SEQ_FRONT) {
4987
4988 err = via_add_control(
4989 spec, VIA_CTL_WIDGET_VOL,
4990 "Master Front Playback Volume",
4991 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4992 if (err < 0)
4993 return err;
4994 err = via_add_control(
4995 spec, VIA_CTL_WIDGET_MUTE,
4996 "Master Front Playback Switch",
4997 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4998 if (err < 0)
4999 return err;
5000
5001 sprintf(name, "%s Playback Volume", chname[i]);
5002 err = via_add_control(
5003 spec, VIA_CTL_WIDGET_VOL, name,
5004 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5005 if (err < 0)
5006 return err;
5007 sprintf(name, "%s Playback Switch", chname[i]);
5008 err = via_add_control(
5009 spec, VIA_CTL_WIDGET_MUTE, name,
5010 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5011 HDA_OUTPUT));
5012 if (err < 0)
5013 return err;
5014 } else {
5015 sprintf(name, "%s Playback Volume", chname[i]);
5016 err = via_add_control(
5017 spec, VIA_CTL_WIDGET_VOL, name,
5018 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5019 if (err < 0)
5020 return err;
5021 sprintf(name, "%s Playback Switch", chname[i]);
5022 err = via_add_control(
5023 spec, VIA_CTL_WIDGET_MUTE, name,
5024 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5025 HDA_OUTPUT));
5026 if (err < 0)
5027 return err;
5028 }
5029 }
5030 return 0;
5031}
5032
5033static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5034{
5035 int err;
5036
5037 if (!pin)
5038 return 0;
5039
5040 spec->multiout.hp_nid = 0x25; /* AOW3 */
5041 spec->hp_independent_mode_index = 1;
5042
5043 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5044 "Headphone Playback Volume",
5045 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5046 if (err < 0)
5047 return err;
5048
5049 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5050 "Headphone Playback Switch",
5051 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5052 if (err < 0)
5053 return err;
5054
5055 create_hp_imux(spec);
5056 return 0;
5057}
5058
5059/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005060static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangf3db4232009-10-10 19:08:41 +08005061 const struct auto_pin_cfg *cfg)
5062{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005063 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
Lydia Wangf3db4232009-10-10 19:08:41 +08005064}
5065
5066static int vt1716S_parse_auto_config(struct hda_codec *codec)
5067{
5068 struct via_spec *spec = codec->spec;
5069 int err;
5070
5071 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5072 if (err < 0)
5073 return err;
5074 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5075 if (err < 0)
5076 return err;
5077 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5078 return 0; /* can't find valid BIOS pin config */
5079
5080 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5081 if (err < 0)
5082 return err;
5083 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5084 if (err < 0)
5085 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005086 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangf3db4232009-10-10 19:08:41 +08005087 if (err < 0)
5088 return err;
5089
5090 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5091
5092 fill_dig_outs(codec);
5093
5094 if (spec->kctls.list)
5095 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5096
5097 spec->input_mux = &spec->private_imux[0];
5098
5099 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005100 via_hp_build(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005101
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005102 via_smart51_build(spec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005103
5104 return 1;
5105}
5106
5107#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005108static const struct hda_amp_list vt1716S_loopbacks[] = {
Lydia Wangf3db4232009-10-10 19:08:41 +08005109 { 0x16, HDA_INPUT, 1 },
5110 { 0x16, HDA_INPUT, 2 },
5111 { 0x16, HDA_INPUT, 3 },
5112 { 0x16, HDA_INPUT, 4 },
5113 { } /* end */
5114};
5115#endif
5116
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005117static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5118{
5119 struct via_spec *spec = codec->spec;
5120 int imux_is_smixer;
5121 unsigned int parm;
5122 unsigned int mono_out, present;
5123 /* SW0 (17h) = stereo mixer */
5124 imux_is_smixer =
5125 (snd_hda_codec_read(codec, 0x17, 0,
5126 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5127 /* inputs */
5128 /* PW 1/2/5 (1ah/1bh/1eh) */
5129 parm = AC_PWRST_D3;
5130 set_pin_power_state(codec, 0x1a, &parm);
5131 set_pin_power_state(codec, 0x1b, &parm);
5132 set_pin_power_state(codec, 0x1e, &parm);
5133 if (imux_is_smixer)
5134 parm = AC_PWRST_D0;
5135 /* SW0 (17h), AIW0(13h) */
5136 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5137 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5138
5139 parm = AC_PWRST_D3;
5140 set_pin_power_state(codec, 0x1e, &parm);
5141 /* PW11 (22h) */
5142 if (spec->dmic_enabled)
5143 set_pin_power_state(codec, 0x22, &parm);
5144 else
5145 snd_hda_codec_write(codec, 0x22, 0,
5146 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5147
5148 /* SW2(26h), AIW1(14h) */
5149 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5150 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5151
5152 /* outputs */
5153 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5154 parm = AC_PWRST_D3;
5155 set_pin_power_state(codec, 0x19, &parm);
5156 /* Smart 5.1 PW2(1bh) */
5157 if (spec->smart51_enabled)
5158 set_pin_power_state(codec, 0x1b, &parm);
5159 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5160 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5161
5162 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5163 parm = AC_PWRST_D3;
5164 set_pin_power_state(codec, 0x23, &parm);
5165 /* Smart 5.1 PW1(1ah) */
5166 if (spec->smart51_enabled)
5167 set_pin_power_state(codec, 0x1a, &parm);
5168 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5169
5170 /* Smart 5.1 PW5(1eh) */
5171 if (spec->smart51_enabled)
5172 set_pin_power_state(codec, 0x1e, &parm);
5173 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5174
5175 /* Mono out */
5176 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5177 present = snd_hda_jack_detect(codec, 0x1c);
5178
5179 if (present)
5180 mono_out = 0;
5181 else {
5182 present = snd_hda_jack_detect(codec, 0x1d);
5183 if (!spec->hp_independent_mode && present)
5184 mono_out = 0;
5185 else
5186 mono_out = 1;
5187 }
5188 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5189 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5190 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5191 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5192
5193 /* PW 3/4 (1ch/1dh) */
5194 parm = AC_PWRST_D3;
5195 set_pin_power_state(codec, 0x1c, &parm);
5196 set_pin_power_state(codec, 0x1d, &parm);
5197 /* HP Independent Mode, power on AOW3 */
5198 if (spec->hp_independent_mode)
5199 snd_hda_codec_write(codec, 0x25, 0,
5200 AC_VERB_SET_POWER_STATE, parm);
5201
5202 /* force to D0 for internal Speaker */
5203 /* MW0 (16h), AOW0 (10h) */
5204 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5205 imux_is_smixer ? AC_PWRST_D0 : parm);
5206 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5207 mono_out ? AC_PWRST_D0 : parm);
5208}
5209
Lydia Wangf3db4232009-10-10 19:08:41 +08005210static int patch_vt1716S(struct hda_codec *codec)
5211{
5212 struct via_spec *spec;
5213 int err;
5214
5215 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005216 spec = via_new_spec(codec);
Lydia Wangf3db4232009-10-10 19:08:41 +08005217 if (spec == NULL)
5218 return -ENOMEM;
5219
Lydia Wangf3db4232009-10-10 19:08:41 +08005220 /* automatic parse from the BIOS config */
5221 err = vt1716S_parse_auto_config(codec);
5222 if (err < 0) {
5223 via_free(codec);
5224 return err;
5225 } else if (!err) {
5226 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5227 "from BIOS. Using genenic mode...\n");
5228 }
5229
5230 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5231 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5232
5233 spec->stream_name_analog = "VT1716S Analog";
5234 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5235 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5236
5237 spec->stream_name_digital = "VT1716S Digital";
5238 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5239
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005240 if (spec->adc_nids && spec->input_mux) {
Lydia Wangf3db4232009-10-10 19:08:41 +08005241 override_mic_boost(codec, 0x1a, 0, 3, 40);
5242 override_mic_boost(codec, 0x1e, 0, 3, 40);
5243 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5244 spec->num_mixers++;
5245 }
5246
5247 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5248 spec->num_mixers++;
5249
5250 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5251
5252 codec->patch_ops = via_patch_ops;
5253
5254 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005255 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangf3db4232009-10-10 19:08:41 +08005256
5257#ifdef CONFIG_SND_HDA_POWER_SAVE
5258 spec->loopback.amplist = vt1716S_loopbacks;
5259#endif
5260
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005261 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
Lydia Wangf3db4232009-10-10 19:08:41 +08005262 return 0;
5263}
Lydia Wang25eaba22009-10-10 19:08:43 +08005264
5265/* for vt2002P */
5266
5267/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005268static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005269 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5270 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5271 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5272 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5273 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5274 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5275 HDA_INPUT),
5276 {
5277 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5278 /* The multiple "Capture Source" controls confuse alsamixer
5279 * So call somewhat different..
5280 */
5281 /* .name = "Capture Source", */
5282 .name = "Input Source",
5283 .count = 2,
5284 .info = via_mux_enum_info,
5285 .get = via_mux_enum_get,
5286 .put = via_mux_enum_put,
5287 },
5288 { } /* end */
5289};
5290
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005291static const struct hda_verb vt2002P_volume_init_verbs[] = {
Lydia Wangeadb9a82011-03-24 12:43:02 +08005292 /* Class-D speaker related verbs */
5293 {0x1, 0xfe0, 0x4},
5294 {0x1, 0xfe9, 0x80},
5295 {0x1, 0xfe2, 0x22},
Lydia Wang25eaba22009-10-10 19:08:43 +08005296 /*
5297 * Unmute ADC0-1 and set the default input to mic-in
5298 */
5299 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5300 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5301
5302
5303 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5304 * mixer widget
5305 */
5306 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5307 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5308 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5309 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5310 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5311 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5312
5313 /* MUX Indices: Mic = 0 */
5314 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5315 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5316
5317 /* PW9 Output enable */
5318 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5319
5320 /* Enable Boost Volume backdoor */
5321 {0x1, 0xfb9, 0x24},
5322
5323 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5324 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5325 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5326 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5327 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5328 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5329 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5330 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5331 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5332
5333 /* set MUX0/1/4/8 = 0 (AOW0) */
5334 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5335 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5336 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5337 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5338
5339 /* set PW0 index=0 (MW0) */
5340 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5341
5342 /* Enable AOW0 to MW9 */
5343 {0x1, 0xfb8, 0x88},
5344 { }
5345};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005346static const struct hda_verb vt1802_volume_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08005347 /*
5348 * Unmute ADC0-1 and set the default input to mic-in
5349 */
5350 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5351 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5352
5353
5354 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5355 * mixer widget
5356 */
5357 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5358 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5359 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5360 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5361 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5362 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5363
5364 /* MUX Indices: Mic = 0 */
5365 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5366 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5367
5368 /* PW9 Output enable */
5369 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5370
5371 /* Enable Boost Volume backdoor */
5372 {0x1, 0xfb9, 0x24},
5373
5374 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5375 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5376 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5377 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5378 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5379 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5380 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5381 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5382 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5383
5384 /* set MUX0/1/4/8 = 0 (AOW0) */
5385 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5386 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5387 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5388 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5389
5390 /* set PW0 index=0 (MW0) */
5391 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5392
5393 /* Enable AOW0 to MW9 */
5394 {0x1, 0xfb8, 0x88},
5395 { }
5396};
Lydia Wang25eaba22009-10-10 19:08:43 +08005397
5398
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005399static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005400 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5401 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5402 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5403 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5404 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5405 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5406 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5407 { }
5408};
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005409static const struct hda_verb vt1802_uniwill_init_verbs[] = {
Lydia Wang118909562011-03-23 17:57:34 +08005410 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5411 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5412 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5413 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5414 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5415 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5416 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5417 { }
5418};
Lydia Wang25eaba22009-10-10 19:08:43 +08005419
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005420static const struct hda_pcm_stream vt2002P_pcm_analog_playback = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005421 .substreams = 2,
5422 .channels_min = 2,
5423 .channels_max = 2,
5424 .nid = 0x8, /* NID to query formats and rates */
5425 .ops = {
5426 .open = via_playback_pcm_open,
5427 .prepare = via_playback_multi_pcm_prepare,
5428 .cleanup = via_playback_multi_pcm_cleanup,
5429 .close = via_pcm_open_close,
5430 },
5431};
5432
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005433static const struct hda_pcm_stream vt2002P_pcm_analog_capture = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005434 .substreams = 2,
5435 .channels_min = 2,
5436 .channels_max = 2,
5437 .nid = 0x10, /* NID to query formats and rates */
5438 .ops = {
5439 .open = via_pcm_open_close,
5440 .prepare = via_capture_pcm_prepare,
5441 .cleanup = via_capture_pcm_cleanup,
5442 .close = via_pcm_open_close,
5443 },
5444};
5445
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005446static const struct hda_pcm_stream vt2002P_pcm_digital_playback = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005447 .substreams = 1,
5448 .channels_min = 2,
5449 .channels_max = 2,
Lydia Wang25eaba22009-10-10 19:08:43 +08005450 /* NID is set in via_build_pcms */
5451 .ops = {
5452 .open = via_dig_playback_pcm_open,
5453 .close = via_dig_playback_pcm_close,
5454 .prepare = via_dig_playback_pcm_prepare,
5455 .cleanup = via_dig_playback_pcm_cleanup
5456 },
5457};
5458
5459/* fill in the dac_nids table from the parsed pin configuration */
5460static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5461 const struct auto_pin_cfg *cfg)
5462{
5463 spec->multiout.num_dacs = 1;
5464 spec->multiout.dac_nids = spec->private_dac_nids;
5465 if (cfg->line_out_pins[0])
Takashi Iwaidda14412011-05-02 11:29:30 +02005466 spec->private_dac_nids[0] = 0x8;
Lydia Wang25eaba22009-10-10 19:08:43 +08005467 return 0;
5468}
5469
5470/* add playback controls from the parsed DAC table */
5471static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5472 const struct auto_pin_cfg *cfg)
5473{
5474 int err;
Lydia Wang118909562011-03-23 17:57:34 +08005475 hda_nid_t sw_nid;
Lydia Wang25eaba22009-10-10 19:08:43 +08005476
5477 if (!cfg->line_out_pins[0])
5478 return -1;
5479
Lydia Wang118909562011-03-23 17:57:34 +08005480 if (spec->codec_type == VT1802)
5481 sw_nid = 0x28;
5482 else
5483 sw_nid = 0x26;
Lydia Wang25eaba22009-10-10 19:08:43 +08005484
5485 /* Line-Out: PortE */
5486 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5487 "Master Front Playback Volume",
5488 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5489 if (err < 0)
5490 return err;
5491 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5492 "Master Front Playback Switch",
Lydia Wang118909562011-03-23 17:57:34 +08005493 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
Lydia Wang25eaba22009-10-10 19:08:43 +08005494 if (err < 0)
5495 return err;
5496
5497 return 0;
5498}
5499
5500static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5501{
5502 int err;
5503
5504 if (!pin)
5505 return 0;
5506
5507 spec->multiout.hp_nid = 0x9;
5508 spec->hp_independent_mode_index = 1;
5509
5510 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5511 "Headphone Playback Volume",
5512 HDA_COMPOSE_AMP_VAL(
5513 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5514 if (err < 0)
5515 return err;
5516
5517 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5518 "Headphone Playback Switch",
5519 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5520 if (err < 0)
5521 return err;
5522
5523 create_hp_imux(spec);
5524 return 0;
5525}
5526
5527/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005528static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wang25eaba22009-10-10 19:08:43 +08005529 const struct auto_pin_cfg *cfg)
5530{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005531 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
Lydia Wang25eaba22009-10-10 19:08:43 +08005532}
5533
5534static int vt2002P_parse_auto_config(struct hda_codec *codec)
5535{
5536 struct via_spec *spec = codec->spec;
5537 int err;
5538
5539
5540 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5541 if (err < 0)
5542 return err;
5543
5544 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5545 if (err < 0)
5546 return err;
5547
5548 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5549 return 0; /* can't find valid BIOS pin config */
5550
5551 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5552 if (err < 0)
5553 return err;
5554 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5555 if (err < 0)
5556 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005557 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wang25eaba22009-10-10 19:08:43 +08005558 if (err < 0)
5559 return err;
5560
5561 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5562
5563 fill_dig_outs(codec);
5564
5565 if (spec->kctls.list)
5566 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5567
5568 spec->input_mux = &spec->private_imux[0];
5569
5570 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02005571 via_hp_build(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08005572
5573 return 1;
5574}
5575
5576#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005577static const struct hda_amp_list vt2002P_loopbacks[] = {
Lydia Wang25eaba22009-10-10 19:08:43 +08005578 { 0x21, HDA_INPUT, 0 },
5579 { 0x21, HDA_INPUT, 1 },
5580 { 0x21, HDA_INPUT, 2 },
5581 { } /* end */
5582};
5583#endif
5584
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005585static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5586{
5587 struct via_spec *spec = codec->spec;
5588 int imux_is_smixer;
5589 unsigned int parm;
5590 unsigned int present;
5591 /* MUX9 (1eh) = stereo mixer */
5592 imux_is_smixer =
5593 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5594 /* inputs */
5595 /* PW 5/6/7 (29h/2ah/2bh) */
5596 parm = AC_PWRST_D3;
5597 set_pin_power_state(codec, 0x29, &parm);
5598 set_pin_power_state(codec, 0x2a, &parm);
5599 set_pin_power_state(codec, 0x2b, &parm);
5600 parm = AC_PWRST_D0;
5601 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5602 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5603 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5604 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5605 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5606
5607 /* outputs */
5608 /* AOW0 (8h)*/
5609 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5610
Lydia Wang118909562011-03-23 17:57:34 +08005611 if (spec->codec_type == VT1802) {
5612 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5613 parm = AC_PWRST_D3;
5614 set_pin_power_state(codec, 0x28, &parm);
5615 snd_hda_codec_write(codec, 0x18, 0,
5616 AC_VERB_SET_POWER_STATE, parm);
5617 snd_hda_codec_write(codec, 0x38, 0,
5618 AC_VERB_SET_POWER_STATE, parm);
5619 } else {
5620 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5621 parm = AC_PWRST_D3;
5622 set_pin_power_state(codec, 0x26, &parm);
5623 snd_hda_codec_write(codec, 0x1c, 0,
5624 AC_VERB_SET_POWER_STATE, parm);
5625 snd_hda_codec_write(codec, 0x37, 0,
5626 AC_VERB_SET_POWER_STATE, parm);
5627 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005628
Lydia Wang118909562011-03-23 17:57:34 +08005629 if (spec->codec_type == VT1802) {
5630 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5631 parm = AC_PWRST_D3;
5632 set_pin_power_state(codec, 0x25, &parm);
5633 snd_hda_codec_write(codec, 0x15, 0,
5634 AC_VERB_SET_POWER_STATE, parm);
5635 snd_hda_codec_write(codec, 0x35, 0,
5636 AC_VERB_SET_POWER_STATE, parm);
5637 } else {
5638 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5639 parm = AC_PWRST_D3;
5640 set_pin_power_state(codec, 0x25, &parm);
5641 snd_hda_codec_write(codec, 0x19, 0,
5642 AC_VERB_SET_POWER_STATE, parm);
5643 snd_hda_codec_write(codec, 0x35, 0,
5644 AC_VERB_SET_POWER_STATE, parm);
5645 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005646
5647 if (spec->hp_independent_mode)
5648 snd_hda_codec_write(codec, 0x9, 0,
5649 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5650
5651 /* Class-D */
5652 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5653 present = snd_hda_jack_detect(codec, 0x25);
5654
5655 parm = AC_PWRST_D3;
5656 set_pin_power_state(codec, 0x24, &parm);
5657 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08005658 if (spec->codec_type == VT1802)
5659 snd_hda_codec_write(codec, 0x14, 0,
5660 AC_VERB_SET_POWER_STATE, parm);
5661 else
5662 snd_hda_codec_write(codec, 0x18, 0,
5663 AC_VERB_SET_POWER_STATE, parm);
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005664 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5665
5666 /* Mono Out */
5667 present = snd_hda_jack_detect(codec, 0x26);
5668
5669 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
Lydia Wang118909562011-03-23 17:57:34 +08005670 if (spec->codec_type == VT1802) {
5671 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5672 snd_hda_codec_write(codec, 0x33, 0,
5673 AC_VERB_SET_POWER_STATE, parm);
5674 snd_hda_codec_write(codec, 0x1c, 0,
5675 AC_VERB_SET_POWER_STATE, parm);
5676 snd_hda_codec_write(codec, 0x3c, 0,
5677 AC_VERB_SET_POWER_STATE, parm);
5678 } else {
5679 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5680 snd_hda_codec_write(codec, 0x31, 0,
5681 AC_VERB_SET_POWER_STATE, parm);
5682 snd_hda_codec_write(codec, 0x17, 0,
5683 AC_VERB_SET_POWER_STATE, parm);
5684 snd_hda_codec_write(codec, 0x3b, 0,
5685 AC_VERB_SET_POWER_STATE, parm);
5686 }
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005687 /* MW9 (21h) */
5688 if (imux_is_smixer || !is_aa_path_mute(codec))
5689 snd_hda_codec_write(codec, 0x21, 0,
5690 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5691 else
5692 snd_hda_codec_write(codec, 0x21, 0,
5693 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5694}
Lydia Wang25eaba22009-10-10 19:08:43 +08005695
5696/* patch for vt2002P */
5697static int patch_vt2002P(struct hda_codec *codec)
5698{
5699 struct via_spec *spec;
5700 int err;
5701
5702 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01005703 spec = via_new_spec(codec);
Lydia Wang25eaba22009-10-10 19:08:43 +08005704 if (spec == NULL)
5705 return -ENOMEM;
5706
Lydia Wang25eaba22009-10-10 19:08:43 +08005707 /* automatic parse from the BIOS config */
5708 err = vt2002P_parse_auto_config(codec);
5709 if (err < 0) {
5710 via_free(codec);
5711 return err;
5712 } else if (!err) {
5713 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5714 "from BIOS. Using genenic mode...\n");
5715 }
5716
Lydia Wang118909562011-03-23 17:57:34 +08005717 if (spec->codec_type == VT1802)
5718 spec->init_verbs[spec->num_iverbs++] =
5719 vt1802_volume_init_verbs;
5720 else
5721 spec->init_verbs[spec->num_iverbs++] =
5722 vt2002P_volume_init_verbs;
Lydia Wang25eaba22009-10-10 19:08:43 +08005723
Lydia Wang118909562011-03-23 17:57:34 +08005724 if (spec->codec_type == VT1802)
5725 spec->init_verbs[spec->num_iverbs++] =
5726 vt1802_uniwill_init_verbs;
5727 else
5728 spec->init_verbs[spec->num_iverbs++] =
5729 vt2002P_uniwill_init_verbs;
5730
5731 if (spec->codec_type == VT1802)
5732 spec->stream_name_analog = "VT1802 Analog";
5733 else
5734 spec->stream_name_analog = "VT2002P Analog";
Lydia Wang25eaba22009-10-10 19:08:43 +08005735 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5736 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5737
Lydia Wang118909562011-03-23 17:57:34 +08005738 if (spec->codec_type == VT1802)
5739 spec->stream_name_digital = "VT1802 Digital";
5740 else
5741 spec->stream_name_digital = "VT2002P Digital";
Lydia Wang25eaba22009-10-10 19:08:43 +08005742 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5743
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005744 if (spec->adc_nids && spec->input_mux) {
Lydia Wang25eaba22009-10-10 19:08:43 +08005745 override_mic_boost(codec, 0x2b, 0, 3, 40);
5746 override_mic_boost(codec, 0x29, 0, 3, 40);
5747 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5748 spec->num_mixers++;
5749 }
5750
5751 codec->patch_ops = via_patch_ops;
5752
5753 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11005754 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wang25eaba22009-10-10 19:08:43 +08005755
5756#ifdef CONFIG_SND_HDA_POWER_SAVE
5757 spec->loopback.amplist = vt2002P_loopbacks;
5758#endif
5759
Lydia Wang3e95b9a2011-03-23 15:13:28 +08005760 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
Lydia Wang25eaba22009-10-10 19:08:43 +08005761 return 0;
5762}
Lydia Wangab6734e2009-10-10 19:08:46 +08005763
5764/* for vt1812 */
5765
5766/* capture mixer elements */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005767static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005768 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5769 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5770 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5771 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5772 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5773 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5774 HDA_INPUT),
5775 {
5776 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5777 /* The multiple "Capture Source" controls confuse alsamixer
5778 * So call somewhat different..
5779 */
5780 .name = "Input Source",
5781 .count = 2,
5782 .info = via_mux_enum_info,
5783 .get = via_mux_enum_get,
5784 .put = via_mux_enum_put,
5785 },
5786 { } /* end */
5787};
5788
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005789static const struct hda_verb vt1812_volume_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005790 /*
5791 * Unmute ADC0-1 and set the default input to mic-in
5792 */
5793 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5794 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5795
5796
5797 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5798 * mixer widget
5799 */
5800 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5801 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5802 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5803 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5804 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5805 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5806
5807 /* MUX Indices: Mic = 0 */
5808 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5809 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5810
5811 /* PW9 Output enable */
5812 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5813
5814 /* Enable Boost Volume backdoor */
5815 {0x1, 0xfb9, 0x24},
5816
5817 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5818 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5819 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5820 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5821 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5822 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5823 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5824 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5825 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5826 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5827 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5828
5829 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5830 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5831 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5832 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5833 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5834 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5835
5836 /* Enable AOW0 to MW9 */
5837 {0x1, 0xfb8, 0xa8},
5838 { }
5839};
5840
5841
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005842static const struct hda_verb vt1812_uniwill_init_verbs[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005843 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5844 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5845 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5846 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5847 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5848 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5849 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5850 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5851 { }
5852};
5853
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005854static const struct hda_pcm_stream vt1812_pcm_analog_playback = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005855 .substreams = 2,
5856 .channels_min = 2,
5857 .channels_max = 2,
5858 .nid = 0x8, /* NID to query formats and rates */
5859 .ops = {
5860 .open = via_playback_pcm_open,
5861 .prepare = via_playback_multi_pcm_prepare,
5862 .cleanup = via_playback_multi_pcm_cleanup,
5863 .close = via_pcm_open_close,
5864 },
5865};
5866
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005867static const struct hda_pcm_stream vt1812_pcm_analog_capture = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005868 .substreams = 2,
5869 .channels_min = 2,
5870 .channels_max = 2,
5871 .nid = 0x10, /* NID to query formats and rates */
5872 .ops = {
5873 .open = via_pcm_open_close,
5874 .prepare = via_capture_pcm_prepare,
5875 .cleanup = via_capture_pcm_cleanup,
5876 .close = via_pcm_open_close,
5877 },
5878};
5879
Takashi Iwai90dd48a2011-05-02 12:38:19 +02005880static const struct hda_pcm_stream vt1812_pcm_digital_playback = {
Lydia Wangab6734e2009-10-10 19:08:46 +08005881 .substreams = 1,
5882 .channels_min = 2,
5883 .channels_max = 2,
Lydia Wangab6734e2009-10-10 19:08:46 +08005884 /* NID is set in via_build_pcms */
5885 .ops = {
5886 .open = via_dig_playback_pcm_open,
5887 .close = via_dig_playback_pcm_close,
5888 .prepare = via_dig_playback_pcm_prepare,
5889 .cleanup = via_dig_playback_pcm_cleanup
5890 },
5891};
5892/* fill in the dac_nids table from the parsed pin configuration */
5893static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5894 const struct auto_pin_cfg *cfg)
5895{
5896 spec->multiout.num_dacs = 1;
5897 spec->multiout.dac_nids = spec->private_dac_nids;
5898 if (cfg->line_out_pins[0])
Takashi Iwaidda14412011-05-02 11:29:30 +02005899 spec->private_dac_nids[0] = 0x8;
Lydia Wangab6734e2009-10-10 19:08:46 +08005900 return 0;
5901}
5902
5903
5904/* add playback controls from the parsed DAC table */
5905static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5906 const struct auto_pin_cfg *cfg)
5907{
5908 int err;
5909
5910 if (!cfg->line_out_pins[0])
5911 return -1;
5912
5913 /* Line-Out: PortE */
5914 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Takashi Iwai3d83e572010-04-14 14:36:23 +02005915 "Front Playback Volume",
Lydia Wangab6734e2009-10-10 19:08:46 +08005916 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5917 if (err < 0)
5918 return err;
5919 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
Takashi Iwai3d83e572010-04-14 14:36:23 +02005920 "Front Playback Switch",
Lydia Wangab6734e2009-10-10 19:08:46 +08005921 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5922 if (err < 0)
5923 return err;
5924
5925 return 0;
5926}
5927
5928static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5929{
5930 int err;
5931
5932 if (!pin)
5933 return 0;
5934
5935 spec->multiout.hp_nid = 0x9;
5936 spec->hp_independent_mode_index = 1;
5937
5938
5939 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5940 "Headphone Playback Volume",
5941 HDA_COMPOSE_AMP_VAL(
5942 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5943 if (err < 0)
5944 return err;
5945
5946 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5947 "Headphone Playback Switch",
5948 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5949 if (err < 0)
5950 return err;
5951
5952 create_hp_imux(spec);
5953 return 0;
5954}
5955
5956/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02005957static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
Lydia Wangab6734e2009-10-10 19:08:46 +08005958 const struct auto_pin_cfg *cfg)
5959{
Takashi Iwaia766d0d2011-06-17 09:01:29 +02005960 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
Lydia Wangab6734e2009-10-10 19:08:46 +08005961}
5962
5963static int vt1812_parse_auto_config(struct hda_codec *codec)
5964{
5965 struct via_spec *spec = codec->spec;
5966 int err;
5967
5968
5969 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5970 if (err < 0)
5971 return err;
5972 fill_dig_outs(codec);
5973 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5974 if (err < 0)
5975 return err;
5976
5977 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5978 return 0; /* can't find valid BIOS pin config */
5979
5980 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5981 if (err < 0)
5982 return err;
5983 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5984 if (err < 0)
5985 return err;
Takashi Iwai10a20af2010-09-09 16:28:02 +02005986 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
Lydia Wangab6734e2009-10-10 19:08:46 +08005987 if (err < 0)
5988 return err;
5989
5990 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5991
5992 fill_dig_outs(codec);
5993
5994 if (spec->kctls.list)
5995 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5996
5997 spec->input_mux = &spec->private_imux[0];
5998
5999 if (spec->hp_mux)
Takashi Iwai3d83e572010-04-14 14:36:23 +02006000 via_hp_build(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08006001
6002 return 1;
6003}
6004
6005#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai90dd48a2011-05-02 12:38:19 +02006006static const struct hda_amp_list vt1812_loopbacks[] = {
Lydia Wangab6734e2009-10-10 19:08:46 +08006007 { 0x21, HDA_INPUT, 0 },
6008 { 0x21, HDA_INPUT, 1 },
6009 { 0x21, HDA_INPUT, 2 },
6010 { } /* end */
6011};
6012#endif
6013
Lydia Wang3e95b9a2011-03-23 15:13:28 +08006014static void set_widgets_power_state_vt1812(struct hda_codec *codec)
6015{
6016 struct via_spec *spec = codec->spec;
6017 int imux_is_smixer =
6018 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
6019 unsigned int parm;
6020 unsigned int present;
6021 /* MUX10 (1eh) = stereo mixer */
6022 imux_is_smixer =
6023 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
6024 /* inputs */
6025 /* PW 5/6/7 (29h/2ah/2bh) */
6026 parm = AC_PWRST_D3;
6027 set_pin_power_state(codec, 0x29, &parm);
6028 set_pin_power_state(codec, 0x2a, &parm);
6029 set_pin_power_state(codec, 0x2b, &parm);
6030 parm = AC_PWRST_D0;
6031 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
6032 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
6033 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
6034 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
6035 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
6036
6037 /* outputs */
6038 /* AOW0 (8h)*/
6039 snd_hda_codec_write(codec, 0x8, 0,
6040 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6041
6042 /* PW4 (28h), MW4 (18h), MUX4(38h) */
6043 parm = AC_PWRST_D3;
6044 set_pin_power_state(codec, 0x28, &parm);
6045 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
6046 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
6047
6048 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
6049 parm = AC_PWRST_D3;
6050 set_pin_power_state(codec, 0x25, &parm);
6051 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
6052 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
6053 if (spec->hp_independent_mode)
6054 snd_hda_codec_write(codec, 0x9, 0,
6055 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6056
6057 /* Internal Speaker */
6058 /* PW0 (24h), MW0(14h), MUX0(34h) */
6059 present = snd_hda_jack_detect(codec, 0x25);
6060
6061 parm = AC_PWRST_D3;
6062 set_pin_power_state(codec, 0x24, &parm);
6063 if (present) {
6064 snd_hda_codec_write(codec, 0x14, 0,
6065 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6066 snd_hda_codec_write(codec, 0x34, 0,
6067 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6068 } else {
6069 snd_hda_codec_write(codec, 0x14, 0,
6070 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6071 snd_hda_codec_write(codec, 0x34, 0,
6072 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6073 }
6074
6075
6076 /* Mono Out */
6077 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6078 present = snd_hda_jack_detect(codec, 0x28);
6079
6080 parm = AC_PWRST_D3;
6081 set_pin_power_state(codec, 0x31, &parm);
6082 if (present) {
6083 snd_hda_codec_write(codec, 0x1c, 0,
6084 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6085 snd_hda_codec_write(codec, 0x3c, 0,
6086 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6087 snd_hda_codec_write(codec, 0x3e, 0,
6088 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6089 } else {
6090 snd_hda_codec_write(codec, 0x1c, 0,
6091 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6092 snd_hda_codec_write(codec, 0x3c, 0,
6093 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6094 snd_hda_codec_write(codec, 0x3e, 0,
6095 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6096 }
6097
6098 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6099 parm = AC_PWRST_D3;
6100 set_pin_power_state(codec, 0x33, &parm);
6101 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6102 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6103
6104}
Lydia Wangab6734e2009-10-10 19:08:46 +08006105
6106/* patch for vt1812 */
6107static int patch_vt1812(struct hda_codec *codec)
6108{
6109 struct via_spec *spec;
6110 int err;
6111
6112 /* create a codec specific record */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01006113 spec = via_new_spec(codec);
Lydia Wangab6734e2009-10-10 19:08:46 +08006114 if (spec == NULL)
6115 return -ENOMEM;
6116
Lydia Wangab6734e2009-10-10 19:08:46 +08006117 /* automatic parse from the BIOS config */
6118 err = vt1812_parse_auto_config(codec);
6119 if (err < 0) {
6120 via_free(codec);
6121 return err;
6122 } else if (!err) {
6123 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6124 "from BIOS. Using genenic mode...\n");
6125 }
6126
6127
6128 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6129 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6130
6131 spec->stream_name_analog = "VT1812 Analog";
6132 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6133 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6134
6135 spec->stream_name_digital = "VT1812 Digital";
6136 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6137
Takashi Iwaia766d0d2011-06-17 09:01:29 +02006138 if (spec->adc_nids && spec->input_mux) {
Lydia Wangab6734e2009-10-10 19:08:46 +08006139 override_mic_boost(codec, 0x2b, 0, 3, 40);
6140 override_mic_boost(codec, 0x29, 0, 3, 40);
6141 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6142 spec->num_mixers++;
6143 }
6144
6145 codec->patch_ops = via_patch_ops;
6146
6147 codec->patch_ops.init = via_auto_init;
Stephen Rothwell0f483272009-10-12 15:56:17 +11006148 codec->patch_ops.unsol_event = via_unsol_event;
Lydia Wangab6734e2009-10-10 19:08:46 +08006149
6150#ifdef CONFIG_SND_HDA_POWER_SAVE
6151 spec->loopback.amplist = vt1812_loopbacks;
6152#endif
6153
Lydia Wang3e95b9a2011-03-23 15:13:28 +08006154 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
Lydia Wangab6734e2009-10-10 19:08:46 +08006155 return 0;
6156}
6157
Joseph Chanc577b8a2006-11-29 15:29:40 +01006158/*
6159 * patch entries
6160 */
Takashi Iwai90dd48a2011-05-02 12:38:19 +02006161static const struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01006162 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6163 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6164 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6165 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6166 { .id = 0x1106e710, .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 = 0x1106e711, .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 = 0x1106e712, .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 = 0x1106e713, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006173 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006174 { .id = 0x1106e714, .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 = 0x1106e715, .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 = 0x1106e716, .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 = 0x1106e717, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006181 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006182 { .id = 0x1106e720, .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 = 0x1106e721, .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 = 0x1106e722, .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 = 0x1106e723, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006189 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006190 { .id = 0x1106e724, .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 = 0x1106e725, .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 = 0x1106e726, .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 = 0x1106e727, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01006197 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01006198 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006199 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006200 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006201 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006202 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006203 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006204 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006205 .patch = patch_vt1708S},
Lydia Wangbc92df72011-03-23 17:56:05 +08006206 { .id = 0x11064397, .name = "VT1705",
Harald Welted949cac2008-09-09 15:56:01 +08006207 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006208 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006209 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006210 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006211 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006212 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08006213 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01006214 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006215 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006216 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006217 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006218 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006219 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006220 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006221 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006222 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006223 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006224 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006225 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006226 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006227 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01006228 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08006229 .patch = patch_vt1702},
Lydia Wangeb7188c2009-10-10 19:08:34 +08006230 { .id = 0x11060428, .name = "VT1718S",
6231 .patch = patch_vt1718S},
6232 { .id = 0x11064428, .name = "VT1718S",
6233 .patch = patch_vt1718S},
Lydia Wangbb3c6bfc2009-10-10 19:08:39 +08006234 { .id = 0x11060441, .name = "VT2020",
6235 .patch = patch_vt1718S},
6236 { .id = 0x11064441, .name = "VT1828S",
6237 .patch = patch_vt1718S},
Lydia Wangf3db4232009-10-10 19:08:41 +08006238 { .id = 0x11060433, .name = "VT1716S",
6239 .patch = patch_vt1716S},
6240 { .id = 0x1106a721, .name = "VT1716S",
6241 .patch = patch_vt1716S},
Lydia Wang25eaba22009-10-10 19:08:43 +08006242 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6243 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
Lydia Wangab6734e2009-10-10 19:08:46 +08006244 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
Lydia Wang36dd5c42009-10-20 13:18:04 +08006245 { .id = 0x11060440, .name = "VT1818S",
6246 .patch = patch_vt1708S},
Lydia Wang118909562011-03-23 17:57:34 +08006247 { .id = 0x11060446, .name = "VT1802",
6248 .patch = patch_vt2002P},
6249 { .id = 0x11068446, .name = "VT1802",
6250 .patch = patch_vt2002P},
Joseph Chanc577b8a2006-11-29 15:29:40 +01006251 {} /* terminator */
6252};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006253
6254MODULE_ALIAS("snd-hda-codec-id:1106*");
6255
6256static struct hda_codec_preset_list via_list = {
6257 .preset = snd_hda_preset_via,
6258 .owner = THIS_MODULE,
6259};
6260
6261MODULE_LICENSE("GPL");
6262MODULE_DESCRIPTION("VIA HD-audio codec");
6263
6264static int __init patch_via_init(void)
6265{
6266 return snd_hda_add_codec_preset(&via_list);
6267}
6268
6269static void __exit patch_via_exit(void)
6270{
6271 snd_hda_delete_codec_preset(&via_list);
6272}
6273
6274module_init(patch_via_init)
6275module_exit(patch_via_exit)