blob: ab90abb04ccddb7c7229522c88d31aa6f50f5982 [file] [log] [blame]
Joseph Chanc577b8a2006-11-29 15:29:40 +01001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Harald Welted949cac2008-09-09 15:56:01 +08004 * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec
Joseph Chanc577b8a2006-11-29 15:29:40 +01005 *
Harald Welte76d9b0d2008-09-09 15:50:37 +08006 * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com>
7 * 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 * * * * * * * * * * * * * * * * */
25/* */
26/* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27/* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28/* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29/* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
Josepch Chanf7278fd2007-12-13 16:40:40 +010030/* 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 */
Harald Welted949cac2008-09-09 15:56:01 +080034/* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
Harald Welte69e52a82008-09-09 15:57:32 +080035/* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
Harald Welte0aa62ae2008-09-09 15:58:27 +080036/* 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 */
Harald Welted7426322008-09-15 22:43:23 +080038/* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
Joseph Chanc577b8a2006-11-29 15:29:40 +010039/* */
40/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
41
42
Joseph Chanc577b8a2006-11-29 15:29:40 +010043#include <linux/init.h>
44#include <linux/delay.h>
45#include <linux/slab.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010046#include <sound/core.h>
Harald Welte0aa62ae2008-09-09 15:58:27 +080047#include <sound/asoundef.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010048#include "hda_codec.h"
49#include "hda_local.h"
Joseph Chanc577b8a2006-11-29 15:29:40 +010050
51/* amp values */
52#define AMP_VAL_IDX_SHIFT 19
53#define AMP_VAL_IDX_MASK (0x0f<<19)
54
Joseph Chanc577b8a2006-11-29 15:29:40 +010055/* Pin Widget NID */
56#define VT1708_HP_NID 0x13
57#define VT1708_DIGOUT_NID 0x14
58#define VT1708_DIGIN_NID 0x16
Josepch Chanf7278fd2007-12-13 16:40:40 +010059#define VT1708_DIGIN_PIN 0x26
Harald Welted949cac2008-09-09 15:56:01 +080060#define VT1708_HP_PIN_NID 0x20
61#define VT1708_CD_PIN_NID 0x24
Joseph Chanc577b8a2006-11-29 15:29:40 +010062
63#define VT1709_HP_DAC_NID 0x28
64#define VT1709_DIGOUT_NID 0x13
65#define VT1709_DIGIN_NID 0x17
Josepch Chanf7278fd2007-12-13 16:40:40 +010066#define VT1709_DIGIN_PIN 0x25
67
68#define VT1708B_HP_NID 0x25
69#define VT1708B_DIGOUT_NID 0x12
70#define VT1708B_DIGIN_NID 0x15
71#define VT1708B_DIGIN_PIN 0x21
Joseph Chanc577b8a2006-11-29 15:29:40 +010072
Harald Welted949cac2008-09-09 15:56:01 +080073#define VT1708S_HP_NID 0x25
74#define VT1708S_DIGOUT_NID 0x12
75
76#define VT1702_HP_NID 0x17
77#define VT1702_DIGOUT_NID 0x11
78
Joseph Chanc577b8a2006-11-29 15:29:40 +010079#define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
80#define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
81#define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
Josepch Chanf7278fd2007-12-13 16:40:40 +010082#define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
83#define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
Harald Welted949cac2008-09-09 15:56:01 +080084#define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
85#define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
Joseph Chanc577b8a2006-11-29 15:29:40 +010086
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,
95 VT1702,
96 CODEC_TYPES,
97};
98
99static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
100{
101 u16 ven_id = vendor_id >> 16;
102 u16 dev_id = vendor_id & 0xffff;
103 enum VIA_HDA_CODEC codec_type;
104
105 /* get codec type */
106 if (ven_id != 0x1106)
107 codec_type = UNKNOWN;
108 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
109 codec_type = VT1708;
110 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
111 codec_type = VT1709_10CH;
112 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
113 codec_type = VT1709_6CH;
114 else if (dev_id >= 0xe720 && dev_id <= 0xe723)
115 codec_type = VT1708B_8CH;
116 else if (dev_id >= 0xe724 && dev_id <= 0xe727)
117 codec_type = VT1708B_4CH;
118 else if ((dev_id & 0xfff) == 0x397
119 && (dev_id >> 12) < 8)
120 codec_type = VT1708S;
121 else if ((dev_id & 0xfff) == 0x398
122 && (dev_id >> 12) < 8)
123 codec_type = VT1702;
124 else
125 codec_type = UNKNOWN;
126 return codec_type;
127};
128
Harald Welte69e52a82008-09-09 15:57:32 +0800129#define VIA_HP_EVENT 0x01
130#define VIA_GPIO_EVENT 0x02
131
Joseph Chanc577b8a2006-11-29 15:29:40 +0100132enum {
133 VIA_CTL_WIDGET_VOL,
134 VIA_CTL_WIDGET_MUTE,
135};
136
137enum {
Harald Welteeb14a462008-09-09 15:40:38 +0800138 AUTO_SEQ_FRONT = 0,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100139 AUTO_SEQ_SURROUND,
140 AUTO_SEQ_CENLFE,
141 AUTO_SEQ_SIDE
142};
143
Harald Welted7426322008-09-15 22:43:23 +0800144/* Some VT1708S based boards gets the micboost setting wrong, so we have
145 * to apply some brute-force and re-write the TLV's by software. */
146static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag,
147 unsigned int size, unsigned int __user *_tlv)
148{
149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
150 hda_nid_t nid = get_amp_nid(kcontrol);
151
152 if (get_codec_type(codec->vendor_id) == VT1708S
153 && (nid == 0x1a || nid == 0x1e)) {
154 if (size < 4 * sizeof(unsigned int))
155 return -ENOMEM;
156 if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */
157 return -EFAULT;
158 if (put_user(2 * sizeof(unsigned int), _tlv + 1))
159 return -EFAULT;
160 if (put_user(0, _tlv + 2)) /* offset = 0 */
161 return -EFAULT;
162 if (put_user(1000, _tlv + 3)) /* step size = 10 dB */
163 return -EFAULT;
164 }
165 return 0;
166}
167
168static int mic_boost_volume_info(struct snd_kcontrol *kcontrol,
169 struct snd_ctl_elem_info *uinfo)
170{
171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
172 hda_nid_t nid = get_amp_nid(kcontrol);
173
174 if (get_codec_type(codec->vendor_id) == VT1708S
175 && (nid == 0x1a || nid == 0x1e)) {
176 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
177 uinfo->count = 2;
178 uinfo->value.integer.min = 0;
179 uinfo->value.integer.max = 3;
180 }
181 return 0;
182}
183
Joseph Chanc577b8a2006-11-29 15:29:40 +0100184static struct snd_kcontrol_new vt1708_control_templates[] = {
185 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
186 HDA_CODEC_MUTE(NULL, 0, 0, 0),
187};
188
189
190struct via_spec {
191 /* codec parameterization */
192 struct snd_kcontrol_new *mixers[3];
193 unsigned int num_mixers;
194
Harald Welte69e52a82008-09-09 15:57:32 +0800195 struct hda_verb *init_verbs[5];
196 unsigned int num_iverbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100197
198 char *stream_name_analog;
199 struct hda_pcm_stream *stream_analog_playback;
200 struct hda_pcm_stream *stream_analog_capture;
201
202 char *stream_name_digital;
203 struct hda_pcm_stream *stream_digital_playback;
204 struct hda_pcm_stream *stream_digital_capture;
205
206 /* playback */
207 struct hda_multi_out multiout;
Takashi Iwai9da29272009-05-07 16:31:14 +0200208 hda_nid_t slave_dig_outs[2];
Joseph Chanc577b8a2006-11-29 15:29:40 +0100209
210 /* capture */
211 unsigned int num_adc_nids;
212 hda_nid_t *adc_nids;
Takashi Iwai337b9d02009-07-07 18:18:59 +0200213 hda_nid_t mux_nids[3];
Joseph Chanc577b8a2006-11-29 15:29:40 +0100214 hda_nid_t dig_in_nid;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +0200215 hda_nid_t dig_in_pin;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100216
217 /* capture source */
218 const struct hda_input_mux *input_mux;
219 unsigned int cur_mux[3];
220
221 /* PCM information */
Harald Welte98aa34c2008-09-09 16:02:09 +0800222 struct hda_pcm pcm_rec[3];
Joseph Chanc577b8a2006-11-29 15:29:40 +0100223
224 /* dynamic controls, init_verbs and input_mux */
225 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200226 struct snd_array kctls;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800227 struct hda_input_mux private_imux[2];
Takashi Iwai41923e42007-10-22 17:20:10 +0200228 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200229
Harald Welte0aa62ae2008-09-09 15:58:27 +0800230 /* HP mode source */
231 const struct hda_input_mux *hp_mux;
232 unsigned int hp_independent_mode;
233
Takashi Iwaicb53c622007-08-10 17:21:45 +0200234#ifdef CONFIG_SND_HDA_POWER_SAVE
235 struct hda_loopback_check loopback;
236#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +0100237};
238
239static hda_nid_t vt1708_adc_nids[2] = {
240 /* ADC1-2 */
241 0x15, 0x27
242};
243
244static hda_nid_t vt1709_adc_nids[3] = {
245 /* ADC1-2 */
246 0x14, 0x15, 0x16
247};
248
Josepch Chanf7278fd2007-12-13 16:40:40 +0100249static hda_nid_t vt1708B_adc_nids[2] = {
250 /* ADC1-2 */
251 0x13, 0x14
252};
253
Harald Welted949cac2008-09-09 15:56:01 +0800254static hda_nid_t vt1708S_adc_nids[2] = {
255 /* ADC1-2 */
256 0x13, 0x14
257};
258
259static hda_nid_t vt1702_adc_nids[3] = {
260 /* ADC1-2 */
261 0x12, 0x20, 0x1F
262};
263
Joseph Chanc577b8a2006-11-29 15:29:40 +0100264/* add dynamic controls */
265static int via_add_control(struct via_spec *spec, int type, const char *name,
266 unsigned long val)
267{
268 struct snd_kcontrol_new *knew;
269
Takashi Iwai603c4012008-07-30 15:01:44 +0200270 snd_array_init(&spec->kctls, sizeof(*knew), 32);
271 knew = snd_array_new(&spec->kctls);
272 if (!knew)
273 return -ENOMEM;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100274 *knew = vt1708_control_templates[type];
275 knew->name = kstrdup(name, GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100276 if (!knew->name)
277 return -ENOMEM;
278 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100279 return 0;
280}
281
Takashi Iwai603c4012008-07-30 15:01:44 +0200282static void via_free_kctls(struct hda_codec *codec)
283{
284 struct via_spec *spec = codec->spec;
285
286 if (spec->kctls.list) {
287 struct snd_kcontrol_new *kctl = spec->kctls.list;
288 int i;
289 for (i = 0; i < spec->kctls.used; i++)
290 kfree(kctl[i].name);
291 }
292 snd_array_free(&spec->kctls);
293}
294
Joseph Chanc577b8a2006-11-29 15:29:40 +0100295/* create input playback/capture controls for the given pin */
296static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
297 const char *ctlname, int idx, int mix_nid)
298{
299 char name[32];
300 int err;
301
302 sprintf(name, "%s Playback Volume", ctlname);
303 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
304 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
305 if (err < 0)
306 return err;
307 sprintf(name, "%s Playback Switch", ctlname);
308 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
309 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
310 if (err < 0)
311 return err;
312 return 0;
313}
314
315static void via_auto_set_output_and_unmute(struct hda_codec *codec,
316 hda_nid_t nid, int pin_type,
317 int dac_idx)
318{
319 /* set as output */
320 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
321 pin_type);
322 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
323 AMP_OUT_UNMUTE);
Takashi Iwaid3a11e62009-07-07 13:43:35 +0200324 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
325 snd_hda_codec_write(codec, nid, 0,
326 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100327}
328
329
330static void via_auto_init_multi_out(struct hda_codec *codec)
331{
332 struct via_spec *spec = codec->spec;
333 int i;
334
335 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
336 hda_nid_t nid = spec->autocfg.line_out_pins[i];
337 if (nid)
338 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
339 }
340}
341
342static void via_auto_init_hp_out(struct hda_codec *codec)
343{
344 struct via_spec *spec = codec->spec;
345 hda_nid_t pin;
346
347 pin = spec->autocfg.hp_pins[0];
348 if (pin) /* connect to front */
349 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
350}
351
352static void via_auto_init_analog_input(struct hda_codec *codec)
353{
354 struct via_spec *spec = codec->spec;
355 int i;
356
357 for (i = 0; i < AUTO_PIN_LAST; i++) {
358 hda_nid_t nid = spec->autocfg.input_pins[i];
359
360 snd_hda_codec_write(codec, nid, 0,
361 AC_VERB_SET_PIN_WIDGET_CONTROL,
362 (i <= AUTO_PIN_FRONT_MIC ?
363 PIN_VREF50 : PIN_IN));
364
365 }
366}
367/*
368 * input MUX handling
369 */
370static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
371 struct snd_ctl_elem_info *uinfo)
372{
373 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
374 struct via_spec *spec = codec->spec;
375 return snd_hda_input_mux_info(spec->input_mux, uinfo);
376}
377
378static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
379 struct snd_ctl_elem_value *ucontrol)
380{
381 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
382 struct via_spec *spec = codec->spec;
383 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
384
385 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
386 return 0;
387}
388
389static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
390 struct snd_ctl_elem_value *ucontrol)
391{
392 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
393 struct via_spec *spec = codec->spec;
394 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100395
Takashi Iwai337b9d02009-07-07 18:18:59 +0200396 if (!spec->mux_nids[adc_idx])
397 return -EINVAL;
398 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
399 spec->mux_nids[adc_idx],
400 &spec->cur_mux[adc_idx]);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100401}
402
Harald Welte0aa62ae2008-09-09 15:58:27 +0800403static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
404 struct snd_ctl_elem_info *uinfo)
405{
406 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407 struct via_spec *spec = codec->spec;
408 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
409}
410
411static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
412 struct snd_ctl_elem_value *ucontrol)
413{
414 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
415 struct via_spec *spec = codec->spec;
416 hda_nid_t nid = spec->autocfg.hp_pins[0];
417 unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
418 AC_VERB_GET_CONNECT_SEL,
419 0x00);
420
421 ucontrol->value.enumerated.item[0] = pinsel;
422
423 return 0;
424}
425
426static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
427 struct snd_ctl_elem_value *ucontrol)
428{
429 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
430 struct via_spec *spec = codec->spec;
431 hda_nid_t nid = spec->autocfg.hp_pins[0];
432 unsigned int pinsel = ucontrol->value.enumerated.item[0];
433 unsigned int con_nid = snd_hda_codec_read(codec, nid, 0,
434 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
435
436 if (con_nid == spec->multiout.hp_nid) {
437 if (pinsel == 0) {
438 if (!spec->hp_independent_mode) {
439 if (spec->multiout.num_dacs > 1)
440 spec->multiout.num_dacs -= 1;
441 spec->hp_independent_mode = 1;
442 }
443 } else if (pinsel == 1) {
444 if (spec->hp_independent_mode) {
445 if (spec->multiout.num_dacs > 1)
446 spec->multiout.num_dacs += 1;
447 spec->hp_independent_mode = 0;
448 }
449 }
450 } else {
451 if (pinsel == 0) {
452 if (spec->hp_independent_mode) {
453 if (spec->multiout.num_dacs > 1)
454 spec->multiout.num_dacs += 1;
455 spec->hp_independent_mode = 0;
456 }
457 } else if (pinsel == 1) {
458 if (!spec->hp_independent_mode) {
459 if (spec->multiout.num_dacs > 1)
460 spec->multiout.num_dacs -= 1;
461 spec->hp_independent_mode = 1;
462 }
463 }
464 }
465 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
466 pinsel);
467
468 if (spec->multiout.hp_nid &&
469 spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
470 snd_hda_codec_setup_stream(codec,
471 spec->multiout.hp_nid,
472 0, 0, 0);
473
474 return 0;
475}
476
477static struct snd_kcontrol_new via_hp_mixer[] = {
478 {
479 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
480 .name = "Independent HP",
481 .count = 1,
482 .info = via_independent_hp_info,
483 .get = via_independent_hp_get,
484 .put = via_independent_hp_put,
485 },
486 { } /* end */
487};
488
Joseph Chanc577b8a2006-11-29 15:29:40 +0100489/* capture mixer elements */
490static struct snd_kcontrol_new vt1708_capture_mixer[] = {
491 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
492 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
493 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
494 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
495 {
496 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
497 /* The multiple "Capture Source" controls confuse alsamixer
498 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +0100499 */
500 /* .name = "Capture Source", */
501 .name = "Input Source",
502 .count = 1,
503 .info = via_mux_enum_info,
504 .get = via_mux_enum_get,
505 .put = via_mux_enum_put,
506 },
507 { } /* end */
508};
509/*
510 * generic initialization of ADC, input mixers and output mixers
511 */
512static struct hda_verb vt1708_volume_init_verbs[] = {
513 /*
514 * Unmute ADC0-1 and set the default input to mic-in
515 */
516 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
517 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
518
519
Josepch Chanf7278fd2007-12-13 16:40:40 +0100520 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +0100521 * mixer widget
522 */
523 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +0100524 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
525 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
526 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
527 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
528 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +0100529
530 /*
531 * Set up output mixers (0x19 - 0x1b)
532 */
533 /* set vol=0 to output mixers */
534 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
535 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
536 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
537
538 /* Setup default input to PW4 */
539 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
Joseph Chanc577b8a2006-11-29 15:29:40 +0100540 /* PW9 Output enable */
541 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Josepch Chanf7278fd2007-12-13 16:40:40 +0100542 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100543};
544
545static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
546 struct hda_codec *codec,
547 struct snd_pcm_substream *substream)
548{
549 struct via_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100550 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
551 hinfo);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100552}
553
554static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
555 struct hda_codec *codec,
556 unsigned int stream_tag,
557 unsigned int format,
558 struct snd_pcm_substream *substream)
559{
560 struct via_spec *spec = codec->spec;
561 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
562 stream_tag, format, substream);
563}
564
565static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
566 struct hda_codec *codec,
567 struct snd_pcm_substream *substream)
568{
569 struct via_spec *spec = codec->spec;
570 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
571}
572
Harald Welte0aa62ae2008-09-09 15:58:27 +0800573
574static void playback_multi_pcm_prep_0(struct hda_codec *codec,
575 unsigned int stream_tag,
576 unsigned int format,
577 struct snd_pcm_substream *substream)
578{
579 struct via_spec *spec = codec->spec;
580 struct hda_multi_out *mout = &spec->multiout;
581 hda_nid_t *nids = mout->dac_nids;
582 int chs = substream->runtime->channels;
583 int i;
584
585 mutex_lock(&codec->spdif_mutex);
586 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
587 if (chs == 2 &&
588 snd_hda_is_supported_format(codec, mout->dig_out_nid,
589 format) &&
590 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
591 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
592 /* turn off SPDIF once; otherwise the IEC958 bits won't
593 * be updated */
594 if (codec->spdif_ctls & AC_DIG1_ENABLE)
595 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
596 AC_VERB_SET_DIGI_CONVERT_1,
597 codec->spdif_ctls &
598 ~AC_DIG1_ENABLE & 0xff);
599 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
600 stream_tag, 0, format);
601 /* turn on again (if needed) */
602 if (codec->spdif_ctls & AC_DIG1_ENABLE)
603 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
604 AC_VERB_SET_DIGI_CONVERT_1,
605 codec->spdif_ctls & 0xff);
606 } else {
607 mout->dig_out_used = 0;
608 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
609 0, 0, 0);
610 }
611 }
612 mutex_unlock(&codec->spdif_mutex);
613
614 /* front */
615 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
616 0, format);
617
618 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
619 !spec->hp_independent_mode)
620 /* headphone out will just decode front left/right (stereo) */
621 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
622 0, format);
623
624 /* extra outputs copied from front */
625 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
626 if (mout->extra_out_nid[i])
627 snd_hda_codec_setup_stream(codec,
628 mout->extra_out_nid[i],
629 stream_tag, 0, format);
630
631 /* surrounds */
632 for (i = 1; i < mout->num_dacs; i++) {
633 if (chs >= (i + 1) * 2) /* independent out */
634 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
635 i * 2, format);
636 else /* copy front */
637 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
638 0, format);
639 }
640}
641
642static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
643 struct hda_codec *codec,
644 unsigned int stream_tag,
645 unsigned int format,
646 struct snd_pcm_substream *substream)
647{
648 struct via_spec *spec = codec->spec;
649 struct hda_multi_out *mout = &spec->multiout;
650 hda_nid_t *nids = mout->dac_nids;
651
652 if (substream->number == 0)
653 playback_multi_pcm_prep_0(codec, stream_tag, format,
654 substream);
655 else {
656 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
657 spec->hp_independent_mode)
658 snd_hda_codec_setup_stream(codec, mout->hp_nid,
659 stream_tag, 0, format);
660 }
661
662 return 0;
663}
664
665static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
666 struct hda_codec *codec,
667 struct snd_pcm_substream *substream)
668{
669 struct via_spec *spec = codec->spec;
670 struct hda_multi_out *mout = &spec->multiout;
671 hda_nid_t *nids = mout->dac_nids;
672 int i;
673
674 if (substream->number == 0) {
675 for (i = 0; i < mout->num_dacs; i++)
676 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
677
678 if (mout->hp_nid && !spec->hp_independent_mode)
679 snd_hda_codec_setup_stream(codec, mout->hp_nid,
680 0, 0, 0);
681
682 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
683 if (mout->extra_out_nid[i])
684 snd_hda_codec_setup_stream(codec,
685 mout->extra_out_nid[i],
686 0, 0, 0);
687 mutex_lock(&codec->spdif_mutex);
688 if (mout->dig_out_nid &&
689 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
690 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
691 0, 0, 0);
692 mout->dig_out_used = 0;
693 }
694 mutex_unlock(&codec->spdif_mutex);
695 } else {
696 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
697 spec->hp_independent_mode)
698 snd_hda_codec_setup_stream(codec, mout->hp_nid,
699 0, 0, 0);
700 }
701
702 return 0;
703}
704
Joseph Chanc577b8a2006-11-29 15:29:40 +0100705/*
706 * Digital out
707 */
708static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
709 struct hda_codec *codec,
710 struct snd_pcm_substream *substream)
711{
712 struct via_spec *spec = codec->spec;
713 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
714}
715
716static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
717 struct hda_codec *codec,
718 struct snd_pcm_substream *substream)
719{
720 struct via_spec *spec = codec->spec;
721 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
722}
723
Harald Welte5691ec72008-09-15 22:42:26 +0800724static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +0800725 struct hda_codec *codec,
726 unsigned int stream_tag,
727 unsigned int format,
728 struct snd_pcm_substream *substream)
729{
730 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +0200731 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
732 stream_tag, format, substream);
733}
Harald Welte5691ec72008-09-15 22:42:26 +0800734
Takashi Iwai9da29272009-05-07 16:31:14 +0200735static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
736 struct hda_codec *codec,
737 struct snd_pcm_substream *substream)
738{
739 struct via_spec *spec = codec->spec;
740 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +0800741 return 0;
742}
743
Joseph Chanc577b8a2006-11-29 15:29:40 +0100744/*
745 * Analog capture
746 */
747static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
748 struct hda_codec *codec,
749 unsigned int stream_tag,
750 unsigned int format,
751 struct snd_pcm_substream *substream)
752{
753 struct via_spec *spec = codec->spec;
754
755 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
756 stream_tag, 0, format);
757 return 0;
758}
759
760static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
761 struct hda_codec *codec,
762 struct snd_pcm_substream *substream)
763{
764 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100765 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100766 return 0;
767}
768
769static struct hda_pcm_stream vt1708_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +0800770 .substreams = 2,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100771 .channels_min = 2,
772 .channels_max = 8,
773 .nid = 0x10, /* NID to query formats and rates */
774 .ops = {
775 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +0800776 .prepare = via_playback_multi_pcm_prepare,
777 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +0100778 },
779};
780
Takashi Iwaibc9b5622008-05-23 17:50:27 +0200781static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
782 .substreams = 1,
783 .channels_min = 2,
784 .channels_max = 8,
785 .nid = 0x10, /* NID to query formats and rates */
786 /* We got noisy outputs on the right channel on VT1708 when
787 * 24bit samples are used. Until any workaround is found,
788 * disable the 24bit format, so far.
789 */
790 .formats = SNDRV_PCM_FMTBIT_S16_LE,
791 .ops = {
792 .open = via_playback_pcm_open,
793 .prepare = via_playback_pcm_prepare,
794 .cleanup = via_playback_pcm_cleanup
795 },
796};
797
Joseph Chanc577b8a2006-11-29 15:29:40 +0100798static struct hda_pcm_stream vt1708_pcm_analog_capture = {
799 .substreams = 2,
800 .channels_min = 2,
801 .channels_max = 2,
802 .nid = 0x15, /* NID to query formats and rates */
803 .ops = {
804 .prepare = via_capture_pcm_prepare,
805 .cleanup = via_capture_pcm_cleanup
806 },
807};
808
809static struct hda_pcm_stream vt1708_pcm_digital_playback = {
810 .substreams = 1,
811 .channels_min = 2,
812 .channels_max = 2,
813 /* NID is set in via_build_pcms */
814 .ops = {
815 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200816 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +0200817 .prepare = via_dig_playback_pcm_prepare,
818 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +0100819 },
820};
821
822static struct hda_pcm_stream vt1708_pcm_digital_capture = {
823 .substreams = 1,
824 .channels_min = 2,
825 .channels_max = 2,
826};
827
828static int via_build_controls(struct hda_codec *codec)
829{
830 struct via_spec *spec = codec->spec;
831 int err;
832 int i;
833
834 for (i = 0; i < spec->num_mixers; i++) {
835 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
836 if (err < 0)
837 return err;
838 }
839
840 if (spec->multiout.dig_out_nid) {
841 err = snd_hda_create_spdif_out_ctls(codec,
842 spec->multiout.dig_out_nid);
843 if (err < 0)
844 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100845 err = snd_hda_create_spdif_share_sw(codec,
846 &spec->multiout);
847 if (err < 0)
848 return err;
849 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100850 }
851 if (spec->dig_in_nid) {
852 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
853 if (err < 0)
854 return err;
855 }
Takashi Iwai603c4012008-07-30 15:01:44 +0200856 via_free_kctls(codec); /* no longer needed */
Joseph Chanc577b8a2006-11-29 15:29:40 +0100857 return 0;
858}
859
860static int via_build_pcms(struct hda_codec *codec)
861{
862 struct via_spec *spec = codec->spec;
863 struct hda_pcm *info = spec->pcm_rec;
864
865 codec->num_pcms = 1;
866 codec->pcm_info = info;
867
868 info->name = spec->stream_name_analog;
869 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
870 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
871 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
872 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
873
874 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
875 spec->multiout.max_channels;
876
877 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
878 codec->num_pcms++;
879 info++;
880 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100881 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100882 if (spec->multiout.dig_out_nid) {
883 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
884 *(spec->stream_digital_playback);
885 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
886 spec->multiout.dig_out_nid;
887 }
888 if (spec->dig_in_nid) {
889 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
890 *(spec->stream_digital_capture);
891 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
892 spec->dig_in_nid;
893 }
894 }
895
896 return 0;
897}
898
899static void via_free(struct hda_codec *codec)
900{
901 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100902
903 if (!spec)
904 return;
905
Takashi Iwai603c4012008-07-30 15:01:44 +0200906 via_free_kctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100907 kfree(codec->spec);
908}
909
Harald Welte69e52a82008-09-09 15:57:32 +0800910/* mute internal speaker if HP is plugged */
911static void via_hp_automute(struct hda_codec *codec)
912{
913 unsigned int present;
914 struct via_spec *spec = codec->spec;
915
916 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
917 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
918 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
919 HDA_OUTPUT, 0, HDA_AMP_MUTE,
920 present ? HDA_AMP_MUTE : 0);
921}
922
923static void via_gpio_control(struct hda_codec *codec)
924{
925 unsigned int gpio_data;
926 unsigned int vol_counter;
927 unsigned int vol;
928 unsigned int master_vol;
929
930 struct via_spec *spec = codec->spec;
931
932 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
933 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
934
935 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
936 0xF84, 0) & 0x3F0000) >> 16;
937
938 vol = vol_counter & 0x1F;
939 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
940 AC_VERB_GET_AMP_GAIN_MUTE,
941 AC_AMP_GET_INPUT);
942
943 if (gpio_data == 0x02) {
944 /* unmute line out */
945 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
946 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
947
948 if (vol_counter & 0x20) {
949 /* decrease volume */
950 if (vol > master_vol)
951 vol = master_vol;
952 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
953 0, HDA_AMP_VOLMASK,
954 master_vol-vol);
955 } else {
956 /* increase volume */
957 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
958 HDA_AMP_VOLMASK,
959 ((master_vol+vol) > 0x2A) ? 0x2A :
960 (master_vol+vol));
961 }
962 } else if (!(gpio_data & 0x02)) {
963 /* mute line out */
964 snd_hda_codec_amp_stereo(codec,
965 spec->autocfg.line_out_pins[0],
966 HDA_OUTPUT, 0, HDA_AMP_MUTE,
967 HDA_AMP_MUTE);
968 }
969}
970
971/* unsolicited event for jack sensing */
972static void via_unsol_event(struct hda_codec *codec,
973 unsigned int res)
974{
975 res >>= 26;
976 if (res == VIA_HP_EVENT)
977 via_hp_automute(codec);
978 else if (res == VIA_GPIO_EVENT)
979 via_gpio_control(codec);
980}
981
Joseph Chanc577b8a2006-11-29 15:29:40 +0100982static int via_init(struct hda_codec *codec)
983{
984 struct via_spec *spec = codec->spec;
Harald Welte69e52a82008-09-09 15:57:32 +0800985 int i;
986 for (i = 0; i < spec->num_iverbs; i++)
987 snd_hda_sequence_write(codec, spec->init_verbs[i]);
988
Josepch Chanf7278fd2007-12-13 16:40:40 +0100989 /* Lydia Add for EAPD enable */
990 if (!spec->dig_in_nid) { /* No Digital In connection */
Takashi Iwai55d1d6c2009-07-07 13:39:03 +0200991 if (spec->dig_in_pin) {
992 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +0100993 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +0100994 PIN_OUT);
Takashi Iwai55d1d6c2009-07-07 13:39:03 +0200995 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +0100996 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
997 }
Takashi Iwai12b74c82008-01-15 12:39:38 +0100998 } else /* enable SPDIF-input pin */
999 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1000 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
Josepch Chanf7278fd2007-12-13 16:40:40 +01001001
Takashi Iwai9da29272009-05-07 16:31:14 +02001002 /* assign slave outs */
1003 if (spec->slave_dig_outs[0])
1004 codec->slave_dig_outs = spec->slave_dig_outs;
Harald Welte5691ec72008-09-15 22:42:26 +08001005
Joseph Chanc577b8a2006-11-29 15:29:40 +01001006 return 0;
1007}
1008
Takashi Iwaicb53c622007-08-10 17:21:45 +02001009#ifdef CONFIG_SND_HDA_POWER_SAVE
1010static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1011{
1012 struct via_spec *spec = codec->spec;
1013 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1014}
1015#endif
1016
Joseph Chanc577b8a2006-11-29 15:29:40 +01001017/*
1018 */
1019static struct hda_codec_ops via_patch_ops = {
1020 .build_controls = via_build_controls,
1021 .build_pcms = via_build_pcms,
1022 .init = via_init,
1023 .free = via_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02001024#ifdef CONFIG_SND_HDA_POWER_SAVE
1025 .check_power_status = via_check_power_status,
1026#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001027};
1028
1029/* fill in the dac_nids table from the parsed pin configuration */
1030static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1031 const struct auto_pin_cfg *cfg)
1032{
1033 int i;
1034 hda_nid_t nid;
1035
1036 spec->multiout.num_dacs = cfg->line_outs;
1037
1038 spec->multiout.dac_nids = spec->private_dac_nids;
1039
1040 for(i = 0; i < 4; i++) {
1041 nid = cfg->line_out_pins[i];
1042 if (nid) {
1043 /* config dac list */
1044 switch (i) {
1045 case AUTO_SEQ_FRONT:
1046 spec->multiout.dac_nids[i] = 0x10;
1047 break;
1048 case AUTO_SEQ_CENLFE:
1049 spec->multiout.dac_nids[i] = 0x12;
1050 break;
1051 case AUTO_SEQ_SURROUND:
Harald Weltefb4cb772008-09-09 15:53:36 +08001052 spec->multiout.dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001053 break;
1054 case AUTO_SEQ_SIDE:
Harald Weltefb4cb772008-09-09 15:53:36 +08001055 spec->multiout.dac_nids[i] = 0x13;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001056 break;
1057 }
1058 }
1059 }
1060
1061 return 0;
1062}
1063
1064/* add playback controls from the parsed DAC table */
1065static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1066 const struct auto_pin_cfg *cfg)
1067{
1068 char name[32];
1069 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1070 hda_nid_t nid, nid_vol = 0;
1071 int i, err;
1072
1073 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1074 nid = cfg->line_out_pins[i];
1075
1076 if (!nid)
1077 continue;
1078
1079 if (i != AUTO_SEQ_FRONT)
Harald Weltefb4cb772008-09-09 15:53:36 +08001080 nid_vol = 0x18 + i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001081
1082 if (i == AUTO_SEQ_CENLFE) {
1083 /* Center/LFE */
1084 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001085 "Center Playback Volume",
1086 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1087 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001088 if (err < 0)
1089 return err;
1090 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1091 "LFE Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001092 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1093 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001094 if (err < 0)
1095 return err;
1096 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1097 "Center Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001098 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1099 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001100 if (err < 0)
1101 return err;
1102 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1103 "LFE Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001104 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1105 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001106 if (err < 0)
1107 return err;
1108 } else if (i == AUTO_SEQ_FRONT){
1109 /* add control to mixer index 0 */
1110 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1111 "Master Front Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001112 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1113 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001114 if (err < 0)
1115 return err;
1116 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1117 "Master Front Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001118 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1119 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001120 if (err < 0)
1121 return err;
1122
1123 /* add control to PW3 */
1124 sprintf(name, "%s Playback Volume", chname[i]);
1125 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001126 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1127 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001128 if (err < 0)
1129 return err;
1130 sprintf(name, "%s Playback Switch", chname[i]);
1131 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001132 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1133 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001134 if (err < 0)
1135 return err;
1136 } else {
1137 sprintf(name, "%s Playback Volume", chname[i]);
1138 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001139 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1140 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001141 if (err < 0)
1142 return err;
1143 sprintf(name, "%s Playback Switch", chname[i]);
1144 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001145 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1146 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001147 if (err < 0)
1148 return err;
1149 }
1150 }
1151
1152 return 0;
1153}
1154
Harald Welte0aa62ae2008-09-09 15:58:27 +08001155static void create_hp_imux(struct via_spec *spec)
1156{
1157 int i;
1158 struct hda_input_mux *imux = &spec->private_imux[1];
1159 static const char *texts[] = { "OFF", "ON", NULL};
1160
1161 /* for hp mode select */
1162 i = 0;
1163 while (texts[i] != NULL) {
1164 imux->items[imux->num_items].label = texts[i];
1165 imux->items[imux->num_items].index = i;
1166 imux->num_items++;
1167 i++;
1168 }
1169
1170 spec->hp_mux = &spec->private_imux[1];
1171}
1172
Joseph Chanc577b8a2006-11-29 15:29:40 +01001173static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1174{
1175 int err;
1176
1177 if (!pin)
1178 return 0;
1179
1180 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1181
1182 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1183 "Headphone Playback Volume",
1184 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1185 if (err < 0)
1186 return err;
1187 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1188 "Headphone Playback Switch",
1189 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1190 if (err < 0)
1191 return err;
1192
Harald Welte0aa62ae2008-09-09 15:58:27 +08001193 create_hp_imux(spec);
1194
Joseph Chanc577b8a2006-11-29 15:29:40 +01001195 return 0;
1196}
1197
1198/* create playback/capture controls for input pins */
1199static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1200 const struct auto_pin_cfg *cfg)
1201{
1202 static char *labels[] = {
1203 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1204 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08001205 struct hda_input_mux *imux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001206 int i, err, idx = 0;
1207
1208 /* for internal loopback recording select */
1209 imux->items[imux->num_items].label = "Stereo Mixer";
1210 imux->items[imux->num_items].index = idx;
1211 imux->num_items++;
1212
1213 for (i = 0; i < AUTO_PIN_LAST; i++) {
1214 if (!cfg->input_pins[i])
1215 continue;
1216
1217 switch (cfg->input_pins[i]) {
1218 case 0x1d: /* Mic */
1219 idx = 2;
1220 break;
1221
1222 case 0x1e: /* Line In */
1223 idx = 3;
1224 break;
1225
1226 case 0x21: /* Front Mic */
1227 idx = 4;
1228 break;
1229
1230 case 0x24: /* CD */
1231 idx = 1;
1232 break;
1233 }
1234 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1235 idx, 0x17);
1236 if (err < 0)
1237 return err;
1238 imux->items[imux->num_items].label = labels[i];
1239 imux->items[imux->num_items].index = idx;
1240 imux->num_items++;
1241 }
1242 return 0;
1243}
1244
Takashi Iwaicb53c622007-08-10 17:21:45 +02001245#ifdef CONFIG_SND_HDA_POWER_SAVE
1246static struct hda_amp_list vt1708_loopbacks[] = {
1247 { 0x17, HDA_INPUT, 1 },
1248 { 0x17, HDA_INPUT, 2 },
1249 { 0x17, HDA_INPUT, 3 },
1250 { 0x17, HDA_INPUT, 4 },
1251 { } /* end */
1252};
1253#endif
1254
Harald Welte76d9b0d2008-09-09 15:50:37 +08001255static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1256{
1257 unsigned int def_conf;
1258 unsigned char seqassoc;
1259
Takashi Iwai2f334f92009-02-20 14:37:42 +01001260 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08001261 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1262 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1263 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
1264 if (seqassoc == 0xff) {
1265 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
Takashi Iwai2f334f92009-02-20 14:37:42 +01001266 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08001267 }
1268 }
1269
1270 return;
1271}
1272
Joseph Chanc577b8a2006-11-29 15:29:40 +01001273static int vt1708_parse_auto_config(struct hda_codec *codec)
1274{
1275 struct via_spec *spec = codec->spec;
1276 int err;
1277
Harald Welte76d9b0d2008-09-09 15:50:37 +08001278 /* Add HP and CD pin config connect bit re-config action */
1279 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
1280 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
1281
Joseph Chanc577b8a2006-11-29 15:29:40 +01001282 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1283 if (err < 0)
1284 return err;
1285 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
1286 if (err < 0)
1287 return err;
1288 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1289 return 0; /* can't find valid BIOS pin config */
1290
1291 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
1292 if (err < 0)
1293 return err;
1294 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1295 if (err < 0)
1296 return err;
1297 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1298 if (err < 0)
1299 return err;
1300
1301 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1302
Takashi Iwai0852d7a2009-02-11 11:35:15 +01001303 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001304 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001305 spec->dig_in_pin = VT1708_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001306 if (spec->autocfg.dig_in_pin)
1307 spec->dig_in_nid = VT1708_DIGIN_NID;
1308
Takashi Iwai603c4012008-07-30 15:01:44 +02001309 if (spec->kctls.list)
1310 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001311
Harald Welte69e52a82008-09-09 15:57:32 +08001312 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001313
Harald Welte0aa62ae2008-09-09 15:58:27 +08001314 spec->input_mux = &spec->private_imux[0];
1315
Harald Weltef8fdd492008-09-15 22:41:31 +08001316 if (spec->hp_mux)
1317 spec->mixers[spec->num_mixers++] = via_hp_mixer;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001318
1319 return 1;
1320}
1321
1322/* init callback for auto-configuration model -- overriding the default init */
1323static int via_auto_init(struct hda_codec *codec)
1324{
1325 via_init(codec);
1326 via_auto_init_multi_out(codec);
1327 via_auto_init_hp_out(codec);
1328 via_auto_init_analog_input(codec);
1329 return 0;
1330}
1331
Takashi Iwai337b9d02009-07-07 18:18:59 +02001332static int get_mux_nids(struct hda_codec *codec)
1333{
1334 struct via_spec *spec = codec->spec;
1335 hda_nid_t nid, conn[8];
1336 unsigned int type;
1337 int i, n;
1338
1339 for (i = 0; i < spec->num_adc_nids; i++) {
1340 nid = spec->adc_nids[i];
1341 while (nid) {
Takashi Iwaia22d5432009-07-27 12:54:26 +02001342 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai1c55d522009-07-08 07:45:46 +02001343 if (type == AC_WID_PIN)
1344 break;
Takashi Iwai337b9d02009-07-07 18:18:59 +02001345 n = snd_hda_get_connections(codec, nid, conn,
1346 ARRAY_SIZE(conn));
1347 if (n <= 0)
1348 break;
1349 if (n > 1) {
1350 spec->mux_nids[i] = nid;
1351 break;
1352 }
1353 nid = conn[0];
1354 }
1355 }
Takashi Iwai1c55d522009-07-08 07:45:46 +02001356 return 0;
Takashi Iwai337b9d02009-07-07 18:18:59 +02001357}
1358
Joseph Chanc577b8a2006-11-29 15:29:40 +01001359static int patch_vt1708(struct hda_codec *codec)
1360{
1361 struct via_spec *spec;
1362 int err;
1363
1364 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08001365 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001366 if (spec == NULL)
1367 return -ENOMEM;
1368
1369 codec->spec = spec;
1370
1371 /* automatic parse from the BIOS config */
1372 err = vt1708_parse_auto_config(codec);
1373 if (err < 0) {
1374 via_free(codec);
1375 return err;
1376 } else if (!err) {
1377 printk(KERN_INFO "hda_codec: Cannot set up configuration "
1378 "from BIOS. Using genenic mode...\n");
1379 }
1380
1381
1382 spec->stream_name_analog = "VT1708 Analog";
1383 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001384 /* disable 32bit format on VT1708 */
1385 if (codec->vendor_id == 0x11061708)
1386 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001387 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
1388
1389 spec->stream_name_digital = "VT1708 Digital";
1390 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1391 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1392
1393
1394 if (!spec->adc_nids && spec->input_mux) {
1395 spec->adc_nids = vt1708_adc_nids;
1396 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
1397 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
1398 spec->num_mixers++;
1399 }
1400
1401 codec->patch_ops = via_patch_ops;
1402
1403 codec->patch_ops.init = via_auto_init;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001404#ifdef CONFIG_SND_HDA_POWER_SAVE
1405 spec->loopback.amplist = vt1708_loopbacks;
1406#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001407
1408 return 0;
1409}
1410
1411/* capture mixer elements */
1412static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1413 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
1414 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
1415 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
1416 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
1417 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
1418 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
1419 {
1420 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1421 /* The multiple "Capture Source" controls confuse alsamixer
1422 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01001423 */
1424 /* .name = "Capture Source", */
1425 .name = "Input Source",
1426 .count = 1,
1427 .info = via_mux_enum_info,
1428 .get = via_mux_enum_get,
1429 .put = via_mux_enum_put,
1430 },
1431 { } /* end */
1432};
1433
Harald Welte69e52a82008-09-09 15:57:32 +08001434static struct hda_verb vt1709_uniwill_init_verbs[] = {
1435 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
1436 { }
1437};
1438
Joseph Chanc577b8a2006-11-29 15:29:40 +01001439/*
1440 * generic initialization of ADC, input mixers and output mixers
1441 */
1442static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1443 /*
1444 * Unmute ADC0-2 and set the default input to mic-in
1445 */
1446 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1447 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1448 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1449
1450
Josepch Chanf7278fd2007-12-13 16:40:40 +01001451 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01001452 * mixer widget
1453 */
1454 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01001455 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1456 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1457 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1458 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1459 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001460
1461 /*
1462 * Set up output selector (0x1a, 0x1b, 0x29)
1463 */
1464 /* set vol=0 to output mixers */
1465 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1466 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1467 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1468
1469 /*
1470 * Unmute PW3 and PW4
1471 */
1472 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1473 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1474
1475 /* Set input of PW4 as AOW4 */
1476 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001477 /* PW9 Output enable */
1478 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1479 { }
1480};
1481
1482static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1483 .substreams = 1,
1484 .channels_min = 2,
1485 .channels_max = 10,
1486 .nid = 0x10, /* NID to query formats and rates */
1487 .ops = {
1488 .open = via_playback_pcm_open,
1489 .prepare = via_playback_pcm_prepare,
1490 .cleanup = via_playback_pcm_cleanup
1491 },
1492};
1493
1494static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1495 .substreams = 1,
1496 .channels_min = 2,
1497 .channels_max = 6,
1498 .nid = 0x10, /* NID to query formats and rates */
1499 .ops = {
1500 .open = via_playback_pcm_open,
1501 .prepare = via_playback_pcm_prepare,
1502 .cleanup = via_playback_pcm_cleanup
1503 },
1504};
1505
1506static struct hda_pcm_stream vt1709_pcm_analog_capture = {
1507 .substreams = 2,
1508 .channels_min = 2,
1509 .channels_max = 2,
1510 .nid = 0x14, /* NID to query formats and rates */
1511 .ops = {
1512 .prepare = via_capture_pcm_prepare,
1513 .cleanup = via_capture_pcm_cleanup
1514 },
1515};
1516
1517static struct hda_pcm_stream vt1709_pcm_digital_playback = {
1518 .substreams = 1,
1519 .channels_min = 2,
1520 .channels_max = 2,
1521 /* NID is set in via_build_pcms */
1522 .ops = {
1523 .open = via_dig_playback_pcm_open,
1524 .close = via_dig_playback_pcm_close
1525 },
1526};
1527
1528static struct hda_pcm_stream vt1709_pcm_digital_capture = {
1529 .substreams = 1,
1530 .channels_min = 2,
1531 .channels_max = 2,
1532};
1533
1534static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1535 const struct auto_pin_cfg *cfg)
1536{
1537 int i;
1538 hda_nid_t nid;
1539
1540 if (cfg->line_outs == 4) /* 10 channels */
1541 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
1542 else if (cfg->line_outs == 3) /* 6 channels */
1543 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
1544
1545 spec->multiout.dac_nids = spec->private_dac_nids;
1546
1547 if (cfg->line_outs == 4) { /* 10 channels */
1548 for (i = 0; i < cfg->line_outs; i++) {
1549 nid = cfg->line_out_pins[i];
1550 if (nid) {
1551 /* config dac list */
1552 switch (i) {
1553 case AUTO_SEQ_FRONT:
1554 /* AOW0 */
1555 spec->multiout.dac_nids[i] = 0x10;
1556 break;
1557 case AUTO_SEQ_CENLFE:
1558 /* AOW2 */
1559 spec->multiout.dac_nids[i] = 0x12;
1560 break;
1561 case AUTO_SEQ_SURROUND:
1562 /* AOW3 */
Harald Weltefb4cb772008-09-09 15:53:36 +08001563 spec->multiout.dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001564 break;
1565 case AUTO_SEQ_SIDE:
1566 /* AOW1 */
Harald Weltefb4cb772008-09-09 15:53:36 +08001567 spec->multiout.dac_nids[i] = 0x27;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001568 break;
1569 default:
1570 break;
1571 }
1572 }
1573 }
1574 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1575
1576 } else if (cfg->line_outs == 3) { /* 6 channels */
1577 for(i = 0; i < cfg->line_outs; i++) {
1578 nid = cfg->line_out_pins[i];
1579 if (nid) {
1580 /* config dac list */
1581 switch(i) {
1582 case AUTO_SEQ_FRONT:
1583 /* AOW0 */
1584 spec->multiout.dac_nids[i] = 0x10;
1585 break;
1586 case AUTO_SEQ_CENLFE:
1587 /* AOW2 */
1588 spec->multiout.dac_nids[i] = 0x12;
1589 break;
1590 case AUTO_SEQ_SURROUND:
1591 /* AOW1 */
1592 spec->multiout.dac_nids[i] = 0x11;
1593 break;
1594 default:
1595 break;
1596 }
1597 }
1598 }
1599 }
1600
1601 return 0;
1602}
1603
1604/* add playback controls from the parsed DAC table */
1605static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1606 const struct auto_pin_cfg *cfg)
1607{
1608 char name[32];
1609 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1610 hda_nid_t nid = 0;
1611 int i, err;
1612
1613 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1614 nid = cfg->line_out_pins[i];
1615
1616 if (!nid)
1617 continue;
1618
1619 if (i == AUTO_SEQ_CENLFE) {
1620 /* Center/LFE */
1621 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1622 "Center Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001623 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1624 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001625 if (err < 0)
1626 return err;
1627 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1628 "LFE Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001629 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1630 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001631 if (err < 0)
1632 return err;
1633 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1634 "Center Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001635 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1636 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001637 if (err < 0)
1638 return err;
1639 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1640 "LFE Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001641 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1642 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001643 if (err < 0)
1644 return err;
1645 } else if (i == AUTO_SEQ_FRONT){
1646 /* add control to mixer index 0 */
1647 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1648 "Master Front Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001649 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1650 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001651 if (err < 0)
1652 return err;
1653 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1654 "Master Front Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001655 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1656 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001657 if (err < 0)
1658 return err;
1659
1660 /* add control to PW3 */
1661 sprintf(name, "%s Playback Volume", chname[i]);
1662 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001663 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1664 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001665 if (err < 0)
1666 return err;
1667 sprintf(name, "%s Playback Switch", chname[i]);
1668 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001669 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1670 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001671 if (err < 0)
1672 return err;
1673 } else if (i == AUTO_SEQ_SURROUND) {
1674 sprintf(name, "%s Playback Volume", chname[i]);
1675 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Harald Weltefb4cb772008-09-09 15:53:36 +08001676 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001677 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001678 if (err < 0)
1679 return err;
1680 sprintf(name, "%s Playback Switch", chname[i]);
1681 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Harald Weltefb4cb772008-09-09 15:53:36 +08001682 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001683 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001684 if (err < 0)
1685 return err;
1686 } else if (i == AUTO_SEQ_SIDE) {
1687 sprintf(name, "%s Playback Volume", chname[i]);
1688 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Harald Weltefb4cb772008-09-09 15:53:36 +08001689 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001690 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001691 if (err < 0)
1692 return err;
1693 sprintf(name, "%s Playback Switch", chname[i]);
1694 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Harald Weltefb4cb772008-09-09 15:53:36 +08001695 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001696 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001697 if (err < 0)
1698 return err;
1699 }
1700 }
1701
1702 return 0;
1703}
1704
1705static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1706{
1707 int err;
1708
1709 if (!pin)
1710 return 0;
1711
1712 if (spec->multiout.num_dacs == 5) /* 10 channels */
1713 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1714 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1715 spec->multiout.hp_nid = 0;
1716
1717 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1718 "Headphone Playback Volume",
1719 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1720 if (err < 0)
1721 return err;
1722 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1723 "Headphone Playback Switch",
1724 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1725 if (err < 0)
1726 return err;
1727
1728 return 0;
1729}
1730
1731/* create playback/capture controls for input pins */
1732static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1733 const struct auto_pin_cfg *cfg)
1734{
1735 static char *labels[] = {
1736 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1737 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08001738 struct hda_input_mux *imux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001739 int i, err, idx = 0;
1740
1741 /* for internal loopback recording select */
1742 imux->items[imux->num_items].label = "Stereo Mixer";
1743 imux->items[imux->num_items].index = idx;
1744 imux->num_items++;
1745
1746 for (i = 0; i < AUTO_PIN_LAST; i++) {
1747 if (!cfg->input_pins[i])
1748 continue;
1749
1750 switch (cfg->input_pins[i]) {
1751 case 0x1d: /* Mic */
1752 idx = 2;
1753 break;
1754
1755 case 0x1e: /* Line In */
1756 idx = 3;
1757 break;
1758
1759 case 0x21: /* Front Mic */
1760 idx = 4;
1761 break;
1762
1763 case 0x23: /* CD */
1764 idx = 1;
1765 break;
1766 }
1767 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1768 idx, 0x18);
1769 if (err < 0)
1770 return err;
1771 imux->items[imux->num_items].label = labels[i];
1772 imux->items[imux->num_items].index = idx;
1773 imux->num_items++;
1774 }
1775 return 0;
1776}
1777
1778static int vt1709_parse_auto_config(struct hda_codec *codec)
1779{
1780 struct via_spec *spec = codec->spec;
1781 int err;
1782
1783 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1784 if (err < 0)
1785 return err;
1786 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
1787 if (err < 0)
1788 return err;
1789 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1790 return 0; /* can't find valid BIOS pin config */
1791
1792 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
1793 if (err < 0)
1794 return err;
1795 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1796 if (err < 0)
1797 return err;
1798 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
1799 if (err < 0)
1800 return err;
1801
1802 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1803
Takashi Iwai0852d7a2009-02-11 11:35:15 +01001804 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001805 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001806 spec->dig_in_pin = VT1709_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001807 if (spec->autocfg.dig_in_pin)
1808 spec->dig_in_nid = VT1709_DIGIN_NID;
1809
Takashi Iwai603c4012008-07-30 15:01:44 +02001810 if (spec->kctls.list)
1811 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001812
Harald Welte0aa62ae2008-09-09 15:58:27 +08001813 spec->input_mux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001814
Harald Weltef8fdd492008-09-15 22:41:31 +08001815 if (spec->hp_mux)
1816 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1817
Joseph Chanc577b8a2006-11-29 15:29:40 +01001818 return 1;
1819}
1820
Takashi Iwaicb53c622007-08-10 17:21:45 +02001821#ifdef CONFIG_SND_HDA_POWER_SAVE
1822static struct hda_amp_list vt1709_loopbacks[] = {
1823 { 0x18, HDA_INPUT, 1 },
1824 { 0x18, HDA_INPUT, 2 },
1825 { 0x18, HDA_INPUT, 3 },
1826 { 0x18, HDA_INPUT, 4 },
1827 { } /* end */
1828};
1829#endif
1830
Joseph Chanc577b8a2006-11-29 15:29:40 +01001831static int patch_vt1709_10ch(struct hda_codec *codec)
1832{
1833 struct via_spec *spec;
1834 int err;
1835
1836 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08001837 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001838 if (spec == NULL)
1839 return -ENOMEM;
1840
1841 codec->spec = spec;
1842
1843 err = vt1709_parse_auto_config(codec);
1844 if (err < 0) {
1845 via_free(codec);
1846 return err;
1847 } else if (!err) {
1848 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1849 "Using genenic mode...\n");
1850 }
1851
Harald Welte69e52a82008-09-09 15:57:32 +08001852 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
1853 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001854
1855 spec->stream_name_analog = "VT1709 Analog";
1856 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
1857 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1858
1859 spec->stream_name_digital = "VT1709 Digital";
1860 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1861 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1862
1863
1864 if (!spec->adc_nids && spec->input_mux) {
1865 spec->adc_nids = vt1709_adc_nids;
1866 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02001867 get_mux_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001868 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1869 spec->num_mixers++;
1870 }
1871
1872 codec->patch_ops = via_patch_ops;
1873
1874 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08001875 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001876#ifdef CONFIG_SND_HDA_POWER_SAVE
1877 spec->loopback.amplist = vt1709_loopbacks;
1878#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001879
1880 return 0;
1881}
1882/*
1883 * generic initialization of ADC, input mixers and output mixers
1884 */
1885static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
1886 /*
1887 * Unmute ADC0-2 and set the default input to mic-in
1888 */
1889 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1890 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1891 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1892
1893
1894 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1895 * mixer widget
1896 */
1897 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1898 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1899 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1900 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1901 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1902 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1903
1904 /*
1905 * Set up output selector (0x1a, 0x1b, 0x29)
1906 */
1907 /* set vol=0 to output mixers */
1908 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1909 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1910 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1911
1912 /*
1913 * Unmute PW3 and PW4
1914 */
1915 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1916 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1917
1918 /* Set input of PW4 as MW0 */
1919 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001920 /* PW9 Output enable */
1921 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1922 { }
1923};
1924
1925static int patch_vt1709_6ch(struct hda_codec *codec)
1926{
1927 struct via_spec *spec;
1928 int err;
1929
1930 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08001931 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001932 if (spec == NULL)
1933 return -ENOMEM;
1934
1935 codec->spec = spec;
1936
1937 err = vt1709_parse_auto_config(codec);
1938 if (err < 0) {
1939 via_free(codec);
1940 return err;
1941 } else if (!err) {
1942 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1943 "Using genenic mode...\n");
1944 }
1945
Harald Welte69e52a82008-09-09 15:57:32 +08001946 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
1947 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001948
1949 spec->stream_name_analog = "VT1709 Analog";
1950 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
1951 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1952
1953 spec->stream_name_digital = "VT1709 Digital";
1954 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1955 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1956
1957
1958 if (!spec->adc_nids && spec->input_mux) {
1959 spec->adc_nids = vt1709_adc_nids;
1960 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02001961 get_mux_nids(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001962 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1963 spec->num_mixers++;
1964 }
1965
1966 codec->patch_ops = via_patch_ops;
1967
1968 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08001969 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001970#ifdef CONFIG_SND_HDA_POWER_SAVE
1971 spec->loopback.amplist = vt1709_loopbacks;
1972#endif
Josepch Chanf7278fd2007-12-13 16:40:40 +01001973 return 0;
1974}
1975
1976/* capture mixer elements */
1977static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
1978 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
1979 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
1980 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
1981 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
1982 {
1983 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1984 /* The multiple "Capture Source" controls confuse alsamixer
1985 * So call somewhat different..
Josepch Chanf7278fd2007-12-13 16:40:40 +01001986 */
1987 /* .name = "Capture Source", */
1988 .name = "Input Source",
1989 .count = 1,
1990 .info = via_mux_enum_info,
1991 .get = via_mux_enum_get,
1992 .put = via_mux_enum_put,
1993 },
1994 { } /* end */
1995};
1996/*
1997 * generic initialization of ADC, input mixers and output mixers
1998 */
1999static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2000 /*
2001 * Unmute ADC0-1 and set the default input to mic-in
2002 */
2003 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2004 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2005
2006
2007 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2008 * mixer widget
2009 */
2010 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2011 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2012 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2013 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2014 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2015 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2016
2017 /*
2018 * Set up output mixers
2019 */
2020 /* set vol=0 to output mixers */
2021 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2022 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2023 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2024
2025 /* Setup default input to PW4 */
2026 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
2027 /* PW9 Output enable */
2028 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2029 /* PW10 Input enable */
2030 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2031 { }
2032};
2033
2034static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2035 /*
2036 * Unmute ADC0-1 and set the default input to mic-in
2037 */
2038 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2039 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2040
2041
2042 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2043 * mixer widget
2044 */
2045 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2046 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2047 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2048 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2049 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2050 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2051
2052 /*
2053 * Set up output mixers
2054 */
2055 /* set vol=0 to output mixers */
2056 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2057 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2058 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2059
2060 /* Setup default input of PW4 to MW0 */
2061 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2062 /* PW9 Output enable */
2063 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2064 /* PW10 Input enable */
2065 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2066 { }
2067};
2068
Harald Welte69e52a82008-09-09 15:57:32 +08002069static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2070 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2071 { }
2072};
2073
Josepch Chanf7278fd2007-12-13 16:40:40 +01002074static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002075 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002076 .channels_min = 2,
2077 .channels_max = 8,
2078 .nid = 0x10, /* NID to query formats and rates */
2079 .ops = {
2080 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002081 .prepare = via_playback_multi_pcm_prepare,
2082 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002083 },
2084};
2085
2086static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002087 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002088 .channels_min = 2,
2089 .channels_max = 4,
2090 .nid = 0x10, /* NID to query formats and rates */
2091 .ops = {
2092 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002093 .prepare = via_playback_multi_pcm_prepare,
2094 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002095 },
2096};
2097
2098static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2099 .substreams = 2,
2100 .channels_min = 2,
2101 .channels_max = 2,
2102 .nid = 0x13, /* NID to query formats and rates */
2103 .ops = {
2104 .prepare = via_capture_pcm_prepare,
2105 .cleanup = via_capture_pcm_cleanup
2106 },
2107};
2108
2109static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2110 .substreams = 1,
2111 .channels_min = 2,
2112 .channels_max = 2,
2113 /* NID is set in via_build_pcms */
2114 .ops = {
2115 .open = via_dig_playback_pcm_open,
2116 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02002117 .prepare = via_dig_playback_pcm_prepare,
2118 .cleanup = via_dig_playback_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002119 },
2120};
2121
2122static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
2123 .substreams = 1,
2124 .channels_min = 2,
2125 .channels_max = 2,
2126};
2127
2128/* fill in the dac_nids table from the parsed pin configuration */
2129static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
2130 const struct auto_pin_cfg *cfg)
2131{
2132 int i;
2133 hda_nid_t nid;
2134
2135 spec->multiout.num_dacs = cfg->line_outs;
2136
2137 spec->multiout.dac_nids = spec->private_dac_nids;
2138
2139 for (i = 0; i < 4; i++) {
2140 nid = cfg->line_out_pins[i];
2141 if (nid) {
2142 /* config dac list */
2143 switch (i) {
2144 case AUTO_SEQ_FRONT:
2145 spec->multiout.dac_nids[i] = 0x10;
2146 break;
2147 case AUTO_SEQ_CENLFE:
2148 spec->multiout.dac_nids[i] = 0x24;
2149 break;
2150 case AUTO_SEQ_SURROUND:
Harald Weltefb4cb772008-09-09 15:53:36 +08002151 spec->multiout.dac_nids[i] = 0x11;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002152 break;
2153 case AUTO_SEQ_SIDE:
Harald Weltefb4cb772008-09-09 15:53:36 +08002154 spec->multiout.dac_nids[i] = 0x25;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002155 break;
2156 }
2157 }
2158 }
2159
2160 return 0;
2161}
2162
2163/* add playback controls from the parsed DAC table */
2164static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
2165 const struct auto_pin_cfg *cfg)
2166{
2167 char name[32];
2168 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
Harald Weltefb4cb772008-09-09 15:53:36 +08002169 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
Josepch Chanf7278fd2007-12-13 16:40:40 +01002170 hda_nid_t nid, nid_vol = 0;
2171 int i, err;
2172
2173 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2174 nid = cfg->line_out_pins[i];
2175
2176 if (!nid)
2177 continue;
2178
2179 nid_vol = nid_vols[i];
2180
2181 if (i == AUTO_SEQ_CENLFE) {
2182 /* Center/LFE */
2183 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2184 "Center Playback Volume",
2185 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2186 HDA_OUTPUT));
2187 if (err < 0)
2188 return err;
2189 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2190 "LFE Playback Volume",
2191 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2192 HDA_OUTPUT));
2193 if (err < 0)
2194 return err;
2195 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2196 "Center Playback Switch",
2197 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2198 HDA_OUTPUT));
2199 if (err < 0)
2200 return err;
2201 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2202 "LFE Playback Switch",
2203 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2204 HDA_OUTPUT));
2205 if (err < 0)
2206 return err;
2207 } else if (i == AUTO_SEQ_FRONT) {
2208 /* add control to mixer index 0 */
2209 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2210 "Master Front Playback Volume",
2211 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2212 HDA_INPUT));
2213 if (err < 0)
2214 return err;
2215 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2216 "Master Front Playback Switch",
2217 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2218 HDA_INPUT));
2219 if (err < 0)
2220 return err;
2221
2222 /* add control to PW3 */
2223 sprintf(name, "%s Playback Volume", chname[i]);
2224 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2225 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2226 HDA_OUTPUT));
2227 if (err < 0)
2228 return err;
2229 sprintf(name, "%s Playback Switch", chname[i]);
2230 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2231 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2232 HDA_OUTPUT));
2233 if (err < 0)
2234 return err;
2235 } else {
2236 sprintf(name, "%s Playback Volume", chname[i]);
2237 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2238 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2239 HDA_OUTPUT));
2240 if (err < 0)
2241 return err;
2242 sprintf(name, "%s Playback Switch", chname[i]);
2243 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2244 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2245 HDA_OUTPUT));
2246 if (err < 0)
2247 return err;
2248 }
2249 }
2250
2251 return 0;
2252}
2253
2254static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2255{
2256 int err;
2257
2258 if (!pin)
2259 return 0;
2260
2261 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
2262
2263 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2264 "Headphone Playback Volume",
2265 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2266 if (err < 0)
2267 return err;
2268 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2269 "Headphone Playback Switch",
2270 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2271 if (err < 0)
2272 return err;
2273
Harald Welte0aa62ae2008-09-09 15:58:27 +08002274 create_hp_imux(spec);
2275
Josepch Chanf7278fd2007-12-13 16:40:40 +01002276 return 0;
2277}
2278
2279/* create playback/capture controls for input pins */
2280static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2281 const struct auto_pin_cfg *cfg)
2282{
2283 static char *labels[] = {
2284 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2285 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08002286 struct hda_input_mux *imux = &spec->private_imux[0];
Josepch Chanf7278fd2007-12-13 16:40:40 +01002287 int i, err, idx = 0;
2288
2289 /* for internal loopback recording select */
2290 imux->items[imux->num_items].label = "Stereo Mixer";
2291 imux->items[imux->num_items].index = idx;
2292 imux->num_items++;
2293
2294 for (i = 0; i < AUTO_PIN_LAST; i++) {
2295 if (!cfg->input_pins[i])
2296 continue;
2297
2298 switch (cfg->input_pins[i]) {
2299 case 0x1a: /* Mic */
2300 idx = 2;
2301 break;
2302
2303 case 0x1b: /* Line In */
2304 idx = 3;
2305 break;
2306
2307 case 0x1e: /* Front Mic */
2308 idx = 4;
2309 break;
2310
2311 case 0x1f: /* CD */
2312 idx = 1;
2313 break;
2314 }
2315 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2316 idx, 0x16);
2317 if (err < 0)
2318 return err;
2319 imux->items[imux->num_items].label = labels[i];
2320 imux->items[imux->num_items].index = idx;
2321 imux->num_items++;
2322 }
2323 return 0;
2324}
2325
2326static int vt1708B_parse_auto_config(struct hda_codec *codec)
2327{
2328 struct via_spec *spec = codec->spec;
2329 int err;
2330
2331 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2332 if (err < 0)
2333 return err;
2334 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
2335 if (err < 0)
2336 return err;
2337 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2338 return 0; /* can't find valid BIOS pin config */
2339
2340 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
2341 if (err < 0)
2342 return err;
2343 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2344 if (err < 0)
2345 return err;
2346 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
2347 if (err < 0)
2348 return err;
2349
2350 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2351
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002352 if (spec->autocfg.dig_outs)
Josepch Chanf7278fd2007-12-13 16:40:40 +01002353 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002354 spec->dig_in_pin = VT1708B_DIGIN_PIN;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002355 if (spec->autocfg.dig_in_pin)
2356 spec->dig_in_nid = VT1708B_DIGIN_NID;
2357
Takashi Iwai603c4012008-07-30 15:01:44 +02002358 if (spec->kctls.list)
2359 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002360
Harald Welte0aa62ae2008-09-09 15:58:27 +08002361 spec->input_mux = &spec->private_imux[0];
2362
Harald Weltef8fdd492008-09-15 22:41:31 +08002363 if (spec->hp_mux)
2364 spec->mixers[spec->num_mixers++] = via_hp_mixer;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002365
2366 return 1;
2367}
2368
2369#ifdef CONFIG_SND_HDA_POWER_SAVE
2370static struct hda_amp_list vt1708B_loopbacks[] = {
2371 { 0x16, HDA_INPUT, 1 },
2372 { 0x16, HDA_INPUT, 2 },
2373 { 0x16, HDA_INPUT, 3 },
2374 { 0x16, HDA_INPUT, 4 },
2375 { } /* end */
2376};
2377#endif
2378
2379static int patch_vt1708B_8ch(struct hda_codec *codec)
2380{
2381 struct via_spec *spec;
2382 int err;
2383
2384 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08002385 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002386 if (spec == NULL)
2387 return -ENOMEM;
2388
2389 codec->spec = spec;
2390
2391 /* automatic parse from the BIOS config */
2392 err = vt1708B_parse_auto_config(codec);
2393 if (err < 0) {
2394 via_free(codec);
2395 return err;
2396 } else if (!err) {
2397 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2398 "from BIOS. Using genenic mode...\n");
2399 }
2400
Harald Welte69e52a82008-09-09 15:57:32 +08002401 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
2402 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002403
2404 spec->stream_name_analog = "VT1708B Analog";
2405 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
2406 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2407
2408 spec->stream_name_digital = "VT1708B Digital";
2409 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2410 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2411
2412 if (!spec->adc_nids && spec->input_mux) {
2413 spec->adc_nids = vt1708B_adc_nids;
2414 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02002415 get_mux_nids(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002416 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2417 spec->num_mixers++;
2418 }
2419
2420 codec->patch_ops = via_patch_ops;
2421
2422 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002423 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002424#ifdef CONFIG_SND_HDA_POWER_SAVE
2425 spec->loopback.amplist = vt1708B_loopbacks;
2426#endif
2427
2428 return 0;
2429}
2430
2431static int patch_vt1708B_4ch(struct hda_codec *codec)
2432{
2433 struct via_spec *spec;
2434 int err;
2435
2436 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08002437 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002438 if (spec == NULL)
2439 return -ENOMEM;
2440
2441 codec->spec = spec;
2442
2443 /* automatic parse from the BIOS config */
2444 err = vt1708B_parse_auto_config(codec);
2445 if (err < 0) {
2446 via_free(codec);
2447 return err;
2448 } else if (!err) {
2449 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2450 "from BIOS. Using genenic mode...\n");
2451 }
2452
Harald Welte69e52a82008-09-09 15:57:32 +08002453 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
2454 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002455
2456 spec->stream_name_analog = "VT1708B Analog";
2457 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
2458 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2459
2460 spec->stream_name_digital = "VT1708B Digital";
2461 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2462 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2463
2464 if (!spec->adc_nids && spec->input_mux) {
2465 spec->adc_nids = vt1708B_adc_nids;
2466 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02002467 get_mux_nids(codec);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002468 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2469 spec->num_mixers++;
2470 }
2471
2472 codec->patch_ops = via_patch_ops;
2473
2474 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002475 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002476#ifdef CONFIG_SND_HDA_POWER_SAVE
2477 spec->loopback.amplist = vt1708B_loopbacks;
2478#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002479
2480 return 0;
2481}
2482
Harald Welted949cac2008-09-09 15:56:01 +08002483/* Patch for VT1708S */
2484
Harald Welted7426322008-09-15 22:43:23 +08002485/* VT1708S software backdoor based override for buggy hardware micboost
2486 * setting */
2487#define MIC_BOOST_VOLUME(xname, nid) { \
2488 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2489 .name = xname, \
2490 .index = 0, \
2491 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2492 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2493 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2494 .info = mic_boost_volume_info, \
2495 .get = snd_hda_mixer_amp_volume_get, \
2496 .put = snd_hda_mixer_amp_volume_put, \
2497 .tlv = { .c = mic_boost_tlv }, \
2498 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2499
Harald Welted949cac2008-09-09 15:56:01 +08002500/* capture mixer elements */
2501static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2502 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2503 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2504 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2505 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
Harald Welted7426322008-09-15 22:43:23 +08002506 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2507 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
Harald Welted949cac2008-09-09 15:56:01 +08002508 {
2509 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2510 /* The multiple "Capture Source" controls confuse alsamixer
2511 * So call somewhat different..
2512 */
2513 /* .name = "Capture Source", */
2514 .name = "Input Source",
2515 .count = 1,
2516 .info = via_mux_enum_info,
2517 .get = via_mux_enum_get,
2518 .put = via_mux_enum_put,
2519 },
2520 { } /* end */
2521};
2522
2523static struct hda_verb vt1708S_volume_init_verbs[] = {
2524 /* Unmute ADC0-1 and set the default input to mic-in */
2525 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2526 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2527
2528 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2529 * analog-loopback mixer widget */
2530 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2531 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2532 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2533 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2534 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2535 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2536
2537 /* Setup default input of PW4 to MW0 */
2538 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
Harald Welte5691ec72008-09-15 22:42:26 +08002539 /* PW9, PW10 Output enable */
Harald Welted949cac2008-09-09 15:56:01 +08002540 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welte5691ec72008-09-15 22:42:26 +08002541 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welted7426322008-09-15 22:43:23 +08002542 /* Enable Mic Boost Volume backdoor */
2543 {0x1, 0xf98, 0x1},
Harald Welted949cac2008-09-09 15:56:01 +08002544 { }
2545};
2546
Harald Welte69e52a82008-09-09 15:57:32 +08002547static struct hda_verb vt1708S_uniwill_init_verbs[] = {
2548 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2549 { }
2550};
2551
Harald Welted949cac2008-09-09 15:56:01 +08002552static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2553 .substreams = 2,
2554 .channels_min = 2,
2555 .channels_max = 8,
2556 .nid = 0x10, /* NID to query formats and rates */
2557 .ops = {
2558 .open = via_playback_pcm_open,
2559 .prepare = via_playback_pcm_prepare,
2560 .cleanup = via_playback_pcm_cleanup
2561 },
2562};
2563
2564static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2565 .substreams = 2,
2566 .channels_min = 2,
2567 .channels_max = 2,
2568 .nid = 0x13, /* NID to query formats and rates */
2569 .ops = {
2570 .prepare = via_capture_pcm_prepare,
2571 .cleanup = via_capture_pcm_cleanup
2572 },
2573};
2574
2575static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
Takashi Iwai9da29272009-05-07 16:31:14 +02002576 .substreams = 1,
Harald Welted949cac2008-09-09 15:56:01 +08002577 .channels_min = 2,
2578 .channels_max = 2,
2579 /* NID is set in via_build_pcms */
2580 .ops = {
2581 .open = via_dig_playback_pcm_open,
2582 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02002583 .prepare = via_dig_playback_pcm_prepare,
2584 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08002585 },
2586};
2587
2588/* fill in the dac_nids table from the parsed pin configuration */
2589static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
2590 const struct auto_pin_cfg *cfg)
2591{
2592 int i;
2593 hda_nid_t nid;
2594
2595 spec->multiout.num_dacs = cfg->line_outs;
2596
2597 spec->multiout.dac_nids = spec->private_dac_nids;
2598
2599 for (i = 0; i < 4; i++) {
2600 nid = cfg->line_out_pins[i];
2601 if (nid) {
2602 /* config dac list */
2603 switch (i) {
2604 case AUTO_SEQ_FRONT:
2605 spec->multiout.dac_nids[i] = 0x10;
2606 break;
2607 case AUTO_SEQ_CENLFE:
2608 spec->multiout.dac_nids[i] = 0x24;
2609 break;
2610 case AUTO_SEQ_SURROUND:
2611 spec->multiout.dac_nids[i] = 0x11;
2612 break;
2613 case AUTO_SEQ_SIDE:
2614 spec->multiout.dac_nids[i] = 0x25;
2615 break;
2616 }
2617 }
2618 }
2619
2620 return 0;
2621}
2622
2623/* add playback controls from the parsed DAC table */
2624static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
2625 const struct auto_pin_cfg *cfg)
2626{
2627 char name[32];
2628 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2629 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
2630 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
2631 hda_nid_t nid, nid_vol, nid_mute;
2632 int i, err;
2633
2634 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2635 nid = cfg->line_out_pins[i];
2636
2637 if (!nid)
2638 continue;
2639
2640 nid_vol = nid_vols[i];
2641 nid_mute = nid_mutes[i];
2642
2643 if (i == AUTO_SEQ_CENLFE) {
2644 /* Center/LFE */
2645 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2646 "Center Playback Volume",
2647 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2648 HDA_OUTPUT));
2649 if (err < 0)
2650 return err;
2651 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2652 "LFE Playback Volume",
2653 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2654 HDA_OUTPUT));
2655 if (err < 0)
2656 return err;
2657 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2658 "Center Playback Switch",
2659 HDA_COMPOSE_AMP_VAL(nid_mute,
2660 1, 0,
2661 HDA_OUTPUT));
2662 if (err < 0)
2663 return err;
2664 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2665 "LFE Playback Switch",
2666 HDA_COMPOSE_AMP_VAL(nid_mute,
2667 2, 0,
2668 HDA_OUTPUT));
2669 if (err < 0)
2670 return err;
2671 } else if (i == AUTO_SEQ_FRONT) {
2672 /* add control to mixer index 0 */
2673 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2674 "Master Front Playback Volume",
2675 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2676 HDA_INPUT));
2677 if (err < 0)
2678 return err;
2679 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2680 "Master Front Playback Switch",
2681 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2682 HDA_INPUT));
2683 if (err < 0)
2684 return err;
2685
2686 /* Front */
2687 sprintf(name, "%s Playback Volume", chname[i]);
2688 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2689 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2690 HDA_OUTPUT));
2691 if (err < 0)
2692 return err;
2693 sprintf(name, "%s Playback Switch", chname[i]);
2694 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2695 HDA_COMPOSE_AMP_VAL(nid_mute,
2696 3, 0,
2697 HDA_OUTPUT));
2698 if (err < 0)
2699 return err;
2700 } else {
2701 sprintf(name, "%s Playback Volume", chname[i]);
2702 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2703 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2704 HDA_OUTPUT));
2705 if (err < 0)
2706 return err;
2707 sprintf(name, "%s Playback Switch", chname[i]);
2708 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2709 HDA_COMPOSE_AMP_VAL(nid_mute,
2710 3, 0,
2711 HDA_OUTPUT));
2712 if (err < 0)
2713 return err;
2714 }
2715 }
2716
2717 return 0;
2718}
2719
2720static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2721{
2722 int err;
2723
2724 if (!pin)
2725 return 0;
2726
2727 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
2728
2729 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2730 "Headphone Playback Volume",
2731 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
2732 if (err < 0)
2733 return err;
2734
2735 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2736 "Headphone Playback Switch",
2737 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2738 if (err < 0)
2739 return err;
2740
Harald Welte0aa62ae2008-09-09 15:58:27 +08002741 create_hp_imux(spec);
2742
Harald Welted949cac2008-09-09 15:56:01 +08002743 return 0;
2744}
2745
2746/* create playback/capture controls for input pins */
2747static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2748 const struct auto_pin_cfg *cfg)
2749{
2750 static char *labels[] = {
2751 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2752 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08002753 struct hda_input_mux *imux = &spec->private_imux[0];
Harald Welted949cac2008-09-09 15:56:01 +08002754 int i, err, idx = 0;
2755
2756 /* for internal loopback recording select */
2757 imux->items[imux->num_items].label = "Stereo Mixer";
2758 imux->items[imux->num_items].index = 5;
2759 imux->num_items++;
2760
2761 for (i = 0; i < AUTO_PIN_LAST; i++) {
2762 if (!cfg->input_pins[i])
2763 continue;
2764
2765 switch (cfg->input_pins[i]) {
2766 case 0x1a: /* Mic */
2767 idx = 2;
2768 break;
2769
2770 case 0x1b: /* Line In */
2771 idx = 3;
2772 break;
2773
2774 case 0x1e: /* Front Mic */
2775 idx = 4;
2776 break;
2777
2778 case 0x1f: /* CD */
2779 idx = 1;
2780 break;
2781 }
2782 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2783 idx, 0x16);
2784 if (err < 0)
2785 return err;
2786 imux->items[imux->num_items].label = labels[i];
2787 imux->items[imux->num_items].index = idx-1;
2788 imux->num_items++;
2789 }
2790 return 0;
2791}
2792
Takashi Iwai9da29272009-05-07 16:31:14 +02002793/* fill out digital output widgets; one for master and one for slave outputs */
2794static void fill_dig_outs(struct hda_codec *codec)
2795{
2796 struct via_spec *spec = codec->spec;
2797 int i;
2798
2799 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2800 hda_nid_t nid;
2801 int conn;
2802
2803 nid = spec->autocfg.dig_out_pins[i];
2804 if (!nid)
2805 continue;
2806 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2807 if (conn < 1)
2808 continue;
2809 if (!spec->multiout.dig_out_nid)
2810 spec->multiout.dig_out_nid = nid;
2811 else {
2812 spec->slave_dig_outs[0] = nid;
2813 break; /* at most two dig outs */
2814 }
2815 }
2816}
2817
Harald Welted949cac2008-09-09 15:56:01 +08002818static int vt1708S_parse_auto_config(struct hda_codec *codec)
2819{
2820 struct via_spec *spec = codec->spec;
2821 int err;
Harald Welted949cac2008-09-09 15:56:01 +08002822
Takashi Iwai9da29272009-05-07 16:31:14 +02002823 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08002824 if (err < 0)
2825 return err;
2826 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
2827 if (err < 0)
2828 return err;
2829 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2830 return 0; /* can't find valid BIOS pin config */
2831
2832 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
2833 if (err < 0)
2834 return err;
2835 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2836 if (err < 0)
2837 return err;
2838 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
2839 if (err < 0)
2840 return err;
2841
2842 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2843
Takashi Iwai9da29272009-05-07 16:31:14 +02002844 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08002845
Takashi Iwai603c4012008-07-30 15:01:44 +02002846 if (spec->kctls.list)
2847 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08002848
Harald Welte0aa62ae2008-09-09 15:58:27 +08002849 spec->input_mux = &spec->private_imux[0];
2850
Harald Weltef8fdd492008-09-15 22:41:31 +08002851 if (spec->hp_mux)
2852 spec->mixers[spec->num_mixers++] = via_hp_mixer;
Harald Welted949cac2008-09-09 15:56:01 +08002853
2854 return 1;
2855}
2856
2857#ifdef CONFIG_SND_HDA_POWER_SAVE
2858static struct hda_amp_list vt1708S_loopbacks[] = {
2859 { 0x16, HDA_INPUT, 1 },
2860 { 0x16, HDA_INPUT, 2 },
2861 { 0x16, HDA_INPUT, 3 },
2862 { 0x16, HDA_INPUT, 4 },
2863 { } /* end */
2864};
2865#endif
2866
2867static int patch_vt1708S(struct hda_codec *codec)
2868{
2869 struct via_spec *spec;
2870 int err;
2871
2872 /* create a codec specific record */
2873 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2874 if (spec == NULL)
2875 return -ENOMEM;
2876
2877 codec->spec = spec;
2878
2879 /* automatic parse from the BIOS config */
2880 err = vt1708S_parse_auto_config(codec);
2881 if (err < 0) {
2882 via_free(codec);
2883 return err;
2884 } else if (!err) {
2885 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2886 "from BIOS. Using genenic mode...\n");
2887 }
2888
Harald Welte69e52a82008-09-09 15:57:32 +08002889 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
2890 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08002891
2892 spec->stream_name_analog = "VT1708S Analog";
2893 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2894 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2895
2896 spec->stream_name_digital = "VT1708S Digital";
2897 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
2898
2899 if (!spec->adc_nids && spec->input_mux) {
2900 spec->adc_nids = vt1708S_adc_nids;
2901 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02002902 get_mux_nids(codec);
Harald Welted949cac2008-09-09 15:56:01 +08002903 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2904 spec->num_mixers++;
2905 }
2906
2907 codec->patch_ops = via_patch_ops;
2908
2909 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002910 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08002911#ifdef CONFIG_SND_HDA_POWER_SAVE
2912 spec->loopback.amplist = vt1708S_loopbacks;
2913#endif
2914
2915 return 0;
2916}
2917
2918/* Patch for VT1702 */
2919
2920/* capture mixer elements */
2921static struct snd_kcontrol_new vt1702_capture_mixer[] = {
2922 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
2923 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
2924 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
2925 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
2926 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
2927 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
2928 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2929 HDA_INPUT),
2930 {
2931 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2932 /* The multiple "Capture Source" controls confuse alsamixer
2933 * So call somewhat different..
2934 */
2935 /* .name = "Capture Source", */
2936 .name = "Input Source",
2937 .count = 1,
2938 .info = via_mux_enum_info,
2939 .get = via_mux_enum_get,
2940 .put = via_mux_enum_put,
2941 },
2942 { } /* end */
2943};
2944
2945static struct hda_verb vt1702_volume_init_verbs[] = {
2946 /*
2947 * Unmute ADC0-1 and set the default input to mic-in
2948 */
2949 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2950 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2951 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2952
2953
2954 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2955 * mixer widget
2956 */
2957 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2958 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2959 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2960 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2961 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2962 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2963
2964 /* Setup default input of PW4 to MW0 */
2965 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
2966 /* PW6 PW7 Output enable */
2967 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2968 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2969 { }
2970};
2971
Harald Welte69e52a82008-09-09 15:57:32 +08002972static struct hda_verb vt1702_uniwill_init_verbs[] = {
2973 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
2974 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2975 { }
2976};
2977
Harald Welted949cac2008-09-09 15:56:01 +08002978static struct hda_pcm_stream vt1702_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002979 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08002980 .channels_min = 2,
2981 .channels_max = 2,
2982 .nid = 0x10, /* NID to query formats and rates */
2983 .ops = {
2984 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002985 .prepare = via_playback_multi_pcm_prepare,
2986 .cleanup = via_playback_multi_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08002987 },
2988};
2989
2990static struct hda_pcm_stream vt1702_pcm_analog_capture = {
2991 .substreams = 3,
2992 .channels_min = 2,
2993 .channels_max = 2,
2994 .nid = 0x12, /* NID to query formats and rates */
2995 .ops = {
2996 .prepare = via_capture_pcm_prepare,
2997 .cleanup = via_capture_pcm_cleanup
2998 },
2999};
3000
3001static struct hda_pcm_stream vt1702_pcm_digital_playback = {
Harald Welte5691ec72008-09-15 22:42:26 +08003002 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08003003 .channels_min = 2,
3004 .channels_max = 2,
3005 /* NID is set in via_build_pcms */
3006 .ops = {
3007 .open = via_dig_playback_pcm_open,
3008 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02003009 .prepare = via_dig_playback_pcm_prepare,
3010 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08003011 },
3012};
3013
3014/* fill in the dac_nids table from the parsed pin configuration */
3015static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
3016 const struct auto_pin_cfg *cfg)
3017{
3018 spec->multiout.num_dacs = 1;
3019 spec->multiout.dac_nids = spec->private_dac_nids;
3020
3021 if (cfg->line_out_pins[0]) {
3022 /* config dac list */
3023 spec->multiout.dac_nids[0] = 0x10;
3024 }
3025
3026 return 0;
3027}
3028
3029/* add playback controls from the parsed DAC table */
3030static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
3031 const struct auto_pin_cfg *cfg)
3032{
3033 int err;
3034
3035 if (!cfg->line_out_pins[0])
3036 return -1;
3037
3038 /* add control to mixer index 0 */
3039 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3040 "Master Front Playback Volume",
3041 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3042 if (err < 0)
3043 return err;
3044 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3045 "Master Front Playback Switch",
3046 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3047 if (err < 0)
3048 return err;
3049
3050 /* Front */
3051 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3052 "Front Playback Volume",
3053 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
3054 if (err < 0)
3055 return err;
3056 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3057 "Front Playback Switch",
3058 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
3059 if (err < 0)
3060 return err;
3061
3062 return 0;
3063}
3064
3065static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3066{
3067 int err;
3068
3069 if (!pin)
3070 return 0;
3071
3072 spec->multiout.hp_nid = 0x1D;
3073
3074 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3075 "Headphone Playback Volume",
3076 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
3077 if (err < 0)
3078 return err;
3079
3080 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3081 "Headphone Playback Switch",
3082 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3083 if (err < 0)
3084 return err;
3085
Harald Welte0aa62ae2008-09-09 15:58:27 +08003086 create_hp_imux(spec);
3087
Harald Welted949cac2008-09-09 15:56:01 +08003088 return 0;
3089}
3090
3091/* create playback/capture controls for input pins */
3092static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3093 const struct auto_pin_cfg *cfg)
3094{
3095 static char *labels[] = {
3096 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3097 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08003098 struct hda_input_mux *imux = &spec->private_imux[0];
Harald Welted949cac2008-09-09 15:56:01 +08003099 int i, err, idx = 0;
3100
3101 /* for internal loopback recording select */
3102 imux->items[imux->num_items].label = "Stereo Mixer";
3103 imux->items[imux->num_items].index = 3;
3104 imux->num_items++;
3105
3106 for (i = 0; i < AUTO_PIN_LAST; i++) {
3107 if (!cfg->input_pins[i])
3108 continue;
3109
3110 switch (cfg->input_pins[i]) {
3111 case 0x14: /* Mic */
3112 idx = 1;
3113 break;
3114
3115 case 0x15: /* Line In */
3116 idx = 2;
3117 break;
3118
3119 case 0x18: /* Front Mic */
3120 idx = 3;
3121 break;
3122 }
3123 err = via_new_analog_input(spec, cfg->input_pins[i],
3124 labels[i], idx, 0x1A);
3125 if (err < 0)
3126 return err;
3127 imux->items[imux->num_items].label = labels[i];
3128 imux->items[imux->num_items].index = idx-1;
3129 imux->num_items++;
3130 }
3131 return 0;
3132}
3133
3134static int vt1702_parse_auto_config(struct hda_codec *codec)
3135{
3136 struct via_spec *spec = codec->spec;
3137 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003138
Takashi Iwai9da29272009-05-07 16:31:14 +02003139 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08003140 if (err < 0)
3141 return err;
3142 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
3143 if (err < 0)
3144 return err;
3145 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3146 return 0; /* can't find valid BIOS pin config */
3147
3148 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
3149 if (err < 0)
3150 return err;
3151 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3152 if (err < 0)
3153 return err;
3154 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3155 if (err < 0)
3156 return err;
3157
3158 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3159
Takashi Iwai9da29272009-05-07 16:31:14 +02003160 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08003161
Takashi Iwai603c4012008-07-30 15:01:44 +02003162 if (spec->kctls.list)
3163 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08003164
Harald Welte0aa62ae2008-09-09 15:58:27 +08003165 spec->input_mux = &spec->private_imux[0];
3166
Harald Weltef8fdd492008-09-15 22:41:31 +08003167 if (spec->hp_mux)
3168 spec->mixers[spec->num_mixers++] = via_hp_mixer;
Harald Welted949cac2008-09-09 15:56:01 +08003169
3170 return 1;
3171}
3172
3173#ifdef CONFIG_SND_HDA_POWER_SAVE
3174static struct hda_amp_list vt1702_loopbacks[] = {
3175 { 0x1A, HDA_INPUT, 1 },
3176 { 0x1A, HDA_INPUT, 2 },
3177 { 0x1A, HDA_INPUT, 3 },
3178 { 0x1A, HDA_INPUT, 4 },
3179 { } /* end */
3180};
3181#endif
3182
3183static int patch_vt1702(struct hda_codec *codec)
3184{
3185 struct via_spec *spec;
3186 int err;
3187 unsigned int response;
3188 unsigned char control;
3189
3190 /* create a codec specific record */
3191 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3192 if (spec == NULL)
3193 return -ENOMEM;
3194
3195 codec->spec = spec;
3196
3197 /* automatic parse from the BIOS config */
3198 err = vt1702_parse_auto_config(codec);
3199 if (err < 0) {
3200 via_free(codec);
3201 return err;
3202 } else if (!err) {
3203 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3204 "from BIOS. Using genenic mode...\n");
3205 }
3206
Harald Welte69e52a82008-09-09 15:57:32 +08003207 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
3208 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003209
3210 spec->stream_name_analog = "VT1702 Analog";
3211 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
3212 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
3213
3214 spec->stream_name_digital = "VT1702 Digital";
3215 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
3216
3217 if (!spec->adc_nids && spec->input_mux) {
3218 spec->adc_nids = vt1702_adc_nids;
3219 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
Takashi Iwai337b9d02009-07-07 18:18:59 +02003220 get_mux_nids(codec);
Harald Welted949cac2008-09-09 15:56:01 +08003221 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3222 spec->num_mixers++;
3223 }
3224
3225 codec->patch_ops = via_patch_ops;
3226
3227 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003228 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08003229#ifdef CONFIG_SND_HDA_POWER_SAVE
3230 spec->loopback.amplist = vt1702_loopbacks;
3231#endif
3232
3233 /* Open backdoor */
3234 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
3235 control = (unsigned char)(response & 0xff);
3236 control |= 0x3;
3237 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control);
3238
3239 /* Enable GPIO 0&1 for volume&mute control */
3240 /* Enable GPIO 2 for DMIC-DATA */
3241 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
3242 control = (unsigned char)((response >> 16) & 0x3f);
3243 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control);
3244
3245 return 0;
3246}
3247
Joseph Chanc577b8a2006-11-29 15:29:40 +01003248/*
3249 * patch entries
3250 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003251static struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01003252 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3253 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3254 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3255 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3256 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003257 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003258 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003259 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003260 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003261 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003262 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003263 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003264 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003265 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003266 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003267 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003268 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003269 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003270 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003271 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003272 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003273 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003274 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003275 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003276 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003277 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003278 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003279 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003280 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003281 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003282 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003283 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003284 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003285 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003286 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003287 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003288 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003289 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003290 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003291 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003292 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003293 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003294 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003295 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003296 { .id = 0x11064397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003297 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003298 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003299 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003300 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003301 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003302 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003303 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003304 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003305 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003306 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003307 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003308 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003309 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003310 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003311 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003312 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003313 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003314 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003315 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003316 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003317 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003318 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003319 .patch = patch_vt1702},
Joseph Chanc577b8a2006-11-29 15:29:40 +01003320 {} /* terminator */
3321};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003322
3323MODULE_ALIAS("snd-hda-codec-id:1106*");
3324
3325static struct hda_codec_preset_list via_list = {
3326 .preset = snd_hda_preset_via,
3327 .owner = THIS_MODULE,
3328};
3329
3330MODULE_LICENSE("GPL");
3331MODULE_DESCRIPTION("VIA HD-audio codec");
3332
3333static int __init patch_via_init(void)
3334{
3335 return snd_hda_add_codec_preset(&via_list);
3336}
3337
3338static void __exit patch_via_exit(void)
3339{
3340 snd_hda_delete_codec_preset(&via_list);
3341}
3342
3343module_init(patch_via_init)
3344module_exit(patch_via_exit)